物料手动推送启源qms
This commit is contained in:
parent
f597770b4b
commit
0a86bc0107
|
|
@ -0,0 +1,272 @@
|
||||||
|
package nccloud.web.uapbd.material.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.bd.baseservice.ArrayClassConvertUtil;
|
||||||
|
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.trade.business.HYSuperDMO;
|
||||||
|
import nc.bs.uapbd.util.MyHelper;
|
||||||
|
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
|
||||||
|
import nc.itf.scmpub.reference.uap.bd.material.MaterialPubService;
|
||||||
|
import nc.jdbc.framework.processor.MapProcessor;
|
||||||
|
import nc.pubitf.uapbd.IMaterialPubService;
|
||||||
|
import nc.util.mmf.framework.base.MMValueCheck;
|
||||||
|
import nc.vo.bd.defdoc.DefdocVO;
|
||||||
|
import nc.vo.bd.material.MaterialVO;
|
||||||
|
import nc.vo.bd.material.plan.MaterialPlanVO;
|
||||||
|
import nc.vo.bd.material.stock.MaterialStockVO;
|
||||||
|
import nc.vo.cmp.util.StringUtils;
|
||||||
|
import nc.vo.ml.NCLangRes4VoTransl;
|
||||||
|
import nc.vo.org.OrgVO;
|
||||||
|
import nc.vo.pub.BusinessException;
|
||||||
|
import nccloud.baseapp.core.log.NCCForPrintLogger;
|
||||||
|
import nccloud.framework.core.exception.ExceptionUtils;
|
||||||
|
import nccloud.framework.core.io.WebFile;
|
||||||
|
import nccloud.framework.core.io.WebFileDisposition;
|
||||||
|
import nccloud.framework.core.json.IJson;
|
||||||
|
import nccloud.framework.web.action.itf.ICommonAction;
|
||||||
|
import nccloud.framework.web.container.IRequest;
|
||||||
|
import nccloud.framework.web.json.JsonFactory;
|
||||||
|
import org.apache.http.client.config.CookieSpecs;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.owasp.esapi.ESAPI;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取物料PLM文件
|
||||||
|
*
|
||||||
|
* @author mzr
|
||||||
|
* @date 2025/8/4
|
||||||
|
*/
|
||||||
|
public class MaterialPushToQmsAction 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=addwlxx";
|
||||||
|
private Map<String, String> configParams;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object doAction(IRequest request) {
|
||||||
|
String read = request.read();
|
||||||
|
|
||||||
|
HYPubBO hyPub = new HYPubBO();
|
||||||
|
IJson json = JsonFactory.create();
|
||||||
|
Map<String,Object> info = json.fromJson(read, Map.class);
|
||||||
|
try {
|
||||||
|
String materialCodeArr = (String) info.get("pk_material"); // 获取所有物料编码
|
||||||
|
if (materialCodeArr == null ) {
|
||||||
|
ExceptionUtils.wrapBusinessException("物料不能为空");
|
||||||
|
}
|
||||||
|
// String[] pks = materialCodeArr.split(",");
|
||||||
|
MaterialVO useVOs = (MaterialVO) hyPub.queryByPrimaryKey(MaterialVO.class, materialCodeArr);
|
||||||
|
// MaterialVO[] materialVOS=new MaterialVO[(useVOs)];
|
||||||
|
configParams = MyHelper.getConfigParams("xb-config", null);
|
||||||
|
if (configParams.isEmpty()) {
|
||||||
|
throw new BusinessException("箱变的QMS接口缺少配置");
|
||||||
|
}
|
||||||
|
buildSyncData(new MaterialVO[]{useVOs}, "1002");
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建同步数据
|
||||||
|
*/
|
||||||
|
private void buildSyncData(MaterialVO[] useVOs, String eventType) throws BusinessException {
|
||||||
|
for (MaterialVO vo : useVOs) {
|
||||||
|
// 判断物料的业务单元是否是精密公司,不是则跳过
|
||||||
|
String pkOrg = vo.getPk_org();
|
||||||
|
String pkMaterial = vo.getPk_material();
|
||||||
|
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
|
||||||
|
String pkOrg1 = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.PK_ORG, OrgVO.CODE, "C038");
|
||||||
|
Integer num = MyHelper.checkIfOrg(configParams, pkMaterial, "jmOrg");
|
||||||
|
if (!"1009".equals(eventType) && ((num <= 0))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 字段值翻译
|
||||||
|
// String pk_marbasclass = vo.getPk_marbasclass();
|
||||||
|
// String mrlTypeName = MyHelper.getStrValByCondition(MarBasClassVO.getDefaultTableName(), MarBasClassVO.NAME,
|
||||||
|
// "pk_marbasclass = '" + pk_marbasclass + "'");
|
||||||
|
// 计量单位
|
||||||
|
Map unitMap = getGoodsInfo(pkMaterial);
|
||||||
|
Map<String, MaterialPlanVO> planMap = queryMaterialPlanInfoByPks(new String[]{pkMaterial}, pkOrg1,
|
||||||
|
new String[]{MaterialPlanVO.DEF2});
|
||||||
|
String qyCode = "";
|
||||||
|
if (MMValueCheck.isNotEmpty(planMap) &&
|
||||||
|
MMValueCheck.isNotEmpty(planMap.get(pkMaterial))) {
|
||||||
|
qyCode = planMap.get(pkMaterial).getDef2();
|
||||||
|
} else {
|
||||||
|
qyCode = vo.getCode();
|
||||||
|
}
|
||||||
|
// 1=未启用;2=已启用;3=已停用;
|
||||||
|
Integer enablestate = vo.getEnablestate();
|
||||||
|
String statusCode = (3 == enablestate) ? "1" : "0";
|
||||||
|
Map<String, Object> stockMap = MyHelper.getMapValByCondition(MaterialStockVO.getDefaultTableName(), "def3,def4,martype",
|
||||||
|
MaterialStockVO.PK_MATERIAL + " = '" + pkMaterial + "' and pk_org = '" + pkOrg1 + "'");
|
||||||
|
// 制造件传启源
|
||||||
|
if (!"MR".equals(stockMap.get("martype"))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 物料标志和产品分类字段在库存信息页签中,分配物料的时候没有默认值,需要在此处设置
|
||||||
|
// 物料标志
|
||||||
|
String wlbz = "产品";
|
||||||
|
String wlbzId = stockMap.get("def3") + "";
|
||||||
|
String defName = getDefName("zdy-jmzz001", wlbzId);
|
||||||
|
if (MMValueCheck.isNotEmpty(defName)) {
|
||||||
|
wlbz = defName;
|
||||||
|
}
|
||||||
|
// 产品分类
|
||||||
|
String cpfl;
|
||||||
|
String cpflId = stockMap.get("def4") + "";
|
||||||
|
String defName1 = getDefName("zdy-jmzz002", cpflId);
|
||||||
|
if (MMValueCheck.isEmpty(defName1)) {
|
||||||
|
continue;// 缺少产品分类则跳过同步启源
|
||||||
|
}
|
||||||
|
cpfl = defName1;
|
||||||
|
// 组装数据
|
||||||
|
JSONObject singleObj = new JSONObject();
|
||||||
|
// 批次编号,用于唯一标识当前传输的物料数据批次,便于追溯和批量处理
|
||||||
|
long cts = System.currentTimeMillis();
|
||||||
|
singleObj.put("batchid", cts);
|
||||||
|
JSONObject contentObj = new JSONObject();
|
||||||
|
// 计划信息自定义项2(原系统编码)BIP传启源物料档案的物料编码,BIP中物料编码传启源自定义字段“BIP物料编码”
|
||||||
|
contentObj.put("meswlbh", qyCode); // 启源物料编码
|
||||||
|
contentObj.put("bipwlbh", vo.getCode()); // BIP物料编码
|
||||||
|
contentObj.put("wlmc", vo.getName()); // 物料名称
|
||||||
|
String wlxhgg = MyHelper.skipNull(vo.getMaterialtype()) + MyHelper.skipNull(vo.getMaterialspec());
|
||||||
|
contentObj.put("wlxhgg", wlxhgg); // 物料型号规格
|
||||||
|
contentObj.put("wlfl", ""); // 物料分类
|
||||||
|
contentObj.put("cpfl", cpfl); // 产品分类
|
||||||
|
contentObj.put("wlbz", wlbz); // 物料标志
|
||||||
|
contentObj.put("sjjldw", unitMap.get("unitname")); // 设计计量单位
|
||||||
|
contentObj.put("cgjldw", unitMap.get("deputy_unitname")); // 采购计量单位
|
||||||
|
contentObj.put("zhxs", unitMap.getOrDefault("convertRate", "1.00")); // 转换系数
|
||||||
|
contentObj.put("flag_fq", statusCode); // 1/0 传递1代表物料废弃
|
||||||
|
contentObj.put("bz", vo.getMemo()); // 备注信息
|
||||||
|
JSONArray contentArr = new JSONArray();
|
||||||
|
contentArr.add(contentObj);
|
||||||
|
singleObj.put("Content", contentArr);
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"batchid": "10001",
|
||||||
|
"Content": [
|
||||||
|
{
|
||||||
|
"meswlbh": "ACC26711", 启源物料编码
|
||||||
|
"bipwlbh": "ACC26711", BIP物料编码
|
||||||
|
"wlmc": "铜排",物料名称
|
||||||
|
"wlxhgg": "15558190831", 物料型号规格
|
||||||
|
"wlfl": "铜排", 物料分类
|
||||||
|
"cpfl": "", 如果物料是产品需要填写产品分类
|
||||||
|
"sjjldw": "根", 设计计量单位
|
||||||
|
"cgjldw": "KG", 采购计量单位
|
||||||
|
"zhxs": "6", 转换系数,用于实物单位与采购单位的换算(即 1 根铜排的长度为 6.00 米),精确到两位小数,提升换算准确性
|
||||||
|
"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-Material-param = " + jsonStr);
|
||||||
|
// NCCForUAPLogger.debug("QMS-Material-param = " + jsonStr);
|
||||||
|
String baseUrl = configParams.get("qmsBaseUrl");
|
||||||
|
String requestUrl = baseUrl + reqUrl;
|
||||||
|
logger.error("QMS-Material-url = " + requestUrl);
|
||||||
|
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr);
|
||||||
|
JSONObject resultObj = JSONObject.parseObject(result);
|
||||||
|
logger.error("QMS-Material-res = " + result);
|
||||||
|
|
||||||
|
if (!"true".equals(resultObj.getString("success"))) {
|
||||||
|
logger.error("QMS-Material-error,result[" + resultObj.toJSONString() + "]");
|
||||||
|
throw new BusinessException("QMS-Material-error:" + resultObj.getString("message"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map getGoodsInfo(String pkMaterial) throws BusinessException {
|
||||||
|
String sql = " select a.pk_measdoc, c.name unitname, b.pk_measdoc deputyUnit, d.name deputy_unitname, nvl(b.measrate, '1/1') measrate " +
|
||||||
|
"from bd_material a " +
|
||||||
|
"left join bd_materialconvert b on a.pk_material = b.pk_material " +
|
||||||
|
"left join bd_measdoc c on a.pk_measdoc = c.pk_measdoc " +
|
||||||
|
"left join bd_measdoc d on b.pk_measdoc = d.pk_measdoc " +
|
||||||
|
"where a.pk_material = '" + pkMaterial + "' ";
|
||||||
|
Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor());
|
||||||
|
map.put("convertRate", MyHelper.transferSpecialField(map.get("measrate") + ""));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException {
|
||||||
|
String targetCode = configParams.get("jmOrg");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, MaterialPlanVO> queryMaterialPlanInfoByPks(String[] pks, String pk_stockorg,
|
||||||
|
String[] fields) throws BusinessException {
|
||||||
|
Map<String, MaterialPlanVO> map = null;
|
||||||
|
List<String> vids = Stream.of(pks).filter(Objects::nonNull).distinct().toList();
|
||||||
|
if (vids.isEmpty()) {
|
||||||
|
map = new HashMap<>();
|
||||||
|
} else {
|
||||||
|
map = NCLocator.getInstance().lookup(IMaterialPubService.class)
|
||||||
|
.queryMaterialPlanInfoByPks(vids.toArray(new String[0]), pk_stockorg, fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取自定义项信息
|
||||||
|
*/
|
||||||
|
private String getDefName(String code, String pk_defdoc) {
|
||||||
|
String res = "";
|
||||||
|
String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + "' and dr=0 ) and dr = 0 and pk_defdoc = '" + pk_defdoc + "'";
|
||||||
|
try {
|
||||||
|
DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere);
|
||||||
|
if (defdocVOs != null && defdocVOs.length > 0) {
|
||||||
|
res = defdocVOs[0].getName().trim();
|
||||||
|
}
|
||||||
|
} catch (DAOException e) {
|
||||||
|
logger.error("gyMes-SaleOrder-error,getDefName[" + e.getMessage() + "]");
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,4 +5,10 @@
|
||||||
<label>物料-下载PLM物料文件</label>
|
<label>物料-下载PLM物料文件</label>
|
||||||
<clazz>nccloud.web.uapbd.material.action.MaterialPlmDownloadAction</clazz>
|
<clazz>nccloud.web.uapbd.material.action.MaterialPlmDownloadAction</clazz>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
|
<action>
|
||||||
|
<name>uapbd.material.pushtoqms</name>
|
||||||
|
<label>物料-下载PLM物料文件</label>
|
||||||
|
<clazz>nccloud.web.uapbd.material.action.MaterialPushToQmsAction</clazz>
|
||||||
|
</action>
|
||||||
</actions>
|
</actions>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
<appcode>*</appcode>
|
<appcode>*</appcode>
|
||||||
<actions>
|
<actions>
|
||||||
<action>uapbd.material.downloadPlmFile</action>
|
<action>uapbd.material.downloadPlmFile</action>
|
||||||
|
<action>uapbd.material.pushtoqms</action>
|
||||||
|
<action>qc.checkbill.pushtoQms</action>
|
||||||
</actions>
|
</actions>
|
||||||
</authorize>
|
</authorize>
|
||||||
</authorizes>
|
</authorizes>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue