下拨单增加sap凭证红冲
This commit is contained in:
parent
bf81981fb5
commit
cf1a6e0fcc
|
|
@ -18,19 +18,23 @@ import kd.bos.orm.query.QCP;
|
||||||
import kd.bos.orm.query.QFilter;
|
import kd.bos.orm.query.QFilter;
|
||||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
import kd.bos.servicehelper.QueryServiceHelper;
|
import kd.bos.servicehelper.QueryServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
import kd.sdk.plugin.Plugin;
|
import kd.sdk.plugin.Plugin;
|
||||||
import shjh.jhzj7.fi.fi.utils.ApiUtils;
|
import shjh.jhzj7.fi.fi.utils.ApiUtils;
|
||||||
|
import shjh.jhzj7.fi.fi.utils.EsbUtils;
|
||||||
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
||||||
import shjh.jhzj7.fi.fi.utils.SapUtils;
|
import shjh.jhzj7.fi.fi.utils.SapUtils;
|
||||||
import shjh.jhzj7.fi.fi.utils.domin.ResponseData;
|
import shjh.jhzj7.fi.fi.utils.domin.ResponseData;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下拨处理
|
* 下拨处理
|
||||||
* shjh_fca_transdownbil_ext
|
* shjh_fca_transdownbil_ext
|
||||||
|
* 0731增加sap凭证红冲处理
|
||||||
*/
|
*/
|
||||||
public class TransdownbillOperation extends AbstractOperationServicePlugIn implements Plugin {
|
public class TransdownbillOperation extends AbstractOperationServicePlugIn implements Plugin {
|
||||||
|
|
||||||
|
|
@ -41,6 +45,12 @@ public class TransdownbillOperation extends AbstractOperationServicePlugIn imple
|
||||||
private static final String ccName = "bos_costcenter";//成本中心
|
private static final String ccName = "bos_costcenter";//成本中心
|
||||||
private static final String glbdName = "gl_assist_bd";//核算项目组合纵表
|
private static final String glbdName = "gl_assist_bd";//核算项目组合纵表
|
||||||
|
|
||||||
|
private static final String INTERFACE_ID = "ReversalVoucher";//识别被调接口并进行路由-SAP反清账
|
||||||
|
|
||||||
|
private static final String RECEIVER_ID = "SAP";//定义的发送者
|
||||||
|
private static final String API_URL = System.getProperty("url_a");//sap相关接口地址
|
||||||
|
private static final String KEY_RED_PUSH = "redpunch";//sap红冲凭证的操作标记
|
||||||
|
|
||||||
private final static Log logger = LogFactory.getLog(TransdownbillOperation.class);
|
private final static Log logger = LogFactory.getLog(TransdownbillOperation.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -61,6 +71,21 @@ public class TransdownbillOperation extends AbstractOperationServicePlugIn imple
|
||||||
e.setCancel(true);
|
e.setCancel(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else if(KEY_RED_PUSH.equals(eok)){
|
||||||
|
//sap凭证红冲处理 前置校验
|
||||||
|
DynamicObject[] dos = e.getDataEntities();
|
||||||
|
DynamicObject prinfo;
|
||||||
|
for (int i = 0; i < dos.length; i++) {
|
||||||
|
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName());
|
||||||
|
//判断下拨处理单是否已生成金蝶凭证
|
||||||
|
if(!prinfo.getBoolean("isvoucher")){
|
||||||
|
e.setCancelMessage(prinfo.getString("billno") + "未生成金蝶凭证,无法推送SAP红冲凭证");
|
||||||
|
e.setCancel(true);
|
||||||
|
}else if(!prinfo.getBoolean("shjh_sendsap")){
|
||||||
|
e.setCancelMessage(prinfo.getString("billno") + "未推送过SAP,无需红冲");
|
||||||
|
e.setCancel(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,8 +123,110 @@ public class TransdownbillOperation extends AbstractOperationServicePlugIn imple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else if(KEY_RED_PUSH.equals(eok)){
|
||||||
|
//sap凭证红冲处理
|
||||||
|
DynamicObject[] dos = e.getDataEntities();
|
||||||
|
DynamicObject prinfo = null;//下拨处理单
|
||||||
|
JSONObject sapReturnData;
|
||||||
|
String billNumber;
|
||||||
|
StringBuilder message = new StringBuilder();
|
||||||
|
for (int i = 0; i < dos.length; i++) {
|
||||||
|
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName());
|
||||||
|
if(prinfo.getBoolean("shjh_sendsap")){
|
||||||
|
//如果下拨处理单已推送sap才需要红冲
|
||||||
|
billNumber = prinfo.getString("billno");//单号
|
||||||
|
HashMap<String, String> responseHead = ApiUtils.buildHead(INTERFACE_ID,RECEIVER_ID);
|
||||||
|
HashMap<String, Object> responseBody = this.assembleRequest(billNumber, prinfo, message);
|
||||||
|
try {
|
||||||
|
String response = ApiUtils.sendPost(responseHead, responseBody, API_URL);
|
||||||
|
if (!EsbUtils.isEmpty(response)) {
|
||||||
|
boolean success = ApiUtils.parseResponse(response, billNumber, responseBody, "SAP反清账或冲销", message);
|
||||||
|
if (success){
|
||||||
|
//sap红冲凭证成功,反写sap凭证号和推送标记
|
||||||
|
sapReturnData = JSONObject.parseObject(response);
|
||||||
|
JSONObject data = sapReturnData.getJSONObject("data");
|
||||||
|
JSONArray rows = data.getJSONArray("IT_ITEM");
|
||||||
|
JSONObject resultData = rows.getJSONObject(0);
|
||||||
|
String key = resultData.getString("OBJ_KEY");
|
||||||
|
if(EsbUtils.isEmpty(key)){
|
||||||
|
message.append("下拨处理【").append(billNumber).append("】:").append("SAP返回的OBJ_KEY为空").append("\n");
|
||||||
|
}else{
|
||||||
|
//sap红冲凭证号根据返回值更新
|
||||||
|
prinfo.set("shjh_hcsappzh",key.length() >= 10 ? key.substring(0, 10) : key);
|
||||||
|
prinfo.set("shjh_sendsap",false);//sap已推送标记-置为false,让后续可以再推蓝字凭证
|
||||||
|
prinfo.set("shjh_sappzh",null);//sap凭证号置为空
|
||||||
|
prinfo.set("shjh_sapyear",null);//sap年度置为空
|
||||||
|
SaveServiceHelper.update(prinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
message.append("下拨处理【").append(billNumber).append("】:").append("SAP返回值为空").append("\n");
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
message.append("下拨处理【").append(billNumber).append("】:").append(ex.getMessage()).append("\n");
|
||||||
|
logger.info("调用下拨红冲凭证接口异常"+message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (message.length() != 0){
|
||||||
|
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
|
||||||
|
operateErrorInfo.setMessage(String.valueOf(message));
|
||||||
|
operateErrorInfo.setErrorLevel(kd.bos.entity.validate.ErrorLevel.Error.name());
|
||||||
|
operateErrorInfo.setPkValue(prinfo.getPkValue());
|
||||||
|
this.operationResult.addErrorInfo(operateErrorInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求头组装
|
||||||
|
* @param billNumber 单据编号
|
||||||
|
* @param recBill 下拨处理
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private HashMap<String, Object> assembleRequest(String billNumber, DynamicObject recBill, StringBuilder message){
|
||||||
|
HashMap<String, Object> responseBody = null;
|
||||||
|
try {
|
||||||
|
// 生成唯一事务ID
|
||||||
|
String rootContextId = UUID.randomUUID().toString();
|
||||||
|
// 获取当前请求时间,格式为 yyyy-MM-dd HH:mm:ss.SSS
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||||
|
String requestTime = sdf.format(new Date());
|
||||||
|
responseBody = new HashMap<>(5);
|
||||||
|
responseBody.put("rootContextID", rootContextId);
|
||||||
|
responseBody.put("requestTime", requestTime);
|
||||||
|
HashMap<String, Object> data = new HashMap<>(1);
|
||||||
|
List<Map<String, Object>> IT_ITEM = new ArrayList<>(1);
|
||||||
|
//用户名-从红冲单上获取人员,当前操作人可能是定时任务
|
||||||
|
DynamicObject userinfo = BusinessDataServiceHelper.loadSingleFromCache(RequestContext.get().getCurrUserId(), userName);
|
||||||
|
String oaUser = userinfo.getString("shjh_oauser");
|
||||||
|
//冲销原因
|
||||||
|
Map<String, Object> IT_ITEMS = new HashMap<>(6);
|
||||||
|
//红冲所需参数从红字下拨单上获取,红单上保留了原蓝字下拨单的凭证号和会计年度
|
||||||
|
IT_ITEMS.put("BELNR",recBill.getString("shjh_sappzh"));//会计凭证编号
|
||||||
|
IT_ITEMS.put("BUKRS",recBill.getString("company.number"));//公司代码
|
||||||
|
IT_ITEMS.put("GJAHR",recBill.getString("shjh_sapyear"));//会计年度
|
||||||
|
IT_ITEMS.put("STGRD","04");//冲销原因 跨期冲销;默认04,冲销日期必传
|
||||||
|
if(EsbUtils.isEmpty(oaUser)){
|
||||||
|
IT_ITEMS.put("UNAME","资金系统");//用户名
|
||||||
|
}else{
|
||||||
|
IT_ITEMS.put("UNAME",oaUser);//用户名
|
||||||
|
}
|
||||||
|
SimpleDateFormat sdfdate = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
if(recBill.getDate("transbilldate") == null){
|
||||||
|
IT_ITEMS.put("BUDAT",sdfdate.format(new Date()));//凭证中的过帐日期
|
||||||
|
}else {
|
||||||
|
IT_ITEMS.put("BUDAT",sdfdate.format(recBill.getDate("transbilldate")));//凭证中的过帐日期
|
||||||
|
}
|
||||||
|
IT_ITEM.add(IT_ITEMS);
|
||||||
|
data.put("IT_ITEM", IT_ITEM);
|
||||||
|
responseBody.put("data", data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
message.append("下拨处理【").append(billNumber).append("】:").append(e.getMessage()).append("\n");
|
||||||
|
EsbUtils.saveLog(billNumber, INTERFACE_ID, null, e.getMessage(), false, KEY_RED_PUSH, "数据异常");
|
||||||
|
}
|
||||||
|
return responseBody;
|
||||||
|
}
|
||||||
|
|
||||||
private JSONObject sendBlueVoucher(DynamicObject prinfo, Map<String, String> sapMap){
|
private JSONObject sendBlueVoucher(DynamicObject prinfo, Map<String, String> sapMap){
|
||||||
//SAP下拨处理单凭证接口入参组装和调用
|
//SAP下拨处理单凭证接口入参组装和调用
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue