From 9d35ba657fa5e3add766405d76e3ff8c4dcd4ad4 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 04 七月 2020 15:38:00 +0800 Subject: [PATCH] 多系统兼容优化 --- fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassServiceImpl.java | 307 +++++++++++++++++++++++++++------------------------ 1 files changed, 162 insertions(+), 145 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassServiceImpl.java index beaacbc..ce8e96c 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassServiceImpl.java @@ -5,6 +5,9 @@ import javax.annotation.Resource; +import com.yeshi.fanli.dao.mybatis.brand.BrandClassSystemMapMapper; +import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.entity.brand.BrandClassSystemMap; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; @@ -18,154 +21,168 @@ @Service public class BrandClassServiceImpl implements BrandClassService { - - @Resource - private BrandClassMapper brandClassMapper; - - @Resource - private GoodsClassService goodsClassService; - @Resource - private BrandClassShopService brandClassShopService; - - - @Override - public BrandClass selectByPrimaryKey(Long id) { - return brandClassMapper.selectByPrimaryKey(id); - } - - - @Override - public List<BrandClass> listEffective() { - return brandClassMapper.listEffective(); - } + @Resource + private BrandClassMapper brandClassMapper; - - @Override - @Cacheable(value = "brandCache", key = "'listBrandClassEffectiveCache'") - public List<BrandClass> listBrandClassEffectiveCache() { - return brandClassMapper.listEffective(); - } + @Resource + private GoodsClassService goodsClassService; - - @Override - public void saveObject(BrandClass record) throws BrandClassException, Exception{ - Long gcid = record.getGcid(); - if (gcid != null) - record.setGoodsClass(new GoodsClass(gcid)); - - String name = record.getName(); - if (name == null || name.trim().length() == 0) - throw new BrandClassException(1, "鍚嶇О鍜屽垎绫讳笉鑳藉悓鏃朵负绌�"); - - Integer state = record.getState(); - if (state == null) - record.setState(0); - - record.setUpdateTime(new Date()); - - Long id = record.getId(); - if (id == null) { - record.setOrderBy(brandClassMapper.getMaxOrder() + 1); - record.setCreateTime(new Date()); - brandClassMapper.insert(record); - } else { - BrandClass resultObj = brandClassMapper.selectByPrimaryKey(id); - if (resultObj == null) - throw new BrandClassException(1, "淇敼鍐呭宸蹭笉瀛樺湪"); - record.setOrderBy(resultObj.getOrderBy()); - record.setCreateTime(resultObj.getCreateTime()); - brandClassMapper.updateByPrimaryKey(record); - } - } - - - @Override - public void switchState(Long id) throws BrandClassException { - if (id == null) { - throw new BrandClassException(1, "璇蜂紶閫掓纭弬鏁�"); - } - BrandClass resultObj = brandClassMapper.selectByPrimaryKey(id); - if (resultObj == null) { - throw new BrandClassException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�"); - } - - Integer state = resultObj.getState(); - if (state == null || state == 0) { - state = 1; - } else { - state = 0; - } - - BrandClass updateObj = new BrandClass(); - updateObj.setId(id); - updateObj.setState(state); - brandClassMapper.updateByPrimaryKeySelective(updateObj); - } - - - - @Override - public void updateOrder(Long id, Integer moveType) throws BrandClassException, Exception{ - if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) - throw new BrandClassException(1, "浼犻�掔殑绫诲瀷涓嶆纭�"); - - if (id == null) - throw new BrandClassException(1, "ID涓嶈兘涓虹┖"); - - BrandClass resultObj = brandClassMapper.selectByPrimaryKey(id); - if (resultObj == null) - throw new BrandClassException(1, "鎿嶄綔鏁版嵁宸蹭笉瀛樺湪"); - - Integer oldOrder = resultObj.getOrderBy(); - BrandClass changeObj = brandClassMapper.getByAdjoinOrder(oldOrder, moveType); - - if (changeObj == null ) - throw new BrandClassException(1, "宸茬粡鍦ㄦ渶杈圭紭锛屾棤鍙氦鎹㈢殑浣嶇疆"); - - // 浜ゆ崲鎺掑簭搴忓彿 - resultObj.setOrderBy(changeObj.getOrderBy()); - changeObj.setOrderBy(oldOrder); - - brandClassMapper.updateByPrimaryKeySelective(changeObj); - brandClassMapper.updateByPrimaryKeySelective(resultObj); - } - - - @Override - public int deleteBatchByPrimaryKey(List<Long> list) { - return brandClassMapper.deleteBatchByPrimaryKey(list); - } - - - @Override - public List<BrandClass> listQuery(long start, int count, String key, Integer state) { - List<BrandClass> listQuery = brandClassMapper.listQuery(start, count, key, state); - if (listQuery == null || listQuery.size() == 0) { - return listQuery; - } - - for (BrandClass brandClass : listQuery) { - GoodsClass goodsClass = brandClass.getGoodsClass(); - if (goodsClass != null) { - GoodsClass baseClass = goodsClassService.selectByPrimaryKey(goodsClass.getId()); - if(baseClass != null) { - brandClass.setGcid(goodsClass.getId()); - brandClass.setGcName(baseClass.getName()); - } - } - } - return listQuery; - } + @Resource + private BrandClassSystemMapMapper brandClassSystemMapMapper; - @Override - public long countQuery(String key, Integer state) { - return brandClassMapper.countQuery(key, state); - } - - - - - + @Override + public BrandClass selectByPrimaryKey(Long id) { + return brandClassMapper.selectByPrimaryKey(id); + } + + + @Override + public List<BrandClass> listEffective(SystemEnum system) { + return brandClassMapper.listEffective(system); + } + + + @Override + @Cacheable(value = "brandCache", key = "'listBrandClassEffectiveCache-'+#system") + public List<BrandClass> listBrandClassEffectiveCache(SystemEnum system) { + return listEffective(system); + } + + + @Override + public void saveObject(BrandClass record, List<SystemEnum> systemList) throws BrandClassException, Exception { + Long gcid = record.getGcid(); + if (gcid != null) + record.setGoodsClass(new GoodsClass(gcid)); + + String name = record.getName(); + if (name == null || name.trim().length() == 0) + throw new BrandClassException(1, "鍚嶇О鍜屽垎绫讳笉鑳藉悓鏃朵负绌�"); + + Integer state = record.getState(); + if (state == null) + record.setState(0); + + record.setUpdateTime(new Date()); + + Long id = record.getId(); + if (id == null) { + record.setOrderBy(brandClassMapper.getMaxOrder() + 1); + record.setCreateTime(new Date()); + brandClassMapper.insert(record); + //娣诲姞鏄犲皠 + if (systemList != null) + for (SystemEnum system : systemList) { + BrandClassSystemMap map=new BrandClassSystemMap(); + map.setBrandClass(record); + map.setCreateTime(new Date()); + map.setSystem(system); + brandClassSystemMapMapper.insertSelective(map); + } + } else { + BrandClass resultObj = brandClassMapper.selectByPrimaryKey(id); + if (resultObj == null) + throw new BrandClassException(1, "淇敼鍐呭宸蹭笉瀛樺湪"); + record.setOrderBy(resultObj.getOrderBy()); + record.setCreateTime(resultObj.getCreateTime()); + brandClassMapper.updateByPrimaryKey(record); + } + } + + + @Override + public void switchState(Long id) throws BrandClassException { + if (id == null) { + throw new BrandClassException(1, "璇蜂紶閫掓纭弬鏁�"); + } + BrandClass resultObj = brandClassMapper.selectByPrimaryKey(id); + if (resultObj == null) { + throw new BrandClassException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�"); + } + + Integer state = resultObj.getState(); + if (state == null || state == 0) { + state = 1; + } else { + state = 0; + } + + BrandClass updateObj = new BrandClass(); + updateObj.setId(id); + updateObj.setState(state); + brandClassMapper.updateByPrimaryKeySelective(updateObj); + } + + + @Override + public void updateOrder(Long id, Integer moveType, SystemEnum system) throws BrandClassException, Exception { + if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) + throw new BrandClassException(1, "浼犻�掔殑绫诲瀷涓嶆纭�"); + + if (id == null) + throw new BrandClassException(1, "ID涓嶈兘涓虹┖"); + + BrandClass resultObj = brandClassMapper.selectByPrimaryKey(id); + if (resultObj == null) + throw new BrandClassException(1, "鎿嶄綔鏁版嵁宸蹭笉瀛樺湪"); + + Integer oldOrder = resultObj.getOrderBy(); + BrandClass changeObj = brandClassMapper.getByAdjoinOrder(oldOrder, moveType); + + if (changeObj == null) + throw new BrandClassException(1, "宸茬粡鍦ㄦ渶杈圭紭锛屾棤鍙氦鎹㈢殑浣嶇疆"); + + // 浜ゆ崲鎺掑簭搴忓彿 + resultObj.setOrderBy(changeObj.getOrderBy()); + changeObj.setOrderBy(oldOrder); + + brandClassMapper.updateByPrimaryKeySelective(changeObj); + brandClassMapper.updateByPrimaryKeySelective(resultObj); + } + + + @Override + public int deleteBatchByPrimaryKey(List<Long> list) { + return brandClassMapper.deleteBatchByPrimaryKey(list); + } + + @Override + public void deleteSystemMapBatch(List<Long> list, SystemEnum system) { + List<BrandClassSystemMap> mapList = brandClassSystemMapMapper.listByClassIdsAndSystem(list, system); + if (mapList != null) { + for (BrandClassSystemMap map : mapList) + brandClassSystemMapMapper.deleteByPrimaryKey(map.getId()); + } + } + + + @Override + public List<BrandClass> listQuery(long start, int count, String key, Integer state, SystemEnum system) { + List<BrandClass> listQuery = brandClassMapper.listQuery(start, count, key, state,system); + if (listQuery == null || listQuery.size() == 0) { + return listQuery; + } + + for (BrandClass brandClass : listQuery) { + GoodsClass goodsClass = brandClass.getGoodsClass(); + if (goodsClass != null) { + GoodsClass baseClass = goodsClassService.selectByPrimaryKey(goodsClass.getId()); + if (baseClass != null) { + brandClass.setGcid(goodsClass.getId()); + brandClass.setGcName(baseClass.getName()); + } + } + } + return listQuery; + } + + + @Override + public long countQuery(String key, Integer state, SystemEnum system) { + return brandClassMapper.countQuery(key, state,system); + } + + } -- Gitblit v1.8.0