Compare commits

..

No commits in common. "51b9d9367e6560fbd385db66d70383e4dfde3079" and "929c11c0fd77753fcf6932f663f38adbb8aa32d2" have entirely different histories.

3 changed files with 32 additions and 59 deletions

View File

@ -2,10 +2,9 @@ package nccloud.web.uapbd.material.action;
import nc.bs.uapbd.util.GetPlmFileUtil; import nc.bs.uapbd.util.GetPlmFileUtil;
import nccloud.framework.core.io.WebFile; import nccloud.framework.core.io.WebFile;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest; import nccloud.framework.web.container.IRequest;
import nccloud.web.action.NCCAction;
import java.util.Map; import nccloud.web.uapbd.commons.web.ParamUtils;
/** /**
* 获取物料PLM文件 * 获取物料PLM文件
@ -13,21 +12,15 @@ import java.util.Map;
* @author mzr * @author mzr
* @date 2025/8/4 * @date 2025/8/4
*/ */
public class MaterialPlmDownloadAction implements ICommonAction { public class MaterialPlmDownloadAction extends NCCAction {
@Override @Override
public Object doAction(IRequest request) { public <T> Object execute(IRequest request, T para) throws Exception {
WebFile files = null; ParamUtils param = new ParamUtils(request);
try { String materialCode = param.getString("materialCode", null);
Map<String, String[]> params_1 = request.readParameters(); materialCode = "101092250323";
String[] pks = params_1.get("materialCode"); // »ñÈ¡ËùÓÐ pk String[] materialCodeArr = materialCode.split(",", -1);
String materialCode = "101092250323,101092250323"; GetPlmFileUtil fileUtil = new GetPlmFileUtil();
String[] materialCodeArr = materialCode.split(",", -1); WebFile files = fileUtil.getPlmFiles(materialCodeArr);
GetPlmFileUtil fileUtil = new GetPlmFileUtil();
files = fileUtil.getPlmFiles(materialCodeArr);
} catch (Exception e) {
throw new RuntimeException(e);
}
return files; return files;
} }
} }

View File

@ -38,28 +38,21 @@ public class MaterialToEpicMesListener implements IBusinessListener {
BDCommonEvent e = (BDCommonEvent) event; BDCommonEvent e = (BDCommonEvent) event;
String eventType = event.getEventType(); String eventType = event.getEventType();
Object[] objs = e.getObjs(); Object[] objs = e.getObjs();
MaterialVO[] useVOs = ArrayClassConvertUtil.convert(objs, MaterialVO.class);
// EventType是事件编码 1002-新增后 1004-修改后 1071-状态由停用变为启用后 1069-状态由启用变为停用后 // EventType是事件编码 1002-新增后 1004-修改后 1071-状态由停用变为启用后 1069-状态由启用变为停用后
if ("1002".equals(eventType) || "1004".equals(eventType)) { if ("1002".equals(eventType) || "1004".equals(eventType)) {
MaterialVO[] useVOs = ArrayClassConvertUtil.convert(objs, MaterialVO.class);
configParams = MyHelper.getConfigParams("Dldz-config", null); configParams = MyHelper.getConfigParams("Dldz-config", null);
if (configParams.isEmpty()) { if (configParams.isEmpty()) {
throw new BusinessException("电力电子的艾普MES接口缺少配置"); throw new BusinessException("电力电子的艾普MES接口缺少配置");
} }
buildSyncData(useVOs, eventType); buildSyncData(useVOs, eventType);
} else if ("1071".equals(eventType) || "1069".equals(eventType)) { } else if ("1071".equals(eventType) || "1069".equals(eventType)) {
MaterialVO[] useVOs = ArrayClassConvertUtil.convert(objs, MaterialVO.class);
configParams = MyHelper.getConfigParams("Dldz-config", null); configParams = MyHelper.getConfigParams("Dldz-config", null);
if (configParams.isEmpty()) { if (configParams.isEmpty()) {
throw new BusinessException("电力电子的艾普MES接口缺少配置"); throw new BusinessException("电力电子的艾普MES接口缺少配置");
} }
} else if ("1009".equals(eventType)) {
Object[] newObjs = e.getNewObjs();
// 物料可见性范围-分配后
for (Object obj : newObjs) {
MaterialVO vo = (MaterialVO) obj;
String pkMaterial = vo.getPk_material();
}
} }
} }

View File

@ -1,6 +1,5 @@
package nc.bs.uapbd.util; package nc.bs.uapbd.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import nc.bs.dao.DAOException; import nc.bs.dao.DAOException;
import nc.bs.logging.Log; import nc.bs.logging.Log;
@ -42,11 +41,11 @@ public class GetPlmFileUtil {
private String token = ""; private String token = "";
private static final String tokenUrl = "/sipmweb/api/oauth"; private static final String tokenUrl = "/sipmweb/api/oauth";
// 根据物料编码获取零部件ID // 根据物料编码获取零部件ID
private String materialIdUrl = "/sipmweb/api/{rid}/search/{t}"; private String materialIdUrl = "/sipmweb/api/{rid}/search/{t}?key={key}&start={start}&size={size}";
// 根据零部件ID获取二维图档ID及信息 // 根据零部件ID获取二维图档ID及信息
private String materialFileIdUrl = "/sipmweb/api/{rid}/relation/{t}/{id}/data"; private String materialFileIdUrl = "/sipmweb/api/{rid}/relation/{t}/{id}/data?re={re}&start={start}&item={item}";
// 下载文件 // 下载文件
private String downlownUrl = "/sipmweb/web/download"; private String downlownUrl = "/sipmweb/web/download?rid={rid}&id={id}&t={t}&type={type}";
// http请求 // http请求
private static final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); private static final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
private static final CloseableHttpClient httpClient; private static final CloseableHttpClient httpClient;
@ -94,29 +93,29 @@ public class GetPlmFileUtil {
ByteArrayOutputStream zipOut = new ByteArrayOutputStream(); ByteArrayOutputStream zipOut = new ByteArrayOutputStream();
ZipOutputStream zipStream = new ZipOutputStream(zipOut); ZipOutputStream zipStream = new ZipOutputStream(zipOut);
try { try {
for (String materialCode : materialCodeArr) { for (String materialCode : materialCodeArr) {
JSONObject plmFileJson = this.getPlmFile(materialCode); JSONObject plmFileJson = this.getPlmFile(materialCode);
String objId = plmFileJson.getString("objId"); String objId = plmFileJson.getString("objId");
String fname = plmFileJson.getString("fname"); String fname = plmFileJson.getString("fname");
InputStream ins = this.doDownloadPlmFile(objId); InputStream ins = this.doDownloadPlmFile(objId);
try { try {
byte[] bytes = parseFileStream(ins); byte[] bytes = parseFileStream(ins);
zipStream.putNextEntry(new ZipEntry(fname)); zipStream.putNextEntry(new ZipEntry(fname));
zipStream.write(bytes); zipStream.write(bytes);
zipStream.closeEntry(); zipStream.closeEntry();
} finally { } finally {
if (ins != null) { if (ins != null) {
try { try {
ins.close(); ins.close();
} catch (IOException e) { } catch (IOException e) {
logger.error("Failed to close input stream: " + e.getMessage()); logger.error("Failed to close input stream: " + e.getMessage());
} }
} }
} }
} }
zipStream.finish(); zipStream.finish();
} finally { } finally {
zipStream.close(); zipStream.close();
} }
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String zipName = "物料图纸下载_" + sdf.format(new Date()); String zipName = "物料图纸下载_" + sdf.format(new Date());
@ -166,13 +165,7 @@ public class GetPlmFileUtil {
String result = doGet(fileUrl, map); String result = doGet(fileUrl, map);
logger.error("GetPlmFileUtil-getMaterialId-result = " + result); logger.error("GetPlmFileUtil-getMaterialId-result = " + result);
JSONObject jsonObject = JSONObject.parseObject(result); JSONObject jsonObject = JSONObject.parseObject(result);
String list = jsonObject.getString("list"); String objId = jsonObject.getString("objId");
JSONArray jsonArray = JSONObject.parseArray(list);
if (jsonArray == null || jsonArray.isEmpty()) {
throw new BusinessException("获取PLM物料id失败");
}
JSONObject listJson = jsonArray.getJSONObject(0);
String objId = listJson.getString("objId");
if (objId == null || objId.isEmpty()) { if (objId == null || objId.isEmpty()) {
throw new BusinessException("获取PLM物料id失败"); throw new BusinessException("获取PLM物料id失败");
} }
@ -196,17 +189,11 @@ public class GetPlmFileUtil {
String result = doGet(fileUrl, map); String result = doGet(fileUrl, map);
logger.error("GetPlmFileUtil-getFileId-result = " + result); logger.error("GetPlmFileUtil-getFileId-result = " + result);
JSONObject jsonObject = JSONObject.parseObject(result); JSONObject jsonObject = JSONObject.parseObject(result);
String list = jsonObject.getString("list"); String objId = jsonObject.getString("objId");
JSONArray jsonArray = JSONObject.parseArray(list);
if (jsonArray == null || jsonArray.isEmpty()) {
throw new BusinessException("获取PLM物料的文件信息失败");
}
JSONObject listJson = jsonArray.getJSONObject(0);
String objId = listJson.getString("objId");
if (objId == null || objId.isEmpty()) { if (objId == null || objId.isEmpty()) {
throw new BusinessException("获取PLM物料的文件信息失败"); throw new BusinessException("获取PLM物料的文件信息失败");
} }
return listJson; return jsonObject;
} }
/** /**