From cfb4c8d2fda383ce14a5842b85a5e635deef4ed1 Mon Sep 17 00:00:00 2001 From: mzr Date: Wed, 11 Jun 2025 19:07:32 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=86=E9=85=8D=E7=BB=84=E7=BB=87=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baseinfo/action/BaseOpenApiReq.java | 268 ++++++++++++++++++ .../baseinfo/action/CustomerSaveAction.java | 32 ++- .../action/CustomerSaveAddAction.java | 25 +- .../baseinfo/action/HttpClientWapper.java | 147 ++++++++++ 4 files changed, 459 insertions(+), 13 deletions(-) create mode 100644 uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/BaseOpenApiReq.java create mode 100644 uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/HttpClientWapper.java diff --git a/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/BaseOpenApiReq.java b/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/BaseOpenApiReq.java new file mode 100644 index 0000000..c04e972 --- /dev/null +++ b/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/BaseOpenApiReq.java @@ -0,0 +1,268 @@ +package nccloud.web.uapbd.customer.baseinfo.action; + + +import com.alibaba.fastjson.JSONObject; +import com.sm.misc.BASE64Decoder; +import com.sm.misc.BASE64Encoder; +import nc.bs.dao.DAOException; +import nc.bs.logging.Logger; +import nc.bs.trade.business.HYSuperDMO; +import nc.vo.opm.thirdapp.ThirdappVO; +import nc.ws.opm.pub.utils.security.SecurityUtil; +import org.apache.commons.httpclient.Header; + +import javax.crypto.Cipher; +import java.io.ByteArrayOutputStream; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.security.*; +import java.security.spec.X509EncodedKeySpec; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @description: openapi请求 + * @author: mzr + * @date: 20250611 + */ +public class BaseOpenApiReq { + public String BASE_URL_DEV = "http://127.0.0.1:9080"; + /** + * APP ID + */ + public String CLIENT_ID = "BIP2312"; + /** + * APP Secret + */ + public String CLIENT_SECRET = ""; + /** + * 公钥 + */ + public String PUBLIC_KEY = ""; + /** + * 账套编码 + */ + public String BIZ_CENTER = "01"; + /** + * 用户编码 + */ + public String USER_CODE = "BIP"; + + public HttpClientWapper client = new HttpClientWapper(); + + /** + * 调用openAPI给客户分配组织 + */ + public void assignOrgApi(String url, JSONObject param) { + ThirdappVO apiInfo = getApiInfo(); + if (apiInfo == null) { + return; + } + CLIENT_ID = apiInfo.getApp_id(); + CLIENT_SECRET = apiInfo.getApp_secret(); + PUBLIC_KEY = apiInfo.getPublic_key(); + USER_CODE = apiInfo.getUser_code(); + try { + String result = requestOpenApi(url, param); + Logger.error("CustomerSaveAction-assignOrg-result = " + result); + } catch (Exception e) { + Logger.error("assignOrgApi-exp:" + e.getMessage()); + throw new RuntimeException(e); + } + } + + /** + * 获取openAPI的应用信息 + */ + private ThirdappVO getApiInfo() { + ThirdappVO result = new ThirdappVO(); + String strWhere = " code = 'BIP2312' and dr=0"; + try { + ThirdappVO[] vos = (ThirdappVO[]) new HYSuperDMO().queryByWhereClause(ThirdappVO.class, strWhere); + if (vos != null) { + result = vos[0]; + } + } catch (DAOException e) { + e.printStackTrace(); + } + return result; + } + + /** + * @param url + * @param param + * @return + * @throws Exception + */ + public String requestOpenApi(String url, Map param) throws Exception { + return requestOpenApi(url, new JSONObject(param)); + } + + /** + * @param url + * @param param + * @return + * @throws Exception + */ + public String requestOpenApi(String url, JSONObject param) throws Exception { + return requestOpenApi(url, param.toJSONString()); + } + + public String requestOpenApi(String url, String param) throws Exception { + String accessToken = this.getAccessTokenByClient(); + Logger.info("requestOpenApi-param:" + param.replace(" ", "")); + String sign = digest(CLIENT_ID + PUBLIC_KEY); + List
headers = new ArrayList<>(); + headers.add(new Header("Content-Type", "application/json;charset=UTF-8")); + headers.add(new Header("signature", sign)); + headers.add(new Header("ucg_flag", "y")); + headers.add(new Header("access_token", accessToken)); + headers.add(new Header("client_id", CLIENT_ID)); + HttpClientWapper.Response response; + try { + response = client.post(BASE_URL_DEV + url, headers.toArray(new Header[headers.size()]), null, param); + return response.getData(); + } catch (Exception e) { + Logger.error("requestOpenApi-exp:" + e.getMessage()); + return e.getMessage(); + } + } + + /** + * @param seed 种子,用于生成公钥 + * @param src 明文 + * @return + * @throws Exception + * @description RSA加密 + */ + public String pubEncrypt(String seed, String src) throws Exception { + String target = null; + ByteArrayOutputStream out = null; + try { + Key key = genPublicKey(PUBLIC_KEY); + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(1, key); + byte[] data = src.getBytes(); + int inputLen = data.length; + out = new ByteArrayOutputStream(); + int offSet = 0; + int i = 0; + while (inputLen - offSet > 0) { + byte[] cache; + ; + if (inputLen - offSet > 117) { + cache = cipher.doFinal(data, offSet, 117); + } else { + cache = cipher.doFinal(data, offSet, inputLen - offSet); + } + out.write(cache, 0, cache.length); + i++; + offSet = i * 117; + } + target = new BASE64Encoder().encodeBuffer(out.toByteArray()); + } catch (Exception e) { + throw new Exception("加密失败" + e.getMessage()); + } finally { + if (out != null) { + out.close(); + } + } + return target; + } + + /** + * @param str + * @return + * @description 信息摘要 + */ + public static String digest(String str) { + String encodestr = ""; + try { + MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); + messageDigest.update(str.getBytes(StandardCharsets.UTF_8)); + encodestr = byte2Hex(messageDigest.digest()); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + return encodestr; + } + + private static String byte2Hex(byte[] bytes) { + StringBuffer stringBuffer = new StringBuffer(); + String temp = null; + for (int i = 0; i < bytes.length; i++) { + temp = Integer.toHexString(bytes[i] & 0xFF); + if (temp.length() == 1) { + stringBuffer.append("0"); + } + stringBuffer.append(temp); + } + return stringBuffer.toString(); + } + + /** + * @return + * @throws Exception + * @description 根据种子生成密钥对 + */ + public static Key genPublicKey(String seed) throws Exception { + Key key = null; + try { + byte[] keyBytes = new BASE64Decoder().decodeBuffer(seed); + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); + key = keyFactory.generatePublic(x509KeySpec); + } catch (Exception e) { + throw new Exception("无效的密钥 " + e.getMessage()); + } + return key; + } + + + public static String getSHA256(String str, String key) throws Exception { + byte[] salt = new byte[16]; + SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); + random.setSeed(key.getBytes()); + random.nextBytes(salt); + String salt_value = new BASE64Encoder().encodeBuffer(salt); + return digest(str + salt_value.replaceAll("\r|\n", "")); + } + + /** + * @return + * @throws Exception + * @description 获取AccessToken + */ + @SuppressWarnings("static-access") + public String getAccessTokenByClient() throws Exception { + String url = BASE_URL_DEV + "/nccloud/opm/accesstoken"; + List
headers = new ArrayList
(); + headers.add(new Header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")); + // 获取信息摘要 + String signature = getSHA256(CLIENT_ID + CLIENT_SECRET + PUBLIC_KEY, PUBLIC_KEY); + // 使用PUBLIC_KEY生成公钥,对CLIENT_SECRET加密 + SecurityUtil securityUtil = new SecurityUtil(); + String CLIENT_SECRETEn = URLEncoder.encode(securityUtil.pubEncrypt(PUBLIC_KEY, CLIENT_SECRET), StandardCharsets.UTF_8); + Map params = new HashMap(); + params.put("client_id", CLIENT_ID); + params.put("userCode", USER_CODE); + params.put("grant_type", "client_credentials"); + params.put("biz_center", BIZ_CENTER); + params.put("signature", signature); + params.put("client_secret", CLIENT_SECRETEn); + try { + HttpClientWapper.Response response = client.post(url, headers.toArray(new Header[headers.size()]), null, client.getURLParam(params)); + JSONObject result = JSONObject.parseObject(response.getData()); + boolean success = result.getBoolean("success"); + if (success) { + return result.getJSONObject("data").getString("access_token"); + } + } catch (Exception e) { + Logger.error("getAccessTokenByClient-exp:" + e.getMessage()); + } + return null; + } +} + diff --git a/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/CustomerSaveAction.java b/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/CustomerSaveAction.java index 9bb9095..e54b31e 100644 --- a/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/CustomerSaveAction.java +++ b/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/CustomerSaveAction.java @@ -5,9 +5,9 @@ package nccloud.web.uapbd.customer.baseinfo.action; +import com.alibaba.fastjson.JSONObject; import nc.bs.dao.BaseDAO; import nc.bs.framework.common.InvocationInfoProxy; -import nc.bs.logging.Logger; import nc.bs.uif2.LockFailedException; import nc.bs.uif2.VersionConflictException; import nc.itf.bd.cust.assign.ICustAssignService; @@ -17,14 +17,12 @@ import nc.itf.uap.IUAPQueryBS; import nc.jdbc.framework.processor.MapProcessor; import nc.uap.utils.ResHelper; import nc.vo.bd.cust.*; -import nc.vo.bd.errorlog.ErrLogReturnValue; import nc.vo.bd.supplier.SupplierVO; import nc.vo.ml.NCLangRes4VoTransl; import nc.vo.org.OrgVO; import nc.vo.pub.BusinessException; import nc.vo.pub.SuperVO; import nc.vo.pub.lang.UFDateTime; -import nccloud.baseapp.core.log.NCCForUAPLogger; import nccloud.commons.lang.StringUtils; import nccloud.framework.core.exception.ExceptionUtils; import nccloud.framework.service.ServiceLocator; @@ -163,15 +161,12 @@ public class CustomerSaveAction implements ICommonAction { } } // 自动分配组织 - String[] customerPks = {customerVO.getPk_customer()}; + /*String[] customerPks = {customerVO.getPk_customer()}; OrgVO[] virtulaOrg = getVirtulaOrg(); String[] assignOrgPks = Arrays.stream(virtulaOrg).map(OrgVO::getPk_org).toArray(String[]::new); - // assignOrgPks = new String[]{"0001A1100000000026HI", "0001A110000000002H9M"}; ErrLogReturnValue errLogReturnValue = cs.getAssignService().assignCustomerByPks(customerPks, assignOrgPks, null); - Logger.error("CustomerSaveAction-errLogReturnValue = " + errLogReturnValue.getErrLogResult()); - // NCCForUAPLogger.debug("customerPks = " + customerPks[0]); - // NCCForUAPLogger.debug("assignOrgPks = " + Arrays.toString(assignOrgPks)); - // NCCForUAPLogger.debug("CustomerSaveAction-errLogReturnValue = " + errLogReturnValue.getErrLogResult()); + Logger.error("CustomerSaveAction-errLogReturnValue = " + errLogReturnValue.getErrLogResult());*/ + assignOrgApi(customerVO); } catch (Exception e) { if (e instanceof UndeclaredThrowableException) { Throwable undeclaredThrowable = ((UndeclaredThrowableException) e).getUndeclaredThrowable(); @@ -200,6 +195,23 @@ public class CustomerSaveAction implements ICommonAction { return ebc; } + public void assignOrgApi(CustomerVO customerVO) throws BusinessException { + String[] customerPks = {customerVO.getCode()}; + OrgVO[] virtulaOrg = getVirtulaOrg(); + String[] assignOrgPks = Arrays.stream(virtulaOrg).map(OrgVO::getCode).toArray(String[]::new); + JSONObject param = new JSONObject(); + JSONObject ufinterfaceJson = new JSONObject(); + JSONObject dataJson = new JSONObject(); + dataJson.put("customer", customerPks); + dataJson.put("org", assignOrgPks); + + ufinterfaceJson.put("sender", "default"); + ufinterfaceJson.put("data", dataJson); + param.put("ufinterface", ufinterfaceJson); + BaseOpenApiReq req = new BaseOpenApiReq(); + req.assignOrgApi("/nccloud/api/uapbd/customermanageext/customer/assign", param); + } + /** * 查询组织信息 * @@ -214,4 +226,6 @@ public class CustomerSaveAction implements ICommonAction { Collection collection = (new BaseDAO()).retrieveByClause(OrgVO.class, condition, "code"); return collection.toArray(new OrgVO[0]); } + + } diff --git a/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/CustomerSaveAddAction.java b/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/CustomerSaveAddAction.java index 2265ed2..8e5b1b2 100644 --- a/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/CustomerSaveAddAction.java +++ b/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/CustomerSaveAddAction.java @@ -5,6 +5,7 @@ package nccloud.web.uapbd.customer.baseinfo.action; +import com.alibaba.fastjson.JSONObject; import nc.bs.dao.BaseDAO; import nc.bs.framework.common.InvocationInfoProxy; import nc.bs.logging.Logger; @@ -109,13 +110,12 @@ public class CustomerSaveAddAction implements ICommonAction { ebc.setUserjson(billCodeContext == null ? "" : "" + billCodeContext.isEditable()); // 自动分配组织 - String[] customerPks = {customerVO.getPk_customer()}; + /*String[] customerPks = {customerVO.getPk_customer()}; OrgVO[] virtulaOrg = getVirtulaOrg(); String[] assignOrgPks = Arrays.stream(virtulaOrg).map(OrgVO::getPk_org).toArray(String[]::new); - // assignOrgPks = new String[]{"0001A1100000000026HI", "0001A110000000002H9M"}; ErrLogReturnValue errLogReturnValue = cs.getAssignService().assignCustomerByPks(customerPks, assignOrgPks, null); - Logger.error("CustomerSaveAddAction-errLogReturnValue = " + errLogReturnValue.getErrLogResult()); - + Logger.error("CustomerSaveAddAction-errLogReturnValue = " + errLogReturnValue.getErrLogResult());*/ + assignOrgApi(customerVO); } catch (BusinessException e) { ExceptionUtils.wrapException(e); } @@ -123,6 +123,23 @@ public class CustomerSaveAddAction implements ICommonAction { return ebc; } + public void assignOrgApi(CustomerVO customerVO) throws BusinessException { + String[] customerPks = {customerVO.getCode()}; + OrgVO[] virtulaOrg = getVirtulaOrg(); + String[] assignOrgPks = Arrays.stream(virtulaOrg).map(OrgVO::getCode).toArray(String[]::new); + JSONObject param = new JSONObject(); + JSONObject ufinterfaceJson = new JSONObject(); + JSONObject dataJson = new JSONObject(); + dataJson.put("customer", customerPks); + dataJson.put("org", assignOrgPks); + + ufinterfaceJson.put("sender", "default"); + ufinterfaceJson.put("data", dataJson); + param.put("ufinterface", ufinterfaceJson); + BaseOpenApiReq req = new BaseOpenApiReq(); + req.assignOrgApi("/nccloud/api/uapbd/customermanageext/customer/assign", param); + } + /** * 查询组织信息 * diff --git a/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/HttpClientWapper.java b/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/HttpClientWapper.java new file mode 100644 index 0000000..df61ca7 --- /dev/null +++ b/uapbd/src/client/nccloud/web/uapbd/customer/baseinfo/action/HttpClientWapper.java @@ -0,0 +1,147 @@ +package nccloud.web.uapbd.customer.baseinfo.action; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.commons.httpclient.util.EncodingUtil; +import org.apache.commons.lang3.StringUtils; + +import java.io.IOException; +import java.util.Map; + +/** + * Http请求包装类 + * + * @author guoxiangqiao + * @date 2019年12月11日 + */ +public class HttpClientWapper { + public static final int HTTP_STATUS_SUCCESS = 200; + + /** + * post请求 + * + * @param url + * @param headers + * @param requestBody + * @return + * @throws Exception + */ + public Response post(String url, Header[] headers, NameValuePair[] requestBody, String requestEntityStr) throws Exception { + HttpClient client = new HttpClient(); + PostMethod postMethod = new PostMethod(url); + if (headers != null) { + for (Header header : headers) { + postMethod.setRequestHeader(header); + } + } + if (requestBody != null) { + postMethod.setRequestBody(requestBody); + } + if (StringUtils.isNotEmpty(requestEntityStr)) { + StringRequestEntity requestEntity = new StringRequestEntity(requestEntityStr, null, "utf-8"); + postMethod.setRequestEntity(requestEntity); + } + int httpStatus = client.executeMethod(postMethod); + String result = this.getResponseBodyAsString(postMethod); + return new Response(httpStatus, result); + } + + public String getResponseBodyAsString(PostMethod postMethod) throws IOException { + byte[] rawdata = null; + rawdata = postMethod.getResponseBody(); + return rawdata != null ? EncodingUtil.getString(rawdata, "utf-8") : null; + } + + /** + * @param params + * @return + * @description Map转URL参数 + * @author guoxqc@yonyou.com + * @date 2020年10月22日 + */ + public String getURLParam(Map params) { + StringBuffer paramStr = new StringBuffer(); + if (!params.isEmpty()) { + for (Map.Entry kv : params.entrySet()) { + paramStr.append(kv.getKey()); + paramStr.append("="); + paramStr.append(kv.getValue()); + paramStr.append("&"); + } + paramStr.deleteCharAt(paramStr.length() - 1); + } + return paramStr.toString(); + } + + /** + * get请求 + * + * @param url + * @param headers + * @param params + * @return + * @throws Exception + */ + public Response get(String url, Header[] headers, NameValuePair[] params) throws Exception { + HttpClient client = new HttpClient(); + GetMethod getMethod = new GetMethod(url); + if (params != null) { + getMethod.setQueryString(params); + } + if (headers != null) { + for (Header header : headers) { + getMethod.setRequestHeader(header); + } + } + int httpStatus = client.executeMethod(getMethod); + String result = getMethod.getResponseBodyAsString(); + return new Response(httpStatus, result); + } + + /** + * 获取url查询参数 + * + * @param params + * @return + */ + public String getQueryString(NameValuePair[] params) { + GetMethod getMethod = new GetMethod(); + getMethod.setQueryString(params); + return getMethod.getQueryString(); + } + + class Response { + private int httpStatus; + private String data; + + public int getHttpStatus() { + return httpStatus; + } + + public void setHttpStatus(int httpStatus) { + this.httpStatus = httpStatus; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public Response(int httpStatus, String data) { + super(); + this.httpStatus = httpStatus; + this.data = data; + } + + public Response() { + super(); + } + } +} From 67aefbe2e3ddb7de3b8f66043a3a38d40bd021e7 Mon Sep 17 00:00:00 2001 From: mzr Date: Thu, 12 Jun 2025 16:26:28 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(uapbd):=20=E6=B7=BB=E5=8A=A0=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=8F=91=E9=80=81=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nccloud/api/uapbd/msg/MsgResource.java | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java diff --git a/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java new file mode 100644 index 0000000..21c1c93 --- /dev/null +++ b/uapbd/src/public/nccloud/api/uapbd/msg/MsgResource.java @@ -0,0 +1,129 @@ +package nccloud.api.uapbd.msg; + +import com.alibaba.fastjson.JSONObject; +import nc.bs.dao.DAOException; +import nc.bs.logging.Logger; +import nc.bs.pub.pf.PfMessageUtil; +import nc.bs.trade.business.HYSuperDMO; +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.sm.UserVO; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.baseapp.core.log.NCCForUAPLogger; +import nccloud.commons.lang.StringUtils; +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.json.JSONString; + +import javax.ws.rs.Consumes; +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; + +/** + * 消息发送api + * + * @author mzr + * @date 2025/06/12 + */ +@Path("uapbd/msg") +public class MsgResource extends AbstractNCCRestResource { + + public String getModule() { + return "uapbd"; + } + + private HYSuperDMO superDMO = null; + + + public HYSuperDMO getSuperDMO() { + if (superDMO == null) { + superDMO = new HYSuperDMO(); + } + return superDMO; + } + + @POST + @Path("operation/save") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString save(JSONObject jsonObject) { + String content = (String) jsonObject.get("content"); + String roleId = (String) jsonObject.get("roleId"); + try { + // 通知消息字段,最大为4000位。 + if (content.length() > 1500) { + content = content.substring(0, 1500); + } + + // 定义接收消息人员信息集合 + ArrayList userList = new ArrayList<>(); + + // 根据传递的角色查询要发送消息的用户信息 + UserVO[] userVOS = getUserByRole(roleId); + if (userVOS == null) { + 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("NC_USER0000000000000"); + commonMessageVO.setSendDataTime(new UFDateTime()); + commonMessageVO.setPriority(1); + commonMessageVO.setMessageContent(content); + + PfMessageUtil.sendNoticeMessage(commonMessageVO); + + return ResultMessageUtil.toJSON(true, "消息发送成功"); + } catch (BusinessException e) { + Logger.error("MsgResource-exp:" + e.getMessage()); + return ResultMessageUtil.exceptionToJSON(new BusinessException(e.getMessage(), e)); + } + } + + /** + * 查询用户 + */ + private UserVO[] getUserByRole(String roleId) { + UserVO[] vos = null; + if (StringUtils.isEmpty(roleId) || "~".equals(roleId)) { + return null; + } + String strWhere = " dr = 0 AND cuserid in (" + + "select cuserid from sm_user_role where pk_role = [roleId] and (disabledate is null or disabledate >= [now]) " + + ")"; + strWhere = strWhere.replace("[roleId]", roleId); + 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); + try { + vos = (UserVO[]) getSuperDMO().queryByWhereClause(UserVO.class, strWhere); + } catch (DAOException e) { + Logger.error("MsgResource-getUserByRole-exp:" + e.getMessage()); + } + return vos; + + } + +} From de285fb90e8491e9e44c2ee2239966109dbf5774 Mon Sep 17 00:00:00 2001 From: lihao Date: Thu, 12 Jun 2025 16:57:56 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=89=A9=E6=96=99=E6=A1=A3=E6=A1=88?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E9=A1=B5=E7=AD=BE=E5=90=AF=E7=94=A8=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=BE=85=E5=8A=A9=E5=B1=9E=E6=80=A7+=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E7=BB=84=E7=BB=87=E5=90=AF=E7=94=A8=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=88=E5=8C=85=E5=90=AB=E4=B8=BB=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=EF=BC=89=EF=BC=8C=E8=AE=A1=E5=88=92=E3=80=81=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E3=80=81=E8=B4=A2=E5=8A=A1=E6=88=90=E6=9C=AC=E9=A1=B5?= =?UTF-8?q?=E7=AD=BE=E5=AF=B9=E5=BA=94=E4=B8=9A=E5=8A=A1=E5=8D=95=E5=85=83?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=90=AF=E7=94=A8=E9=A1=B9=E7=9B=AE=E8=BE=85?= =?UTF-8?q?=E5=8A=A9=E5=B1=9E=E6=80=A7=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MaterialStockAsstsChangedListener.java | 205 ++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 uapbd/src/private/nc/impl/bd/material/baseinfo/MaterialStockAsstsChangedListener.java diff --git a/uapbd/src/private/nc/impl/bd/material/baseinfo/MaterialStockAsstsChangedListener.java b/uapbd/src/private/nc/impl/bd/material/baseinfo/MaterialStockAsstsChangedListener.java new file mode 100644 index 0000000..71ee6ac --- /dev/null +++ b/uapbd/src/private/nc/impl/bd/material/baseinfo/MaterialStockAsstsChangedListener.java @@ -0,0 +1,205 @@ +package nc.impl.bd.material.baseinfo; + +import nc.bs.businessevent.IBusinessEvent; +import nc.bs.businessevent.IBusinessListener; +import nc.bs.businessevent.bd.BDCommonEvent; +import nc.bs.dao.BaseDAO; +import nc.bs.dao.DAOException; +import nc.jdbc.framework.SQLParameter; +import nc.jdbc.framework.processor.ColumnListProcessor; +import nc.vo.bd.material.MaterialVO; +import nc.vo.bd.material.stock.MaterialStockVO; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFBoolean; +import nc.vo.util.BDPKLockUtil; + +import java.util.ArrayList; +import java.util.List; + +public class MaterialStockAsstsChangedListener implements IBusinessListener { + private BaseDAO baseDAO = new BaseDAO(); + public void doAction(IBusinessEvent iBusinessEvent) throws BusinessException { + if (iBusinessEvent instanceof BDCommonEvent event) { + //1銆佸簱瀛樹俊鎭慨鏀圭敓浜у巶鍟嗗拰椤圭洰鍚 鏇存柊璁″垝淇℃伅锛岀敓浜т俊鎭拰鎴愭湰淇℃伅 + this.dealMaterialStockAssts1(event, false); + } + } + private void dealMaterialStockAssts1(BDCommonEvent event, boolean isBatchUp) throws BusinessException { + for(int i = 0; i < event.getNewObjs().length; ++i) { + MaterialStockVO newVO = (MaterialStockVO)event.getNewObjs()[i]; + String pk_material = newVO.getPk_material(); + String pk_marasstframe = this.getmarasstframe(pk_material).get(0); + if (!isBatchUp) { + BDPKLockUtil.lockString(new String[]{pk_material}); + } + if(pk_marasstframe == null){ + return; + } + //濡傛灉搴撳瓨淇℃伅鐢熶骇鍘傚晢鍜岄」鐩閫変腑鍒 鏇存柊璁″垝淇℃伅锛岀敓浜т俊鎭拰鎴愭湰淇℃伅 + UFBoolean fixasst2 = newVO.getFixasst2(); + UFBoolean fixasst4 = newVO.getFixasst4(); + + List fixlist=new ArrayList(); + + + + if(fixasst2.booleanValue()){ + fixlist.add("2"); + } + if(fixasst4.booleanValue()){ + fixlist.add("4"); + } + if(fixlist.isEmpty()){ + return; + }else{ + //鎴愭湰 + this.updateMaterialCostUpdateAssts(fixlist,newVO.getPk_org(), pk_material); + //鐢熶骇淇℃伅 + this.updateMaterialProdAssts(fixlist,newVO.getPk_org(), pk_material); + //鏇存柊璁″垝淇℃伅 + this.updateMaterialPlanAssts(fixlist,newVO.getPk_org(), pk_material); + } + + } + + } + + + + private List getmarasstframe(String materialVID) throws BusinessException { + String sql = "select pk_marasstframe from " + MaterialVO.getDefaultTableName() + " where pk_material = ? "; + SQLParameter param = new SQLParameter(); + param.addParam(materialVID); + return (List)this.getBaseDAO().executeQuery(sql, param, new ColumnListProcessor()); + } + + private BaseDAO getBaseDAO() { + if (this.baseDAO == null) { + this.baseDAO = new BaseDAO(); + } + + return this.baseDAO; + } + private void updateMaterialCostUpdateAssts(List fixlist,String pk_org, String pk_material) throws BusinessException { + //鏌ヨ鎴愭湰淇℃伅 + String sql = "SELECT " + + " pk_materialcost " + + "FROM " + + " bd_materialcost " + + "WHERE " + + " pk_org = (SELECT PK_COSTREGION FROM org_cr_stockorg WHERE pk_stockorg= ?) " + + " AND " + + " pk_material = ? "; + SQLParameter param = new SQLParameter(); + param.addParam(pk_org); + param.addParam(pk_material); + List list =( (List) this.getBaseDAO().executeQuery(sql, param, new ColumnListProcessor())); + String pk_materialcost = list.get(0).toString(); + if(pk_materialcost == null){ + return; + } + //鏇存柊璁′环鏂瑰紡 + String update2 = "update bd_materialcostmod set marasst2 = ? where pk_materialcost = ? "; + String update4 = "update bd_materialcostmod set marasst4 = ? where pk_materialcost = ? "; + String update24 = "update bd_materialcostmod set marasst2 = ?,marasst4 = ? where pk_materialcost = ? "; + if(fixlist.contains("2") && fixlist.contains("4")){ + SQLParameter param1 = new SQLParameter(); + param1.addParam("Y"); + param1.addParam("Y"); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update24, param1); + }else if(fixlist.contains("2")){ + SQLParameter param1 = new SQLParameter(); + param1.addParam("Y"); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update2, param1); + }else if(fixlist.contains("4")){ + SQLParameter param1 = new SQLParameter(); + param1.addParam("Y"); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update4, param1); + } + + } + + private void updateMaterialProdAssts(List fixlist,String pk_org, String pk_material) throws DAOException { + //鏌ヨ鎴愭湰淇℃伅 + String sql = "SELECT " + + " pk_materialprod " + + "FROM " + + " bd_materialprod " + + "WHERE " + + " pk_org = ? and " + + " pk_material = ? "; + SQLParameter param = new SQLParameter(); + param.addParam(pk_org); + param.addParam(pk_material); + List list =( (List) this.getBaseDAO().executeQuery(sql, param, new ColumnListProcessor())); + String pk_materialcost = list.get(0).toString(); + if(pk_materialcost == null){ + return; + } + //鏇存柊璁′环鏂瑰紡 + String update2 = "update bd_materialprod set costvalutasst2 = ? where pk_materialprod = ? "; + String update4 = "update bd_materialprod set costvalutasst4 = ? where pk_materialprod = ? "; + String update24 = "update bd_materialprod set costvalutasst2 = ?,costvalutasst4 = ? where pk_materialprod = ? "; + if(fixlist.contains("2") && fixlist.contains("4")){ + SQLParameter param1 = new SQLParameter(); + param1.addParam("Y"); + param1.addParam("Y"); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update24, param1); + }else if(fixlist.contains("2")){ + SQLParameter param1 = new SQLParameter(); + param1.addParam("Y"); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update2, param1); + }else if(fixlist.contains("4")){ + SQLParameter param1 = new SQLParameter(); + param1.addParam("Y"); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update4, param1); + } + + } + private void updateMaterialPlanAssts(List fixlist,String pk_org, String pk_material) throws DAOException { + //鏌ヨ鎴愭湰淇℃伅 + String sql = "SELECT " + + " pk_materialplan " + + "FROM " + + " bd_materialplan " + + "WHERE " + + " pk_org = ? and " + + " pk_material = ? "; + SQLParameter param = new SQLParameter(); + param.addParam(pk_org); + param.addParam(pk_material); + List list =( (List) this.getBaseDAO().executeQuery(sql, param, new ColumnListProcessor())); + String pk_materialcost = list.get(0).toString(); + if(pk_materialcost == null){ + return; + } + //鏇存柊璁′环鏂瑰紡 + String update2 = "update bd_materialplan set marasst2 = ? where pk_materialplan = ? "; + String update4 = "update bd_materialplan set marasst4 = ? where pk_materialplan = ? "; + String update24 = "update bd_materialplan set marasst2 = ?,marasst4 = ? where pk_materialplan = ? "; + if(fixlist.contains("2") && fixlist.contains("4")){ + SQLParameter param1 = new SQLParameter(); + param1.addParam("Y"); + param1.addParam("Y"); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update24, param1); + }else if(fixlist.contains("2")){ + SQLParameter param1 = new SQLParameter(); + param1.addParam("Y"); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update2, param1); + }else if(fixlist.contains("4")){ + SQLParameter param1 = new SQLParameter(); + param1.addParam("Y"); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update4, param1); + } + + } +} From 436888f96426ca60d676c4750a5b62db3a306e27 Mon Sep 17 00:00:00 2001 From: lihao Date: Thu, 12 Jun 2025 18:07:11 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=89=A9=E6=96=99=E6=A1=A3=E6=A1=88?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E9=A1=B5=E7=AD=BE=E5=90=AF=E7=94=A8=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=BE=85=E5=8A=A9=E5=B1=9E=E6=80=A7+=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E7=BB=84=E7=BB=87=E5=90=AF=E7=94=A8=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=88=E5=8C=85=E5=90=AB=E4=B8=BB=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=EF=BC=89=EF=BC=8C=E8=AE=A1=E5=88=92=E3=80=81=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E3=80=81=E8=B4=A2=E5=8A=A1=E6=88=90=E6=9C=AC=E9=A1=B5?= =?UTF-8?q?=E7=AD=BE=E5=AF=B9=E5=BA=94=E4=B8=9A=E5=8A=A1=E5=8D=95=E5=85=83?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=90=AF=E7=94=A8=E9=A1=B9=E7=9B=AE=E8=BE=85?= =?UTF-8?q?=E5=8A=A9=E5=B1=9E=E6=80=A7=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MaterialStockAsstsChangedListener.java | 99 +++++++------------ 1 file changed, 38 insertions(+), 61 deletions(-) diff --git a/uapbd/src/private/nc/impl/bd/material/baseinfo/MaterialStockAsstsChangedListener.java b/uapbd/src/private/nc/impl/bd/material/baseinfo/MaterialStockAsstsChangedListener.java index 71ee6ac..da08128 100644 --- a/uapbd/src/private/nc/impl/bd/material/baseinfo/MaterialStockAsstsChangedListener.java +++ b/uapbd/src/private/nc/impl/bd/material/baseinfo/MaterialStockAsstsChangedListener.java @@ -42,23 +42,24 @@ public class MaterialStockAsstsChangedListener implements IBusinessListener { List fixlist=new ArrayList(); - - if(fixasst2.booleanValue()){ - fixlist.add("2"); - } - if(fixasst4.booleanValue()){ - fixlist.add("4"); - } - if(fixlist.isEmpty()){ - return; - }else{ + fixlist.add(fixasst2.toString()); + fixlist.add(fixasst4.toString()); +// if(fixasst2.booleanValue()){ +// fixlist.add("Y"); +// } +// if(fixasst4.booleanValue()){ +// fixlist.add("Y"); +// } +// if(fixlist.isEmpty()){ +// return; +// }else{ //鎴愭湰 this.updateMaterialCostUpdateAssts(fixlist,newVO.getPk_org(), pk_material); //鐢熶骇淇℃伅 this.updateMaterialProdAssts(fixlist,newVO.getPk_org(), pk_material); //鏇存柊璁″垝淇℃伅 this.updateMaterialPlanAssts(fixlist,newVO.getPk_org(), pk_material); - } +// } } @@ -99,26 +100,26 @@ public class MaterialStockAsstsChangedListener implements IBusinessListener { return; } //鏇存柊璁′环鏂瑰紡 - String update2 = "update bd_materialcostmod set marasst2 = ? where pk_materialcost = ? "; - String update4 = "update bd_materialcostmod set marasst4 = ? where pk_materialcost = ? "; +// String update2 = "update bd_materialcostmod set marasst2 = ? where pk_materialcost = ? "; +// String update4 = "update bd_materialcostmod set marasst4 = ? where pk_materialcost = ? "; String update24 = "update bd_materialcostmod set marasst2 = ?,marasst4 = ? where pk_materialcost = ? "; - if(fixlist.contains("2") && fixlist.contains("4")){ +// if(fixlist.contains("2") && fixlist.contains("4")){ SQLParameter param1 = new SQLParameter(); - param1.addParam("Y"); - param1.addParam("Y"); + param1.addParam(fixlist.get(0)); + param1.addParam(fixlist.get(1)); param1.addParam(pk_materialcost); this.getBaseDAO().executeUpdate(update24, param1); - }else if(fixlist.contains("2")){ - SQLParameter param1 = new SQLParameter(); - param1.addParam("Y"); - param1.addParam(pk_materialcost); - this.getBaseDAO().executeUpdate(update2, param1); - }else if(fixlist.contains("4")){ - SQLParameter param1 = new SQLParameter(); - param1.addParam("Y"); - param1.addParam(pk_materialcost); - this.getBaseDAO().executeUpdate(update4, param1); - } +// }else if(fixlist.contains("2")){ +// SQLParameter param1 = new SQLParameter(); +// param1.addParam("Y"); +// param1.addParam(pk_materialcost); +// this.getBaseDAO().executeUpdate(update2, param1); +// }else if(fixlist.contains("4")){ +// SQLParameter param1 = new SQLParameter(); +// param1.addParam("Y"); +// param1.addParam(pk_materialcost); +// this.getBaseDAO().executeUpdate(update4, param1); +// } } @@ -143,23 +144,11 @@ public class MaterialStockAsstsChangedListener implements IBusinessListener { String update2 = "update bd_materialprod set costvalutasst2 = ? where pk_materialprod = ? "; String update4 = "update bd_materialprod set costvalutasst4 = ? where pk_materialprod = ? "; String update24 = "update bd_materialprod set costvalutasst2 = ?,costvalutasst4 = ? where pk_materialprod = ? "; - if(fixlist.contains("2") && fixlist.contains("4")){ - SQLParameter param1 = new SQLParameter(); - param1.addParam("Y"); - param1.addParam("Y"); - param1.addParam(pk_materialcost); - this.getBaseDAO().executeUpdate(update24, param1); - }else if(fixlist.contains("2")){ - SQLParameter param1 = new SQLParameter(); - param1.addParam("Y"); - param1.addParam(pk_materialcost); - this.getBaseDAO().executeUpdate(update2, param1); - }else if(fixlist.contains("4")){ - SQLParameter param1 = new SQLParameter(); - param1.addParam("Y"); - param1.addParam(pk_materialcost); - this.getBaseDAO().executeUpdate(update4, param1); - } + SQLParameter param1 = new SQLParameter(); + param1.addParam(fixlist.get(0)); + param1.addParam(fixlist.get(1)); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update24, param1); } private void updateMaterialPlanAssts(List fixlist,String pk_org, String pk_material) throws DAOException { @@ -183,23 +172,11 @@ public class MaterialStockAsstsChangedListener implements IBusinessListener { String update2 = "update bd_materialplan set marasst2 = ? where pk_materialplan = ? "; String update4 = "update bd_materialplan set marasst4 = ? where pk_materialplan = ? "; String update24 = "update bd_materialplan set marasst2 = ?,marasst4 = ? where pk_materialplan = ? "; - if(fixlist.contains("2") && fixlist.contains("4")){ - SQLParameter param1 = new SQLParameter(); - param1.addParam("Y"); - param1.addParam("Y"); - param1.addParam(pk_materialcost); - this.getBaseDAO().executeUpdate(update24, param1); - }else if(fixlist.contains("2")){ - SQLParameter param1 = new SQLParameter(); - param1.addParam("Y"); - param1.addParam(pk_materialcost); - this.getBaseDAO().executeUpdate(update2, param1); - }else if(fixlist.contains("4")){ - SQLParameter param1 = new SQLParameter(); - param1.addParam("Y"); - param1.addParam(pk_materialcost); - this.getBaseDAO().executeUpdate(update4, param1); - } + SQLParameter param1 = new SQLParameter(); + param1.addParam(fixlist.get(0)); + param1.addParam(fixlist.get(1)); + param1.addParam(pk_materialcost); + this.getBaseDAO().executeUpdate(update24, param1); } }