lc/lc123/cloud/app/api/controller/CasPaybillController.java

158 lines
9.3 KiB
Java
Raw Normal View History

2025-08-12 05:18:29 +00:00
package tqq9.lc123.cloud.app.api.controller;
import com.alibaba.fastjson.JSONObject;
import com.drew.lang.annotations.NotNull;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.operate.result.IOperateInfo;
import kd.bos.entity.operate.result.OperateInfo;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.openapi.common.custom.annotation.ApiController;
import kd.bos.openapi.common.custom.annotation.ApiParam;
import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
import kd.bos.openapi.common.result.CustomApiResult;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import tqq9.lc123.cloud.app.api.utils.ApiResultExt;
import tqq9.lc123.cloud.app.api.utils.Constants;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 应收结算记录反结算接口
*/
@ApiController(value = "CasPaybillController", desc = "付款单api接口自定义插件")
public class CasPaybillController {
public static final String LC_PAYBILL_PROPERTIES = "billno,id,billstatus,bizdate,billtype,paymenttype,payeetype,description,issingle,org,payeracctcash,payeracctbank,payerbank," +
"payee,payeeformid,payeename,payeeaccformid,payeeacctbank,payeebanknum,payeebank,payeebankname,actpayamt,currency,exchangerate,localamt,settletype,settletnumber,fundflowitem,usage," +
"expectdate,reccountry,recprovince,reccity,recaccbankname,recbanknumber,sourcetype,sourcebilltype,sourcebillid,cashier,paydate,bankcheckflag,bankcheckflag_tag,entrance,entrustorg," +
"applyorg,e_actamt,e_localamt,e_fundflowitem,e_remark,e_payableAmt,e_payablelocamt,e_discountamt,e_discountlocamt,e_sourcebillentryid,e_unsettledamt,e_settledamt,e_unsettledlocalamt," +
"e_unlockamt,e_material,e_expenseitem,e_corebillno,e_corebillentryseq,e_sourcebillid,e_corebillid,e_corebillentryid,e_corebilltype,conbillid,conbillentryid,settleorg,paymentchannel," +
"payeetype,payee,isvoucher,isdiffcur,dpamt,agreedrate,fee,dpcurrency,iscrosspay,dplocalamt,dpexchangerate,feecurrency,feeactbank,lossamt,draftbill,exratetable,exratedate,inneraccount," +
"acttradedate,feepayer,createtime,payeeacctcash,openorg,totalpayamt,payquotation,dppayquotation,agreedquotation,settletype,settletype.settlementtype,settletnumber,singlestream,basecurrency," +
"paymentidentify,feepaydate,feepay,matchamountpay,unmatchamountpay,unmatchamountrec,matchamountrec,matchflag,bizdate,auditdate,sourcebilltype,entry,entry.e_sourcebillid,cas_draftinfo.draftbillinfo," +
"cas_draftinfo.transamount,cas_draftinfo.draftbilllogid,entry.e_scheid,cas_draftinfo.srcbillindex,cas_draftinfo.paybillcurrency,entry.e_dpamt,tqq9_digital_receipt,tqq9_billstatus,iswaitsche,priority,changestatus," +
"istop,entry.e_refundamt,entry.e_remainrefundamt,totalrefundedamt,totalremainrefundamt,localrefundedamt,localremainrefundamt"; //应收结算记录
private final static Log logger = LogFactory.getLog(CasPaybillController.class);
@ApiPostMapping(value = "/CasPaybill_StatusChange", desc = "付款单状态变更api接口")
public CustomApiResult<ApiResultExt> LC_CasPaybill_StatusChange
(@NotNull @ApiParam(value = "入参", example = "") List<HashMap<String, Object>> data) throws ParseException {
List<ApiResultExt.ResultBean> results = new ArrayList<>();
ApiResultExt resultExt = new ApiResultExt();
List<String> billnos = new ArrayList<>();
HashMap<String, String> billStatusMap = new HashMap<>();
HashMap<String, String> billIdMap = new HashMap<>();
Set<String> validValues = new HashSet<>();
validValues.add("4");
validValues.add("5");
validValues.add("6");
validValues.add("7");
validValues.add("8");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // 目标日期格式
for (int i = 0; i < data.size(); i++) {
HashMap<String, Object> dataMap = data.get(i);
String billno = (String) dataMap.get("billno");
billnos.add(billno);
billStatusMap.put(billno, (String) dataMap.get("billstatus"));
}
QFilter qFilter = new QFilter("billno", QCP.in, billnos);
DynamicObject[] cas_paybills = BusinessDataServiceHelper.load(Constants.CAS_PAYBILL, LC_PAYBILL_PROPERTIES, qFilter.toArray());
Integer index = 0;
for (int i = 0; i < data.size(); i++) {
HashMap<String, Object> dataMap = data.get(i);
String billno = (String) dataMap.get("billno");
JSONObject keys = new JSONObject();
keys.put("billno", billno);
ApiResultExt.ResultBean resultBean = new ApiResultExt.ResultBean();
ApiResultExt.Error error = new ApiResultExt.Error();
error.setRowMsg(new ArrayList<String>());
resultBean.setBillIndex(i);
resultBean.setKeys(keys);
resultBean.setNumber(billno);
resultBean.setType(Constants.TYPE_UPDATE);
Boolean iserror = true;
for (DynamicObject cas_paybill : cas_paybills) {
if (billno.equals(cas_paybill.getString("billno"))) {
Date bizdate = dateFormat.parse(dataMap.get("bizdate").toString());
// cas_paybill.set("bizdate", bizdate);
// cas_paybill.set("openorg.number", dataMap.get("openorg_number"));
// cas_paybill.set("settletype.number", dataMap.get("settletype_number"));
// cas_paybill.set("payeracctbank.number", dataMap.get("bankaccountnumber"));
// cas_paybill.set("tqq9_billstatus", dataMap.get("billstatus"));
cas_paybill.set("description", dataMap.get("description"));
cas_paybill.set("tqq9_digital_receipt", dataMap.get("tqq9_digital_receipt"));
resultBean.setId(cas_paybill.getString("id"));
resultBean.setBillStatus(true);
iserror = false;
if(!validValues.contains((String)dataMap.get("billstatus"))){
List<String> rowMsg = error.getRowMsg();
rowMsg.add("传入编号:" + billno + "的交易状态有误");
error.setRowMsg(rowMsg);
error.setEntityKey(Constants.CAS_PAYBILL);
error.setKeys(keys);
resultBean.setId("");
resultBean.setBillStatus(false);
index++;
}
}
}
if (iserror) {
List<String> rowMsg = error.getRowMsg();
rowMsg.add("根据传入编号:" + billno + "未找到对应付款单");
error.setRowMsg(rowMsg);
error.setEntityKey(Constants.CAS_PAYBILL);
error.setKeys(keys);
resultBean.setId("");
resultBean.setBillStatus(false);
index++;
}
resultBean.setErrors(error);
results.add(resultBean);
}
OperateOption option = OperateOption.create();
for (DynamicObject cas_paybill : cas_paybills) {
String billstatus = billStatusMap.get(cas_paybill.getString("billno"));
if (StringUtils.equals("5", billstatus)) {
// cas_paybill.set("billstatus", "D");
OperationResult payResult = OperationServiceHelper.executeOperate(Constants.TYPE_PAY, Constants.CAS_PAYBILL, new DynamicObject[]{cas_paybill}, option);
List<IOperateInfo> allErrorOrValidateInfo = payResult.getAllErrorOrValidateInfo();
if (!allErrorOrValidateInfo.isEmpty()) {
index++;
}
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, Constants.CAS_PAYBILL);
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
}
} else if (StringUtils.equals("4", billstatus) || StringUtils.equals("6", billstatus)) {
cas_paybill.set("billstatus", "F");
SaveServiceHelper.save(new DynamicObject[]{cas_paybill});
} else if (StringUtils.equals("7", billstatus)) {
cas_paybill.set("billstatus", "E");
SaveServiceHelper.save(new DynamicObject[]{cas_paybill});
} else if (StringUtils.equals("8", billstatus)) {
cas_paybill.set("billstatus", "G");
SaveServiceHelper.save(new DynamicObject[]{cas_paybill});
}
}
int failCount = index;//失败数量
int successCount = data.size() - index;//成功数量
resultExt.setFailCount(failCount);
resultExt.setSuccessCount(successCount);
resultExt.setResult(results);
return CustomApiResult.success(resultExt);
}
}