admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassServiceImpl.java
@@ -1,188 +1,188 @@
package com.yeshi.fanli.service.impl.brand;
import java.util.Date;
import java.util.List;
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;
import com.yeshi.fanli.dao.mybatis.brand.BrandClassMapper;
import com.yeshi.fanli.entity.brand.BrandClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.exception.brand.BrandClassException;
import com.yeshi.fanli.service.inter.brand.BrandClassService;
import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
import com.yeshi.fanli.service.inter.goods.GoodsClassService;
@Service
public class BrandClassServiceImpl implements BrandClassService {
    @Resource
    private BrandClassMapper brandClassMapper;
    @Resource
    private GoodsClassService goodsClassService;
    @Resource
    private BrandClassSystemMapMapper brandClassSystemMapMapper;
    @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);
    }
}
package com.yeshi.fanli.service.impl.brand;
import java.util.Date;
import java.util.List;
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;
import com.yeshi.fanli.dao.mybatis.brand.BrandClassMapper;
import com.yeshi.fanli.entity.brand.BrandClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.exception.brand.BrandClassException;
import com.yeshi.fanli.service.inter.brand.BrandClassService;
import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
import com.yeshi.fanli.service.inter.goods.GoodsClassService;
@Service
public class BrandClassServiceImpl implements BrandClassService {
    @Resource
    private BrandClassMapper brandClassMapper;
    @Resource
    private GoodsClassService goodsClassService;
    @Resource
    private BrandClassSystemMapMapper brandClassSystemMapMapper;
    @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);
    }
}