From b1c790affad5f6d185d4798a229d4ec74a298845 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Fri, 22 Jul 2022 16:20:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=8B=E8=A1=8C=E5=B7=A5=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/form/HistoryDataSyncFormDTO.java | 18 ++ .../dto/form/UpsertPatrolRecordForm.java | 3 +- .../BaseGridDailyworkController.java | 25 +++ .../opendata/dao/BaseGridDailyworkDao.java | 11 ++ .../dao/GridstaffWorkInfoPingyinDao.java | 4 +- .../entity/BaseGridDailyworkEntity.java | 19 +++ .../GridstaffWorkInfoPingyinEntity.java | 9 +- .../OpenDataPatrolChangeEventListener.java | 3 +- .../service/BaseGridDailyworkService.java | 17 ++ .../GridstaffWorkInfoPingyinService.java | 4 +- .../impl/BaseGridDailyworkServiceImpl.java | 155 +++++++++++++++--- .../GridstaffWorkInfoPingyinServiceImpl.java | 6 + .../resources/mapper/BaseGridDailyworkDao.xml | 43 ++--- .../mapper/GridstaffWorkInfoPingyinDao.xml | 3 + 14 files changed, 263 insertions(+), 57 deletions(-) create mode 100644 epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/HistoryDataSyncFormDTO.java diff --git a/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/HistoryDataSyncFormDTO.java b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/HistoryDataSyncFormDTO.java new file mode 100644 index 0000000000..18b6bd212f --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/HistoryDataSyncFormDTO.java @@ -0,0 +1,18 @@ +package com.epmet.opendata.dto.form; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @DateTime 2022/7/22 13:23 + * @DESC + */ +@Data +public class HistoryDataSyncFormDTO implements Serializable { + + private static final long serialVersionUID = -58891187838165930L; + + private String customerId; +} diff --git a/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java index 3e1b0b4dd1..2566ed3af0 100644 --- a/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java +++ b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java @@ -22,8 +22,9 @@ public class UpsertPatrolRecordForm extends PageFormDTO { /** * 记录id + * 2022-07-22 注释校验的原因是兼容初始化,当不传id时,查询全部 */ - @NotEmpty(message = "id不能为空",groups = AddGroup.class) +// @NotEmpty(message = "id不能为空",groups = AddGroup.class) private String id; /** diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/BaseGridDailyworkController.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/BaseGridDailyworkController.java index 1efda7b0b3..a57bd5c201 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/BaseGridDailyworkController.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/BaseGridDailyworkController.java @@ -21,6 +21,7 @@ package com.epmet.opendata.controller; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.DefaultGroup; +import com.epmet.opendata.dto.form.HistoryDataSyncFormDTO; import com.epmet.opendata.dto.form.UpsertPatrolRecordForm; import com.epmet.opendata.service.BaseGridDailyworkService; import org.springframework.beans.factory.annotation.Autowired; @@ -54,5 +55,29 @@ public class BaseGridDailyworkController { return new Result(); } + /** + * Desc: 2022-07-22 新表 例行工作同步 + * @param formDTO + * @author zxc + * @date 2022/7/22 11:16 + */ + @PostMapping("syncV2") + public Result getStaffBaseInfoV2(@RequestBody(required = false) UpsertPatrolRecordForm formDTO) { + ValidatorUtils.validateEntity(formDTO, DefaultGroup.class); + baseGridDailyworkService.insertBaseGridWorkRecordV2(formDTO); + return new Result(); + } + + /** + * Desc: 历史数据处理 + * @param formDTO + * @author zxc + * @date 2022/7/22 13:24 + */ + @PostMapping("historyDataSync") + public Result historyDataSync(@RequestBody HistoryDataSyncFormDTO formDTO){ + baseGridDailyworkService.historyDataSync(formDTO); + return new Result(); + } } diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/BaseGridDailyworkDao.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/BaseGridDailyworkDao.java index f20f9612e7..936617ff7a 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/BaseGridDailyworkDao.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/BaseGridDailyworkDao.java @@ -21,6 +21,9 @@ package com.epmet.opendata.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.opendata.entity.BaseGridDailyworkEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 巡查例行工作 @@ -31,4 +34,12 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface BaseGridDailyworkDao extends BaseDao { + /** + * Desc: 每次查询1000 + * @param customerId + * @author zxc + * @date 2022/7/22 13:26 + */ + List getBaseGridDailyWork(@Param("customerId")String customerId,@Param("size")Integer size); + } diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridstaffWorkInfoPingyinDao.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridstaffWorkInfoPingyinDao.java index d515ae9fd6..997cbf7c8e 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridstaffWorkInfoPingyinDao.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GridstaffWorkInfoPingyinDao.java @@ -12,5 +12,7 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface GridstaffWorkInfoPingyinDao extends BaseDao { - + + Integer delAllGridStaffWorkInfoPY(); + } \ No newline at end of file diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/BaseGridDailyworkEntity.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/BaseGridDailyworkEntity.java index 5be0280fc9..76150c399d 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/BaseGridDailyworkEntity.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/BaseGridDailyworkEntity.java @@ -17,6 +17,7 @@ package com.epmet.opendata.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -152,4 +153,22 @@ public class BaseGridDailyworkEntity implements Serializable { */ private Date updateTime; + @TableField(exist = false) + private String qxBm; + + /** + * 上报区县名称 + */ + @TableField(exist = false) + private String qxMc; + + @TableField(exist = false) + private String workType; + + @TableField(exist = false) + private String happenTimeString; + + @TableField(exist = false) + private Date recoredInsertTime; + } diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/GridstaffWorkInfoPingyinEntity.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/GridstaffWorkInfoPingyinEntity.java index 4583256c90..acc8721b10 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/GridstaffWorkInfoPingyinEntity.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/GridstaffWorkInfoPingyinEntity.java @@ -1,8 +1,7 @@ package com.epmet.opendata.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; - -import com.epmet.commons.mybatis.entity.BaseEpmetEntity; import lombok.Data; import lombok.EqualsAndHashCode; @@ -46,6 +45,9 @@ public class GridstaffWorkInfoPingyinEntity { */ private String gridName; + @TableField(exist = false) + private String gridId; + /** * 例行工作类型,应符合10.27中的例行工作类型 */ @@ -86,4 +88,7 @@ public class GridstaffWorkInfoPingyinEntity { */ private Date recoredInsertTime; + @TableField(exist = false) + private String happenTimeString; + } diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataPatrolChangeEventListener.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataPatrolChangeEventListener.java index d168875abb..e5e7a1f577 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataPatrolChangeEventListener.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataPatrolChangeEventListener.java @@ -98,7 +98,8 @@ public class OpenDataPatrolChangeEventListener implements MessageListenerConcurr aBoolean = true; break; case SystemMessageType.PATROL_ROUTINE_WORK_ADD: - aBoolean = SpringContextUtils.getBean(BaseGridDailyworkService.class).insertBaseGridWorkRecord(patrolRecordForm); +// aBoolean = SpringContextUtils.getBean(BaseGridDailyworkService.class).insertBaseGridWorkRecord(patrolRecordForm); + aBoolean = SpringContextUtils.getBean(BaseGridDailyworkService.class).insertBaseGridWorkRecordV2(patrolRecordForm); break; default: log.error("错误的消息类型:{}", tags); diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/BaseGridDailyworkService.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/BaseGridDailyworkService.java index 010b698d63..6fccfe29e7 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/BaseGridDailyworkService.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/BaseGridDailyworkService.java @@ -18,6 +18,7 @@ package com.epmet.opendata.service; import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.opendata.dto.form.HistoryDataSyncFormDTO; import com.epmet.opendata.dto.form.UpsertPatrolRecordForm; import com.epmet.opendata.entity.BaseGridDailyworkEntity; @@ -36,6 +37,14 @@ public interface BaseGridDailyworkService extends BaseService { + Integer delAllGridStaffWorkInfoPY(); + } \ 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/BaseGridDailyworkServiceImpl.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/BaseGridDailyworkServiceImpl.java index b8232b5ca1..6c2e15dbe2 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/BaseGridDailyworkServiceImpl.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/BaseGridDailyworkServiceImpl.java @@ -1,20 +1,3 @@ -/** - * Copyright 2018 人人开源 https://www.renren.io - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - package com.epmet.opendata.service.impl; import com.alibaba.fastjson.JSON; @@ -23,6 +6,10 @@ import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.redis.common.CustomerOrgRedis; +import com.epmet.commons.tools.redis.common.bean.GridInfoCache; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.AddGroup; @@ -32,15 +19,18 @@ import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.opendata.dao.BaseGridDailyworkDao; import com.epmet.opendata.dto.ExDeptDTO; import com.epmet.opendata.dto.ExUserDTO; +import com.epmet.opendata.dto.form.HistoryDataSyncFormDTO; import com.epmet.opendata.dto.form.UpsertPatrolRecordForm; import com.epmet.opendata.entity.BaseGridDailyworkEntity; -import com.epmet.opendata.service.BaseGridDailyworkService; -import com.epmet.opendata.service.ExDeptService; -import com.epmet.opendata.service.ExUserService; +import com.epmet.opendata.entity.GridstaffWorkInfoPingyinEntity; +import com.epmet.opendata.service.*; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.ListUtils; +import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.ArrayList; @@ -64,6 +54,12 @@ public class BaseGridDailyworkServiceImpl extends BaseServiceImpl list, Map deptMap, Map userMap){ List insertList = new ArrayList<>(); list.forEach(o-> insertList.add(buildEntity(o, deptMap, userMap))); @@ -130,7 +127,6 @@ public class BaseGridDailyworkServiceImpl extends BaseServiceImpl deptMap, Map userMap) { BaseGridDailyworkEntity entity = new BaseGridDailyworkEntity(); entity.setCustomerId(record.getCustomerId()); @@ -178,9 +174,122 @@ public class BaseGridDailyworkServiceImpl extends BaseServiceImpl data; + do { + Result> record = epmetUserOpenFeignClient.getPatrolRoutineWorkListV2(midPatrolFormDTO); + if (record == null || !record.success()) { + log.error("获取例行工作记录V2失败,param:{}", JSON.toJSONString(midPatrolFormDTO)); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + data = record.getData(); + if (CollectionUtils.isEmpty(data)) { + //数据已被删除了 + //暂时设置error 用于排错 + log.error("获取例行工作记录返回为空,param:{}", JSON.toJSONString(midPatrolFormDTO)); + int effectRow = baseDao.deleteById(patrolRecordForm.getId()); + log.warn("del effectRow:{}", effectRow); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + data.forEach(d -> { + GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(d.getGridId()); + if (null == gridInfo){ + throw new EpmetException("未查询到网格信息:"+ d.getGridId()); + } + d.setGridCode(gridInfo.getCode()); + d.setGridName(gridInfo.getGridName()); + }); + insertNewRecordBatch(data); + }while (data.size() == NumConstant.ONE_THOUSAND); + return true; + } + + /** + * Desc: 历史数据处理 + * @param formDTO + * @author zxc + * @date 2022/7/22 13:24 + */ + @Override + public void historyDataSync(HistoryDataSyncFormDTO formDTO) { + Integer pageSize = NumConstant.ONE_THOUSAND; + Integer pageNo = NumConstant.ONE; + List baseGridDailyWork; + do { + baseGridDailyWork = baseDao.getBaseGridDailyWork(formDTO.getCustomerId(),(pageNo - NumConstant.ONE) * pageSize); + List newEntities = ConvertUtils.sourceToTarget(baseGridDailyWork, GridstaffWorkInfoPingyinEntity.class); + newEntities.forEach(n -> { + GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(n.getGridId()); + if (null == gridInfo){ + throw new EpmetException("未查询到网格信息:"+ n.getGridId()); + } + n.setGridCode(gridInfo.getCode()); + n.setHappenTime(DateUtils.parseDate(n.getHappenTimeString(),DateUtils.DATE_PATTERN)); + n.setIsDel(NumConstant.ZERO_STR); + }); + insertGridStaffWorkInfoPY(newEntities); + pageNo++; + }while (baseGridDailyWork.size() == NumConstant.ONE_THOUSAND); + } + + /** + * Desc: 数据存入 + * @param newEntities + * @author zxc + * @date 2022/7/22 14:17 + */ + @Transactional(rollbackFor = Exception.class) + public void insertGridStaffWorkInfoPY(List newEntities){ + if (!CollectionUtils.isEmpty(newEntities)){ + List> partition = ListUtils.partition(newEntities, NumConstant.ONE_HUNDRED); + partition.forEach(p -> { + pingYinService.insertBatch(p); + }); + } + } + + private Boolean insertNewRecordBatch(List list){ + List insertList = new ArrayList<>(); + list.forEach(o-> insertList.add(buildNewEntity(o))); + //insert + if (CollectionUtils.isEmpty(insertList)){ + log.error("新构建要插入的数据为空,param:{}", JSON.toJSONString(list)); + return false; + } + insertGridStaffWorkInfoPY(insertList); +// pingYinService.saveOrUpdateBatch(insertList, NumConstant.ONE_HUNDRED); + return true; + } + } diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridstaffWorkInfoPingyinServiceImpl.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridstaffWorkInfoPingyinServiceImpl.java index 405640c9db..db80164c1d 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridstaffWorkInfoPingyinServiceImpl.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GridstaffWorkInfoPingyinServiceImpl.java @@ -14,4 +14,10 @@ import org.springframework.stereotype.Service; */ @Service public class GridstaffWorkInfoPingyinServiceImpl extends BaseServiceImpl implements GridstaffWorkInfoPingyinService { + + + @Override + public Integer delAllGridStaffWorkInfoPY() { + return baseDao.delAllGridStaffWorkInfoPY(); + } } \ No newline at end of file diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/BaseGridDailyworkDao.xml b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/BaseGridDailyworkDao.xml index 3047bc30c9..da5b05eec7 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/BaseGridDailyworkDao.xml +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/BaseGridDailyworkDao.xml @@ -3,33 +3,22 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridstaffWorkInfoPingyinDao.xml b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridstaffWorkInfoPingyinDao.xml index 44396702fc..ea3bc11030 100755 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridstaffWorkInfoPingyinDao.xml +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GridstaffWorkInfoPingyinDao.xml @@ -18,6 +18,9 @@ + + delete from gridstaff_work_info_pingyin LIMIT 1000 + \ No newline at end of file