| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  | package tqq9.lc123.cloud.app.api.controller;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  | import com.alibaba.fastjson.JSONObject;
 | 
					
						
							| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  | import com.drew.lang.annotations.NotNull;
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  | import kd.bos.dataentity.OperateOption;
 | 
					
						
							|  |  |  | import kd.bos.dataentity.entity.DynamicObject;
 | 
					
						
							|  |  |  | import kd.bos.entity.operate.result.IOperateInfo;
 | 
					
						
							|  |  |  | import kd.bos.entity.operate.result.OperationResult;
 | 
					
						
							| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  | 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;
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  | import kd.bos.orm.query.QFilter;
 | 
					
						
							|  |  |  | import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
					
						
							|  |  |  | import kd.bos.servicehelper.operation.OperationServiceHelper;
 | 
					
						
							|  |  |  | import kd.bos.servicehelper.operation.SaveServiceHelper;
 | 
					
						
							| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  | import tqq9.lc123.cloud.app.api.model.FWBillStateUpdModel;
 | 
					
						
							|  |  |  | import tqq9.lc123.cloud.app.api.utils.ApiResultExt;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import java.util.ArrayList;
 | 
					
						
							|  |  |  | import java.util.List;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @ApiController(value = "FWBillStateUpdController", desc = "泛微-单据状态更新接口")
 | 
					
						
							|  |  |  | public class FWBillStateUpdController {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @ApiPostMapping(value = "/FWBillUpd", desc = "泛微-单据状态更新api接口")
 | 
					
						
							|  |  |  |     public CustomApiResult<ApiResultExt> billUpd
 | 
					
						
							|  |  |  |             (@NotNull @ApiParam(value = "入参", example = "") FWBillStateUpdModel model) {
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  |         String KDBillNumber = model.getKDBillNumber();
 | 
					
						
							|  |  |  |         String KDBillType = model.getKDBillType();
 | 
					
						
							|  |  |  |         int state = model.getState();
 | 
					
						
							|  |  |  |         String message = model.getMessage();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  |         ApiResultExt resultExt = new ApiResultExt();
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  |         ApiResultExt.Error errors = new ApiResultExt.Error();
 | 
					
						
							|  |  |  |         ArrayList<String> errorList = new ArrayList<>();
 | 
					
						
							| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  |         List<ApiResultExt.ResultBean> results = new ArrayList<>();
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  |         ApiResultExt.ResultBean resultBean = new ApiResultExt.ResultBean();
 | 
					
						
							|  |  |  |         resultBean.setBillStatus(true);
 | 
					
						
							|  |  |  |         resultBean.setBillIndex(0);
 | 
					
						
							|  |  |  |         resultBean.setNumber(KDBillNumber);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         DynamicObject approveLog = BusinessDataServiceHelper.newDynamicObject("tqq9_fwapprovelog");
 | 
					
						
							|  |  |  |         approveLog.set("name", KDBillType);
 | 
					
						
							|  |  |  |         approveLog.set("tqq9_billno", KDBillNumber);
 | 
					
						
							|  |  |  |         approveLog.set("tqq9_returnstring_tag", JSONObject.toJSONString(model));
 | 
					
						
							|  |  |  |         approveLog.set("tqq9_message", message);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //校验单据标识是否正确
 | 
					
						
							|  |  |  |         QFilter f1 = new QFilter("number", "=", KDBillType);
 | 
					
						
							|  |  |  |         DynamicObject[] bos_entityobjects = BusinessDataServiceHelper.load("bos_entityobject", "id,name,number,modeltype", new QFilter[]{f1});
 | 
					
						
							|  |  |  |         if(bos_entityobjects == null && bos_entityobjects.length == 0){
 | 
					
						
							|  |  |  |             errorList.add("参数KDBillType["+KDBillType+"]不是正确的标识");
 | 
					
						
							|  |  |  |         }else{
 | 
					
						
							|  |  |  |             DynamicObject bosEntity = bos_entityobjects[0];
 | 
					
						
							|  |  |  |             String modeltype = bosEntity.getString("modeltype");
 | 
					
						
							|  |  |  |             String enetityNumber = bosEntity.getString("number");
 | 
					
						
							|  |  |  |             String enetityName = bosEntity.getString("name");
 | 
					
						
							|  |  |  |             String billNoFieldName = "billno";
 | 
					
						
							|  |  |  |             if("BaseFormModel".equals(modeltype) || "gl_voucher".equals(enetityNumber)){
 | 
					
						
							|  |  |  |                 billNoFieldName = "number";
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             //查询对应的安居
 | 
					
						
							|  |  |  |             QFilter qf1 = new QFilter(billNoFieldName, "=", KDBillNumber);
 | 
					
						
							|  |  |  |             DynamicObject[] billArr = BusinessDataServiceHelper.load(enetityNumber, "id,tqq9_issuccess", new QFilter[]{qf1});
 | 
					
						
							|  |  |  |             if(billArr != null && billArr.length > 0){
 | 
					
						
							|  |  |  |                 boolean isSuccess = false;
 | 
					
						
							|  |  |  |                 if(state == 0){
 | 
					
						
							|  |  |  |                     isSuccess = true;
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |                 billArr[0].set("tqq9_issuccess", isSuccess);
 | 
					
						
							|  |  |  |                 SaveServiceHelper.save(new DynamicObject[]{billArr[0]});
 | 
					
						
							| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  |                 approveLog.set("tqq9_issuccess", isSuccess);
 | 
					
						
							|  |  |  |                 approveLog.set("tqq9_entityname", enetityName);
 | 
					
						
							|  |  |  |                 OperationResult operationResult = OperationServiceHelper.executeOperate("save", "tqq9_fwapprovelog", new DynamicObject[]{approveLog}, OperateOption.create());
 | 
					
						
							| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  |                 if(isSuccess){
 | 
					
						
							|  |  |  |                     OperationResult submitResult = OperationServiceHelper.executeOperate("submit", enetityNumber, new DynamicObject[]{billArr[0]}, OperateOption.create());
 | 
					
						
							|  |  |  |                     if(!submitResult.isSuccess()){
 | 
					
						
							|  |  |  |                         List<IOperateInfo> allErrorOrValidateInfo = submitResult.getAllErrorOrValidateInfo();
 | 
					
						
							|  |  |  |                         for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
 | 
					
						
							|  |  |  |                             errorList.add(enetityName+"审核时否生错误:"+iOperateInfo.getMessage());
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                     }
 | 
					
						
							| 
									
										
										
										
											2025-10-17 07:47:32 +00:00
										 |  |  |                 }else{
 | 
					
						
							|  |  |  |                     OperationResult submitResult = OperationServiceHelper.executeOperate("unsubmit", enetityNumber, new DynamicObject[]{billArr[0]}, OperateOption.create());
 | 
					
						
							|  |  |  |                     if(!submitResult.isSuccess()){
 | 
					
						
							|  |  |  |                         List<IOperateInfo> allErrorOrValidateInfo = submitResult.getAllErrorOrValidateInfo();
 | 
					
						
							|  |  |  |                         for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
 | 
					
						
							|  |  |  |                             errorList.add(enetityName+"撤销时发生错误:"+iOperateInfo.getMessage());
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                     }
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  |                 }
 | 
					
						
							|  |  |  |             }else{
 | 
					
						
							|  |  |  |                 errorList.add("根据参数KDBillType["+KDBillType+"]。KDBillNumber["+KDBillNumber+"]没有查询到对应的"+enetityName+"信息");
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |         if(errorList.size() > 0){
 | 
					
						
							|  |  |  |             resultBean.setBillStatus(false);
 | 
					
						
							|  |  |  |             errors.setRowMsg(errorList);
 | 
					
						
							|  |  |  |             resultBean.setErrors(errors);
 | 
					
						
							| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-16 07:56:42 +00:00
										 |  |  |             resultExt.setFailCount(1);
 | 
					
						
							|  |  |  |             resultExt.setSuccessCount(0);
 | 
					
						
							|  |  |  |         }else{
 | 
					
						
							|  |  |  |             resultExt.setFailCount(0);
 | 
					
						
							|  |  |  |             resultExt.setSuccessCount(1);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |         results.add(resultBean);
 | 
					
						
							| 
									
										
										
										
											2025-08-19 06:54:53 +00:00
										 |  |  |         resultExt.setResult(results);
 | 
					
						
							|  |  |  |         return CustomApiResult.success(resultExt);
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | }
 |