收付款推SAP、费控报错反写前端
This commit is contained in:
parent
37788ee807
commit
d11418d867
|
|
@ -8,17 +8,25 @@ import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|||
import kd.bos.entity.operate.result.OperateErrorInfo;
|
||||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||
import kd.bos.fileservice.FileServiceFactory;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.AttachmentDto;
|
||||
import kd.bos.servicehelper.AttachmentServiceHelper;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.bos.util.StringUtils;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import shjh.jhzj7.fi.fi.plugin.task.RecPushSapTask;
|
||||
import shjh.jhzj7.fi.fi.utils.SapUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -32,6 +40,9 @@ import static shjh.jhzj7.fi.fi.utils.SapUtils.withholding_billing;
|
|||
|
||||
public class PaybillOperation extends AbstractOperationServicePlugIn implements Plugin {
|
||||
|
||||
|
||||
private final static Log logger = LogFactory.getLog(PaybillOperation.class);
|
||||
|
||||
@Override
|
||||
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||
super.afterExecuteOperationTransaction(e);
|
||||
|
|
@ -86,7 +97,10 @@ public class PaybillOperation extends AbstractOperationServicePlugIn implements
|
|||
String code = (String) jsonObject.get("code");
|
||||
if (!"0".equals(code)) {
|
||||
addErrorInfo(bill, ""+jsonObject.get("msg"));
|
||||
//更新推送报错
|
||||
SapUtils.updateBillErrorMsg(bill,jsonObject,"shjh_errormsg");
|
||||
} else {
|
||||
bill.set("shjh_errormsg","");
|
||||
bill.set("shjh_ispushfk", true);
|
||||
SaveServiceHelper.save(new DynamicObject[]{bill});
|
||||
this.operationResult.addSuccessPkId(bill.getPkValue());
|
||||
|
|
@ -171,22 +185,40 @@ public class PaybillOperation extends AbstractOperationServicePlugIn implements
|
|||
header.put("FM_ExpenseTypeCode", FM_ExpenseTypeCode);// 业务大类编码(EQ49,EQ44,EQ1101)
|
||||
header.put("FM_CurrencyCode", "RMB");// 币种编码,默认:RMB
|
||||
header.put("FM_RequestName", bill.getString("description"));// 单据主题_拼接
|
||||
// List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(bill.getDataEntityType().getName(), bill.getLong("id"), "attachmentpanel");
|
||||
// if (attachments.size()!=0){
|
||||
// JSONArray attachUrls = new JSONArray();
|
||||
// for (Map<String, Object> attachment : attachments) {
|
||||
// String url = (String)attachment.get("url");
|
||||
// attachUrls.add(url);
|
||||
// }
|
||||
// header.put("FM_AttachUrl", attachUrls);//附件URL地址:array
|
||||
// }
|
||||
header.put("FM_AttachUrl", null);//附件URL地址:array
|
||||
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(bill.getDataEntityType().getName(), bill.getLong("id"), "attachmentpanel");
|
||||
if (attachments.size()!=0){
|
||||
JSONArray attachUrls = new JSONArray();
|
||||
for (Map<String, Object> attachment : attachments) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String fileBase64 = getFileBase64StrByUrl(attachment);//转换为Base64数据
|
||||
jsonObject.put("attachData",fileBase64);
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(fileBase64);
|
||||
int byteLength = decodedBytes.length;
|
||||
jsonObject.put("attachDataLength",byteLength);
|
||||
jsonObject.put("attachName",attachment.get("name"));
|
||||
jsonObject.put("attachType",attachment.get("type"));
|
||||
attachUrls.add(jsonObject);
|
||||
}
|
||||
header.put("FM_AttachUrl", attachUrls);//附件URL地址:array
|
||||
}
|
||||
//header.put("FM_AttachUrl", null);//附件URL地址:array
|
||||
header.put("FM_BudType", 0);//预算类别0-组织预算,1-全年预算,当前只处理0 int
|
||||
header.put("Remark", bill.getString("description"));// 事项描述_摘要
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
public static String getFileBase64StrByUrl(Map<String, Object> attachment){
|
||||
Object attPKId = attachment.get("attPkId");
|
||||
AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(attPKId);
|
||||
String resourcePath = attachmentDto.getResourcePath();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
FileServiceFactory.getAttachmentFileService().download(resourcePath,out,null);
|
||||
byte[] bytes = out.toByteArray();
|
||||
String baseStr = new String(Base64.getEncoder().encode(bytes));
|
||||
return baseStr;
|
||||
}
|
||||
|
||||
// 构建body方法
|
||||
public static JSONArray buildBody(DynamicObject bill) {
|
||||
bill = BusinessDataServiceHelper.loadSingle(bill.getPkValue(), "cas_paybill");
|
||||
|
|
|
|||
|
|
@ -21,10 +21,7 @@ import kd.bos.servicehelper.QueryServiceHelper;
|
|||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.bos.util.StringUtils;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
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.SysUtils;
|
||||
import shjh.jhzj7.fi.fi.utils.*;
|
||||
import shjh.jhzj7.fi.fi.utils.domin.ResponseData;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -819,6 +816,7 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
bill.set("shjh_credentialnum",responseData.getNumber());
|
||||
bill.set("shjh_sapfiscalyear",responseData.getYear());
|
||||
bill.set("shjh_ispushsap", true);
|
||||
bill.set("shjh_errormsg","");
|
||||
SaveServiceHelper.save(new DynamicObject[]{bill});
|
||||
//处理sap主动付款时,更新日记账的sap凭证号
|
||||
//处理被动付款时,更新流水和日记账的sap凭证号
|
||||
|
|
@ -856,6 +854,8 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
this.operationResult.addErrorInfo(operateErrorInfo);
|
||||
}
|
||||
}else {
|
||||
//更新推送报错
|
||||
SapUtils.updateBillErrorMsg(bill,jsonObject,"shjh_errormsg");
|
||||
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
|
||||
operateErrorInfo.setMessage("推送SAP凭证接口失败,原因:"+jsonObject.get("msg"));
|
||||
operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import kd.sdk.plugin.Plugin;
|
|||
import shjh.jhzj7.fi.fi.plugin.form.info.RecFieldsInfo;
|
||||
import shjh.jhzj7.fi.fi.utils.ApiUtils;
|
||||
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
||||
import shjh.jhzj7.fi.fi.utils.SapUtils;
|
||||
import shjh.jhzj7.fi.fi.utils.SysUtils;
|
||||
import shjh.jhzj7.fi.fi.utils.domin.ResponseData;
|
||||
|
||||
|
|
@ -234,6 +235,8 @@ public class RecPushVoucherOperation extends AbstractOperationServicePlugIn impl
|
|||
recBill.set("shjh_vouchernum",responseData.getNumber());
|
||||
recBill.set("shjh_sapfiscalyear",responseData.getYear());
|
||||
recBill.set("shjh_ispushsap", true);
|
||||
recBill.set("shjh_errormsg","");
|
||||
|
||||
SaveServiceHelper.update(recBill);
|
||||
DynamicObject bankjournal = BusinessDataServiceHelper.loadSingle("cas_bankjournal", new QFilter("billno",
|
||||
QCP.equals, recBill.getString("billno")).toArray());
|
||||
|
|
@ -265,6 +268,8 @@ public class RecPushVoucherOperation extends AbstractOperationServicePlugIn impl
|
|||
|
||||
}
|
||||
}else {
|
||||
//更新推送报错
|
||||
SapUtils.updateBillErrorMsg(recBill,response,"shjh_errormsg");
|
||||
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
|
||||
operateErrorInfo.setMessage((String) response.get("msg"));
|
||||
operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import kd.bos.orm.query.QCP;
|
|||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
|
|
@ -758,4 +759,28 @@ public class SapUtils {
|
|||
|
||||
return sapMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新单据错误信息
|
||||
* @param bill 表单实体
|
||||
* @param response 返回参数
|
||||
* @param filedName 字段标识
|
||||
*/
|
||||
public static void updateBillErrorMsg(DynamicObject bill,JSONObject response,String filedName){
|
||||
try {
|
||||
String errorMsg = response.getString("msg");
|
||||
|
||||
if (errorMsg != null && errorMsg.length() > 2000) {
|
||||
// 记录完整错误信息到日志
|
||||
logger.warn("错误信息过长,已截断。完整信息: {}", errorMsg);
|
||||
// 截取前2000个字符
|
||||
errorMsg = errorMsg.substring(0, 2000);
|
||||
}
|
||||
|
||||
bill.set(filedName, errorMsg);
|
||||
SaveServiceHelper.update(bill);
|
||||
} catch (Exception e) {
|
||||
logger.error("更新单据错误信息报错: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue