BOM消息调整

This commit is contained in:
mzr 2025-08-01 09:20:17 +08:00
parent b10459f27a
commit b6e69902fa
1 changed files with 60 additions and 7 deletions

View File

@ -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<UserNameObject> 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<String, String> 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<String> 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;
}
}