|
@@ -1,6 +1,7 @@
|
|
|
package com.hwrj.cloud.admin.service.impl;
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
+import com.hwrj.cloud.admin.dao.PmsBrandDao;
|
|
|
import com.hwrj.cloud.admin.dto.PmsBrandParam;
|
|
|
import com.hwrj.cloud.admin.mapper.PmsBrandMapper;
|
|
|
import com.hwrj.cloud.admin.mapper.PmsProductMapper;
|
|
@@ -9,11 +10,13 @@ import com.hwrj.cloud.admin.model.PmsBrandExample;
|
|
|
import com.hwrj.cloud.admin.model.PmsProduct;
|
|
|
import com.hwrj.cloud.admin.model.PmsProductExample;
|
|
|
import com.hwrj.cloud.admin.service.PmsBrandService;
|
|
|
+import com.hwrj.cloud.common.exception.GlobalException;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -27,6 +30,9 @@ public class PmsBrandServiceImpl implements PmsBrandService {
|
|
|
@Autowired
|
|
|
private PmsProductMapper productMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PmsBrandDao pmsBrandDao;
|
|
|
+
|
|
|
@Override
|
|
|
public List<PmsBrand> listAllBrand() {
|
|
|
return brandMapper.selectByExample(new PmsBrandExample());
|
|
@@ -40,6 +46,10 @@ public class PmsBrandServiceImpl implements PmsBrandService {
|
|
|
if (StringUtils.isEmpty(pmsBrand.getFirstLetter())) {
|
|
|
pmsBrand.setFirstLetter(pmsBrand.getName().substring(0, 1));
|
|
|
}
|
|
|
+ long i = pmsBrandDao.insertCheck(pmsBrand.getName());
|
|
|
+ if(i>0){
|
|
|
+ throw new GlobalException("该品牌已存在,无法新增!");
|
|
|
+ }
|
|
|
return brandMapper.insertSelective(pmsBrand);
|
|
|
}
|
|
|
|
|
@@ -63,14 +73,26 @@ public class PmsBrandServiceImpl implements PmsBrandService {
|
|
|
|
|
|
@Override
|
|
|
public int deleteBrand(Long id) {
|
|
|
+ long i = pmsBrandDao.deleteCheck(Arrays.asList(id));
|
|
|
+ if(i>0){
|
|
|
+ throw new GlobalException("商品数据绑定改品牌,无法删除!");
|
|
|
+ }
|
|
|
return brandMapper.deleteByPrimaryKey(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int deleteBrand(List<Long> ids) {
|
|
|
- PmsBrandExample pmsBrandExample = new PmsBrandExample();
|
|
|
- pmsBrandExample.createCriteria().andIdIn(ids);
|
|
|
- return brandMapper.deleteByExample(pmsBrandExample);
|
|
|
+ if(ids.size()>0){
|
|
|
+ long i = pmsBrandDao.deleteCheck(ids);
|
|
|
+ if(i>0){
|
|
|
+ throw new GlobalException("商品数据绑定改品牌,无法删除!");
|
|
|
+ }
|
|
|
+ PmsBrandExample pmsBrandExample = new PmsBrandExample();
|
|
|
+ pmsBrandExample.createCriteria().andIdIn(ids);
|
|
|
+ return brandMapper.deleteByExample(pmsBrandExample);
|
|
|
+ }else {
|
|
|
+ throw new GlobalException("请选择你要删除的商品!");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|