105 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			105 lines
		
	
	
		
			5.1 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.entity.DynamicObjectCollection;
 | ||
| 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 tqq9.lc123.cloud.app.api.utils.ApiResultExt;
 | ||
| import tqq9.lc123.cloud.app.api.utils.Constants;
 | ||
| 
 | ||
| import java.util.ArrayList;
 | ||
| import java.util.HashMap;
 | ||
| import java.util.List;
 | ||
| 
 | ||
| 
 | ||
| /**
 | ||
|  * 应收结算记录反结算接口
 | ||
|  */
 | ||
| @ApiController(value = "ArSettleRecordController", desc = "应收结算记录api接口,自定义插件")
 | ||
| public class ArSettleRecordController {
 | ||
|     private final static Log logger = LogFactory.getLog(ArSettleRecordController.class);
 | ||
|     public static final String LC_SETTLERECORD_PROPERTIES = "id,billno,org,mainbillid,mainbillentryid,totalsettleamt,localtotalsettleamt,settlerelation,settletype,mainbilltype," +
 | ||
|             "exchangerate,settledate,corebillid,corebillentryid,settleentry,billentity,billstatus,isvoucher,entry.billtype,entry.currency,entry.settleamt,entry.billid,entry.billentryid," +
 | ||
|             "entry.e_exchangerate,entry.billnum,e_settleentry,iswrittenoff,hadwrittenoff,e_hadwrittenoff,e_billentity,settleseq,mainpayableamt,entry.payableamt,entry.localsettleamt,autosettletype"; //应收结算记录
 | ||
| 
 | ||
| 
 | ||
|     @ApiPostMapping(value = "/ArSettleRecord_Unsettle", desc = "应收结算记录反结算api接口")
 | ||
|     public CustomApiResult<ApiResultExt> LC_ArSettleRecord_Unsettle
 | ||
|             (@NotNull @ApiParam(value = "入参", example = "") ArrayList<String> data) {
 | ||
| 
 | ||
| 
 | ||
|         List<ApiResultExt.ResultBean> results = new ArrayList<>();
 | ||
|         ApiResultExt resultExt = new ApiResultExt();
 | ||
|         QFilter qFilter = new QFilter("entry.billnum", QCP.in, data);
 | ||
|         qFilter.and("billstatus", QCP.equals, "C");
 | ||
|         DynamicObject[] ar_settlerecords = BusinessDataServiceHelper.load(Constants.AR_SETTLERECORD, LC_SETTLERECORD_PROPERTIES, qFilter.toArray());
 | ||
|         HashMap<String,String> map=new HashMap<String,String>();
 | ||
|         for (DynamicObject ar_settlerecord : ar_settlerecords) {
 | ||
|             DynamicObjectCollection entry = ar_settlerecord.getDynamicObjectCollection("entry");
 | ||
|             for (DynamicObject dynamicObject : entry) {
 | ||
|                 map.put(dynamicObject.getString("billnum"),ar_settlerecord.getString("id"));
 | ||
|             }
 | ||
|         }
 | ||
|         Integer index=0;
 | ||
|         for (int i = 0; i < data.size(); i++) {
 | ||
|             String billno = data.get(i);
 | ||
|             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_UNSETTLE);
 | ||
|             if(map.containsKey(billno)){
 | ||
|                 resultBean.setId(map.get(billno));
 | ||
|                 resultBean.setBillStatus(true);
 | ||
|             }else{
 | ||
|                 ArrayList<String> rowMsg = error.getRowMsg();
 | ||
|                 rowMsg.add("根据传入编号:"+billno+"未找到对应结算记录,请核销后再进行反核销");
 | ||
|                 error.setRowMsg(rowMsg);
 | ||
|                 error.setEntityKey(Constants.AR_SETTLERECORD);
 | ||
|                 error.setKeys(keys);
 | ||
|                 resultBean.setId("");
 | ||
|                 resultBean.setBillStatus(false);
 | ||
|                 index++;
 | ||
|             }
 | ||
|             resultBean.setErrors(error);
 | ||
|             results.add(resultBean);
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         OperateOption option = OperateOption.create();
 | ||
|         OperationResult unsettleResult = OperationServiceHelper.executeOperate(Constants.TYPE_UNSETTLE, Constants.AR_SETTLERECORD, ar_settlerecords, option);
 | ||
|         List<IOperateInfo> allErrorOrValidateInfo = unsettleResult.getAllErrorOrValidateInfo();
 | ||
|         if (!allErrorOrValidateInfo.isEmpty()) {
 | ||
|             index++;
 | ||
|         }
 | ||
|         for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
 | ||
|             HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, Constants.AR_SETTLERECORD);
 | ||
|             results= (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
 | ||
|         }
 | ||
|         int failCount = index;//失败数量
 | ||
|         int successCount = data.size() - index;//成功数量
 | ||
|         resultExt.setFailCount(failCount);
 | ||
|         resultExt.setSuccessCount(successCount);
 | ||
|         resultExt.setResult(results);
 | ||
|         return CustomApiResult.success(resultExt);
 | ||
|     }
 | ||
| }
 | ||
| 
 |