From 7589b5a6b2d771bd42416fd8ce445bb058ce0edb Mon Sep 17 00:00:00 2001 From: jianjun Date: Thu, 24 Feb 2022 17:23:19 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=AF=BC=E8=88=AA=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/epmet/commons/tools/redis/RedisKeys.java | 3 +++ .../src/main/java/com/epmet/redis/GovMenuRedis.java | 11 ++++++++++- .../com/epmet/service/impl/GovMenuServiceImpl.java | 9 ++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index fe03008b81..876cc61ccd 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -733,4 +733,7 @@ public class RedisKeys { return rootPrefix.concat("temporary:").concat("temporaryResult:").concat(customerId).concat(":").concat(userId); } + public static String getCustomerMenuList(String customerId, Integer type) { + return rootPrefix.concat("oper:access:nav:customerId:").concat(customerId)+type; + } } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java index 361d6c3014..8f6a61da6c 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java @@ -71,4 +71,13 @@ public class GovMenuRedis { return (Set)redisUtils.get(key); } -} \ No newline at end of file + public void setCustomerMenuList(String customerId, Integer type, List govMenuDTOS) { + String key = RedisKeys.getCustomerMenuList(customerId, type); + redisUtils.set(key,govMenuDTOS,RedisUtils.DEFAULT_EXPIRE); + } + + public List getCustomerMenuList(String customerId, Integer type) { + String key = RedisKeys.getCustomerMenuList(customerId, type); + return (List)redisUtils.get(key); + } +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java index 4e4c142b55..8eb3bcf5e2 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java @@ -42,6 +42,7 @@ import org.slf4j.LoggerFactory; 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.*; @@ -208,9 +209,15 @@ public class GovMenuServiceImpl extends BaseServiceImpl getCustomerMenuList(String customerId, Integer type) { + List govMenuDTOS = govMenuRedis.getCustomerMenuList(customerId,type); + if (!CollectionUtils.isEmpty(govMenuDTOS)){ + return govMenuDTOS; + } List menuList = baseDao.getCustomerMenuList(customerId, type, HttpContextUtils.getLanguage()); List dtoList = ConvertUtils.sourceToTarget(menuList, GovMenuDTO.class); - return TreeUtils.buildTree(dtoList); + govMenuDTOS = TreeUtils.buildTree(dtoList); + govMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS); + return govMenuDTOS; } @Override From 5d9828085ccbf592f44f973282de0a5354421b4b Mon Sep 17 00:00:00 2001 From: jianjun Date: Fri, 25 Feb 2022 10:32:13 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E9=85=8D=E7=BD=AEpc=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=97=B6=20=E5=88=A0=E9=99=A4=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/redis/RedisKeys.java | 2 +- .../com/epmet/redis/GovCustomerMenuRedis.java | 57 ++++++++++++++++--- .../java/com/epmet/redis/GovMenuRedis.java | 10 ---- .../impl/GovCustomerMenuServiceImpl.java | 6 +- .../service/impl/GovMenuServiceImpl.java | 8 +-- 5 files changed, 59 insertions(+), 24 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 876cc61ccd..0798627046 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -734,6 +734,6 @@ public class RedisKeys { } public static String getCustomerMenuList(String customerId, Integer type) { - return rootPrefix.concat("oper:access:nav:customerId:").concat(customerId)+type; + return rootPrefix.concat("oper:access:nav:customerId:").concat(customerId).concat(":type:")+type; } } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovCustomerMenuRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovCustomerMenuRedis.java index 2333a6bd48..3cc19b8ae2 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovCustomerMenuRedis.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovCustomerMenuRedis.java @@ -17,31 +17,72 @@ package com.epmet.redis; +import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.dto.GovMenuDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; + /** * 客户菜单配置表 * * @author generator generator@elink-cn.com * @since v1.0.0 2021-03-16 */ +@Slf4j @Component public class GovCustomerMenuRedis { @Autowired private RedisUtils redisUtils; - - public void delete(Object[] ids) { - + /** + * desc:保存客户菜单缓存 + * @param customerId + * @param type + * @see com.epmet.enums.MenuTypeEnum + */ + public void setCustomerMenuList(String customerId, Integer type, List govMenuDTOS) { + if (checkParam(customerId, type)) { + String key = RedisKeys.getCustomerMenuList(customerId, type); + redisUtils.set(key, govMenuDTOS, RedisUtils.DEFAULT_EXPIRE); + } + } + /** + * desc:获取客户菜单缓存 + * @param customerId + * @param type + * @see com.epmet.enums.MenuTypeEnum + */ + public List getCustomerMenuList(String customerId, Integer type) { + if (checkParam(customerId, type)) { + String key = RedisKeys.getCustomerMenuList(customerId, type); + return (List) redisUtils.get(key); + } + return null; } - public void set(){ + /** + * desc:删除客户菜单缓存 + * @param customerId + * @param type + * @see com.epmet.enums.MenuTypeEnum + */ + public void delCustomerMenu(String customerId, Integer type) { + if (checkParam(customerId, type)) { + String key = RedisKeys.getCustomerMenuList(customerId, type); + redisUtils.delete(key); + } } - public String get(String id){ - return null; + private boolean checkParam(String customerId, Integer type) { + if (StringUtils.isBlank(customerId) || type == null){ + log.warn("checkParam fail, param is null"); + return false; + } + return true; } - -} \ No newline at end of file +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java index 8f6a61da6c..b96405de2e 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/GovMenuRedis.java @@ -70,14 +70,4 @@ public class GovMenuRedis { String key = RedisKeys.getUserPermissionsKey(userId, app, client); return (Set)redisUtils.get(key); } - - public void setCustomerMenuList(String customerId, Integer type, List govMenuDTOS) { - String key = RedisKeys.getCustomerMenuList(customerId, type); - redisUtils.set(key,govMenuDTOS,RedisUtils.DEFAULT_EXPIRE); - } - - public List getCustomerMenuList(String customerId, Integer type) { - String key = RedisKeys.getCustomerMenuList(customerId, type); - return (List)redisUtils.get(key); - } } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovCustomerMenuServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovCustomerMenuServiceImpl.java index 8d7ef26acc..95e4f2f8d2 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovCustomerMenuServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovCustomerMenuServiceImpl.java @@ -20,14 +20,15 @@ package com.epmet.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ConvertUtils; -import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.dao.GovCustomerMenuDao; import com.epmet.dto.GovCustomerMenuDTO; import com.epmet.dto.form.MenuConfigFormDTO; import com.epmet.entity.GovCustomerMenuEntity; +import com.epmet.enums.MenuTypeEnum; import com.epmet.redis.GovCustomerMenuRedis; import com.epmet.service.GovCustomerMenuService; import org.apache.commons.lang3.StringUtils; @@ -105,6 +106,7 @@ public class GovCustomerMenuServiceImpl extends BaseServiceImpl govCustomerMenuRedis.delCustomerMenu(customerId, MenuTypeEnum.MENU.value())); } @Override diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java index 8eb3bcf5e2..eb9467e926 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java @@ -33,7 +33,7 @@ import com.epmet.dao.GovMenuDao; import com.epmet.dto.GovMenuDTO; import com.epmet.entity.GovMenuEntity; import com.epmet.enums.MenuTypeEnum; -import com.epmet.feign.EpmetUserFeignClient; +import com.epmet.redis.GovCustomerMenuRedis; import com.epmet.redis.GovMenuRedis; import com.epmet.service.*; import org.apache.commons.lang3.StringUtils; @@ -58,7 +58,7 @@ public class GovMenuServiceImpl extends BaseServiceImpl getCustomerMenuList(String customerId, Integer type) { - List govMenuDTOS = govMenuRedis.getCustomerMenuList(customerId,type); + List govMenuDTOS = govCustomerMenuRedis.getCustomerMenuList(customerId,type); if (!CollectionUtils.isEmpty(govMenuDTOS)){ return govMenuDTOS; } List menuList = baseDao.getCustomerMenuList(customerId, type, HttpContextUtils.getLanguage()); List dtoList = ConvertUtils.sourceToTarget(menuList, GovMenuDTO.class); govMenuDTOS = TreeUtils.buildTree(dtoList); - govMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS); + govCustomerMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS); return govMenuDTOS; } From 321a7bcb43be195bad2eef71a7b61369b08bf1f6 Mon Sep 17 00:00:00 2001 From: jianjun Date: Fri, 25 Feb 2022 14:37:54 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E6=97=A5=E5=BF=97=E7=BA=A7=E5=88=AB?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java index 6ce851a45e..868c6e0185 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java @@ -33,7 +33,7 @@ public class ScanApiAuthInterceptor implements HandlerInterceptor { String ip = IpUtils.getIpAddr(request); SetOperations setOperations = redisTemplate.opsForSet(); if (!setOperations.isMember(RedisKeys.getWhiteList(), ip)) { - log.warn("preHandle ip:{} is not in whitelist", ip); + log.error("preHandle ip:{} 不在白名单内", ip); String result = JSON.toJSONString(new Result<>().error(EpmetErrorCode.ERR401.getCode(), EpmetErrorCode.ERR401.getMsg())); responseJson(response, result); return false; From 9919509c6fb70966943c2253c07ccf2649430551 Mon Sep 17 00:00:00 2001 From: jianjun Date: Fri, 25 Feb 2022 15:23:00 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E6=8C=AA=E8=B5=B0=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/epmet/commons/tools/filter/LogMsgSendFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/LogMsgSendFilter.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/LogMsgSendFilter.java index d0ba1f61de..9f6be36819 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/LogMsgSendFilter.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/LogMsgSendFilter.java @@ -66,6 +66,7 @@ public class LogMsgSendFilter extends LevelFilter { } if (StringUtils.isNotBlank(activeEnv)) { + stringBuilder.append("告警环境:").append(activeEnv); stringBuilder.append("\n"); } @@ -112,7 +113,6 @@ public class LogMsgSendFilter extends LevelFilter { if (!flag) { logger.warn("msgSender.sendMsg fail,param:{}", stringBuilder.toString()); } - stringBuilder.append("告警环境:").append(activeEnv); } catch (Exception e) { logger.warn("decide exception", e); } From 57a269bf445315cb5228a5d58602208231f68ec9 Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Fri, 25 Feb 2022 15:24:32 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E5=85=9A=E5=91=98=E9=A3=8E=E9=87=87?= =?UTF-8?q?=E5=92=8C=E7=A4=BE=E4=BC=9A=E8=87=AA=E7=BB=84=E7=BB=87=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=94=B9=E4=B8=BA=E5=BC=82=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IcCommunitySelfOrganizationController.java | 8 +++----- .../impl/IcCommunitySelfOrganizationServiceImpl.java | 4 ++++ .../controller/IcPartymemberStyleController.java | 5 ++++- .../service/impl/IcPartymemberStyleServiceImpl.java | 4 ++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java index 94fd66386b..022e6d834b 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java @@ -17,10 +17,6 @@ package com.epmet.controller; -import cn.afterturn.easypoi.excel.ExcelExportUtil; -import cn.afterturn.easypoi.excel.entity.ExportParams; -import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; -import cn.hutool.poi.excel.ExcelUtil; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; import com.epmet.commons.tools.exception.RenException; @@ -143,7 +139,7 @@ public class IcCommunitySelfOrganizationController { * @date 2021/11/25 9:03 上午 */ @PostMapping("importcommunityselforganization") - public void importCommunitySelfOrganization(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws Exception { + public Result importCommunitySelfOrganization(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws Exception { if (file.isEmpty()) { throw new RenException("请上传文件"); } @@ -164,6 +160,8 @@ public class IcCommunitySelfOrganizationController { } //2.执行导入程序 icCommunitySelfOrganizationService.importCommunitySelfOrganization(tokenDto, response, file, result.getData().getTaskId()); + + return new Result(); } /** diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java index 663461c62c..ca222a906c 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java @@ -57,6 +57,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.http.entity.ContentType; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -80,6 +82,7 @@ import static com.epmet.commons.tools.utils.DateUtils.DATE_PATTERN; */ @Service @Slf4j +@EnableAsync public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl implements IcCommunitySelfOrganizationService { @Autowired @@ -472,6 +475,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl fileList = new ArrayList<>(); CommunitySelfOrgImportExcel excel = null; diff --git a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java index 4f41645000..b29fd3f54a 100644 --- a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java +++ b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java @@ -17,6 +17,7 @@ package com.epmet.modules.partymember.controller; +import com.baomidou.mybatisplus.extension.api.R; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; import com.epmet.commons.tools.constant.NumConstant; @@ -124,7 +125,7 @@ public class IcPartymemberStyleController { } @PostMapping("import") - public void importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException { + public Result importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException { // 校验文件类型 String extension = FilenameUtils.getExtension(file.getOriginalFilename()); if (!"xls".equals(extension) && !"xlsx".equals(extension)) { @@ -141,6 +142,8 @@ public class IcPartymemberStyleController { } //2.执行导入程序 icPartymemberStyleService.importData(tokenDto, response, file, result.getData().getTaskId()); + + return new Result(); } /** diff --git a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java index b17d3f3a4a..2d4533ff94 100644 --- a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java +++ b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java @@ -71,6 +71,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.http.entity.ContentType; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -92,6 +94,7 @@ import java.util.stream.Collectors; */ @Slf4j @Service +@EnableAsync public class IcPartymemberStyleServiceImpl extends BaseServiceImpl implements IcPartymemberStyleService { @Resource @@ -255,6 +258,7 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl fileList = new ArrayList<>(); PartyMemberImportExcel excel = null; From c5334c1ab6b4cb49f42f5f76e7d1ad314adca99d Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Fri, 25 Feb 2022 15:52:11 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IcCommunitySelfOrganizationController.java | 3 +++ .../service/impl/IcCommunitySelfOrganizationServiceImpl.java | 2 +- .../partymember/controller/IcPartymemberStyleController.java | 3 +++ .../service/impl/IcPartymemberStyleServiceImpl.java | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java index 022e6d834b..bbea13e834 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java @@ -45,6 +45,7 @@ import com.epmet.service.IcCommunitySelfOrganizationService; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FilenameUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -139,6 +140,8 @@ public class IcCommunitySelfOrganizationController { * @date 2021/11/25 9:03 上午 */ @PostMapping("importcommunityselforganization") + //service方法是异步的,需要事务注解加在被调用方 否则事务不起作用 + @Transactional(rollbackFor = Exception.class) public Result importCommunitySelfOrganization(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws Exception { if (file.isEmpty()) { throw new RenException("请上传文件"); diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java index ca222a906c..8572ededf5 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java @@ -474,7 +474,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl fileList = new ArrayList<>(); diff --git a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java index b29fd3f54a..b99c297700 100644 --- a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java +++ b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java @@ -42,6 +42,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FilenameUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -125,6 +126,8 @@ public class IcPartymemberStyleController { } @PostMapping("import") + //service方法是异步的,需要事务注解加在被调用方 否则事务不起作用 + @Transactional(rollbackFor = Exception.class) public Result importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException { // 校验文件类型 String extension = FilenameUtils.getExtension(file.getOriginalFilename()); diff --git a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java index 2d4533ff94..de24a39521 100644 --- a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java +++ b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java @@ -257,7 +257,7 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl fileList = new ArrayList<>(); From b81267ad11de9b49a2ad12b20b6456369b0a6588 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Fri, 25 Feb 2022 16:22:07 +0800 Subject: [PATCH 07/10] Async --- .../epmet/controller/BuildingController.java | 30 ++++++---- .../com/epmet/controller/HouseController.java | 59 ++++++------------- .../controller/IcNeighborHoodController.java | 19 +++++- .../com/epmet/service/BuildingService.java | 3 +- .../java/com/epmet/service/HouseService.java | 6 ++ .../epmet/service/IcNeighborHoodService.java | 3 +- .../service/impl/BuildingServiceImpl.java | 14 ++--- .../epmet/service/impl/HouseServiceImpl.java | 45 ++++++++++++++ .../impl/IcNeighborHoodServiceImpl.java | 47 ++++----------- 9 files changed, 123 insertions(+), 103 deletions(-) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java index 2ac1605193..83165b6c4f 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java @@ -25,20 +25,22 @@ import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.constant.ImportErrorMsgConstants; +import com.epmet.constants.ImportTaskConstants; import com.epmet.dao.IcBuildingUnitDao; import com.epmet.dto.BuildingTreeLevelDTO; -import com.epmet.dto.form.IcBulidingFormDTO; -import com.epmet.dto.form.IcBulidingUnitFormDTO; -import com.epmet.dto.form.ImportInfoFormDTO; -import com.epmet.dto.form.ListIcNeighborHoodFormDTO; +import com.epmet.dto.form.*; import com.epmet.dto.result.BuildingResultDTO; import com.epmet.dto.result.BuildingResultPagedDTO; import com.epmet.dto.result.IcNeighborHoodResultDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; import com.epmet.entity.IcBuildingUnitEntity; import com.epmet.excel.IcBuildingExcel; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.service.BuildingService; import com.epmet.service.IcBuildingService; import com.epmet.service.NeighborHoodService; @@ -66,17 +68,12 @@ import java.util.stream.Collectors; @RequestMapping("building") public class BuildingController { - - @Autowired - private NeighborHoodService neighborHoodService; - - @Autowired - private IcBuildingService icBuildingService; @Autowired private BuildingService buildingService; @Autowired private IcBuildingUnitDao icBuildingUnitDao; - + @Autowired + private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; @PostMapping("buildinglist") @@ -219,7 +216,16 @@ public class BuildingController { formDTO.setOrgType(orgType); formDTO.setOrgId(orgId); formDTO.setUserId(tokenDTO.getUserId()); - return buildingService.buildingImportExcel(formDTO,file); + ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO(); + importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_BUILDING); + importFormDTO.setOperatorId(formDTO.getUserId()); + importFormDTO.setOriginFileName(ImportErrorMsgConstants.BUILDING_ERROR_NAME); + Result importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO); + if (!importTask.success()){ + throw new EpmetException("当前存在上传任务"); + } + buildingService.buildingImportExcel(formDTO,file,importTask); + return new Result(); } /** diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java index 7bb02aac72..976032bd01 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java @@ -50,15 +50,22 @@ import com.epmet.service.IcNeighborHoodService; import com.epmet.util.ExcelPoiUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.apache.tomcat.util.http.MimeHeaders; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Field; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -83,8 +90,6 @@ public class HouseController implements ResultDataResolver { @Autowired private IcHouseRedis icHouseRedis; @Autowired - private IcNeighborHoodService neighborHoodService; - @Autowired private IcHouseService icHouseService; @Autowired private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; @@ -255,52 +260,22 @@ public class HouseController implements ResultDataResolver { @PostMapping("houseimport") public Result houseImport(@LoginUser TokenDto tokenDTO, @RequestParam("file") MultipartFile file, @RequestParam("orgId")String orgId, - @RequestParam("orgType")String orgType){ + @RequestParam("orgType")String orgType,HttpServletRequest multipartRequest){ ImportInfoFormDTO formDTO = new ImportInfoFormDTO(); formDTO.setCustomerId(tokenDTO.getCustomerId()); formDTO.setOrgType(orgType); formDTO.setOrgId(orgId); formDTO.setUserId(tokenDTO.getUserId()); - ExcelReader excelReader = null; - try { - InputStream inputStream = null; - try { - inputStream = file.getInputStream(); - } catch (IOException e) { - return new Result().error("读取文件失败"); - } - ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO(); - importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_HOUSE); - importFormDTO.setOperatorId(formDTO.getUserId()); - importFormDTO.setOriginFileName(ImportErrorMsgConstants.HOUSE_ERROR_NAME); - Result importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO); - if (!importTask.success()){ - throw new EpmetException("创建任务失败"); - } - excelReader = EasyExcel.read(inputStream).build(); - // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener - ReadSheet readSheet = EasyExcel.readSheet(0).head(HouseInfoModel.class) - .registerReadListener(new ImportHouseInfoListener(formDTO,icBuildingDao,icHouseRedis,neighborHoodService,icHouseService,epmetCommonServiceOpenFeignClient,importTask.getData().getTaskId())) - .build(); - excelReader.read(readSheet); - } finally { - if (excelReader != null) { - excelReader.finish(); - } - } - ImportResultDTO dto = icHouseRedis.getImportResultDTO(formDTO.getCustomerId(), formDTO.getUserId()); - if (null == dto){ - return new Result<>(); - } - List nums = dto.getNums(); - Integer num = dto.getNum(); - String s = "共%s条数据,导入成功%s条。"; - if (nums.size() > NumConstant.ZERO){ - Collections.sort(nums); - s = s + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"条导入失败"; - return new Result<>().error(9999,String.format(s,num,num - nums.size())); + ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO(); + importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_HOUSE); + importFormDTO.setOperatorId(formDTO.getUserId()); + importFormDTO.setOriginFileName(ImportErrorMsgConstants.HOUSE_ERROR_NAME); + Result importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO); + if (!importTask.success()){ + throw new EpmetException("当前存在上传任务"); } - return new Result<>().error(9999,String.format(s,num,num)); + houseService.dispose(file,formDTO,importTask); + return new Result<>(); } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java index a78ea28431..fba75d9432 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java @@ -19,6 +19,7 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.dto.result.OptionResultDTO; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; @@ -27,8 +28,13 @@ import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.AddGroup; import com.epmet.commons.tools.validator.group.DefaultGroup; import com.epmet.commons.tools.validator.group.UpdateGroup; +import com.epmet.constant.ImportErrorMsgConstants; +import com.epmet.constants.ImportTaskConstants; import com.epmet.dto.IcNeighborHoodDTO; import com.epmet.dto.form.ImportInfoFormDTO; +import com.epmet.dto.form.ImportTaskCommonFormDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.service.IcNeighborHoodService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -51,6 +57,8 @@ public class IcNeighborHoodController { @Autowired private IcNeighborHoodService icNeighborHoodService; + @Autowired + private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; @GetMapping("page") public Result> page(@RequestParam Map params){ @@ -128,7 +136,16 @@ public class IcNeighborHoodController { formDTO.setOrgType(orgType); formDTO.setOrgId(orgId); formDTO.setUserId(tokenDTO.getUserId()); - return icNeighborHoodService.neighborhoodImport(formDTO,file); + ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO(); + importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_NEIGHBOR_HOOD); + importFormDTO.setOperatorId(formDTO.getUserId()); + importFormDTO.setOriginFileName(ImportErrorMsgConstants.NEIGHBORHOOD_ERROR_NAME); + Result importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO); + if (!importTask.success()){ + throw new EpmetException("当前存在上传任务"); + } + icNeighborHoodService.neighborhoodImport(formDTO,file,importTask); + return new Result(); } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java index 240c24d454..a5d84c4d7d 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java @@ -25,6 +25,7 @@ import com.epmet.dto.form.ListIcNeighborHoodFormDTO; import com.epmet.dto.result.BuildingResultDTO; import com.epmet.dto.result.BuildingResultPagedDTO; import com.epmet.dto.result.IcNeighborHoodResultDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; import com.epmet.excel.IcBuildingExcel; import org.springframework.web.multipart.MultipartFile; @@ -74,6 +75,6 @@ public interface BuildingService { * @author zxc * @date 2022/2/13 10:18 上午 */ - Result buildingImportExcel(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException; + Result buildingImportExcel(ImportInfoFormDTO formDTO, MultipartFile file,Result importTask) throws IOException; } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java index ad5d1d69cb..c7a065024e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java @@ -17,11 +17,15 @@ package com.epmet.service; +import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.IcHouseFormDTO; +import com.epmet.dto.form.ImportInfoFormDTO; import com.epmet.dto.form.ListIcNeighborHoodFormDTO; import com.epmet.dto.result.HouseInfoDTO; import com.epmet.dto.result.IcNeighborHoodResultDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; import com.epmet.excel.IcHouseExcel; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -62,4 +66,6 @@ public interface HouseService { void exportBuildinginfo(ListIcNeighborHoodFormDTO formDTO, HttpServletResponse response) throws Exception; List queryListHouseInfo(Set houseIds, String customerId); + + Result dispose(MultipartFile file, ImportInfoFormDTO formDTO, Result importTask); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java index 7bfa4733e0..17eb160a64 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java @@ -24,6 +24,7 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.dto.IcNeighborHoodDTO; import com.epmet.dto.ImportGeneralDTO; import com.epmet.dto.form.ImportInfoFormDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; import com.epmet.entity.IcNeighborHoodEntity; import com.epmet.entity.IcNeighborHoodPropertyEntity; import com.epmet.entity.IcPropertyManagementEntity; @@ -128,7 +129,7 @@ public interface IcNeighborHoodService extends BaseService * @author zxc * @date 2022/2/12 11:11 上午 */ - Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException; + void neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file,Result importTask) throws IOException; /** * 获取导入小区,楼栋,单元ID diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java index e1c02d91e5..b617540160 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java @@ -46,6 +46,8 @@ import com.epmet.util.ExcelPoiUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -61,6 +63,7 @@ import java.util.stream.Collectors; @Slf4j @Service +@EnableAsync public class BuildingServiceImpl implements BuildingService { @@ -401,7 +404,8 @@ public class BuildingServiceImpl implements BuildingService { * @date 2022/2/13 10:15 上午 */ @Override - public Result buildingImportExcel(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException { + @Async + public Result buildingImportExcel(ImportInfoFormDTO formDTO, MultipartFile file,Result importTask) throws IOException { ExcelReader excelReader = null; try { InputStream inputStream = null; @@ -410,14 +414,6 @@ public class BuildingServiceImpl implements BuildingService { } catch (IOException e) { return new Result().error("读取文件失败"); } - ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO(); - importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_BUILDING); - importFormDTO.setOperatorId(formDTO.getUserId()); - importFormDTO.setOriginFileName(ImportErrorMsgConstants.BUILDING_ERROR_NAME); - Result importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO); - if (!importTask.success()){ - throw new EpmetException("创建任务失败"); - } excelReader = EasyExcel.read(inputStream).build(); // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener ReadSheet readSheet = EasyExcel.readSheet(0).head(BuildingInfoModel.class) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java index 4c809cb812..a03ce7099b 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java @@ -2,6 +2,9 @@ package com.epmet.service.impl; import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.hutool.core.bean.BeanUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelReader; +import com.alibaba.excel.read.metadata.ReadSheet; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.epmet.commons.tools.constant.NumConstant; @@ -14,6 +17,7 @@ import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; import com.epmet.dao.IcBuildingDao; import com.epmet.dao.IcBuildingUnitDao; import com.epmet.dao.IcHouseDao; @@ -23,15 +27,20 @@ import com.epmet.dto.IcBuildingDTO; import com.epmet.dto.IcBuildingUnitDTO; import com.epmet.dto.IcHouseDTO; import com.epmet.dto.form.IcHouseFormDTO; +import com.epmet.dto.form.ImportInfoFormDTO; import com.epmet.dto.form.ListIcNeighborHoodFormDTO; import com.epmet.dto.result.HouseInfoDTO; import com.epmet.dto.result.IcNeighborHoodResultDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; import com.epmet.entity.IcHouseEntity; import com.epmet.enums.HousePurposeEnums; import com.epmet.enums.HouseRentFlagEnums; import com.epmet.enums.HouseTypeEnums; import com.epmet.excel.IcHouseExcel; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.feign.GovOrgOpenFeignClient; +import com.epmet.model.HouseInfoModel; +import com.epmet.model.ImportHouseInfoListener; import com.epmet.redis.IcHouseRedis; import com.epmet.service.HouseService; import com.epmet.service.IcBuildingService; @@ -42,17 +51,23 @@ import com.epmet.util.ExcelPoiUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; @Slf4j @Service +@EnableAsync public class HouseServiceImpl implements HouseService, ResultDataResolver { @@ -77,6 +92,11 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver { private IcHouseRedis icHouseRedis; @Autowired private AgencyService agencyservice; + @Autowired + private IcNeighborHoodService neighborHoodService; + @Autowired + private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; + @Override @@ -329,4 +349,29 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver { }); return result; } + + @Async + @Override + public Result dispose(MultipartFile file, ImportInfoFormDTO formDTO, Result importTask) { + ExcelReader excelReader = null; + try { + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + } catch (IOException e) { + return new Result().error("读取文件失败"); + } + excelReader = EasyExcel.read(inputStream).build(); + // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener + ReadSheet readSheet = EasyExcel.readSheet(0).head(HouseInfoModel.class) + .registerReadListener(new ImportHouseInfoListener(formDTO,icBuildingDao,icHouseRedis,neighborHoodService,icHouseService,epmetCommonServiceOpenFeignClient,importTask.getData().getTaskId())) + .build(); + excelReader.read(readSheet); + } finally { + if (excelReader != null) { + excelReader.finish(); + } + } + return new Result(); + } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java index c86831ef00..6215d19304 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java @@ -73,6 +73,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.http.entity.ContentType; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -93,6 +95,7 @@ import java.util.stream.Collectors; */ @Slf4j @Service +@EnableAsync public class IcNeighborHoodServiceImpl extends BaseServiceImpl implements IcNeighborHoodService { @Autowired @@ -230,21 +233,9 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcNeighborHoodExcel.class); - List failList = importResult.getFailList(); - //存放错误数据行号 - List numList = new ArrayList<>(); - if(CollectionUtils.isNotEmpty(failList)){ - for ( IcNeighborHoodExcel entity : failList) { - //打印失败的行 和失败的信息 - log.error("第{}行,{}",entity.getRowNum(),entity.getErrorMsg()); - numList.add(entity.getRowNum()); - } - } - List result =importResult.getList(); - return disposeImportNeighborhood(formDTO,result);*/ - return importNeighbor(formDTO,file); + @Async + public void neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file,Result importTask) throws IOException { + importNeighbor(formDTO,file,importTask); } /** @@ -407,7 +398,7 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl importTask){ ExcelReader excelReader = null; try { InputStream inputStream = null; @@ -416,14 +407,7 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl().error("读取文件失败"); } - ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO(); - importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_NEIGHBOR_HOOD); - importFormDTO.setOperatorId(formDTO.getUserId()); - importFormDTO.setOriginFileName(ImportErrorMsgConstants.NEIGHBORHOOD_ERROR_NAME); - Result importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO); - if (!importTask.success()){ - throw new EpmetException("创建任务失败"); - } + excelReader = EasyExcel.read(inputStream).build(); // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener ReadSheet readSheet = EasyExcel.readSheet(0).head(NeighborHoodInfoModel.class) @@ -435,19 +419,8 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl(); - } - List nums = dto.getNums(); - Integer num = dto.getNum(); - String s = "共%s条数据,导入成功%s条。"; - if (nums.size() > NumConstant.ZERO){ - Collections.sort(nums); - s = s + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"条导入失败"; - return new Result<>().error(9999,String.format(s,num,num - nums.size())); - } - return new Result<>().error(9999,String.format(s,num,num)); + + return new Result<>(); } /** From a6ca2de18f549edc1e04c41a54d654adfc04bcde Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Fri, 25 Feb 2022 17:28:36 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=A1=88?= =?UTF-8?q?=E6=97=B6=E5=8F=AA=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=B8=8E=E8=80=97=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ProjectServiceImpl.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java b/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java index e6e70e2c73..6a591d9e8d 100644 --- a/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java +++ b/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectServiceImpl.java @@ -453,10 +453,12 @@ public class ProjectServiceImpl extends BaseServiceImpl Date: Fri, 25 Feb 2022 17:37:22 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8F=98=E5=8A=A8=20up?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/mq/ProjectChangedCustomListener.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 c4c0138ad0..a096dc3307 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 @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.epmet.commons.rocketmq.constants.MQUserPropertys; import com.epmet.commons.rocketmq.messages.DisputeProcessMQMsg; import com.epmet.commons.rocketmq.messages.ProjectChangedMQMsg; +import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.distributedlock.DistributedLock; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; @@ -111,12 +112,19 @@ public class ProjectChangedCustomListener implements MessageListenerConcurrently String customerId = msgObj.getCustomerId(); distributedLock = SpringContextUtils.getBean(DistributedLock.class); lock = distributedLock.getLock(String.format("lock:project_changed:%s:%s", customerId, msgObj.getProjectId()) - ,30L, 30L, TimeUnit.SECONDS); + ,60L, 60L, TimeUnit.SECONDS); if (StringUtils.isBlank(customerId)){ logger.error("consumer project_changed fail,msg:{}",customerId); return; } + //睡一秒 要不然那边执行不完 + try { + Thread.sleep(NumConstant.ONE_THOUSAND); + } catch (InterruptedException e) { + log.error("consumeMessage exception",e); + } + ExtractOriginFormDTO extractOriginFormDTO = new ExtractOriginFormDTO(); extractOriginFormDTO.setCustomerId(customerId); From 781c3d93bea5c93d2b6766d843e3655856b18123 Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Fri, 25 Feb 2022 17:56:53 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E8=AE=AE=E9=A2=98=E8=BD=AC=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=8A=A0=E5=88=86=E5=B8=83=E5=BC=8F=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IssueManageController.java | 3 +- .../java/com/epmet/service/IssueService.java | 3 +- .../epmet/service/impl/IssueServiceImpl.java | 231 ++++++++++-------- 3 files changed, 126 insertions(+), 111 deletions(-) diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/controller/IssueManageController.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/controller/IssueManageController.java index b11a2e960b..1c522d1afb 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/controller/IssueManageController.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/controller/IssueManageController.java @@ -182,8 +182,7 @@ public class IssueManageController { public Result shiftProjectV2(@LoginUser TokenDto tokenDTO, @RequestBody ShiftProjectFormDTO formDTO) { formDTO.setStaffId(tokenDTO.getUserId()); ValidatorUtils.validateEntity(formDTO); - issueService.shiftProjectV2(formDTO); - return new Result(); + return issueService.shiftProjectV2(formDTO); } /** diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/IssueService.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/IssueService.java index 4eca209b95..01e16471da 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/IssueService.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/IssueService.java @@ -3,6 +3,7 @@ package com.epmet.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.Result; import com.epmet.dto.IssueDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; @@ -219,7 +220,7 @@ public interface IssueService extends BaseService { * @param formDTO * @return void */ - void shiftProjectV2(ShiftProjectFormDTO formDTO); + Result shiftProjectV2(ShiftProjectFormDTO formDTO); /** * @Description 已关闭列表 政府端 diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java index a8c3188586..cebca254d9 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java @@ -9,7 +9,9 @@ import com.epmet.commons.rocketmq.messages.GroupAchievementMQMsg; import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.distributedlock.DistributedLock; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; +import com.epmet.commons.tools.enums.AchievementTypeEnum; import com.epmet.commons.tools.enums.EventEnum; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; @@ -41,7 +43,6 @@ import com.epmet.entity.IssueEntity; import com.epmet.entity.IssueProcessEntity; import com.epmet.entity.IssueProjectRelationEntity; import com.epmet.feign.*; -import com.epmet.commons.tools.enums.AchievementTypeEnum; import com.epmet.redis.GovIssueRedis; import com.epmet.redis.IssueVoteDetailRedis; import com.epmet.resi.group.dto.group.form.AllIssueFormDTO; @@ -62,6 +63,7 @@ import com.epmet.utils.ModuleConstants; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.collections4.CollectionUtils; +import org.redisson.api.RLock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -136,6 +138,8 @@ public class IssueServiceImpl extends BaseServiceImpl imp private GovProjectOpenFeignClient govProjectOpenFeignClient; @Autowired private IssueVoteDetailService issueVoteDetailService; + @Autowired + private DistributedLock distributedLock; @Value("${openapi.scan.server.url}") @@ -957,127 +961,138 @@ public class IssueServiceImpl extends BaseServiceImpl imp * @date 2020/12/9 10:01 */ @Override - public void shiftProjectV2(ShiftProjectFormDTO formDTO) { - //1:查询议题数据 - IssueEntity entity = baseDao.selectById(formDTO.getIssueId()); - if (null == entity) { - throw new RenException(IssueConstant.SELECT_EXCEPTION); - } - if (IssueConstant.ISSUE_SHIFT_PROJECT.equals(entity.getIssueStatus())) { - throw new RenException(IssueConstant.ISSUE_SHIFT_PROJECT_EXCEPTION); - } - if (!IssueConstant.ISSUE_VOTING.equals(entity.getIssueStatus())) { - throw new RenException(IssueConstant.ISSUE_VOTING_EXCEPTION); - } - formDTO.setIssueDTO(ConvertUtils.sourceToTarget(entity, IssueDTO.class)); + public Result shiftProjectV2(ShiftProjectFormDTO formDTO) { + RLock lock = null; + try { + // 锁持有10分钟,等待10s + lock = distributedLock.tryLock(formDTO.getIssueId()); + //1:查询议题数据 + IssueEntity entity = baseDao.selectById(formDTO.getIssueId()); + if (null == entity) { + throw new RenException(IssueConstant.SELECT_EXCEPTION); + } + if (IssueConstant.ISSUE_SHIFT_PROJECT.equals(entity.getIssueStatus())) { + throw new RenException(IssueConstant.ISSUE_SHIFT_PROJECT_EXCEPTION); + } + if (!IssueConstant.ISSUE_VOTING.equals(entity.getIssueStatus())) { + throw new RenException(IssueConstant.ISSUE_VOTING_EXCEPTION); + } + formDTO.setIssueDTO(ConvertUtils.sourceToTarget(entity, IssueDTO.class)); - //获取议题分类 - List categoryList = issueCategoryService.getCategoryByIssue(formDTO.getIssueId()); - if (CollectionUtils.isEmpty(categoryList)) { - throw new RenException(EpmetErrorCode.CATEGORY_IS_NULL.getCode()); - } + //获取议题分类 + List categoryList = issueCategoryService.getCategoryByIssue(formDTO.getIssueId()); + if (CollectionUtils.isEmpty(categoryList)) { + throw new RenException(EpmetErrorCode.CATEGORY_IS_NULL.getCode()); + } - //公开回复内容审核 - if (StringUtils.isNotBlank(formDTO.getPublicReply())) { - TextScanParamDTO textScanParamDTO = new TextScanParamDTO(); - TextTaskDTO taskDTO = new TextTaskDTO(); - taskDTO.setDataId(UUID.randomUUID().toString().replace("-", "")); - taskDTO.setContent(formDTO.getPublicReply()); - textScanParamDTO.getTasks().add(taskDTO); - Result textSyncScanResult = ScanContentUtils.textSyncScan(scanApiUrl.concat(textSyncScanMethod), textScanParamDTO); - if (!textSyncScanResult.success()) { - throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); - } else { - if (!textSyncScanResult.getData().isAllPass()) { - throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode()); + //公开回复内容审核 + if (StringUtils.isNotBlank(formDTO.getPublicReply())) { + TextScanParamDTO textScanParamDTO = new TextScanParamDTO(); + TextTaskDTO taskDTO = new TextTaskDTO(); + taskDTO.setDataId(UUID.randomUUID().toString().replace("-", "")); + taskDTO.setContent(formDTO.getPublicReply()); + textScanParamDTO.getTasks().add(taskDTO); + Result textSyncScanResult = ScanContentUtils.textSyncScan(scanApiUrl.concat(textSyncScanMethod), textScanParamDTO); + if (!textSyncScanResult.success()) { + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } else { + if (!textSyncScanResult.getData().isAllPass()) { + throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode()); + } } } - } - - //因需要保证议题表中的转项目时间与创建项目时间一致 因此先新增项目数据再更新议题数据 - - //2:调用resi-group查询话题创建人数据(目前议题来源只有来自话题),为了到项目服务初始数据以及发送消息使用 - Result resultTopicDTO = resiGroupFeignClient.getTopicById(entity.getSourceId()); - if (!resultTopicDTO.success() || null == resultTopicDTO.getData()) { - throw new RenException(IssueConstant.SELECT_TOPIC_EXCEPTION); - } - ResiTopicDTO topicDTO = resultTopicDTO.getData(); - formDTO.setTopicDTO(topicDTO); - //3:调用gov-project服务,新增项目各业务表初始数据 - formDTO.setCategoryList(categoryList); - List tagList = issueTagsService.getTagsByIssue(formDTO.getIssueId()); - formDTO.setTagList(tagList); - Result resultDTO = govProjectFeignClient.issueShiftProject(formDTO); - if (!resultDTO.success() || null == resultDTO.getData()) { - logger.error(resultDTO.getInternalMsg()); - throw new RenException(IssueConstant.GOV_PRJECT_EXCEPTION); - } - IssueProjectResultDTO issueProjectResultDTO = resultDTO.getData(); - //更新项目对标签的引用次数 - if (CollectionUtils.isNotEmpty(tagList)) { - tagList.forEach(item -> { - IssueProjectTagDictDTO tag = issueProjectTagDictService.get(item.getTagId()); - tag.setProjectUseCount(tag.getProjectUseCount() + NumConstant.ONE); - issueProjectTagDictService.update(tag); - }); - } + //因需要保证议题表中的转项目时间与创建项目时间一致 因此先新增项目数据再更新议题数据 - //4:更新议题相关业务表数据 - //4.1:更新议题表数据 - entity.setIssueStatus(IssueConstant.ISSUE_SHIFT_PROJECT); - entity.setShiftedTime(issueProjectResultDTO.getShiftedTime()); - baseDao.updateById(entity); + //2:调用resi-group查询话题创建人数据(目前议题来源只有来自话题),为了到项目服务初始数据以及发送消息使用 + Result resultTopicDTO = resiGroupFeignClient.getTopicById(entity.getSourceId()); + if (!resultTopicDTO.success() || null == resultTopicDTO.getData()) { + throw new RenException(IssueConstant.SELECT_TOPIC_EXCEPTION); + } + ResiTopicDTO topicDTO = resultTopicDTO.getData(); + formDTO.setTopicDTO(topicDTO); + + //3:调用gov-project服务,新增项目各业务表初始数据 + formDTO.setCategoryList(categoryList); + List tagList = issueTagsService.getTagsByIssue(formDTO.getIssueId()); + formDTO.setTagList(tagList); + Result resultDTO = govProjectFeignClient.issueShiftProject(formDTO); + if (!resultDTO.success() || null == resultDTO.getData()) { + logger.error(resultDTO.getInternalMsg()); + throw new RenException(IssueConstant.GOV_PRJECT_EXCEPTION); + } + IssueProjectResultDTO issueProjectResultDTO = resultDTO.getData(); + //更新项目对标签的引用次数 + if (CollectionUtils.isNotEmpty(tagList)) { + tagList.forEach(item -> { + IssueProjectTagDictDTO tag = issueProjectTagDictService.get(item.getTagId()); + tag.setProjectUseCount(tag.getProjectUseCount() + NumConstant.ONE); + issueProjectTagDictService.update(tag); + }); + } - //4.2:议题处理进展表新增数据 - IssueProcessEntity processEntity = new IssueProcessEntity(); - processEntity.setIssueId(entity.getId()); - processEntity.setIssueStatus(IssueConstant.ISSUE_SHIFT_PROJECT); - processEntity.setOrgType(IssueConstant.ISSUE_GRID); - processEntity.setOrgId(entity.getGridId()); - processEntity.setOrgName(issueProjectResultDTO.getOrgName()); - issueProcessDao.insert(processEntity); + //4:更新议题相关业务表数据 + //4.1:更新议题表数据 + entity.setIssueStatus(IssueConstant.ISSUE_SHIFT_PROJECT); + entity.setShiftedTime(issueProjectResultDTO.getShiftedTime()); + baseDao.updateById(entity); + + //4.2:议题处理进展表新增数据 + IssueProcessEntity processEntity = new IssueProcessEntity(); + processEntity.setIssueId(entity.getId()); + processEntity.setIssueStatus(IssueConstant.ISSUE_SHIFT_PROJECT); + processEntity.setOrgType(IssueConstant.ISSUE_GRID); + processEntity.setOrgId(entity.getGridId()); + processEntity.setOrgName(issueProjectResultDTO.getOrgName()); + issueProcessDao.insert(processEntity); + + //4.3:议题项目关系表新增数据 + IssueProjectRelationEntity relationEntity = new IssueProjectRelationEntity(); + relationEntity.setIssueId(entity.getId()); + relationEntity.setProjectId(issueProjectResultDTO.getProjectId()); + issueProjectRelationDao.insert(relationEntity); + + //5:调用epmet-message服务,给居民端话题创建人、议题发起人以及政府端工作人员发送消息 + if (!shiftProjectMessage(issueProjectResultDTO, formDTO, entity).success()) { + throw new RenException(IssueConstant.SAVE_MSG_EXCEPTION); + } + //5-1:2020.10.26 添加给居民端话题创建人、议题发起人以及政府端工作人员推送微信订阅消息功能 sun + if (!wxmpShiftProjectMessage(issueProjectResultDTO, formDTO, entity).success()) { + logger.error("议题转项目,推送微信订阅消息失败!"); + } - //4.3:议题项目关系表新增数据 - IssueProjectRelationEntity relationEntity = new IssueProjectRelationEntity(); - relationEntity.setIssueId(entity.getId()); - relationEntity.setProjectId(issueProjectResultDTO.getProjectId()); - issueProjectRelationDao.insert(relationEntity); + //6:缓存中网格下表决中的议题总数减1 + govIssueRedis.subtractWorkGrassrootsIssueRedDotValue(entity.getGridId()); + try{ + issueVoteStatisticalService.syncVotingCacheToDbByParams(formDTO.getIssueId(),entity.getGridId(),null); + }catch(RenException e){ + logger.error(e.getInternalMsg()); + } - //5:调用epmet-message服务,给居民端话题创建人、议题发起人以及政府端工作人员发送消息 - if (!shiftProjectMessage(issueProjectResultDTO, formDTO, entity).success()) { - throw new RenException(IssueConstant.SAVE_MSG_EXCEPTION); - } - //5-1:2020.10.26 添加给居民端话题创建人、议题发起人以及政府端工作人员推送微信订阅消息功能 sun - if (!wxmpShiftProjectMessage(issueProjectResultDTO, formDTO, entity).success()) { - logger.error("议题转项目,推送微信订阅消息失败!"); - } - //6:缓存中网格下表决中的议题总数减1 - govIssueRedis.subtractWorkGrassrootsIssueRedDotValue(entity.getGridId()); - try{ - issueVoteStatisticalService.syncVotingCacheToDbByParams(formDTO.getIssueId(),entity.getGridId(),null); - }catch(RenException e){ - logger.error(e.getInternalMsg()); - } + //7:发送话题转议题积分事件 + TopicEventFormDTO eventParam = new TopicEventFormDTO(); + eventParam.setTopicId(entity.getSourceId()); + eventParam.setEvent(EventEnum.TOPIC_SHIFTED_TO_PROJECT); + if(!resiGroupOpenFeignClient.sendEvent(eventParam).success()){ + logger.warn("com.epmet.service.impl.IssueServiceImpl.shiftProjectV2,话题被转为项目积分事件发送失败,参数:{}", JSON.toJSONString(formDTO)); + } + // 8.数据库更新表决统计 + SelectIssueVotingDetailFormDTO dto = new SelectIssueVotingDetailFormDTO(); + dto.setGridId(entity.getGridId()); + dto.setIssueId(formDTO.getIssueId()); + issueVoteDetailService.updateVote(dto); - //7:发送话题转议题积分事件 - TopicEventFormDTO eventParam = new TopicEventFormDTO(); - eventParam.setTopicId(entity.getSourceId()); - eventParam.setEvent(EventEnum.TOPIC_SHIFTED_TO_PROJECT); - if(!resiGroupOpenFeignClient.sendEvent(eventParam).success()){ - logger.warn("com.epmet.service.impl.IssueServiceImpl.shiftProjectV2,话题被转为项目积分事件发送失败,参数:{}", JSON.toJSONString(formDTO)); + //8.记录日志 + //SendMqMsgUtil.build().openFeignClient(messageOpenFeignClient).sendProjectChangedMqMsg(); + return new Result(); + } catch (Exception e) { + return new Result().error("议题数据正在处理中,请勿重复提交!"); + } finally { + distributedLock.unLock(lock); } - // 8.数据库更新表决统计 - SelectIssueVotingDetailFormDTO dto = new SelectIssueVotingDetailFormDTO(); - dto.setGridId(entity.getGridId()); - dto.setIssueId(formDTO.getIssueId()); - issueVoteDetailService.updateVote(dto); - - //8.记录日志 - //SendMqMsgUtil.build().openFeignClient(messageOpenFeignClient).sendProjectChangedMqMsg(); } /**