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); } 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..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 @@ -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).concat(":type:")+type; + } } 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); 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..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 @@ -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; @@ -49,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; @@ -143,7 +140,9 @@ 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 { + //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("请上传文件"); } @@ -164,6 +163,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..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 @@ -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 @@ -471,7 +474,8 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl fileList = new ArrayList<>(); CommunitySelfOrgImportExcel excel = null; 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 361d6c3014..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,5 +70,4 @@ public class GovMenuRedis { String key = RedisKeys.getUserPermissionsKey(userId, app, client); return (Set)redisUtils.get(key); } - -} \ No newline at end of file +} 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 4e4c142b55..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; @@ -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.*; @@ -57,7 +58,7 @@ public class GovMenuServiceImpl extends BaseServiceImpl getCustomerMenuList(String customerId, Integer 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); - return TreeUtils.buildTree(dtoList); + govMenuDTOS = TreeUtils.buildTree(dtoList); + govCustomerMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS); + return govMenuDTOS; } @Override 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(); } /** 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<>(); } /** 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 5e2112ba9a..80ceb02393 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 implements IcPartymemberStyleService { @Resource @@ -254,7 +257,8 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl fileList = new ArrayList<>(); PartyMemberImportExcel excel = null; 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;