refactor: 料单导入,新增选项“是否考虑管线号”,不是的话,产生的修改是原先不同管线号记录会合并,管线号设置为空,合并值和前阶段合并值加减;料单阶段比较报告修改:后阶段如果是不考虑管线号的,前阶段数据也处理成不考虑管线号

This commit is contained in:
hwd
2025-09-29 18:04:44 +08:00
parent 7b817a5edf
commit b3284bdc84
5 changed files with 93 additions and 25 deletions

View File

@@ -0,0 +1,12 @@
package com.vverp.constant;
import org.apache.commons.lang3.BooleanUtils;
public class MaterialOrderItemConsts {
// 根据当前阶段的是否考虑管线号,返回之前阶段的管线号
public static String getPrevStageLineAccount(Boolean ignoreLineAccount, String prevStageLineAccount) {
return BooleanUtils.isTrue(ignoreLineAccount) ? "-" : prevStageLineAccount;
}
}

View File

@@ -466,7 +466,7 @@ public class MaterialOrderController extends BaseController {
*/ */
@RequestMapping(value = "/uploadOrderExcel") @RequestMapping(value = "/uploadOrderExcel")
@ResponseBody @ResponseBody
public RespData uploadOrderExcel(MultipartFile file, Long adminId, String preTitle, Integer flowNum, String code, Long orderId, Long stage,String memo,String upReason,String name) { public RespData uploadOrderExcel(MultipartFile file, Long adminId, String preTitle, Integer flowNum, String code, Long orderId, Long stage,String memo,String upReason,String name, Boolean ignoreLineAccount) {
if (orderId == null) { if (orderId == null) {
if (file == null) { if (file == null) {
return RespData.error("文件为空"); return RespData.error("文件为空");
@@ -480,6 +480,9 @@ public class MaterialOrderController extends BaseController {
if (stage == null) { if (stage == null) {
return RespData.error("阶段不能为空"); return RespData.error("阶段不能为空");
} }
if (ignoreLineAccount == null) {
return RespData.error("是否考虑管线号不能为空");
}
} }
//获得文件名 //获得文件名
String fileName = file.getOriginalFilename(); String fileName = file.getOriginalFilename();
@@ -490,7 +493,7 @@ public class MaterialOrderController extends BaseController {
try { try {
System.out.println("开始导入文件"); System.out.println("开始导入文件");
if (orderId == null) { if (orderId == null) {
Integer specialNum = materialOrderService.saveFile(file, adminId, preTitle, flowNum, code, stage,memo,name); Integer specialNum = materialOrderService.saveFile(file, adminId, preTitle, flowNum, code, stage,memo,name, ignoreLineAccount);
if (specialNum >0){ if (specialNum >0){
return RespData.warn("导入成功"); return RespData.warn("导入成功");
} }

View File

@@ -131,6 +131,9 @@ public class MaterialOrder extends OrderBase{
/** 是否创建订货单 */ /** 是否创建订货单 */
private Boolean hasPurchaseOrder; private Boolean hasPurchaseOrder;
/** 匹配忽略管线号 */
private Boolean ignoreLineAccount;
public String getName() { public String getName() {
return name; return name;
} }
@@ -295,4 +298,12 @@ public class MaterialOrder extends OrderBase{
public void setHasPurchaseOrder(Boolean hasPurchaseOrder) { public void setHasPurchaseOrder(Boolean hasPurchaseOrder) {
this.hasPurchaseOrder = hasPurchaseOrder; this.hasPurchaseOrder = hasPurchaseOrder;
} }
public Boolean getIgnoreLineAccount() {
return ignoreLineAccount;
}
public void setIgnoreLineAccount(Boolean ignoreLineAccount) {
this.ignoreLineAccount = ignoreLineAccount;
}
} }

View File

@@ -4,6 +4,7 @@ import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.comparator.CompareUtil; import cn.hutool.core.comparator.CompareUtil;
import com.vverp.base.exception.ImportExcelException; import com.vverp.base.exception.ImportExcelException;
import com.vverp.constant.MaterialOrderItemConsts;
import com.vverp.dao.MaterialOrderDao; import com.vverp.dao.MaterialOrderDao;
import com.vverp.dto.CellDto; import com.vverp.dto.CellDto;
import com.vverp.dto.CompanyQuery; import com.vverp.dto.CompanyQuery;
@@ -18,6 +19,7 @@ import com.vverp.moli.util.Pageable;
import com.vverp.util.*; import com.vverp.util.*;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -603,7 +605,7 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
// @Transactional(propagation = Propagation.NESTED) // @Transactional(propagation = Propagation.NESTED)
@Transactional @Transactional
public Integer saveFile(MultipartFile file, Long adminId, String preTitle, Integer flowNum, String code, Long stageId,String remark,String orderName) { public Integer saveFile(MultipartFile file, Long adminId, String preTitle, Integer flowNum, String code, Long stageId,String remark,String orderName, Boolean ignoreLineAccount) {
specialList = new ArrayList<>(); specialList = new ArrayList<>();
List<ProductType> productTypeList = new ArrayList<>(); List<ProductType> productTypeList = new ArrayList<>();
Admin admin = adminService.find(adminId); Admin admin = adminService.find(adminId);
@@ -620,6 +622,7 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
materialOrder.setPreTitle(preTitle); materialOrder.setPreTitle(preTitle);
materialOrder.setProgressId(admin.getNowProgress()); materialOrder.setProgressId(admin.getNowProgress());
materialOrder.setName(orderName); materialOrder.setName(orderName);
materialOrder.setIgnoreLineAccount(ignoreLineAccount);
if (admin.getNowProgress() != null) { if (admin.getNowProgress() != null) {
Progress progress = progressService.find(admin.getNowProgress()); Progress progress = progressService.find(admin.getNowProgress());
materialOrder.setProgressName(progress.getName()); materialOrder.setProgressName(progress.getName());
@@ -651,6 +654,8 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
Map<String,BigDecimal> countMap = new HashMap<>(); Map<String,BigDecimal> countMap = new HashMap<>();
Map<String, MaterialOrderItem> ignoreLineAccountMergeItemMap = new HashMap<>();
Set<String> ignoreLineAccountSubtractUseCountSet = new HashSet<>();
if (!firstStage){ if (!firstStage){
List<MaterialOrder> materialOrderList = findByStageNum(preTitle, stage.getStageNum(),admin.getNowProgress()); List<MaterialOrder> materialOrderList = findByStageNum(preTitle, stage.getStageNum(),admin.getNowProgress());
// if(materialOrderList.size()<1){ // if(materialOrderList.size()<1){
@@ -668,7 +673,7 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
+"_"+wallThicknessLStr+"_"+materialOrderItem.getMaterial() +"_"+wallThicknessLStr+"_"+materialOrderItem.getMaterial()
+"_"+materialOrderItem.getMemo()+"_"+materialOrderItem.getSize() +"_"+materialOrderItem.getMemo()+"_"+materialOrderItem.getSize()
+"_"+materialOrderItem.getSpecialRequest()+"_"+materialOrderItem.getInsulationCode() +"_"+materialOrderItem.getSpecialRequest()+"_"+materialOrderItem.getInsulationCode()
+"_"+materialOrderItem.getLineAccount()+"_"+materialOrderItem.getAreaAccount() +"_"+ MaterialOrderItemConsts.getPrevStageLineAccount(ignoreLineAccount, materialOrderItem.getLineAccount()) +"_"+materialOrderItem.getAreaAccount()
+"_"+materialOrderItem.getSiteAccount()+"_"+materialOrderItem.getUnitAccount() +"_"+materialOrderItem.getSiteAccount()+"_"+materialOrderItem.getUnitAccount()
+"_"+materialOrderItem.getProductCode()+"_"+materialOrderItem.getPurchaseCode() +"_"+materialOrderItem.getProductCode()+"_"+materialOrderItem.getPurchaseCode()
+"_"+materialOrderItem.getMakeCode()+"_"+materialOrderItem.getMaterialType() +"_"+materialOrderItem.getMakeCode()+"_"+materialOrderItem.getMaterialType()
@@ -823,7 +828,7 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
String areaAccount = ExcelUtil2.getCellValue(row.getCell(2)); String areaAccount = ExcelUtil2.getCellValue(row.getCell(2));
String unitAccount = ExcelUtil2.getCellValue(row.getCell(3)); String unitAccount = ExcelUtil2.getCellValue(row.getCell(3));
String siteAccount = ExcelUtil2.getCellValue(row.getCell(4)); String siteAccount = ExcelUtil2.getCellValue(row.getCell(4));
String lineAccount = ExcelUtil2.getCellValue(row.getCell(5)); String lineAccount = BooleanUtils.isTrue(ignoreLineAccount) ? "-" : ExcelUtil2.getCellValue(row.getCell(5));
String codeType = ExcelUtil2.getCellValue(row.getCell(6)); String codeType = ExcelUtil2.getCellValue(row.getCell(6));
String purchaseCode = ExcelUtil2.getCellValue(row.getCell(7)); String purchaseCode = ExcelUtil2.getCellValue(row.getCell(7));
String shortDescription = ExcelUtil2.getCellValue(row.getCell(8)); String shortDescription = ExcelUtil2.getCellValue(row.getCell(8));
@@ -1011,17 +1016,6 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
} }
BigDecimal count = BigDecimal.ZERO; BigDecimal count = BigDecimal.ZERO;
BigDecimal negativeCount = BigDecimal.ZERO; BigDecimal negativeCount = BigDecimal.ZERO;
if (firstStage) {
if (ExcelUtil2.getCellValue(row.getCell(13)).equals("")){
// throw new RuntimeException("本次采购量不能为空");
notFindFlag = true;
errorMessage += "采购量不能为空;";
} else {
count = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(13)));
}
}else if (nowCount != null){
count = nowCount;
} else {
String diameterSStr = item.getDiameterS()==null?"null":item.getDiameterS().stripTrailingZeros().toString(); String diameterSStr = item.getDiameterS()==null?"null":item.getDiameterS().stripTrailingZeros().toString();
String diameterLStr = item.getDiameterL()==null?"null":item.getDiameterL().stripTrailingZeros().toString(); String diameterLStr = item.getDiameterL()==null?"null":item.getDiameterL().stripTrailingZeros().toString();
String wallThicknessSStr = item.getWallThicknessS()==null?"null":item.getWallThicknessS(); String wallThicknessSStr = item.getWallThicknessS()==null?"null":item.getWallThicknessS();
@@ -1036,9 +1030,24 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
+"_"+item.getProductCode()+"_"+item.getPurchaseCode() +"_"+item.getProductCode()+"_"+item.getPurchaseCode()
+"_"+item.getMakeCode()+"_"+item.getMaterialType() +"_"+item.getMakeCode()+"_"+item.getMaterialType()
+"_"+item.getEndFace()+"_"+item.getPressureLevel(); +"_"+item.getEndFace()+"_"+item.getPressureLevel();
if (firstStage) {
if (ExcelUtil2.getCellValue(row.getCell(13)).equals("")){
// throw new RuntimeException("本次采购量不能为空");
notFindFlag = true;
errorMessage += "采购量不能为空;";
} else {
count = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(13)));
}
}else if (nowCount != null){
count = nowCount;
} else {
BigDecimal useCount = countMap.get(str); BigDecimal useCount = countMap.get(str);
if (useCount!=null){ if (useCount!=null && !ignoreLineAccountSubtractUseCountSet.contains(str)){
count = needCount.subtract(useCount); count = needCount.subtract(useCount);
if (BooleanUtils.isTrue(ignoreLineAccount)) {
// 不考虑管线号的情况,只操作一次减去前阶段的采购量
ignoreLineAccountSubtractUseCountSet.add(str);
}
} else { } else {
count = needCount; count = needCount;
} }
@@ -1117,8 +1126,25 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
item.setExtraField8(value); item.setExtraField8(value);
} }
} }
boolean itemSave = true;
// 不考虑管线号的情况下,料单项合并
if (BooleanUtils.isTrue(ignoreLineAccount)) {
MaterialOrderItem orderItem = ignoreLineAccountMergeItemMap.get(str);
if (orderItem != null) {
orderItem.setNeedCount(orderItem.getNeedCount().add(item.getNeedCount()));
orderItem.setCount(orderItem.getCount().add(item.getCount()));
orderItem.setTotalWeight(totalWeight == null ? (product.getgWeight()==null?BigDecimal.ZERO:product.getgWeight()).multiply(orderItem.getCount()) : totalWeight);
materialOrderItemService.update(orderItem);
itemSave = false;
}
}
if (itemSave) {
item.setMaterialOrder(materialOrder); item.setMaterialOrder(materialOrder);
materialOrderItemService.save(item); materialOrderItemService.save(item);
if (BooleanUtils.isTrue(ignoreLineAccount)) {
ignoreLineAccountMergeItemMap.put(str, item);
}
}
if (notFindFlag) { if (notFindFlag) {
Cell notFindCell = ExcelUtil2.getOrCreateCell(row, 34); Cell notFindCell = ExcelUtil2.getOrCreateCell(row, 34);
@@ -1204,7 +1230,7 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
List<MaterialOrderItem> prevItemList = materialOrderItemService.findByVersionNum(prevMaterialOrder.getVersionNum(), prevMaterialOrder.getId()); List<MaterialOrderItem> prevItemList = materialOrderItemService.findByVersionNum(prevMaterialOrder.getVersionNum(), prevMaterialOrder.getId());
for (MaterialOrderItem prevItem : prevItemList){ for (MaterialOrderItem prevItem : prevItemList){
String str = prevItem.getName()+"_"+prevItem.getUnitAccount()+"_"+prevItem.getSiteAccount() String str = prevItem.getName()+"_"+prevItem.getUnitAccount()+"_"+prevItem.getSiteAccount()
+"_"+prevItem.getLineAccount()+"_"+prevItem.getProductCode(); +"_"+ MaterialOrderItemConsts.getPrevStageLineAccount(materialOrder.getIgnoreLineAccount(), prevItem.getLineAccount()) +"_"+prevItem.getProductCode();
if (!prevMap.containsKey(str)){ if (!prevMap.containsKey(str)){
prevMap.put(str,prevItem.getCount()); prevMap.put(str,prevItem.getCount());
prevMapM.put(str,prevItem); prevMapM.put(str,prevItem);
@@ -1300,7 +1326,7 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
materialOrderItem.setAreaAccount(entry.getValue().getAreaAccount()); materialOrderItem.setAreaAccount(entry.getValue().getAreaAccount());
materialOrderItem.setUnitAccount(entry.getValue().getUnitAccount()); materialOrderItem.setUnitAccount(entry.getValue().getUnitAccount());
materialOrderItem.setSiteAccount(entry.getValue().getSiteAccount()); materialOrderItem.setSiteAccount(entry.getValue().getSiteAccount());
materialOrderItem.setLineAccount(entry.getValue().getLineAccount()); materialOrderItem.setLineAccount(MaterialOrderItemConsts.getPrevStageLineAccount(materialOrder.getIgnoreLineAccount(), entry.getValue().getLineAccount()));
materialOrderItem.setCodeType(entry.getValue().getCodeType()); materialOrderItem.setCodeType(entry.getValue().getCodeType());
materialOrderItem.setProductCode(entry.getValue().getProductCode()); materialOrderItem.setProductCode(entry.getValue().getProductCode());
materialOrderItem.setShortDescription(entry.getValue().getShortDescription()); materialOrderItem.setShortDescription(entry.getValue().getShortDescription());
@@ -1336,7 +1362,7 @@ public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long>
map.put("name",entry.getValue().getName()); map.put("name",entry.getValue().getName());
map.put("unit",entry.getValue().getUnitAccount()); map.put("unit",entry.getValue().getUnitAccount());
map.put("site",entry.getValue().getSiteAccount()); map.put("site",entry.getValue().getSiteAccount());
map.put("line",entry.getValue().getLineAccount()); map.put("line", MaterialOrderItemConsts.getPrevStageLineAccount(materialOrder.getIgnoreLineAccount(), entry.getValue().getLineAccount()));
map.put("code",entry.getValue().getProductCode()); map.put("code",entry.getValue().getProductCode());
map.put("longDescription",entry.getValue().getLongDescription()); map.put("longDescription",entry.getValue().getLongDescription());
map.put("needCount",' '); map.put("needCount",' ');

View File

@@ -80,6 +80,17 @@
</div> </div>
</div> </div>
</div> </div>
<div class="submitBody-row">
<div class="submitBody-row-position">
<div class="input-wrapper required">
<label>是否考虑管线号</label>
<select id="ignoreLineAccount" name="ignoreLineAccount" data-init="false">
<option value="false"></option>
<option value="true"></option>
</select>
</div>
</div>
</div>
<input hidden name="progressId" id="progressId" th:value="${progressId}"/> <input hidden name="progressId" id="progressId" th:value="${progressId}"/>
<div class="formBtns formBtnsExtra"> <div class="formBtns formBtnsExtra">
@@ -107,6 +118,10 @@
Dialog.error("阶段不能为空"); Dialog.error("阶段不能为空");
return; return;
} }
if ($("#ignoreLineAccount").val() == null ||$("#ignoreLineAccount").val() == "null"){
Dialog.error("是否考虑管线号不能为空");
return;
}
if (!check()) { if (!check()) {
Dialog.error("请选择Excel文件"); Dialog.error("请选择Excel文件");
} else { } else {
@@ -122,6 +137,7 @@
fromData.append("stage", $("#stage").val()); fromData.append("stage", $("#stage").val());
fromData.append("memo", $("#memo").val()); fromData.append("memo", $("#memo").val());
fromData.append("name", $("#name").val()); fromData.append("name", $("#name").val());
fromData.append("ignoreLineAccount", $("#ignoreLineAccount").val());
$.ajax({ $.ajax({
type: "POST", type: "POST",
cache: false, cache: false,