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. 6
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java
  6. 4
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagCustomerDao.java
  7. 8
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/TagCustomerEntity.java
  8. 28
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java
  9. 5
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java
  10. 11
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagCustomerServiceImpl.java
  11. 23
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java
  12. 28
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/TagColorUtils.java
  13. 10
      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 * @return
*/ */
public static String getCustomerReTagKey(String customerId,String tagId) { 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 * @return
*/ */
public static String getGridReTagKey(String gridId,String tagId) { 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 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 lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
/** /**
* @Author zxc * @Author zxc
@ -29,6 +28,11 @@ public class InitTagsFormDTO implements Serializable {
*/ */
private String tagName; 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 tagName;
/**
* 标签颜色
*/
private String tagColor;
} }

6
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.enums.RequirePermissionEnum;
import com.epmet.commons.tools.scan.result.SyncScanResult; import com.epmet.commons.tools.scan.result.SyncScanResult;
import com.epmet.commons.tools.security.dto.TokenDto; 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.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.DefaultGroup; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List; import java.util.List;
@ -251,7 +249,7 @@ public class ArticleController {
log.error("scanContent draftId:{} return result null", draftId); log.error("scanContent draftId:{} return result null", draftId);
} }
if (syncScanResult.isAllPass()) { if (syncScanResult != null && syncScanResult.isAllPass()) {
articleService.scanAllPassPublishArticle(tokenDto, draftId, syncScanResult); articleService.scanAllPassPublishArticle(tokenDto, draftId, syncScanResult);
} else { } else {
articleService.updateAuditStatusFailById(draftId, syncScanResult); articleService.updateAuditStatusFailById(draftId, syncScanResult);
@ -404,4 +402,4 @@ public class ArticleController {
return new Result<List<SubjectListResultDTO>>().ok(articleService.subjectList(formDTO)); return new Result<List<SubjectListResultDTO>>().ok(articleService.subjectList(formDTO));
} }
} }

4
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagCustomerDao.java

@ -40,7 +40,7 @@ public interface TagCustomerDao extends BaseDao<TagCustomerEntity> {
* @param formDTO * @param formDTO
* @author zxc * @author zxc
*/ */
void upsertTagCount(UpdateTagFormDTO formDTO); void upsertTagCount(UpdateTagFormDTO formDTO);
/** /**
* @Description 初始化默认标签 * @Description 初始化默认标签
@ -55,4 +55,4 @@ public interface TagCustomerDao extends BaseDao<TagCustomerEntity> {
* @return * @return
*/ */
List<TagCustomerEntity> selectInitData(@Param("customerIdList") List<String> customerIdList); List<TagCustomerEntity> selectInitData(@Param("customerIdList") List<String> customerIdList);
} }

8
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/TagCustomerEntity.java

@ -18,13 +18,10 @@
package com.epmet.entity; package com.epmet.entity;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.Date;
/** /**
* 客户标签表 * 客户标签表
* *
@ -48,6 +45,11 @@ public class TagCustomerEntity extends BaseEpmetEntity {
*/ */
private String tagName; private String tagName;
/**
* 标签颜色
*/
private String tagColor;
/** /**
* 使用计数 * 使用计数
*/ */

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

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

11
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.dto.result.UpdateTagUseCountsResultDTO;
import com.epmet.entity.TagCustomerEntity; import com.epmet.entity.TagCustomerEntity;
import com.epmet.service.TagCustomerService; import com.epmet.service.TagCustomerService;
import com.epmet.utils.TagColorUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -114,11 +115,15 @@ public class TagCustomerServiceImpl extends BaseServiceImpl<TagCustomerDao, TagC
formDTO.setCustomerId(customerId); formDTO.setCustomerId(customerId);
formDTO.setUpdatedBy(userId); formDTO.setUpdatedBy(userId);
formDTO.setTagName(tagName); formDTO.setTagName(tagName);
String randomColor = TagColorUtils.getRandomColor();
formDTO.setTagColor(randomColor);
baseDao.upsertTagCount(formDTO); baseDao.upsertTagCount(formDTO);
TagCustomerEntity tagCustomerEntity = baseDao.selectById(formDTO.getId());
UpdateTagUseCountsResultDTO resultDTO = new UpdateTagUseCountsResultDTO(); UpdateTagUseCountsResultDTO resultDTO = new UpdateTagUseCountsResultDTO();
resultDTO.setTagId(formDTO.getId()); resultDTO.setTagId(tagCustomerEntity.getId());
resultDTO.setTagName(tagName); resultDTO.setTagName(tagCustomerEntity.getTagName());
resultDTO.setTagColor(tagCustomerEntity.getTagColor());
return resultDTO; return resultDTO;
} }
} }

23
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<>(); Map<String, Set<ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO>>> customerTag = new HashMap<>();
customerTagList.stream().forEach(tag -> { customerTagList.forEach(tag -> {
buildZset(customerTag, tag.getCustomerId(), tag.getId(), tag.getTagName(), tag.getUseCount()); buildZset(customerTag, tag.getCustomerId(), tag.getId(), tag.getTagName(),tag.getTagColor(), tag.getUseCount());
}); });
if (customerTag.size() > 0) { 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 //key customerId:tagId
Map<String, Set<UpdateTagUseCountsResultDTO>> reCustomerTagMap = new HashMap<>(); Map<String, Set<UpdateTagUseCountsResultDTO>> reCustomerTagMap = new HashMap<>();
@ -172,9 +176,13 @@ public class TagServiceImpl implements TagService {
throw new RenException("网格标签数为空"); throw new RenException("网格标签数为空");
} }
customerTag.clear(); 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) { 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); Set<ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO>> typedTupleSet = customerTag.get(customerId);
if (typedTupleSet == null) { if (typedTupleSet == null) {
typedTupleSet = new HashSet<>(); typedTupleSet = new HashSet<>();
@ -245,7 +253,8 @@ public class TagServiceImpl implements TagService {
UpdateTagUseCountsResultDTO initTag = new UpdateTagUseCountsResultDTO(); UpdateTagUseCountsResultDTO initTag = new UpdateTagUseCountsResultDTO();
initTag.setTagId(id); initTag.setTagId(id);
initTag.setTagName(tagName); initTag.setTagName(tagName);
initTag.setTagColor(tagColor);
ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO> typedTuple1 = new DefaultTypedTuple<>(initTag, Double.valueOf(useCount)); ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO> typedTuple1 = new DefaultTypedTuple<>(initTag, Double.valueOf(useCount));
typedTupleSet.add(typedTuple1); 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];
}
}

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

@ -7,11 +7,12 @@
<selectKey keyProperty="id" order="AFTER" resultType="String"> <selectKey keyProperty="id" order="AFTER" resultType="String">
select id from tag_customer where tag_name = #{tagName} AND CUSTOMER_ID = #{customerId} select id from tag_customer where tag_name = #{tagName} AND CUSTOMER_ID = #{customerId}
</selectKey> </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 VALUES
(REPLACE ( UUID(), '-', '' ), (REPLACE ( UUID(), '-', '' ),
#{customerId}, #{customerId},
#{tagName}, #{tagName},
#{tagColor},
#{useCount}, #{useCount},
#{delFlag}, #{delFlag},
#{revision}, #{revision},
@ -26,11 +27,11 @@
<!-- 初始化默认标签 --> <!-- 初始化默认标签 -->
<insert id="initTags"> <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 VALUES
<foreach collection="tags" item="tag" separator=","> <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> </foreach>
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@ -41,6 +42,7 @@
ID, ID,
CUSTOMER_ID, CUSTOMER_ID,
TAG_NAME, TAG_NAME,
TAG_COLOR,
USE_COUNT USE_COUNT
FROM FROM
tag_customer tag_customer
@ -54,4 +56,4 @@
ORDER BY CUSTOMER_ID ORDER BY CUSTOMER_ID
</select> </select>
</mapper> </mapper>

Loading…
Cancel
Save