package com.engine.tjyh.xc.cmd; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; import com.api.browser.bean.BrowserValueInfo; import com.api.browser.service.BrowserValueInfoService; import com.engine.common.biz.AbstractCommonCommand; import com.engine.common.entity.BizLogContext; import com.engine.core.interceptor.CommandContext; import com.engine.tjyh.xc.util.HttpRequestUtil; import com.engine.tjyh.xc.util.WorkflowCreateHandler; import okhttp3.*; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSet; import weaver.general.BaseBean; import weaver.general.TimeUtil; import weaver.general.Util; import weaver.workflow.workflow.WorkflowBillComInfo; import weaver.workflow.workflow.WorkflowComInfo; import weaver.workflow.workflow.WorkflowVersion; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.BigDecimal; import java.net.HttpURLConnection; import java.net.URL; import java.util.*; /** * @Description * @Author matrix * @Date 2023/6/15 10:09 **/ public class XcCmd extends AbstractCommonCommand> { public XcCmd(JSONObject params) { this.params = params; } @Override public BizLogContext getLogContext() { return null; } @Override public Map execute(CommandContext commandContext) { HttpRequestUtil httpRequestUtil = HttpRequestUtil.getInstance(); RecordSet rs = new RecordSet(); BaseBean bb = new BaseBean(); Map apimap = new HashMap(); writeLog("XcCmd--------:"+params); String appKey = bb.getPropValue("tjyhxcjc","appKey"); String appSecurity = bb.getPropValue("tjyhxcjc","appSecurity"); String url = bb.getPropValue("tjyhxcjc","url"); String orderurl = bb.getPropValue("tjyhxcjc","orderurl"); String workflowId = bb.getPropValue("tjyhxcjc","workflowId"); Map map= new HashMap<>(); map.put("appKey",appKey); map.put("appSecurity",appSecurity); String input = JSON.toJSONString(map); writeLog("input="+input); String back = httpRequestUtil.doPostJson(url, input); writeLog("back="+back); JSONObject backObj = JSONObject.parseObject(back); String ticket = backObj.getString("Ticket"); bb.writeLog("ticket="+ticket); JSONObject obj = (JSONObject) params; String approveScenario = obj.getString("approveScenario"); String corpId = obj.getString("corpId"); String orderId = obj.getString("orderId"); String orderStatus = obj.getString("orderStatus"); String productType = obj.getString("productType"); String sign = obj.getString("sign"); String tgq="0"; //1 改签 2:退 if("FlightInternational".equals(productType)||"FlightDomestic".equals(productType)){ //机票 ,改签成功 if("rebookSuccess".equals(orderStatus)){ tgq="1"; } //退票成功(退款成功) if("refunded".equals(orderStatus)||"RefundSuccess".equals(orderStatus)){ tgq="2"; } } if("HotelContract".equals(productType)||"HotelMember".equals(productType)){ // 取消 writeLog("HotelContract------->productType="+productType); if("Cancelled".equals(orderStatus)){ tgq="2"; } writeLog("HotelContract------->productType---------->orderStatus="+orderStatus); } if("Train".equals(productType)){ //已改签 if("Rebooked".equals(orderStatus)){ tgq="1"; } //SubmitRefund 退票成功 if("SubmitRefund".equals(orderStatus)){ tgq="2"; } } if("0".equals(tgq)){ apimap.put("errno","-1"); apimap.put("errmsg","不触发流程"); return apimap; } Map orderMap = new HashMap(); Map authMap = new HashMap(); authMap.put("AppKey",appKey); authMap.put("Ticket",ticket); orderMap.put("Auth",authMap); orderMap.put("JourneyNo",""); orderMap.put("OrderID",orderId); orderMap.put("SearchType",1); String orderInput = JSON.toJSONString(orderMap); bb.writeLog("orderInput="+orderInput); String orderBack = httpRequestUtil.doPostJson(orderurl, orderInput); // String orderBack = postData(orderInput,orderurl); bb.writeLog("orderBack="+orderBack); if(isJsonValid(orderBack)) { JSONObject orderObj = JSONObject.parseObject(orderBack); JSONArray array = orderObj.getJSONArray("ItineraryList"); for (int i = 0; i < array.size(); i++) { JSONObject detailObj = array.getJSONObject(i); JSONArray flightOrderInfoList = detailObj.getJSONArray("FlightOrderInfoList"); JSONArray hotelOrderInfoList = detailObj.getJSONArray("HotelOrderInfoList"); JSONArray trainOrderInfoList = detailObj.getJSONArray("TrainOrderInfoList"); if(flightOrderInfoList!=null){ doFlightOrder(flightOrderInfoList,workflowId,tgq); } if(hotelOrderInfoList!=null){ doHotailOrder(hotelOrderInfoList,workflowId,tgq); } if(trainOrderInfoList!=null){ doTrainOrder(trainOrderInfoList,workflowId,tgq); } } }else{ apimap.put("errno","-1"); apimap.put("errmsg","订单数据格式不对"); } if("".equals(params.toString())){ apimap.put("errno","-1"); apimap.put("errmsg","空数据"); }else { apimap.put("errno", "0"); apimap.put("errmsg", ""); } return apimap; } public static String GetSign(String corpId,String productType,String orderStatus,String orderId,String statusIDs ,String refundType,String secret,String approveScenario) { //构造字典 HashMap hashMap=new HashMap(); hashMap.put("secret",secret); hashMap.put("corpId",corpId); hashMap.put("productType",productType); hashMap.put("orderId",orderId); hashMap.put("orderStatus",orderStatus); //排序 Collection collection=hashMap.keySet(); ArrayList list=new ArrayList(collection); Collections.sort(list); //拼接 String str=""; for( int i=0;i2){ input = input.substring(0,input.indexOf(".")+3); } } return input; } public String dobuleAdd(String d1, String d2 ) { BigDecimal value1 = new BigDecimal(d1); BigDecimal value2 = new BigDecimal(d2); return value1.add(value2).toString(); } //保存自定义左侧树信息到requestbase表 private static void updateLeftTreeInfo(String requestid, String workflowid){ BaseBean baseBean = new BaseBean(); RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); WorkflowBillComInfo wbInfo = new WorkflowBillComInfo(); WorkflowComInfo wcInfo = new WorkflowComInfo(); int formid = Util.getIntValue(wcInfo.getFormId(workflowid+"")); String tablename = wbInfo.getTablename(formid + ""); String workflowname = wcInfo.getWorkflowname(workflowid + ""); rs.executeQuery("select id,sfzxsw,secondfieldname,thirdfieldname,showname,doingwfids,donewfids,sencondIsGroupbyFieldname from uf_treelistsetting "); baseBean.writeLog("---LHSP2021----requestid==="+requestid+"----selectSql===="+"select id,sfzxsw,secondfieldname,thirdfieldname,showname from uf_treelistsetting where (','||doingwfids||',' like '%,"+workflowid+",%') or (','||donewfids||',' like '%,"+workflowid+",%')"); while (rs.next()){ String id = rs.getString(1); int sfzxsw = rs.getInt(2); String secondfieldname = rs.getString(3); String thirdfieldname = rs.getString(4); String showname = rs.getString(5); String doingwfids1 = Util.null2String(rs.getString(6)); String donewfids1 = Util.null2String(rs.getString(7)); List list = Arrays.asList(doingwfids1.split(",")); List list1 = Arrays.asList(donewfids1.split(",")); HashSet set = new HashSet<>(); set.addAll(WorkflowVersion.getVersionStringByWfid4List(list)); set.addAll(WorkflowVersion.getVersionStringByWfid4List(list1)); if (set.contains(workflowid+"")) { if (sfzxsw == 1) { String secondShowName = ""; String secondValue = ""; String secondFieldId = ""; String thirdValue = ""; String thirdFieldType = ""; String thirdFieldDBType = ""; String thirdShowName = ""; rs1.executeQuery("select id from workflow_billfield where fieldname = ? and billid = ?", secondfieldname, formid); if (rs1.next()) { secondFieldId = rs1.getString(1); } baseBean.writeLog("---LHSP2021----requestid===" + requestid + "----secondFieldId====" + secondFieldId); rs1.executeQuery("select type,fielddbtype from workflow_billfield where fieldname = ? and billid = ?", thirdfieldname, formid); if (rs1.next()) { thirdFieldType = rs1.getString(1); thirdFieldDBType = rs1.getString(2); } baseBean.writeLog("---LHSP2021----requestid===" + requestid + "----thirdFieldType====" + thirdFieldType + "----thirdFieldDBType====" + thirdFieldDBType); rs1.executeQuery("select " + secondfieldname + "," + thirdfieldname + " from " + tablename + " where requestid = ?", requestid); baseBean.writeLog("---LHSP2021----requestid===" + requestid + "----selectData====" + "select " + secondfieldname + "," + thirdfieldname + " from " + tablename + " where requestid = " + requestid); if (rs1.next()) { secondValue = rs1.getString(1); thirdValue = rs1.getString(2); secondShowName = getSelectFieldValue(secondFieldId, secondValue); List browserValueInfo = getBrowserFieldValue(thirdFieldType, thirdValue, thirdFieldDBType); for (BrowserValueInfo info : browserValueInfo) { String name = info.getName(); thirdShowName += name + ","; } if (thirdShowName.endsWith(",")) { thirdShowName = thirdShowName.substring(0, thirdShowName.length() - 1); } } baseBean.writeLog("---LHSP2021----requestid===" + requestid + "----updateSql====" + "update workflow_requestbase set firstfloor = " + id + ",firstfloorname = " + showname + ",secondfloor = " + secondValue + ",secondfloorname = " + secondShowName + ",thirdfloor = " + thirdValue + ",thirdfloorname = " + thirdShowName + " where requestid = " + requestid); rs1.executeUpdate("update workflow_requestbase set firstfloor = ?,firstfloorname = ?,secondfloor = ?,secondfloorname = ?,thirdfloor = ?,thirdfloorname = ? where requestid = ?", id, showname, secondValue, secondShowName, thirdValue, thirdShowName, requestid); } else { //qc2126083 除了总行收文分类外,其余所有分类,都要支持二级目录按字段分类,且通过建模字段控制是否分类 String sencondIsGroupbyFieldname = Util.null2String(rs.getString(8)); rs1.writeLog(">>>>>> wangsong requestid="+requestid+" 判断二级目录区分是否按照指定字段分类展示 sencondIsGroupbyFieldname="+sencondIsGroupbyFieldname); if("0".equals(sencondIsGroupbyFieldname)){//需要按照字段分类展示 String secondShowName = ""; String secondValue = ""; String secondFieldId = ""; rs1.executeQuery("select id from workflow_billfield where fieldname = ? and billid = ?", secondfieldname, formid); if (rs1.next()) { secondFieldId = rs1.getString(1); } rs1.executeQuery("select * from " + tablename + " where requestid = ?", requestid); if (rs1.next()) { secondValue = rs1.getString(secondfieldname); secondShowName = getSelectFieldValue(secondFieldId, secondValue); } rs1.writeLog(">>>>>> wangsong 更新二级目录的字段数据到workflow_requestbase表 secondFieldId="+secondFieldId+",secondValue="+secondValue+",secondShowName="+secondShowName); rs1.executeUpdate("update workflow_requestbase set firstfloor = ?,firstfloorname = ?,secondfloor = ?,secondfloorname = ? where requestid = ?", id, showname, secondValue, secondShowName, requestid); }else{ baseBean.writeLog("---LHSP2021----requestid===" + requestid + "----updateSql====" + "update workflow_requestbase set firstfloor = " + id + ",firstfloorname = " + showname + ",secondfloor = " + workflowid + ",secondfloorname = " + workflowname + " where requestid = " + requestid); rs1.executeUpdate("update workflow_requestbase set firstfloor = ?,firstfloorname = ?,secondfloor = ?,secondfloorname = ? where requestid = ?", id, showname, workflowid + "", workflowname, requestid); } } } } } /** * 获取选择框选中值 * */ public static String getSelectFieldValue(String fieldId, String selectValue) { String selectValueName = ""; RecordSet rs = new RecordSet(); String sql = "select selectvalue,selectname from workflow_selectitem where selectvalue = ? and fieldid=? and (cancel<>'1' or cancel is null) order by listorder,selectvalue"; rs.executeQuery(sql,selectValue, fieldId); if (rs.next()) { selectValueName = Util.null2String(rs.getString("selectname")); } return selectValueName; } /** * 获取浏览按钮的值 * */ public static List getBrowserFieldValue(String fieldType, String fieldValue, String fieldDbType) { BrowserValueInfoService browserValueInfoService = new BrowserValueInfoService(); List result = new ArrayList<>(); try { result= browserValueInfoService.getBrowserValueInfo(fieldType, fieldDbType, 0, fieldValue, 7, "", ""); } catch (Exception e) { e.printStackTrace(); } return result; } }