|
@@ -1,9 +1,13 @@
|
|
|
package com.fdkk.sxz.webApi.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.fdkk.sxz.base.impl.BaseServiceImpl;
|
|
|
import com.fdkk.sxz.entity.RenovationPartsColorEntity;
|
|
|
import com.fdkk.sxz.webApi.mapper.IRenovationPartsColorMapper;
|
|
|
import com.fdkk.sxz.webApi.service.IRenovationPartsColorService;
|
|
|
+import net.oschina.j2cache.CacheChannel;
|
|
|
+import net.oschina.j2cache.CacheObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -13,9 +17,42 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
*/
|
|
|
@Service
|
|
|
@Transactional
|
|
|
-public class RenovationPartsColorServiceImpl extends BaseServiceImpl<IRenovationPartsColorMapper , RenovationPartsColorEntity> implements IRenovationPartsColorService{
|
|
|
+public class RenovationPartsColorServiceImpl extends BaseServiceImpl<IRenovationPartsColorMapper, RenovationPartsColorEntity> implements IRenovationPartsColorService {
|
|
|
|
|
|
+ private String region = "RenovationPartsColorEntity";
|
|
|
@Autowired
|
|
|
- private IRenovationPartsColorMapper mapper;
|
|
|
+ private CacheChannel cacheChannel;
|
|
|
|
|
|
+ @Override
|
|
|
+ public RenovationPartsColorEntity findById(Long id) {
|
|
|
+ RenovationPartsColorEntity entity = null;
|
|
|
+ if (cacheChannel.exists(region, "id::" + id)) {
|
|
|
+ CacheObject cache = cacheChannel.get(region, "id::" + id);
|
|
|
+ entity = BeanUtil.toBean(cache.getValue(), RenovationPartsColorEntity.class);
|
|
|
+ } else {
|
|
|
+ entity = super.findById(entity);
|
|
|
+ if (ObjectUtil.isNotNull(entity)) {
|
|
|
+ cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean updateById(RenovationPartsColorEntity entity) {
|
|
|
+ boolean updateById = super.updateById(entity);
|
|
|
+ if (updateById) {
|
|
|
+ cacheChannel.set(region, "id::" + entity.getId(), entity, 60 * 30);
|
|
|
+ }
|
|
|
+ return updateById;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean removeById(Long id) {
|
|
|
+ boolean removeById = super.removeById(id);
|
|
|
+ if (removeById) {
|
|
|
+ cacheChannel.evict(region, "id::" + id);
|
|
|
+ }
|
|
|
+ return removeById;
|
|
|
+ }
|
|
|
}
|