diff --git a/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java index df396aa3..78071f50 100644 --- a/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java +++ b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java @@ -65,20 +65,84 @@ public class MsgResource extends AbstractNCCRestResource { if (pkOrg == null || pkOrg.isEmpty()) { return ResultMessageUtil.toJSON(false, "未查询到组织:" + orgCode); } - String materialCode = (String) jsonObject.get("materialCode"); - if (materialCode == null || materialCode.isEmpty()) { - return ResultMessageUtil.toJSON(false, "传参中缺少物料编码"); + String materialCode = ""; + if (jsonObject.containsKey("materialCode")) { + materialCode = (String) jsonObject.get("materialCode"); + if (materialCode == null || materialCode.isEmpty()) { + return ResultMessageUtil.toJSON(false, "传参中缺少物料编码"); + } } + // 通知消息字段,最大为4000位。 if (content != null && content.length() > 1500) { content = content.substring(0, 1500); } - + Map configParams = MyHelper.getConfigParams("Dldz-config", null); // 定义接收消息人员信息集合 ArrayList userList = new ArrayList<>(); // 根据传递的角色查询要发送消息的用户信息 - String roleId = getMsgRole(pkOrg, materialCode); + String roleId = getMsgRole(pkOrg, materialCode, 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("BOM变更信息通知"); + 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)); + } + } + + @POST + @Path("operation/saveXb") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString saveXb(JSONObject jsonObject) { + 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); + if (pkOrg == null || pkOrg.isEmpty()) { + return ResultMessageUtil.toJSON(false, "未查询到组织:" + orgCode); + } + + // 通知消息字段,最大为4000位。 + if (content != null && content.length() > 1500) { + content = content.substring(0, 1500); + } + Map configParams = MyHelper.getConfigParams("xb-config", null); + // 定义接收消息人员信息集合 + ArrayList userList = new ArrayList<>(); + + // 根据传递的角色查询要发送消息的用户信息 + String roleId = getMsgRole(pkOrg, "", configParams); UserVO[] userVOS = getUserByRole(roleId); if (userVOS == null || userVOS.length == 0) { return ResultMessageUtil.toJSON(false, "未查询到用户"); @@ -151,14 +215,15 @@ public class MsgResource extends AbstractNCCRestResource { /** * 查询要发消息的角色id */ - private String getMsgRole(String pkOrg, String materialCode) throws BusinessException { + private String getMsgRole(String pkOrg, String materialCode, Map configParams) throws BusinessException { String pkRole = ""; // 先查询物料分类上配置的角色,如果有则返回,否则查询自定义档案中配置的角色 - pkRole = getGoodsTypeRole(pkOrg, materialCode); - if (pkRole != null && !"~".equals(pkRole) && !pkRole.isEmpty()) { - return pkRole; + if (StringUtils.isNotEmpty(materialCode)) { + pkRole = getGoodsTypeRole(pkOrg, materialCode); + if (pkRole != null && !"~".equals(pkRole) && !pkRole.isEmpty()) { + return pkRole; + } } - Map configParams = MyHelper.getConfigParams("Dldz-config", null); String strWhere = " dr = 0 "; String msgRoleCode = configParams.getOrDefault("msgRoleCode", ""); if (StringUtils.isEmpty(msgRoleCode)) {