|
@@ -297,25 +297,27 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
|
|
|
//获取物料价格
|
|
|
BigDecimal materialPrice = BigDecimal.ZERO;
|
|
|
- List<Long> mIds;
|
|
|
+ List<ProductBomDetail> productBomDetailList = new ArrayList<>();
|
|
|
if (ObjectUtil.isNotEmpty(id)) {
|
|
|
- mIds = productBomDetailService.listObject(ProductBomDetail::getProductId, q -> q
|
|
|
- .eq(ProductBomDetail::getProductId, id)
|
|
|
- );
|
|
|
+ productBomDetailList = productBomDetailService.list(q -> q.eq(ProductBomDetail::getProductId, id));
|
|
|
} else {
|
|
|
- mIds = Arrays.asList(productInfo.getRawMaterialId());
|
|
|
+ ProductBomDetail productBomDetail = new ProductBomDetail();
|
|
|
+ productBomDetail.setMaterialId(productInfo.getRawMaterialId());
|
|
|
+ productBomDetail.setType(1);
|
|
|
+ productBomDetail.setQuantity(BigDecimal.ONE);
|
|
|
+ productBomDetailList.add(productBomDetail);
|
|
|
}
|
|
|
|
|
|
- List<ProductInfo> list = this.list(q -> q.in(ProductInfo::getId, mIds));
|
|
|
- for (ProductInfo materialInfo : list) {
|
|
|
+ for (ProductBomDetail productBomDetail : productBomDetailList) {
|
|
|
+ ProductInfo materialInfo = this.getById(productBomDetail.getMaterialId());
|
|
|
if (ObjectUtil.equals(materialInfo.getClass(), 100)) {
|
|
|
- //原材料
|
|
|
+ //原材料 产品长 * 产品宽 * 原材料单价
|
|
|
BigDecimal multiply = length.multiply(width).multiply(materialInfo.getPrice());
|
|
|
materialPrice = materialPrice.add(multiply);
|
|
|
} else {
|
|
|
- //普通物料
|
|
|
- materialPrice = materialPrice.add(materialInfo.getPrice());
|
|
|
-
|
|
|
+ //普通物料 产品库BOM该物料数量 * 物料单价
|
|
|
+ BigDecimal multiply = productBomDetail.getQuantity().multiply(materialInfo.getPrice());
|
|
|
+ materialPrice = materialPrice.add(multiply);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -333,31 +335,33 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
|
|
|
//修改物料时 更新关联产品价格
|
|
|
if (ObjectUtil.equals(productInfoDto.getDefinition(), 2)) {
|
|
|
- List<Long> pIds = productBomDetailService.listObject(ProductBomDetail::getProductId, q -> q
|
|
|
+ List<ProductBomDetail> productBomDetailList = productBomDetailService.list(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());
|
|
|
+ //获取物料信息
|
|
|
+ ProductInfo materialInfo = this.getById(productInfoDto.getId());
|
|
|
+ BigDecimal oldPrice = materialInfo.getPrice();
|
|
|
+ BigDecimal newPrice = productInfoDto.getPrice();
|
|
|
|
|
|
- BigDecimal oldPrice = materialInfo.getPrice();
|
|
|
- BigDecimal newPrice = productInfoDto.getPrice();
|
|
|
+ for (ProductBomDetail productBomDetail : productBomDetailList) {
|
|
|
+ ProductInfo productInfo = this.getById(productBomDetail.getProductId());
|
|
|
|
|
|
- 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())
|
|
|
- );
|
|
|
+ if (ObjectUtil.equals(materialInfo.getClass(), 100)) {
|
|
|
+ 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())
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -449,20 +453,12 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
private void editFtpFile(ProductInfoDto productInfoDto) {
|
|
|
//操作ftp文件
|
|
|
String prodImgTempPath = productInfoDto.getProdImgPath();
|
|
|
-// String prodFileTempPath = productInfoDto.getProdFilePath();
|
|
|
//生产图片
|
|
|
if (ObjectUtil.isNotEmpty(prodImgTempPath) && prodImgTempPath.startsWith("/temp")) {
|
|
|
String prodImgPath = String.format("/product/prodImg/%s", productInfoDto.getId());
|
|
|
JSONObject prodImgJson = ftpFileService.moveFolder(prodImgTempPath, prodImgPath);
|
|
|
productInfoDto.setProdImgPath(prodImgJson.getString("path"));
|
|
|
}
|
|
|
-// //生产文件
|
|
|
-// if (ObjectUtil.isNotEmpty(prodFileTempPath) && prodFileTempPath.startsWith("/temp")) {
|
|
|
-// File prodFileTemp = new File(prodFileTempPath);
|
|
|
-// String prodFilePath = String.format("/product/prodFile/%s/%s", productInfoDto.getCustomCode(), prodFileTemp.getName());
|
|
|
-// JSONObject prodFileJson = ftpFileService.moveFolder(prodFileTempPath, prodFilePath);
|
|
|
-// productInfoDto.setProdFilePath(prodFileJson.getString("path"));
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
/**
|