diff --git a/ic/src/private/nccloud/api/impl/ic/m4d/APIMaterialOutMaintainImpl.java b/ic/src/private/nccloud/api/impl/ic/m4d/APIMaterialOutMaintainImpl.java index 0271441b..ae57dd7a 100644 --- a/ic/src/private/nccloud/api/impl/ic/m4d/APIMaterialOutMaintainImpl.java +++ b/ic/src/private/nccloud/api/impl/ic/m4d/APIMaterialOutMaintainImpl.java @@ -28,8 +28,8 @@ import nc.vo.mmpac.pickm.entity.AggPickmVO; import nc.vo.mmpac.pickm.entity.PickmItemVO; import nc.vo.pub.BusinessException; import nc.vo.pub.VOStatus; -import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.pattern.pub.MathTool; import nc.vo.scmpub.check.billvalidate.BillVOsCheckRule; import nc.vo.scmpub.res.billtype.ICBillType; import nc.vo.scmpub.util.ArrayUtil; @@ -278,11 +278,13 @@ public class APIMaterialOutMaintainImpl implements IAPIMaterialOutMaintain { if (utils != null && utils.isWMS()) { // 获取originBill里表体的主键和项目字段形成Map,再遍历materialOutVOs去替换明细的项目 Map originProjectMap = new HashMap<>(); + Map originCproductMap = new HashMap<>(); for (MaterialOutVO originBill : originBills) { MaterialOutBodyVO[] originBodys = originBill.getBodys(); if (originBodys != null) { for (MaterialOutBodyVO originBody : originBodys) { originProjectMap.put(originBody.getCgeneralbid(), originBody.getCprojectid()); + originCproductMap.put(originBody.getCgeneralbid(), originBody.getCproductorid()); } } } @@ -292,9 +294,13 @@ public class APIMaterialOutMaintainImpl implements IAPIMaterialOutMaintain { if (bodyVOs != null) { for (MaterialOutBodyVO bodyVO : bodyVOs) { String projectId = originProjectMap.get(bodyVO.getCgeneralbid()); + String cproductId = originCproductMap.get(bodyVO.getCgeneralbid()); if (projectId != null) { bodyVO.setCprojectid(projectId); } + if (cproductId != null) { + bodyVO.setCproductorid(cproductId); + } } } } @@ -384,6 +390,10 @@ public class APIMaterialOutMaintainImpl implements IAPIMaterialOutMaintain { @Override public JSONObject destIssue(Map paramMap) throws BusinessException { + UFDouble num = new UFDouble(paramMap.get("num").toString()); + if (MMValueCheck.isEmpty(num) || MathTool.isZero(num)) { + throw new BusinessException("领料套数不能为0!"); + } // 启源领料 /* 1、传入数据基本非空校验 @@ -392,9 +402,13 @@ public class APIMaterialOutMaintainImpl implements IAPIMaterialOutMaintain { 4、处理材料出库VO部分字段的赋值(行数量 = 本次领料套数(启源传入)*单位主用量(备料计划)) 5、调用材料出库的保存方法 */ - List mids; + List mids = null; + String sql = "SELECT cpickmid from mm_pickm WHERE dr = 0 AND fbillstatus = 1 AND csourcebillrowid = '[csourcebillrowid]'"; + if (MathTool.compareTo(num, UFDouble.ZERO_DBL) < 0) { + // 成套退料-查询审批态和完成态的备料计划 + sql = "SELECT cpickmid from mm_pickm WHERE dr = 0 AND fbillstatus in (1,2) AND csourcebillrowid = '[csourcebillrowid]'"; + } try { - String sql = "SELECT cpickmid from mm_pickm WHERE dr = 0 AND fbillstatus = 1 AND csourcebillrowid = '[csourcebillrowid]'"; sql = sql.replace("[csourcebillrowid]", paramMap.get("cpmobid").toString()); mids = (List) getDao().executeQuery(sql, new ColumnListProcessor()); } catch (DAOException e) { @@ -431,24 +445,8 @@ public class APIMaterialOutMaintainImpl implements IAPIMaterialOutMaintain { newVos.toArray(new AggPickmVO[0]), null, PfButtonClickContext.ClassifyByItfdef); // 设置行号 setMaterialOutRowNum(vos); - UFDouble num = new UFDouble(paramMap.get("num").toString()); for (MaterialOutVO vo : vos) { MaterialOutHeadVO headVo = vo.getHead(); - UFDate dbilldate = headVo.getDbilldate(); - // 因开关账检查的限制需设置单据日期, 如果单据日期小于2025-11-02,则单据日期设置为2025-11-02 - UFDate ufDate = new UFDate("2025-11-02"); - if (dbilldate != null) { - int i = dbilldate.compareTo(ufDate); - if (i < 0) { - headVo.setDbilldate(ufDate); - } - } else { - UFDate nowDate = new UFDate(); - int i = nowDate.compareTo(ufDate); - if (i < 0) { - headVo.setDbilldate(ufDate); - } - } // 设置 vdef9 启源领料id if (MMValueCheck.isNotEmpty(paramMap.get("vdef9"))) { headVo.setVdef9(paramMap.get("vdef9").toString()); diff --git a/uapbd/src/private/nc/bs/uapbd/task/ims/ErpIaI2billFromGyImsPlugin.java b/uapbd/src/private/nc/bs/uapbd/task/ims/ErpIaI2billFromGyImsPlugin.java index 33cbcb67..8b6647cb 100644 --- a/uapbd/src/private/nc/bs/uapbd/task/ims/ErpIaI2billFromGyImsPlugin.java +++ b/uapbd/src/private/nc/bs/uapbd/task/ims/ErpIaI2billFromGyImsPlugin.java @@ -76,7 +76,13 @@ public class ErpIaI2billFromGyImsPlugin implements IBackgroundWorkPlugin { headJson.put("cpayfinorgvid", "C003");// 应付财务组织最新版本 headJson.put("cpayfinorgoid", "C003");// 应付财务组织 headJson.put("creator", "BIP"); - headJson.put("billmaker", map.get("billmaker")); + if (MMValueCheck.isNotEmpty(map.get("creator"))) { + headJson.put("creator", map.get("creator")); + } + headJson.put("billmaker", "BIP"); + if (MMValueCheck.isNotEmpty(map.get("billmaker"))) { + headJson.put("billmaker", map.get("billmaker")); + } if (map.get("dbilldate") != null && map.get("dbilldate") instanceof Timestamp dbilldate) { String dbilldateStr = DATETIME_FORMATTER.format(dbilldate); headJson.put("dbilldate", dbilldateStr); // 单据日期 diff --git a/uapbd/src/private/nc/bs/uapbd/task/mes/epic/MaterialToEpicMesPlugin.java b/uapbd/src/private/nc/bs/uapbd/task/mes/epic/MaterialToEpicMesPlugin.java index 8667825c..d0d49ed9 100644 --- a/uapbd/src/private/nc/bs/uapbd/task/mes/epic/MaterialToEpicMesPlugin.java +++ b/uapbd/src/private/nc/bs/uapbd/task/mes/epic/MaterialToEpicMesPlugin.java @@ -105,7 +105,7 @@ public class MaterialToEpicMesPlugin implements IBackgroundWorkPlugin { String sql = " SELECT DISTINCT b.pk_material" + " FROM bd_materialstock b" + " LEFT JOIN bd_material a ON a.pk_material = b.pk_material" + - " WHERE b.dr = 0 AND a.dr = 0 AND def30 != 'Y'" + + " WHERE b.dr = 0 AND a.dr = 0 AND a.def30 != 'Y'" + " AND " + inStrPkOrg + " AND (b.ts > '" + rangeTimeString + "' OR a.ts > '" + rangeTimeString + "')"; List> pkList = (List>) getDao().executeQuery(sql, new MapListProcessor()); diff --git a/uapbd/src/private/nc/bs/uapbd/task/mes/qy/MaterialToQmsAgainPlugin.java b/uapbd/src/private/nc/bs/uapbd/task/mes/qy/MaterialToQmsAgainPlugin.java new file mode 100644 index 00000000..787eff1e --- /dev/null +++ b/uapbd/src/private/nc/bs/uapbd/task/mes/qy/MaterialToQmsAgainPlugin.java @@ -0,0 +1,261 @@ +package nc.bs.uapbd.task.mes.qy; + +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.logging.Log; +import nc.bs.pub.pa.PreAlertObject; +import nc.bs.pub.taskcenter.BgWorkingContext; +import nc.bs.pub.taskcenter.IBackgroundWorkPlugin; +import nc.bs.trade.business.HYPubBO; +import nc.bs.uapbd.util.MyHelper; +import nc.bs.uapbd.util.ThirdPartyPostRequestUtil; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.jdbc.framework.processor.MapListProcessor; +import nc.jdbc.framework.processor.MapProcessor; +import nc.util.mmf.framework.base.MMValueCheck; +import nc.vo.bd.material.MaterialVO; +import nc.vo.bd.material.marbasclass.MarBasClassVO; +import nc.vo.fi.pub.SqlUtils; +import nc.vo.pub.BusinessException; +import nc.vo.pubapp.pattern.data.ValueUtils; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * 箱变-物料-定时重推推送启源 + * + * @author mzr + * @date 2025-12-13 + */ +public class MaterialToQmsAgainPlugin implements IBackgroundWorkPlugin { + 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 configParams; + private String startDate = ""; + private BaseDAO dao; + + public BaseDAO getDao() { + if (dao == null) { + dao = new BaseDAO(); + } + return dao; + } + + @Override + public PreAlertObject executeTask(BgWorkingContext bgWorkingContext) throws BusinessException { + this.initParams(bgWorkingContext); + configParams = MyHelper.getConfigParams("xb-config", null); + if (configParams.isEmpty()) { + throw new BusinessException("箱变的QMS接口缺少配置"); + } + try { + List> pkList = getPkList(); + if (pkList == null || pkList.isEmpty()) { + return null; + } + HYPubBO hyPub = new HYPubBO(); + List voList = new ArrayList<>(); + for (Map map : pkList) { + String pkMaterial = map.get("pk_material"); + MaterialVO materialVO = (MaterialVO) hyPub.queryByPrimaryKey(MaterialVO.class, pkMaterial); + if (materialVO != null) { + voList.add(materialVO); + } + } + if (!voList.isEmpty()) { + logger.error("MaterialToQmsAgainPlugin-size:" + voList.size()); + buildSyncData(voList); + } + } catch (Exception e) { + logger.error("MaterialToQmsPlugin-exp:" + e.getMessage(), e); + } + return null; + } + + private List> getPkList() throws BusinessException { + String targetCode = configParams.get("xbOrg"); + if (targetCode == null || MMValueCheck.isEmpty(targetCode)) { + throw new BusinessException("未配置组织参数"); + } + String[] orgItem = targetCode.split(","); + String inStr = SqlUtils.getInStr("code", orgItem, true); + String orgSql = " SELECT pk_stockorg,code,name FROM org_stockorg WHERE DR = 0 AND " + inStr; + List> orgList = (List>) getDao().executeQuery(orgSql, new MapListProcessor()); + if (orgList.isEmpty()) { + return null; + } + String[] stockorgs = orgList.stream().map(map -> map.get("pk_stockorg")).distinct().toArray(String[]::new); + String inStrPkOrg = SqlUtils.getInStr("b.pk_org", stockorgs, true); + LocalDateTime nowTime = LocalDateTime.now(); + String timeString = nowTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + String rangeTimeString = timeString + " 00:00:00"; + if (MMValueCheck.isNotEmpty(startDate)) { + // 如果有指定的开始时间,使用指定的时间限制查询条件 + rangeTimeString = startDate; + } + String sql = " SELECT DISTINCT b.pk_material" + + " FROM bd_materialstock b" + + " LEFT JOIN bd_material a ON a.pk_material = b.pk_material" + + " WHERE b.dr = 0 AND a.dr = 0 AND a.def36 != 'Y'" + + " AND " + inStrPkOrg + + " AND (b.ts > '" + rangeTimeString + "' OR a.ts > '" + rangeTimeString + "')"; + logger.error("MaterialToQmsAgainPlugin-sql:" + sql); + List> pkList = (List>) getDao().executeQuery(sql, new MapListProcessor()); + return pkList; + } + + /** + * 构建同步数据 + */ + private void buildSyncData(List useVOs) throws BusinessException { + for (MaterialVO vo : useVOs) { + String pkMaterial = vo.getPk_material(); + // 字段值翻译 + String pk_marbasclass = vo.getPk_marbasclass(); + String mrlTypeName = MyHelper.getStrValByCondition(MarBasClassVO.getDefaultTableName(), MarBasClassVO.CODE, + "pk_marbasclass = '" + pk_marbasclass + "'"); + // 计量单位 + // 过滤物料分类 + String isPushtoQms = MyHelper.getStrValByCondition(MarBasClassVO.getDefaultTableName(), MarBasClassVO.DEF3, + "pk_marbasclass = '" + pk_marbasclass + "'"); + // 计量单位 + if (null != isPushtoQms && "Y".equals(isPushtoQms)) { + continue; + } + // 过滤物料分类 + if (checkMrlType(mrlTypeName, configParams)) { + continue; + } + Map unitMap = getGoodsInfo(pkMaterial); + + // 1=未启用;2=已启用;3=已停用; + Integer enablestate = vo.getEnablestate(); + String statusCode = (3 == enablestate) ? "1" : "0"; + // 组装数据 + JSONObject singleObj = new JSONObject(); + // 批次编号,用于唯一标识当前传输的物料数据批次,便于追溯和批量处理 + long cts = System.currentTimeMillis(); + singleObj.put("batchid", cts); + JSONObject contentObj = new JSONObject(); + contentObj.put("meswlbh", vo.getCode()); // 启源物料编码 + 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", mrlTypeName); // 物料分类 + contentObj.put("wlbz", getMrlType(pkMaterial, configParams.get("mrlOrg"))); // 物料标志 + 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); + updateBs(pkMaterial); + } + } + + private void updateBs(String pkMaterial) throws DAOException { + String sql = "update BD_MATERIAL set def36='Y' where pk_material='" + + pkMaterial + "'"; + getDao().executeUpdate(sql); + } + + private Object getMrlType(String pkMaterial, String xbOrg) throws DAOException { + String sql = " select martype from bd_materialstock left join org_stockorg on org_stockorg.pk_stockorg = bd_materialstock.pk_org " + + " where pk_material = '" + pkMaterial + "' AND bd_materialstock.dr=0 " + " and org_stockorg.code = '" + xbOrg + "' "; + Object map = (Object) new BaseDAO().executeQuery(sql, new ColumnProcessor()); + return map; + } + + private boolean checkMrlType(String mrlTypeName, Map configParams) throws BusinessException { + // 从配置中获取目标类型字符串 + String targetCode = configParams.get("mrlType"); + // 配置为空则直接返回false + if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) { + return false; + } + // 按逗号拆分多个类型 + String[] typeItems = targetCode.split(","); + // 遍历每个类型,检查是否以mrlTypeName为前缀 + for (String typeCode : typeItems) { + // 跳过空字符串,且判断当前类型是否以目标名称为前缀 + if (!typeCode.isEmpty() && typeCode.startsWith(mrlTypeName)) { + return true; + } + } + // 无匹配则返回false + return false; + } + + /** + * 推送同步数据 + */ + private void pushData(JSONObject param) throws BusinessException { + // 转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); + logger.error("QMS-Material-res = " + result); + JSONObject resultObj = JSONObject.parseObject(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 void initParams(BgWorkingContext bgwc) { + this.startDate = ValueUtils.getString(bgwc.getKeyMap().get("startDate")); + } + +} diff --git a/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java index 78071f50..fb769f98 100644 --- a/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java +++ b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java @@ -7,8 +7,9 @@ import nc.bs.logging.Logger; import nc.bs.trade.business.HYSuperDMO; import nc.bs.uapbd.util.MyHelper; import nc.jdbc.framework.processor.ColumnProcessor; +import nc.pubitf.para.SysInitQuery; import nc.vo.fi.pub.SqlUtils; -import nc.vo.org.FactoryVO; +import nc.vo.org.OrgVO; import nc.vo.pub.BusinessException; import nc.vo.pub.lang.UFDateTime; import nc.vo.pub.msg.CommonMessageVO; @@ -61,7 +62,8 @@ public class MsgResource extends AbstractNCCRestResource { String content = (String) jsonObject.get("content"); String orgCode = (String) jsonObject.get("orgCode"); try { - String pkOrg = MyHelper.transferField(FactoryVO.getDefaultTableName(), FactoryVO.PK_FACTORY, FactoryVO.CODE, orgCode); + String pkOrg = MyHelper.getStrValByCondition(OrgVO.getDefaultTableName(), OrgVO.PK_ORG, + OrgVO.CODE + " = '" + orgCode + "' and ISBUSINESSUNIT = 'Y'"); if (pkOrg == null || pkOrg.isEmpty()) { return ResultMessageUtil.toJSON(false, "未查询到组织:" + orgCode); } @@ -128,7 +130,8 @@ public class MsgResource extends AbstractNCCRestResource { String content = (String) jsonObject.get("content"); String orgCode = (String) jsonObject.get("orgCode"); try { - String pkOrg = MyHelper.transferField(FactoryVO.getDefaultTableName(), FactoryVO.PK_FACTORY, FactoryVO.CODE, orgCode); + String pkOrg = MyHelper.getStrValByCondition(OrgVO.getDefaultTableName(), OrgVO.PK_ORG, + OrgVO.CODE + " = '" + orgCode + "' and ISBUSINESSUNIT = 'Y'"); if (pkOrg == null || pkOrg.isEmpty()) { return ResultMessageUtil.toJSON(false, "未查询到组织:" + orgCode); } @@ -180,6 +183,65 @@ public class MsgResource extends AbstractNCCRestResource { } } + @POST + @Path("operation/commonSave") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString commonSave(JSONObject jsonObject) { + String content = (String) jsonObject.get("content"); + String orgCode = (String) jsonObject.get("orgCode"); + String title = jsonObject.get("title") + ""; + try { + String pkOrg = MyHelper.getStrValByCondition(OrgVO.getDefaultTableName(), OrgVO.PK_ORG, + OrgVO.CODE + " = '" + orgCode + "' and ISBUSINESSUNIT = 'Y'"); + if (pkOrg == null || pkOrg.isEmpty()) { + return ResultMessageUtil.toJSON(false, "未查询到组织:" + orgCode); + } + String msgRoleCode = SysInitQuery.getParaString(pkOrg, "msgRoleCode"); + Map configParams = new HashMap<>(); + configParams.put("msgRoleCode", msgRoleCode); + // 定义接收消息人员信息集合 + ArrayList userList = new ArrayList<>(); + + // 根据传递的角色查询要发送消息的用户信息 + String roleId = getMsgRole(pkOrg, "", configParams); + UserVO[] userVOS = getUserByRole(roleId); + if (userVOS == null || userVOS.length == 0) { + return ResultMessageUtil.toJSON(false, "未查询到用户"); + } + + for (UserVO smUser : userVOS) { + // 用户档案主键 + String cuserid = smUser.getCuserid(); + // 用户名称 + String user_name = smUser.getUser_name(); + // 用户编码 + String user_code = smUser.getUser_code(); + + UserNameObject userNameObject = new UserNameObject(user_name);// 用户名称 + userNameObject.setUserCode(user_code);// 用户编码 + userNameObject.setUserPK(cuserid);// 用户档案主键 + userList.add(userNameObject); + } + UserNameObject[] users = userList.toArray(new UserNameObject[0]); + + CommonMessageVO commonMessageVO = new CommonMessageVO(); + commonMessageVO.setReceiver(users); + commonMessageVO.setTitle(title); + commonMessageVO.setSender(DEFAULT_SENDER); + commonMessageVO.setSendDataTime(new UFDateTime()); + commonMessageVO.setPriority(1); + commonMessageVO.setMessageContent(content); + + PfMessageUtil.sendNoticeMessage(commonMessageVO); + + return ResultMessageUtil.toJSON(true, "消息发送成功"); + } catch (Exception e) { + Logger.error("MsgResource-exp:", e); + return ResultMessageUtil.exceptionToJSON(new BusinessException(e.getMessage(), e)); + } + } + /** * 查询用户 */