管理员收款红冲
This commit is contained in:
		
							parent
							
								
									55cf7f477b
								
							
						
					
					
						commit
						849e7f555b
					
				|  | @ -0,0 +1,166 @@ | ||||||
|  | package shjh.jhzj7.fi.fi.plugin.operate; | ||||||
|  | 
 | ||||||
|  | import com.alibaba.fastjson.JSONArray; | ||||||
|  | import com.alibaba.fastjson.JSONObject; | ||||||
|  | import kd.bos.context.RequestContext; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObject; | ||||||
|  | import kd.bos.entity.operate.result.OperateErrorInfo; | ||||||
|  | import kd.bos.entity.plugin.AbstractOperationServicePlugIn; | ||||||
|  | import kd.bos.entity.plugin.args.AfterOperationArgs; | ||||||
|  | import kd.bos.entity.plugin.args.BeforeOperationArgs; | ||||||
|  | import kd.bos.logging.Log; | ||||||
|  | import kd.bos.logging.LogFactory; | ||||||
|  | import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||||
|  | import kd.bos.servicehelper.operation.SaveServiceHelper; | ||||||
|  | import kd.sdk.plugin.Plugin; | ||||||
|  | import shjh.jhzj7.fi.fi.utils.ApiUtils; | ||||||
|  | import shjh.jhzj7.fi.fi.utils.EsbUtils; | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.text.SimpleDateFormat; | ||||||
|  | import java.util.*; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 单据操作插件 | ||||||
|  |  * 收款处理管理员红冲接口 | ||||||
|  |  */ | ||||||
|  | public class AdminRedPushOperation extends AbstractOperationServicePlugIn implements Plugin { | ||||||
|  |     private final static Log logger = LogFactory.getLog(AdminRedPushOperation.class); | ||||||
|  |     private static final String userName = "bos_user";//用户 | ||||||
|  |     private static final String INTERFACE_ID = "ReversalVoucher";//识别被调接口并进行路由-SAP反清账 | ||||||
|  |     private static final String RECEIVER_ID = "SAP";//定义的发送者 | ||||||
|  |     private static final String API_URL = System.getProperty("url_a");//sap相关接口地址 | ||||||
|  |     private static final String KEY_ADMIN_RED_PUSH = "adminredpush";//sap红冲凭证的操作标记 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void beforeExecuteOperationTransaction(BeforeOperationArgs e) { | ||||||
|  |         super.beforeExecuteOperationTransaction(e); | ||||||
|  |         String eok = e.getOperationKey(); | ||||||
|  |         if(KEY_ADMIN_RED_PUSH.equals(eok)){ | ||||||
|  |             //sap凭证红冲处理 前置校验 | ||||||
|  |             DynamicObject[] dos = e.getDataEntities(); | ||||||
|  |             DynamicObject prinfo; | ||||||
|  |             for (int i = 0; i < dos.length; i++) { | ||||||
|  |                 prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName()); | ||||||
|  |                 //判断收款处理单是否已生成金蝶凭证 | ||||||
|  |                 if(!prinfo.getBoolean("isvoucher")){ | ||||||
|  |                     e.setCancelMessage(prinfo.getString("billno") + "未生成金蝶凭证,无法推送SAP红冲凭证"); | ||||||
|  |                     e.setCancel(true); | ||||||
|  |                 }else if(!prinfo.getBoolean("shjh_ispushsap")){ | ||||||
|  |                     e.setCancelMessage(prinfo.getString("billno") + "未推送过SAP,无需红冲"); | ||||||
|  |                     e.setCancel(true); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void afterExecuteOperationTransaction(AfterOperationArgs e) { | ||||||
|  |         super.afterExecuteOperationTransaction(e); | ||||||
|  |         String eok = e.getOperationKey(); | ||||||
|  |         if(KEY_ADMIN_RED_PUSH.equals(eok)){ | ||||||
|  |             //sap凭证红冲处理 | ||||||
|  |             DynamicObject[] dos = e.getDataEntities(); | ||||||
|  |             DynamicObject prinfo = null;//收款处理单 | ||||||
|  |             JSONObject sapReturnData; | ||||||
|  |             String billNumber; | ||||||
|  |             StringBuilder message = new StringBuilder(); | ||||||
|  |             for (int i = 0; i < dos.length; i++) { | ||||||
|  |                 prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName()); | ||||||
|  |                 if(prinfo.getBoolean("shjh_ispushsap")){ | ||||||
|  |                     //如果收款处理单已推送sap才需要红冲 | ||||||
|  |                     billNumber = prinfo.getString("billno");//单号 | ||||||
|  |                     HashMap<String, String> responseHead = ApiUtils.buildHead(INTERFACE_ID,RECEIVER_ID); | ||||||
|  |                     HashMap<String, Object> responseBody = this.assembleRequest(billNumber, prinfo, message); | ||||||
|  |                     try { | ||||||
|  |                         String response = ApiUtils.sendPost(responseHead, responseBody, API_URL); | ||||||
|  |                         if (!EsbUtils.isEmpty(response)) { | ||||||
|  |                             boolean success = ApiUtils.parseResponse(response, billNumber, responseBody, "SAP反清账或冲销", message); | ||||||
|  |                             if (success){ | ||||||
|  |                                 //sap红冲凭证成功,反写sap凭证号和推送标记 | ||||||
|  |                                 sapReturnData = JSONObject.parseObject(response); | ||||||
|  |                                 JSONObject data = sapReturnData.getJSONObject("data"); | ||||||
|  |                                 JSONArray rows = data.getJSONArray("IT_ITEM"); | ||||||
|  |                                 JSONObject resultData = rows.getJSONObject(0); | ||||||
|  |                                 String key = resultData.getString("OBJ_KEY"); | ||||||
|  |                                 if(EsbUtils.isEmpty(key)){ | ||||||
|  |                                     message.append("收款处理【").append(billNumber).append("】:").append("SAP返回的OBJ_KEY为空").append("\n"); | ||||||
|  |                                 }else{ | ||||||
|  |                                     //sap红冲凭证号根据返回值更新 | ||||||
|  |                                     prinfo.set("shjh_adminrednum",key.length() >= 10 ? key.substring(0, 10) : key); | ||||||
|  |                                     prinfo.set("shjh_ispushsap",false);//sap已推送标记-置为false,让后续可以再推蓝字凭证 | ||||||
|  |                                     prinfo.set("shjh_vouchernum",null);//sap凭证号置为空 | ||||||
|  |                                     prinfo.set("shjh_sapfiscalyear",null);//sap年度置为空 | ||||||
|  |                                     SaveServiceHelper.update(prinfo); | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         }else{ | ||||||
|  |                             message.append("收款处理【").append(billNumber).append("】:").append("SAP返回值为空").append("\n"); | ||||||
|  |                         } | ||||||
|  |                     } catch (IOException ex) { | ||||||
|  |                         message.append("收款处理【").append(billNumber).append("】:").append(ex.getMessage()).append("\n"); | ||||||
|  |                         logger.info("调用收款红冲凭证接口异常"+message); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             if (message.length() != 0){ | ||||||
|  |                 OperateErrorInfo operateErrorInfo = new OperateErrorInfo(); | ||||||
|  |                 operateErrorInfo.setMessage(String.valueOf(message)); | ||||||
|  |                 operateErrorInfo.setErrorLevel(kd.bos.entity.validate.ErrorLevel.Error.name()); | ||||||
|  |                 operateErrorInfo.setPkValue(prinfo.getPkValue()); | ||||||
|  |                 this.operationResult.addErrorInfo(operateErrorInfo); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 请求头组装 | ||||||
|  |      * @param billNumber 单据编号 | ||||||
|  |      * @param recBill  下拨处理 | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     private HashMap<String, Object> assembleRequest(String billNumber, DynamicObject recBill, StringBuilder message){ | ||||||
|  |         HashMap<String, Object> responseBody = null; | ||||||
|  |         try { | ||||||
|  |             // 生成唯一事务ID | ||||||
|  |             String rootContextId = UUID.randomUUID().toString(); | ||||||
|  |             // 获取当前请求时间,格式为 yyyy-MM-dd HH:mm:ss.SSS | ||||||
|  |             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | ||||||
|  |             String requestTime = sdf.format(new Date()); | ||||||
|  |             responseBody = new HashMap<>(5); | ||||||
|  |             responseBody.put("rootContextID", rootContextId); | ||||||
|  |             responseBody.put("requestTime", requestTime); | ||||||
|  |             HashMap<String, Object> data = new HashMap<>(1); | ||||||
|  |             List<Map<String, Object>> IT_ITEM = new ArrayList<>(1); | ||||||
|  |             //用户名-从红冲单上获取人员,当前操作人可能是定时任务 | ||||||
|  |             DynamicObject userinfo = BusinessDataServiceHelper.loadSingleFromCache(RequestContext.get().getCurrUserId(), userName); | ||||||
|  |             String oaUser = userinfo.getString("shjh_oauser"); | ||||||
|  |             //冲销原因 | ||||||
|  |             Map<String, Object> IT_ITEMS = new HashMap<>(6); | ||||||
|  |             //红冲所需参数从红字下拨单上获取,红单上保留了原蓝字下拨单的凭证号和会计年度 | ||||||
|  |             IT_ITEMS.put("BELNR",recBill.getString("shjh_vouchernum"));//会计凭证编号 | ||||||
|  |             IT_ITEMS.put("BUKRS",recBill.getString("org.number"));//公司代码 | ||||||
|  |             IT_ITEMS.put("GJAHR",recBill.getString("shjh_sapfiscalyear"));//会计年度 | ||||||
|  |             IT_ITEMS.put("STGRD","04");//冲销原因 跨期冲销;默认04,冲销日期必传 | ||||||
|  |             if(EsbUtils.isEmpty(oaUser)){ | ||||||
|  |                 IT_ITEMS.put("UNAME","资金系统");//用户名 | ||||||
|  |             }else{ | ||||||
|  |                 IT_ITEMS.put("UNAME",oaUser);//用户名 | ||||||
|  |             } | ||||||
|  |             SimpleDateFormat sdfdate = new SimpleDateFormat("yyyy-MM-dd"); | ||||||
|  |             if(recBill.getDate("bookdate") == null){ | ||||||
|  |                 IT_ITEMS.put("BUDAT",sdfdate.format(new Date()));//凭证中的过帐日期 | ||||||
|  |             }else { | ||||||
|  |                 IT_ITEMS.put("BUDAT",sdfdate.format(recBill.getDate("bookdate")));//凭证中的过帐日期 | ||||||
|  |             } | ||||||
|  |             IT_ITEM.add(IT_ITEMS); | ||||||
|  |             data.put("IT_ITEM", IT_ITEM); | ||||||
|  |             responseBody.put("data", data); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             message.append("收款处理【").append(billNumber).append("】:").append(e.getMessage()).append("\n"); | ||||||
|  |             EsbUtils.saveLog(billNumber, INTERFACE_ID, null, e.getMessage(), false, KEY_ADMIN_RED_PUSH, "数据异常"); | ||||||
|  |         } | ||||||
|  |         return responseBody; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -614,6 +614,7 @@ public class RecBillSaveOperation extends AbstractOperationServicePlugIn impleme | ||||||
|         QFilter qFilter = new QFilter("shjh_dfhm", QCP.equals, oppunit); |         QFilter qFilter = new QFilter("shjh_dfhm", QCP.equals, oppunit); | ||||||
|         //新增收款入账中心-资金组织&&映射表组织过滤 |         //新增收款入账中心-资金组织&&映射表组织过滤 | ||||||
|         qFilter.and(new QFilter("shjh_org.id", QCP.equals, companyId)); |         qFilter.and(new QFilter("shjh_org.id", QCP.equals, companyId)); | ||||||
|  |         qFilter.and(new QFilter("enable", QCP.equals, "1")); | ||||||
|         //对方户名与客户名称映射表 shjh_dfhmcust |         //对方户名与客户名称映射表 shjh_dfhmcust | ||||||
|         DynamicObject shjhDfhmcust = BusinessDataServiceHelper.loadSingle("shjh_dfhmcust", qFilter.toArray()); |         DynamicObject shjhDfhmcust = BusinessDataServiceHelper.loadSingle("shjh_dfhmcust", qFilter.toArray()); | ||||||
|         if (null != shjhDfhmcust) { |         if (null != shjhDfhmcust) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue