admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopGoodsClassServiceImpl.java
@@ -1,22 +1,78 @@
package com.yeshi.fanli.service.impl.shop;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.shop.BanLiShopGoodsClassMapper;
import com.yeshi.fanli.entity.shop.BanLiShopGoodsClass;
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsClassService;
@Service
public class BanLiShopGoodsClassServiceImpl implements BanLiShopGoodsClassService {
   @Resource
   private BanLiShopGoodsClassMapper banLiShopGoodsClassMapper;
   @Override
   public BanLiShopGoodsClass selectByPrimaryKey(Long id) {
      return banLiShopGoodsClassMapper.selectByPrimaryKey(id);
   }
}
package com.yeshi.fanli.service.impl.shop;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.yeshi.utils.tencentcloud.COSManager;
import com.yeshi.fanli.dao.mybatis.shop.BanLiShopGoodsClassMapper;
import com.yeshi.fanli.entity.shop.BanLiShopGoodsClass;
import com.yeshi.fanli.exception.shop.BanLiShopGoodsClassException;
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsClassService;
import com.yeshi.fanli.util.StringUtil;
@Service
public class BanLiShopGoodsClassServiceImpl implements BanLiShopGoodsClassService {
   @Resource
   private BanLiShopGoodsClassMapper banLiShopGoodsClassMapper;
   @Override
   public BanLiShopGoodsClass selectByPrimaryKey(Long id) {
      return banLiShopGoodsClassMapper.selectByPrimaryKey(id);
   }
   @Override
   public List<BanLiShopGoodsClass> listAllGoodsClass() {
      return banLiShopGoodsClassMapper.listAllGoodsClass();
   }
   @Override
   public List<BanLiShopGoodsClass> listGoodsClass(int page, int pageSize, String key) {
      return banLiShopGoodsClassMapper.listGoodsClass((page - 1) * pageSize, pageSize, key);
   }
   @Override
   public long countGoodsClass(String key) {
      return banLiShopGoodsClassMapper.countGoodsClass(key);
   }
   @Override
   public void save( BanLiShopGoodsClass record) throws BanLiShopGoodsClassException {
      String name = record.getName();
      if (StringUtil.isNullOrEmpty(name))
         throw new BanLiShopGoodsClassException(1, "名称不能为空");
      record.setUpdateTime(new Date());
      if (record.getId() == null) {
         record.setCreateTime(new Date());
         banLiShopGoodsClassMapper.insert(record);
      } else {
         BanLiShopGoodsClass resultObj = banLiShopGoodsClassMapper.selectByPrimaryKey(record.getId());
         if (resultObj == null)
            throw new BanLiShopGoodsClassException(1, "修改内容已不存在");
         if (StringUtil.isNullOrEmpty(record.getPicture())) {
            record.setPicture(resultObj.getPicture());
         } else if (!StringUtil.isNullOrEmpty(resultObj.getPicture())) {
            COSManager.getInstance().deleteFile(resultObj.getPicture());
         }
         record.setCreateTime(resultObj.getCreateTime());
         banLiShopGoodsClassMapper.updateByPrimaryKey(record);
      }
   }
   @Override
   public void delete(List<Long> idsList) {
      if (idsList != null)
         for (Long id : idsList)
            banLiShopGoodsClassMapper.deleteByPrimaryKey(id);
   }
}