diff --git a/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/GridStaffInfoFormDTO.java b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/GridStaffInfoFormDTO.java new file mode 100644 index 0000000000..399e11a7ee --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/GridStaffInfoFormDTO.java @@ -0,0 +1,17 @@ +package com.epmet.opendata.dto.form; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class GridStaffInfoFormDTO implements Serializable { + + private static final long serialVersionUID = -5277855973512833181L; + + /** + * 客户Id + */ + private String customerId; + +} diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/GridstaffInfoPingyinController.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/GridstaffInfoPingyinController.java index 9fb4b2a2a2..fa6bf83195 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/GridstaffInfoPingyinController.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/GridstaffInfoPingyinController.java @@ -8,10 +8,15 @@ import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.AddGroup; import com.epmet.commons.tools.validator.group.UpdateGroup; import com.epmet.commons.tools.validator.group.DefaultGroup; +import com.epmet.dto.form.CustomerGridStaffListFormDTO; +import com.epmet.dto.result.CustomerGridStaffListResultDTO; +import com.epmet.opendata.dto.form.GridStaffInfoFormDTO; +import com.epmet.opendata.service.GridstaffInfoPingyinService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import java.util.List; import java.util.Map; @@ -25,6 +30,18 @@ import java.util.Map; @RequestMapping("gridstaffInfoPingyin") public class GridstaffInfoPingyinController { + @Autowired + private GridstaffInfoPingyinService gridstaffInfoPingyinService; + /** + * @Author sun + * @Description 网格员基本信息同步 + **/ + @PostMapping(value = "gridstaffinfo") + public Result gridStaffInfo(@RequestBody GridStaffInfoFormDTO formDTO) { + gridstaffInfoPingyinService.gridStaffInfo(formDTO); + return new Result(); + } + } diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridstaffInfoPingyinDao.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridstaffInfoPingyinDao.java index 05b862b40f..d607093a12 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridstaffInfoPingyinDao.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridstaffInfoPingyinDao.java @@ -12,5 +12,6 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface GridstaffInfoPingyinDao extends BaseDao { - + + void del(); } \ No newline at end of file diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GridstaffInfoPingyinService.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GridstaffInfoPingyinService.java index ccf0cbc681..fc0ae09ed3 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GridstaffInfoPingyinService.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GridstaffInfoPingyinService.java @@ -1,6 +1,7 @@ package com.epmet.opendata.service; import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.opendata.dto.form.GridStaffInfoFormDTO; import com.epmet.opendata.entity.GridstaffInfoPingyinEntity; import java.util.Map; @@ -13,4 +14,5 @@ import java.util.Map; */ public interface GridstaffInfoPingyinService extends BaseService { + void gridStaffInfo(GridStaffInfoFormDTO formDTO); } \ No newline at end of file diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridstaffInfoPingyinServiceImpl.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridstaffInfoPingyinServiceImpl.java index 6bd94f326d..f8d7b78a79 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridstaffInfoPingyinServiceImpl.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridstaffInfoPingyinServiceImpl.java @@ -1,10 +1,29 @@ package com.epmet.opendata.service.impl; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.form.CustomerGridStaffListFormDTO; +import com.epmet.dto.form.GridStaffUploadtFormDTO; +import com.epmet.dto.result.CustomerGridStaffListResultDTO; +import com.epmet.dto.result.GridStaffUploadResultDTO; +import com.epmet.feign.EpmetUserOpenFeignClient; +import com.epmet.feign.GovOrgOpenFeignClient; import com.epmet.opendata.dao.GridstaffInfoPingyinDao; +import com.epmet.opendata.dto.form.GridStaffInfoFormDTO; import com.epmet.opendata.entity.GridstaffInfoPingyinEntity; import com.epmet.opendata.service.GridstaffInfoPingyinService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * 平阴区网格员基础信息 @@ -13,6 +32,60 @@ import org.springframework.stereotype.Service; * @since v1.0.0 2022-07-22 */ @Service +@Slf4j public class GridstaffInfoPingyinServiceImpl extends BaseServiceImpl implements GridstaffInfoPingyinService { + @Autowired + private GovOrgOpenFeignClient govOrgOpenFeignClient; + @Autowired + private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + + + @Override + @Transactional(rollbackFor = Exception.class) + public void gridStaffInfo(GridStaffInfoFormDTO formDTO) { + //1.查询客户网格下工作人员 + CustomerGridStaffListFormDTO org = new CustomerGridStaffListFormDTO(); + org.setCustomerId(formDTO.getCustomerId()); + Result> orgList = govOrgOpenFeignClient.gridStaff(org); + if (!orgList.success()) { + throw new RenException("查询客户网格下工作人员列表信息失败:".concat(orgList.toString())); + } + log.info(String.format("网格员数据同步,查询到网格下工作人员记录共%s条", orgList.getData().size())); + + //2.查询客户工作人员基础信息 + GridStaffUploadtFormDTO user = new GridStaffUploadtFormDTO(); + user.setCustomerId(formDTO.getCustomerId()); + Result> userList = epmetUserOpenFeignClient.customerStaff(user); + if (!userList.success()) { + throw new RenException("查询客户下工作人员基础信息失败:".concat(userList.toString())); + } + log.info(String.format("网格员数据同步,查询到客户下工作人员基础信息记录共%s条", userList.getData().size())); + Map map = userList.getData().stream().collect(Collectors.toMap(GridStaffUploadResultDTO::getGridUserId, m -> m, (k1, k2) -> k1)); + + //3.拼装数据 + List entityList = new ArrayList(); + if (!CollectionUtils.isEmpty(orgList.getData()) && !CollectionUtils.isEmpty(userList.getData())) { + for (CustomerGridStaffListResultDTO gs : orgList.getData()) { + if (map.containsKey(gs.getGridUserId())) { + GridstaffInfoPingyinEntity entity = ConvertUtils.sourceToTarget(map.get(gs.getGridUserId()), GridstaffInfoPingyinEntity.class); + entity.setQxBm("370124"); + entity.setQxMc("平阴县"); + entity.setGridCode(gs.getGridCode()); + entity.setGridName(gs.getGridName()); + entityList.add(entity); + } + } + } + + //4.删除表中历史数据 + baseDao.del(); + + //5.批量新增数据 + log.info(String.format("网格员数据同步,本次共同步%s条记录", entityList.size())); + insertBatch(entityList); + + } + + } \ No newline at end of file diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridstaffInfoPingyinDao.xml b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridstaffInfoPingyinDao.xml index c42fd9482b..50b086ad03 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridstaffInfoPingyinDao.xml +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridstaffInfoPingyinDao.xml @@ -3,35 +3,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + delete from gridstaff_info_pingyin + \ No newline at end of file