diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/service/BaseService.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/service/BaseService.java index c82dce8253..9f5a388ab2 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/service/BaseService.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/service/BaseService.java @@ -123,5 +123,31 @@ public interface BaseService { */ boolean deleteBatchIds(Collection idList); + /** + *

+ * 存在更新记录,否插入一条记录 + *

+ * + * @param entity 实体对象 + */ + boolean saveOrUpdate(T entity); + + /** + *

+ * 批量修改插入 + *

+ * + * @param entityList 实体对象集合 + */ + boolean saveOrUpdateBatch(Collection entityList); + /** + *

+ * 批量修改插入 + *

+ * + * @param entityList 实体对象集合 + * @param batchSize 更新批次数量 + */ + boolean saveOrUpdateBatch(Collection entityList, int batchSize); } diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/service/impl/BaseServiceImpl.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/service/impl/BaseServiceImpl.java index fc89437e03..445f5a6e40 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/service/impl/BaseServiceImpl.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/service/impl/BaseServiceImpl.java @@ -13,6 +13,8 @@ import com.baomidou.mybatisplus.core.enums.SqlMethod; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.baomidou.mybatisplus.core.toolkit.*; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; @@ -31,6 +33,7 @@ import java.io.Serializable; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Objects; /** * 基础服务类,所有Service都要继承 @@ -298,4 +301,56 @@ public abstract class BaseServiceImpl, T> implements Bas public boolean deleteBatchIds(Collection idList) { return SqlHelper.delBool(baseDao.deleteBatchIds(idList)); } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean saveOrUpdate(T entity) { + if (null != entity) { + Class cls = entity.getClass(); + TableInfo tableInfo = TableInfoHelper.getTableInfo(cls); + Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); + String keyProperty = tableInfo.getKeyProperty(); + Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); + Object idVal = ReflectionKit.getMethodValue(cls, entity, tableInfo.getKeyProperty()); + return StringUtils.checkValNull(idVal) || Objects.isNull(selectById((Serializable) idVal)) ? insert(entity) : updateById(entity); + } + return false; + } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean saveOrUpdateBatch(Collection entityList) { + return saveOrUpdateBatch(entityList, 100); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean saveOrUpdateBatch(Collection entityList, int batchSize) { + Assert.notEmpty(entityList, "error: entityList must not be empty"); + Class cls = currentModelClass(); + TableInfo tableInfo = TableInfoHelper.getTableInfo(cls); + Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); + String keyProperty = tableInfo.getKeyProperty(); + Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); + try (SqlSession batchSqlSession = sqlSessionBatch()) { + int i = 0; + for (T entity : entityList) { + Object idVal = ReflectionKit.getMethodValue(cls, entity, keyProperty); + if (StringUtils.checkValNull(idVal) || Objects.isNull(selectById((Serializable) idVal))) { + batchSqlSession.insert(sqlStatement(SqlMethod.INSERT_ONE), entity); + } else { + MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); + param.put(Constants.ENTITY, entity); + batchSqlSession.update(sqlStatement(SqlMethod.UPDATE_BY_ID), param); + } + // 不知道以后会不会有人说更新失败了还要执行插入 😂😂😂 + if (i >= 1 && i % batchSize == 0) { + batchSqlSession.flushStatements(); + } + i++; + } + batchSqlSession.flushStatements(); + } + return true; + } } diff --git a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/DisputeProcessMQMsg.java b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/DisputeProcessMQMsg.java index 30a1700054..bed6aa4bf5 100644 --- a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/DisputeProcessMQMsg.java +++ b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/DisputeProcessMQMsg.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import java.io.Serializable; +import java.util.List; /** * @Description @@ -14,7 +15,7 @@ import java.io.Serializable; @AllArgsConstructor public class DisputeProcessMQMsg implements Serializable { private String customerId; - private String projectId; + private List projectId; /** * 操作类型【新增:add 修改删除:edit】 */ diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/basereport/form/EventInfoFormDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/basereport/form/EventInfoFormDTO.java index ee5830567a..8e6c99d562 100644 --- a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/basereport/form/EventInfoFormDTO.java +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/basereport/form/EventInfoFormDTO.java @@ -4,6 +4,7 @@ import com.epmet.commons.tools.dto.form.PageFormDTO; import lombok.Data; import java.io.Serializable; +import java.util.List; /** * @Description @@ -14,7 +15,7 @@ import java.io.Serializable; public class EventInfoFormDTO extends PageFormDTO implements Serializable { private static final long serialVersionUID = 8479649048108914555L; private String customerId; - private String projectId; + private List projectId; /** * 操作类型【新增:add 修改删除:edit】 */ diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenProjectDataDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenProjectDataDao.java index 26aa8892d9..701348e39a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenProjectDataDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenProjectDataDao.java @@ -68,7 +68,7 @@ public interface ScreenProjectDataDao extends BaseDao { int updateProjectSatisfactionScore(@Param("projectId")String projectId, @Param("score")BigDecimal score); - List selectProjectList(@Param("customerId") String customerId, @Param("projectId") String projectId); + List selectProjectList(@Param("customerId") String customerId, @Param("projectIds") List projectIds); /** * @Description 查询网格下的项目分类 diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/mq/ProjectChangedCustomListener.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/mq/ProjectChangedCustomListener.java index 72e12ff5dc..d5f304cc0d 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/mq/ProjectChangedCustomListener.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/mq/ProjectChangedCustomListener.java @@ -27,6 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.PreDestroy; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.concurrent.ExecutionException; @@ -154,14 +155,18 @@ public class ProjectChangedCustomListener implements MessageListenerConcurrently logger.info("consumer projectChanged msg success,{}",aBoolean); //发送项目数据上报的mq消息 - String type; - if ("issue_shift_project".equals(msgObj.getOperation()) || "created".equals(msgObj.getOperation())) { - type = SystemMessageType.PROJECT_ADD; - } else { - type = SystemMessageType.PROJECT_EDIT; + if ("issue_shift_project".equals(msgObj.getOperation()) || "created".equals(msgObj.getOperation()) || "close".equals(msgObj.getOperation())) { + String type; + if ("issue_shift_project".equals(msgObj.getOperation()) || "created".equals(msgObj.getOperation())) { + type = SystemMessageType.PROJECT_ADD; + } else { + type = SystemMessageType.PROJECT_EDIT; + } + List projectList = new ArrayList<>(); + projectList.add(msgObj.getProjectId()); + DisputeProcessMQMsg msg = new DisputeProcessMQMsg(customerId, projectList, type); + SpringContextUtils.getBean(ScreenProjectDataService.class).sendProjectChangeMq(msg); } - DisputeProcessMQMsg msg = new DisputeProcessMQMsg(customerId, msgObj.getProjectId(), type); - SpringContextUtils.getBean(ScreenProjectDataService.class).sendProjectChangeMq(msg); } catch (RenException e) { // 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试 logger.error("【RocketMQ】消费项目变动消息失败:",e); diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenProjectDataService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenProjectDataService.java index 845a2fc844..cf5279027a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenProjectDataService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenProjectDataService.java @@ -137,7 +137,7 @@ public interface ScreenProjectDataService extends BaseService getProjectList(String customerId, String projectId, Integer pageNo, Integer pageSize); + List getProjectList(String customerId, List projectId, Integer pageNo, Integer pageSize); /** * 项目变更MQ diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectDataServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectDataServiceImpl.java index e2597eae16..98bd3ff9cf 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectDataServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectDataServiceImpl.java @@ -48,12 +48,12 @@ import com.epmet.service.evaluationindex.screen.ScreenProjectDataService; import com.epmet.service.stats.CustomerProjectCategoryDictService; import com.github.pagehelper.PageHelper; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; @@ -298,7 +298,7 @@ public class ScreenProjectDataServiceImpl extends BaseServiceImpl getProjectList(String customerId, String projectId, Integer pageNo, Integer pageSize) { + public List getProjectList(String customerId, List projectId, Integer pageNo, Integer pageSize) { PageHelper.startPage(pageNo, pageSize); return baseDao.selectProjectList(customerId, projectId); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DataReportingServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DataReportingServiceImpl.java index 2fbd1d0037..6a113754dd 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DataReportingServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DataReportingServiceImpl.java @@ -164,7 +164,7 @@ public class DataReportingServiceImpl implements DataReportingService { } Map codeMap = customerProjectCategoryDictService.getByCategoryCodeMap(formDTO.getCustomerId());; //项目ID不为空时,因为只有一条,可以直接处理 - if (StringUtils.isNotEmpty(formDTO.getProjectId())) { + if (CollectionUtils.isNotEmpty(formDTO.getProjectId())) { list = projectList.stream().map(project -> { EventInfoResultDTO dto = getEventInfoResultDTO(project, epmetCodeMap, codeMap); if (OrgTypeConstant.AGENCY.equals(project.getOrgType())) { @@ -188,10 +188,12 @@ public class DataReportingServiceImpl implements DataReportingService { EventInfoResultDTO dto = getEventInfoResultDTO(project, epmetCodeMap, codeMap); if (OrgTypeConstant.AGENCY.equals(project.getOrgType())) { ScreenCustomerAgencyEntity agency = agencyMap.get(project.getOrgId()); + dto.setOrgId(project.getOrgId()); dto.setOrgCode(agency.getCode()); dto.setOrgName(agency.getAgencyName()); } else { ScreenCustomerGridDTO grid = gridMap.get(project.getOrgId()); + dto.setOrgId(project.getOrgId()); dto.setOrgCode(grid.getCode()); dto.setOrgName(grid.getGridName()); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenProjectDataDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenProjectDataDao.xml index a15debd1c6..913bdcb179 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenProjectDataDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenProjectDataDao.xml @@ -253,8 +253,10 @@ AND b.CUSTOMER_ID = #{customerId} - - AND b.PROJECT_ID = #{projectId} + + + b.PROJECT_ID = #{projectId} + LEFT JOIN screen_customer_agency c ON b.HANDLER_ID = c.AGENCY_ID WHERE a.DEL_FLAG = '0' @@ -263,8 +265,10 @@ AND a.CUSTOMER_ID = #{customerId} - - AND a.PROJECT_ID = #{projectId} + + + a.PROJECT_ID = #{projectId} + ORDER BY a.CREATED_TIME ASC diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/BaseDisputeProcessServiceImpl.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/BaseDisputeProcessServiceImpl.java index 7c9a1aeabf..484d2b17b7 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/BaseDisputeProcessServiceImpl.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/BaseDisputeProcessServiceImpl.java @@ -69,6 +69,7 @@ public class BaseDisputeProcessServiceImpl extends BaseServiceImpl> result = dataStatisticalOpenFeignClient.getEventInfo(formDTO); if (!result.success()) { throw new RenException(result.getInternalMsg()); @@ -119,9 +120,9 @@ public class BaseDisputeProcessServiceImpl extends BaseServiceImpl