Merge remote-tracking branch 'origin/main'

This commit is contained in:
张明 2025-06-13 09:14:29 +08:00
commit 6225338437
6 changed files with 770 additions and 13 deletions

View File

@ -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<String, Object> 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<Header> 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<Header> headers = new ArrayList<Header>();
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<String, Object> params = new HashMap<String, Object>();
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;
}
}

View File

@ -5,9 +5,9 @@
package nccloud.web.uapbd.customer.baseinfo.action; package nccloud.web.uapbd.customer.baseinfo.action;
import com.alibaba.fastjson.JSONObject;
import nc.bs.dao.BaseDAO; import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.InvocationInfoProxy; import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.logging.Logger;
import nc.bs.uif2.LockFailedException; import nc.bs.uif2.LockFailedException;
import nc.bs.uif2.VersionConflictException; import nc.bs.uif2.VersionConflictException;
import nc.itf.bd.cust.assign.ICustAssignService; import nc.itf.bd.cust.assign.ICustAssignService;
@ -17,14 +17,12 @@ import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.MapProcessor; import nc.jdbc.framework.processor.MapProcessor;
import nc.uap.utils.ResHelper; import nc.uap.utils.ResHelper;
import nc.vo.bd.cust.*; import nc.vo.bd.cust.*;
import nc.vo.bd.errorlog.ErrLogReturnValue;
import nc.vo.bd.supplier.SupplierVO; import nc.vo.bd.supplier.SupplierVO;
import nc.vo.ml.NCLangRes4VoTransl; import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.org.OrgVO; import nc.vo.org.OrgVO;
import nc.vo.pub.BusinessException; import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO; import nc.vo.pub.SuperVO;
import nc.vo.pub.lang.UFDateTime; import nc.vo.pub.lang.UFDateTime;
import nccloud.baseapp.core.log.NCCForUAPLogger;
import nccloud.commons.lang.StringUtils; import nccloud.commons.lang.StringUtils;
import nccloud.framework.core.exception.ExceptionUtils; import nccloud.framework.core.exception.ExceptionUtils;
import nccloud.framework.service.ServiceLocator; 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(); OrgVO[] virtulaOrg = getVirtulaOrg();
String[] assignOrgPks = Arrays.stream(virtulaOrg).map(OrgVO::getPk_org).toArray(String[]::new); 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); ErrLogReturnValue errLogReturnValue = cs.getAssignService().assignCustomerByPks(customerPks, assignOrgPks, null);
Logger.error("CustomerSaveAction-errLogReturnValue = " + errLogReturnValue.getErrLogResult()); Logger.error("CustomerSaveAction-errLogReturnValue = " + errLogReturnValue.getErrLogResult());*/
// NCCForUAPLogger.debug("customerPks = " + customerPks[0]); assignOrgApi(customerVO);
// NCCForUAPLogger.debug("assignOrgPks = " + Arrays.toString(assignOrgPks));
// NCCForUAPLogger.debug("CustomerSaveAction-errLogReturnValue = " + errLogReturnValue.getErrLogResult());
} catch (Exception e) { } catch (Exception e) {
if (e instanceof UndeclaredThrowableException) { if (e instanceof UndeclaredThrowableException) {
Throwable undeclaredThrowable = ((UndeclaredThrowableException) e).getUndeclaredThrowable(); Throwable undeclaredThrowable = ((UndeclaredThrowableException) e).getUndeclaredThrowable();
@ -200,6 +195,23 @@ public class CustomerSaveAction implements ICommonAction {
return ebc; 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<OrgVO> collection = (new BaseDAO()).retrieveByClause(OrgVO.class, condition, "code"); Collection<OrgVO> collection = (new BaseDAO()).retrieveByClause(OrgVO.class, condition, "code");
return collection.toArray(new OrgVO[0]); return collection.toArray(new OrgVO[0]);
} }
} }

View File

@ -5,6 +5,7 @@
package nccloud.web.uapbd.customer.baseinfo.action; package nccloud.web.uapbd.customer.baseinfo.action;
import com.alibaba.fastjson.JSONObject;
import nc.bs.dao.BaseDAO; import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.InvocationInfoProxy; import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.logging.Logger; import nc.bs.logging.Logger;
@ -109,13 +110,12 @@ public class CustomerSaveAddAction implements ICommonAction {
ebc.setUserjson(billCodeContext == null ? "" : "" + billCodeContext.isEditable()); ebc.setUserjson(billCodeContext == null ? "" : "" + billCodeContext.isEditable());
// 自动分配组织 // 自动分配组织
String[] customerPks = {customerVO.getPk_customer()}; /*String[] customerPks = {customerVO.getPk_customer()};
OrgVO[] virtulaOrg = getVirtulaOrg(); OrgVO[] virtulaOrg = getVirtulaOrg();
String[] assignOrgPks = Arrays.stream(virtulaOrg).map(OrgVO::getPk_org).toArray(String[]::new); 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); 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) { } catch (BusinessException e) {
ExceptionUtils.wrapException(e); ExceptionUtils.wrapException(e);
} }
@ -123,6 +123,23 @@ public class CustomerSaveAddAction implements ICommonAction {
return ebc; 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);
}
/** /**
* 查询组织信息 * 查询组织信息
* *

View File

@ -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<String, Object> params) {
StringBuffer paramStr = new StringBuffer();
if (!params.isEmpty()) {
for (Map.Entry<String, Object> 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();
}
}
}

View File

@ -0,0 +1,182 @@
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<String> fixlist=new ArrayList();
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);
// }
}
}
private List<String> 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<String> 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(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);
// }
}
private void updateMaterialProdAssts(List<String> 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 = ? ";
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<String> 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 = ? ";
SQLParameter param1 = new SQLParameter();
param1.addParam(fixlist.get(0));
param1.addParam(fixlist.get(1));
param1.addParam(pk_materialcost);
this.getBaseDAO().executeUpdate(update24, param1);
}
}

View File

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