Browse Source

项目标签保存接口修改

dev_shibei_match
wangchao 5 years ago
parent
commit
e454251fcf
  1. 21
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueProjectTagDictDao.java
  2. 21
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java
  3. 52
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectTagDictServiceImpl.java
  4. 31
      epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueProjectTagDictDao.xml

21
epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueProjectTagDictDao.java

@ -44,6 +44,17 @@ public interface IssueProjectTagDictDao extends BaseDao<IssueProjectTagDictEntit
*/
void updateTagsUseCount(@Param("tags") List<IssueTagFormDTO> tags,@Param("customerId")String customerId,@Param("status")String status);
/**
* @Description 更新标签使用次数
* @param tagIds
* @param customerId
* @param score
* @return void
* @author wangc
* @date 2020.12.14 09:33
*/
void updateTagUsage(@Param("tagIds") List<String> tagIds,@Param("customerId")String customerId,@Param("score") Integer score);
/**
* @Description 查询标签ID
* @Param newTags
@ -81,4 +92,14 @@ public interface IssueProjectTagDictDao extends BaseDao<IssueProjectTagDictEntit
* @date 2020.12.10 10:07
*/
List<IssueProjectTagDictEntity> selectTagByCategory(@Param("categories") List<String> categories,@Param("customerId") String customerId,@Param("isDefault")String isDefault);
/**
* @Description 根据客户Id和标签Id集合查询标签的基础信息(标签名标签码标签所属分类)
* @param customerId
* @param tagIds
* @return java.util.List<com.epmet.entity.IssueProjectTagDictEntity>
* @author wangc
* @date 2020.12.13 14:23
*/
List<IssueProjectTagDictEntity> selectTagsByCustomerIdAndTagIds(@Param("customerId") String customerId,@Param("tagIds")List<String> tagIds);
}

21
epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java

@ -39,6 +39,7 @@ import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import sun.security.krb5.internal.PAData;
import java.util.*;
import java.util.stream.Collectors;
@ -348,6 +349,26 @@ public class IssueProjectTagDictRedis {
redisUtils.zSetAdd(key,o);
}
public void batchIncrScore(Map<String,Map<String,List<IssueCategoryTagResultDTO>>> param){
if(CollectionUtils.isEmpty(param)) return;
redisTemplate.executePipelined((RedisCallback) connection -> {
param.forEach((operation,map) -> {
if(!CollectionUtils.isEmpty(map)){
map.forEach((key,list) -> {
if(!CollectionUtils.isEmpty(list)){
list.forEach(obj -> {
connection.zSetCommands().zIncrBy(redisTemplate.getKeySerializer().serialize(key),
StringUtils.equals(NumConstant.ONE_STR,operation) ? 1d : -1d ,
redisTemplate.getValueSerializer().serialize(obj));
});
}
});
}
});
return null;
});
}
public <T> T parseObject(Object o,Class<T> clazz){
ObjectMapper objectMapper = new ObjectMapper();
T t = objectMapper.convertValue(o, clazz);

52
epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueProjectTagDictServiceImpl.java

@ -25,11 +25,13 @@ import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.constant.GovIssueRedisKeys;
import com.epmet.dao.IssueProjectTagDictDao;
import com.epmet.dto.IssueProjectTagDictDTO;
import com.epmet.dto.form.TagDifferentSetFormDTO;
import com.epmet.dto.form.TagListFormDTO;
import com.epmet.dto.result.IssueCategoryTagResultDTO;
import com.epmet.dto.result.IssueProjectTagsResultDTO;
import com.epmet.dto.result.TagListResultDTO;
import com.epmet.entity.IssueProjectTagDictEntity;
import com.epmet.redis.IssueProjectTagDictRedis;
@ -152,8 +154,58 @@ public class IssueProjectTagDictServiceImpl extends BaseServiceImpl<IssueProject
* @date 2020.12.11 14:00
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateTagHeat(TagDifferentSetFormDTO param) {
//key : 1(plus) 0(minus)
//value : {
// key : redisKey
// value : List<Obj>
// }
Map<String,Map<String,List<IssueCategoryTagResultDTO>>> redisParam = new HashMap<>();
if(CollectionUtils.isNotEmpty(param.getMinus())){
List<IssueProjectTagDictEntity> tags = baseDao.selectTagsByCustomerIdAndTagIds(param.getCustomerId(),param.getMinus());
if(CollectionUtils.isNotEmpty(tags)){
Map<String,List<IssueCategoryTagResultDTO>> value = new HashMap<>();
tags.forEach(tag -> {
String redisKey = GovIssueRedisKeys.getGovernmentTagKey(param.getCustomerId(),tag.getCategoryId());
IssueCategoryTagResultDTO cache = new IssueCategoryTagResultDTO();
cache.setId(tag.getId());cache.setName(tag.getTagName());
if(CollectionUtils.isNotEmpty(value.get(redisKey))){
value.get(redisKey).add(cache);
}else{
List<IssueCategoryTagResultDTO> list = new LinkedList<>();
list.add(cache);
value.put(redisKey,list);
}
});
if(!value.isEmpty()) redisParam.put(NumConstant.ZERO_STR,value);
baseDao.updateTagUsage(param.getMinus(),param.getCustomerId(),NumConstant.ONE_NEG);
}
}
if(CollectionUtils.isNotEmpty(param.getPlus())){
List<IssueProjectTagDictEntity> tags = baseDao.selectTagsByCustomerIdAndTagIds(param.getCustomerId(),param.getPlus());
if(CollectionUtils.isNotEmpty(tags)){
Map<String,List<IssueCategoryTagResultDTO>> value = new HashMap<>();
tags.forEach(tag -> {
String redisKey = GovIssueRedisKeys.getGovernmentTagKey(param.getCustomerId(),tag.getCategoryId());
IssueCategoryTagResultDTO cache = new IssueCategoryTagResultDTO();
cache.setId(tag.getId());cache.setName(tag.getTagName());
if(CollectionUtils.isNotEmpty(value.get(redisKey))){
value.get(redisKey).add(cache);
}else{
List<IssueCategoryTagResultDTO> list = new LinkedList<>();
list.add(cache);
value.put(redisKey,list);
}
});
if(!value.isEmpty()) redisParam.put(NumConstant.ONE_STR,value);
baseDao.updateTagUsage(param.getPlus(),param.getCustomerId(),NumConstant.ONE);
}
}
issueProjectTagDictRedis.batchIncrScore(redisParam);
}
}

31
epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueProjectTagDictDao.xml

@ -21,6 +21,22 @@
</where>
</update>
<update id="updateTagUsage">
UPDATE issue_project_tag_dict
SET issue_use_count = (CASE
WHEN issue_use_count IS NULL THEN IF(#{score} > 0 ,#{score} ,0)
WHEN issue_use_count <![CDATA[<]]> 0 THEN 0
ELSE issue_use_count + #{score} END)
<where>
del_flag = 0
AND
customer_id = #{customerId}
<foreach collection="tagIds" item="tagId" open=" AND ( " separator=" OR " close=" ) ">
id = #{tagId}
</foreach>
</where>
</update>
<!-- 查询标签ID -->
<select id="selectTagId" resultType="com.epmet.dto.form.IssueTagFormDTO">
SELECT ID AS tagId,
@ -104,4 +120,19 @@
, CONVERT ( tag.TAG_NAME USING gbk )
</select>
<!-- 根据客户Id和标签Id集合查询标签的基础信息(标签名、标签码,标签所属分类) -->
<select id="selectTagsByCustomerIdAndTagIds" resultType="com.epmet.entity.IssueProjectTagDictEntity">
SELECT
*
FROM
issue_project_tag_dict
WHERE
del_flag = '0'
AND customer_id = #{customerId}
<if test="null != tagIds and tagIds.size() > 0">
<foreach collection="tagIds" item="tagId" open=" AND (" separator=" OR " close=" )">
ID = #{tagId}
</foreach>
</if>
</select>
</mapper>
Loading…
Cancel
Save