yujian
2020-01-18 f4a0f2acc63d7785eab108419a4e16f5f688cb95
fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopGoodsClassServiceImpl.java
@@ -1,12 +1,18 @@
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 {
@@ -19,4 +25,54 @@
      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);
   }
}