箱变-质检报告推启源MES
This commit is contained in:
parent
8d86ad7e43
commit
bcd0662b19
|
@ -0,0 +1,160 @@
|
|||
package nc.impl.qc.c003.approve.action.rule;
|
||||
|
||||
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.logging.Log;
|
||||
import nc.bs.uapbd.util.MyHelper;
|
||||
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
|
||||
import nc.impl.pubapp.pattern.rule.IRule;
|
||||
import nc.vo.bd.material.MaterialVO;
|
||||
import nc.vo.org.OrgVO;
|
||||
import nc.vo.pub.BusinessException;
|
||||
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
||||
import nc.vo.qc.c003.entity.ReportHeaderVO;
|
||||
import nc.vo.qc.c003.entity.ReportItemVO;
|
||||
import nc.vo.qc.c003.entity.ReportVO;
|
||||
import nccloud.baseapp.core.log.NCCForUAPLogger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 箱变-质检报告推启源MES
|
||||
*
|
||||
* @author mzr
|
||||
* @date 2025/8/26
|
||||
*/
|
||||
public class SyncQcQmsRule implements IRule<ReportVO> {
|
||||
|
||||
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 void process(ReportVO[] reportVOS) {
|
||||
try {
|
||||
if (reportVOS == null || reportVOS.length == 0) {
|
||||
return;
|
||||
}
|
||||
configParams = MyHelper.getConfigParams("xb-config", null);
|
||||
if (configParams.isEmpty()) {
|
||||
throw new BusinessException("箱变的QMS接口缺少配置");
|
||||
}
|
||||
buildSyncData(reportVOS);
|
||||
} catch (Exception e) {
|
||||
ExceptionUtils.wrappException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建同步数据
|
||||
*/
|
||||
private void buildSyncData(ReportVO[] useVOs) throws BusinessException {
|
||||
BaseDAO baseDAO = new BaseDAO();
|
||||
for (ReportVO vo : useVOs) {
|
||||
ReportHeaderVO hvo = vo.getHVO();
|
||||
ReportItemVO[] bvo = vo.getBVO();
|
||||
// 判断物料的业务单元是否是箱变公司,不是则跳过
|
||||
String pkOrg = hvo.getPk_org();
|
||||
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
|
||||
if (checkIfOrg(orgCode, configParams)) {
|
||||
continue;
|
||||
}
|
||||
// 组装数据
|
||||
JSONObject singleObj = new JSONObject();
|
||||
long cts = System.currentTimeMillis();
|
||||
singleObj.put("batchid", cts);
|
||||
singleObj.put("csdh", hvo.getVapplybillcode());// 送检单号,采购送检单的唯一标识编号
|
||||
singleObj.put("sjrq", hvo.getDapplydate().toString());// 送检日期,格式建议为 yyyy-MM-dd
|
||||
singleObj.put("wlgysid", "");// 供应商编码
|
||||
singleObj.put("wlgysmc", "");// 供应商名称
|
||||
singleObj.put("sjr", hvo.getPk_applyer());// 送检人,负责提交送检单的人员姓名
|
||||
singleObj.put("cghth", "");// 采购合同号,关联对应的采购合同
|
||||
singleObj.put("bz", "");// 摘要备注,用于填写送检单的补充说明信息
|
||||
|
||||
String pkMaterial = hvo.getPk_material();
|
||||
Map<String, Object> materialMap = MyHelper.getMapValByCondition(MaterialVO.getDefaultTableName(), "code,name,materialspec,materialtype",
|
||||
"pk_material = '" + pkMaterial + "'");
|
||||
// 处理Content数组
|
||||
JSONArray contentArray = new JSONArray();
|
||||
for (ReportItemVO item : bvo) {
|
||||
JSONObject itemObj = new JSONObject();
|
||||
itemObj.put("wlbh", materialMap.getOrDefault("code", "")); // 物料编码
|
||||
itemObj.put("wlmc", materialMap.getOrDefault("name", "")); // 物料名称
|
||||
String materialtype = materialMap.getOrDefault("materialtype", "") + "";
|
||||
String materialspec = materialMap.getOrDefault("materialspec", "") + "";
|
||||
itemObj.put("wlxhgg", materialtype + materialspec); // 物料型号规格
|
||||
itemObj.put("sjsl", ""); // 送检数量(设计单位),按设计计量单位统计的送检数量
|
||||
itemObj.put("jldw", ""); // 计量单位
|
||||
itemObj.put("bz", ""); // 明细备注,用于填写该送检物料的补充说明
|
||||
contentArray.add(itemObj);
|
||||
}
|
||||
|
||||
singleObj.put("Content", contentArray);
|
||||
/* {
|
||||
"batchid": "10002",
|
||||
"csdh": "SJ202405001",
|
||||
"sjrq": "2024-05-20",
|
||||
"wlgysid": "GY001",
|
||||
"wlgysmc": "XX 金属材料有限公司",
|
||||
"sjr": "张三",
|
||||
"cghth": "HT202405003",
|
||||
"bz": "紧急送检,需优先检测",
|
||||
"Content": [
|
||||
{
|
||||
"wlbh": "ACC26711",
|
||||
"wlmc": "铜排",
|
||||
"wlxhgg": "15558190831",
|
||||
"jldw": "米",
|
||||
"sjsl": "50",
|
||||
"bz": "无特殊要求"
|
||||
}
|
||||
]
|
||||
}*/
|
||||
pushData(singleObj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送同步数据
|
||||
*/
|
||||
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);
|
||||
JSONObject resultObj = JSONObject.parseObject(result);
|
||||
logger.error("QMS-QC-res = " + result);
|
||||
|
||||
if (!"success".equals(resultObj.getString("success"))) {
|
||||
// throw new BusinessException("QMS-QC-error:" + resultObj.getString("msg"));
|
||||
logger.error("QMS-QC-error,result[" + resultObj.toJSONString() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException {
|
||||
String targetCode = configParams.get("xbOrg");
|
||||
if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) {
|
||||
throw new BusinessException("未配置组织参数");
|
||||
}
|
||||
String[] orgItem = targetCode.split(",");
|
||||
for (String orgCode : orgItem) {
|
||||
if (!orgCode.isEmpty() && orgCode.equals(code)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue