From 049e403bf6125ea62a098f0e4a2e8372c83b85ea Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Thu, 25 Mar 2021 16:04:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=B0=86=E5=AE=A2=E6=88=B7=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=88=86=E7=B1=BB=E6=A0=87=E7=AD=BE=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=94=BE=E5=85=A5=E6=96=B0=E5=AE=A2=E6=88=B7=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=9A=84=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constants/ConsomerGroupConstants.java | 4 ++ .../gov-issue/gov-issue-server/pom.xml | 6 ++ .../IssueProjectCategoryTagInitListener.java | 67 +++++++++++++++++++ .../IssueProjectCategoryDictServiceImpl.java | 12 ---- .../impl/IssueProjectTagDictServiceImpl.java | 14 ---- 5 files changed, 77 insertions(+), 26 deletions(-) create mode 100644 epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/mq/listener/IssueProjectCategoryTagInitListener.java diff --git a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java index 9c332a6626..ded5a9aa8d 100644 --- a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java +++ b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java @@ -17,5 +17,9 @@ public interface ConsomerGroupConstants { * 初始化客户组织机构信息分组 */ String INIT_CUSTOMER_ORG_ROLES_GROUP = "init_customer_org_roles_group"; + /** + * 客户初始化议题、项目分类、标签数据 + */ + String ISSUE_PROJECT_CATEGORY_TAG = "issue_project_category_tag"; } diff --git a/epmet-module/gov-issue/gov-issue-server/pom.xml b/epmet-module/gov-issue/gov-issue-server/pom.xml index 54a2ff009c..208fea460c 100644 --- a/epmet-module/gov-issue/gov-issue-server/pom.xml +++ b/epmet-module/gov-issue/gov-issue-server/pom.xml @@ -108,6 +108,12 @@ 2.0.0 compile + + com.epmet + epmet-commons-rocketmq + 2.0.0 + compile + diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/mq/listener/IssueProjectCategoryTagInitListener.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/mq/listener/IssueProjectCategoryTagInitListener.java new file mode 100644 index 0000000000..beb1fa1473 --- /dev/null +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/mq/listener/IssueProjectCategoryTagInitListener.java @@ -0,0 +1,67 @@ +package com.epmet.mq.listener; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants; +import com.epmet.commons.rocketmq.constants.TopicConstants; +import com.epmet.commons.rocketmq.messages.InitCustomerMQMsg; +import com.epmet.commons.tools.distributedlock.DistributedLock; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.dto.form.CategoryTagInitFormDTO; +import com.epmet.service.IssueProjectCategoryDictService; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.spring.annotation.MessageModel; +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; +import org.apache.rocketmq.spring.core.RocketMQListener; +import org.redisson.api.RLock; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +/** + * 监听初始化客户动作,为客户初始化议题、项目的分类、标签数据 + */ +@RocketMQMessageListener(topic = TopicConstants.INIT_CUSTOMER, + consumerGroup = ConsomerGroupConstants.ISSUE_PROJECT_CATEGORY_TAG, + messageModel = MessageModel.CLUSTERING, + selectorExpression = "*") +@Component +public class IssueProjectCategoryTagInitListener implements RocketMQListener { + + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private IssueProjectCategoryDictService issueProjectCategoryDictService; + + @Autowired + private DistributedLock distributedLock; + + @Override + public void onMessage(MessageExt messageExt) { + String msg = new String(messageExt.getBody()); + logger.info("初始化客户-初始化客户自定义信息-收到消息内容:{}", msg); + InitCustomerMQMsg msgObj = JSON.parseObject(msg, InitCustomerMQMsg.class); + + CategoryTagInitFormDTO dto = new CategoryTagInitFormDTO(); + dto.setCustomerId(msgObj.getCustomerId()); + + RLock lock = null; + try { + lock = distributedLock.getLock(String.format("lock:init_customer_home:%s", msgObj.getCustomerId()), + 30l, 30l, TimeUnit.SECONDS); + issueProjectCategoryDictService.init(dto); + } catch (RenException e) { + // 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试 + logger.error("【RocketMQ】初始化客户组件失败:".concat(ExceptionUtils.getErrorStackTrace(e))); + } catch (Exception e) { + // 不是我们自己抛出的异常,可以让MQ重试 + logger.error("【RocketMQ】初始化客户组件失败:".concat(ExceptionUtils.getErrorStackTrace(e))); + throw e; + } finally { + distributedLock.unLock(lock); + } + } +} \ No newline at end of file diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectCategoryDictServiceImpl.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectCategoryDictServiceImpl.java index d78c3a3458..545e6e810d 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectCategoryDictServiceImpl.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectCategoryDictServiceImpl.java @@ -148,18 +148,6 @@ public class IssueProjectCategoryDictServiceImpl extends BaseServiceImpl categoryList(String customerId) { List resultList = baseDao.selectCustomerCategoryList(customerId); - //2021.3.24 sun 客户初始化分类标签的接口不想加到新客户创建的程序里,因此加到这里 在标签列表的查询方法中也有关于初始化分类标签的逻辑 - try { - if(CollectionUtils.isEmpty(resultList)){ - CategoryTagInitFormDTO dto = new CategoryTagInitFormDTO(); - dto.setCustomerId(customerId); - init(dto); - resultList = baseDao.selectCustomerCategoryList(customerId); - } - } catch (Exception e) { - logger.error("客户初始化分类、标签失败,客户Id->"+customerId, e); - } - //end return resultList; } diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectTagDictServiceImpl.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectTagDictServiceImpl.java index ee06f971d3..deede50676 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectTagDictServiceImpl.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectTagDictServiceImpl.java @@ -131,20 +131,6 @@ public class IssueProjectTagDictServiceImpl extends BaseServiceImpl> map = issueProjectTagDictRedis.getDefaultTagsSortedByCategoryAndCustomizedTagsOrderByRank(tokenDto.getCustomerId(), formDTO.getCategoryIdList()); result.setDefaulted(map.get(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME)); - //2021.3.24 sun 客户初始化分类标签的接口不想加到新客户创建的程序里,因此加到这里 在分类列表的查询方法中也有关于初始化分类标签的逻辑 - try { - if(CollectionUtils.isEmpty(result.getDefaulted())){ - CategoryTagInitFormDTO dto = new CategoryTagInitFormDTO(); - dto.setCustomerId(tokenDto.getCustomerId()); - issueProjectCategoryDictService.init(dto); - Map> map1 = issueProjectTagDictRedis.getDefaultTagsSortedByCategoryAndCustomizedTagsOrderByRank(tokenDto.getCustomerId(), - formDTO.getCategoryIdList()); - result.setDefaulted(map1.get(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME)); - } - } catch (Exception e) { - logger.error("客户初始化分类、标签失败,客户Id->"+tokenDto.getCustomerId(), e); - } - //end List list = map.get(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME); if (CollectionUtils.isNotEmpty(list)) { result.setCustomized(list.stream().limit(NumConstant.TEN).collect(Collectors.toList())); From 19fbf3780086334fc735bb4ebfacb26a57b06eb8 Mon Sep 17 00:00:00 2001 From: wangchao Date: Thu, 25 Mar 2021 16:46:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E8=A1=A5=E5=81=BF=E6=9C=BA=E5=88=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/dao/IssueProjectTagDictDao.java | 2 +- .../epmet/redis/IssueProjectTagDictRedis.java | 13 +++++++---- .../mapper/IssueProjectTagDictDao.xml | 23 +++++++++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueProjectTagDictDao.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueProjectTagDictDao.java index 8439b7d940..45fa05d7cf 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueProjectTagDictDao.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueProjectTagDictDao.java @@ -85,7 +85,7 @@ public interface IssueProjectTagDictDao extends BaseDao selectTagListByCustomer(@Param("customerId") String customerId); /** - * @Description 根据类别查询客户下标签 + * @Description 根据类别查询客户下默认标签 * @param categories * @param customerId * @return java.util.List diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java index b5ee686890..b041b7efd4 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java @@ -269,26 +269,31 @@ public class IssueProjectTagDictRedis { CategoryTagInitFormDTO customerIdParam = new CategoryTagInitFormDTO(); customerIdParam.setCustomerId(customerId); if (!CollectionUtils.isEmpty(redisUtils.keys(GovIssueRedisKeys.getGovernmentTagKey(customerId, null)))){ + //缓存不为空 if(CollectionUtils.isEmpty(preResult) || CollectionUtils.isEmpty(preResult.get(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME))) { if (ifOtherOnly || CollectionUtils.isEmpty(category)) { //补偿全部默认标签 categoryDictService.init(customerIdParam); - db.addAll(poolDao.selectTagListByCustomer(customerId)); + db.addAll(poolDao.selectTagByCategory(null, customerId, customerId)); } else { if (NumConstant.ZERO <= poolDao.selectCountByCustomerId(customerId)) { categoryDictService.init(customerIdParam); } else { //只插入category中的标签 - tagDictService.insertBatch(poolDao.selectTagByCategory(category, "default", customerId)); - db.addAll(poolDao.selectTagsByCustomerIdAndTagIds(customerId, category)); + List missingTags = poolDao.selectTagByCategory(category, "default", customerId); + if(!CollectionUtils.isEmpty(missingTags)){ + tagDictService.insertBatch(missingTags); + db.addAll(missingTags);} } } } + }else{ + //缓存为空 if (NumConstant.ZERO <= poolDao.selectCountByCustomerId(customerId)) { categoryDictService.init(customerIdParam); } - db.addAll(poolDao.selectTagListByCustomer(customerId)); + db.addAll(poolDao.selectTagByCategory(null, customerId, customerId)); } if(CollectionUtils.isEmpty(preResult) || CollectionUtils.isEmpty(preResult.get(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME))){ diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueProjectTagDictDao.xml b/epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueProjectTagDictDao.xml index 8bd6bbba53..51b847163b 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueProjectTagDictDao.xml +++ b/epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueProjectTagDictDao.xml @@ -92,16 +92,31 @@ #{targetCustomerId} as customerId, - TAG_NAME,CATEGORY_ID,IS_DEFAULT,ISSUE_USE_COUNT,PROJECT_USE_COUNT,IS_DISABLE,DEL_FLAG,REVISION + TAG_NAME,CATEGORY_ID,IS_DEFAULT, + + + ISSUE_USE_COUNT, + + + IFNULL(ISSUE_USE_COUNT,0)+IFNULL(PROJECT_USE_COUNT,0) AS issueUseCount, + + + PROJECT_USE_COUNT, + IS_DISABLE,DEL_FLAG,REVISION FROM ISSUE_PROJECT_TAG_DICT WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId} - - CATEGORY_ID = #{categoryId} - + AND + IS_DEFAULT = '0' + + + CATEGORY_ID = #{categoryId} + + +