Эх сурвалжийг харах

Merge branch 'master' of http://111.75.220.136:10030/Tzz/jxcl

Tzz 5 өдөр өмнө
parent
commit
93d2e9c8d8

+ 11 - 3
base/nckd-base-common/src/main/java/nckd/base/common/utils/GzwCommonUtils.java

@@ -146,6 +146,9 @@ public class GzwCommonUtils {
         List<File> xmlFileList = new ArrayList<>();
         //生成单据数据XML文件
         for (Map.Entry<String, Object> entry : xmlMap.entrySet()) {
+            if(ObjectUtils.isEmpty(entry.getValue())){
+                continue;
+            }
             File xmlFile = GzwCommonUtils.createXMLFile(uscc, entry.getKey(), ver, cusDateStr, (List<LinkedHashMap<String, Object>>) entry.getValue());
             xmlFileList.add(xmlFile);
         }
@@ -376,7 +379,7 @@ public class GzwCommonUtils {
      * @param obj 业务数据
      * @return 获取数据标识( 1  表示新增,2 表示修改,3  表示删除 ),默认为 1
      */
-    public static String getDataFlag(DynamicObject obj,String pushState) {
+    public static String getDataFlag(DynamicObject obj, String pushState) {
         //是否推送
         boolean isPush = obj.getBoolean("nckd_ispush");
         //元数据
@@ -389,7 +392,7 @@ public class GzwCommonUtils {
         String numberSign = properties.containsKey("number") ? "number" : "billno";
         //单据已审核 且 未推送单据  标识 = 新增。  如果已推送,说明不需要再次推送
         if ((obj.getString(statusSign).equals("C") || obj.getString(statusSign).equals("E")) && !isPush) {
-            if(pushState.equals("ZCTS")){
+            if (pushState.equals("ZCTS")) {
                 //设置已推送
                 obj.set("nckd_ispush", Boolean.TRUE);
             }
@@ -397,7 +400,7 @@ public class GzwCommonUtils {
         }
         //单据非已审核 且 已推送 标识=删除。 如果未推送,说明数据还未审核过 或者 已进行过删除,也不需要再次推送
         if (!obj.getString(statusSign).equals("C") && !obj.getString(statusSign).equals("E") && isPush) {
-            if(pushState.equals("ZCTS")){
+            if (pushState.equals("ZCTS")) {
                 //设置未推送
                 obj.set("nckd_ispush", Boolean.FALSE);
             }
@@ -526,6 +529,11 @@ public class GzwCommonUtils {
     public static File saveXmlToFile(String xmlContent, String filePath) {
         File xmlFile = new File(filePath);
 
+        File parentDir = xmlFile.getParentFile();
+        if (parentDir != null && !parentDir.exists()) {
+            parentDir.mkdirs();
+        }
+
         try (BufferedWriter writer = new BufferedWriter(
                 new OutputStreamWriter(new FileOutputStream(xmlFile), StandardCharsets.UTF_8))) {
             writer.write(xmlContent);

+ 1 - 4
base/nckd-base-common/src/main/java/nckd/base/common/utils/GzwXmlUtils.java

@@ -183,10 +183,7 @@ public class GzwXmlUtils {
         Element headElement = doc.createElement("Head");
         packageElement.appendChild(headElement);
 
-        // 检查数据是否有效
-        if (recordList.isEmpty()) {
-            throw new IllegalArgumentException("recordList不能为空");
-        }
+
 
         LinkedHashMap<String, Object> firstRecord = recordList.get(0);
 

+ 69 - 6
base/nckd-base-common/src/main/java/nckd/base/common/utils/TripSyncUtils.java

@@ -2,11 +2,21 @@ package nckd.base.common.utils;
 
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSONObject;
+import kd.bos.coderule.api.CodeRuleInfo;
+import kd.bos.context.RequestContext;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.metadata.IDataEntityType;
+import kd.bos.db.DB;
+import kd.bos.db.tx.TX;
+import kd.bos.db.tx.TXHandle;
 import kd.bos.exception.ErrorCode;
 import kd.bos.exception.KDBizException;
 import kd.bos.exception.KDException;
 import kd.bos.logging.Log;
 import kd.bos.logging.LogFactory;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
 
 
 import java.io.UnsupportedEncodingException;
@@ -30,13 +40,14 @@ public class TripSyncUtils {
 
 
     /**
-     * 推送,不需要返回结果
+     * 推送,不需要返回结果,单条推送:数据量不多且接口只能传单条
      *
      * @param service              接口名称
      * @param urlIsContainsService url是否包含接口名称
      * @param data                 具体业务数据
+     * @param obj                  单据数据
      */
-    public static void pushApi(String service, Boolean urlIsContainsService, Map<String, Object> data) {
+    public static void pushApi(String service, Boolean urlIsContainsService, Map<String, Object> data, DynamicObject obj) {
         logger.info(String.format("推送API接口名称:%s,业务数据参数:\n%s", service, JSONObject.toJSONString(data)));
 
         //获取费用核算应用参数.胜意环境地址
@@ -53,16 +64,68 @@ public class TripSyncUtils {
         try {
             String s = HttpUtils.postJson(url, syCommonParam);
             logger.info(String.format("推送API接口名称:%s,完成推送,接口出参:\n%s", service, s));
-
             JSONObject result = JSONObject.parseObject(s);
-            if (result.getBoolean("fail")) {
-                throw new KDBizException("推送接口失败:" + result.getString("message"));
+            //推送状态
+            Boolean fail = result.getBoolean("fail");
+            //记录推送日志
+            createLog(obj, !fail, JSONObject.toJSONString(syCommonParam), s);
+            if (fail) {
+                throw new KDBizException(result.getString("message"));
             }
         } catch (Exception e) {
-            throw new KDBizException("推送接口异常" + e);
+            throw new KDBizException("推送接口异常:" + e);
+        }
+    }
+
+
+    /**
+     * @param obj         单据数据
+     * @param isSuccess   是否成功
+     * @param pushParam   推送报文
+     * @param returnParam 返回报文
+     * @return 创建推送日志
+     */
+    public static void createLog(DynamicObject obj, Boolean isSuccess, String pushParam, String returnParam) {
+        //另外开启事务,报错不会滚,记录日志
+        try (TXHandle h = TX.requiresNew()) {
+            IDataEntityType dataEntityType = obj.getDataEntityType();
+            String formId = dataEntityType.getName();
+            String billNoField = dataEntityType.getProperties().containsKey("number") ? "number" : "billno";
+            DynamicObject log = createLog(formId, obj.getString(billNoField), isSuccess, pushParam, returnParam);
+            SaveServiceHelper.save(new DynamicObject[]{log});
+        } catch (Exception e) {
+            throw new KDBizException("生成日志异常:" + e);
         }
     }
 
+    /**
+     * @param formId      单据标识
+     * @param billNos     单据编号
+     * @param isSuccess   是否推送成功
+     * @param pushParam   推送报文
+     * @param returnParam 返回报文
+     * @return 创建推送日志
+     */
+    public static DynamicObject createLog(String formId, String billNos, Boolean isSuccess, String pushParam, String returnParam) {
+        DynamicObject log = BusinessDataServiceHelper.newDynamicObject("nckd_em_pushlog");
+        Long id = DB.genLongId(formId);
+        CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule(log.getDataEntityType().getName(), log, null);
+        log.set("id", id);
+        log.set("billno", CodeRuleServiceHelper.getNumber(codeRule, log));
+        log.set("billstatus", "C");
+        log.set("nckd_entityobject", formId);
+        log.set("nckd_bizbillnos", billNos);
+        log.set("nckd_pushuser", RequestContext.get().getCurrUserId());
+        log.set("nckd_pushtime", new Date());
+        log.set("nckd_pushstatus", isSuccess ? "success" : "error");
+        log.set("nckd_pushparam", "点击查看报文");
+        log.set("nckd_pushparam_tag", pushParam);
+        log.set("nckd_returnparam", "点击查看报文");
+        log.set("nckd_returnparam_tag", returnParam);
+        return log;
+    }
+
+
     /**
      * @param service              接口名称
      * @param urlIsContainsService url是否包含接口名称

+ 15 - 11
nckd-fi/src/main/java/nckd/fi/er/message/SendMsgToWeChatOA.java

@@ -24,6 +24,7 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.IOException;
+import java.net.URLEncoder;
 import java.util.*;
 
 /**
@@ -49,20 +50,16 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
     public void sendMessage(MessageContext ctx, MessageInfo message) {
         super.sendMessage(ctx, message);
         log.info("-----------------------------------------"+"微信公众号发送提醒信息:" +message.getMessageContent().getLocaleValue_zh_CN()+" begin--------------------------------------------------");
-        //微信公众号消息推送地址
-        String mobUrl = message.getMobContentUrl();
-        //微信公众号消息推送地址
-        String contentUrl = message.getContentUrl();
         //表单数据id
         Long bizDataId = message.getBizDataId();
         if(bizDataId == null){
-            log.info("表单数据id为空");
+            log.info("表单数据id为空,跳过微信公众号消息发送");
             return;
         }
         //表单标识
         String entityNumber = message.getEntityNumber();
         if(StringUtils.isEmpty(entityNumber)){
-            log.info("表单标识为空");
+            log.info("表单标识为空,跳过微信公众号消息发送");
             return;
         }
 
@@ -71,6 +68,8 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
 
         //从系统参数中获取以下参数值
         Map<String, Object> sysCtrlParamMap = sysCtrlParam(entityNumber);
+        //域名
+        String domain = (String) sysCtrlParamMap.get("nckd_domain");
         //微信获取token地址
         String url = (String) sysCtrlParamMap.get("nckd_tokenurl");
         //公众号appid
@@ -115,10 +114,14 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
             //微信公众号对应跳转信息
             Map<String, String> nckdRes = getResMap(entityNumber, (String) sysCtrlParamMap.get("nckd_res"));
             //拼接移动端供应商跳转路径
-            String msgUrl = "http://erp-test.jxctly.com/ierp/mobile.html?"+nckdRes.get("nckd_rescode")+bizDataId +"&accountId="+ RequestContext.get().getAccountId();
-            log.info("供应商跳转路径msgUrl:"+msgUrl);
+            String msgUrl = domain+"/ierp/mobile.html?"+nckdRes.get("nckd_rescode")+bizDataId +"&accountId="+ RequestContext.get().getAccountId();
+            //Url编码
+            String encodeUrl = URLEncoder.encode(msgUrl);
 
-            requestJson.put("url",msgUrl);
+            log.info("供应商跳转路径msgUrl:"+msgUrl+" Url编码:"+encodeUrl);
+
+            String AllUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appid+"&redirect_uri=" +encodeUrl+"&response_type=code&scope=snsapi_userinfo&state=wxgzh_split_"+appid+"_split_" +appsecret+"#wechat_redirect";
+            requestJson.put("url",AllUrl);
             requestJson.put("client_msg_id",id);
             //组装data参数
             JSONObject dataJson = madeJsonObject(entityNumber,bizDataId);
@@ -159,8 +162,7 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
         }else{
             throw new KDBizException("推送公众号消息失败,获取token失败!");
         }
-
-
+        log.info("-----------------------------------------"+"微信公众号发送提醒信息:" +message.getMessageContent().getLocaleValue_zh_CN()+" end--------------------------------------------------");
     }
 
     /**
@@ -236,6 +238,8 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
     private Map<String, Object> sysCtrlParam(String entityNumber) {
         //获取采购应用参数
         Map<String, Object> sysCtrlParamMap = ParamUtils.getSysCtrlParameter(ParamUtils.PM);
+        //域名
+        sysCtrlParamMap.get("nckd_domain");
         //微信获取token地址
         sysCtrlParamMap.get("nckd_tokenurl");
         //公众号appid

+ 6 - 1
nckd-fi/src/main/java/nckd/fi/er/opplugin/AccommodationPushOpPlugin.java

@@ -4,10 +4,13 @@ import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 import kd.bos.entity.plugin.PreparePropertysEventArgs;
 import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
 import nckd.base.common.utils.TripSyncBillUtils;
 import nckd.base.common.utils.TripSyncUtils;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -36,9 +39,11 @@ public class AccommodationPushOpPlugin extends AbstractOperationServicePlugIn {
      * @param accommodation 住宿补助标准
      */
     private void pushSYDHotelTravelStandards(DynamicObject accommodation) {
+
         //将住宿补助标准单据数据转换成接口的业务数据
         Map<String, Object> data = TripSyncBillUtils.getAccommodationDataParam(accommodation);
         //推送API
-        TripSyncUtils.pushApi("syncDHotelTravelStandards", Boolean.TRUE, data);
+        TripSyncUtils.pushApi("syncDHotelTravelStandards", Boolean.TRUE, data, accommodation);
+
     }
 }

+ 6 - 3
nckd-fi/src/main/java/nckd/fi/er/opplugin/GzwPushOpPlugin.java

@@ -1,7 +1,9 @@
 package nckd.fi.er.opplugin;
 
 import com.alibaba.fastjson.JSONObject;
+import kd.bos.dataentity.entity.CloneUtils;
 import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.utils.OrmUtils;
 import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 import kd.bos.entity.plugin.PreparePropertysEventArgs;
 import kd.bos.entity.plugin.args.AfterOperationArgs;
@@ -50,10 +52,11 @@ public abstract class GzwPushOpPlugin extends AbstractOperationServicePlugIn {
      * @param dynamicObjects 业务单据数据
      */
     protected void pushGzw(DynamicObject[] dynamicObjects) {
-        //重新创建数组,如果报错,修改了单据的数据无法还原,所以此处用新数组进行处理
+        CloneUtils cloneUtils = new CloneUtils(false, false);
+        //复制单据,如果报错,修改了单据的数据无法还原,所以此处用新数组进行处理
         DynamicObject[] bills = new DynamicObject[dynamicObjects.length];
         for (int i = 0; i < dynamicObjects.length; i++) {
-            bills[i] = dynamicObjects[i];
+            bills[i] = (DynamicObject) cloneUtils.clone(dynamicObjects[i]);
         }
         // 获取费控系统参数
         Map<String, Object> sysCtrlParameter = ParamUtils.getSysCtrlParameter(ParamUtils.EM);
@@ -186,7 +189,7 @@ public abstract class GzwPushOpPlugin extends AbstractOperationServicePlugIn {
         }
 
         if (!successList.isEmpty()) {
-            SaveServiceHelper.save(successList.toArray(new DynamicObject[0]));
+            SaveServiceHelper.update(successList.toArray(new DynamicObject[0]));
         }
         //创建日志
         if (!logList.isEmpty()) {

+ 4 - 1
nckd-fi/src/main/java/nckd/fi/er/opplugin/ReimburseLevelOpPlugin.java

@@ -4,10 +4,13 @@ import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 import kd.bos.entity.plugin.PreparePropertysEventArgs;
 import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
 import nckd.base.common.utils.TripSyncBillUtils;
 import nckd.base.common.utils.TripSyncUtils;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -39,6 +42,6 @@ public class ReimburseLevelOpPlugin extends AbstractOperationServicePlugIn {
         //将出差地域单据数据转换成接口的业务数据
         Map<String, Object> data = TripSyncBillUtils.getReimburseLevelDataParam(reimburseLevel);
         //推送API
-        TripSyncUtils.pushApi("syncBasicData", Boolean.TRUE, data);
+        TripSyncUtils.pushApi("syncBasicData", Boolean.TRUE, data,reimburseLevel);
     }
 }

+ 5 - 1
nckd-fi/src/main/java/nckd/fi/er/opplugin/TripAreaPushOpPlugin.java

@@ -4,10 +4,13 @@ import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 import kd.bos.entity.plugin.PreparePropertysEventArgs;
 import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
 import nckd.base.common.utils.TripSyncBillUtils;
 import nckd.base.common.utils.TripSyncUtils;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -39,6 +42,7 @@ public class TripAreaPushOpPlugin extends AbstractOperationServicePlugIn {
         //将出差地域单据数据转换成接口的业务数据
         Map<String, Object> data = TripSyncBillUtils.getTripAreaBillDataParam(tripArea);
         //推送API
-        TripSyncUtils.pushApi("syncCityClassificationCommon", Boolean.FALSE, data);
+        TripSyncUtils.pushApi("syncCityClassificationCommon", Boolean.FALSE, data,tripArea);
+
     }
 }

+ 4 - 1
nckd-fi/src/main/java/nckd/fi/er/opplugin/VehicleStdPushOpPlugin.java

@@ -4,10 +4,13 @@ import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 import kd.bos.entity.plugin.PreparePropertysEventArgs;
 import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
 import nckd.base.common.utils.TripSyncBillUtils;
 import nckd.base.common.utils.TripSyncUtils;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -47,6 +50,6 @@ public class VehicleStdPushOpPlugin extends AbstractOperationServicePlugIn {
         //将交通工具标准单据数据转换成接口的业务数据
         Map<String, Object> data = TripSyncBillUtils.getVehicleStdDataParam(vehicleStd);
         //推送API
-        TripSyncUtils.pushApi(stdType.equals("train") ? "syncTrainTravelStandards" : "syncDTicketTravelStandards", Boolean.TRUE, data);
+        TripSyncUtils.pushApi(stdType.equals("train") ? "syncTrainTravelStandards" : "syncDTicketTravelStandards", Boolean.TRUE, data,vehicleStd);
     }
 }