This commit is contained in:
parent
277823f24d
commit
1ee7936bbb
|
|
@ -1,6 +1,12 @@
|
|||
package nccloud.web.so.saleorder.action;
|
||||
|
||||
|
||||
import nc.bs.scmpub.query.SCMBillQuery;
|
||||
import nc.itf.so.initoutreg.IInitoutregMaintainApp;
|
||||
import nc.vo.ic.m4c.entity.SaleOutVO;
|
||||
import nc.vo.so.m30.entity.SaleOrderVO;
|
||||
import nc.vo.so.m4330.entity.AggInitoutregVO;
|
||||
import nc.vo.so.m4330.entity.InitoutregHVO;
|
||||
import nccloud.commons.lang.ArrayUtils;
|
||||
import com.yonyou.cloud.utils.StringUtils;
|
||||
import nc.bs.dao.BaseDAO;
|
||||
|
|
@ -10,10 +16,12 @@ import nccloud.framework.core.exception.BusinessException;
|
|||
import nccloud.framework.core.exception.ExceptionUtils;
|
||||
import nccloud.framework.core.io.WebFile;
|
||||
import nccloud.framework.core.json.IJson;
|
||||
import nccloud.framework.service.ServiceLocator;
|
||||
import nccloud.framework.web.action.itf.ICommonAction;
|
||||
import nccloud.framework.web.container.IRequest;
|
||||
import nccloud.framework.web.container.SessionContext;
|
||||
import nccloud.framework.web.json.JsonFactory;
|
||||
import nccloud.pubitf.so.saleorder.service.ISaleOrderQueryWebService;
|
||||
import nccloud.web.hrwa.psndocwadoc.vo.ImportHead;
|
||||
import nccloud.web.hrwa.pub.ErrorContent;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
|
|
@ -28,10 +36,7 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class SaleInvoiceNumImportAction implements ICommonAction {
|
||||
public SaleInvoiceNumImportAction() {
|
||||
|
|
@ -43,8 +48,78 @@ public class SaleInvoiceNumImportAction implements ICommonAction {
|
|||
if (ArrayUtils.isEmpty(webFiles)) {
|
||||
ExceptionUtils.wrapBusinessException(ErrorContent.FILEUPLOADNULL);
|
||||
}
|
||||
Map<String,String[]> readParameters=request.readParameters();
|
||||
List<String> srctype =new ArrayList<>();
|
||||
srctype.add("30");
|
||||
srctype.add("4330");
|
||||
srctype.add("4C");
|
||||
|
||||
String[] srcid = ArrayUtils.isEmpty(readParameters.get("srcids"))? null:readParameters.get("srcids")[0].split(",");
|
||||
String[] vsrctype = ArrayUtils.isEmpty(readParameters.get("vsrctype"))? null:readParameters.get("vsrctype")[0].split(",");
|
||||
|
||||
// 初始化三个分组,分别对应 srctype 的三个值
|
||||
List<String> srcidGroup30 = new ArrayList<>(); // 对应 "30"
|
||||
List<String> srcidGroup4330 = new ArrayList<>(); // 对应 "4330"
|
||||
List<String> srcidGroup4C = new ArrayList<>(); // 对应 "4C"
|
||||
ISaleOrderQueryWebService service = ServiceLocator.find(ISaleOrderQueryWebService.class);
|
||||
IInitoutregMaintainApp service1 = (IInitoutregMaintainApp)ServiceLocator.find(IInitoutregMaintainApp.class);
|
||||
// 用于记录已处理的 srcid,实现去重(HashSet 查找效率 O(1))
|
||||
Set<String> processedSrcids = new HashSet<>();
|
||||
SCMBillQuery<SaleOutVO> queryTool =
|
||||
new SCMBillQuery<SaleOutVO>(SaleOutVO.class);
|
||||
|
||||
|
||||
|
||||
List<Map<String, Object>> tslist = new ArrayList<>();
|
||||
try {
|
||||
// 安全校验:只有当两个数组都不为 null 且长度相等时才进行分组
|
||||
if (srcid != null && vsrctype != null && srcid.length == vsrctype.length) {
|
||||
// 遍历数组,按 vsrctype 与 srctype 的匹配关系分组
|
||||
for (int i = 0; i < srcid.length; i++) {
|
||||
String currentVsrctype = vsrctype[i].trim(); // 去除空格,避免匹配问题
|
||||
String currentSrcid = srcid[i].trim(); // 去除空格,保证数据干净
|
||||
|
||||
// 过滤空 srcid 或已处理过的重复 srcid
|
||||
if (currentSrcid.isEmpty() || processedSrcids.contains(currentSrcid)) {
|
||||
System.out.println("跳过无效/重复 srcid: " + currentSrcid);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2. 标记为已处理(避免后续重复)
|
||||
processedSrcids.add(currentSrcid);
|
||||
Map<String,Object> tsmap = new HashMap<>();
|
||||
tsmap.put("srcid",currentSrcid);
|
||||
String ts="";
|
||||
// 根据 vsrctype 匹配对应的 srctype,将 srcid 加入对应分组
|
||||
switch (currentVsrctype) {
|
||||
case "30":
|
||||
SaleOrderVO saleorderVO = service.querySaleOrderVObyId(currentSrcid);
|
||||
ts=saleorderVO.getParentVO().getTs().toString();
|
||||
break;
|
||||
case "4330":
|
||||
AggInitoutregVO[] checkBillVOs = service1.queryInitoutregAppByid(new String[]{currentSrcid});
|
||||
if(checkBillVOs.length>0){
|
||||
ts=checkBillVOs[0].getParentVO().getTs().toString();
|
||||
}
|
||||
// srcidGroup4330.add(currentSrcid);
|
||||
break;
|
||||
case "4C":
|
||||
|
||||
SaleOutVO[] saleOutVOs = queryTool.queryVOByIDs(new String[]{currentSrcid});
|
||||
if(saleOutVOs.length>0){
|
||||
ts=saleOutVOs[0].getParentVO().getTs().toString();
|
||||
}
|
||||
// srcidGroup4C.add(currentSrcid);
|
||||
break;
|
||||
default:
|
||||
// 处理不匹配的 vsrctype(可选,根据业务需求决定是否忽略或报错)
|
||||
System.out.println("忽略不匹配的 vsrctype: " + currentVsrctype + ",对应的 srcid: " + currentSrcid);
|
||||
break;
|
||||
}
|
||||
tsmap.put("ts",ts);
|
||||
tslist.add(tsmap);
|
||||
}
|
||||
}
|
||||
// 导入Excel文件,获取数据列表
|
||||
List<Map<String, Object>> dataList = importFormFile(
|
||||
webFiles[0].getInputStream(),
|
||||
|
|
@ -56,6 +131,8 @@ public class SaleInvoiceNumImportAction implements ICommonAction {
|
|||
result.put("error", "导入的数据为空");
|
||||
} else {
|
||||
result.put("isSuccess", "Y");
|
||||
|
||||
result.put("tsdata", tslist);
|
||||
result.put("data", dataList); // 返回数据列表
|
||||
result.put("totalCount", dataList.size()); // 返回总记录数
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue