人员导入,人员地区绑定

This commit is contained in:
wenc000 2020-05-02 19:06:14 +08:00
parent 6992c36126
commit c894047ff9
8 changed files with 361 additions and 0 deletions

View File

@ -60,4 +60,14 @@ public class DataController {
return dataService.saveCompanyPerson();
}
@PostMapping("saveuser")
public SuccessResult saveUser() throws Exception {
return dataService.saveUser();
}
@PostMapping("saveuserarea")
public SuccessResult saveUserArea() throws Exception {
return dataService.saveUserArea();
}
}

View File

@ -1,10 +1,12 @@
package com.cm.inspection.dao.data;
import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO;
import com.cm.inspection.pojo.dtos.data.DepartmentDTO;
import com.cm.inspection.pojo.dtos.data.UserDTO;
import com.cm.inspection.pojo.vos.data.DepartmentVO;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
/**
@ -29,4 +31,8 @@ public interface IDataDao {
void saveUser(Map<String, Object> userParams);
void saveDepartmentUser(Map<String, Object> params);
List<UserDTO> listDepartmentUser();
DataDictionaryDTO getArea(Map<String, Object> params);
}

View File

@ -0,0 +1,87 @@
package com.cm.inspection.listener.excel.data;
import com.alibaba.excel.annotation.ExcelProperty;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: UserExcel
* @Description: 用户
* @Author: WangGeng
* @Date: 2020/5/2 16:34
* @Version: 1.0
**/
public class UserExcel {
@ExcelProperty(index = 2)
private String area1;
@ExcelProperty(index = 3)
private String area2;
@ExcelProperty(index = 4)
private String area3;
@ExcelProperty(index = 5)
private String area4;
@ExcelProperty(index = 15)
private String area5;
@ExcelProperty(index = 6)
private String name;
@ExcelProperty(index = 11)
private String phone;
public String getArea1() {
return area1 == null ? "" : area1;
}
public void setArea1(String area1) {
this.area1 = area1;
}
public String getArea2() {
return area2 == null ? "" : area2;
}
public void setArea2(String area2) {
this.area2 = area2;
}
public String getArea3() {
return area3 == null ? "" : area3;
}
public void setArea3(String area3) {
this.area3 = area3;
}
public String getArea4() {
return area4 == null ? "" : area4;
}
public void setArea4(String area4) {
this.area4 = area4;
}
public String getArea5() {
return area5 == null ? "" : area5;
}
public void setArea5(String area5) {
this.area5 = area5;
}
public String getName() {
return name == null ? "" : name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone == null ? "" : phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}

View File

@ -0,0 +1,49 @@
package com.cm.inspection.listener.excel.data;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: UserExcelListener
* @Description: 用户
* @Author: WangGeng
* @Date: 2020/5/2 16:34
* @Version: 1.0
**/
public abstract class UserExcelListener extends AnalysisEventListener<UserExcel> {
private static final Logger LOG = LoggerFactory.getLogger(UserExcelListener.class);
private List<UserExcel> userExcels = new ArrayList<>();
@Override
public void invoke(UserExcel userExcel, AnalysisContext analysisContext) {
userExcels.add(userExcel);
if (userExcels.size() > 500) {
try {
listUserExcel(userExcels);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
userExcels.clear();
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
try {
listUserExcel(userExcels);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
userExcels.clear();
}
public abstract void listUserExcel(List<UserExcel> userExcels) throws Exception;
}

View File

@ -11,6 +11,8 @@ public class UserDTO {
private Integer userState;
private Integer loginType;
private String remarks;
private String departmentId;
private String departmentName;
public String getUserId() {
return userId == null ? "" : userId;
@ -75,4 +77,20 @@ public class UserDTO {
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public String getDepartmentId() {
return departmentId == null ? "" : departmentId;
}
public void setDepartmentId(String departmentId) {
this.departmentId = departmentId;
}
public String getDepartmentName() {
return departmentName == null ? "" : departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
}

View File

@ -67,4 +67,21 @@ public interface IDataService {
* @throws Exception
*/
SuccessResult saveCompanyPerson() throws Exception;
/**
* 保存人员
*
* @return
* @throws Exception
*/
SuccessResult saveUser() throws Exception;
/**
* 保存人员地区
*
* @return
* @throws Exception
*/
SuccessResult saveUserArea() throws Exception;
}

View File

@ -22,10 +22,12 @@ import com.cm.inspection.pojo.vos.data.DepartmentVO;
import com.cm.inspection.pojo.vos.data.UserVO;
import com.cm.inspection.pojo.vos.enterprise.EnterpriseVO;
import com.cm.inspection.pojo.vos.enterpriseofgridoperator.EnterpriseOfGridOperatorVO;
import com.cm.inspection.pojo.vos.gridpersonnel.GridPersonnelVO;
import com.cm.inspection.service.BaseService;
import com.cm.inspection.service.data.IDataService;
import com.cm.inspection.service.enterprise.IEnterpriseService;
import com.cm.inspection.service.enterpriseofgridoperator.IEnterpriseOfGridOperatorService;
import com.cm.inspection.service.gridpersonnel.IGridPersonnelService;
import com.hazelcast.util.MD5Util;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -59,6 +61,8 @@ public class DataServiceImpl extends BaseService implements IDataService {
private IDataDao dataDao;
@Autowired
private IEnterpriseOfGridOperatorService enterpriseOfGridOperatorService;
@Autowired
private IGridPersonnelService gridPersonnelService;
@Override
public SuccessResult saveArea() throws Exception {
@ -336,6 +340,125 @@ public class DataServiceImpl extends BaseService implements IDataService {
return new SuccessResultData<>(result);
}
@Override
public SuccessResult saveUser() throws Exception {
File userFile = new File("/Users/wenc/Desktop/包头应急局数据data/jd_com_village_rel.xlsx");
List<String> existUsers = new ArrayList<>();
EasyExcel.read(userFile, UserExcel.class, new UserExcelListener() {
@Override
public void listUserExcel(List<UserExcel> userExcels) throws Exception {
Map<String, Object> params = getHashMap(1);
String currentDate = DateUtil.getTime();
for (UserExcel userExcel : userExcels) {
params.put("userUsername", userExcel.getPhone());
UserDTO userDTO = dataDao.getUser(params);
if (userDTO != null) {
existUsers.add(String.format("%s|%s", userDTO.getUserUsername(), userDTO.getUserName()));
continue;
}
UserVO userVO = new UserVO();
userVO.setUserUsername(userExcel.getPhone().replaceAll("\\s+", ""));
userVO.setUserName(userExcel.getName().replaceAll("\\s+", ""));
userVO.setUserPhone(userExcel.getPhone().replaceAll("\\s+", ""));
userVO.setUserPassword(new BCryptPasswordEncoder().encode(MD5Util.toMD5String(MD5Util.toMD5String(MD5Util.toMD5String("123456")))));
userVO.setUserState(1);
userVO.setLoginType(1);
String remarks = "";
if (!StringUtils.isBlank(userExcel.getArea1())) {
remarks += userExcel.getArea1();
if (!StringUtils.isBlank(userExcel.getArea2())) {
remarks += "|" + userExcel.getArea2();
if (!StringUtils.isBlank(userExcel.getArea3())) {
remarks += "|" + userExcel.getArea3();
if (!StringUtils.isBlank(userExcel.getArea4())) {
remarks += "|" + userExcel.getArea4();
if (!StringUtils.isBlank(userExcel.getArea5())) {
remarks += "|" + userExcel.getArea5();
}
}
}
}
}
userVO.setRemarks(remarks);
Map<String, Object> userParams = HashMapUtil.beanToMap(userVO);
userParams.put("userId", UUIDUtil.getUUID());
userParams.put("creator", "1");
userParams.put("gmtCreate", currentDate);
userParams.put("modifier", "1");
userParams.put("gmtModified", currentDate);
userParams.put("isDelete", 0);
dataDao.saveUser(userParams);
}
}
}).sheet().doRead();
Map<String, Object> result = getHashMap(2);
result.put("existUsers", existUsers);
result.put("existUserCount", existUsers.size());
return new SuccessResultData<>(result);
}
@Override
public SuccessResult saveUserArea() throws Exception {
List<UserDTO> userDTOs = dataDao.listDepartmentUser();
List<String> unBindUserIds = new ArrayList<>();
Map<String, Object> params = getHashMap(1);
for (UserDTO userDTO : userDTOs) {
if (StringUtils.isBlank(userDTO.getRemarks())) {
unBindUserIds.add(userDTO.getUserUsername());
continue;
}
if (StringUtils.isBlank(userDTO.getRemarks())) {
continue;
}
String[] remarkArray = userDTO.getRemarks().split("\\|");
String userArea = remarkArray[remarkArray.length - 1];
params.put("dictionarySummary", userArea);
List<DataDictionaryDTO> dataDictionaryDTOs = new ArrayList<>();
DataDictionaryDTO dataDictionaryDTO = dataDao.getArea(params);
areaDataList(dataDictionaryDTOs, dataDictionaryDTO);
String gridUserId = String.format("%s|%s|%s|【%s】%s", userDTO.getUserId(), userDTO.getDepartmentId(), userDTO.getUserName(), userDTO.getDepartmentName(), userDTO.getUserName());
GridPersonnelVO gridPersonnelVO = new GridPersonnelVO();
gridPersonnelVO.setLevel(dataDictionaryDTOs.size());
gridPersonnelVO.setIsGridOperator(1);
gridPersonnelVO.setUserId(gridUserId);
for (int i = dataDictionaryDTOs.size(); i > 0; i--) {
String dictionaryId = dataDictionaryDTOs.get(i - 1).getDictionaryId();
if (i == 5) {
gridPersonnelVO.setArea5(dictionaryId);
} else if (i == 4) {
gridPersonnelVO.setArea4(dictionaryId);
} else if (i == 3) {
gridPersonnelVO.setArea4(dictionaryId);
} else if (i == 2) {
gridPersonnelVO.setArea4(dictionaryId);
} else if (i == 1) {
gridPersonnelVO.setArea4(dictionaryId);
}
}
gridPersonnelService.saveGridPersonnel(gridPersonnelVO);
}
Map<String, Object> result = getHashMap(2);
result.put("unBindUserIds", unBindUserIds);
result.put("unBindUserIdCount", unBindUserIds.size());
return new SuccessResultData<>(result);
}
/**
* 地区列表倒叙
*
* @param dataDictionaryDTOs
* @param dataDictionaryDTO
*/
private void areaDataList(List<DataDictionaryDTO> dataDictionaryDTOs, DataDictionaryDTO dataDictionaryDTO) {
dataDictionaryDTOs.add(dataDictionaryDTO);
if (StringUtils.equals("81583ade-5466-49aa-b7b6-c643c131ea34", dataDictionaryDTO.getDictionaryId())) {
return;
}
DataDictionaryDTO parentDataDictionary = dataDictionaryService.getDictionaryById(dataDictionaryDTO.getDictionaryParentId());
areaDataList(dataDictionaryDTOs, parentDataDictionary);
}
/**
* 设置高风险
*

View File

@ -21,6 +21,18 @@
<result property="userState" column="user_state"/>
<result property="loginType" column="login_type"/>
<result property="remarks" column="remarks"/>
<result property="departmentId" column="department_id"/>
<result property="departmentName" column="department_name"/>
</resultMap>
<resultMap id="dictionaryDTO" type="com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO">
<id property="dictionaryId" column="dictionary_id"/>
<result property="dictionaryParentId" column="dictionary_parent_id"/>
<result property="dictionaryParentName" column="dictionary_parent_name"/>
<result property="dictionaryName" column="dictionary_name"/>
<result property="dictionarySummary" column="dictionary_summary"/>
<result property="dictionaryCode" column="dictionary_code"/>
<result property="dictionarySort" column="dictionary_sort"/>
</resultMap>
<insert id="saveDepartment" parameterType="map">
@ -94,6 +106,27 @@
)
</insert>
<select id="listDepartmentUser" resultMap="userDTO">
SELECT
t2.department_id,
t2.department_name,
t3.*
FROM
db_cloud_v2.sys_department t1
INNER JOIN
db_cloud_v2.sys_department t2
ON
t1.department_id = t2.department_id
AND
t2.is_delete = 0
INNER JOIN
db_cloud_v2.sys_user t3
ON
t1.user_id = t3.user_id
AND
t3.is_delete = 0
</select>
<select id="getUser" parameterType="map" resultMap="userDTO">
SELECT
*
@ -118,4 +151,22 @@
)
</insert>
<select id="getArea" parameterType="map" resultMap="dataDictionaryDTO">
SELECT
*
FROM
data_dictionary
WHERE
is_delete = 0
<if test="dictionaryId != null and dictionaryId != ''">
AND
dictionary_id = #{dictionaryId}
</if>
<if test="dictionarySummary != null and dictionarySummary != ''">
AND
dictionary_summary = #{dictionarySummary}
</if>
</select>
</mapper>