|
@@ -0,0 +1,531 @@
|
|
|
|
+package nckd.jimin.jyyy.fi.business;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+import kd.bos.context.RequestContext;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
+import kd.bos.dataentity.resource.ResManager;
|
|
|
|
+import kd.bos.logging.Log;
|
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.operation.DeleteServiceHelper;
|
|
|
|
+import kd.bos.util.CollectionUtils;
|
|
|
|
+import kd.fi.er.business.servicehelper.HttpRetryServiceHelper;
|
|
|
|
+import kd.fi.er.business.trip.exception.TripSyncLogParam;
|
|
|
|
+import kd.fi.er.business.trip.exception.TripSyncLogUtils;
|
|
|
|
+import kd.fi.er.business.trip.model.*;
|
|
|
|
+import kd.fi.er.business.trip.service.function.AbstractTripReqBillInvoke;
|
|
|
|
+import kd.fi.er.business.trip.supplier.Supplier;
|
|
|
|
+import kd.fi.er.business.trip.supplier.didi.systemexternal.DiDiServiceUtil;
|
|
|
|
+import kd.fi.er.business.trip.supplier.didi.systemexternal.DiDiTripCarRegulationUtil;
|
|
|
|
+import kd.fi.er.business.trip.util.TripCityUtil;
|
|
|
|
+import kd.fi.er.business.trip.util.TripCommonUtil;
|
|
|
|
+import kd.fi.er.business.trip.util.TripSyncConfigUtil;
|
|
|
|
+import kd.fi.er.business.trip.util.TripSyncDataMappingUtil;
|
|
|
|
+import kd.fi.er.common.ExternalConstants;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+public class DiDiTripReqBillCusInvoke extends AbstractTripReqBillInvoke<JSONObject> {
|
|
|
|
+ private static final Log logger = LogFactory.getLog(DiDiTripReqBillCusInvoke.class);
|
|
|
|
+ private static int APPROVAL_TYPE = 1;
|
|
|
|
+
|
|
|
|
+ public DiDiTripReqBillCusInvoke() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected String supplier() {
|
|
|
|
+ return Supplier.DIDI.name();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected Object convert(Object value) {
|
|
|
|
+ switch ((String)this.getParams().get("syncStatus")) {
|
|
|
|
+ case "1":
|
|
|
|
+ case "3":
|
|
|
|
+ return this.convertPushBill(value, false);
|
|
|
|
+ case "2":
|
|
|
|
+ return this.convertStatusChange((TripReqbillModel)value);
|
|
|
|
+ default:
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected JSONObject convertPushBill(Object info) {
|
|
|
|
+ return this.convertPushBill(info, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected JSONObject convertPushBill(Object info, boolean updateFlag) {
|
|
|
|
+ TripReqbillModel reqbill = (TripReqbillModel)info;
|
|
|
|
+ String out_approval_id = reqbill.getBillNo();
|
|
|
|
+ logger.info("商旅集成,滴滴出差申请单,推送单据,开始数据转换,出差单号:" + out_approval_id);
|
|
|
|
+ Map<String, String> supplierMap = TripCommonUtil.getTripServiceInfo(this.supplier());
|
|
|
|
+ String client_id = (String)supplierMap.get("appkey");
|
|
|
|
+ String company_id = (String)supplierMap.get("orationid");
|
|
|
|
+ String access_token = DiDiServiceUtil.getCacheToken(new Date());
|
|
|
|
+ if (access_token == null) {
|
|
|
|
+ this.tripSyncLogParam.setMessage(String.format(ResManager.loadKDString("商旅集成,出差单号:%s,获取滴滴token为空,请检查配置!", "DiDiTripReqBillInvoke_0", "fi-er-business", new Object[0]), out_approval_id));
|
|
|
|
+ this.tripSyncLogParam.setStatus("B");
|
|
|
|
+ return null;
|
|
|
|
+ } else {
|
|
|
|
+ String phone = reqbill.getApplyEmpPhone();
|
|
|
|
+ String regulation_id = DiDiTripCarRegulationUtil.getUserTripCarRegulation(phone, "2");
|
|
|
|
+ if (StringUtils.isBlank(regulation_id)) {
|
|
|
|
+ this.tripSyncLogParam.setMessage(String.format(ResManager.loadKDString("商旅集成,出差单号:%s,获取出差用车制度为空,请检查配置!", "DiDiTripReqBillInvoke_1", "fi-er-business", new Object[0]), out_approval_id));
|
|
|
|
+ this.tripSyncLogParam.setStatus("B");
|
|
|
|
+ return null;
|
|
|
|
+ } else {
|
|
|
|
+ int approval_type = APPROVAL_TYPE;
|
|
|
|
+ String reason = reqbill.getDesc();
|
|
|
|
+ String timestamp = String.valueOf(System.currentTimeMillis() / 1000L);
|
|
|
|
+ HashMap<String, Object> signMap = new HashMap();
|
|
|
|
+ signMap.put("client_id", client_id);
|
|
|
|
+ signMap.put("company_id", company_id);
|
|
|
|
+ signMap.put("access_token", access_token);
|
|
|
|
+ signMap.put("regulation_id", regulation_id);
|
|
|
|
+ signMap.put("out_approval_id", out_approval_id);
|
|
|
|
+ signMap.put("phone", phone);
|
|
|
|
+ signMap.put("type", 1);
|
|
|
|
+ QFilter uFilter = new QFilter("server", "=", this.supplier());
|
|
|
|
+ uFilter.and(new QFilter("datatype", "=", "bos_org"));
|
|
|
|
+ Map<Object, Object> dataOrgMappingMap = TripSyncDataMappingUtil.getDataMappingMapByFilter(uFilter, "innerdataid", "outdataid");
|
|
|
|
+ Object budgetCenterId = null;
|
|
|
|
+ if (dataOrgMappingMap.size() > 0) {
|
|
|
|
+ budgetCenterId = TripSyncDataMappingUtil.getBudgetCenterId((DailyVehicleBillModel)null, reqbill, dataOrgMappingMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (budgetCenterId != null) {
|
|
|
|
+ signMap.put("budget_center_id", budgetCenterId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ signMap.put("approval_type", approval_type);
|
|
|
|
+ signMap.put("reason", reason.trim());
|
|
|
|
+ JSONObject travelDetailInfo = this.converTravelDetailInfo(reqbill);
|
|
|
|
+ signMap.put("travel_detail", gbEncoding(travelDetailInfo.toString()));
|
|
|
|
+ signMap.put("timestamp", timestamp);
|
|
|
|
+ JSONArray companions = this.setCompanions(reqbill);
|
|
|
|
+ signMap.put("passenger_list", gbEncoding(companions.toString()));
|
|
|
|
+ JSONObject tripReqObj = new JSONObject();
|
|
|
|
+ if (updateFlag) {
|
|
|
|
+ QFilter updateFilter = new QFilter("server", "=", this.supplier());
|
|
|
|
+ updateFilter.and(new QFilter("datatype", "=", "er_tripreq"));
|
|
|
|
+ updateFilter.and(new QFilter("number", "=", out_approval_id));
|
|
|
|
+ Map<Object, Object> updateDataOrgMappingMap = TripSyncDataMappingUtil.getDataMappingMapByFilter(updateFilter, "number", "outdataid");
|
|
|
|
+ Object o = updateDataOrgMappingMap.get(out_approval_id);
|
|
|
|
+ if (o != null) {
|
|
|
|
+ signMap.put("approval_id", o);
|
|
|
|
+ tripReqObj.put("approval_id", o);
|
|
|
|
+ } else if (null != this.params.get("approval_id")) {
|
|
|
|
+ signMap.put("approval_id", this.params.get("approval_id"));
|
|
|
|
+ tripReqObj.put("approval_id", this.params.get("approval_id"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String tripreqSignKey = DiDiServiceUtil.genSign(signMap, (String)supplierMap.get("reservedfield1"));
|
|
|
|
+ tripReqObj.put("client_id", client_id);
|
|
|
|
+ tripReqObj.put("company_id", company_id);
|
|
|
|
+ tripReqObj.put("access_token", access_token);
|
|
|
|
+ tripReqObj.put("timestamp", timestamp);
|
|
|
|
+ tripReqObj.put("regulation_id", regulation_id);
|
|
|
|
+ tripReqObj.put("out_approval_id", out_approval_id);
|
|
|
|
+ tripReqObj.put("phone", phone);
|
|
|
|
+ tripReqObj.put("approval_type", approval_type);
|
|
|
|
+ tripReqObj.put("type", 1);
|
|
|
|
+ if (budgetCenterId != null) {
|
|
|
|
+ tripReqObj.put("budget_center_id", budgetCenterId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tripReqObj.put("reason", reason.trim());
|
|
|
|
+ tripReqObj.put("travel_detail", travelDetailInfo);
|
|
|
|
+ tripReqObj.put("passenger_list", companions);
|
|
|
|
+ tripReqObj.put("sign", tripreqSignKey);
|
|
|
|
+ return tripReqObj;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JSONArray setCompanions(TripReqbillModel reqbill) {
|
|
|
|
+ boolean paramValue = TripSyncConfigUtil.getBoolean("Reservation_ personnel_range", Boolean.FALSE);
|
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
|
+ if (paramValue) {
|
|
|
|
+ List<JourneyModel> journeyModelList = reqbill.getJourneyModelList();
|
|
|
|
+ int size = journeyModelList.size();
|
|
|
|
+ List<String> userNumberList = Lists.newArrayListWithCapacity(16);
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < size; ++i) {
|
|
|
|
+ JourneyModel journeyModel = (JourneyModel)journeyModelList.get(i);
|
|
|
|
+ Set<DynamicObject> travelers = journeyModel.getTravelers();
|
|
|
|
+ Set<String> travelNumberSet = (Set)travelers.stream().filter((traveler) -> {
|
|
|
|
+ return StringUtils.isNotEmpty(traveler.getString("number"));
|
|
|
|
+ }).map((traveler) -> {
|
|
|
|
+ return traveler.getString("number");
|
|
|
|
+ }).collect(Collectors.toSet());
|
|
|
|
+ userNumberList.addAll(travelNumberSet);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!userNumberList.contains(reqbill.getCreatEmpNum())) {
|
|
|
|
+ userNumberList.add(reqbill.getCreatEmpNum());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!userNumberList.contains(reqbill.getApplyEmpNum())) {
|
|
|
|
+ userNumberList.add(reqbill.getApplyEmpNum());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(userNumberList)) {
|
|
|
|
+ return jsonArray;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObjectCollection users = QueryServiceHelper.query("bos_user", "number,name,id", new QFilter[]{new QFilter("number", "in", userNumberList)});
|
|
|
|
+ Iterator var15 = users.iterator();
|
|
|
|
+
|
|
|
|
+ while(var15.hasNext()) {
|
|
|
|
+ DynamicObject user = (DynamicObject)var15.next();
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("member_type", "1");
|
|
|
|
+ jsonObject.put("passenger_type", "0");
|
|
|
|
+ jsonObject.put("employee_number", user.getString("number"));
|
|
|
|
+ jsonObject.put("passenger_name", user.getString("name"));
|
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ String creatEmpNum = reqbill.getCreatEmpNum();
|
|
|
|
+ String applyEmpNum = reqbill.getApplyEmpNum();
|
|
|
|
+ JSONObject jsonObject;
|
|
|
|
+ if (StringUtils.isNotEmpty(creatEmpNum) && StringUtils.isNotEmpty(applyEmpNum) && creatEmpNum.equals(applyEmpNum)) {
|
|
|
|
+ jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("member_type", "1");
|
|
|
|
+ jsonObject.put("passenger_type", "0");
|
|
|
|
+ jsonObject.put("employee_number", creatEmpNum);
|
|
|
|
+ jsonObject.put("passenger_name", reqbill.getCreatEmpName());
|
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
|
+ } else {
|
|
|
|
+ jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("member_type", "1");
|
|
|
|
+ jsonObject.put("passenger_type", "0");
|
|
|
|
+ jsonObject.put("employee_number", creatEmpNum);
|
|
|
|
+ jsonObject.put("passenger_name", reqbill.getCreatEmpName());
|
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
|
+ jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("member_type", "1");
|
|
|
|
+ jsonObject.put("passenger_type", "0");
|
|
|
|
+ jsonObject.put("employee_number", applyEmpNum);
|
|
|
|
+ jsonObject.put("passenger_name", reqbill.getApplyEmpName());
|
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return jsonArray;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JSONObject converTravelDetailInfo(TripReqbillModel reqbill) {
|
|
|
|
+ JSONObject travelDetailInfo = new JSONObject();
|
|
|
|
+ List<JourneyModel> tripentryList = reqbill.getJourneyModelList();
|
|
|
|
+ if (tripentryList != null && tripentryList.size() > 0) {
|
|
|
|
+ Date firstStartDate = ((JourneyModel)tripentryList.get(0)).getStartDate();
|
|
|
|
+ Date endStartDate = ((JourneyModel)tripentryList.get(tripentryList.size() - 1)).getEndDate();
|
|
|
|
+ DynamicObject tripControlsetting = TripCommonUtil.getTripControlSettings(reqbill.getCompanyId(), this.supplier());
|
|
|
|
+ int start_city_rule = 1;
|
|
|
|
+ int end_city_rule = 1;
|
|
|
|
+ if (null != tripControlsetting && null != tripControlsetting.getString("startcityrule")) {
|
|
|
|
+ start_city_rule = Integer.parseInt(tripControlsetting.getString("startcityrule"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null != tripControlsetting && null != tripControlsetting.getString("endcityrule")) {
|
|
|
|
+ end_city_rule = Integer.parseInt(tripControlsetting.getString("endcityrule"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ HashMap<String, Object> paramMap = new HashMap();
|
|
|
|
+ paramMap.put("start_date", TripCommonUtil.date2TimeStamp(firstStartDate, "yyyy-MM-dd"));
|
|
|
|
+ paramMap.put("end_date", TripCommonUtil.date2TimeStamp(endStartDate, "yyyy-MM-dd"));
|
|
|
|
+ JSONArray trips = this.getTrips(new JSONArray(), tripentryList, paramMap);
|
|
|
|
+ travelDetailInfo.put("start_date", TripCommonUtil.date2TimeStamp(firstStartDate, "yyyy-MM-dd"));
|
|
|
|
+ travelDetailInfo.put("end_date", TripCommonUtil.date2TimeStamp(endStartDate, "yyyy-MM-dd"));
|
|
|
|
+ travelDetailInfo.put("trips", trips);
|
|
|
|
+ travelDetailInfo.put("start_city_rule", start_city_rule);
|
|
|
|
+ travelDetailInfo.put("end_city_rule", end_city_rule);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return travelDetailInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JSONArray getTrips(JSONArray trips, List<JourneyModel> tripentryList, Map<String, Object> paramMap) {
|
|
|
|
+ int dtrip_to_citys = TripSyncConfigUtil.getIntValue("dtrip_to_citys", 0);
|
|
|
|
+ JSONObject tripObj;
|
|
|
|
+ if (dtrip_to_citys == 1) {
|
|
|
|
+ tripObj = new JSONObject();
|
|
|
|
+ if (tripentryList == null || tripentryList.size() == 0) {
|
|
|
|
+ logger.info("商旅集成,滴滴出差申请单,tripentryList为空");
|
|
|
|
+ return trips;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JourneyModel tripentry = (JourneyModel)tripentryList.get(0);
|
|
|
|
+ tripObj.put("departure_city", tripentry.getFromCity());
|
|
|
|
+ tripObj.put("departure_city_id", TripCityUtil.getDiDiCityId(tripentry.getFromCityID()).get(tripentry.getFromCityID()));
|
|
|
|
+ tripObj.put("start_date", paramMap.get("start_date"));
|
|
|
|
+ tripObj.put("end_date", paramMap.get("end_date"));
|
|
|
|
+ tripObj.put("trip_type", "0");
|
|
|
|
+ tripObj.put("to_citys", this.getToCitys(tripentryList));
|
|
|
|
+ trips.add(tripObj);
|
|
|
|
+ } else {
|
|
|
|
+ for(int i = 0; i < tripentryList.size(); ++i) {
|
|
|
|
+ tripObj = new JSONObject();
|
|
|
|
+ JourneyModel tripentry = (JourneyModel)tripentryList.get(i);
|
|
|
|
+ tripObj.put("departure_city_id", TripCityUtil.getDiDiCityId(tripentry.getFromCityID()).get(tripentry.getFromCityID()));
|
|
|
|
+ tripObj.put("destination_city_id", TripCityUtil.getDiDiCityId(tripentry.getToCityID()).get(tripentry.getToCityID()));
|
|
|
|
+ tripObj.put("departure_city", tripentry.getFromCity());
|
|
|
|
+ tripObj.put("destination_city", tripentry.getToCity());
|
|
|
|
+ tripObj.put("start_date", TripCommonUtil.date2TimeStamp(tripentry.getStartDate(), "yyyy-MM-dd"));
|
|
|
|
+ tripObj.put("end_date", TripCommonUtil.date2TimeStamp(tripentry.getEndDate(), "yyyy-MM-dd"));
|
|
|
|
+ tripObj.put("trip_type", "0");
|
|
|
|
+ trips.add(tripObj);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!trips.getJSONObject(0).getString("departure_city").equals(trips.getJSONObject(trips.size() - 1).getString("destination_city"))) {
|
|
|
|
+ tripObj = new JSONObject();
|
|
|
|
+ tripObj.put("departure_city_id", trips.getJSONObject(trips.size() - 1).getString("destination_city_id"));
|
|
|
|
+ tripObj.put("destination_city_id", trips.getJSONObject(0).getString("departure_city_id"));
|
|
|
|
+ tripObj.put("departure_city", trips.getJSONObject(trips.size() - 1).getString("destination_city"));
|
|
|
|
+ tripObj.put("destination_city", trips.getJSONObject(0).getString("departure_city"));
|
|
|
|
+ tripObj.put("start_date", trips.getJSONObject(trips.size() - 1).getString("end_date"));
|
|
|
|
+ tripObj.put("end_date", trips.getJSONObject(trips.size() - 1).getString("end_date"));
|
|
|
|
+ tripObj.put("trip_type", "0");
|
|
|
|
+ trips.add(tripObj);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return trips;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Object getToCitys(List<JourneyModel> tripentryList) {
|
|
|
|
+ JSONArray to_citys = new JSONArray();
|
|
|
|
+ HashSet<Long> toCitySet = new HashSet();
|
|
|
|
+ Iterator var4 = tripentryList.iterator();
|
|
|
|
+
|
|
|
|
+ while(true) {
|
|
|
|
+ Set mulwaytos;
|
|
|
|
+ do {
|
|
|
|
+ if (!var4.hasNext()) {
|
|
|
|
+ QFilter filter = new QFilter("id", "in", toCitySet);
|
|
|
|
+ Map<Object, DynamicObject> cities = BusinessDataServiceHelper.loadFromCache("er_city", "id,didicityid,admindivisionid.name", new QFilter[]{filter});
|
|
|
|
+ if (cities == null) {
|
|
|
|
+ return to_citys;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Iterator var12 = cities.values().iterator();
|
|
|
|
+
|
|
|
|
+ while(var12.hasNext()) {
|
|
|
|
+ DynamicObject city = (DynamicObject)var12.next();
|
|
|
|
+ DynamicObject admindivisionid = city.getDynamicObject("admindivisionid");
|
|
|
|
+ if (admindivisionid != null && StringUtils.isNotBlank(admindivisionid.getString("name"))) {
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("id", city.getLong("didicityid"));
|
|
|
|
+ jsonObject.put("name", admindivisionid.getString("name"));
|
|
|
|
+ to_citys.add(jsonObject);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return to_citys;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JourneyModel journeyModel = (JourneyModel)var4.next();
|
|
|
|
+ toCitySet.add(journeyModel.getFromCityID());
|
|
|
|
+ toCitySet.add(journeyModel.getToCityID());
|
|
|
|
+ mulwaytos = journeyModel.getMulwaytos();
|
|
|
|
+ } while(mulwaytos == null);
|
|
|
|
+
|
|
|
|
+ Iterator var7 = mulwaytos.iterator();
|
|
|
|
+
|
|
|
|
+ while(var7.hasNext()) {
|
|
|
|
+ Object obj = var7.next();
|
|
|
|
+ if (obj != null) {
|
|
|
|
+ MulwaytoModel mulwayto = (MulwaytoModel)obj;
|
|
|
|
+ toCitySet.add(mulwayto.getToCityID());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JSONObject convertStatusChange(TripReqbillModel reqbill) {
|
|
|
|
+ String out_approval_id = reqbill.getBillNo();
|
|
|
|
+ logger.info("商旅集成,滴滴出差申请单,取消单据,开始数据转换,出差单号:" + out_approval_id);
|
|
|
|
+ Map<String, String> supplierMap = TripCommonUtil.getTripServiceInfo(this.supplier());
|
|
|
|
+ String client_id = (String)supplierMap.get("appkey");
|
|
|
|
+ String company_id = (String)supplierMap.get("orationid");
|
|
|
|
+ String access_token = DiDiServiceUtil.getCacheToken(new Date());
|
|
|
|
+ if (access_token == null) {
|
|
|
|
+ this.tripSyncLogParam.setMessage(String.format(ResManager.loadKDString("商旅集成,出差单号:%s,获取滴滴token为空,请检查配置!", "DiDiTripReqBillInvoke_0", "fi-er-business", new Object[0]), out_approval_id));
|
|
|
|
+ this.tripSyncLogParam.setStatus("B");
|
|
|
|
+ return null;
|
|
|
|
+ } else {
|
|
|
|
+ QFilter uFilter = new QFilter("server", "=", this.supplier());
|
|
|
|
+ uFilter.and(new QFilter("datatype", "=", "er_tripreq"));
|
|
|
|
+ Map<Object, Object> dataTripReqMappingMap = TripSyncDataMappingUtil.getDataMappingMapByFilter(uFilter, "number", "outdataid");
|
|
|
|
+ Object tripReqBillId = dataTripReqMappingMap.get(out_approval_id);
|
|
|
|
+ if (dataTripReqMappingMap != null && dataTripReqMappingMap.size() > 0 && tripReqBillId != null) {
|
|
|
|
+ String approval_id = String.valueOf(tripReqBillId);
|
|
|
|
+ if (approval_id != null && !StringUtils.isEmpty(approval_id)) {
|
|
|
|
+ String timestamp = String.valueOf(System.currentTimeMillis() / 1000L);
|
|
|
|
+ HashMap<String, Object> signMap = new HashMap();
|
|
|
|
+ signMap.put("client_id", client_id);
|
|
|
|
+ signMap.put("company_id", company_id);
|
|
|
|
+ signMap.put("access_token", access_token);
|
|
|
|
+ signMap.put("approval_id", approval_id);
|
|
|
|
+ signMap.put("timestamp", timestamp);
|
|
|
|
+ String tripreqCloseSignKey = DiDiServiceUtil.genSign(signMap, (String)supplierMap.get("reservedfield1"));
|
|
|
|
+ JSONObject tripreqCloseObj = new JSONObject(signMap);
|
|
|
|
+ tripreqCloseObj.put("sign", tripreqCloseSignKey);
|
|
|
|
+ return tripreqCloseObj;
|
|
|
|
+ } else {
|
|
|
|
+ this.tripSyncLogParam.setMessage(String.format(ResManager.loadKDString("商旅集成,出差单号:%s,获取滴滴侧出差申请单id为空,该单据尚未推送,暂不需要取消!", "DiDiTripReqBillInvoke_2", "fi-er-business", new Object[0]), out_approval_id));
|
|
|
|
+ this.tripSyncLogParam.setStatus("A");
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected String batPushProcess(Object value) {
|
|
|
|
+ String jsonStr;
|
|
|
|
+ if (value == null) {
|
|
|
|
+ jsonStr = "200";
|
|
|
|
+ if (this.tripSyncLogParam.getStatus().equals("B")) {
|
|
|
|
+ jsonStr = "300";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return jsonStr;
|
|
|
|
+ } else {
|
|
|
|
+ jsonStr = JSON.toJSONString(value, new SerializerFeature[]{SerializerFeature.DisableCircularReferenceDetect});
|
|
|
|
+ String url = "";
|
|
|
|
+ String syncStatus = (String)this.getParams().get("syncStatus");
|
|
|
|
+ switch ((String)this.getParams().get("syncStatus")) {
|
|
|
|
+ case "1":
|
|
|
|
+ case "3":
|
|
|
|
+ url = (String) ExternalConstants.DIDIURLMAP.get("approvalAddKey");
|
|
|
|
+ break;
|
|
|
|
+ case "2":
|
|
|
|
+ url = (String)ExternalConstants.DIDIURLMAP.get("approvalCancelKey");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.tripSyncLogParam.setRequestdata(value);
|
|
|
|
+ this.tripSyncLogParam.setRequesturl(url);
|
|
|
|
+ String result = HttpRetryServiceHelper.PostData(url, jsonStr);
|
|
|
|
+ this.tripSyncLogParam.setResponsedata(result);
|
|
|
|
+ JSONObject resultJsonObject = JSONObject.parseObject(result);
|
|
|
|
+ List dataMappingList = new ArrayList();
|
|
|
|
+ if (resultJsonObject != null && (resultJsonObject.getIntValue("errno") == 0 || resultJsonObject.getIntValue("errno") == 50506)) {
|
|
|
|
+ String outdataid;
|
|
|
|
+ if (resultJsonObject.getIntValue("errno") == 50506) {
|
|
|
|
+ logger.info("didi update api");
|
|
|
|
+ String errmsg = resultJsonObject.getString("errmsg");
|
|
|
|
+ if (null == errmsg) {
|
|
|
|
+ logger.info("商旅集成,滴滴出差申请单同步:{}", resultJsonObject.toJSONString());
|
|
|
|
+ return "300";
|
|
|
|
+ } else {
|
|
|
|
+ errmsg = errmsg.substring(errmsg.lastIndexOf("("), errmsg.lastIndexOf(")"));
|
|
|
|
+ if (null == errmsg) {
|
|
|
|
+ logger.info("商旅集成,滴滴出差申请单同步:{}", resultJsonObject.toJSONString());
|
|
|
|
+ return "300";
|
|
|
|
+ } else {
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ char[] var24 = errmsg.toCharArray();
|
|
|
|
+ int var26 = var24.length;
|
|
|
|
+
|
|
|
|
+ for(int var12 = 0; var12 < var26; ++var12) {
|
|
|
|
+ char c = var24[var12];
|
|
|
|
+ if (Character.isDigit(c)) {
|
|
|
|
+ sb.append(c);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.dealData(jsonStr);
|
|
|
|
+ TripSyncDataMappingModel TripSyncDataMappingObj = new TripSyncDataMappingModel("er_tripreq", this.supplier());
|
|
|
|
+ outdataid = sb.toString();
|
|
|
|
+ JSONObject reqJson = JSONObject.parseObject(jsonStr);
|
|
|
|
+ String out_approval_id = reqJson.getString("out_approval_id");
|
|
|
|
+ TripSyncDataMappingObj.setNumber(out_approval_id);
|
|
|
|
+ TripSyncDataMappingObj.setOutdataid(Long.parseLong(outdataid));
|
|
|
|
+ dataMappingList.add(TripSyncDataMappingObj);
|
|
|
|
+ TripSyncDataMappingUtil.saveTripSyncDataMapping(dataMappingList);
|
|
|
|
+ Object updateValue = this.redealJson();
|
|
|
|
+ String updateJsonStr = JSON.toJSONString(updateValue, new SerializerFeature[]{SerializerFeature.DisableCircularReferenceDetect});
|
|
|
|
+ TripSyncLogParam updateTripSyncLogParam = new TripSyncLogParam(RequestContext.get().getTraceId(), this.supplier(), this.function());
|
|
|
|
+ String updateUrl = (String)ExternalConstants.DIDIURLMAP.get("approvalUpdateKey");
|
|
|
|
+ updateTripSyncLogParam.setRequestdata(updateValue);
|
|
|
|
+ Object billId = this.getParams().get("billId");
|
|
|
|
+ updateTripSyncLogParam.setBillno(String.valueOf(billId));
|
|
|
|
+ updateTripSyncLogParam.setRequesturl(updateUrl);
|
|
|
|
+ String updateResult = HttpRetryServiceHelper.PostData(updateUrl, updateJsonStr);
|
|
|
|
+ updateTripSyncLogParam.setResponsedata(updateResult);
|
|
|
|
+ JSONObject updateResultJsonObject = JSONObject.parseObject(updateResult);
|
|
|
|
+ if (updateResultJsonObject != null && updateResultJsonObject.getIntValue("errno") == 0) {
|
|
|
|
+ updateTripSyncLogParam.setStatus("A");
|
|
|
|
+ } else {
|
|
|
|
+ updateTripSyncLogParam.setStatus("B");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TripSyncLogUtils.saveErrorLog(Collections.singletonList(updateTripSyncLogParam));
|
|
|
|
+ return "200";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ this.tripSyncLogParam.setStatus("A");
|
|
|
|
+ if (StringUtils.equals(syncStatus, "1") || StringUtils.equals(syncStatus, "3")) {
|
|
|
|
+ this.dealData(jsonStr);
|
|
|
|
+ TripSyncDataMappingModel TripSyncDataMappingObj = new TripSyncDataMappingModel("er_tripreq", this.supplier());
|
|
|
|
+ JSONObject data = JSON.parseObject(JSON.toJSONString(resultJsonObject.get("data")));
|
|
|
|
+ outdataid = data.getString("approval_id");
|
|
|
|
+ outdataid = JSON.parseObject(JSON.toJSONString(value)).getString("out_approval_id");
|
|
|
|
+ TripSyncDataMappingObj.setNumber(outdataid);
|
|
|
|
+ TripSyncDataMappingObj.setOutdataid(Long.parseLong(outdataid));
|
|
|
|
+ dataMappingList.add(TripSyncDataMappingObj);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TripSyncDataMappingUtil.saveTripSyncDataMapping(dataMappingList);
|
|
|
|
+ return "200";
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ this.tripSyncLogParam.setStatus("B");
|
|
|
|
+ return "300";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void dealData(String jsonStr) {
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
|
|
|
+ if (jsonObject != null) {
|
|
|
|
+ String applyNumber = jsonObject.getString("out_approval_id");
|
|
|
|
+ DeleteServiceHelper.delete("er_tripsync_datamapping", new QFilter[]{new QFilter("server", "=", this.supplier()), new QFilter("number", "=", applyNumber)});
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static String gbEncoding(String s) {
|
|
|
|
+ StringBuilder buf = new StringBuilder();
|
|
|
|
+ char[] c = s.toCharArray();
|
|
|
|
+ char[] var3 = c;
|
|
|
|
+ int var4 = c.length;
|
|
|
|
+
|
|
|
|
+ for(int var5 = 0; var5 < var4; ++var5) {
|
|
|
|
+ char tmp = var3[var5];
|
|
|
|
+ if (tmp > 255) {
|
|
|
|
+ buf = buf.append("\\u").append(Integer.toHexString(tmp));
|
|
|
|
+ } else {
|
|
|
|
+ buf = buf.append(tmp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return buf.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Object redealJson() {
|
|
|
|
+ Object innerData = this.getInnerData();
|
|
|
|
+ return this.convertPushBill(innerData, true);
|
|
|
|
+ }
|
|
|
|
+}
|