ic_uapbd_销售出库签字推送锐制MOM
This commit is contained in:
parent
df12cbce7c
commit
f237cd1f40
|
@ -53,6 +53,9 @@ public class SignBP implements ISignBP<SaleOutVO>, ISignRuleProvider<SaleOutVO>
|
|||
// 销售出库 签字后 同步到MES金思维系统
|
||||
processor.addAfterRule(new AfterSigningSynchronizeRule());
|
||||
// 盘点(审批后传MES)
|
||||
|
||||
// 销售出库 签字后 同步到锐制
|
||||
processor.addAfterRule(new AfterSigningSynchronizeRuleRZ());
|
||||
}
|
||||
|
||||
public void addBeforeRule(SaleOutVO[] vos, AroundProcesser<SaleOutVO> processor) {
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
package nc.bs.ic.m4c.sign.rule;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import nc.bs.dao.BaseDAO;
|
||||
import nc.bs.logging.Log;
|
||||
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
|
||||
import nc.impl.pubapp.pattern.rule.IRule;
|
||||
import nc.jdbc.framework.processor.ColumnProcessor;
|
||||
import nc.pubitf.para.SysInitQuery;
|
||||
import nc.vo.bd.cust.CustomerVO;
|
||||
import nc.vo.bd.material.MaterialVO;
|
||||
import nc.vo.bd.stordoc.StordocVO;
|
||||
import nc.vo.cmp.util.StringUtils;
|
||||
import nc.vo.ic.m4c.entity.SaleOutBodyVO;
|
||||
import nc.vo.ic.m4c.entity.SaleOutHeadVO;
|
||||
import nc.vo.ic.m4c.entity.SaleOutVO;
|
||||
import nc.vo.org.DeptVO;
|
||||
import nc.vo.org.OrgVO;
|
||||
import nc.vo.pub.BusinessException;
|
||||
import nc.vo.pub.lang.UFDate;
|
||||
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
||||
import nc.vo.pubapp.pattern.pub.SqlBuilder;
|
||||
import nc.vo.scmpub.util.ArrayUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Classname AfterSigningSynchronizeRuleRZ
|
||||
* @Description TODO
|
||||
* @Version 1.0.0
|
||||
* @Date 2025/5/16 9:01
|
||||
* @Created by ame
|
||||
*/
|
||||
public class AfterSigningSynchronizeRuleRZ implements IRule<SaleOutVO> {
|
||||
private static Log log=Log.getInstance("rzmomlog");
|
||||
|
||||
private static BaseDAO dao = new BaseDAO();
|
||||
@Override
|
||||
public void process(SaleOutVO[] saleOutVOS) {
|
||||
if(ArrayUtil.isEmpty(saleOutVOS)){
|
||||
return;
|
||||
}
|
||||
try{
|
||||
//检查并筛选销售出库单据为互感器公司
|
||||
List<SaleOutVO> newSaleOutVOS= checkAndFilterBillSrcOrg(saleOutVOS);
|
||||
if(newSaleOutVOS==null||newSaleOutVOS.size()<1){
|
||||
return;
|
||||
}
|
||||
pushToRZMOM(newSaleOutVOS.toArray(new SaleOutVO[0]));
|
||||
}catch (Exception e){
|
||||
ExceptionUtils.wrappException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<SaleOutVO> checkAndFilterBillSrcOrg(SaleOutVO[] saleOutVOS) throws BusinessException {
|
||||
List<SaleOutVO> aggvoList=new ArrayList<>();
|
||||
for(SaleOutVO aggvo:saleOutVOS){
|
||||
String pkOrg = aggvo.getHead().getPk_org();
|
||||
String orgCode = transferCodeByPk(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
|
||||
if("30401".equals(orgCode)){
|
||||
aggvoList.add(aggvo);
|
||||
}
|
||||
}
|
||||
return aggvoList;
|
||||
}
|
||||
|
||||
private void pushToRZMOM(SaleOutVO[] saleOutVOS) throws BusinessException {
|
||||
String rzwmsip = SysInitQuery.getParaString("GLOBLE00000000000000", "RZWMSIP");
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject dataIn = new JSONObject();
|
||||
JSONObject dataIn2 = new JSONObject();
|
||||
JSONArray details = new JSONArray();
|
||||
jsonObject.put("dataflow","泰开BIP→RZMOMv6");
|
||||
jsonObject.put("actionCode","cpfhtzdb");
|
||||
//单笔/批量按明细传
|
||||
for (SaleOutVO saleOutVO : saleOutVOS) {
|
||||
SaleOutHeadVO head = saleOutVO.getHead();
|
||||
SaleOutBodyVO[] bodys = saleOutVO.getBodys();
|
||||
// 构建需要同步的数据
|
||||
buildSyncData(head, bodys,details);
|
||||
}
|
||||
dataIn2.put("Details",details);
|
||||
dataIn.put("Data",dataIn2);
|
||||
data.put("data",dataIn);
|
||||
jsonObject.put("data",data);
|
||||
log.error("销售出库签字推送锐制请求报文:"+jsonObject.toJSONString());
|
||||
String result = ThirdPartyPostRequestUtil.sendPostRequest(rzwmsip, jsonObject.toJSONString());
|
||||
JSONObject resultObj = JSONObject.parseObject(result);
|
||||
if("false".equals(resultObj.getString("success"))){
|
||||
throw new BusinessException("RZMOM同步失败,原因:"+resultObj.getString("msg"));
|
||||
}
|
||||
}
|
||||
|
||||
private void buildSyncData(SaleOutHeadVO head, SaleOutBodyVO[] bodys, JSONArray details) throws BusinessException {
|
||||
|
||||
String vbillcode = head.getVbillcode();//单据号
|
||||
String vtrantypecode = head.getVtrantypecode();//出入库类型编码
|
||||
//部门
|
||||
String cdptCode =transferCodeByPk(DeptVO.getDefaultTableName(), DeptVO.CODE,DeptVO.PK_DEPT,head.getCdptid());
|
||||
|
||||
for(SaleOutBodyVO body:bodys){
|
||||
JSONObject singleObj = new JSONObject();
|
||||
String cgeneralhid = body.getCgeneralhid();//表头主键
|
||||
String cgeneralbid = body.getCgeneralbid();//表体主键
|
||||
String crowno = body.getCrowno();//行号
|
||||
String cmaterialvid = body.getCmaterialvid();//物料
|
||||
String casscustid = body.getCasscustid();//客户
|
||||
String cbodywarehouseid = body.getCbodywarehouseid();//仓库
|
||||
UFDate dbizdate = body.getDbizdate();//仓库
|
||||
singleObj.put("djbh_id",cgeneralhid+"_"+cgeneralbid);//单据id
|
||||
singleObj.put("djbh",vbillcode);//单据编号
|
||||
singleObj.put("djxh",crowno);//单据序号
|
||||
singleObj.put("djrq",dbizdate.toString());//单据日期--出库日期
|
||||
singleObj.put("wbid",cgeneralhid);//第三方系统主键id
|
||||
singleObj.put("wbpid",cgeneralbid);//第三方系统分组id
|
||||
//第三方系统物料名称id--编码
|
||||
singleObj.put("wlbm_wbid",transferCodeByPk(MaterialVO.getDefaultTableName(),MaterialVO.CODE,MaterialVO.PK_MATERIAL,cmaterialvid));
|
||||
//第三方系统客户id--编码
|
||||
singleObj.put("khbh_wbid",transferCodeByPk(CustomerVO.getDefaultTableName(),CustomerVO.CODE,CustomerVO.PK_CUSTOMER,casscustid));
|
||||
//送达地点-code
|
||||
String storeCode = transferCodeByPk(StordocVO.getDefaultTableName(), StordocVO.CODE, StordocVO.PK_STORDOC, cbodywarehouseid);
|
||||
singleObj.put("sddd",storeCode);
|
||||
//第三方系统仓库id -code
|
||||
singleObj.put("ckbh_wbid",storeCode);
|
||||
//部门
|
||||
singleObj.put("bzsm",cdptCode);
|
||||
//签发标记
|
||||
singleObj.put("qfbj",1);
|
||||
//订单编号
|
||||
singleObj.put("ddbh",body.getVsourcebillcode());
|
||||
//订单序号
|
||||
singleObj.put("ddxh",body.getVsourcerowno());
|
||||
//单据数量
|
||||
singleObj.put("djsl",body.getNshouldassistnum().getDouble());
|
||||
//操作状态 1新增/修改、2删除(删除时只需上传wbid)
|
||||
singleObj.put("operate",1);
|
||||
details.add(singleObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String transferCodeByPk(String tableName, String selectField, String pkField, String pk) throws BusinessException {
|
||||
if(StringUtils.isEmpty(pk)){
|
||||
return null;
|
||||
}
|
||||
SqlBuilder sqlBuilder = new SqlBuilder();
|
||||
sqlBuilder.append(" select " + selectField);
|
||||
sqlBuilder.append(" from " + tableName);
|
||||
sqlBuilder.append(" where ");
|
||||
sqlBuilder.append(pkField, pk);
|
||||
Object o = dao.executeQuery(sqlBuilder.toString(), new ColumnProcessor());
|
||||
if (o == null) {
|
||||
throw new BusinessException("未查询到编码信息,sql【" + sqlBuilder + "】");
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package nc.bs.uapbd.util;
|
||||
|
||||
|
||||
import nc.vo.pub.BusinessException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
/**
|
||||
* @Classname ThirdPartyPostRequestUtil
|
||||
* @Description TODO
|
||||
* @Version 1.0.0
|
||||
* @Date 2025/5/15 18:22
|
||||
* @Created by ame
|
||||
*/
|
||||
public class ThirdPartyPostRequestUtil {
|
||||
|
||||
private static final int DEFAULT_CONNECT_TIMEOUT = 10000;
|
||||
private static final int DEFAULT_READ_TIMEOUT = 10000;
|
||||
|
||||
/**
|
||||
* 向第三方系统发送 POST 请求,并根据 HTTP 状态码返回数据
|
||||
*
|
||||
* @param requestUrl 请求地址
|
||||
* @param requestBody 请求体(JSON 格式)
|
||||
* @return 如果响应码为 200,则返回响应内容;否则返回错误信息
|
||||
*/
|
||||
public static String sendPostRequest(String requestUrl, String requestBody) throws BusinessException {
|
||||
try {
|
||||
URL url = new URL(requestUrl);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
// 设置请求方法和参数
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true); // 允许输出
|
||||
connection.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT); // 设置连接超时时间
|
||||
connection.setReadTimeout(DEFAULT_READ_TIMEOUT); // 设置读取超时时间
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // 设置请求头
|
||||
|
||||
// 发送请求体
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
byte[] input = requestBody.getBytes("utf-8");
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
|
||||
// 获取响应
|
||||
int responseCode = connection.getResponseCode();
|
||||
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) { // 成功响应
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line;
|
||||
StringBuilder responseBuilder = new StringBuilder();
|
||||
while ((line = in.readLine()) != null) {
|
||||
responseBuilder.append(line);
|
||||
}
|
||||
in.close();
|
||||
return responseBuilder.toString(); // 返回成功响应数据
|
||||
} else {
|
||||
throw new BusinessException("POST 请求失败,响应码:" + responseCode) ; // 返回失败信息
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("发生异常:" + e.getMessage()) ; // 异常处理
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue