From b6e69902faa7ab9c54b5ee185ba279d527d26c81 Mon Sep 17 00:00:00 2001 From: mzr Date: Fri, 1 Aug 2025 09:20:17 +0800 Subject: [PATCH] =?UTF-8?q?BOM=E6=B6=88=E6=81=AF=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nccloud/api/uapbd/msg/MsgResource.java | 67 +++++++++++++++++-- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java index 00539e1..cb1820d 100644 --- a/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java +++ b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java @@ -4,13 +4,18 @@ import com.alibaba.fastjson.JSONObject; import nc.bs.dao.DAOException; import nc.bs.logging.Logger; import nc.bs.trade.business.HYSuperDMO; +import nc.bs.uapbd.util.MyHelper; +import nc.vo.fi.pub.SqlUtils; +import nc.vo.org.FactoryVO; import nc.vo.pub.BusinessException; import nc.vo.pub.lang.UFDateTime; import nc.vo.pub.msg.CommonMessageVO; import nc.vo.pub.msg.UserNameObject; 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; @@ -21,8 +26,7 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; +import java.util.*; /** * 消息发送api @@ -54,7 +58,7 @@ public class MsgResource extends AbstractNCCRestResource { @Produces({"application/json"}) public JSONString save(JSONObject jsonObject) { String content = (String) jsonObject.get("content"); - String roleId = (String) jsonObject.get("roleId"); + String orgCode = (String) jsonObject.get("orgCode"); try { // 通知消息字段,最大为4000位。 if (content != null && content.length() > 1500) { @@ -65,6 +69,7 @@ public class MsgResource extends AbstractNCCRestResource { ArrayList userList = new ArrayList<>(); // 根据传递的角色查询要发送消息的用户信息 + String roleId = getMsgRole(orgCode); UserVO[] userVOS = getUserByRole(roleId); if (userVOS == null || userVOS.length == 0) { return ResultMessageUtil.toJSON(false, "未查询到用户"); @@ -105,19 +110,26 @@ public class MsgResource extends AbstractNCCRestResource { /** * 查询用户 */ - private UserVO[] getUserByRole(String roleId) { + private UserVO[] getUserByRole(String roleId) throws BusinessException { UserVO[] vos = null; if (StringUtils.isEmpty(roleId) || "~".equals(roleId)) { + ExceptionUtils.wrappBusinessException("角色查询失败"); return null; } + String roleSql = ""; + if (roleId.contains(",")) { + roleSql = SqlUtils.getInStr("pk_role", roleId.split(",", -1), Boolean.TRUE); + } else { + roleSql = "pk_role = '" + roleId + "'"; + } String strWhere = " dr = 0 AND cuserid in (" + - "select cuserid from sm_user_role where pk_role = '[roleId]' and (disabledate is null or disabledate >= '[now]') " + + "select cuserid from sm_user_role where [roleSql] and (disabledate is null or disabledate >= '[now]') " + ")"; - strWhere = strWhere.replace("[roleId]", roleId); + strWhere = strWhere.replace("[roleSql]", roleSql); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = sdf.format(new Date()); strWhere = strWhere.replace("[now]", time); - // NCCForUAPLogger.debug("time = " + time); + NCCForUAPLogger.debug("getUserByRole-strWhere = " + strWhere); try { vos = (UserVO[]) getSuperDMO().queryByWhereClause(UserVO.class, strWhere); } catch (DAOException e) { @@ -125,7 +137,48 @@ public class MsgResource extends AbstractNCCRestResource { ExceptionUtils.wrappBusinessException(e.getMessage()); } return vos; + } + /** + * 查询要发消息的角色id + */ + private String getMsgRole(String orgCode) throws BusinessException { + String pkRole = ""; + String pkOrg = MyHelper.transferField(FactoryVO.getDefaultTableName(), FactoryVO.PK_FACTORY, FactoryVO.CODE, orgCode); + Map configParams = MyHelper.getConfigParams("Dldz-config", null); + String strWhere = " dr = 0 "; + String msgRoleCode = configParams.getOrDefault("msgRoleCode", ""); + if (StringUtils.isEmpty(msgRoleCode)) { + ExceptionUtils.wrappBusinessException("未配置消息角色编码"); + } + if (msgRoleCode.contains(",")) { + String inSql = SqlUtils.getInStr("role_code", msgRoleCode.split(",", -1), Boolean.TRUE); + strWhere += " AND " + inSql; + NCCForUAPLogger.debug("多角色-strWhere = " + strWhere); + } else { + strWhere += " AND role_code = '" + msgRoleCode + "'"; + } + if (StringUtils.isNotEmpty(orgCode) && !"~".equals(orgCode) && + StringUtils.isNotEmpty(pkOrg) && !"~".equals(pkOrg)) { + strWhere += " AND pk_org = '" + pkOrg + "'"; + } + Set pkRoleSet = new HashSet<>(); + try { + RoleVO[] vos = (RoleVO[]) getSuperDMO().queryByWhereClause(RoleVO.class, strWhere); + if (vos != null && vos.length > 0) { + for (RoleVO roleVO : vos) { + pkRoleSet.add(roleVO.getPk_role()); + } + pkRole = vos[0].getPk_role(); + } + } catch (DAOException e) { + Logger.error("MsgResource-getMsgRole-exp:" + e.getMessage()); + ExceptionUtils.wrappBusinessException(e.getMessage()); + } + if (!pkRoleSet.isEmpty()) { + pkRole = String.join(",", pkRoleSet); + } + return pkRole; } }