Browse Source

政府端初始化默认标签

dev_shibei_match
zxc 5 years ago
parent
commit
15b647eb08
  1. 56
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/InitTagsFormDTO.java
  2. 10
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagCustomerDao.java
  3. 9
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/TagDefaultDao.java
  4. 21
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java
  5. 46
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java
  6. 11
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagCustomerDao.xml
  7. 4
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagDefaultDao.xml

56
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";
}

10
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<TagCustomerEntity> {
*/
void checkTagInfo(UpdateTagFormDTO formDTO);
/**
* @Description 初始化默认标签
* @param tags
* @author zxc
*/
void initTags(@Param("tags") List<InitTagsFormDTO> tags);
}

9
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<TagDefaultEntity> {
/**
* @Description 获取默认标签
* @param
* @author zxc
*/
List<String> selectDefaultTags();
}

21
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<List>() {
@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 更新标签级联

46
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<TagInfoResultDTO> tagList(TokenDto tokenDto) {
String customerId = tokenDto.getCustomerId();
List<TagInfoResultDTO> 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<TagInfoResultDTO> initTags(String customerId){
List<InitTagsFormDTO> tags = new ArrayList<>();
List<UpdateTagUseCountsResultDTO> initCacheTags = new ArrayList<>();
List<String> 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

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

@ -24,4 +24,15 @@
UPDATED_BY = #{updatedBy};
</insert>
<!-- 初始化默认标签 -->
<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 )
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()
)
</foreach>
</insert>
</mapper>

4
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/TagDefaultDao.xml

@ -3,5 +3,9 @@
<mapper namespace="com.epmet.dao.TagDefaultDao">
<!-- 获取默认标签 -->
<select id="selectDefaultTags" resultType="java.lang.String">
SELECT tag_name AS tagName FROM tag_default WHERE del_flag = 0
</select>
</mapper>
Loading…
Cancel
Save