Browse Source

Merge remote-tracking branch 'origin/dev_issue_category' into dev_temp

master
wangchao 4 years ago
parent
commit
072284c50e
  1. 4
      epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java
  2. 6
      epmet-module/gov-issue/gov-issue-server/pom.xml
  3. 2
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueProjectTagDictDao.java
  4. 67
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/mq/listener/IssueProjectCategoryTagInitListener.java
  5. 13
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java
  6. 12
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectCategoryDictServiceImpl.java
  7. 14
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectTagDictServiceImpl.java
  8. 23
      epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueProjectTagDictDao.xml

4
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";
}

6
epmet-module/gov-issue/gov-issue-server/pom.xml

@ -108,6 +108,12 @@
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

2
epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueProjectTagDictDao.java

@ -85,7 +85,7 @@ public interface IssueProjectTagDictDao extends BaseDao<IssueProjectTagDictEntit
List<IssueProjectTagDictEntity> selectTagListByCustomer(@Param("customerId") String customerId);
/**
* @Description 根据类别查询客户下标签
* @Description 根据类别查询客户下默认标签
* @param categories
* @param customerId
* @return java.util.List<com.epmet.entity.IssueProjectTagDictEntity>

67
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<MessageExt> {
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);
}
}
}

13
epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java

@ -270,26 +270,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<IssueProjectTagDictEntity> 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))){

12
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<IssuePr
@Override
public List<CustomerCategoryListResultDTO> categoryList(String customerId) {
List<CustomerCategoryListResultDTO> 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;
}

14
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<IssueProject
Map<String,List<IssueCategoryTagResultDTO>> 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<String,List<IssueCategoryTagResultDTO>> 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<IssueCategoryTagResultDTO> list = map.get(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME);
if (CollectionUtils.isNotEmpty(list)) {
result.setCustomized(list.stream().limit(NumConstant.TEN).collect(Collectors.toList()));

23
epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueProjectTagDictDao.xml

@ -92,16 +92,31 @@
<if test='null != targetCustomerId and "" != targetCustomerId'>
#{targetCustomerId} as customerId,
</if>
TAG_NAME,CATEGORY_ID,IS_DEFAULT,ISSUE_USE_COUNT,PROJECT_USE_COUNT,IS_DISABLE,DEL_FLAG,REVISION
TAG_NAME,CATEGORY_ID,IS_DEFAULT,
<choose>
<when test='"default" == customerId'>
ISSUE_USE_COUNT,
</when>
<otherwise>
IFNULL(ISSUE_USE_COUNT,0)+IFNULL(PROJECT_USE_COUNT,0) AS issueUseCount,
</otherwise>
</choose>
PROJECT_USE_COUNT,
IS_DISABLE,DEL_FLAG,REVISION
FROM
ISSUE_PROJECT_TAG_DICT
WHERE
DEL_FLAG = '0'
AND
CUSTOMER_ID = #{customerId}
<foreach collection="categories" item="categoryId" open="AND ( " separator=" OR " close=" )">
CATEGORY_ID = #{categoryId}
</foreach>
AND
IS_DEFAULT = '0'
<if test="null != categories and categories.size() > 0">
<foreach collection="categories" item="categoryId" open="AND ( " separator=" OR " close=" )">
CATEGORY_ID = #{categoryId}
</foreach>
</if>
</select>
<select id="selectCountByCustomerId" resultType="int">

Loading…
Cancel
Save