From 15b647eb080e008d35d22b61f7de345f963f6a21 Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Mon, 8 Jun 2020 16:15:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=BF=E5=BA=9C=E7=AB=AF=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=BB=98=E8=AE=A4=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/dto/form/InitTagsFormDTO.java | 56 +++++++++++++++++++ .../java/com/epmet/dao/TagCustomerDao.java | 10 ++++ .../java/com/epmet/dao/TagDefaultDao.java | 9 +++ .../main/java/com/epmet/redis/TagRedis.java | 21 +++++++ .../epmet/service/impl/TagServiceImpl.java | 46 ++++++++++++++- .../main/resources/mapper/TagCustomerDao.xml | 11 ++++ .../main/resources/mapper/TagDefaultDao.xml | 4 ++ 7 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/InitTagsFormDTO.java 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 new file mode 100644 index 0000000000..ded8bc1f43 --- /dev/null +++ b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/InitTagsFormDTO.java @@ -0,0 +1,56 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @Author zxc + * @CreateTime 2020/6/8 14:39 + */ +@Data +public class InitTagsFormDTO implements Serializable { + + private static final long serialVersionUID = 5507978729190322412L; + + /** + * 主键ID + */ + private String id; + + /** + * 客户ID + */ + private String customerId; + + /** + * 标签名称 + */ + private String tagName; + + /** + * 使用计数 + */ + private Integer useCount = 0; + + /** + * 删除标识 0.未删除 1.已删除 + */ + private Integer delFlag = 0; + + /** + * 乐观锁 + */ + private Integer revision = 0; + + /** + * 创建人 + */ + private String createdBy = "default"; + + /** + * 更新人 + */ + private String updatedBy = "default"; +} 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 2c40c98331..4a837ca1a7 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 @@ -18,11 +18,14 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.form.InitTagsFormDTO; import com.epmet.dto.form.UpdateTagFormDTO; import com.epmet.entity.TagCustomerEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** * 客户标签表 * @@ -39,4 +42,11 @@ public interface TagCustomerDao extends BaseDao { */ void checkTagInfo(UpdateTagFormDTO formDTO); + /** + * @Description 初始化默认标签 + * @param tags + * @author zxc + */ + void initTags(@Param("tags") List tags); + } \ No newline at end of file diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagDefaultDao.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagDefaultDao.java index 4de3aae4bf..2c9ad87528 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagDefaultDao.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagDefaultDao.java @@ -21,6 +21,8 @@ import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.entity.TagDefaultEntity; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 默认标签表 * @@ -29,5 +31,12 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface TagDefaultDao extends BaseDao { + + /** + * @Description 获取默认标签 + * @param + * @author zxc + */ + List selectDefaultTags(); } \ No newline at end of file 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 2c61830779..47957e68dd 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 @@ -242,6 +242,27 @@ public class TagRedis { public Double updateTagUseCounts(String key, Object formDTO){ return redisUtils.zIncrementScore(key, formDTO, NumConstant.ONE); } + + /** + * @Description 初始化缓存标签 + * @param key + * @param list + * @author zxc + */ + public void initCacheTags(String key, List list){ + redisTemplate.executePipelined(new RedisCallback() { + @Override + public List doInRedis(RedisConnection connection) throws DataAccessException { + for (Object o : list) { + connection.zIncrBy( + redisTemplate.getKeySerializer().serialize(key), + NumConstant.ZERO, + redisTemplate.getValueSerializer().serialize(o)); + } + return null; + } + }); + } /** * @Description set 更新标签级联 diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java index 1a625c42d1..186b427914 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java @@ -2,19 +2,23 @@ package com.epmet.service.impl; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.constant.TagConstant; import com.epmet.dao.ArticleDao; -import com.epmet.dto.form.CorrelationTagListFormDTO; -import com.epmet.dto.form.ResiTagListFormDTO; -import com.epmet.dto.form.TagCascadeListFormDTO; +import com.epmet.dao.TagCustomerDao; +import com.epmet.dao.TagDefaultDao; +import com.epmet.dto.form.*; import com.epmet.dto.result.CorrelationTagListResultDTO; import com.epmet.dto.result.TagInfoResultDTO; +import com.epmet.dto.result.UpdateTagUseCountsResultDTO; import com.epmet.redis.TagRedis; import com.epmet.service.TagService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; +import java.util.UUID; @Service public class TagServiceImpl implements TagService { @@ -23,6 +27,10 @@ public class TagServiceImpl implements TagService { private TagRedis tagRedis; @Autowired private ArticleDao articleDao; + @Autowired + private TagDefaultDao tagDefaultDao; + @Autowired + private TagCustomerDao tagCustomerDao; /** * @Description 已发布列表页的标签——政府端 @@ -30,9 +38,13 @@ public class TagServiceImpl implements TagService { * @author zxc */ @Override + @Transactional(rollbackFor = Exception.class) public List tagList(TokenDto tokenDto) { String customerId = tokenDto.getCustomerId(); List resultDtos = tagRedis.zRevRange(customerId); + if (resultDtos.size() == NumConstant.ZERO){ + resultDtos = this.initTags(customerId); + } return resultDtos; } @@ -51,6 +63,34 @@ public class TagServiceImpl implements TagService { return tagRedis.zGridRevRange(formDto.getGridId()); } + /** + * @Description 初始化标签 + * @param customerId + * @author zxc + */ + public List initTags(String customerId){ + List tags = new ArrayList<>(); + List initCacheTags = new ArrayList<>(); + List tagNames = tagDefaultDao.selectDefaultTags(); + tagNames.forEach(tagName -> { + InitTagsFormDTO tagInfo = new InitTagsFormDTO(); + UpdateTagUseCountsResultDTO initTag = new UpdateTagUseCountsResultDTO(); + UUID uuid = UUID.randomUUID(); + String replaceUuid = uuid.toString().replace("-", ""); + tagInfo.setId(replaceUuid); + initTag.setTagId(replaceUuid); + tagInfo.setTagName(tagName); + initTag.setTagName(tagName); + tagInfo.setCustomerId(customerId); + tags.add(tagInfo); + initCacheTags.add(initTag); + }); + tagCustomerDao.initTags(tags); + String key = TagConstant.GOV_TAG_KEY+customerId; + tagRedis.initCacheTags(key,initCacheTags); + return tagRedis.zRevRange(customerId); + } + /** * @Description 已发布列表页-获取关联标签——政府端 * @param tokenDto 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 6520094e27..f1a9ed06ca 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 @@ -24,4 +24,15 @@ UPDATED_BY = #{updatedBy}; + + + INSERT INTO tag_customer ( ID, CUSTOMER_ID, TAG_NAME, 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() + ) + + + \ No newline at end of file diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagDefaultDao.xml b/epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagDefaultDao.xml index 4916e09728..d54d427024 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagDefaultDao.xml +++ b/epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagDefaultDao.xml @@ -3,5 +3,9 @@ + + \ No newline at end of file