Browse Source

修改定时同步任务

master
jianjun 3 years ago
parent
commit
580c5cee01
  1. 2
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/DataSyncConfigController.java
  2. 19
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/DataSyncConfigDao.java
  3. 55
      epmet-user/epmet-user-server/src/main/java/com/epmet/enums/DataSyncEnum.java
  4. 4
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/DataSyncConfigService.java
  5. 103
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java
  6. 36
      epmet-user/epmet-user-server/src/main/resources/mapper/DataSyncConfigDao.xml

2
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/DataSyncConfigController.java

@ -108,7 +108,7 @@ public class DataSyncConfigController {
@PostMapping("natInfoScanTask")
public Result natInfoScanTask(@RequestBody NatInfoScanTaskFormDTO formDTO){
dataSyncConfigService.natInfoScanTask(formDTO);
dataSyncConfigService.dataSyncForYanTaiTask(formDTO);
return new Result();
}

19
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/DataSyncConfigDao.java

@ -22,6 +22,7 @@ public interface DataSyncConfigDao extends BaseDao<DataSyncConfigEntity> {
/**
* Desc: 数据配置配置开关
*
* @param formDTO
* @author zxc
* @date 2022/9/26 14:36
@ -30,30 +31,32 @@ public interface DataSyncConfigDao extends BaseDao<DataSyncConfigEntity> {
/**
* Desc: 数据配置列表
*
* @param customerId
* @param switchStatus
* @author zxc
* @date 2022/9/26 15:04
*/
List<DataSyncConfigDTO> list(@Param("customerId")String customerId);
List<DataSyncConfigDTO> list(@Param("customerId") String customerId, @Param("switchStatus") String switchStatus);
List<DataSyncScopeDTO> scopeList(@Param("id")String id);
List<DataSyncScopeDTO> scopeList(@Param("id") String id);
/**
* Desc: 删除范围
*
* @param dataSyncConfigId
* @author zxc
* @date 2022/9/26 15:46
*/
void delScope(@Param("dataSyncConfigId")String dataSyncConfigId);
void delScope(@Param("dataSyncConfigId") String dataSyncConfigId);
/**
* Desc: 根据范围查询居民证件号
* @param list
*
* @param orgList
* @author zxc
* @date 2022/9/27 09:23
*/
List<NatUserInfoResultDTO> getIdCardsByScope(@Param("list") List<DataSyncScopeDTO> list);
List<NatUserInfoResultDTO> getIdCardsByScope(@Param("orgList") List<DataSyncScopeDTO> orgList, @Param("idCardList") List<String> idCardList);
List<NatUserInfoResultDTO> getUserIdByIdCard(@Param("list") List<String> list);
}
}

55
epmet-user/epmet-user-server/src/main/java/com/epmet/enums/DataSyncEnum.java

@ -0,0 +1,55 @@
package com.epmet.enums;
/**
* desc:数据同步配置枚举 对应data_sync_config中的DATA_CODE
* @author Administrator
*/
public enum DataSyncEnum {
/**
* 环境变量枚举
*/
HE_SUAN("hesuan", "核酸检测数据"),
CAN_JI("canji", "残疾数据"),
SI_WANG("siwang", "死亡数据"),
OTHER("qita","其他"),
;
private final String code;
private final String name;
DataSyncEnum(String code, String name) {
this.code = code;
this.name = name;
}
public static DataSyncEnum getEnum(String code) {
DataSyncEnum[] values = DataSyncEnum.values();
for (DataSyncEnum value : values) {
if (value.getCode().equals(code)) {
return value;
}
}
return DataSyncEnum.OTHER;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
public static void main(String[] args) {
Integer pageNo = 1;
for (int i = 0; i < 5; i++) {
System.out.println(pageNo++);
}
}
}

4
epmet-user/epmet-user-server/src/main/java/com/epmet/service/DataSyncConfigService.java

@ -82,5 +82,5 @@ public interface DataSyncConfigService extends BaseService<DataSyncConfigEntity>
*/
void scopeSave(ScopeSaveFormDTO formDTO);
void natInfoScanTask(NatInfoScanTaskFormDTO formDTO);
}
void dataSyncForYanTaiTask(NatInfoScanTaskFormDTO formDTO);
}

103
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java

@ -1,4 +1,5 @@
package com.epmet.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
@ -25,12 +26,14 @@ import com.epmet.entity.DataSyncConfigEntity;
import com.epmet.entity.DataSyncScopeEntity;
import com.epmet.entity.IcNatEntity;
import com.epmet.entity.IcNatRelationEntity;
import com.epmet.enums.DataSyncEnum;
import com.epmet.service.DataSyncConfigService;
import com.epmet.service.DataSyncScopeService;
import com.epmet.service.IcNatRelationService;
import com.epmet.service.IcNatService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
@ -50,6 +53,7 @@ import java.util.stream.Collectors;
* @author generator generator@elink-cn.com
* @since v1.0.0 2022-09-26
*/
@Slf4j
@Service
public class DataSyncConfigServiceImpl extends BaseServiceImpl<DataSyncConfigDao, DataSyncConfigEntity> implements DataSyncConfigService {
@ -119,10 +123,11 @@ public class DataSyncConfigServiceImpl extends BaseServiceImpl<DataSyncConfigDao
@Override
public PageData list(TokenDto tokenDto, PageFormDTO formDTO) {
PageData<DataSyncConfigDTO> result = new PageData<>(new ArrayList<>(), NumConstant.ZERO_L);
PageInfo<DataSyncConfigDTO> pageInfo = PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize()).doSelectPageInfo(() -> baseDao.list(tokenDto.getCustomerId()));
PageInfo<DataSyncConfigDTO> pageInfo = PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize())
.doSelectPageInfo(() -> baseDao.list(tokenDto.getCustomerId(), null));
if (CollectionUtils.isNotEmpty(pageInfo.getList())){
result.setList(pageInfo.getList());
result.setTotal(Integer.valueOf(String.valueOf(pageInfo.getTotal())));
result.setTotal(Integer.parseInt(String.valueOf(pageInfo.getTotal())));
}
return result;
}
@ -171,40 +176,78 @@ public class DataSyncConfigServiceImpl extends BaseServiceImpl<DataSyncConfigDao
* @date 2022/9/26 17:16
*/
@Override
public void natInfoScanTask(NatInfoScanTaskFormDTO formDTO) {
if (CollectionUtils.isNotEmpty(formDTO.getIdCards())){
List<NatUserInfoResultDTO> userIdByIdCard = baseDao.getUserIdByIdCard(formDTO.getIdCards());
List<NatUserInfoResultDTO> collect = formDTO.getIdCards().stream().map(id -> {
NatUserInfoResultDTO e = new NatUserInfoResultDTO();
e.setIdCard(id);
e.setUserId("");
return e;
}).collect(Collectors.toList());
collect.forEach(c -> userIdByIdCard.stream().filter(u -> u.getIdCard().equals(c.getIdCard())).forEach(u -> c.setUserId(u.getUserId())));
hsjc(collect,formDTO.getCustomerId());
public void dataSyncForYanTaiTask(NatInfoScanTaskFormDTO formDTO) {
List<DataSyncConfigDTO> allConfigList = baseDao.list(formDTO.getCustomerId() ,"open");
if (CollectionUtils.isEmpty(allConfigList)){
return;
}
List<DataSyncConfigDTO> allConfigList = baseDao.list(StringUtils.isNotBlank(formDTO.getCustomerId()) ? formDTO.getCustomerId() : null);
if (CollectionUtils.isEmpty(allConfigList)){
//TODO 根据dataCode 调用不同的方法 抽取数据
if (CollectionUtils.isNotEmpty(allConfigList)){
log.warn("dataSyncForYanTaiTask don't have any resi data to pull data form YanTai interface");
return;
}
List<DataSyncConfigDTO> configList = allConfigList.stream().filter(l -> l.getDeptCode().equals("dsjj") && l.getSwitchStatus().equals("open")).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(configList)){
configList.forEach(c -> {
if (CollectionUtils.isNotEmpty(c.getScopeList())){
Integer no = NumConstant.ONE;
Integer size;
do {
PageInfo<NatUserInfoResultDTO> pageInfo = PageHelper.startPage(no, NumConstant.ONE_THOUSAND).doSelectPageInfo(() -> baseDao.getIdCardsByScope(c.getScopeList()));
size = pageInfo.getList().size();
hsjc(pageInfo.getList(),c.getCustomerId());
no++;
}while (size.compareTo(NumConstant.ONE_THOUSAND) == NumConstant.ZERO);
}
});
for (DataSyncConfigDTO config : allConfigList) {
//没有配置 数据拉取范围 继续下次循环
if (CollectionUtils.isEmpty(config.getScopeList())){
continue;
}
//如果传了身份证号 则按照身份证号查询 并同步记录, userId如果为空则是 手动录入的 此人没有录入居民库 但是也可以同步
if (CollectionUtils.isNotEmpty(formDTO.getIdCards())){
List<NatUserInfoResultDTO> userIdByIdCard = baseDao.getIdCardsByScope(config.getScopeList(),formDTO.getIdCards());
List<NatUserInfoResultDTO> collect = formDTO.getIdCards().stream().map(id -> {
NatUserInfoResultDTO e = new NatUserInfoResultDTO();
e.setIdCard(id);
e.setUserId("");
return e;
}).collect(Collectors.toList());
collect.forEach(c -> userIdByIdCard.stream().filter(u -> u.getIdCard().equals(c.getIdCard())).forEach(u -> c.setUserId(u.getUserId())));
executeSyncData(config, collect);
return;
} else {
//没传具体参数 则 按照
int pageNo = NumConstant.ONE;
int pageSize = NumConstant.ONE_THOUSAND;
PageInfo<NatUserInfoResultDTO> pageInfo = null;
do {
//根据 组织 分页获取 居民数据
pageInfo = PageHelper.startPage(pageNo, pageSize, false)
.doSelectPageInfo(() -> baseDao.getIdCardsByScope(config.getScopeList(),formDTO.getIdCards()));
executeSyncData(config, pageInfo.getList());
pageNo++;
} while (pageInfo != null && pageInfo.getSize() == pageSize);
}
}
}
/**
* desc根据居民身份证号 从蓝图api接口 获取数据到本地
* @param config
* @param resiList
*/
private void executeSyncData(DataSyncConfigDTO config, List<NatUserInfoResultDTO> resiList) {
DataSyncEnum anEnum = DataSyncEnum.getEnum(config.getDataCode());
switch (anEnum) {
case HE_SUAN:
hsjc(resiList, config.getCustomerId());
break;
case CAN_JI:
//todo
break;
case SI_WANG:
//todo
break;
default:
log.warn("没有要处理的数据");
}
}
/**
* Desc: 根据证件号 查询nat 存在 ? 不处理 : 新增
* @param idCards
@ -269,4 +312,4 @@ public class DataSyncConfigServiceImpl extends BaseServiceImpl<DataSyncConfigDao
}
}
}
}
}

36
epmet-user/epmet-user-server/src/main/resources/mapper/DataSyncConfigDao.xml

@ -41,9 +41,12 @@
customer_id as customerId
FROM data_sync_config
WHERE DEL_FLAG = 0
<if test='null != customerId and customerId != "" '>
AND CUSTOMER_ID = #{customerId}
</if>
<if test="switchStatus != null and switchStatus != ''">
AND switch_status = #{switchStatus}
</if>
<if test='null != customerId and customerId != "" '>
AND CUSTOMER_ID = #{customerId}
</if>
order by sort
</select>
@ -62,29 +65,20 @@
FROM ic_resi_user
WHERE DEL_FLAG = '0'
AND `STATUS` = '0'
<if test="idCardList != null and idCardList.size() != 0">
AND id_card in
<foreach collection="idCardList" item="idCard" separator="," close=")" open="(" >
#{idCard}
</foreach>
</if>
AND (
<foreach collection="list" item="l" separator="OR">
<foreach collection="orgList" item="l" separator="OR">
<choose>
<when test='"grid" == l.orgType'>GRID_ID = #{l.orgId}</when>
<otherwise>PIDS LIKE CONCAT('%',#{l.orgId},'%')</otherwise>
<otherwise>PIDS LIKE CONCAT(#{l.orgIdPath},'%')</otherwise>
</choose>
</foreach>
)
ORDER BY CREATED_TIME
</select>
<select id="getUserIdByIdCard" resultType="com.epmet.dto.result.NatUserInfoResultDTO">
SELECT
DISTINCT ID_CARD AS idCard,
ID AS userId,
AGENCY_ID AS agencyId,
pids
FROM ic_resi_user
WHERE DEL_FLAG = '0'
AND `STATUS` = '0'
AND id_card in (
<foreach collection="list" item="l" separator=",">
#{l}
</foreach>
)
</select>
</mapper>
</mapper>

Loading…
Cancel
Save