理财记账红冲处理

This commit is contained in:
yuxueliang0813 2025-05-17 17:01:48 +08:00
parent eb087d77c4
commit 31803bd153
3 changed files with 161 additions and 18 deletions

View File

@ -432,8 +432,11 @@ public class ClearAccountBillOperation extends AbstractOperationServicePlugIn im
//添加用户名-操作反清账按钮的用户OA用户名
DynamicObject userinfo = BusinessDataServiceHelper.loadSingleFromCache(RequestContext.get().getCurrUserId(), userName);
String oauser = userinfo.getString("shjh_oauser");
// addFilterCondition(IT_LIST, "UNAME", oauser, oauser);
iteminfo.put("UNAME", oauser);
if(JhzjUtils.isEmpty(oauser)){
iteminfo.put("UNAME","资金系统");//用户名
}else{
iteminfo.put("UNAME",oauser);//用户名
}
//添加反清账日期
if(prinfo.getDate("shjh_uncleardate") != null){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@ -451,8 +454,17 @@ public class ClearAccountBillOperation extends AbstractOperationServicePlugIn im
//sap返回的结果不为空且正确
if(sapReturnData != null && "0".equals(sapReturnData.getString("code"))){
JSONObject data = sapReturnData.getJSONObject("data");
if(data == null){
return null;
}
JSONArray rows = data.getJSONArray("IT_ITEM");
if(rows == null){
return null;
}
JSONObject resultData = rows.getJSONObject(0);
if(resultData == null){
return null;
}
//"ZFLAG":"成功与否标记"
//"ZMESSAGE":"消息"
return resultData.getString("OBJ_KEY");

View File

@ -26,6 +26,7 @@ import shjh.jhzj7.fi.fi.utils.domin.ResponseData;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 理财预提记账处理 shjh_cim_intbill_reve_ext-单据推送sap操作插件
@ -33,7 +34,7 @@ import java.text.SimpleDateFormat;
*/
public class RevenueBillOperation extends AbstractOperationServicePlugIn implements Plugin {
private static final String updateVoucherFlag = "update t_cim_revenue set fk_shjh_sendsap=1,fk_shjh_sappzh=? where fid=?;";
private static final String updateVoucherFlag = "update t_cim_revenue set fk_shjh_sendsap=1,fk_shjh_sappzh=?,fk_shjh_sapyear=? where fid=?;";
private static final String userName = "bos_user";//用户
private static final String voucherName = "gl_voucher";//凭证
private static final String pcName = "shjh_pc";//利润中心
@ -78,28 +79,104 @@ public class RevenueBillOperation extends AbstractOperationServicePlugIn impleme
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName());
if(prinfo.getBoolean("shjh_needvoucher") && !prinfo.getBoolean("shjh_sendsap")){
//如果预提记账处理单需要生成凭证且未推送sap的才推送sap
sapReturnData = sendVoucher(prinfo);
if(sapReturnData != null && "0".equals(sapReturnData.getString("code"))){
//解析sap凭证接口返回值
respdata = ApiUtils.getResponseData(sapReturnData);
if(respdata == null){
addErrorInfo(prinfo,"SAP凭证接口返回值为空详见接口日志");
continue;
//判断原蓝单和红单调用sap不同接口 操作类别 冲销预提收益-红单 预提收益-蓝单
if("interestrev".equals(prinfo.getString("operatype"))){
sapReturnData = sendBlueVoucher(prinfo);//蓝单
if(sapReturnData != null && "0".equals(sapReturnData.getString("code"))){
//解析sap凭证接口返回值
respdata = ApiUtils.getResponseData(sapReturnData);
if(respdata == null){
addErrorInfo(prinfo,"SAP凭证接口返回值为空详见接口日志");
continue;
}
//推送sap成功后反写已推送标记和sap凭证号和年度至预提单中
DB.update(DBRoute.of("fi"), updateVoucherFlag, new Object[]{respdata.getNumber(),respdata.getYear(),prinfo.getPkValue()});
this.operationResult.addSuccessPkId(prinfo.getPkValue());
}else if(sapReturnData != null){
addErrorInfo(prinfo,"推送SAP接口失败"+sapReturnData.getString("msg"));
}else{
addErrorInfo(prinfo,"推送SAP接口失败SAP返回值为空或者金蝶凭证未审核请检查");
}
}else if("writeoffrev".equals(prinfo.getString("operatype"))){
sapReturnData = sendRedVoucher(prinfo);//红单
if(sapReturnData != null && "0".equals(sapReturnData.getString("code"))){
//解析sap凭证接口返回值
JSONObject data = sapReturnData.getJSONObject("data");
if(data == null){
addErrorInfo(prinfo,"推送SAP接口失败SAP返回值data为空");
continue;
}
JSONArray rows = data.getJSONArray("IT_ITEM");
if(rows == null){
addErrorInfo(prinfo,"推送SAP接口失败SAP返回值IT_ITEM为空");
continue;
}
JSONObject resultData = rows.getJSONObject(0);
if(resultData == null){
addErrorInfo(prinfo,"推送SAP接口失败SAP返回值IT_ITEM为空");
continue;
}
String key = resultData.getString("OBJ_KEY");
if(JhzjUtils.isEmpty(key)){
addErrorInfo(prinfo,"推送SAP接口失败SAP返回值OBJ_KEY为空");
continue;
}
//推送sap成功后反写已推送标记和sap凭证号和年度至预提单中
DB.update(DBRoute.of("fi"), updateVoucherFlag, new Object[]{key.length() >= 10 ? key.substring(0, 10) : key,
key.length() >= 4 ? key.substring(key.length() - 4) : key, prinfo.getPkValue()});
this.operationResult.addSuccessPkId(prinfo.getPkValue());
}else if(sapReturnData != null){
addErrorInfo(prinfo,"推送SAP接口失败"+sapReturnData.getString("msg"));
}else{
addErrorInfo(prinfo,"推送SAP接口失败SAP返回值为空");
}
//推送sap成功后反写已推送标记和sap凭证号至预提单中
DB.update(DBRoute.of("fi"), updateVoucherFlag, new Object[]{respdata.getNumber(),prinfo.getPkValue()});
this.operationResult.addSuccessPkId(prinfo.getPkValue());
}else if(sapReturnData != null){
addErrorInfo(prinfo,"推送SAP接口失败"+sapReturnData.getString("msg"));
}else{
addErrorInfo(prinfo,"推送SAP接口失败SAP返回值为空或者金蝶凭证未审核请检查");
}
}
}
}
}
private JSONObject sendVoucher(DynamicObject prinfo){
private JSONObject sendRedVoucher(DynamicObject prinfo){
//SAP反清账接口入参组装和调用
JSONArray IT_LIST = new JSONArray();
JSONObject iteminfo = new JSONObject();
String companyCode = prinfo.getString("org.number");
//添加公司
iteminfo.put("BUKRS", companyCode);
String shjh_pzh = prinfo.getString("shjh_sappzh");
//添加会计凭证编号
iteminfo.put("BELNR", shjh_pzh);
String shjh_year = prinfo.getString("shjh_sapyear");
//添加会计年度
iteminfo.put("GJAHR", shjh_year);
//添加冲销原因-04-跨期冲销默认04冲销日期必传
iteminfo.put("STGRD", "04");
//添加用户名-操作反清账按钮的用户OA用户名
DynamicObject userinfo = BusinessDataServiceHelper.loadSingleFromCache(RequestContext.get().getCurrUserId(), userName);
String oauser = userinfo.getString("shjh_oauser");
if(JhzjUtils.isEmpty(oauser)){
iteminfo.put("UNAME","资金系统");//用户名
}else{
iteminfo.put("UNAME",oauser);//用户名
}
//添加反清账日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String datestr = sdf.format(new Date());
iteminfo.put("BUDAT", datestr);
IT_LIST.add(iteminfo);
JSONObject sapReturnData = SapUtils.sapReversalAPI(IT_LIST,prinfo.getString("billno"));
//sap返回的结果不为空且正确
// if(sapReturnData != null && "0".equals(sapReturnData.getString("code"))){
// JSONObject data = sapReturnData.getJSONObject("data");
// JSONArray rows = data.getJSONArray("IT_ITEM");
// JSONObject resultData = rows.getJSONObject(0);
// return resultData.getString("OBJ_KEY");
// }
return sapReturnData;
}
private JSONObject sendBlueVoucher(DynamicObject prinfo){
//SAP预提收益凭证接口入参组装和调用
JSONObject IS_HEADER = new JSONObject();//抬头
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//日期格式化工具

View File

@ -0,0 +1,54 @@
package shjh.jhzj7.fi.fi.plugin.operate;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
/**
* 理财预提记账处理 shjh_cim_intbill_reve_ext-红冲单中清空已推送sap标记
* 反冲销时判断是否已推送sap如果已推送不允许反冲销
* @author yuxueliang
*/
public class RevenueBillRedWriteOp extends AbstractOperationServicePlugIn implements Plugin {
private static final String updateSapFlag = "update t_cim_revenue set fk_shjh_sendsap=0 where fwriteoffpreintbillid=?;";
@Override
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
super.beforeExecuteOperationTransaction(e);
String eok = e.getOperationKey();
if("unredwriteoff".equals(eok)){
//反冲销标识
DynamicObject[] dos = e.getDataEntities();
DynamicObject prinfo;
for (int i = 0; i < dos.length; i++) {
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName());
//判断预提记账处理单-红单是否已推送了sap如果已推送了则不允许反冲销
if(prinfo.getBoolean("shjh_sendsap")){
e.setCancelMessage(prinfo.getString("billno") + "已推送至SAP不允许反冲销");
e.setCancel(true);
}
}
}
}
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
String eok = e.getOperationKey();
if("redwriteoff".equals(eok)){
//冲销标识
DynamicObject[] dos = e.getDataEntities();
for (DynamicObject prinfo : dos) {
//预提记账处理单-原蓝单 prinfo 拿此id找到对应的红单并其清空已推送sap标记
//红单中的被冲销预提单id writeoffpreintbillid 字段存的是蓝单的id
DB.update(DBRoute.of("fi"), updateSapFlag, new Object[]{prinfo.getPkValue()});
}
}
}
}