|
@@ -202,13 +202,15 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //归属公司过滤
|
|
|
+ wrapper.eq("pi", ProductInfo::getCompanyId, dto.getCompanyId());
|
|
|
+
|
|
|
//没禁用权限过滤的情况
|
|
|
if (!ObjectUtil.equals(dto.getDisablePerm(), 1)) {
|
|
|
//权限过滤:产品
|
|
|
wrapper.and(q1 -> q1.
|
|
|
and(q -> q.eq("pi", ProductInfo::getDefinition, 1)
|
|
|
.in("pi", ProductInfo::getCompanyId, SecurityUtils.getCompanyIds())
|
|
|
- .eq("pi", ProductInfo::getCompanyId, dto.getCompanyId())
|
|
|
)
|
|
|
.or().eq("pi", ProductInfo::getDefinition, 2)
|
|
|
);
|
|
@@ -280,9 +282,82 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
saveOrEditRawMaterial(productInfoDto);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取产品价格
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ProductInfo getProductPrice(ProductInfo productInfo) {
|
|
|
+ Long id = productInfo.getId();
|
|
|
+ BigDecimal length = productInfo.getLength();
|
|
|
+ BigDecimal width = productInfo.getWidth();
|
|
|
+ Long technologyId = productInfo.getTechnologyId();
|
|
|
+ Assert.notEmpty(length, "产品长度不能为空!");
|
|
|
+ Assert.notEmpty(width, "产品宽度不能为空!");
|
|
|
+ Assert.notEmpty(technologyId, "工艺id不能为空");
|
|
|
+
|
|
|
+ //获取物料价格
|
|
|
+ BigDecimal materialPrice = BigDecimal.ZERO;
|
|
|
+ if (ObjectUtil.isNotEmpty(id)) {
|
|
|
+ List<Long> mIds = productBomDetailService.listObject(ProductBomDetail::getProductId, q -> q
|
|
|
+ .eq(ProductBomDetail::getProductId, id)
|
|
|
+ );
|
|
|
+
|
|
|
+ List<ProductInfo> list = this.list(q -> q.in(ProductInfo::getId, mIds));
|
|
|
+ for (ProductInfo materialInfo : list) {
|
|
|
+ if (ObjectUtil.equals(materialInfo.getClass(), 100)) {
|
|
|
+ //原材料
|
|
|
+ BigDecimal multiply = length.multiply(width).multiply(materialInfo.getPrice());
|
|
|
+ materialPrice = materialPrice.add(multiply);
|
|
|
+ } else {
|
|
|
+ //普通物料
|
|
|
+ materialPrice = materialPrice.add(materialInfo.getPrice());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取工序价格
|
|
|
+ List<ProcessesBo> processesList = baseMapper.getProcessesByTechnologyId(productInfo.getTechnologyId());
|
|
|
+ BigDecimal processesPrice = processesList.stream().map(ProcessesBo::getCostPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ productInfo.setPrice(materialPrice.add(processesPrice));
|
|
|
+ return productInfo;
|
|
|
+ }
|
|
|
+
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
public void edit(ProductInfoDto productInfoDto) {
|
|
|
+
|
|
|
+ //修改物料时 更新关联产品价格
|
|
|
+ if (ObjectUtil.equals(productInfoDto.getDefinition(), 2)) {
|
|
|
+ List<Long> pIds = productBomDetailService.listObject(ProductBomDetail::getProductId, q -> q
|
|
|
+ .eq(ProductBomDetail::getMaterialId, productInfoDto.getId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(pIds)) {
|
|
|
+ List<ProductInfo> productInfoList = this.listByIds(pIds);
|
|
|
+ for (ProductInfo productInfo : productInfoList) {
|
|
|
+ ProductInfo materialInfo = this.getById(productInfoDto.getId());
|
|
|
+
|
|
|
+ BigDecimal oldPrice = materialInfo.getPrice();
|
|
|
+ BigDecimal newPrice = productInfoDto.getPrice();
|
|
|
+
|
|
|
+ if (ObjectUtil.equals(materialInfo.getClass(), 100)) {
|
|
|
+ oldPrice = productInfo.getLength().multiply(productInfo.getWidth()).multiply(oldPrice);
|
|
|
+ newPrice = productInfo.getLength().multiply(productInfo.getWidth()).multiply(newPrice);
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal subtract = newPrice.subtract(oldPrice);
|
|
|
+ this.update(q -> q
|
|
|
+ .in(ProductInfo::getId, productInfo.getId())
|
|
|
+ .setSql("price = price + " + subtract)
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 禁止产品编号修改
|
|
|
productInfoDto.setCode(null);
|
|
|
//检查【产品名称】和【规格型号】不能同时重复,但可以单项重复。
|
|
@@ -316,7 +391,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
ObsFileUtil.editFile(productInfoDto.getFileList(), productInfoDto.getId());
|
|
|
ObsFileUtil.editFile(productInfoDto.getProdFileList(), productInfoDto.getId(), 2);
|
|
|
|
|
|
- //修改原材料
|
|
|
+ //修改产品时 修改原材料
|
|
|
saveOrEditRawMaterial(productInfoDto);
|
|
|
}
|
|
|
|
|
@@ -350,6 +425,16 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
+ //删除物料时 检查是否关联产品
|
|
|
+ List<Long> pIds = productBomDetailService.listObject(ProductBomDetail::getProductId, q -> q
|
|
|
+ .eq(ProductBomDetail::getMaterialId, id)
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isNotEmpty(pIds)) {
|
|
|
+ List<String> strings = this.listObject(ProductInfo::getName, q -> q.in(ProductInfo::getId, pIds));
|
|
|
+ String collect = strings.stream().collect(Collectors.joining(","));
|
|
|
+ throw new ServiceException("该物料当前关联了以下产品:" + collect + " 禁止删除!");
|
|
|
+ }
|
|
|
+
|
|
|
this.removeById(id);
|
|
|
ObsFileUtil.removeFile(id);
|
|
|
}
|