From 08ea9ceb4425c700946f55f04430e5b1f3fe0326 Mon Sep 17 00:00:00 2001 From: jianjun Date: Mon, 19 Jul 2021 14:39:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E9=A2=9C=E8=89=B2=E9=80=82?= =?UTF-8?q?=E5=BA=94=E8=B0=83=E6=95=B4=EF=BC=9A=E6=96=B0=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=9A=8F=E6=9C=BA=E6=B7=BB=E5=8A=A0=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=20=E7=BC=93=E5=AD=98=E5=86=85=E6=B7=BB=E5=8A=A0=E9=A2=9C?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/redis/RedisKeys.java | 12 ++++++-- .../com/epmet/dto/form/UpdateTagFormDTO.java | 5 ++++ .../com/epmet/dto/form/InitTagsFormDTO.java | 6 +++- .../result/UpdateTagUseCountsResultDTO.java | 5 ++++ .../epmet/controller/ArticleController.java | 6 ++-- .../java/com/epmet/dao/TagCustomerDao.java | 4 +-- .../com/epmet/entity/TagCustomerEntity.java | 8 ++++-- .../main/java/com/epmet/redis/TagRedis.java | 28 +++++++++++++++++-- .../service/impl/ArticleServiceImpl.java | 5 +++- .../service/impl/TagCustomerServiceImpl.java | 11 ++++++-- .../epmet/service/impl/TagServiceImpl.java | 23 ++++++++++----- .../java/com/epmet/utils/TagColorUtils.java | 28 +++++++++++++++++++ .../main/resources/mapper/TagCustomerDao.xml | 10 ++++--- 13 files changed, 122 insertions(+), 29 deletions(-) create mode 100644 epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/TagColorUtils.java 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 6f5e7bf1f3..6d5a5f0cfb 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 @@ -228,7 +228,11 @@ public class RedisKeys { * @return */ public static String getCustomerReTagKey(String customerId,String tagId) { - return rootPrefix.concat("tags:customer:relationTag:").concat(customerId).concat(StrConstant.COLON).concat(tagId); + String reTagKey = rootPrefix.concat("tags:customer:relationTag:").concat(customerId); + if (StringUtils.isNotBlank(tagId)){ + reTagKey = reTagKey.concat(StrConstant.COLON).concat(tagId); + } + return reTagKey; } /** @@ -247,7 +251,11 @@ public class RedisKeys { * @return */ public static String getGridReTagKey(String gridId,String tagId) { - return rootPrefix.concat("tags:grid:relationTag:").concat(gridId).concat(StrConstant.COLON).concat(tagId); + String gridReTagKey = rootPrefix.concat("tags:grid:relationTag:").concat(gridId); + if (StringUtils.isNotBlank(tagId)){ + gridReTagKey = gridReTagKey.concat(StrConstant.COLON).concat(tagId); + } + return gridReTagKey; } /** diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/UpdateTagFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/UpdateTagFormDTO.java index d2000b366f..96b7f73fa2 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/UpdateTagFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/UpdateTagFormDTO.java @@ -25,6 +25,11 @@ public class UpdateTagFormDTO implements Serializable { */ private String tagName; + /** + * 标签颜色 + */ + private String tagColor; + /** * 使用计数 */ diff --git a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/InitTagsFormDTO.java b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/InitTagsFormDTO.java index ded8bc1f43..13d14e5fef 100644 --- a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/InitTagsFormDTO.java +++ b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/InitTagsFormDTO.java @@ -3,7 +3,6 @@ package com.epmet.dto.form; import lombok.Data; import java.io.Serializable; -import java.util.Date; /** * @Author zxc @@ -29,6 +28,11 @@ public class InitTagsFormDTO implements Serializable { */ private String tagName; + /** + * 标签颜色 + */ + private String tagColor; + /** * 使用计数 */ diff --git a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateTagUseCountsResultDTO.java b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateTagUseCountsResultDTO.java index fba5e29854..2e282b17e5 100644 --- a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateTagUseCountsResultDTO.java +++ b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateTagUseCountsResultDTO.java @@ -31,4 +31,9 @@ public class UpdateTagUseCountsResultDTO implements Serializable { * 标签名称 */ private String tagName; + + /** + * 标签颜色 + */ + private String tagColor; } diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java index 7495fb6561..58e3e968d4 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java @@ -22,7 +22,6 @@ import com.epmet.commons.tools.annotation.RequirePermission; import com.epmet.commons.tools.enums.RequirePermissionEnum; import com.epmet.commons.tools.scan.result.SyncScanResult; import com.epmet.commons.tools.security.dto.TokenDto; -import com.epmet.commons.tools.utils.HttpClientManager; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.DefaultGroup; @@ -40,7 +39,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.HashMap; import java.util.List; @@ -251,7 +249,7 @@ public class ArticleController { log.error("scanContent draftId:{} return result null", draftId); } - if (syncScanResult.isAllPass()) { + if (syncScanResult != null && syncScanResult.isAllPass()) { articleService.scanAllPassPublishArticle(tokenDto, draftId, syncScanResult); } else { articleService.updateAuditStatusFailById(draftId, syncScanResult); @@ -404,4 +402,4 @@ public class ArticleController { return new Result>().ok(articleService.subjectList(formDTO)); } -} \ No newline at end of file +} diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagCustomerDao.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagCustomerDao.java index edcc5ec3b5..595f2a9a18 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagCustomerDao.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagCustomerDao.java @@ -40,7 +40,7 @@ public interface TagCustomerDao extends BaseDao { * @param formDTO * @author zxc */ - void upsertTagCount(UpdateTagFormDTO formDTO); + void upsertTagCount(UpdateTagFormDTO formDTO); /** * @Description 初始化默认标签 @@ -55,4 +55,4 @@ public interface TagCustomerDao extends BaseDao { * @return */ List selectInitData(@Param("customerIdList") List customerIdList); -} \ No newline at end of file +} diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/TagCustomerEntity.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/TagCustomerEntity.java index 878b9e05e5..7a2a54d7ae 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/TagCustomerEntity.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/TagCustomerEntity.java @@ -18,13 +18,10 @@ package com.epmet.entity; import com.baomidou.mybatisplus.annotation.TableName; - import com.epmet.commons.mybatis.entity.BaseEpmetEntity; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.Date; - /** * 客户标签表 * @@ -48,6 +45,11 @@ public class TagCustomerEntity extends BaseEpmetEntity { */ private String tagName; + /** + * 标签颜色 + */ + private String tagColor; + /** * 使用计数 */ diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java index c8657af1a5..fcf736da02 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java @@ -282,7 +282,7 @@ public class TagRedis { } }); } - + /** * @Description set 更新标签级联 * @param key @@ -305,6 +305,30 @@ public class TagRedis { } } + /** + * desc: 根据Key删除 缓存 + * + * @param customerId + * @return java.lang.Boolean + * @author LiuJanJun + * @date 2021/7/19 1:34 下午 + */ + public void clearCustomerTag(String customerId) { + String customerTagKey = RedisKeys.getCustomerTagKey(customerId); + Boolean delete = redisTemplate.delete(customerTagKey); + log.info("clearCustomerTag result:{}, customerRankingTagKey:{}",delete, customerTagKey); + String customerReTagKey = RedisKeys.getCustomerReTagKey(customerId, null).concat(":*"); + delete = redisTemplate.delete(customerReTagKey); + log.info("clearCustomerTag result:{}, customerReTagKey:{}",delete, customerReTagKey); + } -} \ No newline at end of file + public void clearGridTag(String gridId) { + String gridTagKey = RedisKeys.getGridTagKey(gridId); + Boolean delete = redisTemplate.delete(gridTagKey); + log.info("clearGridTag result:{}, gridRankingTagKey:{}",delete, gridTagKey); + String gridReTagKey = RedisKeys.getGridReTagKey(gridId, null).concat(":*"); + delete = redisTemplate.delete(gridReTagKey); + log.info("clearGridTag result:{}, gridReTagKey:{}",delete, gridReTagKey); + } +} diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java index d4bacc8197..b2b12d5966 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java @@ -1105,7 +1105,7 @@ public class ArticleServiceImpl extends BaseServiceImpl failDataIds = syncScanResult.getFailDataIds(); for (String id : failDataIds) { if (id.indexOf(ModuleConstant.SCAN_COVER_PREFIX) >= NumConstant.ZERO) { diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagCustomerServiceImpl.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagCustomerServiceImpl.java index 58ece05108..b5c69d76c1 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagCustomerServiceImpl.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagCustomerServiceImpl.java @@ -29,6 +29,7 @@ import com.epmet.dto.form.UpdateTagFormDTO; import com.epmet.dto.result.UpdateTagUseCountsResultDTO; import com.epmet.entity.TagCustomerEntity; import com.epmet.service.TagCustomerService; +import com.epmet.utils.TagColorUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -114,11 +115,15 @@ public class TagCustomerServiceImpl extends BaseServiceImpl>> customerTag = new HashMap<>(); - customerTagList.stream().forEach(tag -> { - buildZset(customerTag, tag.getCustomerId(), tag.getId(), tag.getTagName(), tag.getUseCount()); + customerTagList.forEach(tag -> { + buildZset(customerTag, tag.getCustomerId(), tag.getId(), tag.getTagName(),tag.getTagColor(), tag.getUseCount()); }); if (customerTag.size() > 0) { - customerTag.forEach((customerId, tagSet) -> tagRedis.zAddCustomerTag(customerId, tagSet)); + customerTag.forEach((customerId, tagSet) -> { + //先删除(排行及关联标签) 再添加 + tagRedis.clearCustomerTag(customerId); + tagRedis.zAddCustomerTag(customerId, tagSet); + }); } //key customerId:tagId Map> reCustomerTagMap = new HashMap<>(); @@ -172,9 +176,13 @@ public class TagServiceImpl implements TagService { throw new RenException("网格标签数为空"); } customerTag.clear(); - gridTagList.stream().forEach(tag -> buildZset(customerTag, tag.getGridId(), tag.getTagId(), tag.getTagName(), tag.getUseCount())); + gridTagList.forEach(tag -> buildZset(customerTag, tag.getGridId(), tag.getTagId(), tag.getTagName(), null, tag.getUseCount())); if (customerTag.size() > 0) { - customerTag.forEach((gridId, tagSet) -> tagRedis.zAddGridTag(gridId, tagSet)); + customerTag.forEach((gridId, tagSet) -> { + //先删除(排行及关联标签) 再添加 + tagRedis.clearGridTag(gridId); + tagRedis.zAddGridTag(gridId, tagSet); + }); } //获取网格发布的文章 按网格排序 @@ -236,7 +244,7 @@ public class TagServiceImpl implements TagService { }); } - private void buildZset(Map>> customerTag, String customerId, String id, String tagName, Integer useCount) { + private void buildZset(Map>> customerTag, String customerId, String id, String tagName, String tagColor, Integer useCount) { Set> typedTupleSet = customerTag.get(customerId); if (typedTupleSet == null) { typedTupleSet = new HashSet<>(); @@ -245,7 +253,8 @@ public class TagServiceImpl implements TagService { UpdateTagUseCountsResultDTO initTag = new UpdateTagUseCountsResultDTO(); initTag.setTagId(id); initTag.setTagName(tagName); + initTag.setTagColor(tagColor); ZSetOperations.TypedTuple typedTuple1 = new DefaultTypedTuple<>(initTag, Double.valueOf(useCount)); typedTupleSet.add(typedTuple1); } -} \ No newline at end of file +} diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/TagColorUtils.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/TagColorUtils.java new file mode 100644 index 0000000000..ce1e289f31 --- /dev/null +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/TagColorUtils.java @@ -0,0 +1,28 @@ +package com.epmet.utils; + +import java.util.Random; + +/** + * desc:标签颜色工具类 + * + * @author: LiuJanJun + * @date: 2021/7/19 10:39 上午 + * @version: 1.0 + */ +public class TagColorUtils { + private static final String[] tagColorArr = {"#E3271C","#FB7900","#FFC100","#0089FF","#17B886"}; + + /** + * desc: 随机获取标签颜色 + * + * @param + * @return java.lang.String + * @author LiuJanJun + * @date 2021/7/19 2:38 下午 + */ + public static String getRandomColor(){ + int size = tagColorArr.length; + int index = new Random().nextInt(size); + return tagColorArr[index]; + } +} diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagCustomerDao.xml b/epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagCustomerDao.xml index 12da65d434..183eb8317f 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagCustomerDao.xml +++ b/epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagCustomerDao.xml @@ -7,11 +7,12 @@ select id from tag_customer where tag_name = #{tagName} AND CUSTOMER_ID = #{customerId} - INSERT INTO tag_customer ( ID, CUSTOMER_ID, TAG_NAME, USE_COUNT, DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) + INSERT INTO tag_customer ( ID, CUSTOMER_ID, TAG_NAME, TAG_COLOR, USE_COUNT, DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) VALUES (REPLACE ( UUID(), '-', '' ), #{customerId}, #{tagName}, + #{tagColor}, #{useCount}, #{delFlag}, #{revision}, @@ -26,11 +27,11 @@ - INSERT INTO tag_customer ( ID, CUSTOMER_ID, TAG_NAME, USE_COUNT, DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) + INSERT INTO tag_customer ( ID, CUSTOMER_ID, TAG_NAME, TAG_COLOR, USE_COUNT, DEL_FLAG, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) VALUES ( - #{tag.id},#{tag.customerId}, #{tag.tagName}, #{tag.useCount}, #{tag.delFlag}, #{tag.revision}, #{tag.createdBy}, NOW(), #{tag.updatedBy}, NOW() + #{tag.id},#{tag.customerId}, #{tag.tagName}, #{tag.tagColor} #{tag.useCount}, #{tag.delFlag}, #{tag.revision}, #{tag.createdBy}, NOW(), #{tag.updatedBy}, NOW() ) ON DUPLICATE KEY UPDATE @@ -41,6 +42,7 @@ ID, CUSTOMER_ID, TAG_NAME, + TAG_COLOR, USE_COUNT FROM tag_customer @@ -54,4 +56,4 @@ ORDER BY CUSTOMER_ID - \ No newline at end of file +