parent
670c39f54f
commit
dfc9bd99aa
|
|
@ -26,6 +26,8 @@ import kd.bos.orm.query.QFilter;
|
|||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
||||
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
||||
import shjh.jhzj7.fi.fi.webapi.model.ApiResultExt;
|
||||
import shjh.jhzj7.fi.fi.webapi.model.ApiResultPayApplyExt;
|
||||
import shjh.jhzj7.fi.fi.webapi.model.ApplyBillModel;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
|
@ -56,18 +58,19 @@ public class ApplyBillControler {
|
|||
private static final Log log = LogFactory.getLog(ApplyBillControler.class);
|
||||
|
||||
@ApiPostMapping(value = apimenthod, desc = "应付付款申请单接口")
|
||||
public CustomApiResult<ApiResult> applybill_sync (@NotNull @Valid @ApiRequestBody(value="入参json格式数据") ApplyBillModel applybill) {
|
||||
public CustomApiResult<ApiResultPayApplyExt> applybill_sync (@NotNull @Valid @ApiRequestBody(value="入参json格式数据") ApplyBillModel applybill) {
|
||||
JSONObject json_body;
|
||||
String jsonBodyString = null;
|
||||
|
||||
|
||||
//返回值
|
||||
ApiResultPayApplyExt apiResultExt = new ApiResultPayApplyExt();
|
||||
try {
|
||||
// 解析入参,如果格式不正确,日志记录,并反馈esb
|
||||
json_body = (JSONObject) JSON.toJSON(applybill);
|
||||
jsonBodyString = JSON.toJSONString(json_body);
|
||||
} catch (JSONException e) {
|
||||
handleError("应付付款申请单接口入参异常:" + e.getMessage(), Apimenthod, "费控", null);
|
||||
return CustomApiResult.fail("400", "接口入参异常");
|
||||
return handleErrorAndReturn(apiResultExt, "接口入参异常");
|
||||
}
|
||||
// 费控单据编号
|
||||
String fkBillNum = applybill.getFkBillNum();
|
||||
|
|
@ -82,7 +85,9 @@ public class ApplyBillControler {
|
|||
if (null != ap_payapply) {
|
||||
String errorMessage = "同步失败,fkBillID:" + fkBillID + ",fkEntryID:" + fkEntryID + "的费控单据已存在";
|
||||
handleError(errorMessage, fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", errorMessage);
|
||||
apiResultExt.setKdPayBillID(""+ap_payapply.getPkValue());
|
||||
apiResultExt.setKdPayBillNo(ap_payapply.getString("billno"));
|
||||
return handleErrorAndReturn(apiResultExt, errorMessage);
|
||||
}
|
||||
|
||||
// 未查到,新增应付付款申请单
|
||||
|
|
@ -94,7 +99,7 @@ public class ApplyBillControler {
|
|||
|
||||
if (null == fkBillNum || fkBillNum.isEmpty()) {
|
||||
handleError("同步失败,费控单据编号为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "费控单据编号为空");
|
||||
return handleErrorAndReturn(apiResultExt, "费控单据编号为空");
|
||||
}
|
||||
ap_payapply.set("shjh_fkdjbh", fkBillNum);//外部系统单号
|
||||
|
||||
|
|
@ -102,13 +107,13 @@ public class ApplyBillControler {
|
|||
String companyNum = applybill.getCompanyNum();
|
||||
if (companyNum == null || companyNum.isEmpty()) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的公司编号为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "公司编号为空");
|
||||
return handleErrorAndReturn(apiResultExt, "公司编号为空");
|
||||
}
|
||||
QFilter Q3 = new QFilter("number", QCP.equals, companyNum);
|
||||
DynamicObject org = BusinessDataServiceHelper.loadSingle(orgEntName, new QFilter[]{Q3});
|
||||
if (null == org) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的组织编码不存在", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "组织编码不存在");
|
||||
return handleErrorAndReturn(apiResultExt, "组织编码不存在");
|
||||
}
|
||||
ap_payapply.set("settleorg", org); // 结算组织
|
||||
ap_payapply.set("applyorg" , org); // 申请组织
|
||||
|
|
@ -118,7 +123,7 @@ public class ApplyBillControler {
|
|||
Date bizDate = applybill.getBizDate();
|
||||
if (null == bizDate) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的申请日期为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "申请日期为空");
|
||||
return handleErrorAndReturn(apiResultExt,"申请日期为空");
|
||||
}
|
||||
ap_payapply.set("applydate", bizDate);
|
||||
//请款事由
|
||||
|
|
@ -137,14 +142,14 @@ public class ApplyBillControler {
|
|||
// 检查币别编号是否为空
|
||||
if (currencyNumber == null || currencyNumber.trim().isEmpty()) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的" + currencyTypeName + "为空", fkBillNum, Apimenthod, jsonBodyString);
|
||||
return CustomApiResult.fail("400", currencyTypeName + "为空");
|
||||
return handleErrorAndReturn(apiResultExt, currencyTypeName + "为空");
|
||||
}
|
||||
QFilter filter = new QFilter("number", QCP.equals, currencyNumber);
|
||||
DynamicObject currency = BusinessDataServiceHelper.loadSingle(BD_CURRENCY, new QFilter[]{filter});
|
||||
// 检查 currency 是否为空
|
||||
if (currency == null) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的" + currencyTypeName + "不存在", fkBillNum, Apimenthod, jsonBodyString);
|
||||
return CustomApiResult.fail("400", currencyTypeName + "不存在");
|
||||
return handleErrorAndReturn(apiResultExt,currencyTypeName + "不存在");
|
||||
}
|
||||
ap_payapply.set(currencyType, currency);
|
||||
}
|
||||
|
|
@ -175,11 +180,11 @@ public class ApplyBillControler {
|
|||
} catch (NumberFormatException e) {
|
||||
// 处理数字格式异常
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的" + fieldDesc + "格式不正确", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", fieldDesc + "格式不正确");
|
||||
return handleErrorAndReturn(apiResultExt,fieldDesc + "格式不正确");
|
||||
} catch (Exception e) {
|
||||
// 处理反射调用方法时可能出现的其他异常
|
||||
handleError("同步失败,获取费控单据编号:" + fkBillNum + "的" + fieldDesc + "时出现异常", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", fieldDesc + "格式不正确");
|
||||
return handleErrorAndReturn(apiResultExt,fieldDesc + "格式不正确");
|
||||
}
|
||||
}
|
||||
//汇率日期
|
||||
|
|
@ -189,26 +194,26 @@ public class ApplyBillControler {
|
|||
String reqdept = applybill.getReqdept();
|
||||
if (reqdept == null || reqdept.isEmpty()) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的申请部门为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "申请部门为空");
|
||||
return handleErrorAndReturn(apiResultExt,"申请部门为空");
|
||||
}
|
||||
QFilter q7 = new QFilter("number", QCP.equals, reqdept);
|
||||
DynamicObject adminorg = BusinessDataServiceHelper.loadSingle("bos_adminorg", new QFilter[]{q7});
|
||||
if (null == adminorg) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的申请部门不存在", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "申请部门不存在");
|
||||
return handleErrorAndReturn(apiResultExt,"申请部门不存在");
|
||||
}
|
||||
ap_payapply.set("shjh_secondarydept", adminorg);
|
||||
//原因码
|
||||
String causeNum = applybill.getCauseNum();
|
||||
if (causeNum == null || causeNum.isEmpty()) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的原因码为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "原因码为空");
|
||||
return handleErrorAndReturn(apiResultExt,"原因码为空");
|
||||
}
|
||||
QFilter Q7 = new QFilter("number", QCP.equals, causeNum);
|
||||
DynamicObject cause = BusinessDataServiceHelper.loadSingle(GL_CASHFLOWITEM, new QFilter[]{Q7});
|
||||
if (null == cause) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的原因码不存在", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "原因码不存在");
|
||||
return handleErrorAndReturn(apiResultExt,"原因码不存在");
|
||||
}
|
||||
ap_payapply.set("shjh_yym", cause);
|
||||
|
||||
|
|
@ -226,7 +231,7 @@ public class ApplyBillControler {
|
|||
if (asstacttype == null || asstacttype.isEmpty() ||!asstactTypeMap.containsKey(asstacttype)) {
|
||||
String errorMessage = asstacttype == null || asstacttype.isEmpty() ? "往来类型为空" : "往来类型不存在";
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的" + errorMessage, fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", errorMessage);
|
||||
return handleErrorAndReturn(apiResultExt,errorMessage);
|
||||
}
|
||||
// 根据往来类型设置值
|
||||
ap_payapply_entry.set("e_asstacttype", asstactTypeMap.get(asstacttype));
|
||||
|
|
@ -234,7 +239,7 @@ public class ApplyBillControler {
|
|||
String asstact = applybill.getAsstact();
|
||||
if (asstact == null || asstact.isEmpty()) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的往来户为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "往来户为空");
|
||||
return handleErrorAndReturn(apiResultExt,"往来户为空");
|
||||
}
|
||||
QFilter Q4 = new QFilter("number", QCP.equals, asstact);
|
||||
DynamicObject party = "供应商".equals(asstacttype)
|
||||
|
|
@ -243,41 +248,41 @@ public class ApplyBillControler {
|
|||
if (party == null) {
|
||||
String errorMessage = "同步失败,费控单据编号:" + fkBillNum + "的" + ("供应商".equals(asstacttype) ? "供应商" : "客户") + "不存在";
|
||||
handleError(errorMessage, fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", errorMessage);
|
||||
return handleErrorAndReturn(apiResultExt,errorMessage);
|
||||
}
|
||||
ap_payapply_entry.set("e_asstact", party);
|
||||
//往来账户
|
||||
String assacct = applybill.getAssacct();
|
||||
if(assacct == null || assacct.isEmpty()){
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的往来账户为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "往来账户为空");
|
||||
return handleErrorAndReturn(apiResultExt,"往来账户为空");
|
||||
}
|
||||
ap_payapply_entry.set("e_assacct", assacct);
|
||||
//往来银行
|
||||
String bebanknum = applybill.getBebankNum();
|
||||
if(bebanknum == null || bebanknum.isEmpty()){
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的联行号为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "联行号为空");
|
||||
return handleErrorAndReturn(apiResultExt,"联行号为空");
|
||||
}
|
||||
QFilter Q5 = new QFilter("number", QCP.equals, bebanknum);
|
||||
DynamicObject bank = BusinessDataServiceHelper.loadSingle(BD_BEBANK, new QFilter[]{Q5});
|
||||
if (null == bank) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的联行号对应往来银行不存在", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "联行号对应往来银行不存在");
|
||||
return handleErrorAndReturn(apiResultExt,"联行号对应往来银行不存在");
|
||||
}
|
||||
ap_payapply_entry.set("e_bebank", bank);
|
||||
//往来账户名称
|
||||
String asstactname = applybill.getAsstactName();
|
||||
if (asstactname == null || asstactname.isEmpty()) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的往来账户名称(实际收款账户名称)为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "往来账户名称(实际收款账户名称)为空");
|
||||
return handleErrorAndReturn(apiResultExt,"往来账户名称(实际收款账户名称)为空");
|
||||
}
|
||||
ap_payapply_entry.set("shjh_asstactrealname", asstactname);
|
||||
//到期日
|
||||
Date duedate = applybill.getDuedate();
|
||||
if (null == duedate) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的到期日为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "到期日为空");
|
||||
return handleErrorAndReturn(apiResultExt,"到期日为空");
|
||||
}
|
||||
ap_payapply_entry.set("e_duedate", duedate);
|
||||
|
||||
|
|
@ -290,13 +295,13 @@ public class ApplyBillControler {
|
|||
String settlementtype = applybill.getSettlementtype();
|
||||
if (settlementtype == null || settlementtype.isEmpty()) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的结算方式为空", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "结算方式为空");
|
||||
return handleErrorAndReturn(apiResultExt,"结算方式为空");
|
||||
}
|
||||
QFilter Q6 = new QFilter("name", QCP.equals, settlementtype);
|
||||
DynamicObject settlement = BusinessDataServiceHelper.loadSingle(BD_SETTLEMENTTYPE, new QFilter[]{Q6});
|
||||
if (null == settlement) {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "的结算方式不存在", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "结算方式不存在");
|
||||
return handleErrorAndReturn(apiResultExt,"结算方式不存在");
|
||||
}
|
||||
ap_payapply_entry.set("e_settlementtype", settlement);
|
||||
String remark = applybill.getRemark();//备注
|
||||
|
|
@ -368,7 +373,7 @@ public class ApplyBillControler {
|
|||
ap_payapply_entry.set("e_paymenttype", paytype_s);//对私
|
||||
}else {
|
||||
handleError("同步失败,费控单据编号:" + fkBillNum + "解析类型失败", fkBillNum, Apimenthod,jsonBodyString);
|
||||
return CustomApiResult.fail("400", "费控单据编号解析类型失败:"+fkBillNum);
|
||||
return handleErrorAndReturn(apiResultExt,"费控单据编号解析类型失败:"+fkBillNum);
|
||||
}
|
||||
/*
|
||||
---------------------------------------------------默认字段----------------------------------------------------
|
||||
|
|
@ -434,7 +439,7 @@ public class ApplyBillControler {
|
|||
OperationResult saveResult = OperationServiceHelper.executeOperate("save", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
|
||||
if (!saveResult.isSuccess()) {
|
||||
handleAndLogError(saveResult, "保存失败", fkBillNum, jsonBodyString);
|
||||
return CustomApiResult.fail("400", getFirstErrorMessage(saveResult));
|
||||
return handleErrorAndReturn(apiResultExt,getFirstErrorMessage(saveResult));
|
||||
}
|
||||
|
||||
OperationResult submitResult = OperationServiceHelper.executeOperate("submit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
|
||||
|
|
@ -442,25 +447,37 @@ public class ApplyBillControler {
|
|||
// 提交失败,将保存的数据删除,记录日志
|
||||
OperationServiceHelper.executeOperate("delete", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
|
||||
handleAndLogError(submitResult, "提交失败", fkBillNum, jsonBodyString);
|
||||
return CustomApiResult.fail("400", getFirstErrorMessage(submitResult));
|
||||
return handleErrorAndReturn(apiResultExt,getFirstErrorMessage(submitResult));
|
||||
}
|
||||
|
||||
OperationResult auditResult = OperationServiceHelper.executeOperate("audit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
|
||||
if (!auditResult.isSuccess()) {
|
||||
handleAndLogError(auditResult, "审核失败", fkBillNum, jsonBodyString);
|
||||
return CustomApiResult.fail("400", getFirstErrorMessage(auditResult));
|
||||
return handleErrorAndReturn(apiResultExt,getFirstErrorMessage(auditResult));
|
||||
}
|
||||
|
||||
log.error("审核成功,费控单据编号:" + fkBillNum);
|
||||
JhzjUtils.saveLog(fkBillNum, Apimenthod, jsonBodyString, null, true, "API");
|
||||
ApiResult customApiResult = new ApiResult("");
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
customApiResult.setHeaders(map);
|
||||
customApiResult.getHeaders().put("billno",fkBillNum);
|
||||
customApiResult.getHeaders().put("billid",""+ap_payapply.getPkValue());
|
||||
return CustomApiResult.success(customApiResult);
|
||||
apiResultExt.setErrorCode("0");
|
||||
apiResultExt.setStatus(true);
|
||||
apiResultExt.setMessage(null);
|
||||
apiResultExt.setKdPayBillID(""+ap_payapply.getPkValue());
|
||||
apiResultExt.setKdPayBillNo(ap_payapply.getString("billno"));
|
||||
return CustomApiResult.success(apiResultExt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理错误并返回失败结果
|
||||
* @return 失败的CustomApiResult对象
|
||||
*/
|
||||
public static CustomApiResult<ApiResultPayApplyExt> handleErrorAndReturn(ApiResultPayApplyExt apiResultExt, String errorMessage) {
|
||||
apiResultExt.setErrorCode("400");
|
||||
apiResultExt.setStatus(false);
|
||||
apiResultExt.setMessage(errorMessage);
|
||||
return CustomApiResult.success(apiResultExt);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理错误日志(解析操作日志)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ import kd.bos.openapi.common.custom.annotation.ApiParam;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 电子回单返回结果模型
|
||||
*/
|
||||
@ApiModel
|
||||
public class ApiResultExt implements Serializable {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
package shjh.jhzj7.fi.fi.webapi.model;
|
||||
|
||||
import kd.bos.openapi.common.custom.annotation.ApiModel;
|
||||
import kd.bos.openapi.common.custom.annotation.ApiParam;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 付款申请接口返回模型
|
||||
*/
|
||||
|
||||
@ApiModel
|
||||
public class ApiResultPayApplyExt implements Serializable {
|
||||
|
||||
@ApiParam("接口访问是否成功")
|
||||
private Boolean status;
|
||||
@ApiParam("错误码")
|
||||
private String errorCode;
|
||||
@ApiParam("接口调用错误信息")
|
||||
private String message;
|
||||
@ApiParam("金蝶付款单ID")
|
||||
private String kdPayBillID;
|
||||
@ApiParam("金蝶付款单号")
|
||||
private String kdPayBillNo;
|
||||
|
||||
public Boolean getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(String errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getKdPayBillID() {
|
||||
return kdPayBillID;
|
||||
}
|
||||
|
||||
public void setKdPayBillID(String kdPayBillID) {
|
||||
this.kdPayBillID = kdPayBillID;
|
||||
}
|
||||
|
||||
public String getKdPayBillNo() {
|
||||
return kdPayBillNo;
|
||||
}
|
||||
|
||||
public void setKdPayBillNo(String kdPayBillNo) {
|
||||
this.kdPayBillNo = kdPayBillNo;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue