Browse Source

标签颜色适应调整:新加标签随机添加颜色 缓存内添加颜色

dev_shibei_match
jianjun 4 years ago
parent
commit
08ea9ceb44
  1. 12
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 5
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/UpdateTagFormDTO.java
  3. 6
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/InitTagsFormDTO.java
  4. 5
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/UpdateTagUseCountsResultDTO.java
  5. 4
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java
  6. 8
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/TagCustomerEntity.java
  7. 24
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java
  8. 5
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java
  9. 9
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagCustomerServiceImpl.java
  10. 21
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java
  11. 28
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/TagColorUtils.java
  12. 8
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagCustomerDao.xml

12
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;
}
/**

5
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;
/**
* 使用计数
*/

6
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;
/**
* 使用计数
*/

5
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;
}

4
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);

8
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;
/**
* 使用计数
*/

24
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java

@ -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);
}
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);
}
}

5
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<ArticleDao, ArticleEntit
log.error("updateAuditStatusFailById draftId:{} is not exist in db", draftId);
throw new RenException(EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getCode(), EpmetErrorCode.INTERNAL_VALIDATE_ERROR.getMsg());
}
if (syncScanResult.isAllPass()) {
if (syncScanResult != null && syncScanResult.isAllPass()) {
this.updateDraftPublishStatus(draftId, DraftConstant.PUBLISHED, null);
} else {
this.updateDraftPublishStatus(draftId, DraftConstant.AUDITFAIL, null);
@ -1113,6 +1113,9 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
boolean coverFail = false, contentFail = false, titleFail = false;
try {
if (syncScanResult == null){
syncScanResult = new SyncScanResult();
}
List<String> failDataIds = syncScanResult.getFailDataIds();
for (String id : failDataIds) {
if (id.indexOf(ModuleConstant.SCAN_COVER_PREFIX) >= NumConstant.ZERO) {

9
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,10 +115,14 @@ public class TagCustomerServiceImpl extends BaseServiceImpl<TagCustomerDao, TagC
formDTO.setCustomerId(customerId);
formDTO.setUpdatedBy(userId);
formDTO.setTagName(tagName);
String randomColor = TagColorUtils.getRandomColor();
formDTO.setTagColor(randomColor);
baseDao.upsertTagCount(formDTO);
TagCustomerEntity tagCustomerEntity = baseDao.selectById(formDTO.getId());
UpdateTagUseCountsResultDTO resultDTO = new UpdateTagUseCountsResultDTO();
resultDTO.setTagId(formDTO.getId());
resultDTO.setTagName(tagName);
resultDTO.setTagId(tagCustomerEntity.getId());
resultDTO.setTagName(tagCustomerEntity.getTagName());
resultDTO.setTagColor(tagCustomerEntity.getTagColor());
return resultDTO;
}

21
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java

@ -141,12 +141,16 @@ public class TagServiceImpl implements TagService {
}
Map<String, Set<ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO>>> 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<String, Set<UpdateTagUseCountsResultDTO>> 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<String, Set<ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO>>> customerTag, String customerId, String id, String tagName, Integer useCount) {
private void buildZset(Map<String, Set<ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO>>> customerTag, String customerId, String id, String tagName, String tagColor, Integer useCount) {
Set<ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO>> typedTupleSet = customerTag.get(customerId);
if (typedTupleSet == null) {
typedTupleSet = new HashSet<>();
@ -245,6 +253,7 @@ public class TagServiceImpl implements TagService {
UpdateTagUseCountsResultDTO initTag = new UpdateTagUseCountsResultDTO();
initTag.setTagId(id);
initTag.setTagName(tagName);
initTag.setTagColor(tagColor);
ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO> typedTuple1 = new DefaultTypedTuple<>(initTag, Double.valueOf(useCount));
typedTupleSet.add(typedTuple1);
}

28
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];
}
}

8
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagCustomerDao.xml

@ -7,11 +7,12 @@
<selectKey keyProperty="id" order="AFTER" resultType="String">
select id from tag_customer where tag_name = #{tagName} AND CUSTOMER_ID = #{customerId}
</selectKey>
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 id="initTags">
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
<foreach collection="tags" item="tag" separator=",">
(
#{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()
)
</foreach>
ON DUPLICATE KEY UPDATE
@ -41,6 +42,7 @@
ID,
CUSTOMER_ID,
TAG_NAME,
TAG_COLOR,
USE_COUNT
FROM
tag_customer

Loading…
Cancel
Save