yujian
2020-05-23 28cf328a098334b51a3e9d2d56f983fb8c862211
fanli/src/main/java/com/yeshi/fanli/service/impl/lable/LabelServiceImpl.java
@@ -10,14 +10,12 @@
import java.util.UUID;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import jxl.Sheet;
import jxl.Workbook;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.yeshi.utils.tencentcloud.COSManager;
import com.yeshi.fanli.dao.mybatis.lable.LabelClassMapper;
import com.yeshi.fanli.dao.mybatis.lable.LabelGoodsMapper;
@@ -25,19 +23,19 @@
import com.yeshi.fanli.entity.bus.lable.Label;
import com.yeshi.fanli.entity.bus.lable.LabelGoods;
import com.yeshi.fanli.entity.common.AdminUser;
import com.yeshi.fanli.exception.LabelException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.exception.goods.quality.LabelException;
import com.yeshi.fanli.service.inter.lable.LabelService;
import com.yeshi.fanli.util.FilePathEnum;
import com.yeshi.fanli.util.StringUtil;
import org.yeshi.utils.tencentcloud.COSManager;
import jxl.Sheet;
import jxl.Workbook;
@Service
public class LabelServiceImpl implements LabelService {
   @Resource
   private LabelMapper labelMapper;
   @Resource
   private LabelService labelService;
   
   @Resource
   private LabelGoodsMapper labelGoodsMapper;
@@ -52,7 +50,7 @@
   }
   @Override
   @Transactional
   @Transactional(rollbackFor=Exception.class)
   public void insertList(List<Label>  records,AdminUser admin) throws LabelException{
      if (records != null && records.size() > 0) {
         for (Label label : records) {
@@ -92,14 +90,14 @@
      
      // 上传图片
      if (file != null) {
         labelService.uploadPicture(file, label);
         uploadPicture(file, label);
      }
            
      
   }
   
   @Override
   @Transactional
   @Transactional(rollbackFor=Exception.class)
   public void updateList(List<Label>  records) throws LabelException{
      if (records != null && records.size() > 0) {
         for (Label label : records) {
@@ -128,19 +126,19 @@
   
   @Override
   @Transactional
   @Transactional(rollbackFor=Exception.class)
   public int deleteBatchById(long[] ids) throws LabelException{
      return labelMapper.deleteBatchByPrimaryKey(ids);
   }
   @Override
   @Transactional
   @Transactional(rollbackFor=Exception.class)
   public void deleteBatchByPrimaryKey(List<Long> ids) throws LabelException {
      for (Long id : ids) {
         Label label = labelMapper.selectByPrimaryKey(id);
         if (label != null) {
            // 删除图片
            labelService.deleteImg(label);
            deleteImg(label);
            // 删除数据信息
            labelMapper.deleteByPrimaryKey(id);
            
@@ -159,14 +157,21 @@
   
   @Override
   public List<Label> selectByTitle(String title) throws LabelException{
      LogHelper.test("查询标签:  "+title);
      return labelMapper.selectByTitle(title);
   }
   @Override
   @Cacheable(value = "labelCache",key="'selectByTitleCache-'+#labKey +'-'+#title")
   public List<Label> selectByTitleCache(String labKey, String title) throws LabelException{
      return selectByTitle(title);
   @Cacheable(value = "labelCache",key="'getByTitleCache-'+#labKey +'-'+#title")
   public Label getByTitleCache(String labKey, String title) throws LabelException{
      return labelMapper.getByTitle(title);
   }
   @Override
   @Cacheable(value = "labelCache",key="'listByTitlesCache-'+#list")
   public List<Label> listByTitlesCache(List<String> list){
      return labelMapper.listByTitles(list);
   }
   
   
@@ -215,7 +220,7 @@
         
         for (String title : titles) {
            
            List<Label> labels = labelService.selectByTitle(title.trim());
            List<Label> labels = selectByTitle(title.trim());
            // 若已存在则不存入数据库
            if (labels == null || labels.size() == 0) {
               Label label = new Label();
@@ -226,7 +231,7 @@
               label.setUpdatetime(nowTime);
               label.setCreateUser(admin);
               
               labelService.insertSelective(label);
               insertSelective(label);
            }
         }
@@ -241,7 +246,7 @@
      String contentType = file.getContentType();
      String type = contentType.substring(contentType.indexOf("/") + 1);
      // 上传文件相对位置
      String fileUrl="LableImg/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
      String fileUrl=FilePathEnum.lable.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type;
      
      boolean deleteFile =true;
      
@@ -266,7 +271,7 @@
            label.setPicture(uploadFilePath);
            label.setUpdatetime(nowTime);
            
            result = labelService.updateByPrimaryKeySelective(label);
            result = updateByPrimaryKeySelective(label);
         }
      }
      
@@ -295,7 +300,7 @@
            label.setPicture(null);
            label.setUpdatetime(nowTime);
            // 更新数据库
            result = labelService.updateByPrimaryKey(label);
            result = updateByPrimaryKey(label);
         }
         
      }
@@ -366,7 +371,7 @@
      
      for (String title : arrtitles) {
         /* 遍历标签名称:查询数据库中是否已存在 */
         List<Label> labels = labelService.selectByTitle(title.trim());
         List<Label> labels = selectByTitle(title.trim());
         if (labels != null && labels.size() > 0) {
            Label label = labels.get(0);
            listLabs.add(label);
@@ -380,7 +385,7 @@
            label.setCreateUser(admin);
            label.setIosClick(0l);
            label.setAndroidClick(0l);
            labelService.insertSelective(label);
            insertSelective(label);
            
            listLabs.add(label);
         }