| | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import liquibase.repackaged.org.apache.commons.lang3.StringUtils; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | import org.springblade.modules.police.service.IPoliceAffairsGridService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @DS("slave_1") |
| | | public boolean SynchronizeData(EcOrderParamDTO ecOrderParamDTO) { |
| | | processPages(100, ecOrderParamDTO); |
| | | return true; |
| | |
| | | |
| | | public void processPages(int pageSize, EcOrderParamDTO ecOrderParamDTO) { |
| | | QueryWrapper<EcOrder> ecOrderQueryWrapper = new QueryWrapper<>(); |
| | | ecOrderQueryWrapper.between("import_time", ecOrderParamDTO.getStartTime(), ecOrderParamDTO.getEndTime()); |
| | | if (StringUtils.isNotBlank(ecOrderParamDTO.getStartTime()) && StringUtils.isNotEmpty(ecOrderParamDTO.getEndTime())) { |
| | | ecOrderQueryWrapper.between("import_time", ecOrderParamDTO.getStartTime(), ecOrderParamDTO.getEndTime()); |
| | | } |
| | | // System.out.println("**********参数**************************" + JSON.toJSONString(ecOrderParamDTO)); |
| | | long count = count(ecOrderQueryWrapper); |
| | | System.out.println("**********总数**************************" + count); |
| | | int totalPages = (int) Math.ceil((double) count / pageSize); // 计算总页数 |
| | | |
| | | for (int pageNum = 1; pageNum <= totalPages; pageNum++) { |
| | | Page<EcOrder> page = new Page<>(pageNum, pageSize); |
| | | QueryWrapper<EcOrder> objectQueryWrapper = new QueryWrapper<>(); |
| | | IPage<EcOrder> resultPage = page(page, objectQueryWrapper); |
| | | IPage<EcOrder> resultPage = baseMapper.selectPage(page, ecOrderQueryWrapper); |
| | | List<EcOrder> records = resultPage.getRecords(); |
| | | List<ECallEventTwoEntity> recordEntityList = BeanUtil.copy(records, ECallEventTwoEntity.class); |
| | | recordEntityList.forEach(ecOrderEntity -> { |
| | | // 点落面 设置警格网格信息 |
| | | setGridInfo(ecOrderEntity); |
| | | List<ECallEventTwoEntity> addList = new ArrayList<>(); |
| | | List<ECallEventTwoEntity> updateList = new ArrayList<>(); |
| | | // 过滤出已同步的订单 |
| | | recordEntityList.forEach(record -> { |
| | | long count1 = ecOrderService.count(Wrappers.<ECallEventTwoEntity>lambdaQuery().eq(ECallEventTwoEntity::getOrderCode, record.getOrderCode())); |
| | | if (count1 == 0) { |
| | | setGridInfo(record); |
| | | addList.add(record); |
| | | } else { |
| | | updateList.add(record); |
| | | } |
| | | }); |
| | | boolean b = ecOrderService.saveBatch(recordEntityList); |
| | | // 同步订单 |
| | | boolean b = false; |
| | | if (addList.size() > 0) { |
| | | b = ecOrderService.saveBatch(addList); |
| | | } |
| | | if (updateList.size() > 0) { |
| | | b = ecOrderService.saveOrUpdateBatch(updateList); |
| | | } |
| | | System.out.println("更新第" + pageNum + "页" + b); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @DS("master") |
| | | public boolean saveEcOrder(List<ECallEventTwoEntity> recordEntityList) { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置警格网格信息 |
| | |
| | | * @param ecOrderEntity |
| | | */ |
| | | public void setGridInfo(ECallEventTwoEntity ecOrderEntity) { |
| | | if (ecOrderEntity.getSceneGeoLng() == null || ecOrderEntity.getSceneGeoLat() == null) { |
| | | return; |
| | | } |
| | | // 根据位置设置网格,警格编号 |
| | | IGridService gridService = SpringUtils.getBean(IGridService.class); |
| | | IPoliceAffairsGridService policeAffairsGridService = SpringUtils.getBean(IPoliceAffairsGridService.class); |
| | | String point = "'POINT(" + ecOrderEntity.getSceneGeoLng().toString() + " " + ecOrderEntity.getSceneGeoLat().toString() + ")'"; |
| | | // 点坐标解析网格 |
| | | List<GridEntity> gridEntityList = gridService.spatialAnalysis(point); |
| | | if (gridEntityList.size() > 0) { |
| | | GridEntity gridEntity = gridEntityList.get(0); |
| | | ecOrderEntity.setGridCode(gridEntity.getGridCode()); |
| | | } |
| | | // 点坐标解析警格 |
| | | List<PoliceAffairsGridEntity> policeAffairsGridEntityList = policeAffairsGridService.spatialAnalysis(point); |
| | | if (policeAffairsGridEntityList.size() > 0) { |
| | | PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridEntityList.get(0); |
| | | ecOrderEntity.setJwGridCode(policeAffairsGridEntity.getJwGridCode()); |
| | | try { |
| | | if (ecOrderEntity.getSceneGeoLng() == null || ecOrderEntity.getSceneGeoLat() == null) { |
| | | return; |
| | | } |
| | | // 根据位置设置网格,警格编号 |
| | | IGridService gridService = SpringUtils.getBean(IGridService.class); |
| | | IPoliceAffairsGridService policeAffairsGridService = SpringUtils.getBean(IPoliceAffairsGridService.class); |
| | | String point = "'POINT(" + ecOrderEntity.getSceneGeoLng().toString() + " " + ecOrderEntity.getSceneGeoLat().toString() + ")'"; |
| | | // 点坐标解析网格 |
| | | List<GridEntity> gridEntityList = gridService.spatialAnalysis(point); |
| | | if (gridEntityList.size() > 0) { |
| | | GridEntity gridEntity = gridEntityList.get(0); |
| | | ecOrderEntity.setGridCode(gridEntity.getGridCode()); |
| | | } |
| | | // 点坐标解析警格 |
| | | List<PoliceAffairsGridEntity> policeAffairsGridEntityList = policeAffairsGridService.spatialAnalysis(point); |
| | | if (policeAffairsGridEntityList.size() > 0) { |
| | | PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridEntityList.get(0); |
| | | ecOrderEntity.setJwGridCode(policeAffairsGridEntity.getJwGridCode()); |
| | | } |
| | | } catch (Exception e) { |
| | | System.out.println("获取警格网格信息失败" + e); |
| | | } |
| | | } |
| | | |