diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/org/result/CustomerAgencyDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/org/result/CustomerAgencyDTO.java index 658a3e9c2d..e281c7400e 100644 --- a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/org/result/CustomerAgencyDTO.java +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/org/result/CustomerAgencyDTO.java @@ -147,4 +147,14 @@ public class CustomerAgencyDTO implements Serializable { * 社区 */ private String community; + + /** + * 中心位置经度 + */ + private String longitude; + + /** + * 中心位置纬度 + */ + private String latitude; } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/DataStatisticalOpenFeignClient.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/DataStatisticalOpenFeignClient.java index 67f56957dc..1c865240ea 100644 --- a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/DataStatisticalOpenFeignClient.java +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/DataStatisticalOpenFeignClient.java @@ -36,8 +36,8 @@ import java.util.List; * @author: jianjun liu */ //url="http://localhost:8108" -//@FeignClient(name = ServiceConstant.DATA_STATISTICAL_SERVER, fallback = DataStatisticalOpenFeignClientFallBack.class, url = "http://localhost:6666") -@FeignClient(name = ServiceConstant.DATA_STATISTICAL_SERVER, fallbackFactory = DataStatisticalOpenFeignClientFallBackFactory.class) +@FeignClient(name = ServiceConstant.DATA_STATISTICAL_SERVER, fallbackFactory = DataStatisticalOpenFeignClientFallBackFactory.class, url = "http://localhost:8108") +// @FeignClient(name = ServiceConstant.DATA_STATISTICAL_SERVER, fallbackFactory = DataStatisticalOpenFeignClientFallBackFactory.class) public interface DataStatisticalOpenFeignClient { /** diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml index 7ab6ca322c..8622167974 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml @@ -160,6 +160,8 @@ customer_grid WHERE del_flag = '0' AND customer_id = #{customerId} + and CODE is not null + and CODE !='' #{gridId} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml index fa5da30046..105a4efcc7 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml @@ -216,6 +216,8 @@ customer_agency WHERE del_flag = '0' AND customer_id = #{customerId} + and CODE is not null + and CODE !='' #{agencyId} diff --git a/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/ExractGridInfoPingYinFormDTO.java b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/ExractGridInfoPingYinFormDTO.java new file mode 100644 index 0000000000..d57c25a387 --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/ExractGridInfoPingYinFormDTO.java @@ -0,0 +1,38 @@ +package com.epmet.opendata.dto.form; + +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.List; + +/** + * @Description + * @Author yzm + * @Date 2022/7/22 14:02 + */ +@Data +public class ExractGridInfoPingYinFormDTO implements Serializable { + + public interface GridInfo extends CustomerClientShowGroup { + } + + /** + * 客户Id + */ + @NotBlank(message = "客户Id不能为空", groups = {GridInfo.class}) + private String customerId = ""; + + /** + * 网格Id或者组织id + */ + private List orgIdList; + + /** + * 操作类型【新增:add 修改删除:edit 初始化所有数据:all】 + */ + @NotBlank(message = "操作类型【新增:add 修改删除:edit 初始化所有数据:all】不能为空", groups = {GridInfo.class}) + private String type; +} + diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/GridInfoPingyinController.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/GridInfoPingyinController.java index 26e84cad1a..2a1ac80444 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/GridInfoPingyinController.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/GridInfoPingyinController.java @@ -1,19 +1,14 @@ package com.epmet.opendata.controller; -import com.epmet.commons.tools.aop.NoRepeatSubmit; -import com.epmet.commons.tools.page.PageData; -import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.Result; -import com.epmet.commons.tools.validator.AssertUtils; 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.opendata.dto.form.ExractGridInfoPingYinFormDTO; +import com.epmet.opendata.service.GridInfoPingyinService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletResponse; -import java.util.Map; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** @@ -26,6 +21,28 @@ import java.util.Map; @RequestMapping("gridInfoPingyin") public class GridInfoPingyinController { + @Autowired + private GridInfoPingyinService gridInfoPingyinService; + /** + * @Author yzm + * @Description 组织基础信息中间库同步 + **/ + @PostMapping("extract-agency") + public Result getAgencyBaseInfo(@RequestBody ExractGridInfoPingYinFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, ExractGridInfoPingYinFormDTO.GridInfo.class); + gridInfoPingyinService.exractAgency(formDTO); + return new Result(); + } + /** + * @Author yzm + * @Description 网格基础信息中间库同步 + **/ + @PostMapping("extract-grid") + public Result getGridBaseInfo(@RequestBody ExractGridInfoPingYinFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, ExractGridInfoPingYinFormDTO.GridInfo.class); + gridInfoPingyinService.exractGrid(formDTO); + return new Result(); + } } diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridInfoPingyinDao.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridInfoPingyinDao.java index fc6be9e1db..e070cc30ce 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridInfoPingyinDao.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridInfoPingyinDao.java @@ -3,6 +3,10 @@ package com.epmet.opendata.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.opendata.entity.GridInfoPingyinEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.math.BigDecimal; +import java.util.List; /** * 平阴区网格表 @@ -12,5 +16,16 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface GridInfoPingyinDao extends BaseDao { - + + int deleteAllAgencyData(); + + int deleteAllGridData(); + + List selectByGridCode(String gridCode); + + int updateSomeCol(@Param("id") Long id, + @Param("gridName")String gridName, + @Param("gridLevel")Integer gridLevel, + @Param("lng")BigDecimal lng, + @Param("lat")BigDecimal lat); } \ No newline at end of file diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataOrgChangeEventListener.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataOrgChangeEventListener.java index 928489f8b0..02fc563a78 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataOrgChangeEventListener.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataOrgChangeEventListener.java @@ -10,8 +10,8 @@ import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.SpringContextUtils; -import com.epmet.opendata.dto.form.ExDeptFormDTO; -import com.epmet.opendata.service.ExDeptService; +import com.epmet.opendata.dto.form.ExractGridInfoPingYinFormDTO; +import com.epmet.opendata.service.GridInfoPingyinService; import org.apache.commons.lang.StringUtils; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; @@ -78,17 +78,31 @@ public class OpenDataOrgChangeEventListener implements MessageListenerConcurrent lock = distributedLock.getLock(String.format("lock:open_data_org:%s", obj.getOrgId()), 30L, 30L, TimeUnit.SECONDS); - ExDeptFormDTO dto = new ExDeptFormDTO(); - dto.setCustomerId(obj.getCustomerId()); - dto.setType(obj.getType()); + // ExDeptFormDTO dto = new ExDeptFormDTO(); + // dto.setCustomerId(obj.getCustomerId()); + // dto.setType(obj.getType()); + // List orgIdList = new ArrayList<>(); + // orgIdList.add(obj.getOrgId()); + // dto.setOrgIdList(orgIdList); + // if ("agency".equals(obj.getOrgType())) { + // SpringContextUtils.getBean(ExDeptService.class).getAgencyBaseInfo(dto); + // } else { + // SpringContextUtils.getBean(ExDeptService.class).getGridBaseInfo(dto); + // } + + // 抽取到grid_info_pingyin + ExractGridInfoPingYinFormDTO extractFormDto = new ExractGridInfoPingYinFormDTO(); + extractFormDto.setCustomerId(obj.getCustomerId()); + extractFormDto.setType(obj.getType()); List orgIdList = new ArrayList<>(); orgIdList.add(obj.getOrgId()); - dto.setOrgIdList(orgIdList); + extractFormDto.setOrgIdList(orgIdList); if ("agency".equals(obj.getOrgType())) { - SpringContextUtils.getBean(ExDeptService.class).getAgencyBaseInfo(dto); + SpringContextUtils.getBean(GridInfoPingyinService.class).exractAgency(extractFormDto); } else { - SpringContextUtils.getBean(ExDeptService.class).getGridBaseInfo(dto); + SpringContextUtils.getBean(GridInfoPingyinService.class).exractGrid(extractFormDto); } + } catch (RenException e) { // 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试 logger.error("【开放数据事件监听器】-组织信息变更-同步信息到中间库失败:".concat(ExceptionUtils.getErrorStackTrace(e))); diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GridInfoPingyinService.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GridInfoPingyinService.java index 096739ee37..3feaabc3eb 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GridInfoPingyinService.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GridInfoPingyinService.java @@ -1,10 +1,9 @@ package com.epmet.opendata.service; import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.opendata.dto.form.ExractGridInfoPingYinFormDTO; import com.epmet.opendata.entity.GridInfoPingyinEntity; -import java.util.Map; - /** * 平阴区网格表 * @@ -12,5 +11,17 @@ import java.util.Map; * @since v1.0.0 2022-07-22 */ public interface GridInfoPingyinService extends BaseService { + /** + * 抽取customer_agency到grid_info_pingyin表 + * + * @param formDTO + */ + void exractAgency(ExractGridInfoPingYinFormDTO formDTO); + /** + * 抽取customer_grid到grid_info_pingyin表 + * + * @param formDTO + */ + void exractGrid(ExractGridInfoPingYinFormDTO 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/GridInfoPingyinServiceImpl.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridInfoPingyinServiceImpl.java index 2e0574706a..d9e505adef 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridInfoPingyinServiceImpl.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridInfoPingyinServiceImpl.java @@ -1,11 +1,27 @@ package com.epmet.opendata.service.impl; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.constant.IndexCalConstant; +import com.epmet.dto.org.result.CustomerAgencyDTO; +import com.epmet.dto.org.result.CustomerGridDTO; +import com.epmet.feign.DataStatisticalOpenFeignClient; import com.epmet.opendata.dao.GridInfoPingyinDao; +import com.epmet.opendata.dto.form.ExractGridInfoPingYinFormDTO; import com.epmet.opendata.entity.GridInfoPingyinEntity; import com.epmet.opendata.service.GridInfoPingyinService; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.ListUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + /** * 平阴区网格表 @@ -15,5 +31,153 @@ import org.springframework.stereotype.Service; */ @Service public class GridInfoPingyinServiceImpl extends BaseServiceImpl implements GridInfoPingyinService { + @Autowired + private DataStatisticalOpenFeignClient dataStatisticalOpenFeignClient; + + + /** + * 抽取customer_agency到grid_info_pingyin表 + * + * @param formDTO + */ + @Override + public void exractAgency(ExractGridInfoPingYinFormDTO formDTO) { + // 1.查询组织基础信息,customer_agency.code为空的不抽取 + com.epmet.dto.org.form.GridBaseInfoFormDTO formDTO1 = ConvertUtils.sourceToTarget(formDTO, com.epmet.dto.org.form.GridBaseInfoFormDTO.class); + Result> result = dataStatisticalOpenFeignClient.getAgencyBaseInfo(formDTO1); + if (!result.success()) { + throw new RenException(result.getInternalMsg()); + } + if (null == result.getData() || result.getData().size() < NumConstant.ONE) { + return; + } + // 2.封装数据 + List gridInfoList = new ArrayList<>(); + result.getData().forEach(ag -> { + GridInfoPingyinEntity entity = new GridInfoPingyinEntity(); + entity.setQxBm("370124"); + entity.setQxMc("平阴县"); + entity.setGridCode(ag.getCode()); + entity.setGridName(ag.getOrganizationName()); + if ("district".equals(ag.getLevel())) { + entity.setGridLevel(3); + } else if ("street".equals(ag.getLevel())) { + entity.setGridLevel(4); + } else if ("community".equals(ag.getLevel())) { + entity.setGridLevel(6); + } + entity.setLat(new BigDecimal(ag.getLatitude())); + entity.setLng(new BigDecimal(ag.getLongitude())); + gridInfoList.add(entity); + }); + // 3、初始化传all;新增或者编辑 + if ("all".equals(formDTO.getType())) { + // 全删,全增 + baseDao.deleteAllAgencyData(); + // 一次100 + List> partition = ListUtils.partition(gridInfoList, IndexCalConstant.INSERT_SIZE); + partition.forEach(list -> { + this.insertBatch(list); + }); + + } else if ("add".equals(formDTO.getType())) { + // 单独新增组织 + this.insertBatch(gridInfoList); + + } else if ("edit".equals(formDTO.getType())) { + // 修改组织时,先根据code查询,如果有数据,更新 + for (GridInfoPingyinEntity entity : gridInfoList) { + + List orginList = baseDao.selectByGridCode(entity.getGridCode()); + + if (CollectionUtils.isNotEmpty(orginList)) { + + // 更新网格名称、网格层级、网格中心点的经度,网格中心点纬度 + for (GridInfoPingyinEntity oigin : orginList) { + baseDao.updateSomeCol(oigin.getId(), entity.getGridName(), entity.getGridLevel(), entity.getLng(), entity.getLat()); + } + + } else { + // 插入 + baseDao.insert(entity); + } + } + } + + } + + /** + * 抽取customer_grid到grid_info_pingyin表 + * + * @param formDTO + */ + @Override + public void exractGrid(ExractGridInfoPingYinFormDTO formDTO) { + // 1.查询网格基础信息 + com.epmet.dto.org.form.GridBaseInfoFormDTO formDTO1 = ConvertUtils.sourceToTarget(formDTO, com.epmet.dto.org.form.GridBaseInfoFormDTO.class); + Result> result = dataStatisticalOpenFeignClient.getGridBaseInfo(formDTO1); + if (!result.success()) { + throw new RenException(result.getInternalMsg()); + } + if (null == result.getData() || result.getData().size() < NumConstant.ONE) { + return; + } + + // 2.封装数据 + List gridInfoList = new ArrayList<>(); + result.getData().forEach(ag -> { + GridInfoPingyinEntity entity = new GridInfoPingyinEntity(); + entity.setQxBm("370124"); + entity.setQxMc("平阴县"); + entity.setGridCode(ag.getCode()); + entity.setGridName(ag.getGridName()); + entity.setGridLevel(7); + if (ag.getLatitude().length() > 10) { + entity.setLat(new BigDecimal(ag.getLatitude().substring(0, 10))); + } else { + entity.setLat(new BigDecimal(ag.getLatitude())); + } + if (ag.getLongitude().length() > 10) { + entity.setLng(new BigDecimal(ag.getLongitude().substring(0, 10))); + } else { + entity.setLng(new BigDecimal(ag.getLongitude())); + } + gridInfoList.add(entity); + }); + // 3、初始化传all;新增或者编辑 + if ("all".equals(formDTO.getType())) { + // 全删,全增 + baseDao.deleteAllGridData(); + // 一次100 + List> partition = ListUtils.partition(gridInfoList, IndexCalConstant.INSERT_SIZE); + partition.forEach(list -> { + this.insertBatch(list); + }); + } else if ("add".equals(formDTO.getType())) { + // 单独新增组织 + this.insertBatch(gridInfoList); + + } else if ("edit".equals(formDTO.getType())) { + // 修改组织时,先根据code查询,如果有数据,更新 + for (GridInfoPingyinEntity entity : gridInfoList) { + + List orginList = baseDao.selectByGridCode(entity.getGridCode()); + + if (CollectionUtils.isNotEmpty(orginList)) { + + // 更新网格名称、网格层级、网格中心点的经度,网格中心点纬度 + for (GridInfoPingyinEntity oigin : orginList) { + baseDao.updateSomeCol(oigin.getId(), entity.getGridName(), entity.getGridLevel(), entity.getLng(), entity.getLat()); + } + + } else { + // 插入 + baseDao.insert(entity); + } + } + } + + } + } \ No newline at end of file diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridInfoPingyinDao.xml b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridInfoPingyinDao.xml index 3cb20d2d76..fd75c023f0 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridInfoPingyinDao.xml +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridInfoPingyinDao.xml @@ -22,5 +22,26 @@ + + delete from grid_info_pingyin where grid_level !='7' + + + + delete from grid_info_pingyin where grid_level ='7' + + + + + + update grid_info_pingyin + set grid_name = #{gridName}, + grid_level = #{gridLevel}, + lng = #{lng}, + lat = #{lat} + where id = #{id} + \ No newline at end of file