Commit a42e4708 authored by libin's avatar libin

随车物品

parent 8c345442
......@@ -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(){
......@@ -75,6 +87,7 @@ public class AccompanyingItemBiz extends BaseBiz<AccompanyingItemMapper, Accompa
accompanyingItem.setId(null);
BeanUtils.copyProperties(accompanyingItem,addOrUpdateAccompanyingItem);
Integer effected = mapper.insertSelective(accompanyingItem);
redisTemplate.delete(ACCOMPANY_ITEM);
return RestResponse.suc();
}
......@@ -83,17 +96,33 @@ public class AccompanyingItemBiz extends BaseBiz<AccompanyingItemMapper, Accompa
AccompanyingItem accompanyingItem = new AccompanyingItem();
BeanUtils.copyProperties(accompanyingItem,addOrUpdateAccompanyingItem);
Integer effected = mapper.updateByPrimaryKeySelective(accompanyingItem);
redisTemplate.delete(ACCOMPANY_ITEM);
return RestResponse.suc();
}
@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();
}
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);
......@@ -112,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