|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |