Browse Source

初始化居民变更记录和变更明细数据

dev
sunyuchao 4 years ago
parent
commit
e40b0ca92c
  1. 20
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcUserChangeRecordInitFormDTO.java
  2. 13
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcUserChangeRecordController.java
  3. 4
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java
  4. 8
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcUserChangeDetailedDao.java
  5. 6
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcUserChangeRecordDao.java
  6. 5
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcUserChangeDetailedService.java
  7. 9
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcUserChangeRecordService.java
  8. 9
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeDetailedServiceImpl.java
  9. 142
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeRecordServiceImpl.java
  10. 45
      epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml
  11. 8
      epmet-user/epmet-user-server/src/main/resources/mapper/IcUserChangeDetailedDao.xml
  12. 10
      epmet-user/epmet-user-server/src/main/resources/mapper/IcUserChangeRecordDao.xml

20
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcUserChangeRecordInitFormDTO.java

@ -0,0 +1,20 @@
package com.epmet.dto.form;
import lombok.Data;
import java.io.Serializable;
/**
* @Description 基础信息变更记录
* @Author sun
*/
@Data
public class IcUserChangeRecordInitFormDTO implements Serializable {
private static final long serialVersionUID = 9156247659994638103L;
/**
* 客户Id
*/
private String customerId;
}

13
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcUserChangeRecordController.java

@ -22,6 +22,7 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.IcResiUserChangeRecordFormDTO;
import com.epmet.dto.form.IcResiUserTransferFormDTO;
import com.epmet.dto.form.IcUserChangeRecordInitFormDTO;
import com.epmet.dto.form.IcUsercategoryAnalysisFormDTO;
import com.epmet.dto.result.IcUserChangeRecordResultDTO;
import com.epmet.dto.result.IcUsercategoryAnalysisResultDTO;
@ -32,6 +33,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
/**
* 居民变更记录表
@ -67,4 +70,14 @@ public class IcUserChangeRecordController {
ValidatorUtils.validateEntity(formDTO,IcUsercategoryAnalysisFormDTO.AddUserShowGroup.class,IcUsercategoryAnalysisFormDTO.AddUserInternalGroup.class);
return new Result<PageData<IcUsercategoryAnalysisResultDTO>>().ok(icUserChangeRecordService.categoryAnalysisList(formDTO));
}
/**
* @Author sun
* @Description 历史居民数据生成变更记录和变更明细数据
**/
@PostMapping("icuserchangerecordinit")
public Result icUserChangeRecordInit(@RequestBody IcUserChangeRecordInitFormDTO formDTO) throws ParseException {
icUserChangeRecordService.icUserChangeRecordInit(formDTO);
return new Result();
}
}

4
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java

@ -233,4 +233,8 @@ public interface IcResiUserDao extends BaseDao<IcResiUserEntity> {
Map<String, String> getCategoryListMap(@Param("icUserId") String icUserId);
List<Map<String,Object>> selectResiUsers(@Param("types")List<String> types,@Param("orgId")String orgId);
List<String> icUserCustomerIds();
List<Map<String, String>> getIcUserList(@Param("customerId") String customerId);
}

8
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcUserChangeDetailedDao.java

@ -20,6 +20,7 @@ package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.entity.IcUserChangeDetailedEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 变更明细表
@ -30,5 +31,10 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface IcUserChangeDetailedDao extends BaseDao<IcUserChangeDetailedEntity> {
/**
* @Author sun
* @Description 删除客户是新增类型的变更明细历史数据
**/
void delByCustomerId(@Param("customerId") String customerId, @Param("type") String type);
}

6
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcUserChangeRecordDao.java

@ -43,4 +43,10 @@ public interface IcUserChangeRecordDao extends BaseDao<IcUserChangeRecordEntity>
List<IcUserChangeRecordDTO> getList(@Param("icUserId") String icUserId);
List<IcUsercategoryAnalysisResultDTO> categoryAnalysisList(IcUsercategoryAnalysisFormDTO formDTO);
/**
* @Author sun
* @Description 删除客户是新增类型的变更历史数据
**/
void delByCustomerId(@Param("customerId") String customerId, @Param("type") String type);
}

5
epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcUserChangeDetailedService.java

@ -29,4 +29,9 @@ import com.epmet.entity.IcUserChangeDetailedEntity;
*/
public interface IcUserChangeDetailedService extends BaseService<IcUserChangeDetailedEntity> {
/**
* @Author sun
* @Description 删除客户是新增类型的变更明细历史数据
**/
void delByCustomerId(String customerId, String type);
}

9
epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcUserChangeRecordService.java

@ -20,11 +20,14 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.form.IcResiUserChangeRecordFormDTO;
import com.epmet.dto.form.IcUserChangeRecordInitFormDTO;
import com.epmet.dto.form.IcUsercategoryAnalysisFormDTO;
import com.epmet.dto.result.IcUserChangeRecordResultDTO;
import com.epmet.dto.result.IcUsercategoryAnalysisResultDTO;
import com.epmet.entity.IcUserChangeRecordEntity;
import java.text.ParseException;
/**
* 居民变更记录表
*
@ -45,4 +48,10 @@ public interface IcUserChangeRecordService extends BaseService<IcUserChangeRecor
* @return
*/
PageData<IcUsercategoryAnalysisResultDTO> categoryAnalysisList(IcUsercategoryAnalysisFormDTO formDTO);
/**
* @Author sun
* @Description 历史居民数据生成变更记录和变更明细数据
**/
void icUserChangeRecordInit(IcUserChangeRecordInitFormDTO formDTO) throws ParseException;
}

9
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeDetailedServiceImpl.java

@ -33,5 +33,12 @@ import org.springframework.stereotype.Service;
@Service
public class IcUserChangeDetailedServiceImpl extends BaseServiceImpl<IcUserChangeDetailedDao, IcUserChangeDetailedEntity> implements IcUserChangeDetailedService {
/**
* @Author sun
* @Description 删除客户是新增类型的变更明细历史数据
**/
@Override
public void delByCustomerId(String customerId, String type) {
baseDao.delByCustomerId(customerId, type);
}
}

142
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeRecordServiceImpl.java

@ -20,29 +20,39 @@ package com.epmet.service.impl;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dao.IcResiUserDao;
import com.epmet.dao.IcUserChangeRecordDao;
import com.epmet.dto.IcResiCategoryWarnConfigDTO;
import com.epmet.dto.IcUserChangeRecordDTO;
import com.epmet.dto.form.IcResiUserChangeRecordFormDTO;
import com.epmet.dto.form.IcUserChangeRecordInitFormDTO;
import com.epmet.dto.form.IcUsercategoryAnalysisFormDTO;
import com.epmet.dto.result.AllGridsByUserIdResultDTO;
import com.epmet.dto.result.BuildingResultDTO;
import com.epmet.dto.result.IcUserChangeRecordResultDTO;
import com.epmet.dto.result.IcUsercategoryAnalysisResultDTO;
import com.epmet.entity.IcUserChangeDetailedEntity;
import com.epmet.entity.IcUserChangeRecordEntity;
import com.epmet.feign.GovOrgOpenFeignClient;
import com.epmet.feign.OperCustomizeOpenFeignClient;
import com.epmet.service.IcUserChangeDetailedService;
import com.epmet.service.IcUserChangeRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -53,9 +63,18 @@ import java.util.stream.Collectors;
* @since v1.0.0 2022-01-14
*/
@Service
@Slf4j
public class IcUserChangeRecordServiceImpl extends BaseServiceImpl<IcUserChangeRecordDao, IcUserChangeRecordEntity> implements IcUserChangeRecordService {
@Autowired
private GovOrgOpenFeignClient govOrgOpenFeignClient;
@Autowired
private IcResiUserDao icResiUserDao;
@Autowired
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient;
@Autowired
private IcUserChangeRecordService icUserChangeRecordService;
@Autowired
private IcUserChangeDetailedService icUserChangeDetailedService;
/**
@ -118,4 +137,119 @@ public class IcUserChangeRecordServiceImpl extends BaseServiceImpl<IcUserChangeR
return new PageData<>(list, pageInfo.getTotal());
}
/**
* @Author sun
* @Description 历史居民数据生成变更记录和变更明细数据
**/
@Override
public void icUserChangeRecordInit(IcUserChangeRecordInitFormDTO formDTO) throws ParseException {
//1.有客户id按客户执行,没有的按ic_resi_user表有效客户执行
//入参有客户Id的则按客户Id执行,没有的则全部客户都执行
if (null != formDTO && StringUtils.isNotBlank(formDTO.getCustomerId())) {
initIcUserChange(formDTO.getCustomerId());
} else {
List<String> customerIdList = icResiUserDao.icUserCustomerIds();
for (String customerId : customerIdList) {
try {
//遍历统计每一个客户数据
initIcUserChange(customerId);
} catch (Exception e) {
log.error("初始客户居民变更记录数据失败,对应客户Id:" + customerId, e);
log.error("Error creating model JSON", e);
}
}
}
}
/**
* @Author sun
* @Description 按客户初始化客户下居民的变更记录变更明细数据
**/
@Transactional(rollbackFor = Exception.class)
public void initIcUserChange(String customerId) throws ParseException {
log.info("开始初始客户下居民的变更记录和变更明细数据,客户Id->"+customerId);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//1.获取客户居民类别预警配置表数据
Result<List<IcResiCategoryWarnConfigDTO>> resultList = operCustomizeOpenFeignClient.categoryWarnConfigList(customerId);
if (!resultList.success()) {
throw new RuntimeException("居民信息修改,获取客户居民类别预警配置表数据失败");
}
List<IcUserChangeRecordEntity> changeList = new ArrayList<>();
IcUserChangeRecordEntity change = null;
List<IcUserChangeDetailedEntity> detailedList = new ArrayList<>();
IcUserChangeDetailedEntity detailed = null;
//存放工作人员姓名
Map<String, String> hash = new HashMap<>();
//2.分批处理客户下居民数据
int pageNo = NumConstant.ONE;
List<Map<String, String>> icUserList = new ArrayList<>();
do {
//一千条一循环查询客户下居民数据
PageHelper.startPage(pageNo, NumConstant.ONE_THOUSAND);
icUserList = icResiUserDao.getIcUserList(customerId);
pageNo++;
//3.遍历封装数据
for (Map<String,String> map : icUserList){
//存放一个人的类别为是的变更明细数据
List<IcUserChangeDetailedEntity> subList = new ArrayList<>();
String changeId = UUID.randomUUID().toString().replaceAll("-", "");
for (IcResiCategoryWarnConfigDTO dto : resultList.getData()){
if(map.containsKey(dto.getColumnName())&&"1".equals(map.get(dto.getColumnName()))){
detailed = new IcUserChangeDetailedEntity();
detailed.setCustomerId(customerId);
detailed.setIcUserChangeRecordId(changeId);
detailed.setPids(map.get("PIDS"));
detailed.setAgencyId(map.get("AGENCY_ID"));
detailed.setGridId(map.get("GRID_ID"));
detailed.setNeighborHoodId(map.get("VILLAGE_ID"));
detailed.setBuildingId(map.get("BUILD_ID"));
detailed.setBuildingUnitId(map.get("UNIT_ID"));
detailed.setHouseId(map.get("HOME_ID"));
detailed.setIcUserId(map.get("HOME_ID"));
detailed.setType("add");
detailed.setTypeName("新增");
detailed.setFieldName(dto.getColumnName());
detailed.setValue(1);
detailed.setCreatedBy(map.get("CREATED_BY"));
detailed.setCreatedTime(sdf.parse(map.get("CREATED_TIME")));
detailed.setUpdatedBy("APP_USER");
detailed.setUpdatedTime(new Date());
subList.add(detailed);
}
}
if (subList.size() > NumConstant.ZERO) {
detailedList.addAll(subList);
if (!hash.containsKey(map.get("CREATED_BY"))) {
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, map.get("CREATED_BY"));
//被删除或被移除的工作人员,名字为空
hash.put(map.get("CREATED_BY"), null != staffInfoCache ? staffInfoCache.getRealName() : "");
}
change = new IcUserChangeRecordEntity();
change.setId(changeId);
change.setCustomerId(customerId);
change.setOperatorId(map.get("CREATED_BY"));
change.setIcUserId(map.get("ID"));
change.setOperatorName(hash.get(map.get("CREATED_BY")));
change.setIcUserName(map.get("NAME"));
change.setType("add");
change.setTypeName("新增");
change.setBeforeChangeName("-");
change.setAfterChangeName("-");
change.setChangeTime(sdf.parse(map.get("CREATED_TIME")));
change.setCreatedBy(map.get("CREATED_BY"));
change.setCreatedTime(sdf.parse(map.get("CREATED_TIME")));
change.setUpdatedBy("APP_USER");
change.setUpdatedTime(new Date());
changeList.add(change);
}
}
} while (icUserList.size() == NumConstant.ONE_THOUSAND);
//4.批量新增数据,先删后增【只删除新增节点的历史数据】
baseDao.delByCustomerId(customerId, "add");
icUserChangeDetailedService.delByCustomerId(customerId, "add");
icUserChangeRecordService.insertBatch(changeList);
icUserChangeDetailedService.insertBatch(detailedList);
}
}

45
epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml

@ -560,4 +560,49 @@
ORDER BY CREATED_TIME DESC
</select>
<select id="icUserCustomerIds" resultType="java.lang.String">
SELECT customer_id FROM ic_resi_user GROUP BY customer_id
</select>
<select id="getIcUserList" resultType="java.util.Map">
SELECT
id ID,
customer_id CUSTOMER_ID,
agency_id AGENCY_ID,
pids PIDS,
grid_id GRID_ID,
village_id VILLAGE_ID,
build_id BUILD_ID,
unit_id UNIT_ID,
home_id HOME_ID,
name NAME,
created_by CREATED_BY,
date_format(created_time, '%Y-%m-%d %h:%i:%s') CREATED_TIME,
IFNULL(is_kc,'0') IS_KC,
IFNULL(is_cj,'0') IS_CJ,
IFNULL(is_ylfn,'0') IS_YLFN,
IFNULL(is_sn,'0') IS_SN,
IFNULL(is_special,'0') IS_SPECIAL,
IFNULL(is_volunteer,'0') IS_VOLUNTEER,
IFNULL(is_unemployed,'0') IS_UNEMPLOYED,
IFNULL(is_mb,'0') IS_MB,
IFNULL(is_sz,'0') IS_SZ,
IFNULL(is_sd,'0') IS_SD,
IFNULL(is_veterans,'0') IS_VETERANS,
IFNULL(is_ensure_house,'0') IS_ENSURE_HOUSE,
IFNULL(is_party,'0') IS_PARTY,
IFNULL(is_old_people,'0') IS_OLD_PEOPLE,
IFNULL(is_xfry,'0')IS_XFRY,
IFNULL(is_united_front,'0') IS_UNITED_FRONT,
IFNULL(is_db,'0') IS_DB,
IFNULL(is_dbh,'0') IS_DBH
FROM
ic_resi_user
WHERE
del_flag = '0'
AND `status` = '0'
AND customer_id = #{customerId}
ORDER BY created_time ASC
</select>
</mapper>

8
epmet-user/epmet-user-server/src/main/resources/mapper/IcUserChangeDetailedDao.xml

@ -3,5 +3,13 @@
<mapper namespace="com.epmet.dao.IcUserChangeDetailedDao">
<delete id="delByCustomerId">
DELETE
FROM
ic_user_change_detailed
WHERE
CUSTOMER_ID = #{customerId}
AND type = #{type}
</delete>
</mapper>

10
epmet-user/epmet-user-server/src/main/resources/mapper/IcUserChangeRecordDao.xml

@ -58,4 +58,14 @@
<![CDATA[ AND DATE_FORMAT( d.CREATED_TIME, '%Y%m%d' ) <= #{endDate} ]]>
order by d.CREATED_TIME asc,d.id asc
</select>
<delete id="delByCustomerId">
DELETE
FROM
ic_user_change_record
WHERE
CUSTOMER_ID = #{customerId}
AND type = #{type}
</delete>
</mapper>
Loading…
Cancel
Save