diff --git a/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java index 6c831016..0745fc68 100644 --- a/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java +++ b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java @@ -1,10 +1,12 @@ package nccloud.api.uapbd.msg; import com.alibaba.fastjson.JSONObject; +import nc.bs.dao.BaseDAO; import nc.bs.dao.DAOException; 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.vo.fi.pub.SqlUtils; import nc.vo.org.FactoryVO; import nc.vo.pub.BusinessException; @@ -15,7 +17,6 @@ import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.vo.sm.UserVO; import nc.vo.uap.rbac.role.RoleVO; import nccloud.api.rest.utils.ResultMessageUtil; -import nccloud.baseapp.core.log.NCCForUAPLogger; import nccloud.bs.pub.pf.PfMessageUtil; import nccloud.commons.lang.StringUtils; import nccloud.ws.rest.resource.AbstractNCCRestResource; @@ -60,6 +61,14 @@ 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); + if (pkOrg != null) { + return ResultMessageUtil.toJSON(false, "未查询到组织:" + orgCode); + } + String 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); @@ -69,7 +78,7 @@ public class MsgResource extends AbstractNCCRestResource { ArrayList userList = new ArrayList<>(); // 根据传递的角色查询要发送消息的用户信息 - String roleId = getMsgRole(orgCode); + String roleId = getMsgRole(pkOrg, materialCode); UserVO[] userVOS = getUserByRole(roleId); if (userVOS == null || userVOS.length == 0) { return ResultMessageUtil.toJSON(false, "未查询到用户"); @@ -129,7 +138,7 @@ public class MsgResource extends AbstractNCCRestResource { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = sdf.format(new Date()); strWhere = strWhere.replace("[now]", time); - NCCForUAPLogger.debug("getUserByRole-strWhere = " + strWhere); + // NCCForUAPLogger.debug("getUserByRole-strWhere = " + strWhere); try { vos = (UserVO[]) getSuperDMO().queryByWhereClause(UserVO.class, strWhere); } catch (DAOException e) { @@ -142,9 +151,13 @@ public class MsgResource extends AbstractNCCRestResource { /** * 查询要发消息的角色id */ - private String getMsgRole(String orgCode) throws BusinessException { + private String getMsgRole(String pkOrg, String materialCode) throws BusinessException { String pkRole = ""; - String pkOrg = MyHelper.transferField(FactoryVO.getDefaultTableName(), FactoryVO.PK_FACTORY, FactoryVO.CODE, orgCode); + // 先查询物料分类上配置的角色,如果有则返回,否则查询自定义档案中配置的角色 + 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", ""); @@ -154,12 +167,11 @@ public class MsgResource extends AbstractNCCRestResource { if (msgRoleCode.contains(",")) { String inSql = SqlUtils.getInStr("role_code", msgRoleCode.split(",", -1), Boolean.TRUE); strWhere += " AND " + inSql; - NCCForUAPLogger.debug("多角色-strWhere = " + strWhere); + // NCCForUAPLogger.debug("多角色-strWhere = " + strWhere); } else { strWhere += " AND role_code = '" + msgRoleCode + "'"; } - if (StringUtils.isNotEmpty(orgCode) && !"~".equals(orgCode) && - StringUtils.isNotEmpty(pkOrg) && !"~".equals(pkOrg)) { + if (StringUtils.isNotEmpty(pkOrg) && !"~".equals(pkOrg)) { strWhere += " AND pk_org = '" + pkOrg + "'"; } Set pkRoleSet = new HashSet<>(); @@ -181,4 +193,20 @@ public class MsgResource extends AbstractNCCRestResource { return pkRole; } + private String getGoodsTypeRole(String pkOrg, String materialCode) throws BusinessException { + String pkRole = ""; + String sql = "SELECT marclass.def1" + + " FROM bd_marbasclass marclass" + + " LEFT JOIN bd_material mar ON marclass.pk_marbasclass = mar.pk_marbasclass" + + " LEFT JOIN bd_materialstock marstock ON mar.pk_material = marstock.pk_material" + + " WHERE " + + " marclass.DR = 0" + + " AND marstock.pk_org = '[pkOrg]'" + + " AND mar.CODE = '[materialCode]'"; + sql = sql.replace("[pkOrg]", pkOrg); + sql = sql.replace("[materialCode]", materialCode); + pkRole = (String) new BaseDAO().executeQuery(sql, new ColumnProcessor()); + return pkRole; + } + }