人员、部门和企业的绑定关系

This commit is contained in:
wenc000 2020-05-02 14:37:24 +08:00
parent 8f5d2a8f6a
commit 6992c36126
11 changed files with 337 additions and 9 deletions

View File

@ -50,4 +50,14 @@ public class DataController {
return dataService.saveVillageGroupPerson();
}
@PostMapping("savevillageorganperson")
public SuccessResult saveVillageOrganPerson() throws Exception {
return dataService.saveVillageOrganPerson();
}
@PostMapping("savecompanyperson")
public SuccessResult saveCompanyPerson() throws Exception {
return dataService.saveCompanyPerson();
}
}

View File

@ -27,4 +27,6 @@ public interface IDataDao {
UserDTO getUser(Map<String, Object> params);
void saveUser(Map<String, Object> userParams);
void saveDepartmentUser(Map<String, Object> params);
}

View File

@ -0,0 +1,47 @@
package com.cm.inspection.listener.excel.data;
import com.alibaba.excel.annotation.ExcelProperty;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: EnterprisePersonExcel
* @Description: 企业人员
* @Author: WangGeng
* @Date: 2020/5/2 10:54 上午
* @Version: 1.0
**/
public class EnterprisePersonExcel {
@ExcelProperty(index = 2)
private Integer companyId;
@ExcelProperty(index = 4)
private Integer userId;
@ExcelProperty(index = 5)
private Integer isDeleted;
public Integer getCompanyId() {
return companyId;
}
public void setCompanyId(Integer companyId) {
this.companyId = companyId;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Integer getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Integer isDeleted) {
this.isDeleted = isDeleted;
}
}

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: EnterprisePersonListener
* @Description: 企业人员
* @Author: WangGeng
* @Date: 2020/5/2 10:54 上午
* @Version: 1.0
**/
public abstract class EnterprisePersonListener extends AnalysisEventListener<EnterprisePersonExcel> {
private static final Logger LOG = LoggerFactory.getLogger(EnterprisePersonListener.class);
private List<EnterprisePersonExcel> enterprisePersonExcels = new ArrayList<>();
@Override
public void invoke(EnterprisePersonExcel enterprisePersonExcel, AnalysisContext analysisContext) {
enterprisePersonExcels.add(enterprisePersonExcel);
if (enterprisePersonExcels.size() > 1000) {
try {
listEnterprisePersonExcel(enterprisePersonExcels);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
enterprisePersonExcels.clear();
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
try {
listEnterprisePersonExcel(enterprisePersonExcels);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
enterprisePersonExcels.clear();
}
public abstract void listEnterprisePersonExcel(List<EnterprisePersonExcel> enterprisePersonExcels) throws Exception;
}

View File

@ -0,0 +1,37 @@
package com.cm.inspection.listener.excel.data;
import com.alibaba.excel.annotation.ExcelProperty;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: VillageOrganPersonExcel
* @Description: 机构人员
* @Author: WangGeng
* @Date: 2020/5/2 10:49 上午
* @Version: 1.0
**/
public class VillageOrganPersonExcel {
@ExcelProperty(index = 1)
private Integer organId;
@ExcelProperty(index = 2)
private Integer userId;
public Integer getOrganId() {
return organId;
}
public void setOrganId(Integer organId) {
this.organId = organId;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
}

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: VillageOrganPersonListener
* @Description: 机构人员
* @Author: WangGeng
* @Date: 2020/5/2 10:50 上午
* @Version: 1.0
**/
public abstract class VillageOrganPersonListener extends AnalysisEventListener<VillageOrganPersonExcel> {
private static final Logger LOG = LoggerFactory.getLogger(VillageOrganPersonListener.class);
private List<VillageOrganPersonExcel> villageOrganPersonExcels = new ArrayList<>();
@Override
public void invoke(VillageOrganPersonExcel villageOrganPersonExcel, AnalysisContext analysisContext) {
villageOrganPersonExcels.add(villageOrganPersonExcel);
if (villageOrganPersonExcels.size() > 200) {
try {
listVillageOrganPersonExcel(villageOrganPersonExcels);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
villageOrganPersonExcels.clear();
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
try {
listVillageOrganPersonExcel(villageOrganPersonExcels);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
villageOrganPersonExcels.clear();
}
public abstract void listVillageOrganPersonExcel(List<VillageOrganPersonExcel> villageOrganPersonExcels) throws Exception;
}

View File

@ -15,7 +15,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
public class VillagePerson {
@ExcelProperty(index = 1)
private String id;
private Integer id;
@ExcelProperty(index = 2)
private String name;
@ExcelProperty(index = 3)
@ -45,11 +45,11 @@ public class VillagePerson {
@ExcelProperty(index = 32)
private String belongAreaName;
public String getId() {
return id == null ? "" : id;
public Integer getId() {
return id;
}
public void setId(String id) {
public void setId(Integer id) {
this.id = id;
}

View File

@ -51,4 +51,20 @@ public interface IDataService {
* @throws Exception
*/
SuccessResult saveVillageGroupPerson() throws Exception;
/**
* 网格员和部门
*
* @return
* @throws Exception
*/
SuccessResult saveVillageOrganPerson() throws Exception;
/**
* 网格员和企业
*
* @return
* @throws Exception
*/
SuccessResult saveCompanyPerson() throws Exception;
}

View File

@ -8,6 +8,7 @@ import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO;
import com.cm.common.plugin.pojo.vos.datadictionary.DataDictionaryVO;
import com.cm.common.plugin.service.datadictionary.IDataDictionaryService;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultData;
import com.cm.common.utils.DateUtil;
import com.cm.common.utils.HashMapUtil;
import com.cm.common.utils.UUIDUtil;
@ -15,12 +16,16 @@ import com.cm.inspection.dao.data.IDataDao;
import com.cm.inspection.listener.excel.data.*;
import com.cm.inspection.pojo.dtos.data.DepartmentDTO;
import com.cm.inspection.pojo.dtos.data.UserDTO;
import com.cm.inspection.pojo.dtos.enterprise.EnterpriseDTO;
import com.cm.inspection.pojo.dtos.enterpriseofgridoperator.EnterpriseOfGridOperatorDTO;
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.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.hazelcast.util.MD5Util;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -52,6 +57,8 @@ public class DataServiceImpl extends BaseService implements IDataService {
private IEnterpriseService enterpriseService;
@Autowired
private IDataDao dataDao;
@Autowired
private IEnterpriseOfGridOperatorService enterpriseOfGridOperatorService;
@Override
public SuccessResult saveArea() throws Exception {
@ -203,7 +210,7 @@ public class DataServiceImpl extends BaseService implements IDataService {
@Override
public SuccessResult saveVillageGroupPerson() throws Exception {
File villagePersonFile = new File("C:\\Users\\Administrator\\Desktop\\jd_village_person.xlsx");
File villagePersonFile = new File("/Users/wenc/Desktop/包头应急局数据data/jd_village_person.xls");
EasyExcel.read(villagePersonFile, VillagePerson.class, new VillagePersonListener() {
@Override
public void listVillagePerson(List<VillagePerson> villagePersons) throws Exception {
@ -216,13 +223,13 @@ public class DataServiceImpl extends BaseService implements IDataService {
continue;
}
UserVO userVO = new UserVO();
userVO.setUserUsername(villagePerson.getAccount());
userVO.setUserName(villagePerson.getName());
userVO.setUserPhone(villagePerson.getHandset());
userVO.setUserUsername(villagePerson.getAccount().replaceAll("\\s+", ""));
userVO.setUserName(villagePerson.getName().replaceAll("\\s+", ""));
userVO.setUserPhone(villagePerson.getHandset().replaceAll("\\s+", ""));
userVO.setUserPassword(new BCryptPasswordEncoder().encode(MD5Util.toMD5String(MD5Util.toMD5String(MD5Util.toMD5String("123456")))));
userVO.setUserState(1);
userVO.setLoginType(1);
userVO.setRemarks(villagePerson.getId());
userVO.setRemarks(villagePerson.getId() + "|" + villagePerson.getBelongAreaCode().replaceAll("\\s+", ""));
Map<String, Object> userParams = HashMapUtil.beanToMap(userVO);
userParams.put("userId", UUIDUtil.getUUID());
userParams.put("creator", "1");
@ -237,6 +244,98 @@ public class DataServiceImpl extends BaseService implements IDataService {
return new SuccessResult();
}
@Override
public SuccessResult saveVillageOrganPerson() throws Exception {
File villageOrganPersonFile = new File("/Users/wenc/Desktop/包头应急局数据data/jd_village_organ_person_rel.xls");
final int[] unExistUserCount = {0};
final int[] unExistDepartmentCount = {0};
final List<String> unExistUserIds = new ArrayList<>();
final List<String> unExistDepartmentIds = new ArrayList<>();
EasyExcel.read(villageOrganPersonFile, VillageOrganPersonExcel.class, new VillageOrganPersonListener() {
@Override
public void listVillageOrganPersonExcel(List<VillageOrganPersonExcel> villageOrganPersonExcels) throws Exception {
Map<String, Object> params = getHashMap(1);
for (VillageOrganPersonExcel villageOrganPersonExcel : villageOrganPersonExcels) {
params.put("remarksId", villageOrganPersonExcel.getUserId() + "|");
UserDTO userDTO = dataDao.getUser(params);
if (userDTO == null) {
unExistUserCount[0]++;
unExistUserIds.add(villageOrganPersonExcel.getUserId().toString());
continue;
}
params.clear();
params.put("departmentSummary", villageOrganPersonExcel.getOrganId());
DepartmentDTO departmentDTO = dataDao.getDepartment(params);
if (departmentDTO == null) {
unExistDepartmentCount[0]++;
unExistDepartmentIds.add(villageOrganPersonExcel.getOrganId() + "|" + villageOrganPersonExcel.getUserId());
continue;
}
params.clear();
params.put("departmentId", departmentDTO.getDepartmentId());
params.put("userId", userDTO.getUserId());
dataDao.saveDepartmentUser(params);
}
}
}).sheet().doRead();
Map<String, Object> result = getHashMap(2);
result.put("unExistUserCount", unExistUserCount[0]);
result.put("unExistEnterpriseCount", unExistDepartmentCount[0]);
result.put("unExistUserIds", unExistUserIds);
result.put("unExistDepartmentIds", unExistDepartmentIds);
return new SuccessResultData<>(result);
}
@Override
public SuccessResult saveCompanyPerson() throws Exception {
File companyPersonFile = new File("/Users/wenc/Desktop/包头应急局数据data/jd_com_village_rel.xlsx");
List<String> unExistEnterpriseIds = new ArrayList<>();
List<String> moreEnterpriseIds = new ArrayList<>();
List<String> unExistPersonIds = new ArrayList<>();
EasyExcel.read(companyPersonFile, EnterprisePersonExcel.class, new EnterprisePersonListener() {
@Override
public void listEnterprisePersonExcel(List<EnterprisePersonExcel> enterprisePersonExcels) throws Exception {
Map<String, Object> params = getHashMap(1);
for (EnterprisePersonExcel enterprisePersonExcel : enterprisePersonExcels) {
if (enterprisePersonExcel.getIsDeleted() != 0) {
continue;
}
params.put("remarks", enterprisePersonExcel.getCompanyId());
List<EnterpriseDTO> enterpriseDTOs = enterpriseService.listEnterprise(params);
if (enterpriseDTOs.size() == 0) {
unExistEnterpriseIds.add(enterprisePersonExcel.getCompanyId() + "|" + enterprisePersonExcel.getUserId());
continue;
}
if (enterpriseDTOs.size() > 1) {
moreEnterpriseIds.add(enterprisePersonExcel.getCompanyId() + "|" + enterprisePersonExcel.getUserId());
continue;
}
if (enterprisePersonExcel.getUserId() == null) {
continue;
}
params.put("remarksId", enterprisePersonExcel.getUserId() + "|");
UserDTO userDTO = dataDao.getUser(params);
if (userDTO == null) {
unExistPersonIds.add(enterprisePersonExcel.getCompanyId() + "|" + enterprisePersonExcel.getUserId());
continue;
}
EnterpriseOfGridOperatorVO enterpriseOfGridOperatorVO = new EnterpriseOfGridOperatorVO();
enterpriseOfGridOperatorVO.setEnterpriseId(enterpriseDTOs.get(0).getEnterpriseId());
enterpriseOfGridOperatorVO.setUserId(userDTO.getUserId());
enterpriseOfGridOperatorService.saveEnterpriseOfGridOperator(enterpriseOfGridOperatorVO);
}
}
}).sheet().doRead();
Map<String, Object> result = getHashMap(6);
result.put("unExistEnterpriseCount", unExistEnterpriseIds.size());
result.put("unExistEnterpriseIds", unExistEnterpriseIds);
result.put("moreEnterpriseCount", moreEnterpriseIds.size());
result.put("moreEnterpriseIds", moreEnterpriseIds);
result.put("unExistPersonCount", unExistPersonIds.size());
result.put("unExistPersonIds", unExistPersonIds);
return new SuccessResultData<>(result);
}
/**
* 设置高风险
*

View File

@ -100,7 +100,22 @@
FROM
db_cloud_v2.sys_user
WHERE
<if test="userUsername != null and userUsername != ''">
user_username = #{userUsername}
</if>
<if test="remarksId != null and remarksId != ''">
remarks LIKE CONCAT(#{remarksId}, '%')
</if>
</select>
<insert id="saveDepartmentUser" parameterType="map">
INSERT INTO db_cloud_v2.sys_department_user(
department_id,
user_id
) VALUES(
#{departmentId},
#{userId}
)
</insert>
</mapper>

View File

@ -430,6 +430,10 @@
AND
t1.area5 = #{area5}
</if>
<if test="remarks != null and remarks != ''">
AND
t1.remarks = #{remarks}
</if>
<if test="enterpriseIds != null and enterpriseIds.size > 0">
AND
t1.enterprise_id IN