Browse Source

添加导入功能

master
shenzhouyu 11 months ago
parent
commit
cb064113a7
  1. 1
      src/main/java/com/gaotao/modules/customer/service/impl/CustomerIssueServiceImpl.java
  2. 20
      src/main/java/com/gaotao/modules/notify/controller/IssureNotifyController.java
  3. 5
      src/main/java/com/gaotao/modules/notify/entity/vo/ImportPartAttrVo.java
  4. 2
      src/main/java/com/gaotao/modules/notify/service/IssureNotifyService.java
  5. 137
      src/main/java/com/gaotao/modules/notify/service/impl/IssureNotifyServiceImpl.java

1
src/main/java/com/gaotao/modules/customer/service/impl/CustomerIssueServiceImpl.java

@ -164,6 +164,7 @@ public class CustomerIssueServiceImpl implements CustomerIssueService {
subDto.setEngChgLevel(material.getEngChgLevel() == null?"1": material.getEngChgLevel());
subDto.setSqeNo(seqNo);
subList.add(subDto);
seqNo++;
}
List<String> ids = changeAndAddHandlingUnit(customerIssueDto);

20
src/main/java/com/gaotao/modules/notify/controller/IssureNotifyController.java

@ -2,6 +2,7 @@ package com.gaotao.modules.notify.controller;
import com.gaotao.common.utils.PageUtils;
import com.gaotao.common.utils.PartAttributeUtil;
import com.gaotao.common.utils.R;
import com.gaotao.modules.base.entity.SOScheduledRoutingData;
import com.gaotao.modules.customer.entity.dto.ShipmentIssueDto;
@ -24,6 +25,9 @@ public class IssureNotifyController {
@Autowired
private IssureNotifyService issureNotifyService;
@Autowired
private PartAttributeUtil partAttributeUtil;
/**
* @Description 获取用户下面未下达领料申请单
* @Title getUserNotifyNo
@ -444,8 +448,20 @@ public class IssureNotifyController {
@RequestParam("site") String site,
@RequestParam("notifyNo") String notifyNo) {
try {
List<ImportPartAttrVo> importPartAttrVos = issureNotifyService.uploadNoorderNotifyExcel(file, site, notifyNo);
return R.ok().put("rows",importPartAttrVos);
List<ShopOrderAndMaterialVo> rows = issureNotifyService.uploadNoorderNotifyExcel(file, site, notifyNo);
if(rows != null && rows.size() > 0){
// 提前赋值:用contract赋值给site,用componentPartNo赋值给partQuery - rqrq
for (ShopOrderAndMaterialVo row : rows) {
row.setSite(row.getSite());
row.setPartQuery(row.getComponentPartNo()); // componentPartNo用于fillIsInWh查询 - rqrq
}
// 批量填充isInWh字段 - rqrq
partAttributeUtil.fillIsInWh(rows);
return R.ok().put("rows", rows);
}
return R.error("无法解析Excel中的值");
} catch (Exception e) {
return R.error("Excel导入失败: " + e.getMessage());
}

5
src/main/java/com/gaotao/modules/notify/entity/vo/ImportPartAttrVo.java

@ -65,4 +65,9 @@ public class ImportPartAttrVo {
* 托盘类型
*/
private String palletType;
/**
* 数量
*/
private BigDecimal qty;
}

2
src/main/java/com/gaotao/modules/notify/service/IssureNotifyService.java

@ -179,7 +179,7 @@ public interface IssureNotifyService {
List<SOIssueNotifyOrderList> getNotifyNoOrderDetailByType(SOIssueNotifyOrderList data)throws Exception;
List<ImportPartAttrVo> uploadNoorderNotifyExcel(MultipartFile file, String site, String notifyNo)throws Exception;
List<ShopOrderAndMaterialVo> uploadNoorderNotifyExcel(MultipartFile file, String site, String notifyNo)throws Exception;
int updateMaterialDetail(SOIssueNotifyOrderMaterialList data);
}

137
src/main/java/com/gaotao/modules/notify/service/impl/IssureNotifyServiceImpl.java

@ -1021,7 +1021,7 @@ public class IssureNotifyServiceImpl implements IssureNotifyService {
}
@Override
public List<ImportPartAttrVo> uploadNoorderNotifyExcel(MultipartFile file, String site, String notifyNo) throws Exception{
public List<ShopOrderAndMaterialVo> uploadNoorderNotifyExcel(MultipartFile file, String site, String notifyNo) throws Exception{
// 校验文件格式
if (file == null || file.isEmpty()) {
throw new RuntimeException("请选择要上传的文件");
@ -1044,148 +1044,49 @@ public class IssureNotifyServiceImpl implements IssureNotifyService {
throw new RuntimeException("Excel文件中没有有效数据");
}
// 转换为NotifyExcelData列表
List<NotifyExcelData> notifyExcelDataList = new ArrayList<>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
// 转换为ImportPartAttrVo列表
List<ShopOrderAndMaterialVo> importPartAttrVoList = new ArrayList<>();
for (int i = 0; i < excelDataList.size(); i++) {
Map<String, Object> rowData = excelDataList.get(i);
int rowIndex = i + 2; // Excel行号(考虑表头)
try {
NotifyExcelData notifyData = new NotifyExcelData();
ShopOrderAndMaterialVo importPartAttrVo = new ShopOrderAndMaterialVo();
// 第一列:site
Object siteObj = rowData.get("0");
if (siteObj == null || StringUtils.isBlank(siteObj.toString())) {
throw new RuntimeException("第" + rowIndex + "行的工厂编码(site)不能为空");
}
if (!siteObj.toString().trim().equals(site)){
throw new RuntimeException("第" + rowIndex + "行的工厂编码(site)与当前工厂不一致");
}
notifyData.setSite(siteObj.toString().trim());
// 第二列:orderNo
Object orderNoObj = rowData.get("1");
if (orderNoObj == null || StringUtils.isBlank(orderNoObj.toString())) {
throw new RuntimeException("第" + rowIndex + "行的订单号(orderNo)不能为空");
}
notifyData.setOrderNo(orderNoObj.toString().trim());
// 第三列:releaseNo
Object releaseNoObj = rowData.get("2");
if (releaseNoObj == null || StringUtils.isBlank(releaseNoObj.toString())) {
throw new RuntimeException("第" + rowIndex + "行的发布号(releaseNo)不能为空");
}
notifyData.setReleaseNo(releaseNoObj.toString().trim());
// 第四列:sequenceNo
Object sequenceNoObj = rowData.get("3");
if (sequenceNoObj == null || StringUtils.isBlank(sequenceNoObj.toString())) {
throw new RuntimeException("第" + rowIndex + "行的序列号(sequenceNo)不能为空");
}
notifyData.setSequenceNo(sequenceNoObj.toString().trim());
// 第五列:bomLineNo
Object bomLineNoObj = rowData.get("4");
if (bomLineNoObj == null || StringUtils.isBlank(bomLineNoObj.toString())) {
throw new RuntimeException("第" + rowIndex + "行的BOM行号(bomLineNo)不能为空");
}
try {
Integer bomLineNo = Integer.valueOf(bomLineNoObj.toString().trim());
if (bomLineNo <= 0) {
throw new RuntimeException("第" + rowIndex + "行的BOM行号(bomLineNo)必须是大于0的整数");
}
notifyData.setBomLineNo(bomLineNo);
} catch (NumberFormatException e) {
throw new RuntimeException("第" + rowIndex + "行的BOM行号(bomLineNo)必须是有效的整数");
}
// 设置站点
importPartAttrVo.setSite(site);
// 第六列:materialPartNo
Object materialPartNoObj = rowData.get("5");
if (materialPartNoObj == null || StringUtils.isBlank(materialPartNoObj.toString())) {
throw new RuntimeException("第" + rowIndex + "行的物料编码(materialPartNo)不能为空");
// 第一列:料号(A列,索引0)
Object partNoObj = rowData.get("0");
if (partNoObj == null || StringUtils.isBlank(partNoObj.toString())) {
throw new RuntimeException("第" + rowIndex + "行的料号不能为空");
}
notifyData.setMaterialPartNo(materialPartNoObj.toString().trim());
importPartAttrVo.setComponentPartNo(partNoObj.toString().trim());
// 第七列:needDate
Object needDateObj = rowData.get("6");
if (needDateObj == null || StringUtils.isBlank(needDateObj.toString())) {
throw new RuntimeException("第" + rowIndex + "行的需求日期(needDate)不能为空");
}
try {
Date needDate = dateFormat.parse(needDateObj.toString().trim());
notifyData.setNeedDate(needDate);
} catch (ParseException e) {
throw new RuntimeException("第" + rowIndex + "行的需求日期(needDate)格式不正确,请使用YYYY-MM-DD格式");
}
// 第八列:qty
Object qtyObj = rowData.get("7");
// 第二列:数量(B列,索引1)
Object qtyObj = rowData.get("1");
if (qtyObj == null || StringUtils.isBlank(qtyObj.toString())) {
throw new RuntimeException("第" + rowIndex + "行的数量(qty)不能为空");
throw new RuntimeException("第" + rowIndex + "行的数量不能为空");
}
try {
BigDecimal qty = new BigDecimal(qtyObj.toString().trim());
if (qty.compareTo(BigDecimal.ZERO) <= 0) {
throw new RuntimeException("第" + rowIndex + "行的数量(qty)必须大于0");
throw new RuntimeException("第" + rowIndex + "行的数量必须大于0");
}
notifyData.setQty(qty);
importPartAttrVo.setQtyIssued(qty);
} catch (NumberFormatException e) {
throw new RuntimeException("第" + rowIndex + "行的数量(qty)必须是有效的数字");
throw new RuntimeException("第" + rowIndex + "行的数量必须是有效的数字");
}
notifyExcelDataList.add(notifyData);
importPartAttrVoList.add(importPartAttrVo);
} catch (Exception e) {
throw new RuntimeException("第" + rowIndex + "行数据处理异常: " + e.getMessage());
}
}
// 打印解析结果到控制台
System.out.println("=== Excel解析结果 ===");
System.out.println("共解析到 " + notifyExcelDataList.size() + " 条数据:");
for (int i = 0; i < notifyExcelDataList.size(); i++) {
NotifyExcelData data = notifyExcelDataList.get(i);
System.out.println("第" + (i + 1) + "条: site=" + data.getSite()
+ ", orderNo=" + data.getOrderNo()
+ ", releaseNo=" + data.getReleaseNo()
+ ", sequenceNo=" + data.getSequenceNo()
+ ", bomLineNo=" + data.getBomLineNo()
+ ", materialPartNo=" + data.getMaterialPartNo()
+ ", needDate=" + dateFormat.format(data.getNeedDate())
+ ", qty=" + data.getQty());
}
System.out.println("=== 解析完成 ===");
// 按 site+orderNo+releaseNo+sequenceNo 分组
Map<String, List<NotifyExcelData>> groupedDataMap = notifyExcelDataList.stream()
.collect(Collectors.groupingBy(data ->
data.getSite() + "|" + data.getOrderNo() + "|" + data.getReleaseNo() + "|" + data.getSequenceNo()
));
System.out.println("=== 分组处理开始 ===");
System.out.println("共分为 " + groupedDataMap.size() + " 个工单组:");
// 遍历每个分组,进行业务处理
for (Map.Entry<String, List<NotifyExcelData>> entry : groupedDataMap.entrySet()) {
String groupKey = entry.getKey();
List<NotifyExcelData> groupData = entry.getValue();
// 解析分组key
String[] keyParts = groupKey.split("\\|");
String site2 = keyParts[0];
String orderNo = keyParts[1];
String releaseNo = keyParts[2];
String sequenceNo = keyParts[3];
System.out.println("处理工单组: site=" + site2 + ", orderNo=" + orderNo +
", releaseNo=" + releaseNo + ", sequenceNo=" + sequenceNo +
", 包含物料数量=" + groupData.size());
}
return null;
return importPartAttrVoList;
}
@Override

Loading…
Cancel
Save