到货单检验

This commit is contained in:
lihao 2025-10-28 10:13:02 +08:00
parent 49f56dc502
commit 8c76f8e3e9
1 changed files with 477 additions and 0 deletions

View File

@ -0,0 +1,477 @@
package nccloud.web.pu.arrivalqc.action;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Log;
import nc.bs.trade.business.HYPubBO;
import nc.bs.uapbd.util.MyHelper;
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
import nc.itf.bd.supplier.baseinfo.ISupplierBaseInfoQryService;
import nc.itf.pu.m23.qc.IArriveForQC;
import nc.pubitf.pu.m23.pubquery.IArrivePubQuery;
import nc.pubitf.qc.c001.pu.ReturnObjectFor23;
import nc.vo.am.common.util.StringUtils;
import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.measdoc.MeasdocVO;
import nc.vo.bd.psn.PsndocVO;
import nc.vo.bd.supplier.SupplierVersionVO;
import nc.vo.org.OrgVO;
import nc.vo.pu.m23.entity.ArriveHeaderVO;
import nc.vo.pu.m23.entity.ArriveItemVO;
import nc.vo.pu.m23.entity.ArriveVO;
import nc.vo.pu.m23.entity.ArriveViewVO;
import nc.vo.pu.pub.util.AggVOUtil;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.model.entity.view.AbstractDataView;
import nc.vo.pubapp.pattern.model.tool.BillComposite;
import nc.vo.qc.c003.entity.ReportHeaderVO;
import nc.vo.qc.c003.entity.ReportItemVO;
import nc.vo.qc.pub.enumeration.StrictLevelEnum;
import nc.vo.sm.UserVO;
import nccloud.baseapp.core.log.NCCForUAPLogger;
import nccloud.commons.lang.ArrayUtils;
import nccloud.dto.pu.puinvoice.entity.DataInfo;
import nccloud.framework.core.exception.ExceptionUtils;
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.json.JsonFactory;
import nccloud.framework.web.processor.template.GridConvertProcessor;
import nccloud.pubitf.pu.arrival.service.IArrivalQueryService;
import nccloud.web.pu.arrivalqc.entity.QualityCheckInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @description 检验
* @author ligangt
* @date 2018年8月28日 下午1:43:35
* @version ncc1.0
*/
public class QualityCheckAction implements ICommonAction {
private static final String LOG_INFO_NAME = "qyMesLog";
private static final Log logger = Log.getInstance(LOG_INFO_NAME);
private static final String reqUrl = "/IF_QyErpApi.ashx?action=addsjd";
private Map<String, String> configParams;
@Override
public Object doAction(IRequest request) {
try {
// 获取前台json
IJson json = JsonFactory.create();
QualityCheckInfo info = json.fromJson(request.read(),
QualityCheckInfo.class);
ArriveViewVO[] views = null;
if (info.isQcEnable()) {
DataInfo[] idTs = info.getIdTs();
views = queryViewVOs(idTs);
} else {
GridConvertProcessor processor = new GridConvertProcessor();
views = processor.fromGrid(info.getGrid());
}
if (views != null && views.length > 0) {
// IPubUtilService pubService = ServiceLocator
// .find(IPubUtilService.class);
// if (pubService.isOrgQcEnable(info.getPk_org())) {
// 非紧急放行入库数量>0,即根据质检入库
// ArriveItemVO item = views[0].getBVO();
// if
// (MathTool.compareTo(MathTool.sub(item.getNaccumstorenum(),
// item.getNaccumletgoinnum()), UFDouble.ZERO_DBL) > 0) {
// //ExceptionUtils.wrapBusinessException("紧急放行数量大于入库数量");
// return false;
// }
// }
ArriveVO[] vos = this.getArriveVOs(views);
for (ArriveVO vo : vos) {
ArriveItemVO[] bvos = vo.getBVO();
for (ArriveItemVO bvo : bvos) {
UFDouble nchecknum = bvo.getNchecknum();
UFDouble nwillelignum = bvo.getNwillelignum();
if (nchecknum != null && nwillelignum != null) {
if (nchecknum.compareTo(UFDouble.ZERO_DBL) < 0
|| nwillelignum.compareTo(UFDouble.ZERO_DBL) < 0) {
ExceptionUtils.wrapBusinessException(
nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID(
"4004100_0", "04004100-0010")/*
* @res "报检数量和合格主数量不允许为负数"
*/);
}
}
UFDouble naccumchecknum = bvo.getNaccumchecknum();
if (naccumchecknum != null) {
if (naccumchecknum.compareTo(bvo.getNnum()) == 0) {
UFDouble naccumstorenum = bvo.getNaccumstorenum();
if (naccumstorenum != null
&& naccumstorenum.compareTo(UFDouble.ZERO_DBL) > 0) {
// ExceptionUtils.wrapBusinessException(
// nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
// .getStrByID("4004100_0", "04004100-0012")
// /* @res "第" */ + bvo.getCrowno()
// + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
// .getStrByID("4004100_0",
// "04004100-0307")/* @res 04004100-0062 "行已经完全入库,不能生成报检单"
// NCC-362748 修改后行已经生成过报检单且正在检验中不允许复检*/);
ExceptionUtils.wrapBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4008015_0",
"04008015-0077"+"\n", null, new String[] {
bvo.getCrowno()
}));
/* @res 04004100-0062 "行已经完全入库,不能生成报检单"
NCC-362748 修改后{0}行已经生成过报检单且正在检验中不允许复检*/
}
}
}
}
}
ArriveVO[] returnVos = this.check(vos, info.isCheck());
if (null == returnVos) {
ExceptionUtils.wrapBusinessException(
nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4004100_0",
"04004100-0011")/* @res "到货单检验失败!" */);
}
List<ArriveVO> validArriveList = new ArrayList<>();
configParams = MyHelper.getConfigParams("xb-config", null);
if (configParams.isEmpty()) {
throw new BusinessException("箱变的QMS接口缺少配置");
}
for (ArriveVO arriveVO : returnVos) {
ArriveItemVO[] bvos = arriveVO.getBVO();
boolean needSkip = false; // 标记是否需要跳过当前ArriveVO
// 检查当前到货单的所有明细只要有一个明细的vbdef23为Y/y就跳过整个到货单
if (bvos != null && bvos.length > 0) {
for (ArriveItemVO itemVO : bvos) {
// 获取vbdef23字段值处理null情况
String vbdef32 = (String) itemVO.getAttributeValue("vbdef32");
if (vbdef32 != null && "Y".equalsIgnoreCase(vbdef32)) {
needSkip = true;
break; // 只要有一个明细符合直接跳出明细循环
}
}
}
// 不需要跳过的加入有效列表
if (!needSkip) {
validArriveList.add(arriveVO);
}
}
buildSyncData(returnVos);
ServiceLocator.find(IArriveForQC.class).pushWmsByArriveVOs(vos);
// 把后台返回的轻量级聚合VO转换为视图VO
// new ClientBillCombinServer<ArriveVO>().combine(vos,
// returnVos);
// ArriveViewVO[] newViews = ArrivePublicUtil
// .convertAggToViewVO(vos);
// grid = processor.convert(info.getGrid().getPageid(),
// newViews);
// String[] successIds = this.getSuccessBIDs(returnVos);
// return successIds;
}
} catch (Exception e) {
ExceptionUtils.wrapException(e);
}
return null;
}
private ArriveViewVO[] queryViewVOs(DataInfo[] idTs) {
List<String> bids = new ArrayList<String>();
Map<String, String> idTsIndex = new HashMap<String, String>();
for (DataInfo item : idTs) {
bids.add(item.getId());
idTsIndex.put(item.getId(), item.getTs());
}
IArrivalQueryService qryService = ServiceLocator
.find(IArrivalQueryService.class);
ArriveViewVO[] viewvos = qryService
.queryViewByBIDs(bids.toArray(new String[0]));
// 重设ts
for (ArriveViewVO viewvo : viewvos) {
viewvo.setAttributeValue("ts",
idTsIndex.get(viewvo.getPk_arriveorder_b()));
}
return viewvos;
}
// private String[] getSuccessBIDs(ArriveVO[] returnVos) {
// List<String> bid_l = new ArrayList<String>();
// for (ArriveVO arrivevo : returnVos) {
// ArriveItemVO[] itemvos = arrivevo.getBVO();
// for (ArriveItemVO item : itemvos) {
// bid_l.add(item.getPk_arriveorder_b());
// }
// }
// return bid_l.toArray(new String[0]);
// }
private ArriveVO[] getArriveVOs(ArriveViewVO[] views) {
List<ArriveHeaderVO> headers = new ArrayList<ArriveHeaderVO>();
List<ArriveItemVO> items = new ArrayList<ArriveItemVO>();
for (AbstractDataView view : views) {
headers.add((ArriveHeaderVO) view.getVO(ArriveHeaderVO.class));
items.add((ArriveItemVO) view.getVO(ArriveItemVO.class));
}
BillComposite<ArriveVO> bc = new BillComposite<ArriveVO>(ArriveVO.class);
ArriveVO tempVO = new ArriveVO();
bc.append(tempVO.getMetaData().getParent(),
headers.toArray(new ArriveHeaderVO[headers.size()]));
bc.append(tempVO.getMetaData().getVOMeta(ArriveItemVO.class),
items.toArray(new ArriveItemVO[items.size()]));
return bc.composite();
}
/**
* 调用后台接口进行检验
*
* @param vos
* 到货单vo
* @param isCheck
* @return 检验结果数组
* @throws Exception
*/
private ArriveVO[] check(ArriveVO[] vos, boolean isCheck) throws Exception {
Object[] objs = ServiceLocator.find(IArriveForQC.class).qualityCheck(vos,
isCheck);
ArriveVO[] result = (ArriveVO[]) objs[0];
ReturnObjectFor23 rof = (ReturnObjectFor23) objs[1];
// 得到质检模块的提示信息
if (rof != null) {
Map<String, Integer> strictMap = rof.getCsourcebid_strictlevel();
Set<String> keySet = strictMap.keySet();
IArrivePubQuery arriveQuery = ServiceLocator.find(IArrivePubQuery.class);
ArriveItemVO[] items = arriveQuery
.queryItemVOByBids(keySet.toArray(new String[keySet.size()]));
String[] bpks = AggVOUtil.getPrimaryKeys(items);
if (strictMap.size() > 0) {
for (Map.Entry<String, Integer> entry : strictMap.entrySet()) {
String itempk = entry.getKey();
int dji = entry.getValue().intValue();
if (StrictLevelEnum.FREE.getReturnType() == dji) {
int i = Arrays.binarySearch(bpks, itempk);
items[i].getCrowno();
ExceptionUtils.wrapBusinessException(
nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
.getStrByID("4004100_0", "04004100-0012")/* @res "第" */
+ items[i].getCrowno()
+ nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID(
"4004100_0",
"04004100-0013")/*
* @res "行为质检连续批的严格程度为免检,不需要生成报检单!"
*/);
} else if (StrictLevelEnum.PAUSE.getReturnType() == dji) {
int i = Arrays.binarySearch(bpks, itempk);
items[i].getCrowno();
ExceptionUtils.wrapBusinessException(
nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
.getStrByID("4004100_0", "04004100-0012")/* @res "第" */
+ items[i].getCrowno()
+ nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID(
"4004100_0",
"04004100-0014")/*
* @res "行为质检连续批的严格程度为暂停, 不能生成报检单!"
*/);/*
* { 0 } 行为质检连续批的严格程度为暂停
* 不能生成报检单
*/
}
}
}
}
if (!ArrayUtils.isEmpty(result)) {
return result;
}
return null;
}
/**
* 构建同步数据
*
* @param arriveVOS 到货单VO
*/
private void buildSyncData(ArriveVO[] arriveVOS) throws BusinessException {
List<String> update =new ArrayList<>();
for (ArriveVO arriveVO : arriveVOS) {
ArriveHeaderVO hvo = arriveVO.getHVO();
ArriveItemVO[] bvo = arriveVO.getBVO();
String pk_arriveorder = hvo.getPk_arriveorder();
String pkOrg = hvo.getPk_org();
// 判断物料的业务单元是否是箱变公司不是则跳过
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
if (checkIfOrg(orgCode, configParams)) {
continue;
}
// 查询供应商信息
String pk_supplier_v = hvo.getPk_supplier_v();
SupplierVersionVO supplierVersionVO = new SupplierVersionVO();
if (pk_supplier_v != null && !pk_supplier_v.isEmpty() && !"~".equals(pk_supplier_v)) {
ISupplierBaseInfoQryService baseQryService = NCLocator.getInstance().lookup(ISupplierBaseInfoQryService.class);
supplierVersionVO = baseQryService.querySupplierVersionByVID(pk_supplier_v);
}
// 制单人名称
String creatorName = MyHelper.getStrValByCondition("sm_user", UserVO.USER_NAME,
UserVO.CUSERID + " = '" + hvo.getBillmaker() + "'");
JSONObject singleObj = new JSONObject();
// 采购合同号
String cghth = getCghthVal(hvo, bvo);
// 启源送检单主表
long cts = System.currentTimeMillis();
singleObj.put("batchid", cts);
singleObj.put("csdh", hvo.getVbillcode());// 送检单号BIP到货单号
singleObj.put("sjrq", hvo.getDmakedate().toString());// 送检日期格式建议为 yyyy-MM-dd
singleObj.put("wlgysid", supplierVersionVO.getCode());// 供应商编码
singleObj.put("wlgysmc", supplierVersionVO.getName());// 供应商名称
singleObj.put("sjr", creatorName);// 送检人BIP制单人
singleObj.put("cghth", cghth);// 采购合同号关联对应的采购合同
singleObj.put("bz", hvo.getVmemo());// 摘要备注用于填写送检单的补充说明信息
// 查询关联的质检报告-传入启源送检单的明细
HYPubBO hybo = new HYPubBO();
ReportItemVO[] reportItemVOS = (ReportItemVO[]) hybo.queryByCondition(ReportItemVO.class, " cfirstid = '" + pk_arriveorder + "'");
JSONArray contentArray = new JSONArray();
for (ReportItemVO reportItemVO : reportItemVOS) {
String pkReportbill = reportItemVO.getPk_reportbill();
ReportHeaderVO reportHeaderVO = (ReportHeaderVO) hybo.queryByPrimaryKey(ReportHeaderVO.class, pkReportbill);
String pkMaterial = reportHeaderVO.getPk_material();
Map<String, Object> materialMap = MyHelper.getMapValByCondition(MaterialVO.getDefaultTableName(), "code,name,materialspec,materialtype",
"pk_material = '" + pkMaterial + "'");
String cunitid = reportHeaderVO.getCunitid();// 主单位
String cunitname = MyHelper.getStrValByCondition(MeasdocVO.getDefaultTableName(), MeasdocVO.NAME,
MeasdocVO.PK_MEASDOC + " = '" + cunitid + "'");
JSONObject itemObj = new JSONObject();
itemObj.put("wlbh", materialMap.getOrDefault("code", "")); // 物料编码
itemObj.put("wlmc", materialMap.getOrDefault("name", "")); // 物料名称
String materialtype = skipNull(materialMap.get("materialtype"));
String materialspec = skipNull(materialMap.get("materialspec"));
itemObj.put("wlxhgg", materialtype + materialspec); // 物料型号规格
itemObj.put("sjsl", reportHeaderVO.getNapplynum().toString()); // 送检数量设计单位按设计计量单位统计的送检数量
itemObj.put("jldw", cunitname); // 计量单位
itemObj.put("bz", getBz(bvo,reportItemVO.getCfirstbid())); // 明细备注用于填写该送检物料的补充说明
itemObj.put("bipzyid", pkReportbill); // 质检报告ID
itemObj.put("bipqdid", reportItemVO.getPk_reportbill_b()); // 质检报告明细ID
contentArray.add(itemObj);
}
singleObj.put("Content", contentArray);
pushData(singleObj);
update.add(hvo.getPk_arriveorder());
updateArrveOrder(hvo.getPk_arriveorder());
}
}
private Object getBz(ArriveItemVO[] bvo, String cfirstbid) {
for (ArriveItemVO arriveItemVO : bvo) {
if(arriveItemVO.getPk_arriveorder_b().equals(cfirstbid)) {
return arriveItemVO.getVmemob();
}
}
return null;
}
private void updateArrveOrder(String pkArriveorder) throws DAOException {
BaseDAO dao = new BaseDAO();
String sql = "update po_arriveorder_b set vbdef32='Y' where pk_arriveorder='"
+ pkArriveorder + "'";
dao.executeUpdate(sql);
}
private String getCghthVal(ArriveHeaderVO hvo, ArriveItemVO[] bvo) throws BusinessException {
String cghth = "";
String pkPupsndoc = hvo.getPk_pupsndoc();
// 查询采购员名称
String name = "";
if (pkPupsndoc != null && !pkPupsndoc.isEmpty() && !"~".equals(pkPupsndoc)) {
name = MyHelper.getStrValByCondition(PsndocVO.getDefaultTableName(), PsndocVO.NAME,
PsndocVO.PK_PSNDOC + " = '" + pkPupsndoc + "'");
}
if (bvo != null && bvo.length > 0) {
StringBuilder cghthBuilder = new StringBuilder();
for (int i = 0; i < bvo.length; i++) {
String vsourcecode = bvo[i].getVsourcecode();
if (vsourcecode == null || vsourcecode.isEmpty() || "~".equals(vsourcecode)) {
continue;
}
if (i > 0) {
cghthBuilder.append(",");
}
cghthBuilder.append(vsourcecode);
if (!name.isEmpty()) {
cghthBuilder.append(name);
}
}
cghth = cghthBuilder.toString();
}
return cghth;
}
/**
* 推送同步数据
*/
private void pushData(JSONObject param) throws BusinessException {
// String jsonString = param.toJSONString();
// 转json字符串的时候保留null值
String jsonStr = JSON.toJSONString(param,
SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullStringAsEmpty
);
logger.error("QMS-QC-param = " + jsonStr);
NCCForUAPLogger.debug("QMS-QC-param = " + jsonStr);
String baseUrl = configParams.get("qmsBaseUrl");
String requestUrl = baseUrl + reqUrl;
logger.error("QMS-QC-url = " + requestUrl);
// String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr);
// NCCForUAPLogger.debug("QMS-QC-result = " + result);
// JSONObject resultObj = JSONObject.parseObject(result);
// logger.error("QMS-QC-res = " + result);
//
// if (!"true".equals(resultObj.getString("success"))) {
// logger.error("QMS-QC-error,result[" + resultObj.toJSONString() + "]");
// throw new BusinessException("QMS-QC-error:" + resultObj.getString("message"));
// }
}
private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException {
String targetCode = configParams.get("xbqcOrg");
if (targetCode == null || StringUtils.isEmpty(targetCode)) {
throw new BusinessException("未配置组织参数");
}
if (targetCode.contains("qc-")) {
targetCode = targetCode.replace("qc-", "");
}
String[] orgItem = targetCode.split(",");
for (String orgCode : orgItem) {
if (!orgCode.isEmpty() && orgCode.equals(code)) {
return false;
}
}
return true;
}
public String skipNull(Object value) {
if ((value == null) || (value.toString().trim().length() == 0)) {
return "";
}
return value.toString().trim();
}
}