Commit 6e5b961e authored by 周健威's avatar 周健威

Merge remote-tracking branch 'origin/base-modify' into base-modify

parents 357a9573 d7c5d76d
......@@ -2,6 +2,8 @@ package com.xxfc.platform.vehicle.biz;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
......@@ -16,20 +18,30 @@ import com.xxfc.platform.vehicle.pojo.vo.AccompanyingItemVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
public class AccompanyingItemBiz extends BaseBiz<AccompanyingItemMapper, AccompanyingItem> {
@Autowired
private RedisTemplate redisTemplate;
@Resource(name = "redisTemplate")
HashOperations itemHashOperations;
private static final String ACCOMPANY_ITEM="accompany:item";
@Cache(key = RedisKey.ACCOMPANYING_ITEM_CACHE_ALL)
public List<AccompanyingItem> getAll(){
......@@ -69,31 +81,49 @@ public class AccompanyingItemBiz extends BaseBiz<AccompanyingItemMapper, Accompa
return PageDataVO.pageInfo(accompanyingItemsPageInfo);
}
@CacheClear(pre= RedisKey.ACCOMPANYING_ITEM_CACHE_ALL)
@CacheClear(key= RedisKey.ACCOMPANYING_ITEM_CACHE_ALL)
public RestResponse<Integer> add( AddOrUpdateAccompanyingItem addOrUpdateAccompanyingItem) throws Exception{
AccompanyingItem accompanyingItem = new AccompanyingItem();
accompanyingItem.setId(null);
BeanUtils.copyProperties(accompanyingItem,addOrUpdateAccompanyingItem);
Integer effected = mapper.insertSelective(accompanyingItem);
redisTemplate.delete(ACCOMPANY_ITEM);
return RestResponse.suc();
}
@CacheClear(pre= RedisKey.ACCOMPANYING_ITEM_CACHE_ALL)
@CacheClear(key= RedisKey.ACCOMPANYING_ITEM_CACHE_ALL)
public RestResponse<Integer> update( AddOrUpdateAccompanyingItem addOrUpdateAccompanyingItem) throws Exception{
AccompanyingItem accompanyingItem = new AccompanyingItem();
BeanUtils.copyProperties(accompanyingItem,addOrUpdateAccompanyingItem);
Integer effected = mapper.updateByPrimaryKeySelective(accompanyingItem);
redisTemplate.delete(ACCOMPANY_ITEM);
return RestResponse.suc();
}
@CacheClear(pre= RedisKey.ACCOMPANYING_ITEM_CACHE_ALL)
@CacheClear(key= RedisKey.ACCOMPANYING_ITEM_CACHE_ALL)
public RestResponse<Integer> del(Integer id){
Integer effected = mapper.deleteByPrimaryKey(id);
redisTemplate.delete(ACCOMPANY_ITEM);
return RestResponse.suc();
}
@Cache(key = RedisKey.ACCOMPANYING_ITEM_CACHE_ALL_APP+ "{1}")
public List<AccompanyingItemVo> listAllItem(List<Integer> types){
String typeKey = null;
if (CollectionUtils.isNotEmpty(types)){
typeKey = types.stream().sorted(Integer::compareTo).map(String::valueOf).reduce("",(x, y)-> x+":"+y);
String itemJson = (String) itemHashOperations.get(ACCOMPANY_ITEM,typeKey);
if (!StringUtils.isEmpty(itemJson)){
return JSON.parseObject(itemJson,new TypeReference<List<AccompanyingItemVo>>(){});
}
}
if (CollectionUtils.isEmpty(types)){
typeKey= "all";
String itemJson = (String) itemHashOperations.get(ACCOMPANY_ITEM, typeKey);
if (!StringUtils.isEmpty(itemJson)){
return JSON.parseObject(itemJson,new TypeReference<List<AccompanyingItemVo>>(){});
}
}
List<AccompanyingItemVo> accompanyingItemVos = new ArrayList<>();
Example example = new Example(AccompanyingItem.class);
Example.Criteria criteria = example.createCriteria();
......@@ -111,7 +141,7 @@ public class AccompanyingItemBiz extends BaseBiz<AccompanyingItemMapper, Accompa
org.springframework.beans.BeanUtils.copyProperties(item, accompanyingItemVo);
return accompanyingItemVo;
}).sorted(Comparator.comparing(AccompanyingItemVo::getType).thenComparing(AccompanyingItemVo::getRank)).collect(Collectors.toList());
itemHashOperations.put(ACCOMPANY_ITEM,typeKey,JSON.toJSONString(accompanyingItemVoList));
return accompanyingItemVoList;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment