|  | @@ -12,6 +12,7 @@ import com.kmall.common.utils.RRException;
 | 
	
		
			
				|  |  |  import com.kmall.common.utils.ValidatorUtil;
 | 
	
		
			
				|  |  |  import com.kmall.manager.manager.express.sf.ServiceException;
 | 
	
		
			
				|  |  |  import com.kmall.manager.manager.redis.JedisUtil;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
	
		
			
				|  | @@ -235,55 +236,48 @@ public class BrandServiceImpl implements BrandService {
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional
 | 
	
		
			
				|  |  |      public void uploadExcel(List<BrandEntity> brandEntityList) {
 | 
	
		
			
				|  |  | -        if (brandEntityList != null && brandEntityList.size() > 0) {
 | 
	
		
			
				|  |  | -            for (int i = 0; i < brandEntityList.size(); i++) {
 | 
	
		
			
				|  |  | -                BrandEntity brandEntity = brandEntityList.get(i);
 | 
	
		
			
				|  |  | -                Integer brandId = brandEntity.getId();
 | 
	
		
			
				|  |  | -                Integer isShow = brandEntity.getIsShow();
 | 
	
		
			
				|  |  | -                Integer isNew = brandEntity.getIsNew();
 | 
	
		
			
				|  |  | -                // 品牌唯一标识符正则校验
 | 
	
		
			
				|  |  | -                String uniqueIdentifier = brandEntity.getUniqueIdentifier();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                if (isShow.intValue() != 0 && isShow.intValue() != 1 && isNew.intValue() != 0 && isNew != 1) {
 | 
	
		
			
				|  |  | -                    throw new ServiceException("第" + (i + 1) + "行的是否显示或者是否新品牌只可填(0:否 1:是)");
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +        for (int i = 0; i < brandEntityList.size(); i++) {
 | 
	
		
			
				|  |  | +            BrandEntity brandEntity = brandEntityList.get(i);
 | 
	
		
			
				|  |  | +            String name = brandEntity.getName();
 | 
	
		
			
				|  |  | +            Integer isShow = brandEntity.getIsShow();
 | 
	
		
			
				|  |  | +            Integer isNew = brandEntity.getIsNew();
 | 
	
		
			
				|  |  | +            // 品牌唯一标识符正则校验
 | 
	
		
			
				|  |  | +            String uniqueIdentifier = brandEntity.getUniqueIdentifier();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (isShow.intValue() != 0 && isShow.intValue() != 1 && isNew.intValue() != 0 && isNew != 1) {
 | 
	
		
			
				|  |  | +                throw new ServiceException("第" + (i + 1) + "行的是否显示或者是否新品牌只可填(0:否 1:是)");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +            if (StringUtils.isNotBlank(uniqueIdentifier)) {
 | 
	
		
			
				|  |  | +                String regex = "(^[0-9a-zA-Z_&]{1,10}$)";
 | 
	
		
			
				|  |  | +                if (!Pattern.matches(regex, uniqueIdentifier)) {
 | 
	
		
			
				|  |  | +                    throw new RuntimeException("请输入正确的品牌唯一简码,有问题的简码:" + uniqueIdentifier);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +            // 数据库查询是否存在对应名字的对象
 | 
	
		
			
				|  |  | +            BrandEntity isExist = brandDao.queryByName(name);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                // 如果是0就添加数据
 | 
	
		
			
				|  |  | -                if (brandId.intValue() == 0) {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    String regex = "(^[0-9a-zA-Z_&]{1,10}$)";
 | 
	
		
			
				|  |  | -                    if(!Pattern.matches(regex,uniqueIdentifier)){
 | 
	
		
			
				|  |  | -                        throw new RuntimeException("请输入正确的品牌唯一简码,有问题的简码:"+uniqueIdentifier);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    // 如果是正确的,根据唯一简码查询该简码是否存在
 | 
	
		
			
				|  |  | -                    BrandEntity queryBrandEntity = brandDao.queryByUniqueIdentifier(uniqueIdentifier);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    if (Objects.nonNull(queryBrandEntity)){
 | 
	
		
			
				|  |  | -                        throw new ServiceException("第" + (i + 1) + "行的该品牌:【" + queryBrandEntity.getName() + "】已存在!");
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    BrandEntity insertBrandEntity = new BrandEntity();
 | 
	
		
			
				|  |  | -                    insertBrandEntity.setName(brandEntity.getName());
 | 
	
		
			
				|  |  | -                    insertBrandEntity.setSimpleDesc(brandEntity.getSimpleDesc());
 | 
	
		
			
				|  |  | -                    insertBrandEntity.setUniqueIdentifier(uniqueIdentifier);
 | 
	
		
			
				|  |  | -                    insertBrandEntity.setIsShow(isShow);
 | 
	
		
			
				|  |  | -                    insertBrandEntity.setIsNew(isNew);
 | 
	
		
			
				|  |  | -                    this.save(insertBrandEntity);
 | 
	
		
			
				|  |  | -                } else {
 | 
	
		
			
				|  |  | -                    String regex = "(^[0-9a-zA-Z_&]{1,10}$)";
 | 
	
		
			
				|  |  | -                    if(!Pattern.matches(regex,uniqueIdentifier)){
 | 
	
		
			
				|  |  | -                        throw new RuntimeException("请输入正确的品牌唯一简码,有问题的简码:"+uniqueIdentifier);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    BrandEntity updateBrandEntity = brandDao.queryObject(brandId);
 | 
	
		
			
				|  |  | -                    if (Objects.isNull(updateBrandEntity)) {
 | 
	
		
			
				|  |  | -                        throw new ServiceException("第" + (i + 1) + "行的该品牌编号:【" + brandId + "】不存在!");
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    BeanUtils.copyProperties(brandEntity,updateBrandEntity);
 | 
	
		
			
				|  |  | -                    this.update(updateBrandEntity);
 | 
	
		
			
				|  |  | +            // 不存在则添加
 | 
	
		
			
				|  |  | +            if (isExist == null) {
 | 
	
		
			
				|  |  | +                // 如果是正确的,根据唯一简码查询该简码是否存在
 | 
	
		
			
				|  |  | +                BrandEntity queryBrandEntity = brandDao.queryByUniqueIdentifier(uniqueIdentifier);
 | 
	
		
			
				|  |  | +                if (Objects.nonNull(queryBrandEntity)) {
 | 
	
		
			
				|  |  | +                    throw new ServiceException("第" + (i + 1) + "行的该品牌:【" + queryBrandEntity.getName() + "】已存在!");
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                BrandEntity insertBrandEntity = new BrandEntity();
 | 
	
		
			
				|  |  | +                insertBrandEntity.setName(brandEntity.getName());
 | 
	
		
			
				|  |  | +                insertBrandEntity.setSimpleDesc(brandEntity.getSimpleDesc());
 | 
	
		
			
				|  |  | +                insertBrandEntity.setUniqueIdentifier(uniqueIdentifier);
 | 
	
		
			
				|  |  | +                insertBrandEntity.setIsShow(isShow);
 | 
	
		
			
				|  |  | +                insertBrandEntity.setIsNew(isNew);
 | 
	
		
			
				|  |  | +                this.save(insertBrandEntity);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                // 存在则修改
 | 
	
		
			
				|  |  | +                BeanUtils.copyProperties(brandEntity, isExist);
 | 
	
		
			
				|  |  | +                this.update(isExist);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 |