Browse Source

组织网格数据抽取到pingyin

dev
yinzuomei 3 years ago
parent
commit
508caf19c9
  1. 10
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/org/result/CustomerAgencyDTO.java
  2. 4
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/DataStatisticalOpenFeignClient.java
  3. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerGridDao.xml
  4. 2
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/StatsCustomerAgencyDao.xml
  5. 38
      epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/ExractGridInfoPingYinFormDTO.java
  6. 39
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/GridInfoPingyinController.java
  7. 15
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridInfoPingyinDao.java
  8. 30
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataOrgChangeEventListener.java
  9. 15
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GridInfoPingyinService.java
  10. 164
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridInfoPingyinServiceImpl.java
  11. 21
      epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridInfoPingyinDao.xml

10
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;
}

4
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 {
/**

2
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 !=''
<if test="orgIdList != null and orgIdList.size() > 0">
<foreach collection="orgIdList" item="gridId" open="AND id IN (" separator="," close=")">
#{gridId}

2
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 !=''
<if test="orgIdList != null and orgIdList.size() > 0">
<foreach collection="orgIdList" item="agencyId" open="AND id IN (" separator="," close=")">
#{agencyId}

38
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<String> orgIdList;
/**
* 操作类型新增:add 修改删除:edit 初始化所有数据:all
*/
@NotBlank(message = "操作类型【新增:add 修改删除:edit 初始化所有数据:all】不能为空", groups = {GridInfo.class})
private String type;
}

39
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();
}
}

15
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;
/**
* 平阴区网格表
@ -13,4 +17,15 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface GridInfoPingyinDao extends BaseDao<GridInfoPingyinEntity> {
int deleteAllAgencyData();
int deleteAllGridData();
List<GridInfoPingyinEntity> 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);
}

30
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<String> 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<String> 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)));

15
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<GridInfoPingyinEntity> {
/**
* 抽取customer_agency到grid_info_pingyin表
*
* @param formDTO
*/
void exractAgency(ExractGridInfoPingYinFormDTO formDTO);
/**
* 抽取customer_grid到grid_info_pingyin表
*
* @param formDTO
*/
void exractGrid(ExractGridInfoPingYinFormDTO formDTO);
}

164
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<GridInfoPingyinDao, GridInfoPingyinEntity> 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<List<CustomerAgencyDTO>> result = dataStatisticalOpenFeignClient.getAgencyBaseInfo(formDTO1);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
if (null == result.getData() || result.getData().size() < NumConstant.ONE) {
return;
}
// 2.封装数据
List<GridInfoPingyinEntity> 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<List<GridInfoPingyinEntity>> 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<GridInfoPingyinEntity> 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<List<CustomerGridDTO>> result = dataStatisticalOpenFeignClient.getGridBaseInfo(formDTO1);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
if (null == result.getData() || result.getData().size() < NumConstant.ONE) {
return;
}
// 2.封装数据
List<GridInfoPingyinEntity> 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<List<GridInfoPingyinEntity>> 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<GridInfoPingyinEntity> 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);
}
}
}
}
}

21
epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridInfoPingyinDao.xml

@ -22,5 +22,26 @@
<result property="recoredInsertTime" column="recored_insert_time"/>
</resultMap>
<delete id="deleteAllAgencyData">
delete from grid_info_pingyin where grid_level !='7'
</delete>
<delete id="deleteAllGridData">
delete from grid_info_pingyin where grid_level ='7'
</delete>
<select id="selectByGridCode" parameterType="java.lang.String" resultType="com.epmet.opendata.entity.GridInfoPingyinEntity">
select g.* from grid_info_pingyin g
where g.grid_code = #{gridCode}
</select>
<update id="updateSomeCol" parameterType="map">
update grid_info_pingyin
set grid_name = #{gridName},
grid_level = #{gridLevel},
lng = #{lng},
lat = #{lat}
where id = #{id}
</update>
</mapper>
Loading…
Cancel
Save