提交 cff0ddaa 作者: 余乾开

hotfix(删除品牌):补充删除品牌条件校验(无绑定型号)

上级 66ba65a9
...@@ -22,15 +22,14 @@ import java.util.stream.Collectors; ...@@ -22,15 +22,14 @@ import java.util.stream.Collectors;
/** /**
* @Author LW * @Author LW
*
* @date 2023/3/14 13:27 概要: * @date 2023/3/14 13:27 概要:
*/ */
@Service @Service
public class BrandManageServiceImpl implements BrandManageService { public class BrandManageServiceImpl implements BrandManageService {
@Autowired @Autowired private BrandManageDao brandManageDao;
private BrandManageDao brandManageDao; @Resource private ProductDao productDao;
@Resource
private ProductDao productDao;
/** /**
* 添加品牌信息 * 添加品牌信息
...@@ -65,15 +64,23 @@ public class BrandManageServiceImpl implements BrandManageService { ...@@ -65,15 +64,23 @@ public class BrandManageServiceImpl implements BrandManageService {
List<BrandInfoDO> brandInfo = brandManageDao.listBrandInfo(itemIndex, pageSize); List<BrandInfoDO> brandInfo = brandManageDao.listBrandInfo(itemIndex, pageSize);
List<Integer> ids = brandInfo.stream().map(BrandInfoDO::getId).collect(Collectors.toList()); List<Integer> ids = brandInfo.stream().map(BrandInfoDO::getId).collect(Collectors.toList());
List<DeviceModeDO> deviceModeDOList = brandManageDao.listDeviceModeByBrandId(ids); List<DeviceModeDO> deviceModeDOList = brandManageDao.listDeviceModeByBrandId(ids);
Map<Integer, List<DeviceModeDO>> map = deviceModeDOList.stream().collect(Collectors.groupingBy(DeviceModeDO::getBrandInfoId)); Map<Integer, List<DeviceModeDO>> map =
deviceModeDOList.stream().collect(Collectors.groupingBy(DeviceModeDO::getBrandInfoId));
List<BrandInfoDTO> brandInfoList = List<BrandInfoDTO> brandInfoList =
brandInfo.stream().map(BrandInfoDO::buildBrandInfoDTO).collect(Collectors.toList()); brandInfo.stream().map(BrandInfoDO::buildBrandInfoDTO).collect(Collectors.toList());
brandInfoList = brandInfoList.stream().peek(d -> { brandInfoList =
brandInfoList.stream()
.peek(
d -> {
List<DeviceModeDO> deviceModeList = map.get(d.getId()); List<DeviceModeDO> deviceModeList = map.get(d.getId());
if (CollectionUtils.isNotEmpty(deviceModeList)) { if (CollectionUtils.isNotEmpty(deviceModeList)) {
d.setModeInfoList(deviceModeList.stream().map(DeviceModeDO::buildModeInfoVO).collect(Collectors.toList())); d.setModeInfoList(
deviceModeList.stream()
.map(DeviceModeDO::buildModeInfoVO)
.collect(Collectors.toList()));
} }
}).collect(Collectors.toList()); })
.collect(Collectors.toList());
return PageResult.buildPage(pageNo, pageSize, count, brandInfoList); return PageResult.buildPage(pageNo, pageSize, count, brandInfoList);
} }
...@@ -87,7 +94,11 @@ public class BrandManageServiceImpl implements BrandManageService { ...@@ -87,7 +94,11 @@ public class BrandManageServiceImpl implements BrandManageService {
public ResultBody deleteBrandInfo(Integer id) { public ResultBody deleteBrandInfo(Integer id) {
// 判断该品牌是否绑定产品信息 // 判断该品牌是否绑定产品信息
int count = productDao.countLeaseGoodsByBrandId(id); int count = productDao.countLeaseGoodsByBrandId(id);
if (count > 0) { // 是否绑定型号
ModeInfoQO qo = new ModeInfoQO();
qo.setBrandInfoId(id);
int deviceModeCount = brandManageDao.countModeInfo(qo);
if (count > 0 || deviceModeCount > 0) {
return ResultBody.error(ResultEnum.BRAND_DELETE_FAIL); return ResultBody.error(ResultEnum.BRAND_DELETE_FAIL);
} }
brandManageDao.removeBrandInfoById(id); brandManageDao.removeBrandInfoById(id);
...@@ -127,7 +138,8 @@ public class BrandManageServiceImpl implements BrandManageService { ...@@ -127,7 +138,8 @@ public class BrandManageServiceImpl implements BrandManageService {
Integer pageNo = param.getPageNo(); Integer pageNo = param.getPageNo();
param.buildCurrentPage(); param.buildCurrentPage();
List<DeviceModeDO> deviceModeDOList = brandManageDao.listDeviceMode(param); List<DeviceModeDO> deviceModeDOList = brandManageDao.listDeviceMode(param);
List<ModeInfoVO> list = deviceModeDOList.stream().map(DeviceModeDO::buildModeInfoVO).collect(Collectors.toList()); List<ModeInfoVO> list =
deviceModeDOList.stream().map(DeviceModeDO::buildModeInfoVO).collect(Collectors.toList());
return PageResult.buildPage(pageNo, param.getPageSize(), count, list); return PageResult.buildPage(pageNo, param.getPageSize(), count, list);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论