| | |
| | | import com.moral.api.service.UnitConversionService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.ConvertUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | |
| | | UnitConversionMapper unitConversionMapper; |
| | | @Autowired |
| | | SysDictDataService sysDictDataService; |
| | | @Autowired |
| | | RedisTemplate redisTemplate; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | } |
| | | //插入数据 |
| | | unitConversionMapper.insert(unitConversion); |
| | | //刷新缓存 |
| | | refreshCache(); |
| | | //封装返回数据 |
| | | dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); |
| | |
| | | oldUnitConversion = unitConversionMapper.selectOne(oldWrapper); |
| | | //更新 |
| | | unitConversionMapper.updateById(unitConversion); |
| | | //刷新缓存 |
| | | refreshCache(); |
| | | //封装返回结果 |
| | | dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); |
| | |
| | | deleteWrapper.set("is_delete", Constants.DELETE); |
| | | deleteWrapper.eq("id", id); |
| | | unitConversionMapper.update(null, deleteWrapper); |
| | | //刷新缓存 |
| | | refreshCache(); |
| | | //封装返回对象 |
| | | dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); |
| | | dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); |
| | | return dto; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | int[] array = new int[]{1,2,3,4,5,}; |
| | | String s = JSON.toJSONString(array); |
| | | System.out.println(s); |
| | | /*刷新缓存*/ |
| | | @Override |
| | | public void refreshCache(){ |
| | | redisTemplate.delete((RedisConstants.UNIT_CONVERSION)); |
| | | QueryWrapper<UnitConversion> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | List<UnitConversion> unitConversions = unitConversionMapper.selectList(queryWrapper); |
| | | redisTemplate.opsForList().leftPushAll(RedisConstants.UNIT_CONVERSION,unitConversions); |
| | | } |
| | | } |