169 lines
		
	
	
		
			9.8 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			169 lines
		
	
	
		
			9.8 KiB
		
	
	
	
		
			Java
		
	
	
	
| 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.utils.StringUtils;
 | ||
| import kd.bos.entity.operate.result.IOperateInfo;
 | ||
| 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.*;
 | ||
| 
 | ||
| 
 | ||
| /**
 | ||
|  * 付款单状态变更api接口
 | ||
|  */
 | ||
| @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, JSONObject> 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);
 | ||
|             JSONObject jsonObject = new JSONObject();
 | ||
|             jsonObject.put("billstatus",dataMap.get("billstatus"));
 | ||
|             jsonObject.put("tqq9_digital_receipt",dataMap.get("tqq9_digital_receipt"));
 | ||
|             billStatusMap.put(billno, jsonObject);
 | ||
|         }
 | ||
|         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"))) {
 | ||
|                     String billstatus = cas_paybill.getString("billstatus");
 | ||
|                     if(!StringUtils.equals("C",billstatus)){
 | ||
|                         ArrayList<String> rowMsg = error.getRowMsg();
 | ||
|                         rowMsg.add("传入编号:" + billno + "的单据状态非已审核,无法变更");
 | ||
|                         error.setRowMsg(rowMsg);
 | ||
|                         error.setEntityKey(Constants.CAS_PAYBILL);
 | ||
|                         error.setKeys(keys);
 | ||
|                         resultBean.setId("");
 | ||
|                         resultBean.setBillStatus(false);
 | ||
|                         index++;
 | ||
|                     }
 | ||
|                     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"))){
 | ||
| //                        ArrayList<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) {
 | ||
|                 ArrayList<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) {
 | ||
|             JSONObject json = billStatusMap.get(cas_paybill.getString("billno"));
 | ||
|             String billstatus = json.getString("billstatus");
 | ||
|             String tqq9_digital_receipt = json.getString("tqq9_digital_receipt");
 | ||
|             if (StringUtils.equals("D", billstatus)) {
 | ||
|                 OperationResult payResult = OperationServiceHelper.executeOperate(Constants.TYPE_PAY, Constants.CAS_PAYBILL, new DynamicObject[]{cas_paybill}, option);
 | ||
|                 List<IOperateInfo> allErrorOrValidateInfo = payResult.getAllErrorOrValidateInfo();
 | ||
|                 if (!payResult.isSuccess()) {
 | ||
|                     index++;
 | ||
|                     for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
 | ||
|                         HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, Constants.CAS_PAYBILL);
 | ||
|                         results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
 | ||
|                     }
 | ||
|                 }else{
 | ||
|                     cas_paybill.set("tqq9_digital_receipt", tqq9_digital_receipt);
 | ||
|                     SaveServiceHelper.save(new DynamicObject[]{cas_paybill});
 | ||
| 
 | ||
|                 }
 | ||
|             } else if (StringUtils.equals("F", billstatus) ) {
 | ||
|                 cas_paybill.set("billstatus", "F");
 | ||
|                 SaveServiceHelper.save(new DynamicObject[]{cas_paybill});
 | ||
|             } else if (StringUtils.equals("E", billstatus)) {
 | ||
|                 cas_paybill.set("billstatus", "E");
 | ||
|                 SaveServiceHelper.save(new DynamicObject[]{cas_paybill});
 | ||
|             } else if (StringUtils.equals("G", 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);
 | ||
|     }
 | ||
| }
 | ||
| 
 |