From e454251fcf8d0e9df6b02bbe80c1166cf970733e Mon Sep 17 00:00:00 2001 From: wangchao Date: Mon, 14 Dec 2020 13:41:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=A0=87=E7=AD=BE=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/dao/IssueProjectTagDictDao.java | 21 ++++++++ .../epmet/redis/IssueProjectTagDictRedis.java | 21 ++++++++ .../impl/IssueProjectTagDictServiceImpl.java | 52 +++++++++++++++++++ .../mapper/IssueProjectTagDictDao.xml | 31 +++++++++++ 4 files changed, 125 insertions(+) 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 3da76c1ca6..2d14833f4a 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 @@ -44,6 +44,17 @@ public interface IssueProjectTagDictDao extends BaseDao tags,@Param("customerId")String customerId,@Param("status")String status); + /** + * @Description 更新标签使用次数 + * @param tagIds + * @param customerId + * @param score + * @return void + * @author wangc + * @date 2020.12.14 09:33 + */ + void updateTagUsage(@Param("tagIds") List tagIds,@Param("customerId")String customerId,@Param("score") Integer score); + /** * @Description 查询标签ID * @Param newTags @@ -81,4 +92,14 @@ public interface IssueProjectTagDictDao extends BaseDao selectTagByCategory(@Param("categories") List categories,@Param("customerId") String customerId,@Param("isDefault")String isDefault); + + /** + * @Description 根据客户Id和标签Id集合查询标签的基础信息(标签名、标签码,标签所属分类) + * @param customerId + * @param tagIds + * @return java.util.List + * @author wangc + * @date 2020.12.13 14:23 + */ + List selectTagsByCustomerIdAndTagIds(@Param("customerId") String customerId,@Param("tagIds")List tagIds); } \ No newline at end of file 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 944b347b1e..8494a00ec7 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 @@ -39,6 +39,7 @@ import org.springframework.data.redis.core.ZSetOperations; import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import sun.security.krb5.internal.PAData; import java.util.*; import java.util.stream.Collectors; @@ -348,6 +349,26 @@ public class IssueProjectTagDictRedis { redisUtils.zSetAdd(key,o); } + public void batchIncrScore(Map>> param){ + if(CollectionUtils.isEmpty(param)) return; + redisTemplate.executePipelined((RedisCallback) connection -> { + param.forEach((operation,map) -> { + if(!CollectionUtils.isEmpty(map)){ + map.forEach((key,list) -> { + if(!CollectionUtils.isEmpty(list)){ + list.forEach(obj -> { + connection.zSetCommands().zIncrBy(redisTemplate.getKeySerializer().serialize(key), + StringUtils.equals(NumConstant.ONE_STR,operation) ? 1d : -1d , + redisTemplate.getValueSerializer().serialize(obj)); + }); + } + }); + } + }); + return null; + }); + } + public T parseObject(Object o,Class clazz){ ObjectMapper objectMapper = new ObjectMapper(); T t = objectMapper.convertValue(o, clazz); 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 d325b96b79..2fe298a91a 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 @@ -25,11 +25,13 @@ import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.constant.GovIssueRedisKeys; import com.epmet.dao.IssueProjectTagDictDao; import com.epmet.dto.IssueProjectTagDictDTO; import com.epmet.dto.form.TagDifferentSetFormDTO; import com.epmet.dto.form.TagListFormDTO; import com.epmet.dto.result.IssueCategoryTagResultDTO; +import com.epmet.dto.result.IssueProjectTagsResultDTO; import com.epmet.dto.result.TagListResultDTO; import com.epmet.entity.IssueProjectTagDictEntity; import com.epmet.redis.IssueProjectTagDictRedis; @@ -152,8 +154,58 @@ public class IssueProjectTagDictServiceImpl extends BaseServiceImpl + // } + Map>> redisParam = new HashMap<>(); + + if(CollectionUtils.isNotEmpty(param.getMinus())){ + List tags = baseDao.selectTagsByCustomerIdAndTagIds(param.getCustomerId(),param.getMinus()); + if(CollectionUtils.isNotEmpty(tags)){ + Map> value = new HashMap<>(); + tags.forEach(tag -> { + String redisKey = GovIssueRedisKeys.getGovernmentTagKey(param.getCustomerId(),tag.getCategoryId()); + IssueCategoryTagResultDTO cache = new IssueCategoryTagResultDTO(); + cache.setId(tag.getId());cache.setName(tag.getTagName()); + if(CollectionUtils.isNotEmpty(value.get(redisKey))){ + value.get(redisKey).add(cache); + }else{ + List list = new LinkedList<>(); + list.add(cache); + value.put(redisKey,list); + } + }); + if(!value.isEmpty()) redisParam.put(NumConstant.ZERO_STR,value); + baseDao.updateTagUsage(param.getMinus(),param.getCustomerId(),NumConstant.ONE_NEG); + } + } + + if(CollectionUtils.isNotEmpty(param.getPlus())){ + List tags = baseDao.selectTagsByCustomerIdAndTagIds(param.getCustomerId(),param.getPlus()); + if(CollectionUtils.isNotEmpty(tags)){ + Map> value = new HashMap<>(); + tags.forEach(tag -> { + String redisKey = GovIssueRedisKeys.getGovernmentTagKey(param.getCustomerId(),tag.getCategoryId()); + IssueCategoryTagResultDTO cache = new IssueCategoryTagResultDTO(); + cache.setId(tag.getId());cache.setName(tag.getTagName()); + if(CollectionUtils.isNotEmpty(value.get(redisKey))){ + value.get(redisKey).add(cache); + }else{ + List list = new LinkedList<>(); + list.add(cache); + value.put(redisKey,list); + } + }); + if(!value.isEmpty()) redisParam.put(NumConstant.ONE_STR,value); + baseDao.updateTagUsage(param.getPlus(),param.getCustomerId(),NumConstant.ONE); + } + } + issueProjectTagDictRedis.batchIncrScore(redisParam); } } \ No newline at end of file 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 fb36c15a15..ec80fe2af3 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 @@ -21,6 +21,22 @@ + + UPDATE issue_project_tag_dict + SET issue_use_count = (CASE + WHEN issue_use_count IS NULL THEN IF(#{score} > 0 ,#{score} ,0) + WHEN issue_use_count 0 THEN 0 + ELSE issue_use_count + #{score} END) + + del_flag = 0 + AND + customer_id = #{customerId} + + id = #{tagId} + + + + + + \ No newline at end of file