瀏覽代碼

测试

Signed-off-by: EDZ <1>
EDZ 3 年之前
父節點
當前提交
2876a94f7b

+ 608 - 3
src/main/java/net/chenlin/dp/common/openapi4j/examples/voucher/VoucherAdd.java

@@ -1,6 +1,8 @@
 package net.chenlin.dp.common.openapi4j.examples.voucher;
 
+import com.mysql.cj.util.StringUtils;
 import net.chenlin.dp.common.utils.DateUtils;
+import net.sf.json.JSONArray;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -11,6 +13,7 @@ import net.chenlin.dp.common.openapi4j.service.VoucherService;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.math.BigDecimal;
 import java.util.*;
 
 /**
@@ -26,7 +29,7 @@ public class VoucherAdd {
     final static Logger logger = LoggerFactory.getLogger(VoucherAdd.class);
 
     /**
-     * 新增凭证
+     * 新增凭证(备用金)
      * @param map 数据
      * @param biz_id  唯一来源id
      * @param type 数据源 1昆山,3潍坊
@@ -74,7 +77,7 @@ public class VoucherAdd {
 //        entryCreditMap.put("document_id","321654");
 //        entryCreditMap.put("exchange_rate2","0");
         entryCreditMap.put("abstract",map.get("abstract"));
-        entryCreditMap.put("account_code",map.get("account_code"));
+        entryCreditMap.put("account_code",map.get("account_code_df"));
 //        entryCreditMap.put("entry_id","0");//
         entryCreditMap.put("natural_credit_currency",map.get("naturalCurrency"));//本币贷方发生额*与本币借方发生额不能同时为空
 //        entryCreditMap.put("primary_credit_amount","0");//
@@ -113,7 +116,7 @@ public class VoucherAdd {
 //        entryDebitMap.put("document_date","2021-09-18");
 //        entryDebitMap.put("document_id","123456");
 //        entryDebitMap.put("exchange_rate2","0");
-        entryDebitMap.put("account_code",map.get("account_code"));
+        entryDebitMap.put("account_code",map.get("account_code_jf"));
 //
         entryDebitMap.put("natural_debit_currency",map.get("naturalCurrency"));//本币贷方发生额*与本币借方发生额不能同时为空
 //        entryDebitMap.put("primary_debit_amount","0");//
@@ -142,5 +145,607 @@ public class VoucherAdd {
         }
 
     }
+    /**
+     * 新增凭证(报销单)
+     * @param map 数据
+     * @param biz_id  唯一来源id
+     * @param type 数据源 1昆山,3潍坊
+     */
+    public static String addVoucherNew(Map<String,Object> map,String biz_id,String type) {
+        //1昆山,3潍坊
+        Map<String,Object> jsonBodyMap = new HashMap<>();
+        Map<String,Object> voucher = new HashMap<>();//凭证数据详情
+
+        voucher.put("voucher_type","记");//凭证类别
+        voucher.put("date", DateUtils.format(new Date()));//制单日期
+        voucher.put("enter","OA");//制单人名称
+
+        BigDecimal allNum = new BigDecimal("0");//总金额(所有未税金额和税额之和,用作贷方金额)
+
+        Map<String,Object> debit = new HashMap<>();                     //voucher > debit
+        List<Map<String,Object>> entryDebit = new ArrayList<>();        //voucher > debit > entryDebit
+
+        String bm = map.get("申请人所属部门").toString();
+
+        if(map.get("其他报销科目") != null){
+            JSONArray jsonArray = JSONArray.fromObject(map.get("其他报销科目").toString());
+            if(jsonArray.size() > 0){
+                for(int i=0;i<jsonArray.size();i++){
+                    net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                    String bxKm = object.get("报销科目").toString();
+                    /**
+                     * 获取科目编码
+                     */
+                    String account_code = null;
+                    if(type.equals("3")){//山东
+                        account_code = getCodeSD(bm,bxKm);
+                    }else{
+                        account_code = getCode(bm,bxKm);
+                    }
+
+                    String mingC = bxKm;
+                    if(object.get("名称") != null){
+                        mingC = object.get("名称").toString();
+                    }
+                    BigDecimal jinE = new BigDecimal(object.get("未税金额").toString());
+                    BigDecimal sl = new BigDecimal(object.get("数量").toString());
+
+                    if(object.get("税额") != null){
+                        BigDecimal se = new BigDecimal(object.get("税额").toString());
+                        Map<String,Object> entryDebitMap = new HashMap<>();             //voucher > debit > entryDebit > entryDebitMap
+
+                        Map<String,Object> auxiliaryDebit = new HashMap<>();
+                        auxiliaryDebit.put("dept_id",map.get("dept_code"));
+                        auxiliaryDebit.put("personnel_id",map.get("job_number"));
+
+                        if(map.containsKey("item_class")){
+                            auxiliaryDebit.put("item_class","00");//项目大类
+                            auxiliaryDebit.put("item_id","YFYYYY00001-99");//项目档案
+                        }
+                        entryDebitMap.put("auxiliary",auxiliaryDebit);
+                        entryDebitMap.put("abstract",mingC+"/税额");
+//                        entryDebitMap.put("account_code",map.get("account_code"));
+                        String seCode = getCodeSE(bxKm);
+                        entryDebitMap.put("account_code",seCode);
+//
+                        entryDebitMap.put("natural_debit_currency",se.multiply(sl));//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                        if(se.compareTo(new BigDecimal("0")) != 0){
+                            entryDebit.add(entryDebitMap);
+                            allNum = allNum.add(se.multiply(sl));
+                        }
+
+                    }
+
+                    Map<String,Object> entryDebitMap = new HashMap<>();             //voucher > debit > entryDebit > entryDebitMap
+        //        List<Map<String,Object>> cash_flowListDebit = new ArrayList<>();//voucher > debit > entryDebit > entryDebitMap > cash_flowListDebit
+        //        Map<String,Object> cash_flowMapDebit = new HashMap<>();         //voucher > debit > entryDebit > entryDebitMap > cash_flowListDebit > cash_flowMapDebit
+        //
+        //        cash_flowMapDebit.put("natural_credit_currency","0.00");
+        //        cash_flowMapDebit.put("natural_debit_currency","4.00");
+        //        cash_flowMapDebit.put("cdept_id","021");
+        //        cash_flowMapDebit.put("cperson_id","CHK2019001");
+        //        cash_flowListDebit.add(cash_flowMapDebit);
+        //        entryDebitMap.put("cash_flow",cash_flowListDebit);
+
+                    Map<String,Object> auxiliaryDebit = new HashMap<>();
+                    auxiliaryDebit.put("dept_id",map.get("dept_code"));
+                    auxiliaryDebit.put("personnel_id",map.get("job_number"));
+
+                    if(map.containsKey("item_class")){
+                        auxiliaryDebit.put("item_class","00");//项目大类
+                        auxiliaryDebit.put("item_id","YFYYYY00001-99");//项目档案
+                    }
+                    entryDebitMap.put("auxiliary",auxiliaryDebit);
+                    entryDebitMap.put("abstract",mingC);
+//                    entryDebitMap.put("account_code",map.get("account_code"));
+                    entryDebitMap.put("account_code",account_code);
+                    entryDebitMap.put("natural_debit_currency",jinE.multiply(sl));//(末税金额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                    entryDebit.add(entryDebitMap);
+                    allNum = allNum.add(jinE.multiply(sl));
+                }
+            }
+        }
+
+        if(map.get("差旅报销") != null){
+            JSONArray jsonArray = JSONArray.fromObject(map.get("差旅报销").toString());
+            if(jsonArray.size() > 0){
+                for(int i=0;i<jsonArray.size();i++){
+
+                    net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+
+                    String bxKm = object.get("报销科目").toString();
+                    /**
+                     * 获取科目编码
+                     */
+                    String account_code = null;
+                    if(type.equals("3")){//山东
+                        account_code = getCodeSD(bm,bxKm);
+                    }else{
+                        account_code = getCode(bm,bxKm);
+                    }
+
+                    String mingC = bxKm;
+                    if(object.get("名称") != null){
+                        mingC = object.get("名称").toString();
+                    }
+                    BigDecimal jinE = new BigDecimal(object.get("未税金额").toString());
+                    BigDecimal sl = new BigDecimal(object.get("次数").toString());
+
+                    if(object.get("税额") != null){
+                        BigDecimal se = new BigDecimal(object.get("税额").toString());
+                        Map<String,Object> entryDebitMap = new HashMap<>();             //voucher > debit > entryDebit > entryDebitMap
+
+                        Map<String,Object> auxiliaryDebit = new HashMap<>();
+                        auxiliaryDebit.put("dept_id",map.get("dept_code"));
+                        auxiliaryDebit.put("personnel_id",map.get("job_number"));
+
+                        if(map.containsKey("item_class")){
+                            auxiliaryDebit.put("item_class","00");//项目大类
+                            auxiliaryDebit.put("item_id","YFYYYY00001-99");//项目档案
+                        }
+                        entryDebitMap.put("auxiliary",auxiliaryDebit);
+                        entryDebitMap.put("abstract",mingC+"/税额");
+//                        entryDebitMap.put("account_code",map.get("account_code"));
+                        String seCode = getCodeSE(bxKm);
+                        entryDebitMap.put("account_code",seCode);
+//
+                        entryDebitMap.put("natural_debit_currency",se.multiply(sl));//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                        if(se.compareTo(new BigDecimal("0")) != 0){
+                            entryDebit.add(entryDebitMap);
+                            allNum = allNum.add(se.multiply(sl));
+                        }
+
+                    }else{
+                        if("飞机、火车".contains(bxKm)){
+                            Map<String,Object> entryDebitMap = new HashMap<>();             //voucher > debit > entryDebit > entryDebitMap
+
+                            Map<String,Object> auxiliaryDebit = new HashMap<>();
+                            auxiliaryDebit.put("dept_id",map.get("dept_code"));
+                            auxiliaryDebit.put("personnel_id",map.get("job_number"));
+
+                            if(map.containsKey("item_class")){
+                                auxiliaryDebit.put("item_class","00");//项目大类
+                                auxiliaryDebit.put("item_id","YFYYYY00001-99");//项目档案
+                            }
+                            entryDebitMap.put("auxiliary",auxiliaryDebit);
+                            entryDebitMap.put("abstract",mingC+"/税额");
+                            String seCode = getCodeSE(bxKm);
+                            entryDebitMap.put("account_code",seCode);
+                            //当报销科目为火车,飞机时,税率自动计算(税额=未税金额*9%)
+                            BigDecimal lv = new BigDecimal("0.09");
+                            BigDecimal multiply = jinE.multiply(lv).multiply(sl);
+                            multiply = multiply.setScale(2,BigDecimal.ROUND_HALF_UP);
+                            entryDebitMap.put("natural_debit_currency", multiply);//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+
+                            entryDebit.add(entryDebitMap);
+                            allNum = allNum.add(multiply);
+
+                        }
+                    }
+
+                    Map<String,Object> entryDebitMap = new HashMap<>();             //voucher > debit > entryDebit > entryDebitMap
+
+                    Map<String,Object> auxiliaryDebit = new HashMap<>();
+                    auxiliaryDebit.put("dept_id",map.get("dept_code"));
+                    auxiliaryDebit.put("personnel_id",map.get("job_number"));
+
+                    if(map.containsKey("item_class")){
+                        auxiliaryDebit.put("item_class","00");//项目大类
+                        auxiliaryDebit.put("item_id","YFYYYY00001-99");//项目档案
+                    }
+                    entryDebitMap.put("auxiliary",auxiliaryDebit);
+                    entryDebitMap.put("abstract",mingC);
+//                    entryDebitMap.put("account_code",map.get("account_code"));
+                    entryDebitMap.put("account_code",account_code);
+                    entryDebitMap.put("natural_debit_currency",jinE.multiply(sl));//(末税金额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                    entryDebit.add(entryDebitMap);
+                    allNum = allNum.add(jinE.multiply(sl));
+                }
+            }
+        }
+        if(map.get("私车公用报销") != null){
+            JSONArray jsonArray = JSONArray.fromObject(map.get("私车公用报销").toString());
+            if(jsonArray.size() > 0){
+                for(int i=0;i<jsonArray.size();i++){
+                    net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                    String bxKm = object.get("报销科目").toString();
+                    /**
+                     * 获取科目编码
+                     */
+                    String account_code = null;
+                    if(type.equals("3")){//山东
+                        account_code = getCodeSD(bm,bxKm);
+                    }else{
+                        account_code = getCode(bm,bxKm);
+                    }
+
+                    BigDecimal jinE = new BigDecimal(object.get("未税金额").toString());
+                    BigDecimal sl = new BigDecimal(object.get("次数").toString());
+
+                    if(object.get("税额") != null){
+                        BigDecimal se = new BigDecimal(object.get("税额").toString());
+                        Map<String,Object> entryDebitMap = new HashMap<>();             //voucher > debit > entryDebit > entryDebitMap
+
+                        Map<String,Object> auxiliaryDebit = new HashMap<>();
+                        auxiliaryDebit.put("dept_id",map.get("dept_code"));
+                        auxiliaryDebit.put("personnel_id",map.get("job_number"));
+
+                        if(map.containsKey("item_class")){
+                            auxiliaryDebit.put("item_class","00");//项目大类
+                            auxiliaryDebit.put("item_id","YFYYYY00001-99");//项目档案
+                        }
+                        entryDebitMap.put("auxiliary",auxiliaryDebit);
+                        entryDebitMap.put("abstract",bxKm+"/税额");
+//                        entryDebitMap.put("account_code",map.get("account_code"));
+                        String seCode = getCodeSE(bxKm);
+                        entryDebitMap.put("account_code",seCode);
+//
+                        entryDebitMap.put("natural_debit_currency",se.multiply(sl));//(税额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                        if(se.compareTo(new BigDecimal("0")) != 0){
+                            entryDebit.add(entryDebitMap);
+                            allNum = allNum.add(se.multiply(sl));
+                        }
+
+                    }
+
+                    Map<String,Object> entryDebitMap = new HashMap<>();             //voucher > debit > entryDebit > entryDebitMap
+
+                    Map<String,Object> auxiliaryDebit = new HashMap<>();
+                    auxiliaryDebit.put("dept_id",map.get("dept_code"));
+                    auxiliaryDebit.put("personnel_id",map.get("job_number"));
+
+                    if(map.containsKey("item_class")){
+                        auxiliaryDebit.put("item_class","00");//项目大类
+                        auxiliaryDebit.put("item_id","YFYYYY00001-99");//项目档案
+                    }
+                    entryDebitMap.put("auxiliary",auxiliaryDebit);
+                    entryDebitMap.put("abstract",bxKm);
+//                    entryDebitMap.put("account_code",map.get("account_code"));
+                    entryDebitMap.put("account_code",account_code);
+                    entryDebitMap.put("natural_debit_currency",jinE.multiply(sl));//(末税金额*数量) 本币贷方发生额*与本币借方发生额不能同时为空
+                    entryDebit.add(entryDebitMap);
+                    allNum = allNum.add(jinE.multiply(sl));
+                }
+            }
+        }
+
+
+        debit.put("entry",entryDebit);
+        voucher.put("debit",debit);//借方
+
+
+
+        Map<String,Object> credit = new HashMap<>();                     //voucher > credit
+        List<Map<String,Object>> entryCredit = new ArrayList<>();        //voucher > credit > entryCredit
+        Map<String,Object> entryCreditMap = new HashMap<>();             //voucher > credit > entryCredit > entryCreditMap
+//        List<Map<String,Object>> cash_flowListCredit = new ArrayList<>();//voucher > credit > entryCredit > entryCreditMap > cash_flowListCredit
+//        Map<String,Object> cash_flowMapCredit = new HashMap<>();         //voucher > credit > entryCredit > entryCreditMap > cash_flowListCredit > cash_flowMapCredit
+//
+//        cash_flowMapCredit.put("natural_credit_currency","0.00");
+//        cash_flowMapCredit.put("natural_debit_currency","4.00");
+//        cash_flowMapCredit.put("cdept_id","021");
+//        cash_flowMapCredit.put("cperson_id","CHK2019001");
+//        cash_flowListCredit.add(cash_flowMapCredit);
+//        entryCreditMap.put("cash_flow",cash_flowListCredit);
+
+        Map<String,Object> auxiliaryCredit = new HashMap<>();
+        auxiliaryCredit.put("dept_id",map.get("dept_code"));
+        auxiliaryCredit.put("personnel_id",map.get("job_number"));
+
+        if(map.containsKey("item_class")){
+            auxiliaryCredit.put("item_class","00");//项目大类
+            auxiliaryCredit.put("item_id","YFYYYY00001-99");//项目档案
+        }
+
+        entryCreditMap.put("auxiliary",auxiliaryCredit);
+
+        entryCreditMap.put("abstract","费用报销");
+//        entryCreditMap.put("account_code",map.get("account_code"));
+
+        entryCreditMap.put("account_code","10020101");//贷方科目固定
+
+//        entryCreditMap.put("natural_credit_currency",map.get("naturalCurrency"));//本币贷方发生额*与本币借方发生额不能同时为空
+        entryCreditMap.put("natural_credit_currency",allNum);//本币贷方发生额*与本币借方发生额不能同时为空
+        entryCredit.add(entryCreditMap);
+        credit.put("entry",entryCredit);
+        voucher.put("credit",credit);//贷方
+
+        System.out.println(allNum);
+        jsonBodyMap.put("voucher",voucher);
+
+        JSONObject json = new JSONObject(jsonBodyMap);
+        String jsonBody = json.toJSONString();
+
+        VoucherService voucherService = new VoucherService();
+        try {
+            JSONObject record = voucherService.add(jsonBody, biz_id,type);
+            logger.info(record.toString());
+            return record.toString();
+        } catch (OpenAPIException e) {
+            e.printStackTrace();
+            StringWriter sw = new StringWriter();
+            e.printStackTrace(new PrintWriter(sw, true));
+            String str = sw.toString();
+            if(StringUtils.isNullOrEmpty(str)){
+                str = "数据异常,未进行同步";
+            }
+            return str;
+        }
+    }
+
+
+    /**
+     * 获取税额科目编码
+     * @return
+     */
+    public static String getCodeSE(String type){
+        if("飞机、火车".contains(type)){
+            return "2221030504";
+        }else if("高速通行费".contains(type)){
+            return "2221030505";
+        }else{
+            return "2221030501";
+        }
+
+    }
+
+    /**
+     * 通过报销科目、部门,获取报销科目编码
+     * @param dept 部门
+     * @param type 科目
+     * @return
+     */
+    public static String getCode(String dept,String type){
+
+          if(dept.equals("营销设计中心-销售部")){
+            //OA差旅报销
+            if("飞机、火车、出租车、轮渡".contains(type)){
+                return "6601070101";
+            }else if("租车费".contains(type)){
+                return "66020702";
+            }else if("酒店、住宿费".contains(type)){
+                return "6601070104";
+            }else if("餐饮费".contains(type)){
+                return "66010201";
+            }else if("宴客费".contains(type)){
+                return "660106";
+            }else if("误餐补贴".contains(type)){
+                return "6601070105";
+            }
+            //OA私车公用报销
+            else if("汽车租赁费、高速通行费、停车费、汽油费".contains(type)){
+                return "6601070102";
+            }
+            //OA其他报销科目
+            else if("零星采买、文件打印费".contains(type)){
+                return "660110";
+            }else if("展会宣传、展位布置".contains(type)){
+                return "66011802";
+            }else if("邮寄/物流".contains(type)){
+                return "66012003";
+            }else if("全员聚餐费".contains(type)){
+                return "66010205";
+            }else if("其他费用".contains(type)){
+                return "660124";
+            }else if("公出打车费".contains(type)){
+                return "6601070102";
+            }else if("移动开发费".contains(type)){
+                return "66012001";
+            }
+            else{
+                return "66010208";
+            }
+        }else if(dept.equals("营销设计中心-设计部")){
+            //OA差旅报销
+            if("飞机、火车、出租车、轮渡".contains(type)){
+                return "66040701";
+            }else if("租车费".contains(type)){
+                return "66020702";
+            }else if("酒店、住宿费".contains(type)){
+                return "66040704";
+            }else if("餐饮费".contains(type)){
+                return "66040201";
+            }else if("宴客费".contains(type)){
+                return "660406";
+            }else if("误餐补贴".contains(type)){
+                return "66040705";
+            }
+            //OA私车公用报销
+            else if("汽车租赁费、高速通行费、停车费、汽油费".contains(type)){
+                return "66040702";
+            }
+            //OA其他报销科目
+            else if("零星采买、文件打印费".contains(type)){
+                return "660423";
+            }else if("展会宣传、展位布置".contains(type)){
+                return "66041801";
+            }else if("邮寄/物流".contains(type)){
+                return "66042003";
+            }else if("全员聚餐费".contains(type)){
+                return "66040205";
+            }else if("其他费用".contains(type)){
+                return "66040113";
+            }else if("公出打车费".contains(type)){
+                return "66040701";
+            }else if("移动开发费".contains(type)){
+                return "66042001";
+            }
+            else{//OA差旅报销-其他
+                return "66040113";
+            }
+        }else if(dept.equals("营销设计中心-项目部") || dept.equals("营销设计中心-市场部")){
+            //OA差旅报销
+            if("飞机、火车、出租车、轮渡".contains(type)){
+                return "6601070101";
+            }else if("租车费".contains(type)){
+                return "66020702";
+            }else if("酒店、住宿费".contains(type)){
+                return "6601070104";
+            }else if("餐饮费".contains(type)){
+                return "66010201";
+            }else if("宴客费".contains(type)){
+                return "660106";
+            }else if("误餐补贴".contains(type)){
+                return "6601070105";
+            }
+            //OA私车公用报销
+            else if("汽车租赁费、高速通行费、停车费、汽油费".contains(type)){
+                return "6601070102";
+            }
+            //OA其他报销科目
+            else if("零星采买、文件打印费".contains(type)){
+                return "660110";
+            }else if("展会宣传、展位布置".contains(type)){
+                return "66011802";
+            }else if("邮寄/物流".contains(type)){
+                return "66012003";
+            }else if("全员聚餐费".contains(type)){
+                return "66010205";
+            }else if("其他费用".contains(type)){
+                return "660124";
+            }else if("公出打车费".contains(type)){
+                return "6601070102";
+            }else if("移动开发费".contains(type)){
+                return "66012001";
+            }
+            else{//OA差旅报销-其他
+                return "66010208";
+            }
+        }else{
+            //OA差旅报销
+            if("飞机、火车、出租车、轮渡".contains(type)){
+                return "66020701";
+            }else if("租车费".contains(type)){
+                return "66020702";
+            }else if("酒店、住宿费".contains(type)){
+                return "66020704";
+            }else if("餐饮费".contains(type)){
+                return "66020201";
+            }else if("宴客费".contains(type)){
+                return "660206";
+            }else if("误餐补贴".contains(type)){
+                return "66020705";
+            }
+            //OA私车公用报销
+            else if("汽车租赁费、高速通行费、停车费、汽油费".contains(type)){
+                return "66020702";
+            }
+            //OA其他报销科目
+            else if("零星采买、文件打印费".contains(type)){
+                return "660223";
+            }else if("展会宣传、展位布置".contains(type)){
+                return "66021801";
+            }else if("邮寄/物流".contains(type)){
+                return "66022003";
+            }else if("全员聚餐费".contains(type)){
+                return "66020205";
+            }else if("其他费用".contains(type)){
+                return "66020208";
+            }else if("公出打车费".contains(type)){
+                return "66020701";
+            }else if("移动开发费".contains(type)){
+                return "66021801";
+            }
+            else{//OA差旅报销-其他
+                return "66020706";
+            }
+        }
+
+    }
+   /**
+     * 通过报销科目、部门,获取报销科目编码(山东)
+     * @param dept 部门
+     * @param type 科目
+     * @return
+     */
+    public static String getCodeSD(String dept,String type){
+
+        if(dept.equals("营销设计中心-总经理室") || dept.equals("营销设计中心-采购部") || dept.equals("共享中心-财务部")
+                || dept.equals("共享中心-人事行政部")){
+
+            //OA差旅报销
+            if("飞机、火车、出租车、租车费、轮渡".contains(type)){
+                return "66020701";
+            }else if("酒店、住宿费".contains(type)){
+                return "66020704";
+            }else if("餐饮费".contains(type)){
+                return "660227";
+            }else if("宴客费".contains(type)){
+                return "660227";
+            }else if("误餐补贴".contains(type)){
+                return "66020705";
+            }
+            //OA私车公用报销
+            else if("高速通行费、停车费、汽油费".contains(type)){
+                return "66020702";
+            }else if("汽车租赁费".contains(type)){
+                return "66021105";
+            }
+            //OA其他报销科目
+            else if("零星采买、文件打印费".contains(type)){
+                return "660223";
+            }else if("展会宣传、展位布置".contains(type)){
+                return "66021801";
+            }else if("邮寄/物流".contains(type)){
+                return "66022003";
+            }else if("全员聚餐费".contains(type)){
+                return "66020201";
+            }else if("其他费用".contains(type)){
+                return "660229";
+            }else if("公出打车费".contains(type)){
+                return "66020701";
+            }else if("移动开发费".contains(type)){
+                return "660223";
+            }
+            else{//OA差旅报销-其他
+                return "66020706";
+            }
+        }else{
+            //OA差旅报销
+            if("飞机、火车、出租车、租车费、轮渡".contains(type)){
+                return "51010701";
+            }else if("酒店、住宿费".contains(type)){
+                return "51010704";
+            }else if("餐饮费".contains(type)){
+                return "660227";
+            }else if("宴客费".contains(type)){
+                return "660227";
+            }else if("误餐补贴".contains(type)){
+                return "51010705";
+            }
+            //OA私车公用报销
+            else if("汽车租赁费、高速通行费、停车费、汽油费".contains(type)){
+                return "51010702";
+            }
+            //OA其他报销科目
+            else if("零星采买、文件打印费".contains(type)){
+                return "510122";
+            }else if("展会宣传、展位布置".contains(type)){
+                return "51011601";
+            }else if("邮寄/物流".contains(type)){
+                return "51011302";
+            }else if("全员聚餐费".contains(type)){
+                return "51010201";
+            }else if("其他费用".contains(type)){
+                return "510127";
+            }else if("公出打车费".contains(type)){
+                return "51010701";
+            }else if("移动开发费".contains(type)){
+                return "510122";
+            }
+            else{//OA差旅报销-其他
+                return "51010706";
+            }
+        }
+
+    }
+
+    public static void main(String[] args) {
+        BigDecimal se = new BigDecimal("0.0");
+        if(se.compareTo(new BigDecimal("0")) == 0){
+            System.out.println(getCode("营销设计中心-销售部","邮寄/物流"));
+        }
+
+    }
 
 }

+ 1 - 1
src/main/java/net/chenlin/dp/common/openapi4j/service/VoucherService.java

@@ -45,7 +45,7 @@ public class VoucherService extends BaseService {
         try {
             Properties prop = PropUtil.getProperties("/config.properties");
             String to_account = prop.getProperty("to_account");
-//            String tradeId = TradeService.getTradeId();
+            String tradeId = TradeService.getTradeId();
             Map<String, String> paramMap = new HashMap();
             paramMap.put("to_account", to_account);
 //            paramMap.put("tradeid", tradeId);

+ 25 - 14
src/main/java/net/chenlin/dp/modules/TaskDemo.java

@@ -24,22 +24,33 @@ public class TaskDemo {
     private  SaleOrderController controller=new SaleOrderController();
 
     /**
-     * 定时任务 备用金 同步至 u8凭证
+     * 定时任务 银行回单 同步至 u8凭证
      */
-    public static void autoUpdataPettyJob() throws Exception {
+    public static void autoReimbursementNew() throws Exception {
+        ReimbursementService reimbursementService = new ReimbursementService();
+        reimbursementService.autoReimbursementNew();
+        System.out.println("==================================");
+        System.out.println("===========银行回单 同步至 u8凭证任务执行 "+ DateUtils.getNowTime()+" ============" );
+        System.out.println("==================================");
+    }
+
+   /**
+     * 定时任务 备用金 同步至 银行回单
+     */
+    public static void autoOABankPetty() throws Exception {
         PettyCashService pettyCashService = new PettyCashService();
-        pettyCashService.autoUpdataPetty();
+        pettyCashService.autoOABankPetty();
         System.out.println("==================================");
         System.out.println("===========备用金定时任务执行 "+ DateUtils.getNowTime()+" ============" );
         System.out.println("==================================");
     }
 
     /**
-     * 定时任务 报销申请 同步至 u8凭证
+     * 定时任务 报销申请 同步至 银行回单
      */
-    public static void autoReimbursementJob() throws Exception {
+    public static void autoOABankReceipt() throws Exception {
         ReimbursementService reimbursementService = new ReimbursementService();
-        reimbursementService.autoReimbursement();
+        reimbursementService.autoOABankReceipt();
         System.out.println("==================================");
         System.out.println("===========报销申请定时任务执行 "+ DateUtils.getNowTime()+" ============" );
         System.out.println("==================================");
@@ -157,7 +168,7 @@ public class TaskDemo {
     }
 
     /**
-     * 定时任务 crm调用存储过程 同步客户档案
+     * 定时任务 crm 同步客户档案
      * @throws OpenAPIException
      */
     public void autoCallCustomer() throws OpenAPIException {
@@ -168,7 +179,7 @@ public class TaskDemo {
     }
 
     /**
-     * 定时任务 crm调用存储过程 同步客诉单-退款
+     * 定时任务 crm 同步客诉单-退款
      * @throws OpenAPIException
      */
     public void autoCallAcceptOrder() throws OpenAPIException {
@@ -180,7 +191,7 @@ public class TaskDemo {
 
 
     /**
-     * 定时任务 crm调用存储过程 同步销售订单
+     * 定时任务 crm 同步销售订单
      * @throws OpenAPIException
      */
     public void autoCallSaleOrder() throws OpenAPIException {
@@ -191,7 +202,7 @@ public class TaskDemo {
 
 
     /**
-     * 定时任务 crm调用存储过程 同步销售报价订单
+     * 定时任务 crm 同步销售报价订单
      * @throws OpenAPIException
      */
     public void autoCallSaleOrderBJ() throws OpenAPIException {
@@ -201,7 +212,7 @@ public class TaskDemo {
     }
 
     /**
-     * 定时任务 crm调用存储过程 同步打样单
+     * 定时任务 crm 同步打样单
      * @throws OpenAPIException
      */
     public void autoCallDYD() throws OpenAPIException {
@@ -211,7 +222,7 @@ public class TaskDemo {
     }
 
     /**
-     * 定时任务 crm调用存储过程 同步送样单
+     * 定时任务 crm 同步送样单
      * @throws OpenAPIException
      */
     public void autoCallSYD() throws OpenAPIException {
@@ -221,7 +232,7 @@ public class TaskDemo {
     }
 
     /**
-     * 定时任务 crm调用存储过程 同步客诉单-抵扣
+     * 定时任务 crm 同步客诉单-抵扣
      * @throws OpenAPIException
      */
     public void autoCallKSDDK() throws OpenAPIException {
@@ -231,7 +242,7 @@ public class TaskDemo {
     }
 
     /**
-     * 定时任务 crm调用存储过程 同步客诉单-退货
+     * 定时任务 crm 同步客诉单-退货
      * @throws OpenAPIException
      */
     public void autoCallKSDTH() throws OpenAPIException {

+ 68 - 5
src/main/java/net/chenlin/dp/modules/api/controller/DingdingOpenInterface.java

@@ -77,7 +77,63 @@ public class DingdingOpenInterface {
 
             req.setProcessCode(processCode);
             Calendar nowTime = Calendar.getInstance();
-            nowTime.add(Calendar.DAY_OF_YEAR, -10);
+            nowTime.add(Calendar.DAY_OF_YEAR, -7);
+            Date date = nowTime.getTime();
+            req.setStartTime(Long.valueOf(date.getTime()));//时间戳:例1586448000000
+//            Date now = new Date();
+//            long time = 30*60*1000;//30分钟
+//            Date beforeDate = new Date(now .getTime() - time);//30分钟前的时间
+//            req.setStartTime(beforeDate.getTime());
+//            req.setEndTime(now.getTime());
+            String next_cursor = "1";
+            req.setSize(20L);
+            while (!StringUtils.isNullOrEmpty(next_cursor)){
+
+                OapiProcessinstanceListidsResponse rsp = client.execute(req, gettoken);//access_token
+                map = JSONUtils.jsonToMap(rsp.getBody());
+                if(map.get("errcode").equals(0)){
+                    Map<String,Object> mapList = (Map<String, Object>) map.get("result");
+                    if(mapList.get("next_cursor") != null){
+                        next_cursor = mapList.get("next_cursor").toString();
+                        req.setCursor(Long.valueOf(next_cursor));
+                    }else{
+                        next_cursor = "";
+                    }
+
+                    list.addAll((List<String>) mapList.get("list"));
+                }
+            }
+//            System.out.println(list);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return list;
+
+    }
+
+     /**
+     * 获取审批实例ID列表
+     * 备用金process_code:PROC-9331671D-265D-4A79-A6F2-93326D727673(备用金列表获取)
+     * 销售订单process_code:PROC-40356B7F-6825-4DC3-83B9-8AD6D0D2CA49(销售订单列表获取)
+     * 钉钉接口仅支持120天内数据
+     */
+
+    public static List<String> getOrderIdList2(String processCode,int times){
+        getToken();//获取token
+
+        Map<String,Object> map = new HashMap<>();
+        List<String> list = new ArrayList<>();
+
+        try {
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/listids");
+            OapiProcessinstanceListidsRequest req = new OapiProcessinstanceListidsRequest();
+
+            req.setProcessCode(processCode);
+            Calendar nowTime = Calendar.getInstance();
+            nowTime.add(Calendar.DAY_OF_YEAR, times);
             Date date = nowTime.getTime();
             req.setStartTime(Long.valueOf(date.getTime()));//时间戳:例1586448000000
 //            Date now = new Date();
@@ -148,13 +204,20 @@ public class DingdingOpenInterface {
      * @param map1
      * @return
      */
-    public static Map<String,Object> tableToMap(Map<String,Object> map1){
+    public static Map<String,Object> tableToMap(Map<String,Object> map1) throws Exception {
 
         List<Map<String,Object>> listMap = (List<Map<String, Object>>) map1.get("form_component_values");
         Map<String,Object> newMap = new HashMap<>();
         for(Map<String, Object> o:listMap){
             newMap.put((String) o.get("name"),o.get("value"));
             newMap.put((String) o.get("name")+"_ext_value",o.get("ext_value"));
+            if(o.get("component_type") != null && o.get("component_type").equals("RecipientAccountField")){
+                Map<String,Object> mapValue = JSONUtils.jsonToMap((String) o.get("ext_value"));
+                newMap.put("户名",mapValue.get("name"));
+                newMap.put("账号",mapValue.get("cardNo"));
+                newMap.put("开户银行",mapValue.get("instName"));
+            }
+
         }
         return newMap;
     }
@@ -217,7 +280,6 @@ public class DingdingOpenInterface {
      * @throws ApiException
      */
     public static Map<String,Object> getViewByUserId(String userId) throws Exception {
-        getToken();//获取token
         DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
         OapiV2UserGetRequest req = new OapiV2UserGetRequest();
 //        req.setUserid("2965176200854153");
@@ -226,7 +288,7 @@ public class DingdingOpenInterface {
         OapiV2UserGetResponse rsp = client.execute(req, gettoken);
         Map<String,Object> map;
         map = JSONUtils.jsonToMap(rsp.getBody());
-        System.out.println(map);
+//        System.out.println(map);
         if(map.get("errcode").equals(0)){
             Map<String,Object> mapList = (Map<String, Object>) map.get("result");
 //            System.out.println(mapList);
@@ -250,7 +312,8 @@ public class DingdingOpenInterface {
 
     public static void main(String[] args) throws Exception {
 //        getViewByUserId("2006265537678286");
-        getOrderIdList("PROC-A561B73E-8282-4780-BB05-DCBA8125C45C");
+        getOrderIdList("PROC-C1EBBC4A-AA0D-4101-BEE8-8BFA5FEFABD8");
+//        getOrderIdList("PROC-DD8FF68E-B90E-4885-8C17-F69E53BE5C81");
 //            for (Map.Entry<String, Object> entry : JSONUtils.jsonToMap(rsp.getBody()).entrySet()) {
 //                System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
 //            }

+ 259 - 20
src/main/java/net/chenlin/dp/modules/api/service/PettyCashService.java

@@ -1,7 +1,15 @@
 package net.chenlin.dp.modules.api.service;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.DingTalkClient;
+import com.dingtalk.api.request.OapiGettokenRequest;
+import com.dingtalk.api.request.OapiProcessinstanceCreateRequest;
+import com.dingtalk.api.response.OapiGettokenResponse;
+import com.dingtalk.api.response.OapiProcessinstanceCreateResponse;
 import com.mysql.cj.util.StringUtils;
+import com.taobao.api.ApiException;
 import net.chenlin.dp.common.openapi4j.examples.voucher.VoucherAdd;
 import net.chenlin.dp.common.openapi4j.exception.OpenAPIException;
 import net.chenlin.dp.common.openapi4j.service.PersonService;
@@ -11,11 +19,10 @@ import net.chenlin.dp.common.utils.SpringContextUtils;
 import net.chenlin.dp.modules.api.controller.DingdingOpenInterface;
 import net.chenlin.dp.modules.sys.entity.SyViewEntity;
 import net.chenlin.dp.modules.sys.service.testU8Service;
+import net.sf.json.JSONArray;
+import org.springframework.boot.configurationprocessor.json.JSONException;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 
 /**
  * 钉钉备用金
@@ -24,35 +31,38 @@ import java.util.Properties;
 public class PettyCashService {
 
     private testU8Service u8Service= SpringContextUtils.getBean("testU8Service",testU8Service.class);
+    public static String gettoken = "";
 
-    public void autoUpdataPetty() throws Exception {
+    public static void autoUpdataPetty() throws Exception {
 
         DingdingOpenInterface dingdingOpenInterface = new DingdingOpenInterface();
         Properties prop = PropUtil.getProperties("/config.properties");
         String PROC = prop.getProperty("byj_process_code");
         List<String> list = dingdingOpenInterface.getOrderIdList(PROC);
 //
-        List<SyViewEntity> listId = u8Service.selectView("备用金");
+
+//        List<SyViewEntity> listId = u8Service.selectView("备用金");
         if(list.size() > 0){
             outCycle:for(String o:list){
 
-                if(listId.size() > 0){
-                    for(SyViewEntity en:listId){
-                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
-                            continue outCycle;
-                        }
-                    }
-                }
+//                if(listId.size() > 0){
+//                    for(SyViewEntity en:listId){
+//                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
+//                            continue outCycle;
+//                        }
+//                    }
+//                }
 
                 String job_number = "";//工号
                 String work_place = "";//办公地(潍坊对03账套 昆山对01账套)
                 String dept_code = ""; //部门编码
                 String type = ""; //数据源账套 1昆山,3潍坊
-                Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);
-//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("0861edce-4cfb-4b1d-ac3a-19ed29ae5214");
+//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);
+                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("cecf74b9-6a7e-492f-af10-c6b37086b4e5");
                 if(StringUtils.isNullOrEmpty(map.get("result").toString()) || !map.get("result").toString().equals("agree")){
                     continue;
                 }
+//                System.out.println("============="+map);
 //                System.out.println(map.get("originator_dept_name"));CHK2019001
                 Map<String,Object> map1 = dingdingOpenInterface.tableToMap(map);
                 Map<String,Object> mapPerson = dingdingOpenInterface.getViewByUserId(map.get("originator_userid").toString());
@@ -82,7 +92,7 @@ public class PettyCashService {
                 map1.put("account_code","122102");//科目编码
                 map1.put("dept_code",dept_code);//部门编码
                 map1.put("job_number",job_number);//人员编码
-                String mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString(),type);
+//                String mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString(),type);
 
                 SyViewEntity entity = new SyViewEntity();
                 entity.setOaId(o);
@@ -92,9 +102,9 @@ public class PettyCashService {
                 entity.setDeptCode(dept_code);
                 entity.setJobNumber(job_number);
                 entity.setTableType("备用金");
-                entity.setSyMessage(mess);
+//                entity.setSyMessage(mess);
                 try {
-                    u8Service.saveSyView(entity);
+//                    u8Service.saveSyView(entity);
                 }catch (Exception e){
                     System.out.println("异常备用金");
                 }
@@ -103,6 +113,181 @@ public class PettyCashService {
         }
 
 
+    }
+
+    /**
+     * 备用金同步至银行回单
+     * @throws Exception
+     */
+    public void autoOABankPetty() throws Exception {
+
+        DingdingOpenInterface dingdingOpenInterface = new DingdingOpenInterface();
+        Properties prop = PropUtil.getProperties("/config.properties");
+        String PROC = prop.getProperty("byj_process_code");
+        String YHHD = prop.getProperty("yhhd_process_code");
+        String userid = prop.getProperty("userid");
+        String agentid = prop.getProperty("agentid");
+        String deptid = prop.getProperty("deptid");
+        List<String> list = dingdingOpenInterface.getOrderIdList2(PROC,-7);
+        System.out.println("备用金:"+list);
+        List<SyViewEntity> listIdError = u8Service.selectViewByError("备用金至银行凭证");
+        List<SyViewEntity> listIdTrue = u8Service.selectViewByTrue("备用金至银行凭证");
+
+        if(list.size() > 0){
+            getToken();
+
+            outCycle:for(String o:list){
+
+                //获取当日同步失败的单据,控制当日不再同步
+                if(listIdError.size() > 0){
+                    for(SyViewEntity en:listIdError){
+                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
+                            continue outCycle;
+                        }
+                    }
+                }
+                //获取10天内同步成功的数据,控制不再同步
+                if(listIdTrue.size() > 0){
+                    for(SyViewEntity en:listIdTrue){
+                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
+                            continue outCycle;
+                        }
+                    }
+                }
+
+                Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);
+//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("cecf74b9-6a7e-492f-af10-c6b37086b4e5");
+                if(StringUtils.isNullOrEmpty(map.get("result").toString()) || !map.get("result").toString().equals("agree")){
+                    continue;
+                }
+                Map<String,Object> map1 = dingdingOpenInterface.tableToMap(map);
+
+                DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/create");
+                OapiProcessinstanceCreateRequest req = new OapiProcessinstanceCreateRequest();
+                req.setAgentId(Long.valueOf(agentid));
+//                req.setProcessCode("PROC-C1EBBC4A-AA0D-4101-BEE8-8BFA5FEFABD8");//银行回单TEST
+                req.setProcessCode(YHHD);//银行回单TEST
+                req.setOriginatorUserId(userid);
+                req.setDeptId(Long.valueOf(deptid));
+
+                List<OapiProcessinstanceCreateRequest.FormComponentValueVo> formComponentValueVoList = new ArrayList<OapiProcessinstanceCreateRequest.FormComponentValueVo>();
+
+                //申请人编码
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV5 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV5.setName("申请人编码");
+                formComponentValueV5.setValue(map.get("originator_userid").toString());
+                formComponentValueVoList.add(formComponentValueV5);
+
+                //申请人名称
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV6 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV6.setName("申请人");
+                formComponentValueV6.setValue(map.get("title").toString());
+                formComponentValueVoList.add(formComponentValueV6);
+
+                //所属部门
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV7 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV7.setName("申请人所属部门");
+                formComponentValueV7.setValue(map.get("originator_dept_name").toString());
+                formComponentValueVoList.add(formComponentValueV7);
+
+                //单据类型(报销申请、备用金申请)
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV8 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV8.setName("单据类型");
+                formComponentValueV8.setValue("备用金申请");
+                formComponentValueVoList.add(formComponentValueV8);
+
+                //申请时间
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV9 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV9.setName("申请时间");
+                formComponentValueV9.setValue(map.get("create_time").toString());
+                formComponentValueVoList.add(formComponentValueV9);
+
+                //联系人明细
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo1 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item1 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item1.setName("户名");
+                Item1.setValue(map1.get("收款账户").toString());
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item2 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item2.setName("账号");
+                if(map1.get("账号")!=null){
+                    Item2.setValue(map1.get("账号").toString());
+                }else if(map1.get("收款账号")!=null){
+                    Item2.setValue(map1.get("收款账号").toString());
+                }else{
+                    Item2.setValue("空");
+                }
+
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item3 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item3.setName("开户银行");
+                if(map1.get("开户银行")!=null){
+                    Item3.setValue(map1.get("开户银行").toString());
+                }else{
+                    Item3.setValue("空");
+                }
+
+                formComponentValueVo1.setName("收款人");
+                formComponentValueVo1.setValue(JSON.toJSONString(Arrays.asList(Arrays.asList(Item1, Item2, Item3))));
+                formComponentValueVoList.add(formComponentValueVo1);
+
+
+                //备用金申请
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo2 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item21 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item21.setName("申请日期");
+                Item21.setValue(map1.get("申请日期").toString());
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item22 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item22.setName("申请事由");
+                Item22.setValue(map1.get("申请事由").toString());
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item23 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item23.setName("申请金额");
+                Item23.setValue(map1.get("申请金额(元)").toString());
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item24 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item24.setName("[\"使用日期\",\"归还日期\"]");
+                JSONArray jsonArray1 = JSONArray.fromObject(map1.get("[\"使用日期\",\"归还日期\"]").toString());
+                JSONArray jsonArray = new JSONArray();
+                jsonArray.add(jsonArray1.get(0));
+                jsonArray.add(jsonArray1.get(1));
+                Item24.setValue(jsonArray.toString());
+                formComponentValueVo2.setName("备用金申请");
+                formComponentValueVo2.setValue(JSON.toJSONString(Arrays.asList(Arrays.asList(Item21, Item22, Item23, Item24))));
+                formComponentValueVoList.add(formComponentValueVo2);
+
+                req.setFormComponentValues(formComponentValueVoList);
+
+                String useridshenh = prop.getProperty("shenhe_userid");
+                if (!useridshenh.equals("")){
+                    List<OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo> processInstanceApproverVoList = new ArrayList<OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo>();
+                    OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo processInstanceApproverVo = new OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo();
+                    processInstanceApproverVoList.add(processInstanceApproverVo);
+                    processInstanceApproverVo.setTaskActionType("NONE");
+                    processInstanceApproverVo.setUserIds(Arrays.asList(useridshenh));
+                    req.setApproversV2(processInstanceApproverVoList);
+                }
+
+                OapiProcessinstanceCreateResponse rsp = client.execute(req, gettoken);
+
+                SyViewEntity entity = new SyViewEntity();
+                entity.setOaId(o);
+                entity.setOaNid(rsp.getProcessInstanceId());
+                entity.setDeptName(map.get("originator_dept_name").toString());
+                entity.setJobNumber(map.get("title").toString());
+                entity.setTableType("备用金至银行凭证");
+                entity.setSyMessage(rsp.getErrmsg());
+                if(rsp.isSuccess()){
+                    entity.setSyState("true");
+                }else{
+                    entity.setSyState("false");
+                }
+                try {
+                    u8Service.saveSyView(entity);
+                }catch (Exception e){
+                    System.out.println("异常-备用金同步至银行回单");
+                }
+            }
+
+        }
+
+
     }
 
 
@@ -123,7 +308,7 @@ public class PettyCashService {
                 JSONObject record1 = (JSONObject) record.get("person");
                 code = record1.get("cdept_num").toString();
             }
-            System.out.println(record);
+//            System.out.println(record);
 
         } catch (OpenAPIException e) {
             return code;
@@ -132,9 +317,63 @@ public class PettyCashService {
         return code;
     }
 
+    /**
+     * 获取钉钉企业内部应用的access_token
+     */
+    public static void getToken(){
+
+        try {
+            Properties prop = PropUtil.getProperties("/config.properties");
+            String appkey = prop.getProperty("ding_appkey");
+            String appsecret = prop.getProperty("ding_appsecret");
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
+            OapiGettokenRequest req = new OapiGettokenRequest();
+            req.setHttpMethod("GET");
+            req.setAppkey(appkey);
+            req.setAppsecret(appsecret);
+            OapiGettokenResponse rsp = client.execute(req);
+
+            Map<String,String> map;
+            map = toMap(rsp.getBody());
+            if(map.get("errcode").equals("0")){
+                gettoken = map.get("access_token");
+            }else{
+                gettoken = "error";
+            }
+
+
+        } catch (ApiException | JSONException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+
+    public static Map toMap(String jsonString) throws JSONException {
+        org.springframework.boot.configurationprocessor.json.JSONObject jsonObject = new org.springframework.boot.configurationprocessor.json.JSONObject(jsonString);
+        Map result = new HashMap();
+        Iterator iterator = jsonObject.keys();
+        String key = null;
+        String value = null;
+
+        while (iterator.hasNext()) {
+
+            key = (String) iterator.next();
+            value = jsonObject.getString(key);
+            result.put(key, value);
+
+        }
+
+        return result;
+
+    }
+
+
 
     public static void main(String[] args) throws Exception {
-//        autoUpdataPetty();
+//        autoOABankPetty();
 //        getPerson("CHK2021001",null);
     }
 

+ 956 - 17
src/main/java/net/chenlin/dp/modules/api/service/ReimbursementService.java

@@ -1,25 +1,40 @@
 package net.chenlin.dp.modules.api.service;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.DingTalkClient;
+import com.dingtalk.api.request.OapiGettokenRequest;
+import com.dingtalk.api.request.OapiProcessinstanceCreateRequest;
+import com.dingtalk.api.response.OapiGettokenResponse;
+import com.dingtalk.api.response.OapiProcessinstanceCreateResponse;
 import com.mysql.cj.util.StringUtils;
+import com.taobao.api.ApiException;
 import net.chenlin.dp.common.openapi4j.examples.voucher.VoucherAdd;
 import net.chenlin.dp.common.openapi4j.exception.OpenAPIException;
 import net.chenlin.dp.common.openapi4j.service.PersonService;
 import net.chenlin.dp.common.openapi4j.util.PropUtil;
+import net.chenlin.dp.common.utils.JSONUtils;
 import net.chenlin.dp.common.utils.SpringContextUtils;
 import net.chenlin.dp.modules.api.controller.DingdingOpenInterface;
 import net.chenlin.dp.modules.sys.entity.SyViewEntity;
-import net.chenlin.dp.modules.sys.service.SysUserService;
 import net.chenlin.dp.modules.sys.service.testU8Service;
-import org.springframework.beans.factory.annotation.Autowired;
+import net.sf.json.JSONArray;
+import org.springframework.boot.configurationprocessor.json.JSONException;
 
+import java.math.BigDecimal;
 import java.util.*;
 
 public class ReimbursementService {
 
     private testU8Service u8Service= SpringContextUtils.getBean("testU8Service",testU8Service.class);
+    public static String gettoken = "";
 
-    public void autoReimbursement() throws Exception {
+    /**
+     * (不再使用)
+     * @throws Exception
+     */
+    public static void autoReimbursement() throws Exception {
 
         DingdingOpenInterface dingdingOpenInterface = new DingdingOpenInterface();
         Properties prop = PropUtil.getProperties("/config.properties");
@@ -31,26 +46,29 @@ public class ReimbursementService {
         String account_code = ""; //科目编码
         String type = ""; //数据源账套 1昆山,3潍坊
 
-        List<SyViewEntity> listId = u8Service.selectView("报销单");
+//        List<SyViewEntity> listId = u8Service.selectView("报销单");
 
         if(list.size() > 0){
             outCycle:for(String o:list){
 
-                if(listId.size() > 0){
-                    for(SyViewEntity en:listId){
-                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
-                            continue outCycle;
-                        }
-                    }
-                }
+//                if(listId.size() > 0){
+//                    for(SyViewEntity en:listId){
+//                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
+//                            continue outCycle;
+//                        }
+//                    }
+//                }
 
-//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("90325515-a5a5-4af8-abf9-2d4ef1eb7c23");
-                Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);
+                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("01dc1264-85ab-41a5-8e15-a0905268e1b3");
+//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("435bfa21-2366-43e3-b71a-041485d51a31");
+//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);
                 if(StringUtils.isNullOrEmpty(map.get("result").toString()) || !map.get("result").toString().equals("agree")){
                     continue;
                 }
 //                System.out.println(map);
                 Map<String,Object> map1 = tableToMap2(map);
+                //             System.out.println(map1);
+
                 Map<String,Object> mapPerson = dingdingOpenInterface.getViewByUserId(map.get("originator_userid").toString());
 
                 if(mapPerson !=null ){
@@ -102,7 +120,7 @@ public class ReimbursementService {
 //                    System.out.println("============================差旅报销"+account_code);
 //                    System.out.println(map1);
                     try {
-                        mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"差旅",type);
+//                        mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"差旅",type);
                     }catch (Exception e){
                         mess = e.getMessage();
                     }
@@ -123,7 +141,7 @@ public class ReimbursementService {
 //                    System.out.println(map1);
 //                    System.out.println("============================私车公用报销"+account_code);
                     try {
-                        mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"私车公用",type);
+//                        mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"私车公用",type);
                     }catch (Exception e){
                         mess = e.getMessage();
                     }
@@ -158,7 +176,7 @@ public class ReimbursementService {
                 entity.setTableType("报销单");
                 entity.setSyMessage(mess);
                 try {
-                    u8Service.saveSyView(entity);
+//                    u8Service.saveSyView(entity);
                 }catch (Exception e){
                     System.out.println("异常1");
                 }
@@ -170,12 +188,856 @@ public class ReimbursementService {
 
     }
 
-    public static Map<String,Object> tableToMap2(Map<String,Object> map1){
+
+    /**
+     * 同步银行回单至u8凭证
+     * @throws Exception
+     */
+    public void autoReimbursementNew() throws Exception {
+
+        DingdingOpenInterface dingdingOpenInterface = new DingdingOpenInterface();
+        Properties prop = PropUtil.getProperties("/config.properties");
+        String PROC = prop.getProperty("yhhd_process_code");
+//        List<String> list = dingdingOpenInterface.getOrderIdList(PROC);
+//        List<String> list = dingdingOpenInterface.getOrderIdList2("PROC-C1EBBC4A-AA0D-4101-BEE8-8BFA5FEFABD8",-5);
+        List<String> list = dingdingOpenInterface.getOrderIdList2(PROC,-31);
+//        System.out.println(list);
+        String job_number = "";//工号
+        String work_place = "";//办公地(潍坊对03账套 昆山对01账套)
+        String dept_code = ""; //部门编码
+        String type = ""; //数据源账套 1昆山,3潍坊
+//        List<SyViewEntity> listId = u8Service.selectView("银行凭证至U8");
+        if(list.size() > 0){
+            outCycle:for(String o:list){
+
+//                if(listId.size() > 0){
+//                    for(SyViewEntity en:listId){
+//                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
+//                            continue outCycle;
+//                        }
+//                    }
+//                }
+
+//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("24715cdf-4389-44b3-a634-5c30871a095b");//
+                Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);//
+
+                if(StringUtils.isNullOrEmpty(map.get("result").toString()) || !map.get("result").toString().equals("agree")){
+                    continue;
+                }
+
+                Map<String,Object> map1 = tableToMap4(map);
+
+                Map<String,Object> mapPerson = dingdingOpenInterface.getViewByUserId((String) map1.get("申请人编码"));
+
+                if(mapPerson !=null ){
+                    job_number = mapPerson.get("job_number").toString();//"CHK2019002";
+                    work_place = mapPerson.get("work_place").toString();
+                    if(StringUtils.isNullOrEmpty(work_place)){
+                        continue;
+                    }
+
+                    if (work_place.equals("昆山")){
+                        dept_code = getPerson(job_number,"1");
+                        type = "1";
+                    }else if(work_place.equals("潍坊")){
+                        dept_code = getPerson(job_number,"3");
+                        type = "3";
+                    }else{
+                        continue;
+                    }
+                }else{
+                    continue;
+                }
+
+                if(map1.get("申请人所属部门") == null){
+                    continue;
+                }
+                //如果是以下部门,则需要填写项目大类和项目名称
+                if(map1.get("申请人所属部门").toString().equals("营销设计中心-设计部") ||
+                        map1.get("申请人所属部门").toString().equals("营销设计中心-项目部") ||
+                        map1.get("申请人所属部门").toString().equals("营销设计中心-市场部")){
+
+                    map1.put("item_class","00");//项目大类  --研发项目
+                    map1.put("item_id","YFYYYY00001");//项目名称  --项目研发-公共
+                }
+
+                if(map1.get("单据类型") == null){//备用金申请、报销申请
+                    continue;
+                }
+                String mess = null;
+
+                map1.put("dept_code",dept_code);//部门编码
+                map1.put("job_number",job_number);//人员编码
+
+                SyViewEntity entity = new SyViewEntity();
+                entity.setOaId(o);
+                entity.setDeptName(map1.get("申请人所属部门").toString());
+                entity.setJobNumber(job_number);
+                entity.setTableType("银行凭证至U8");
+
+                if(map1.get("单据类型").toString().equals("备用金申请")){
+                    entity.setParType("备用金至U8凭证");
+                    map1.put("account_code_jf","122102");//科目编码(借方)
+                    map1.put("account_code_df","10020101");//科目编码(贷方)
+
+                    JSONArray jsonArray2 = JSONArray.fromObject(map1.get("备用金申请").toString());
+                    if(jsonArray2.size() == 0){
+                        continue ;
+                    }
+                    net.sf.json.JSONObject object1 = jsonArray2.getJSONObject(0);
+                    map1.put("abstract",object1.get("申请事由"));
+                    map1.put("naturalCurrency",object1.get("申请金额"));
+
+                    try {
+                        mess = VoucherAdd.addVoucher(map1,map.get("business_id").toString()+"备用金",type);
+                    }catch (Exception e){
+                        mess = e.getMessage();
+                    }
+//                    System.out.println(mess);
+
+                }else if(map1.get("单据类型").toString().equals("报销申请")){
+                    entity.setParType("报销申请至U8");
+                    try {
+                        mess = VoucherAdd.addVoucherNew(map1,map.get("business_id").toString()+"报销申请",type);
+                    }catch (Exception e){
+                        mess = e.getMessage();
+                    }
+
+                }else{
+                    continue ;
+                }
+                entity.setSyMessage(mess);
+
+            }
+
+        }
+
+    }
+
+
+
+
+
+
+    /**
+     * 同步报销单至银行凭证
+     * @throws Exception
+     */
+    public void autoOABankReceipt() throws Exception {
+
+        DingdingOpenInterface dingdingOpenInterface = new DingdingOpenInterface();
+        Properties prop = PropUtil.getProperties("/config.properties");
+        String PROC = prop.getProperty("bx_process_code");//报销单
+        String YHHD = prop.getProperty("yhhd_process_code");//银行回单
+        String agentid = prop.getProperty("agentid");
+        String deptid = prop.getProperty("deptid");
+        String userid = prop.getProperty("userid");
+        List<String> list = dingdingOpenInterface.getOrderIdList2(PROC,-7);
+//        List<String> list = dingdingOpenInterface.getOrderIdList("PROC-DD8FF68E-B90E-4885-8C17-F69E53BE5C81");
+        System.out.println("报销申请:"+list);
+        List<SyViewEntity> listIdError = u8Service.selectViewByError("报销单至银行凭证");
+        List<SyViewEntity> listIdTrue = u8Service.selectViewByTrue("报销单至银行凭证");
+
+        if(list.size() > 0){
+            getToken();
+            outCycle:for(String o:list){
+            //获取当日同步失败的单据,控制当日不再同步
+               if(listIdError.size() > 0){
+                    for(SyViewEntity en:listIdError){
+                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
+                            continue outCycle;
+                        }
+                    }
+                }
+               //获取10天内同步成功的数据,控制不再同步
+               if(listIdTrue.size() > 0){
+                    for(SyViewEntity en:listIdTrue){
+                        if(!StringUtils.isNullOrEmpty(en.getOaId()) && en.getOaId().equals(o)){
+                            continue outCycle;
+                        }
+                    }
+                }
+
+//                Map<String,Object> map = dingdingOpenInterface.getOrderDetails("e12ca8e8-e783-4652-b68e-e12648ed00c3");
+                Map<String,Object> map = dingdingOpenInterface.getOrderDetails(o);
+                if(StringUtils.isNullOrEmpty(map.get("result").toString()) || !map.get("result").toString().equals("agree")){
+                    continue;
+                }
+                SyViewEntity entity = new SyViewEntity();
+                Map<String,Object> newMap = tableToMap2(map);
+                DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/create");
+                OapiProcessinstanceCreateRequest req = new OapiProcessinstanceCreateRequest();
+                req.setAgentId(Long.valueOf(agentid));
+//                req.setProcessCode("PROC-C1EBBC4A-AA0D-4101-BEE8-8BFA5FEFABD8");//银行回单TEST
+                req.setProcessCode(YHHD);//银行回单
+                req.setOriginatorUserId(userid);
+                req.setDeptId(Long.valueOf(deptid));
+
+                List<OapiProcessinstanceCreateRequest.FormComponentValueVo> formComponentValueVoList = new ArrayList<OapiProcessinstanceCreateRequest.FormComponentValueVo>();
+
+                //申请人编码
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV5 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV5.setName("申请人编码");
+                formComponentValueV5.setValue(map.get("originator_userid").toString());
+                formComponentValueVoList.add(formComponentValueV5);
+
+                //申请人名称
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV6 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV6.setName("申请人");
+                formComponentValueV6.setValue(map.get("title").toString());
+                formComponentValueVoList.add(formComponentValueV6);
+
+                //所属部门
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV7 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV7.setName("申请人所属部门");
+                formComponentValueV7.setValue(map.get("originator_dept_name").toString());
+                formComponentValueVoList.add(formComponentValueV7);
+
+                //单据类型(报销申请、备用金申请)
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV8 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV8.setName("单据类型");
+                formComponentValueV8.setValue("报销申请");
+                formComponentValueVoList.add(formComponentValueV8);
+
+                //申请时间
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueV9 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                formComponentValueV9.setName("申请时间");//create_time
+                formComponentValueV9.setValue(map.get("create_time").toString());
+                formComponentValueVoList.add(formComponentValueV9);
+
+                //联系人明细
+                OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo1 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item1 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item1.setName("户名");
+                if(newMap.get("户名") == null){
+                    continue ;
+                }
+                Item1.setValue(newMap.get("户名").toString());
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item2 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item2.setName("账号");
+                if(newMap.get("账号") != null){
+                    Item2.setValue(newMap.get("账号").toString());
+                }else{
+                    Item2.setValue("空");
+                }
+
+                OapiProcessinstanceCreateRequest.FormComponentValueVo Item3 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                Item3.setName("开户银行");
+                if(newMap.get("开户银行") != null){
+                    Item3.setValue(newMap.get("开户银行").toString());
+                }else{
+                    Item3.setValue("空");
+                }
+
+                formComponentValueVo1.setName("收款人");
+                formComponentValueVo1.setValue(JSON.toJSONString(Arrays.asList(Arrays.asList(Item1, Item2, Item3))));
+                formComponentValueVoList.add(formComponentValueVo1);
+
+                //差旅报销明细
+                 if(newMap.get("差旅报销") != null && JSONArray.fromObject(newMap.get("差旅报销").toString()).size() > 0){
+                     OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo2 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                     List<List<OapiProcessinstanceCreateRequest.FormComponentValueVo>> viewList2 = new ArrayList<>();
+
+                     JSONArray jsonArray1 = JSONArray.fromObject(newMap.get("差旅报销").toString());
+                    for (int j = 0; j < jsonArray1.size(); j++) {
+                        List<OapiProcessinstanceCreateRequest.FormComponentValueVo> view = new ArrayList<>();
+                        net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+
+                        if(object1.get("发生日期") != null && object1.get("结束日期") != null && object1.get("发生日期") != "" && object1.get("结束日期") != ""){
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item21 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            JSONArray jsonArray = new JSONArray();
+                            jsonArray.add(object1.get("发生日期").toString());
+                            jsonArray.add(object1.get("结束日期").toString());
+                            Item21.setName("[\"发生日期\",\"结束日期\"]");
+                            Item21.setValue(jsonArray.toString());
+//                            Item21.setValue("[\"2019-02-19\",\"2019-02-25\"]");
+                            view.add(Item21);
+                        }else{
+                            continue ;
+                        }
+                        if(object1.get("报销科目") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item22 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item22.setName("报销科目");
+                            Item22.setValue(object1.get("报销科目").toString());
+                            view.add(Item22);
+                        }else{
+                            continue ;
+                        }
+                        if(object1.get("名称") != null && object1.get("名称") != "") {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item23 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item23.setName("名称");
+                            Item23.setValue(object1.get("名称").toString());
+                            view.add(Item23);
+                        }
+                        if(object1.get("次数") != null && object1.get("次数") != "") {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item24 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item24.setName("次数");
+                            Item24.setValue(object1.get("次数").toString());
+                            view.add(Item24);
+                        }
+                        if(object1.get("未税金额") != null && object1.get("未税金额") != "") {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item25 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item25.setName("未税金额");
+                            Item25.setValue(object1.get("未税金额").toString());
+                            view.add(Item25);
+                        }else{
+                            continue ;
+                        }
+                        if(object1.get("税额") != null && object1.get("税额") != "") {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item26 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item26.setName("税额");
+                            Item26.setValue(object1.get("税额").toString());
+                            view.add(Item26);
+                        }
+                        if(object1.get("费用说明") != null && object1.get("费用说明") != "") {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item27 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item27.setName("费用说明");
+                            Item27.setValue(object1.get("费用说明").toString());
+                            view.add(Item27);
+                        }
+                        viewList2.add(view);
+                    }
+                    formComponentValueVo2.setName("差旅报销");
+                    formComponentValueVo2.setValue(JSON.toJSONString(viewList2));
+                    formComponentValueVoList.add(formComponentValueVo2);
+                }
+
+                //私车公用报销明细
+                if(newMap.get("私车公用报销") != null && JSONArray.fromObject(newMap.get("私车公用报销").toString()).size() > 0) {
+                    OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo3 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                    List<List<OapiProcessinstanceCreateRequest.FormComponentValueVo>> viewList3 = new ArrayList<>();
+
+                    JSONArray jsonArray1 = JSONArray.fromObject(newMap.get("私车公用报销").toString());
+                    for (int j = 0; j < jsonArray1.size(); j++) {
+                        List<OapiProcessinstanceCreateRequest.FormComponentValueVo> view = new ArrayList<>();
+                        net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+                        if(object1.get("发生日期") != null && object1.get("结束日期") != null && object1.get("发生日期") != "" && object1.get("结束日期") != ""){
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item31 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+//                            Item31.setName("[\"发生日期\",\"结束日期\"]");
+//                            Item31.setValue("[\"2019-02-19\",\"2019-02-25\"]");
+//                            view.add(Item31);
+                            JSONArray jsonArray = new JSONArray();
+                            jsonArray.add(object1.get("发生日期").toString());
+                            jsonArray.add(object1.get("结束日期").toString());
+                            Item31.setName("[\"发生日期\",\"结束日期\"]");
+                            Item31.setValue(jsonArray.toString());
+                            view.add(Item31);
+                        }else{
+                            continue ;
+                        }
+                        if(object1.get("报销科目") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item32 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item32.setName("报销科目");
+                            Item32.setValue(object1.get("报销科目").toString());
+                            view.add(Item32);
+                        }else{
+                            continue ;
+                        }
+                        if(object1.get("行程") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item33 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item33.setName("行程");
+                            Item33.setValue(object1.get("行程").toString());
+                            view.add(Item33);
+                        }
+                        if(object1.get("次数") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item34 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item34.setName("次数");
+                            Item34.setValue(object1.get("次数").toString());
+                            view.add(Item34);
+                        }
+                        if(object1.get("未税金额") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item35 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item35.setName("未税金额");
+                            Item35.setValue(object1.get("未税金额").toString());
+                            view.add(Item35);
+                        }else{
+                            continue ;
+                        }
+                        if(object1.get("税额") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item36 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item36.setName("税额");
+                            Item36.setValue(object1.get("税额").toString());
+                            view.add(Item36);
+                        }
+                        if(object1.get("费用说明") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item37 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item37.setName("费用说明");
+                            Item37.setValue(object1.get("费用说明").toString());
+                            view.add(Item37);
+                        }
+//                        viewList3.add(Arrays.asList(Item31, Item32, Item33, Item34, Item35, Item36, Item37));
+                        viewList3.add(view);
+                    }
+                    formComponentValueVo3.setName("私车公用报销");
+                    formComponentValueVo3.setValue(JSON.toJSONString(viewList3));
+                    formComponentValueVoList.add(formComponentValueVo3);
+                }
+
+                //其他报销科目明细
+                if(newMap.get("其他报销科目") != null && JSONArray.fromObject(newMap.get("其他报销科目").toString()).size() > 0) {
+                    OapiProcessinstanceCreateRequest.FormComponentValueVo formComponentValueVo4 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                    List<List<OapiProcessinstanceCreateRequest.FormComponentValueVo>> viewList4 = new ArrayList<>();
+
+                    JSONArray jsonArray1 = JSONArray.fromObject(newMap.get("其他报销科目").toString());
+                    for (int j = 0; j < jsonArray1.size(); j++) {
+
+                        List<OapiProcessinstanceCreateRequest.FormComponentValueVo> view = new ArrayList<>();
+                        net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+                        if(object1.get("发生日期") != null && object1.get("结束日期") != null && object1.get("发生日期") != "" && object1.get("结束日期") != ""){
+
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item41 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+//                            Item41.setName("[\"发生日期\",\"结束日期\"]");
+//                            Item41.setValue("[\"2019-02-19\"");
+//                            view.add(Item41);
+
+                            JSONArray jsonArray = new JSONArray();
+                            jsonArray.add(object1.get("发生日期").toString());
+                            jsonArray.add(object1.get("结束日期").toString());
+                            Item41.setName("[\"发生日期\",\"结束日期\"]");
+                            Item41.setValue(jsonArray.toString());
+                            view.add(Item41);
+                        }else{
+                            continue ;
+                        }
+                        if(object1.get("报销科目") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item42 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item42.setName("报销科目");
+                            Item42.setValue(object1.get("报销科目").toString());
+                            view.add(Item42);
+                        }else{
+                            continue ;
+                        }
+                        if(object1.get("名称") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item43 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item43.setName("名称");
+                            Item43.setValue(object1.get("名称").toString());
+                            view.add(Item43);
+                        }
+                        if(object1.get("单位") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item44 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item44.setName("单位");
+                            Item44.setValue(object1.get("单位").toString());
+                            view.add(Item44);
+                        }
+                        if(object1.get("数量") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item48 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item48.setName("数量");
+                            Item48.setValue(object1.get("数量").toString());
+                            view.add(Item48);
+                        }
+                        if(object1.get("未税金额") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item45 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item45.setName("未税金额");
+                            Item45.setValue(object1.get("未税金额").toString());
+                            view.add(Item45);
+                        }else{
+                            continue ;
+                        }
+                        if(object1.get("税额") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item46 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item46.setName("税额");
+                            Item46.setValue(object1.get("税额").toString());
+                            view.add(Item46);
+                        }
+                        if(object1.get("费用说明") != null) {
+                            OapiProcessinstanceCreateRequest.FormComponentValueVo Item47 = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
+                            Item47.setName("费用说明");
+                            Item47.setValue(object1.get("费用说明").toString());
+                            view.add(Item47);
+                        }
+//                        viewList4.add(Arrays.asList(Item41, Item42, Item43, Item44, Item48, Item45, Item46, Item47));
+                        viewList4.add(view);
+                    }
+                    if(viewList4.size() > 0){
+                        formComponentValueVo4.setName("其他报销科目");
+                        formComponentValueVo4.setValue(JSON.toJSONString(viewList4));
+                        formComponentValueVoList.add(formComponentValueVo4);
+                    }
+                }
+
+                req.setFormComponentValues(formComponentValueVoList);
+
+                String useridshenh = prop.getProperty("shenhe_userid");
+                if (!useridshenh.equals("")){
+                    List<OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo> processInstanceApproverVoList = new ArrayList<OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo>();
+                    OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo processInstanceApproverVo = new OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo();
+                    processInstanceApproverVoList.add(processInstanceApproverVo);
+                    processInstanceApproverVo.setTaskActionType("NONE");
+                    processInstanceApproverVo.setUserIds(Arrays.asList(useridshenh));
+                    req.setApproversV2(processInstanceApproverVoList);
+                }
+
+                OapiProcessinstanceCreateResponse rsp = client.execute(req, gettoken);
+
+                entity.setOaId(o);
+                entity.setOaNid(rsp.getProcessInstanceId());
+                entity.setDeptName(map.get("originator_dept_name").toString());
+                entity.setJobNumber(map.get("title").toString());
+                entity.setTableType("报销单至银行凭证");
+                entity.setSyMessage(rsp.getErrmsg());
+                if(rsp.isSuccess()){
+                    entity.setSyState("true");
+                }else{
+                    entity.setSyState("false");
+                }
+                try {
+                    u8Service.saveSyView(entity);
+                }catch (Exception e){
+                    System.out.println("异常2");
+                }
+//                System.out.println("============"+JSON.toJSONString(rsp));
+//                System.out.println("============"+JSON.toJSONString(rsp.getErrmsg()));
+//                System.out.println("============"+JSON.toJSONString(rsp.isSuccess()));
+
+            }
+        }
+
+    }
+
+    public static Map<String,Object> tableToMap4(Map<String,Object> map1) throws Exception {
+
+        List<Map<String,Object>> listMap = (List<Map<String, Object>>) map1.get("form_component_values");
+        Map<String,Object> newMap = new HashMap<String,Object>();
+//        System.out.println(map1);
+        for(Map<String, Object> o:listMap){
+
+            if(o.get("name")==null || StringUtils.isNullOrEmpty(o.get("name").toString())){
+                continue;
+            }
+
+            if(o.get("name").equals("申请人编码") && o.get("value") != null){
+                newMap.put("申请人编码",o.get("value"));
+            }
+            if(o.get("name").equals("申请人所属部门") && o.get("value") != null){
+                newMap.put("申请人所属部门",o.get("value"));
+            }
+            if(o.get("name").equals("申请人") && o.get("value") != null){
+                newMap.put("申请人",o.get("value"));
+            }
+            if(o.get("name").equals("单据类型") && o.get("value") != null){
+                newMap.put("单据类型",o.get("value"));
+
+            }
+
+            if(o.get("name").equals("收款人") && o.get("value") != null){
+                JSONArray jsonArray = JSONArray.fromObject(o.get("value").toString());
+                if(jsonArray.size() > 0){
+                    List<Map<String,Object>> listView = new ArrayList<>();
+
+                    for(int i=0;i<jsonArray.size();i++){
+                        net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                        if(object.get("rowValue") == null || object.get("rowValue") == ""){
+                            continue;
+                        }
+                        JSONArray jsonArray1 = JSONArray.fromObject(object.get("rowValue").toString());
+                        JSONObject map = new JSONObject();
+                        if(jsonArray1.size() > 0){
+                            for(int j=0;j<jsonArray1.size();j++){
+
+                                net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+
+                                map.put(object1.get("label").toString(),object1.get("value"));
+                            }
+                            listView.add(map);
+                        }
+                    }
+                    newMap.put("收款人",listView);
+                }
+
+            }
+
+            if(o.get("name").equals("备用金申请") && o.get("value") != null){
+                JSONArray jsonArray = JSONArray.fromObject(o.get("value").toString());
+                if(jsonArray.size() > 0){
+                    List<Map<String,Object>> listView = new ArrayList<>();
+
+                    for(int i=0;i<jsonArray.size();i++){
+                        net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                        if(object.get("rowValue") == null || object.get("rowValue") == ""){
+                            continue;
+                        }
+                        JSONArray jsonArray1 = JSONArray.fromObject(object.get("rowValue").toString());
+                        JSONObject map = new JSONObject();
+                        if(jsonArray1.size() > 0){
+                            for(int j=0;j<jsonArray1.size();j++){
+
+                                net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+                                if(object1.get("label").toString().equals("[\"使用日期\",\"归还日期\"]")){
+                                    JSONArray aa = JSONArray.fromObject(object1.get("value"));
+                                    if(aa.size() > 1){
+                                        map.put("使用日期",aa.get(0));
+                                        map.put("归还日期",aa.get(1));
+                                    }
+
+                                }else{
+                                    map.put(object1.get("label").toString(),object1.get("value"));
+                                }
+                            }
+                            listView.add(map);
+                        }
+                    }
+                    newMap.put("备用金申请",listView);
+                }
+
+            }
+
+            if(o.get("name").equals("差旅报销") && o.get("value") != null){
+                JSONArray jsonArray = JSONArray.fromObject(o.get("value").toString());
+                if(jsonArray.size() > 0){
+                    List<Map<String,Object>> listView = new ArrayList<>();
+
+                    for(int i=0;i<jsonArray.size();i++){
+                        net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                        if(object.get("rowValue") == null || object.get("rowValue") == ""){
+                            continue;
+                        }
+                        JSONArray jsonArray1 = JSONArray.fromObject(object.get("rowValue").toString());
+                        JSONObject map = new JSONObject();
+                        if(jsonArray1.size() > 0){
+                            for(int j=0;j<jsonArray1.size();j++){
+
+                                net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+                                if(object1.get("label").toString().equals("[\"发生日期\",\"结束日期\"]")){
+                                    JSONArray aa = JSONArray.fromObject(object1.get("value"));
+                                    if(aa.size() > 1){
+                                        map.put("发生日期",aa.get(0));
+                                        map.put("结束日期",aa.get(1));
+                                    }
+
+                                }else{
+                                    map.put(object1.get("label").toString(),object1.get("value"));
+                                }
+                            }
+                            listView.add(map);
+                        }
+                    }
+                    newMap.put("差旅报销",listView);
+                }
+
+            }
+            if(o.get("name").equals("私车公用报销") && o.get("value") != null){
+                JSONArray jsonArray = JSONArray.fromObject(o.get("value").toString());
+                if(jsonArray.size() > 0){
+                    List<Map<String,Object>> listView = new ArrayList<>();
+
+                    for(int i=0;i<jsonArray.size();i++){
+                        net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                        if(object.get("rowValue") == null || object.get("rowValue") == ""){
+                            continue;
+                        }
+                        JSONArray jsonArray1 = JSONArray.fromObject(object.get("rowValue").toString());
+                        JSONObject map = new JSONObject();
+                        if(jsonArray1.size() > 0){
+                            for(int j=0;j<jsonArray1.size();j++){
+
+                                net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+                                if(object1.get("label").toString().equals("[\"发生日期\",\"结束日期\"]")){
+                                    JSONArray aa = JSONArray.fromObject(object1.get("value"));
+                                    if(aa.size() > 1){
+                                        map.put("发生日期",aa.get(0));
+                                        map.put("结束日期",aa.get(1));
+                                    }
+
+                                }else{
+                                    map.put(object1.get("label").toString(),object1.get("value"));
+                                }
+                            }
+                            listView.add(map);
+                        }
+                    }
+                    newMap.put("私车公用报销",listView);
+                }
+
+            }
+            if(o.get("name").equals("其他报销科目") && o.get("value") != null){
+                JSONArray jsonArray = JSONArray.fromObject(o.get("value").toString());
+                if(jsonArray.size() > 0){
+                    List<Map<String,Object>> listView = new ArrayList<>();
+
+                    for(int i=0;i<jsonArray.size();i++){
+                        net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                        if(object.get("rowValue") == null || object.get("rowValue") == ""){
+                            continue;
+                        }
+                        JSONArray jsonArray1 = JSONArray.fromObject(object.get("rowValue").toString());
+                        JSONObject map = new JSONObject();
+                        if(jsonArray1.size() > 0){
+                            for(int j=0;j<jsonArray1.size();j++){
+                                net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+                                if(object1.get("label").toString().equals("[\"发生日期\",\"结束日期\"]")){
+                                    JSONArray aa = JSONArray.fromObject(object1.get("value"));
+                                    if(aa.size() > 1){
+                                        map.put("发生日期",aa.get(0));
+                                        map.put("结束日期",aa.get(1));
+                                    }
+
+                                }else{
+                                    map.put(object1.get("label").toString(),object1.get("value"));
+                                }
+                            }
+                            listView.add(map);
+                        }
+                    }
+                    newMap.put("其他报销科目",listView);
+                }
+
+            }
+
+        }
+
+        return newMap;
+    }
+
+   public static Map<String,Object> tableToMap2(Map<String,Object> map1) throws Exception {
 
         List<Map<String,Object>> listMap = (List<Map<String, Object>>) map1.get("form_component_values");
+        Map<String,Object> newMap = new HashMap<String,Object>();
+
+        for(Map<String, Object> o:listMap){
+            if(o.get("component_type").equals("RecipientAccountField")){
+                Map<String,Object> mapValue = JSONUtils.jsonToMap((String) o.get("ext_value"));
+                newMap.put("户名",mapValue.get("name"));
+                newMap.put("账号",mapValue.get("cardNo"));
+                newMap.put("开户银行",mapValue.get("instName"));
+            }
+
+            if(o.get("name")==null || StringUtils.isNullOrEmpty(o.get("name").toString())){
+                continue;
+            }
+
+            if(o.get("name").equals("收款账号") && o.get("value") != null && newMap.get("账号") == null){
+                newMap.put("账号",o.get("value"));
+            }
+            if(o.get("name").equals("差旅报销") && o.get("value") != null){
+                JSONArray jsonArray = JSONArray.fromObject(o.get("value").toString());
+                if(jsonArray.size() > 0){
+                    List<Map<String,Object>> listView = new ArrayList<>();
+
+                    for(int i=0;i<jsonArray.size();i++){
+                        net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                        JSONArray jsonArray1 = JSONArray.fromObject(object.get("rowValue").toString());
+//                        Map<String,Object> map = new HashMap<>();
+                        JSONObject map = new JSONObject();
+                        if(jsonArray1.size() > 0){
+                            for(int j=0;j<jsonArray1.size();j++){
+                                net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+                                if(object1.get("label").toString().equals("[\"发生日期\",\"结束日期\"]")){
+                                    List<String> aa = (List<String>) object1.get("value");
+                                    if(aa.size() > 1){
+                                        map.put("发生日期",aa.get(0));
+                                        map.put("结束日期",aa.get(1));
+                                    }
+
+                                }else if(object1.get("label").toString().equals("报销科目")){
+
+                                    List<String> aa = (List<String>) object1.get("value");
+                                    if(aa.size() > 0){
+                                        map.put("报销科目",aa.get(0));
+                                    }
+                                }else{
+                                    map.put(object1.get("label").toString(),object1.get("value"));
+                                }
+                            }
+                            listView.add(map);
+                        }
+                    }
+                    newMap.put("差旅报销",listView);
+                }
+
+            }
+            if(o.get("name").equals("私车公用报销") && o.get("value") != null){
+                JSONArray jsonArray = JSONArray.fromObject(o.get("value").toString());
+                if(jsonArray.size() > 0){
+                    List<Map<String,Object>> listView = new ArrayList<>();
+
+                    for(int i=0;i<jsonArray.size();i++){
+                        net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                        JSONArray jsonArray1 = JSONArray.fromObject(object.get("rowValue").toString());
+//                        Map<String,Object> map = new HashMap<>();
+                        JSONObject map = new JSONObject();
+                        if(jsonArray1.size() > 0){
+                            for(int j=0;j<jsonArray1.size();j++){
+
+                                net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+                                if(object1.get("label").toString().equals("[\"发生日期\",\"结束日期\"]")){
+                                    List<String> aa = (List<String>) object1.get("value");
+                                    if(aa.size() > 1){
+                                        map.put("发生日期",aa.get(0));
+                                        map.put("结束日期",aa.get(1));
+                                    }
+
+                                }else if(object1.get("label").toString().equals("报销科目")){
+
+                                    List<String> aa = (List<String>) object1.get("value");
+                                    if(aa.size() > 0){
+                                        map.put("报销科目",aa.get(0));
+                                    }
+                                }else{
+                                    map.put(object1.get("label").toString(),object1.get("value"));
+                                }
+                            }
+                            listView.add(map);
+                        }
+                    }
+                    newMap.put("私车公用报销",listView);
+                }
+
+            }
+            if(o.get("name").equals("其他报销科目") && o.get("value") != null){
+                JSONArray jsonArray = JSONArray.fromObject(o.get("value").toString());
+                if(jsonArray.size() > 0){
+                    List<Map<String,Object>> listView = new ArrayList<>();
+
+                    for(int i=0;i<jsonArray.size();i++){
+                        net.sf.json.JSONObject object = jsonArray.getJSONObject(i);
+                        JSONArray jsonArray1 = JSONArray.fromObject(object.get("rowValue").toString());
+//                        Map<String,Object> map = new HashMap<>();
+                        JSONObject map = new JSONObject();
+                        if(jsonArray1.size() > 0){
+                            for(int j=0;j<jsonArray1.size();j++){
+                                net.sf.json.JSONObject object1 = jsonArray1.getJSONObject(j);
+                                if(object1.get("label").toString().equals("[\"发生日期\",\"结束日期\"]")){
+                                    List<String> aa = (List<String>) object1.get("value");
+                                    if(aa.size() > 1){
+                                        map.put("发生日期",aa.get(0));
+                                        map.put("结束日期",aa.get(1));
+                                    }
+
+                                }else if(object1.get("label").toString().equals("报销科目")){
+
+                                    List<String> aa = (List<String>) object1.get("value");
+                                    if(aa.size() > 0){
+                                        map.put("报销科目",aa.get(0));
+                                    }
+                                }else{
+                                    map.put(object1.get("label").toString(),object1.get("value"));
+                                }
+                            }
+                            listView.add(map);
+                        }
+                    }
+                    newMap.put("其他报销科目",listView);
+                }
+
+            }
+        }
+
+//        System.out.println("=========================");
+//        System.out.println("=========================");
+
+        return newMap;
+    }
+
+    public static Map<String,Object> tableToMap3(Map<String,Object> map1){
+
+        List<Map<String,Object>> listMap = (List<Map<String, Object>>) map1.get("form_component_values");
+//        System.out.println(listMap);
         Map<String,Object> newMap = new HashMap<>();
         int st = 0;
         for(Map<String, Object> o:listMap){
+
+//            System.out.println(o);
+//            System.out.println("=========================");
             if(o.get("name")==null || StringUtils.isNullOrEmpty(o.get("name").toString())){
                 continue;
             }
@@ -285,10 +1147,87 @@ public class ReimbursementService {
         return code;
     }
 
+    /**
+     * 获取钉钉企业内部应用的access_token
+     */
+    public static void getToken(){
+
+        try {
+            Properties prop = PropUtil.getProperties("/config.properties");
+            String appkey = prop.getProperty("ding_appkey");
+            String appsecret = prop.getProperty("ding_appsecret");
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
+            OapiGettokenRequest req = new OapiGettokenRequest();
+            req.setHttpMethod("GET");
+            req.setAppkey(appkey);
+            req.setAppsecret(appsecret);
+            OapiGettokenResponse rsp = client.execute(req);
+
+            Map<String,String> map;
+            map = toMap(rsp.getBody());
+            if(map.get("errcode").equals("0")){
+                gettoken = map.get("access_token");
+            }else{
+                gettoken = "error";
+            }
+
+
+        } catch (ApiException | JSONException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    public static Map toMap(String jsonString) throws JSONException {
+        org.springframework.boot.configurationprocessor.json.JSONObject jsonObject = new org.springframework.boot.configurationprocessor.json.JSONObject(jsonString);
+        Map result = new HashMap();
+        Iterator iterator = jsonObject.keys();
+        String key = null;
+        String value = null;
+
+        while (iterator.hasNext()) {
+
+            key = (String) iterator.next();
+            value = jsonObject.getString(key);
+            result.put(key, value);
+
+        }
+
+        return result;
+
+    }
+
 
     public static void main(String[] args) throws Exception {
+//        autoOABankReceipt();
 //        autoReimbursement();
+//        autoReimbursementNew();
+
+//        String aa  = "";
+//        if("12334".contains("1")){
+//            System.out.println("sssssssssss");
+//        }
+//        BigDecimal aa = new BigDecimal("10");
+//        BigDecimal multiply = aa.multiply(BigDecimal.valueOf(0.09)).multiply(aa);
+//        System.out.println(multiply);
+//        DingdingOpenInterface dingdingOpenInterface = new DingdingOpenInterface();
+//        Properties prop = PropUtil.getProperties("/config.properties");
+//        String PROC = prop.getProperty("bx_process_code");
+//        String PROC1 = prop.getProperty("byj_process_code");
+//        List<String> list = dingdingOpenInterface.getOrderIdList2(PROC,-2);
+//        List<String> list1 = dingdingOpenInterface.getOrderIdList2(PROC1,-7);
+//        System.out.println(list);
+        System.out.println("========1======");
+        Thread.currentThread().sleep(5000);//延迟5秒
+        Thread.sleep(3000);//与上行代码无区别
+        System.out.println("========2======");
+//        System.out.println(list1);
+
+
     }
 
 
+
 }

+ 7 - 2
src/main/java/net/chenlin/dp/modules/sys/controller/U8TestController.java

@@ -24,7 +24,12 @@ public class U8TestController {
 
     public static void main(String[] args) {
 
-        String connectionUrl =
+
+        System.out.println(Math.round(1.5) );
+
+
+
+       /* String connectionUrl =
 
                 "jdbc:sqlserver://10.0.0.199:1433;DatabaseName=UFDATA_998_2021;integratedSecurity=false;";
 
@@ -46,7 +51,7 @@ public class U8TestController {
 
             e.printStackTrace();
 
-        }
+        }*/
 
     }
 }

+ 4 - 0
src/main/java/net/chenlin/dp/modules/sys/dao/TestU8Mapper.java

@@ -20,6 +20,10 @@ public interface TestU8Mapper extends BaseMapper<SyViewEntity> {
 
 	List<SyViewEntity> selectView(String tableType);
 
+	List<SyViewEntity> selectViewByError(String tableType);
+
+	List<SyViewEntity> selectViewByTrue(String tableType);
+
 	/**
 	 * 调用存储过程 获取下一个编码
 	 * @param StuNo

+ 28 - 2
src/main/java/net/chenlin/dp/modules/sys/entity/SyViewEntity.java

@@ -14,10 +14,15 @@ public class SyViewEntity implements Serializable {
 
 
 	/**
-	 * 钉钉中id
+	 * 钉钉中原始单据id
 	 */
 	private String oaId;
 
+	/**
+	 * 钉钉中传入的新单据id
+	 */
+	private String oaNid;
+
 	/**
 	 * 报销类型
 	 */
@@ -50,10 +55,31 @@ public class SyViewEntity implements Serializable {
 	private Timestamp createTime;
 
 	/**
-	 * 备用金、报销单
+	 * 备用金至银行凭证、报销单至银行凭证、银行凭证至U8
 	 */
 	private String tableType;
 
+	/**
+	 * 同步状态(ture/false)
+	 */
+	private String syState;
+
+	public String getOaNid() {
+		return oaNid;
+	}
+
+	public void setOaNid(String oaNid) {
+		this.oaNid = oaNid;
+	}
+
+	public String getSyState() {
+		return syState;
+	}
+
+	public void setSyState(String syState) {
+		this.syState = syState;
+	}
+
 	public String getTableType() {
 		return tableType;
 	}

+ 16 - 0
src/main/java/net/chenlin/dp/modules/sys/mapper/testU8.xml

@@ -62,9 +62,22 @@
 		and table_type = #{tableType}
 	</select>
 
+	<select id="selectViewByError" resultType="net.chenlin.dp.modules.sys.entity.SyViewEntity">
+		select oa_Id as oaId from sy_view
+		where DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') and sy_state = "error"
+		and table_type = #{tableType}
+	</select>
+
+	<select id="selectViewByTrue" resultType="net.chenlin.dp.modules.sys.entity.SyViewEntity">
+		select oa_Id as oaId from sy_view
+		where DATE_FORMAT(create_time,'%Y-%m-%d') >= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 10 DAY),'%Y-%m-%d')
+		and sy_state = "true" and table_type = #{tableType}
+	</select>
+
 	<insert id="save">
 		INSERT INTO sy_view (
 			oa_id,
+			oa_nid,
 			par_type,
 			account_code,
 			dept_name,
@@ -72,10 +85,12 @@
 			job_number,
 			create_time,
 			sy_message,
+			sy_state,
 			table_type
 		)
 		VALUES (
 			   #{oaId},
+			   #{oaNid},
 			   #{parType},
 			   #{accountCode},
 			   #{deptName},
@@ -83,6 +98,7 @@
 			   #{jobNumber},
 			   now(),
 			   #{syMessage},
+			   #{syState},
 		        #{tableType}
 
 			   )

+ 10 - 0
src/main/java/net/chenlin/dp/modules/sys/service/impl/testU8ServiceImpl.java

@@ -35,6 +35,16 @@ public class testU8ServiceImpl implements testU8Service {
 		return testU8Mapper.selectView(tableType);
 	}
 
+	@Override
+	public List<SyViewEntity> selectViewByError(String tableType) {
+		return testU8Mapper.selectViewByError(tableType);
+	}
+
+	@Override
+	public List<SyViewEntity> selectViewByTrue(String tableType) {
+		return testU8Mapper.selectViewByTrue(tableType);
+	}
+
 	@Override
 	public R saveSyView(SyViewEntity area) {
 		int count = testU8Mapper.save(area);

+ 4 - 0
src/main/java/net/chenlin/dp/modules/sys/service/testU8Service.java

@@ -18,6 +18,10 @@ public interface testU8Service {
 
 	public List<SyViewEntity> selectView(String tableType);
 
+	public List<SyViewEntity> selectViewByError(String tableType);
+
+	public List<SyViewEntity> selectViewByTrue(String tableType);
+
 	/**
 	 * 调用存储过程 获取下一个编码
 	 * @param StuNo