|
@@ -8,6 +8,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -16,25 +17,21 @@ import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.common.entity.AvailableStockBo;
|
|
|
import com.fjhx.common.service.file.FtpFileService;
|
|
|
import com.fjhx.common.service.file.impl.FtpFileServiceImpl;
|
|
|
-import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.file.entity.FileInfoVo;
|
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.fjhx.item.entity.product.ProcessesBo;
|
|
|
import com.fjhx.item.entity.product.bo.ProductAnalysisBo;
|
|
|
import com.fjhx.item.entity.product.bo.ProductExcelExportBo;
|
|
|
+import com.fjhx.item.entity.product.dto.ProductCustomInfoDto;
|
|
|
import com.fjhx.item.entity.product.dto.ProductInfoDto;
|
|
|
import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
|
|
|
-import com.fjhx.item.entity.product.po.ProductBomDetail;
|
|
|
-import com.fjhx.item.entity.product.po.ProductClassify;
|
|
|
-import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
-import com.fjhx.item.entity.product.po.ProductStockInfo;
|
|
|
+import com.fjhx.item.entity.product.po.*;
|
|
|
+import com.fjhx.item.entity.product.vo.ProductBomDetailVo;
|
|
|
+import com.fjhx.item.entity.product.vo.ProductCustomInfoVo;
|
|
|
import com.fjhx.item.entity.product.vo.ProductInfoVo;
|
|
|
import com.fjhx.item.enums.ProductAvailableRecordType;
|
|
|
import com.fjhx.item.mapper.product.ProductInfoMapper;
|
|
|
-import com.fjhx.item.service.product.ProductBomDetailService;
|
|
|
-import com.fjhx.item.service.product.ProductClassifyService;
|
|
|
-import com.fjhx.item.service.product.ProductInfoService;
|
|
|
-import com.fjhx.item.service.product.ProductStockInfoService;
|
|
|
+import com.fjhx.item.service.product.*;
|
|
|
import com.fjhx.item.util.CodeEnum;
|
|
|
import com.fjhx.item.util.excel.ExcelImgUtils;
|
|
|
import com.fjhx.item.util.excel.util.ExcelUtil;
|
|
@@ -91,6 +88,8 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
private ProductStockInfoService productStockInfoService;
|
|
|
@Autowired
|
|
|
private ProductBomDetailService productBomDetailService;
|
|
|
+ @Autowired
|
|
|
+ private ProductCustomInfoService productCustomInfoService;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -231,6 +230,34 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
if (ObjectUtil.isNotEmpty(productClassify)) {
|
|
|
result.setClassifyName(productClassify.getName());
|
|
|
}
|
|
|
+
|
|
|
+ //赋值物料信息
|
|
|
+ List<ProductBomDetail> productBomDetailList = productBomDetailService.list(q -> q.eq(ProductBomDetail::getProductId, id));
|
|
|
+ List<ProductBomDetailVo> productBomDetailVos = BeanUtil.copyToList(productBomDetailList, ProductBomDetailVo.class);
|
|
|
+ this.attributeAssign(productBomDetailVos, ProductBomDetail::getMaterialId, (item, material) -> {
|
|
|
+ item.setMaterialName(material.getName());
|
|
|
+ item.setMaterialCode(material.getCustomCode());
|
|
|
+ item.setMaterialLength(material.getLength());
|
|
|
+ item.setMaterialWidth(material.getWidth());
|
|
|
+ item.setMaterialHeight(material.getHeight());
|
|
|
+ item.setMaterialPrice(material.getPrice());
|
|
|
+ item.setMaterialNetWeight(material.getNetWeight());
|
|
|
+ item.setMaterialColor(material.getColor());
|
|
|
+ item.setMaterialColorCardCode(material.getColorCardCode());
|
|
|
+ });
|
|
|
+ result.setProductBomDetailList(productBomDetailVos);
|
|
|
+
|
|
|
+ //赋值产品定制信息
|
|
|
+ List<ProductCustomInfo> productCustomInfoList = productCustomInfoService.list(q -> q.eq(ProductCustomInfo::getProductId, id));
|
|
|
+ List<Long> pIds = productCustomInfoList.stream().map(ProductCustomInfo::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<FileInfoVo>> fileMap = ObsFileUtil.getFileMap(pIds, 0);
|
|
|
+ List<ProductCustomInfoVo> productCustomInfoVos = BeanUtil.copyToList(productCustomInfoList, ProductCustomInfoVo.class);
|
|
|
+ for (ProductCustomInfoVo productCustomInfoVo : productCustomInfoVos) {
|
|
|
+ List<FileInfoVo> fileInfoVoList = fileMap.get(productCustomInfoVo.getId());
|
|
|
+ productCustomInfoVo.setFileList(fileInfoVoList);
|
|
|
+ }
|
|
|
+ result.setProductCustomInfoList(productCustomInfoVos);
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -274,12 +301,20 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
//操作ftp文件
|
|
|
editFtpFile(productInfoDto);
|
|
|
|
|
|
+ //保存原材料信息
|
|
|
+ saveOrEditRawMaterial(productInfoDto);
|
|
|
+
|
|
|
this.save(productInfoDto);
|
|
|
ObsFileUtil.saveFile(productInfoDto.getFileList(), productInfoDto.getId());
|
|
|
ObsFileUtil.saveFile(productInfoDto.getProdFileList(), productInfoDto.getId(), 2);
|
|
|
|
|
|
- //保存原材料信息
|
|
|
- saveOrEditRawMaterial(productInfoDto);
|
|
|
+ //保存物料信息
|
|
|
+ List<ProductBomDetail> productBomDetailList = productInfoDto.getProductBomDetailList();
|
|
|
+ productBomDetailList.forEach(item -> item.setProductId(productInfoDto.getId()));
|
|
|
+ productBomDetailService.saveBatch(productBomDetailList);
|
|
|
+
|
|
|
+ //保存产品定制信息
|
|
|
+ saveOrEditCustomInfo(productInfoDto);
|
|
|
}
|
|
|
|
|
|
// /**
|
|
@@ -333,37 +368,37 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
@Override
|
|
|
public void edit(ProductInfoDto productInfoDto) {
|
|
|
|
|
|
- //修改物料时 更新关联产品价格
|
|
|
- if (ObjectUtil.equals(productInfoDto.getDefinition(), 2)) {
|
|
|
- List<ProductBomDetail> productBomDetailList = productBomDetailService.list(q -> q
|
|
|
- .eq(ProductBomDetail::getMaterialId, productInfoDto.getId())
|
|
|
- );
|
|
|
-
|
|
|
- //获取物料信息
|
|
|
- ProductInfo materialInfo = this.getById(productInfoDto.getId());
|
|
|
- BigDecimal oldPrice = materialInfo.getPrice();
|
|
|
- BigDecimal newPrice = productInfoDto.getPrice();
|
|
|
-
|
|
|
- for (ProductBomDetail productBomDetail : productBomDetailList) {
|
|
|
- ProductInfo productInfo = this.getById(productBomDetail.getProductId());
|
|
|
-
|
|
|
- if (ObjectUtil.equals(productBomDetail.getType(), 1)) {
|
|
|
- oldPrice = productInfo.getLength().multiply(productInfo.getWidth()).multiply(oldPrice);
|
|
|
- newPrice = productInfo.getLength().multiply(productInfo.getWidth()).multiply(newPrice);
|
|
|
- } else {
|
|
|
- oldPrice = oldPrice.multiply(productBomDetail.getQuantity());
|
|
|
- newPrice = newPrice.multiply(productBomDetail.getQuantity());
|
|
|
- }
|
|
|
-
|
|
|
- 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())
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
+// //修改物料时 更新关联产品价格
|
|
|
+// if (ObjectUtil.equals(productInfoDto.getDefinition(), 2)) {
|
|
|
+// List<ProductBomDetail> productBomDetailList = productBomDetailService.list(q -> q
|
|
|
+// .eq(ProductBomDetail::getMaterialId, productInfoDto.getId())
|
|
|
+// );
|
|
|
+//
|
|
|
+// //获取物料信息
|
|
|
+// ProductInfo materialInfo = this.getById(productInfoDto.getId());
|
|
|
+// BigDecimal oldPrice = materialInfo.getPrice();
|
|
|
+// BigDecimal newPrice = productInfoDto.getPrice();
|
|
|
+//
|
|
|
+// for (ProductBomDetail productBomDetail : productBomDetailList) {
|
|
|
+// ProductInfo productInfo = this.getById(productBomDetail.getProductId());
|
|
|
+//
|
|
|
+// if (ObjectUtil.equals(productBomDetail.getType(), 1)) {
|
|
|
+// oldPrice = productInfo.getLength().multiply(productInfo.getWidth()).multiply(oldPrice);
|
|
|
+// newPrice = productInfo.getLength().multiply(productInfo.getWidth()).multiply(newPrice);
|
|
|
+// } else {
|
|
|
+// oldPrice = oldPrice.multiply(productBomDetail.getQuantity());
|
|
|
+// newPrice = newPrice.multiply(productBomDetail.getQuantity());
|
|
|
+// }
|
|
|
+//
|
|
|
+// 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())
|
|
|
+// );
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
|
|
|
// 禁止产品编号修改
|
|
@@ -395,39 +430,53 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
productInfoDto.setCompanyId(SecurityUtils.getCompanyId());
|
|
|
}
|
|
|
|
|
|
+ //修改产品时 修改原材料
|
|
|
+ saveOrEditRawMaterial(productInfoDto);
|
|
|
+
|
|
|
this.updateById(productInfoDto);
|
|
|
ObsFileUtil.editFile(productInfoDto.getFileList(), productInfoDto.getId());
|
|
|
ObsFileUtil.editFile(productInfoDto.getProdFileList(), productInfoDto.getId(), 2);
|
|
|
|
|
|
- //修改产品时 修改原材料
|
|
|
- saveOrEditRawMaterial(productInfoDto);
|
|
|
+ //保存物料信息
|
|
|
+ List<ProductBomDetail> productBomDetailList = productInfoDto.getProductBomDetailList();
|
|
|
+ productBomDetailList.forEach(item -> item.setProductId(productInfoDto.getId()));
|
|
|
+ productBomDetailService.editLinked(productBomDetailList, ProductBomDetail::getProductId, productInfoDto.getId());
|
|
|
+
|
|
|
+ //保存产品定制信息
|
|
|
+ saveOrEditCustomInfo(productInfoDto);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 保存修改产品原材料
|
|
|
+ * 保存产品定制信息
|
|
|
*/
|
|
|
- private void saveOrEditRawMaterial(ProductInfoDto productInfoDto) {
|
|
|
- Long rawMaterialId = productInfoDto.getRawMaterialId();
|
|
|
+ private void saveOrEditCustomInfo(ProductInfoDto productInfoDto) {
|
|
|
+ //保存产品定制信息
|
|
|
+ List<ProductCustomInfoDto> productCustomInfoList = productInfoDto.getProductCustomInfoList();
|
|
|
|
|
|
- //非产品跳过
|
|
|
- if (ObjectUtil.notEqual(productInfoDto.getDefinition(), 1)) {
|
|
|
- return;
|
|
|
+ for (ProductCustomInfoDto productCustomInfoDto : productCustomInfoList) {
|
|
|
+ if (ObjectUtil.isEmpty(productCustomInfoDto.getId())) {
|
|
|
+ productCustomInfoDto.setId(IdWorker.getId());
|
|
|
+ }
|
|
|
+ productCustomInfoDto.setProductId(productInfoDto.getId());
|
|
|
+ ObsFileUtil.saveFile(productCustomInfoDto.getFileList(), productCustomInfoDto.getId());
|
|
|
}
|
|
|
- Assert.notEmpty(rawMaterialId, "原材料ID不能为空!");
|
|
|
|
|
|
- //保存原材料信息
|
|
|
- ProductBomDetail productBomDetail = productBomDetailService.getOne(q -> q
|
|
|
- .eq(ProductBomDetail::getProductId, productInfoDto.getId())
|
|
|
- .eq(ProductBomDetail::getType, 1)
|
|
|
- );
|
|
|
- if (ObjectUtil.isEmpty(productBomDetail)) {
|
|
|
- productBomDetail = new ProductBomDetail();
|
|
|
- productBomDetail.setProductId(productInfoDto.getId());
|
|
|
- productBomDetail.setType(1);
|
|
|
- productBomDetail.setQuantity(BigDecimal.ONE);
|
|
|
- productBomDetail.setMaterialId(rawMaterialId);
|
|
|
+ List<ProductCustomInfo> productCustomInfos = BeanUtil.copyToList(productCustomInfoList, ProductCustomInfo.class);
|
|
|
+ productCustomInfoService.editLinked(productCustomInfos, ProductCustomInfo::getProductId, productInfoDto.getId());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存修改产品原材料
|
|
|
+ */
|
|
|
+ private void saveOrEditRawMaterial(ProductInfoDto productInfoDto) {
|
|
|
+ List<ProductBomDetail> productBomDetailList = productInfoDto.getProductBomDetailList();
|
|
|
+ List<ProductBomDetail> rawMaterialList = productBomDetailList.stream()
|
|
|
+ .filter(item -> ObjectUtil.equals(item.getType(), 1)).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isNotEmpty(rawMaterialList)) {
|
|
|
+ ProductBomDetail productBomDetail = rawMaterialList.get(0);
|
|
|
+ productInfoDto.setRawMaterialId(productBomDetail.getMaterialId());
|
|
|
}
|
|
|
- productBomDetailService.saveOrUpdate(productBomDetail);
|
|
|
}
|
|
|
|
|
|
@DSTransactional
|