Просмотр исходного кода

Merge branch 'master' of http://111.75.220.136:10030/13246659623/jxyh

sbtjtserver/zhaoxh 8 месяцев назад
Родитель
Сommit
8a41240741
23 измененных файлов с 2826 добавлено и 438 удалено
  1. 20 53
      src/main/java/fi/em/formPlugin/AmountEditPlugin.java
  2. 3 1
      src/main/java/fi/em/formPlugin/BusinessProcessingPlugin.java
  3. 5 5
      src/main/java/fi/em/formPlugin/ReimbursementFormPlugin.java
  4. 225 0
      src/main/java/fi/em/formPlugin/SalaryDistributeEditPlugin.java
  5. 0 21
      src/main/java/fi/em/formPlugin/TripreimBurseEditPlugin.java
  6. 87 0
      src/main/java/fi/em/opplugin/AmountOpPlugin.java
  7. 1 3
      src/main/java/fi/em/opplugin/BusinessProcessingOpPlugin.java
  8. 44 0
      src/main/java/fi/em/opplugin/SalaryDistributeOpPlugin.java
  9. 1 3
      src/main/java/fi/fa/formPlugin/AssetSplitBilFormPlugin.java
  10. 350 0
      src/main/java/fi/fa/opplugin/AssetMidBillOpPlugin.java
  11. 60 0
      src/main/java/fi/fa/opplugin/BusProcessBillOpPlugin.java
  12. 105 0
      src/main/java/fi/fa/opplugin/FaChangeDeptBillOpPlugin.java
  13. 57 0
      src/main/java/fi/fa/opplugin/FaDispatchBillOpPlugin.java
  14. 7 9
      src/main/java/fi/fa/opplugin/RealCardSplitF7OpPlugin.java
  15. 70 0
      src/main/java/fi/fa/webService/ApisaveDemoPlugin.java
  16. 160 39
      src/main/java/fi/fa/webService/DispatchMidController.java
  17. 1 1
      src/main/java/kd/imc/rim/common/helper/RecognitionCheckHelperEx.java
  18. 0 202
      src/main/java/kd/imc/rim/common/invoice/collector/InvoiceCollectTaskNew.java
  19. 185 30
      src/main/java/kd/imc/rim/common/invoice/recognition/impl/RecognitionCheckTaskEx.java
  20. 453 0
      src/main/java/kd/imc/rim/common/service/ElectAccVoucherServiceEx.java
  21. 125 70
      src/main/java/kd/imc/rim/common/service/RecognitionCheckServiceEx.java
  22. 867 0
      src/main/java/kd/imc/rim/common/utils/FileUtilsEx.java
  23. 0 1
      src/main/java/kd/imc/rim/formplugin/collector/InvoiceCollectPluginEx.java

+ 20 - 53
src/main/java/fi/em/formPlugin/AmountEditPlugin.java

@@ -7,6 +7,7 @@ import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.dataentity.entity.DynamicObjectCollection;
 import kd.bos.entity.datamodel.events.ChangeData;
 import kd.bos.entity.datamodel.events.PropertyChangedArgs;
+import kd.bos.exception.KDBizException;
 import kd.bos.list.plugin.AbstractListPlugin;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
@@ -37,37 +38,17 @@ public class AmountEditPlugin extends AbstractListPlugin implements Plugin,IErSe
     {
         super.beforePropertyChanged(e);
         String name = e.getProperty().getName();
-        //重新出发付现金额计算
-        if(nckd_unexporiusedamount.equals(name))
-        {
-            DynamicObject data=this.getModel().getDataEntity();//获取单据模型
-            DynamicObjectCollection tripentry = data.getDynamicObjectCollection("tripentry");//获取形成信息分录
-            //付现金额触发
-            for (DynamicObject item:tripentry) {
-                DynamicObjectCollection entryentity_cl=item.getDynamicObjectCollection("entryentity");//差旅明细分录
-                for (int i=0;i< entryentity_cl.size();i++) {
-                    //判断报销金额是否有值
-                    if (entryentity_cl.get(i).getBigDecimal("orientryamount").compareTo(BigDecimal.ZERO)>0) {
-                        BigDecimal amount=entryentity_cl.get(i).getBigDecimal("orientryamount");
-                        this.getModel().setValue("orientryamount",0,i);
-                        this.getModel().setValue("orientryamount",amount,i);
-                        break;
-                    }
-                }
-            }
-
-        }
 
 
         if (nckd_unexporiusedamount.equals(name)||orientryamount.equals(name))
         {
-            DynamicObject data=this.getModel().getDataEntity();//获取单据模型
+
             //冲销金额总数
             BigDecimal orgiexpebalanceamount_sum = new BigDecimal("0");
             //费用合计
             BigDecimal amountfy=new BigDecimal("0");
             //行程信息
-            DynamicObjectCollection tripentry = data.getDynamicObjectCollection("tripentry");//获取形成信息分录
+            DynamicObjectCollection tripentry = this.getModel().getEntryEntity("tripentry");//获取形成信息分录
             for (DynamicObject item:tripentry) {
                 DynamicObjectCollection entryentity_cl=item.getDynamicObjectCollection("entryentity");//差旅明细分录
                 for (int i=0;i< entryentity_cl.size();i++) {
@@ -76,7 +57,8 @@ public class AmountEditPlugin extends AbstractListPlugin implements Plugin,IErSe
                 }
             }
             //amountfy报销金额总和
-            DynamicObjectCollection nckd_clearloanentry = data.getDynamicObjectCollection("nckd_clearloanentry");//获取冲预付借款分录
+            //获取冲预付借款分录
+            DynamicObjectCollection nckd_clearloanentry=this.getModel().getEntryEntity("nckd_clearloanentry");
             for (DynamicObject entryentity:nckd_clearloanentry)
             {
                 //冲销金额
@@ -86,41 +68,26 @@ public class AmountEditPlugin extends AbstractListPlugin implements Plugin,IErSe
             }
             //计算收款金额
             this.getModel().setValue("orireceiveamount",amountfy.subtract(orgiexpebalanceamount_sum),0);
+        }
 
-
-            //反写预付借款单未核销金额(借款余额)
-            //获取冲预付借款分录
-             nckd_clearloanentry=data.getDynamicObjectCollection("nckd_clearloanentry");
-            //获取分录改变行号
-            int number=e.getChangeSet()[0].getRowIndex();
-            //数据id
-            Long id=nckd_clearloanentry.get(number).getLong("nckd_bigintfield");
-            //冲销金额
-            BigDecimal nckd_unexporiusedamount=nckd_clearloanentry.get(number).getBigDecimal("nckd_unexporiusedamount");
-            //借款余额
-            BigDecimal nckd_exporiusedamount=nckd_clearloanentry.get(number).getBigDecimal("nckd_exporiusedamount");
-            //获取改变行预付单借款编号
-            String nckd_billno=nckd_clearloanentry.get(number).getString("nckd_billno");
-            //根据行号查询预付借款单预付信息数据
-            QFilter nckd_orgamountFilter = new QFilter("billno", QCP.equals, nckd_billno);
-            DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.
-                    load(er_prepaybill, "id,number", new QFilter[]{nckd_orgamountFilter});
-            for (int i=0;i<nckd_orgamountaccount.length;i++) {
-                DynamicObject dynamicObject = BusinessDataServiceHelper.
-                        loadSingle(nckd_orgamountaccount[i].getPkValue(), nckd_orgamountaccount[i].getDynamicObjectType().getName());
-                //获取预付信息分录
-                DynamicObjectCollection expenseentryentity=dynamicObject.getDynamicObjectCollection("expenseentryentity");
-                for (DynamicObject list:expenseentryentity) {
-                    Long listid=list.getLong("id");
-                    if (listid.equals(id)) {
-                        //未核销金额(借款余额)=借款余额-冲销金额
-                        list.set("nckd_settleamount_et",nckd_exporiusedamount.subtract(nckd_unexporiusedamount));
-                        SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
+        //重新触发付现金额计算
+        if(nckd_unexporiusedamount.equals(name))
+        {
+            DynamicObjectCollection tripentry = this.getModel().getEntryEntity("tripentry");//获取形成信息分录
+            //付现金额触发
+            for (DynamicObject item:tripentry) {
+                DynamicObjectCollection entryentity_cl=item.getDynamicObjectCollection("entryentity");//差旅明细分录
+                for (int i=0;i< entryentity_cl.size();i++) {
+                    //判断报销金额是否有值
+                    if (entryentity_cl.get(i).getBigDecimal("orientryamount").compareTo(BigDecimal.ZERO)>0) {
+                        BigDecimal amount=entryentity_cl.get(i).getBigDecimal("orientryamount");
+                        this.getModel().setValue("orientryamount",0,i);
+                        this.getModel().setValue("orientryamount",amount,i);
+                        break;
                     }
                 }
             }
 
-
         }
     }
 

+ 3 - 1
src/main/java/fi/em/formPlugin/BusinessProcessingPlugin.java

@@ -166,7 +166,9 @@ public class BusinessProcessingPlugin extends AbstractFormPlugin implements Plug
                     obj.put("nckd_cysnumber", billno);
                     obj.put("nckd_cysdata", bizdate);
                     obj.put("expectdate", expectdate);
-                    obj.put("settleorg", settleorg.getString("number"));
+                    if (settleorg != null) {
+                        obj.put("settleorg", settleorg.getString("number"));
+                    }
                     if (eExpenseitem != null) {
                         obj.put("nckd_cysfyxm", eExpenseitem.getString("number"));
                     } else {

+ 5 - 5
src/main/java/fi/em/formPlugin/ReimbursementFormPlugin.java

@@ -125,16 +125,16 @@ public class ReimbursementFormPlugin extends AbstractFormPlugin implements Plugi
                 DynamicObject expenseitem=entryentity.getDynamicObject("expenseitem");
                 //申请金额
                 BigDecimal expenseamount=entryentity.getBigDecimal("expenseamount");
-                //结算金额(借款余额)
-                BigDecimal exporiusedamount=entryentity.getBigDecimal("nckd_settleamount_et");
-                //未结算金额
+                //结算金额
+                BigDecimal exporiusedamount=entryentity.getBigDecimal("nckd_unsettleamount_et");
+                //未结算金额(借款余额)
                 BigDecimal orgiexpebalanceamount=entryentity.getBigDecimal("nckd_unsettleamount_et");
                 //备注
                 String remark=entryentity.getString("remark");
 
                 Long id=entryentity.getLong("id");
-                //借款余额大于0
-                if (exporiusedamount.compareTo(BigDecimal.ZERO)>0)
+                //未结算金额大于0
+                if (orgiexpebalanceamount.compareTo(BigDecimal.ZERO)>0)
                 {
                     //新增动态单据分录
                     int rowIndex = this.getModel().createNewEntryRow(FORMID_ENTRY);

+ 225 - 0
src/main/java/fi/em/formPlugin/SalaryDistributeEditPlugin.java

@@ -0,0 +1,225 @@
+package fi.em.formPlugin;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.entity.datamodel.events.ChangeData;
+import kd.bos.entity.datamodel.events.PropertyChangedArgs;
+import kd.bos.form.ConfirmCallBackListener;
+import kd.bos.form.ConfirmTypes;
+import kd.bos.form.MessageBoxOptions;
+import kd.bos.form.MessageBoxResult;
+import kd.bos.form.events.BeforeDoOperationEventArgs;
+import kd.bos.form.events.MessageBoxClosedEvent;
+import kd.bos.form.operate.FormOperate;
+import kd.bos.list.plugin.AbstractListPlugin;
+import kd.sdk.plugin.Plugin;
+
+import java.util.ArrayList;
+import java.util.EventObject;
+import java.util.List;
+
+/**
+ * @author cjz
+ * @date 2024/8/19 9:01
+ * @description:薪酬计提单,根据业务类型显示分录
+ */
+public class SalaryDistributeEditPlugin extends AbstractListPlugin implements Plugin {
+
+    private static String nckd_entrytype="nckd_entrytype";//业务类型标识
+    private static String nckd_generalemployees="nckd_generalemployees";//薪酬明细(一般员工)分录标识
+    private static String nckd_earlyretired="nckd_earlyretired";//薪酬明细(内退)分录标识
+    private static String nckd_retired="nckd_retired";//薪酬明细(退休)分录标识
+    private static String nckd_pay="nckd_pay";//人力薪酬分录标识
+    private static String oldentryNum="oldentryNum";
+    private static String newentryNum="newentryNum";
+
+
+    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
+//        super.beforeDoOperation(args);
+//        FormOperate source = (FormOperate) args.getSource();
+//        String KEY_PAY = source.getOperateKey();
+//        //判断是否是绑定操作编码
+//        if (KEY_PAY.equals("操作编码")){
+//            // 查询数据判断是否满足条件(校验):这里可以改成自已的逻辑
+//            DynamicObject status = (DynamicObject) this.getModel().getValue("cqkd_workstatus");
+//            if (status.getString("name").equals("xxx")){
+//                // 显示确认消息
+//                ConfirmCallBackListener confirmCallBacks = new ConfirmCallBackListener(KEY_PAY, this);
+//                String confirmTip = "您确认要执行xxx操作吗?";
+//                this.getView().showConfirm(confirmTip, MessageBoxOptions.YesNo, ConfirmTypes.Default, confirmCallBacks);
+//                //确认或取消之前取消后续操作
+//                args.setCancel(true);
+//            }else {
+//                //如果没有通过校验则显示xxx
+//                this.getView().showMessage("xxx");
+//            }
+//        }
+
+    }
+    //VieaFlag为分录标识,传入的分录显示,其他则隐藏
+    public void setVieeVisible(String Viewflag)
+    {
+        List<String> viewList=new ArrayList<>();
+        viewList.add(nckd_generalemployees);
+        viewList.add(nckd_earlyretired);
+        viewList.add(nckd_retired);
+        viewList.add(nckd_pay);
+
+        if (Viewflag.isEmpty()) {
+            for (String item:viewList) {
+                this.getView().setVisible(false,item);
+            }
+            //清空所有分录
+            //一般员工分录
+            this.getModel().deleteEntryData("nckd_staffentry");
+            //内退分录
+            this.getModel().deleteEntryData("nckd_earlyretiredentry");
+            //退休分录
+            this.getModel().deleteEntryData("nckd_retireentry");
+            //人力薪酬分录
+            this.getModel().deleteEntryData("nckd_salaryentry");
+        }
+        //薪酬明细(一般员工)分录
+        if (Viewflag.equals(nckd_generalemployees)) {
+            for (String item:viewList) {
+                this.getView().setVisible(false,item);
+            }
+            //内退分录
+            this.getModel().deleteEntryData("nckd_earlyretiredentry");
+            //退休分录
+            this.getModel().deleteEntryData("nckd_retireentry");
+            //人力薪酬分录
+            this.getModel().deleteEntryData("nckd_salaryentry");
+            this.getView().setVisible(true,nckd_generalemployees);
+        }
+        //薪酬明细(内退)分录
+        if (Viewflag.equals(nckd_earlyretired)) {
+            for (String item:viewList) {
+                this.getView().setVisible(false,item);
+            }
+            //一般员工分录
+            this.getModel().deleteEntryData("nckd_staffentry");
+            //退休分录
+            this.getModel().deleteEntryData("nckd_retireentry");
+            //人力薪酬分录
+            this.getModel().deleteEntryData("nckd_salaryentry");
+            this.getView().setVisible(true,nckd_earlyretired);
+        }
+        //薪酬明细(退休)分录
+        if (Viewflag.equals(nckd_retired)) {
+            for (String item:viewList) {
+                this.getView().setVisible(false,item);
+            }
+            //一般员工分录
+            this.getModel().deleteEntryData("nckd_staffentry");
+            //内退分录
+            this.getModel().deleteEntryData("nckd_earlyretiredentry");
+            //人力薪酬分录
+            this.getModel().deleteEntryData("nckd_salaryentry");
+            this.getView().setVisible(true,nckd_retired);
+        }
+        //人力薪酬分录
+        if (Viewflag.equals(nckd_pay)) {
+            for (String item:viewList) {
+                this.getView().setVisible(false,item);
+            }
+            //清空其他分录
+            //一般员工分录
+            this.getModel().deleteEntryData("nckd_staffentry");
+            //内退分录
+            this.getModel().deleteEntryData("nckd_earlyretiredentry");
+            //退休分录
+            this.getModel().deleteEntryData("nckd_retireentry");
+            this.getView().setVisible(true,nckd_pay);
+        }
+    }
+
+    public void afterCreateNewData(EventObject e){
+        super.afterBindData(e);
+        //设置初始状态分录为不可见
+        this.setVieeVisible("");
+    }
+
+
+    public void propertyChanged(PropertyChangedArgs e)
+    {
+        super.beforePropertyChanged(e);
+        String name=e.getProperty().getName();
+        //获取单据模型
+        DynamicObject data=this.getModel().getDataEntity();
+
+        if (nckd_entrytype.equals(name)) {
+            //获取当前分录类型
+            ChangeData[] changeSet=e.getChangeSet();
+            ChangeData changeData=changeSet[0];
+//            String oldValue =(String)changeData.getOldValue();
+//            String newValue =(String)changeData.getNewValue() ;
+            oldentryNum=(String)changeData.getOldValue();
+            newentryNum=(String)changeData.getNewValue();
+            String entrytype=data.getString(nckd_entrytype);
+
+            if (entrytype.isEmpty()) {
+                this.setVieeVisible("");
+            }
+            //分录类型为薪酬明细(一般员工)
+            if (entrytype.equals("A")) {
+                ConfirmCallBackListener confirmCallBacks = new ConfirmCallBackListener(String.valueOf(false), this);
+                String confirmTip = "您确定要将分录类型改变为薪酬明细(一般员工)?操作会清空其他分录的数据,是否继续?";
+                this.getView().showConfirm(confirmTip,MessageBoxOptions.YesNo, ConfirmTypes.Default, confirmCallBacks);
+            }
+            //分录类型为薪酬明细(内退)
+            if (entrytype.equals("B")) {
+                ConfirmCallBackListener confirmCallBacks = new ConfirmCallBackListener(String.valueOf(false), this);
+                String confirmTip = "您确定要将分录类型改变为薪酬明细(内退)?操作会清空其他分录的数据,是否继续?";
+                this.getView().showConfirm(confirmTip,MessageBoxOptions.YesNo, ConfirmTypes.Default, confirmCallBacks);
+            }
+            //分录类型为薪酬明细退休
+            if (entrytype.equals("C")) {
+                ConfirmCallBackListener confirmCallBacks = new ConfirmCallBackListener(String.valueOf(false), this);
+                String confirmTip = "您确定要将分录类型改变为薪酬明细(退休)?操作会清空其他分录的数据,是否继续?";
+                this.getView().showConfirm(confirmTip,MessageBoxOptions.YesNo, ConfirmTypes.Default, confirmCallBacks);
+            }
+            //分录类型为人力薪酬
+            if (entrytype.equals("D")) {
+                ConfirmCallBackListener confirmCallBacks = new ConfirmCallBackListener(String.valueOf(false), this);
+                String confirmTip = "您确定要将分录类型改变为人力薪酬?操作会清空其他分录的数据,是否继续?";
+                this.getView().showConfirm(confirmTip,MessageBoxOptions.YesNo, ConfirmTypes.Default, confirmCallBacks);
+            }
+        }
+    }
+
+    //点击弹窗后回调
+    public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) {
+        super.confirmCallBack(messageBoxClosedEvent);
+        DynamicObject data=this.getModel().getDataEntity();
+        //获取当前分录类型
+        String entrytype=data.getString(nckd_entrytype);
+        // 判断如果是确认按钮
+        if (messageBoxClosedEvent.getResult() == MessageBoxResult.Yes) {
+            //分录类型为薪酬明细(一般员工)
+            if (entrytype.equals("A")) {
+                this.setVieeVisible(nckd_generalemployees);
+            }
+            //分录类型为薪酬明细(内退)
+            if (entrytype.equals("B")) {
+                this.setVieeVisible(nckd_earlyretired);
+            }
+            //分录类型为薪酬明细退休
+            if (entrytype.equals("C")) {
+                this.setVieeVisible(nckd_retired);
+            }
+            //分录类型为人力薪酬
+            if (entrytype.equals("D")) {
+                this.setVieeVisible(nckd_pay);
+            }
+        }
+        //如果为取消,则
+        if (messageBoxClosedEvent.getResult()==MessageBoxResult.No)
+        {
+            //设置回原来的值,不触发值改变事件
+            this.getModel().beginInit();
+            data.set("nckd_entrytype",oldentryNum);
+            this.getModel().endInit();
+            this.getView().updateView();
+        }
+    }
+}

+ 0 - 21
src/main/java/fi/em/formPlugin/TripreimBurseEditPlugin.java

@@ -100,27 +100,6 @@ public class TripreimBurseEditPlugin extends AbstractListPlugin implements Plugi
                     this.getModel().setValue("nckd_remark",remark,rowIndex);//备注
                     this.getModel().setValue("nckd_bigintfield",id,rowIndex);//id
                     this.getModel().setValue("nckd_billno",loanbillno,rowIndex);
-
-                    //反写预付借款单
-                    QFilter nckd_orgamountFilter = new QFilter("billno", QCP.equals, loanbillno);
-                    DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.
-                            load(er_prepaybill, "id,number", new QFilter[]{nckd_orgamountFilter});
-                    for (int j=0;j<nckd_orgamountaccount.length;j++) {
-                        DynamicObject dynamicObject = BusinessDataServiceHelper.
-                                loadSingle(nckd_orgamountaccount[i].getPkValue(), nckd_orgamountaccount[i].getDynamicObjectType().getName());
-                        //获取预付信息分录
-                        DynamicObjectCollection expenseentryentity=dynamicObject.getDynamicObjectCollection("expenseentryentity");
-                        for (DynamicObject list:expenseentryentity) {
-                            Long listid=list.getLong("id");
-                            if (listid.equals(id)) {
-                                //借款余额-冲销金额
-                                list.set("nckd_settleamount_et",exporiusedamount.subtract(orgiexpebalanceamount));
-                                SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
-                            }
-                        }
-                    }
-
-
                 }
                 //刷新分录
                 this.getView().updateView("nckd_clearloanentry");

+ 87 - 0
src/main/java/fi/em/opplugin/AmountOpPlugin.java

@@ -0,0 +1,87 @@
+package fi.em.opplugin;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
+import kd.bos.exception.KDBizException;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+
+import java.math.BigDecimal;
+
+/**
+ * @author cjz
+ * @date 2024/8/19 16:07
+ * @description:提交前校验,冲销金额不能大于借款余额,反写预付借款单
+ */
+public class AmountOpPlugin extends AbstractOperationServicePlugIn {
+
+    private static String er_prepaybill="er_prepaybill";//预付报销单标识
+
+
+
+    @Override
+    public void beginOperationTransaction(BeginOperationTransactionArgs e){
+        //获取当前操作单据数组
+        DynamicObject[] dynamicObjects = e.getDataEntities();
+        for (int i=0;i< dynamicObjects.length;i++)
+        {
+            DynamicObject info = BusinessDataServiceHelper.
+                    loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());
+            DynamicObjectCollection nckd_clearloanentry=info.getDynamicObjectCollection("nckd_clearloanentry");//获取冲预付借款分录
+
+            //获取冲销金额
+            for (int j=0;j< nckd_clearloanentry.size();j++)
+            {
+                //获取借款余额
+                BigDecimal nckd_exporiusedamount=nckd_clearloanentry.get(i).getBigDecimal("nckd_exporiusedamount");
+                //获取冲销金额
+                BigDecimal orgiexpebalanceamount=nckd_clearloanentry.get(i).getBigDecimal("nckd_unexporiusedamount");
+                //冲销金额大于借款余额
+                if (orgiexpebalanceamount.compareTo(nckd_exporiusedamount)==1) {
+                    throw new KDBizException("第"+(j+1)+"行存在错误,冲销金额不能大于借款余额!");
+                }else {
+                    //反写字段到预付借款单
+                    //数据id
+                     Long id=nckd_clearloanentry.get(j).getLong("nckd_bigintfield");
+                    //获取行预付单借款编号
+                    String nckd_billno=nckd_clearloanentry.get(j).getString("nckd_billno");
+                    //根据行号查询预付借款单预付信息数据
+                    QFilter nckd_orgamountFilter = new QFilter("billno", QCP.equals, nckd_billno);
+                    //获取预付单信息分录
+                    DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.
+                         load(er_prepaybill, "id,number", new QFilter[]{nckd_orgamountFilter});
+                    for (int c=0;c<nckd_orgamountaccount.length;c++)
+                    {
+                        DynamicObject dynamicObject=BusinessDataServiceHelper
+                                .loadSingle(nckd_orgamountaccount[c].getPkValue(),nckd_orgamountaccount[c].getDynamicObjectType().getName());
+                        //获取预付借款单预付信息分录
+                        DynamicObjectCollection expenseentryentity=dynamicObject.getDynamicObjectCollection("expenseentryentity");
+                        for (DynamicObject list:expenseentryentity) {
+                            //id
+                            Long listid=list.getLong("id");
+                            //未核销金额
+                            BigDecimal orgamount=list.getBigDecimal("orgiexpebalanceamount");
+                            //未结算金额
+                            BigDecimal nckd_unsettleamount_et=list.getBigDecimal("nckd_unsettleamount_et");
+                            //结算金额
+                            BigDecimal nckd_settleamount_et=list.getBigDecimal("nckd_settleamount_et");
+                            if (listid.equals(id)) {
+                                //未核销金额-冲销金额
+                                list.set("orgiexpebalanceamount",orgamount.subtract(orgiexpebalanceamount));
+                                //未结算金额-冲销金额
+                                list.set("nckd_unsettleamount_et",nckd_unsettleamount_et.subtract(orgiexpebalanceamount));
+                                //已结算金额+冲销金额
+                                list.set("nckd_settleamount_et",nckd_settleamount_et.add(orgiexpebalanceamount));
+                                SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

+ 1 - 3
src/main/java/fi/em/opplugin/BusinessProcessingOpPlugin.java

@@ -32,9 +32,7 @@ public class BusinessProcessingOpPlugin extends AbstractOperationServicePlugIn {
                     if (latitudeDou != latitudeDous) {
                         throw new KDBizException("收款金额与冲销金额不一致!");
                     }
-                    if (latitudeDou != latitudeDo) {
-                        throw new KDBizException("收款金额与合同冲销金额不一致!");
-                    }
+
                 }
                 DynamicObjectCollection nckdEntryentity3 = info.getDynamicObjectCollection("nckd_entryentity3");
                 if (!nckdEntryentity3.isEmpty()) {

+ 44 - 0
src/main/java/fi/em/opplugin/SalaryDistributeOpPlugin.java

@@ -0,0 +1,44 @@
+package fi.em.opplugin;
+
+import kd.bos.context.RequestContext;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
+import kd.bos.form.events.BeforeDoOperationEventArgs;
+import kd.bos.form.operate.FormOperate;
+import kd.bos.list.plugin.AbstractListPlugin;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import kd.sdk.plugin.Plugin;
+
+/**
+ * @author cjz
+ * @date 2024/8/20 9:01
+ * @description:薪酬计提单,审核后自动带出审核人和审核日期
+ */
+public class SalaryDistributeOpPlugin extends AbstractOperationServicePlugIn  {
+
+    private static String nckd_salarydistribute="nckd_salarydistribute";//薪酬计提单标识
+    private static String audit="audit";//审核操作标识
+
+
+
+    @Override
+    public void beginOperationTransaction(BeginOperationTransactionArgs args){
+        DynamicObject[] dynamicObjects = args.getDataEntities();
+        for(int i=0;i< dynamicObjects.length;i++) {
+            String billno=dynamicObjects[i].getString("billno");
+            //根据单据号查询
+            QFilter filter=new QFilter("billno", QCP.equals, billno);
+            DynamicObject nckd_salary = BusinessDataServiceHelper.
+                    loadSingle(nckd_salarydistribute, "id,number,billno,nckd_auditor", new QFilter[]{filter});
+            //设置审核人
+            nckd_salary.set("nckd_auditor",RequestContext.get().getUserId());
+            SaveServiceHelper.save(new DynamicObject[]{nckd_salary});
+        }
+    }
+
+
+}

+ 1 - 3
src/main/java/fi/fa/formPlugin/AssetSplitBilFormPlugin.java

@@ -21,9 +21,7 @@ public class AssetSplitBilFormPlugin extends AbstractListPlugin implements Plugi
             DynamicObjectCollection subassetsplitentry = (DynamicObjectCollection) this.getModel().getValue("subassetsplitentry");
             String number = this.getModel().getDataEntity().getDynamicObjectCollection("assetsplitentry").get(0).getDynamicObject("realcard").getString("number");
             //查询e管家实物卡片清单
-//            QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
-            QFilter filter = new QFilter("name", QCP.equals,"电脑");
-            filter.or("name", QCP.equals, "手机");
+            QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
             DynamicObject[] dynamicObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
             for (int i = 0; i < dynamicObjects.length; i++) {
                 DynamicObject info = BusinessDataServiceHelper.loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());

+ 350 - 0
src/main/java/fi/fa/opplugin/AssetMidBillOpPlugin.java

@@ -0,0 +1,350 @@
+package fi.fa.opplugin;
+
+import com.alibaba.druid.util.StringUtils;
+import kd.bos.dataentity.OperateOption;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.entity.operate.result.OperationResult;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
+import kd.bos.exception.KDBizException;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.OperationServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import org.apache.commons.lang3.ObjectUtils;
+import java.util.ArrayList;
+import java.util.List;
+
+public class AssetMidBillOpPlugin extends AbstractOperationServicePlugIn {
+    @Override
+    public void beginOperationTransaction(BeginOperationTransactionArgs e) {
+        super.beginOperationTransaction(e);
+        DynamicObject[] dynamicObjects = e.getDataEntities();
+        for (int i = 0; i < dynamicObjects.length; i++) {
+            if (StringUtils.equals(e.getOperationKey(), "push")) {
+                DynamicObject info = BusinessDataServiceHelper.loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());
+                String nckd_flag = info.getString("nckd_flag");
+                if ("1".equals(nckd_flag)) {
+                    throw new KDBizException("单据" + info.getString("number") + "已经下推生成了资产调拨单,不允许重复下推!");
+                }else {
+                    String dispatchType = info.getString("nckd_dispatch_type");
+                    String direction = info.getString("nckd_direction");
+                    String nckd_card_real_code = info.getString("nckd_card_number_tag");
+                    String[] asset = nckd_card_real_code.split(",");
+                    // 存储键的数组
+                    String[] keys = new String[asset.length];
+                    List<String> number = new ArrayList<>();
+                    List<String> cardNumber = new ArrayList<>();
+                    // 遍历每个键值对并获取键
+                    for (int j = 0; j < asset.length; j++) {
+                        String[] keyValue = asset[j].split(":");
+                        if (keyValue.length > 0) {
+                            number.add(keyValue[0]);
+                        }
+                    }
+                    //查询e管家实物卡片清单
+                    QFilter cardFilter = new QFilter("number", QCP.in,number);
+                    DynamicObject[] eCard = BusinessDataServiceHelper.load("nckd_fa_card_real_list","nckd_card_real_code",new QFilter[] {cardFilter});
+                    for (DynamicObject object : eCard) {
+                        cardNumber.add(object.getString("nckd_card_real_code"));
+                    }
+                    if ("0".equals(dispatchType)) {
+                        List<String> list = new ArrayList<>();
+                        list.add("A00100101900240600002");
+                        list.add("A00100101900240600008");
+                        QFilter filter = new QFilter("number", QCP.in,"A00100101900240600002");
+                        filter.and("isbak",  QCP.equals, "0");
+                        DynamicObject[] card = BusinessDataServiceHelper.load("fa_card_real","id",new QFilter[] {filter});
+//                        if (asset.length == card.length) {
+                            DynamicObject dispatch = BusinessDataServiceHelper.newDynamicObject("fa_dispatch");
+                            //单据头
+                            dispatch.set("dispatchdate", info.getDate("nckd_date_out"));//调出日期
+                            dispatch.set("assetunit", getOrg(info.getString("nckd_org_out")));//调出组织
+                            dispatch.set("inassetunit", getOrg(info.getString("nckd_org_in")));//调入组织
+                            dispatch.set("org", getOrg(info.getString("nckd_org_out")));//调出核算组织
+                            dispatch.set("inorg", getOrg(info.getString("nckd_org_in")));//调入核算组织
+                            dispatch.set("reason", info.getString("nckd_reason"));//调出原因
+                            dispatch.set("dispatchtype", "A");//调拨类型 A="平价调拨",B="非平价调拨"
+                            dispatch.set("changemode", 14);//减少方式默认"调出"
+                            dispatch.set("currency", 1);//币种
+                            dispatch.set("currencyrate", 1);//结算汇率
+                            //制单信息
+                            dispatch.set("billstatus", "A");//暂存
+                        //调出方向
+                        if("0".equals(direction)){
+                            dispatch.set("outuser", getUser(info.getString("nckd_user_out")));//调出申请人
+                            dispatch.set("inuser", getUser(info.getString("nckd_user_in")));//调入负责人
+                            dispatch.set("creator", getUser(info.getString("nckd_user_out")));//创建人
+                            dispatch.set("modifier", getUser(info.getString("nckd_user_out")));//修改人
+                            dispatch.set("auditor", getUser(info.getString("nckd_user_out")));//审核人
+                            dispatch.set("appliant", getUser(info.getString("nckd_user_out")));//调拨申请人
+                        }//调入方向
+                        else if ("1".equals(direction)) {
+                            dispatch.set("outuser", getUser(info.getString("nckd_user_in")));//调出申请人
+                            dispatch.set("inuser", getUser(info.getString("nckd_user_out")));//调入负责人
+                            dispatch.set("creator", getUser(info.getString("nckd_user_in")));//创建人
+                            dispatch.set("modifier", getUser(info.getString("nckd_user_in")));//修改人
+                            dispatch.set("auditor", getUser(info.getString("nckd_user_in")));//审核人
+                            dispatch.set("appliant", getUser(info.getString("nckd_user_in")));//调拨申请人
+                        }
+                            for (int c = 0; c < card.length; c++) {
+                                DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(card[c].getPkValue(), card[c].getDynamicObjectType().getName());
+                                //创建调出单分录
+                                DynamicObjectCollection entryEntity = dispatch.getDynamicObjectCollection("dispatchentry");
+                                DynamicObject entry1 = entryEntity.addNew();
+                                entry1.set("realcard", cardInfo);//资产编码
+                                entry1.set("measurement", cardInfo.getDynamicObject("unit").getLong("id"));//计量单位
+                                entry1.set("dispatchqty", cardInfo.getInt("assetamount"));//数量
+                                entry1.set("inusedept", getOrg(info.getString("nckd_dept_in")));//调入使用部门
+                            }
+                            //执行保存-提交-审核
+                            OperationResult saveResult = SaveServiceHelper.saveOperate("fa_dispatch", new DynamicObject[]{dispatch}, OperateOption.create());
+                            if (saveResult.isSuccess()){
+                                info.set("nckd_flag", "1");
+                                SaveServiceHelper.save(new DynamicObject[]{info});
+                                this.operationResult.setSuccess(true);
+                                this.operationResult.setMessage("下推资产调出单成功");
+                                this.operationResult.setShowMessage(true);
+                                OperationResult submitResult = OperationServiceHelper.executeOperate("submit", "fa_dispatch",saveResult.getSuccessPkIds().toArray(),OperateOption.create());
+                                OperationResult auditResult = OperationServiceHelper.executeOperate("audit", "fa_dispatch",submitResult.getSuccessPkIds().toArray(),OperateOption.create());
+                            }else {
+                                this.operationResult.setShowMessage(true);
+                                this.operationResult.setSuccess(false);
+                                this.operationResult.setMessage("下推资产调出单单失败");
+                            }
+
+//                        }else {
+//                            throw new KDBizException("请先拆分实物卡片再下推生单!");
+//                        }
+
+                    }else if ("1".equals(dispatchType)) {
+                        DynamicObject changeDept = BusinessDataServiceHelper.newDynamicObject("fa_change_dept");
+                        //单据头
+                        DynamicObject orgInfo = queryOrg(getOrg(info.getString("nckd_org_in")));
+                        changeDept.set("org", orgInfo);//核算组织
+                        changeDept.set("changedate", info.getDate("nckd_date_out"));//记账日期
+                        changeDept.set("appliantid", getUser(info.getString("nckd_user_out")));//变更申请人
+                        changeDept.set("remark", info.getString("nckd_reason"));//调出原因
+                        changeDept.set("sourcetype", 2);//来源方式(5:API生成)
+                        changeDept.set("changetype", queryChangeType(Long.parseLong("733953285719123968")));//变更类型,默认部门变更
+                        changeDept.set("chtypedetail", "1");//变更类型明细默认实物变更1
+                        changeDept.set("voucherflag", "A");//记账标识默认无需记账A
+                        changeDept.set("billstatus", "A");//暂存
+                        QFilter filter = new QFilter("number", QCP.in,"A00100101900240600007");
+                        filter.and("isbak",  QCP.equals, "0");
+                        DynamicObject[] card = BusinessDataServiceHelper.load("fa_card_real","id",new QFilter[] {filter});
+                        for (int c = 0; c < card.length; c++) {
+                            DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(card[c].getPkValue(), card[c].getDynamicObjectType().getName());
+                            //查询财务卡片
+                            DynamicObject fin = queryFinCard(cardInfo.getLong("id"));//财务卡片id
+                            //创建变更字段分录
+                            DynamicObjectCollection fieldentry = changeDept.getDynamicObjectCollection("fieldentry");
+                            if (!getOrg(info.getString("nckd_org_in")).equals(cardInfo.getDynamicObject("headusedept").getLong("id"))){
+                                DynamicObject entry1 = fieldentry.addNew();
+                                entry1.set("realcard1", cardInfo);//资产编码
+                                entry1.set("depreuse1", queryDepreuse(Long.parseLong("418714318096331776")));//折旧用途默认
+                                entry1.set("currency1", 1);//币别
+                                entry1.set("basecurrency1", 1);//本币位
+                                entry1.set("assetnumber",cardInfo.getString("number"));//资产编码
+                                entry1.set("bizdate1", info.getDate("nckd_date_out"));//业务日期
+                                entry1.set("field", "fa_card_real.headusedept");//变更字段-部门
+                                entry1.set("beforevalue", String.valueOf(cardInfo.getDynamicObject("headusedept").getLong("id")));//变更前值
+                                entry1.set("aftervalue", getOrg(info.getString("nckd_dept_in")).toString());//变更后值
+                                entry1.set("realcardmasterid", cardInfo);//实物卡片id
+                                entry1.set("fincard1", fin);//财务卡片
+                            }
+                            if (ObjectUtils.isEmpty(cardInfo.getDynamicObject("headuseperson")) ||
+                                    ObjectUtils.isNotEmpty(cardInfo.getDynamicObject("headuseperson")) && !getUser(info.getString("nckd_used_user")).equals(cardInfo.getDynamicObject("headuseperson").getLong("id"))) {
+                                String beforevalue = cardInfo.getDynamicObject("headuseperson") == null ? "" : String.valueOf(cardInfo.getDynamicObject("headuseperson").getLong("id"));
+                                DynamicObject entry2 = fieldentry.addNew();
+                                entry2.set("realcard1", cardInfo);//资产编码
+                                entry2.set("depreuse1", queryDepreuse(Long.parseLong("418714318096331776")));//折旧用途默认
+                                entry2.set("currency1", 1);//币别
+                                entry2.set("basecurrency1", 1);//本币位
+                                entry2.set("assetnumber",cardInfo.getString("number"));//资产编码
+                                entry2.set("bizdate1", info.getDate("nckd_date_out"));//业务日期
+                                entry2.set("field", "fa_card_real.headuseperson");//变更字段-使用人
+                                entry2.set("beforevalue", beforevalue);//变更前值
+                                entry2.set("aftervalue", String.valueOf(getUser(info.getString("nckd_used_user")).getLong("id")));//变更后值
+                                entry2.set("realcardmasterid", cardInfo);//实物卡片id
+                                entry2.set("fincard1", fin);//财务卡片
+                            }
+
+                            //创建实物变更分录
+                            DynamicObjectCollection realentry = changeDept.getDynamicObjectCollection("realentry");
+                            DynamicObject realentry1 = realentry.addNew();
+                            realentry1.set("realcard", cardInfo.getLong("id"));//资产编码
+
+                            //创建财务变更分录
+                            DynamicObjectCollection finentry = realentry1.getDynamicObjectCollection("finentry");
+                            DynamicObject finentry1 = finentry.addNew();
+                            finentry1.set("depreuse", queryDepreuse(Long.parseLong("418714318096331776")));//折旧用途默认
+                            finentry1.set("fincard", fin);
+                            finentry1.set("bizdate", info.getDate("nckd_date_out"));
+
+                        }
+                        //执行保存-提交-审核
+                        OperationResult saveResult = SaveServiceHelper.saveOperate("fa_change_dept", new DynamicObject[]{changeDept}, OperateOption.create());
+                        if (saveResult.isSuccess()) {
+                            info.set("nckd_flag", "1");
+                            SaveServiceHelper.save(new DynamicObject[]{info});
+                            this.operationResult.setShowMessage(true);
+                            this.operationResult.setSuccess(true);
+                            this.operationResult.setMessage("下推资产变更单成功");
+                            OperationResult submitResult = OperationServiceHelper.executeOperate("submit", "fa_change_dept",saveResult.getSuccessPkIds().toArray(),OperateOption.create());
+                            OperationResult auditResult = OperationServiceHelper.executeOperate("audit", "fa_change_dept",submitResult.getSuccessPkIds().toArray(),OperateOption.create());
+                        }else {
+                            this.operationResult.setShowMessage(true);
+                            this.operationResult.setSuccess(false);
+                            this.operationResult.setMessage("下推资产变更单失败");
+                        }
+                    }
+                    else if ("2".equals(dispatchType)) {
+                        DynamicObject busProcess = BusinessDataServiceHelper.newDynamicObject("nckd_ywcld");
+                        busProcess.set("nckd_bizdate", info.getDate("nckd_date_out"));//业务日期
+                        busProcess.set("nckd_detailtype", "D");//业务类型 D:报废
+                        busProcess.set("nckd_costcompany", getOrg(info.getString("nckd_org_in")));//资产组织
+                        busProcess.set("nckd_textfield1", info.getString("nckd_reason"));//摘要事由
+                        busProcess.set("nckd_applierv", getUser(info.getString("nckd_user_out")));//制单人
+
+                        //制单信息
+                        busProcess.set("creator", getUser(info.getString("nckd_user_out")));//创建人
+                        busProcess.set("createtime", info.getDate("nckd_date_out"));//创建时间
+                        busProcess.set("modifier", getUser(info.getString("nckd_user_out")));//修改人
+                        busProcess.set("modifytime", info.getDate("nckd_date_out"));//修改时间
+                        busProcess.set("auditor", getUser(info.getString("nckd_user_out")));//审核人
+                        busProcess.set("auditdate", info.getDate("nckd_date_out"));//审核时间
+                        busProcess.set("billstatus", "A");//状态
+                        QFilter filter = new QFilter("number", QCP.equals,"A00100101900240700007");
+                        cardFilter.and("isbak",  QCP.equals, "0");
+                        DynamicObject[] card = BusinessDataServiceHelper.load("fa_card_real","id",new QFilter[] {filter});
+                        for (int c = 0; c < card.length; c++) {
+                            DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(card[c].getPkValue(), card[c].getDynamicObjectType().getName());
+                            //创建报废明细分录
+                            DynamicObjectCollection entryEntity = busProcess.getDynamicObjectCollection("nckd_entryentity6");
+                            DynamicObject entry1 = entryEntity.addNew();
+                            entry1.set("nckd_basedatafield", cardInfo);//资产编码
+                            Integer count = Integer.valueOf(info.getString("nckd_count"));
+                            entry1.set("nckd_integerfield", count);//报废数量
+                        }
+                        //执行保存-提交-审核
+                        OperationResult saveResult = SaveServiceHelper.saveOperate("nckd_ywcld", new DynamicObject[]{busProcess}, OperateOption.create());
+                        if (saveResult.isSuccess()){
+                            info.set("nckd_flag", "1");
+                            SaveServiceHelper.save(new DynamicObject[]{info});
+                            this.operationResult.setShowMessage(true);
+                            this.operationResult.setSuccess(true);
+                            this.operationResult.setMessage("下推业务处理单成功");
+                            OperationResult submitResult = OperationServiceHelper.executeOperate("submit", "nckd_ywcld",saveResult.getSuccessPkIds().toArray(),OperateOption.create());
+                            OperationResult auditResult = OperationServiceHelper.executeOperate("audit", "nckd_ywcld",submitResult.getSuccessPkIds().toArray(),OperateOption.create());
+                        }else {
+                            this.operationResult.setShowMessage(true);
+                            this.operationResult.setSuccess(false);
+                            this.operationResult.setMessage("下推业务处理单失败");
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * @description 查询用户表获取用户
+     * @param eUser
+     * @return Long
+     */
+    private DynamicObject getUser(String eUser) {
+        QFilter filter = new QFilter("number", QCP.in, eUser);
+        DynamicObject[] user = BusinessDataServiceHelper.load("bos_user","id",new QFilter[] {filter});
+        if (user.length > 0) {
+            DynamicObject userInfo = BusinessDataServiceHelper.loadSingle(user[0].getPkValue(), user[0].getDynamicObjectType().getName());
+            return userInfo;
+        }
+        return null;
+    }
+
+    /**
+     * @description 查询组织对照表获取组织id
+     * @param eOrgId
+     * @return Long
+     */
+    private Long getOrg(String eOrgId) {
+        QFilter orgFilter = new QFilter("nckd_e_org", QCP.equals,eOrgId);
+        DynamicObject[] orgControl = BusinessDataServiceHelper.load("nckd_base_org_ext","id",new QFilter[] {orgFilter});
+        if (orgControl.length > 0) {
+            DynamicObject orgControlInfo = BusinessDataServiceHelper.loadSingle(orgControl[0].getPkValue(), orgControl[0].getDynamicObjectType().getName());
+            Long orgId = Long.parseLong(orgControlInfo.getString("nckd_org_number"));
+            return orgId;
+        }//组织对照表查询不到,查询组织表
+        else {
+            if (StringUtils.isEmpty(eOrgId)) {
+                return null;
+            }
+            QFilter filter = new QFilter("id", QCP.equals,Long.parseLong(eOrgId));
+            DynamicObject[] org = BusinessDataServiceHelper.load("bos_org","id",new QFilter[] {filter});
+            if (org.length > 0) {
+                DynamicObject orgInfo = BusinessDataServiceHelper.loadSingle(org[0].getPkValue(), org[0].getDynamicObjectType().getName());
+                return orgInfo.getLong("id");
+            }
+            return null;
+        }
+    }
+
+    /**
+     * @description 查询财务卡片
+     * @param realCardId
+     */
+    private DynamicObject queryFinCard(Long realCardId) {
+        QFilter cardFilter = new QFilter("realcardmasterid", QCP.equals,realCardId);
+        DynamicObject[] card = BusinessDataServiceHelper.load("fa_card_fin","id",new QFilter[] {cardFilter});
+        for (int c = 0; c < card.length; c++) {
+            DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(card[c].getPkValue(), card[c].getDynamicObjectType().getName());
+            return cardInfo;
+        }
+        return null;
+    }
+
+    /**
+     * @description 查询折旧用途
+     * @param id
+     */
+    private DynamicObject queryDepreuse(Long id) {
+        QFilter orgQFilter= new QFilter("id", QCP.equals,id);
+        DynamicObject[] depreuse = BusinessDataServiceHelper.load("fa_depreuse","id",new QFilter[] {orgQFilter});
+        for (int c = 0; c < depreuse.length; c++) {
+            DynamicObject depreuseInfo = BusinessDataServiceHelper.loadSingle(depreuse[c].getPkValue(), depreuse[c].getDynamicObjectType().getName());
+            return depreuseInfo;
+        }
+        return null;
+    }
+
+    /**
+     * @description 查询变更类型
+     * @param id
+     */
+    private DynamicObject queryChangeType(Long id) {
+        QFilter orgQFilter= new QFilter("id", QCP.equals,id);
+        DynamicObject[] changeType = BusinessDataServiceHelper.load("fa_change_type","id",new QFilter[] {orgQFilter});
+        for (int c = 0; c < changeType.length; c++) {
+            DynamicObject changeInfo = BusinessDataServiceHelper.loadSingle(changeType[c].getPkValue(), changeType[c].getDynamicObjectType().getName());
+            return changeInfo;
+        }
+        return null;
+    }
+
+    /**
+     * @description 查询组织
+     * @param orgId
+     */
+    private DynamicObject queryOrg(Long orgId) {
+        QFilter orgQFilter= new QFilter("id", QCP.equals,orgId);
+        DynamicObject[] org = BusinessDataServiceHelper.load("bos_org","id",new QFilter[] {orgQFilter});
+        for (int c = 0; c < org.length; c++) {
+            DynamicObject orgInfo = BusinessDataServiceHelper.loadSingle(org[c].getPkValue(), org[c].getDynamicObjectType().getName());
+            return orgInfo;
+        }
+        return null;
+    }
+}

+ 60 - 0
src/main/java/fi/fa/opplugin/BusProcessBillOpPlugin.java

@@ -0,0 +1,60 @@
+package fi.fa.opplugin;
+
+import com.alibaba.druid.util.StringUtils;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+
+//业务处理单
+public class BusProcessBillOpPlugin extends AbstractOperationServicePlugIn {
+    @Override
+    public void beginOperationTransaction(BeginOperationTransactionArgs e) {
+        DynamicObject[] dynamicObjects = e.getDataEntities();
+        for (int i = 0; i < dynamicObjects.length; i++) {
+            if (StringUtils.equals(e.getOperationKey(),"audit")) {
+                DynamicObject info = BusinessDataServiceHelper.loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());
+                if ("D".equals(info.getString("nckd_detailtype"))) {
+                    for (DynamicObject nckd_entryentity6 : info.getDynamicObjectCollection("nckd_entryentity6")) {
+                        String  number = nckd_entryentity6.getDynamicObject("nckd_basedatafield").getString("number");
+                        if (!StringUtils.isEmpty(number)) {
+                            //查询e管家实物卡片清单
+                            QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
+                            DynamicObject[] cardObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
+                            for (int j = 0; j < cardObjects.length; j++) {
+                                DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(cardObjects[j].getPkValue(), cardObjects[j].getDynamicObjectType().getName());
+                                //回写e管家实物清单字段
+                                cardInfo.set("nckd_discard", "1");//是否报废
+                                SaveServiceHelper.save(new DynamicObject[]{cardInfo});
+                            }
+                        }
+
+                    }
+                }
+            }
+            else if (StringUtils.equals(e.getOperationKey(),"unaudit")) {
+                DynamicObject info = BusinessDataServiceHelper.loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());
+                if ("D".equals(info.getString("nckd_detailtype"))) {
+                    for (DynamicObject nckd_entryentity6 : info.getDynamicObjectCollection("nckd_entryentity6")) {
+                        String  number = nckd_entryentity6.getDynamicObject("nckd_basedatafield").getString("number");
+                        if (!StringUtils.isEmpty(number)) {
+                            //查询e管家实物卡片清单
+                            QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
+                            DynamicObject[] cardObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
+                            for (int j = 0; j < cardObjects.length; j++) {
+                                DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(cardObjects[j].getPkValue(), cardObjects[j].getDynamicObjectType().getName());
+                                //回写e管家实物清单字段
+                                cardInfo.set("nckd_discard", "0");//是否报废
+                                SaveServiceHelper.save(new DynamicObject[]{cardInfo});
+                            }
+                        }
+
+                    }
+                }
+            }
+        }
+    }
+}

+ 105 - 0
src/main/java/fi/fa/opplugin/FaChangeDeptBillOpPlugin.java

@@ -0,0 +1,105 @@
+package fi.fa.opplugin;
+
+import com.alibaba.druid.util.StringUtils;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+
+//资产变更单
+public class FaChangeDeptBillOpPlugin extends AbstractOperationServicePlugIn {
+    @Override
+    public void beginOperationTransaction(BeginOperationTransactionArgs e) {
+        DynamicObject[] dynamicObjects = e.getDataEntities();
+        for (int i = 0; i < dynamicObjects.length; i++) {
+            if (StringUtils.equals(e.getOperationKey(),"audit")) {
+                DynamicObject info = BusinessDataServiceHelper.loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());
+                Long queryChangeType = Long.parseLong("733953285719123968");
+                Long changetype = info.getDynamicObject("changetype").getLong("id");
+                if (queryChangeType.equals(changetype)) {
+                    Long deptId = null;
+                    Long user = null;
+                    String number = null;
+                    DynamicObject userInfo = null;
+                    for (DynamicObject fieldentry : info.getDynamicObjectCollection("fieldentry")) {
+                        if ("fa_card_real.headusedept".equals(fieldentry.getString("field")) && !StringUtils.isEmpty(fieldentry.getString("aftervalue"))) {
+                            deptId = Long.parseLong(fieldentry.getString("aftervalue"));
+                        }
+                        if ("fa_card_real.headuseperson".equals(fieldentry.getString("field")) && !StringUtils.isEmpty(fieldentry.getString("aftervalue"))) {
+                            user = Long.parseLong(fieldentry.getString("aftervalue"));
+                            userInfo = getUser(user);
+                        }
+                        number = fieldentry.getString("assetnumber");
+                    }
+                    if (!StringUtils.isEmpty(number)) {
+                        //查询e管家实物卡片清单
+                        QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
+                        DynamicObject[] cardObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
+                        for (int j = 0; j < cardObjects.length; j++) {
+                            DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(cardObjects[j].getPkValue(), cardObjects[j].getDynamicObjectType().getName());
+                            //回写e管家实物清单字段
+                            cardInfo.set("nckd_dept", deptId);//归属部门
+                            if (userInfo != null) {
+                                cardInfo.set("nckd_use_name", userInfo.getString("number"));//使用人
+                            }
+                        SaveServiceHelper.save(new DynamicObject[]{cardInfo});
+                        }
+                    }
+                }
+            }
+            else if (StringUtils.equals(e.getOperationKey(),"unaudit")) {
+                DynamicObject info = BusinessDataServiceHelper.loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());
+                Long queryChangeType = Long.parseLong("733953285719123968");
+                Long changetype = info.getDynamicObject("changetype").getLong("id");
+                if (queryChangeType.equals(changetype)) {
+                    Long deptId = null;
+                    Long user = null;
+                    String number = null;
+                    DynamicObject userInfo = null;
+                    for (DynamicObject fieldentry : info.getDynamicObjectCollection("fieldentry")) {
+                        if ("fa_card_real.headusedept".equals(fieldentry.getString("field")) && !StringUtils.isEmpty(fieldentry.getString("aftervalue"))) {
+                            deptId = Long.parseLong(fieldentry.getString("beforevalue"));
+                        }
+                        if ("fa_card_real.headuseperson".equals(fieldentry.getString("field")) && !StringUtils.isEmpty(fieldentry.getString("aftervalue"))) {
+                            user = Long.parseLong(fieldentry.getString("beforevalue"));
+                            userInfo = getUser(user);
+                        }
+                        number = fieldentry.getString("assetnumber");
+                    }
+                    if (!StringUtils.isEmpty(number)) {
+                        //查询e管家实物卡片清单
+                        QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
+                        DynamicObject[] cardObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
+                        for (int j = 0; j < cardObjects.length; j++) {
+                            DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(cardObjects[j].getPkValue(), cardObjects[j].getDynamicObjectType().getName());
+                            //回写e管家实物清单字段
+                            cardInfo.set("nckd_dept", deptId);//归属部门
+                            if (userInfo != null) {
+                                cardInfo.set("nckd_use_name", userInfo.getString("number"));//使用人
+                            }
+                        SaveServiceHelper.save(new DynamicObject[]{cardInfo});
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * @description 查询用户表获取用户
+     * @param id
+     * @return Long
+     */
+    private DynamicObject getUser(Long id) {
+        QFilter filter = new QFilter("id", QCP.in, id);
+        DynamicObject[] user = BusinessDataServiceHelper.load("bos_user","id",new QFilter[] {filter});
+        if (user.length > 0) {
+            DynamicObject userInfo = BusinessDataServiceHelper.loadSingle(user[0].getPkValue(), user[0].getDynamicObjectType().getName());
+            return userInfo;
+        }
+        return null;
+    }
+}

+ 57 - 0
src/main/java/fi/fa/opplugin/FaDispatchBillOpPlugin.java

@@ -0,0 +1,57 @@
+package fi.fa.opplugin;
+
+import com.alibaba.druid.util.StringUtils;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+
+//资产调出单
+public class FaDispatchBillOpPlugin extends AbstractOperationServicePlugIn {
+    @Override
+    public void beginOperationTransaction(BeginOperationTransactionArgs e) {
+        DynamicObject[] dynamicObjects = e.getDataEntities();
+        for (int i = 0; i < dynamicObjects.length; i++) {
+            if (StringUtils.equals(e.getOperationKey(),"audit")) {
+                DynamicObject info = BusinessDataServiceHelper.loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());
+                //审批通过,若关联e管家实物卡片清单,更新调入组织,调入部门,使用人
+                for (DynamicObject dispatchentry : info.getDynamicObjectCollection("dispatchentry")) {
+                    DynamicObject realcard = dispatchentry.getDynamicObject("realcard");
+                    String number = realcard.getString("number");
+                    //查询实物卡片清单
+                    QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
+                    DynamicObject[] cardObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
+                    for (int j = 0; j < cardObjects.length; j++) {
+                        DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(cardObjects[j].getPkValue(), cardObjects[j].getDynamicObjectType().getName());
+                        //回写e管家实物清单字段
+                        cardInfo.set("nckd_orgfield", info.getDynamicObject("inassetunit").getLong("id"));//归属组织
+                        cardInfo.set("nckd_dept", dispatchentry.getDynamicObject("inusedept").getLong("id"));//归属部门
+                        SaveServiceHelper.save(new DynamicObject[]{cardInfo});
+                    }
+                }
+            }
+            if (StringUtils.equals(e.getOperationKey(),"unaudit")) {
+                DynamicObject info = BusinessDataServiceHelper.loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());
+                //审批通过,若关联e管家实物卡片清单,更新调入组织,调入部门,使用人
+                for (DynamicObject dispatchentry : info.getDynamicObjectCollection("dispatchentry")) {
+                    DynamicObject realcard = dispatchentry.getDynamicObject("realcard");
+                    String number = realcard.getString("number");
+                    //查询实物卡片清单
+                    QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
+                    DynamicObject[] cardObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
+                    for (int j = 0; j < cardObjects.length; j++) {
+                        DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(cardObjects[j].getPkValue(), cardObjects[j].getDynamicObjectType().getName());
+                        //还原e卡片实物清单字段
+                        cardInfo.set("nckd_orgfield", info.getDynamicObject("assetunit").getLong("id"));//归属组织
+                        cardInfo.set("nckd_dept", dispatchentry.getDynamicObject("realcard").getDynamicObject("headusedept").getLong("id"));//归属部门
+                        SaveServiceHelper.save(new DynamicObject[]{cardInfo});
+                    }
+                }
+            }
+        }
+    }
+}

+ 7 - 9
src/main/java/fi/fa/opplugin/RealCardSplitF7OpPlugin.java

@@ -18,10 +18,6 @@ import java.util.EventObject;
 public class RealCardSplitF7OpPlugin extends AbstractFormPlugin implements BeforeF7SelectListener {
     @Override
     public void registerListener(EventObject e) {
-        //监听单据字段
-//        super.registerListener(e);
-//        RefBillEdit bill = this.getView().getControl("split_realcard");
-//        bill.addBeforeF7SelectListener(this);
     }
     @Override
     public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
@@ -38,12 +34,14 @@ public class RealCardSplitF7OpPlugin extends AbstractFormPlugin implements Befor
             if (dynamicObject != null) {
                 String number = dynamicObject.getString("number");
                 //查询e管家实物卡片清单
-//                QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
-                QFilter filter = new QFilter("name", QCP.equals,"电脑");
-                filter.or("name", QCP.equals, "手机");
+                QFilter filter = new QFilter("nckd_card_real_code", QCP.equals,number);
                 DynamicObject[] cardDynamicObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
-                int splitqty = cardDynamicObjects.length;
-                this.getModel().setValue("splitqty", splitqty);
+                if (cardDynamicObjects.length > 1) {
+                    this.getModel().setValue("splitqty", cardDynamicObjects.length);
+                    this.getModel().setValue("nckd_e_flag", "1");
+                }else {
+                    this.getModel().setValue("nckd_e_flag", null);
+                }
             }
         }
     }

+ 70 - 0
src/main/java/fi/fa/webService/ApisaveDemoPlugin.java

@@ -0,0 +1,70 @@
+package fi.fa.webService;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.openapi.api.plugin.ApiSavePlugin;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+public class ApisaveDemoPlugin implements ApiSavePlugin {
+    @Override
+    public List<Map<String, Object>> preHandleRequestData(List<Map<String, Object>> reqData) {
+        for (Map<String, Object> data : reqData) {
+            // 获取组织和部门的数据
+            Map<String, Object> org = (Map<String, Object>) data.get("nckd_orgfield");
+            Map<String, Object> dept = (Map<String, Object>) data.get("nckd_dept");
+
+            // 获取组织和部门的 ID
+            String orgId = String.valueOf(org.get("id"));
+            String deptId = String.valueOf(dept.get("id"));
+
+            // 创建包含组织和部门 ID 的列表
+            List<String> idList = Arrays.asList(orgId, deptId);
+
+            // 构建查询过滤器以查找相关的组织信息
+            QFilter filter = new QFilter("nckd_e_org", QCP.in, idList);
+
+            // 加载与过滤器匹配的组织数据
+            DynamicObject[] orgControl = BusinessDataServiceHelper.load("nckd_base_org_ext", "id", new QFilter[]{filter});
+
+            // 检查是否有返回的组织控制数据
+            if (orgControl.length > 0) {
+                // 处理每个组织控制信息
+                for (int i = 0; i < orgControl.length; i++) {
+                    DynamicObject orgControlInfo = BusinessDataServiceHelper.loadSingle(orgControl[i].getPkValue(), orgControl[i].getDynamicObjectType().getName());
+                    updateOrgAndDeptIds(org, dept, orgId, deptId, orgControlInfo);
+                }
+            }
+        }
+        return reqData;
+    }
+
+    /**
+     * 更新组织和部门的 ID
+     *
+     * @param org             组织 Map
+     * @param dept            部门 Map
+     * @param orgId          组织 ID
+     * @param orgControlInfo  组织控制信息
+     */
+    private void updateOrgAndDeptIds(Map<String, Object> org, Map<String, Object> dept, String orgId, String deptId, DynamicObject orgControlInfo) {
+        String orgNumber = orgControlInfo.getString("nckd_org_number");
+
+        if (orgId.equals(deptId)) {
+            // 如果组织 ID 和部门 ID 相同,则都设置为组织编号
+            org.put("id", Long.valueOf(orgNumber));
+            dept.put("id", Long.valueOf(orgNumber));
+        } else if (orgControlInfo.getString("nckd_e_org").equals(orgId)) {
+            // 如果当前控制信息的组织 ID 等于 orgId,更新组织 ID
+            org.put("id", Long.valueOf(orgNumber));
+        } else {
+            // 否则更新部门 ID
+            dept.put("id", Long.valueOf(orgNumber));
+        }
+    }
+}

+ 160 - 39
src/main/java/fi/fa/webService/DispatchMidController.java

@@ -53,7 +53,7 @@ public class DispatchMidController implements Serializable {
                 String errorCode = Check(eobject, map);
                 //第三步:下推生成调拨单
                 if (StringUtils.isEmpty(errorCode) && StringUtils.isEmpty(errorChange)) {
-                    //下推生成资产调拨
+                    //下推生成单
                     Push(eobject, map);
                 }
                 // 错误拼接
@@ -94,6 +94,7 @@ public class DispatchMidController implements Serializable {
         midDispatch.set("nckd_dept_in", jsonObject.getString("inDeptId"));//调入部门
         midDispatch.set("nckd_used_user", jsonObject.getString("user"));//调入使用人
         midDispatch.set("nckd_storeplace", jsonObject.getString("storeplace"));//调入存放地点
+        midDispatch.set("nckd_direction", jsonObject.getString("direction"));//调入存放地点
         //拼接资产信息的组织和编码
         String cardNumber = "";
         JSONArray assetArray = jsonObject.getJSONArray("asset");
@@ -103,6 +104,9 @@ public class DispatchMidController implements Serializable {
             String number = asset.getString("number");
             String orgId = asset.getString("orgId");
             cardNumber = number+ ":" + orgId + ",";
+            if ("2".equals(jsonObject.getString("dispatchType"))) {
+                midDispatch.set("nckd_count", asset.getString("count"));//资产数量
+            }
         }
         midDispatch.set("nckd_card_number_tag", cardNumber);
         SaveServiceHelper.save(new DynamicObject[]{midDispatch});
@@ -116,11 +120,12 @@ public class DispatchMidController implements Serializable {
     private  String Check(JSONObject jsonObject, HashMap<String , Long> map) {
         String billno = jsonObject.getString("billno");//源单编号
         String user = jsonObject.getString("user");//使用人
+        String dispatchType = jsonObject.getString("dispatchType");//调拨类型
         List<String> numberList = new ArrayList<>();
         // 校验该单据是否已经下推生成调拨单
-//        if (isAlreadyDispatched(billno)) {
-//            return "单据" + billno + "已经生成调拨单,请勿重复推送!";
-//        }
+        if (isAlreadyDispatched(billno)) {
+            return "单据" + billno + "已经生成调拨单,请勿重复推送!";
+        }
         // 获取资产编号数组
         JSONArray assetArray = jsonObject.getJSONArray("asset");
         if (assetArray.isEmpty()) {
@@ -151,16 +156,31 @@ public class DispatchMidController implements Serializable {
                 if (StringUtils.isEmpty(code)) {
                     //星瀚未生成实物卡片,更新实物卡片清单数据-查询组织对照表
                     Long orgId = getOrg(e_orgId);
-                    if (ObjectUtils.isNotEmpty(orgId)) {
+                    if (ObjectUtils.isNotEmpty(orgId) && ("0".equals(dispatchType))) {
                         //更新归属机构,归属部门,使用人
                         for (int a = 0; a < dynamicObjects.length ; a++) {
                             DynamicObject ecardInfoList = BusinessDataServiceHelper.loadSingle(dynamicObjects[a].getPkValue(), dynamicObjects[a].getDynamicObjectType().getName());
                             ecardInfoList.set("nckd_orgfield",orgId);
                             ecardInfoList.set("nckd_dept",map.get("inDeptId"));
+                            SaveServiceHelper.save(new DynamicObject[]{ecardInfoList});
+                        }
+                    }else if (ObjectUtils.isNotEmpty(orgId) && "1".equals(dispatchType)) {
+                        //更新是否报废为是
+                        for (int a = 0; a < dynamicObjects.length ; a++) {
+                            DynamicObject ecardInfoList = BusinessDataServiceHelper.loadSingle(dynamicObjects[a].getPkValue(), dynamicObjects[a].getDynamicObjectType().getName());
+                            ecardInfoList.set("nckd_dept",map.get("inDeptId"));
                             ecardInfoList.set("nckd_use_name",user);
                             SaveServiceHelper.save(new DynamicObject[]{ecardInfoList});
                         }
-                    }else {
+                    }
+                    else if (ObjectUtils.isNotEmpty(orgId) && "2".equals(dispatchType)) {
+                        //更新是否报废为是
+                        for (int a = 0; a < dynamicObjects.length ; a++) {
+                            DynamicObject ecardInfoList = BusinessDataServiceHelper.loadSingle(dynamicObjects[a].getPkValue(), dynamicObjects[a].getDynamicObjectType().getName());
+                            ecardInfoList.set("nckd_discard",1);
+                            SaveServiceHelper.save(new DynamicObject[]{ecardInfoList});
+                        }
+                    } else {
                         return "资产信息的组织在组织对照表中未查询到数据,生成调拨单失败";
                     }
                 }else {
@@ -187,15 +207,14 @@ public class DispatchMidController implements Serializable {
      */
     private void Push(JSONObject jsonObject, HashMap<String , Long> map) {
         String dispatchType = jsonObject.getString("dispatchType");
+        String direction = jsonObject.getString("direction");
         //组织间,生成资产调出单
         if ("0".equals(dispatchType)) {
             DynamicObject dispatch = BusinessDataServiceHelper.newDynamicObject("fa_dispatch");
             String nckd_card_real_code = jsonObject.getString("nckd_card_real_code");
-            nckd_card_real_code = "A00100101900240600005";
+            nckd_card_real_code = "A00100101900240600002";
 
             //单据头
-            dispatch.set("outuser", map.get("sendUser"));//调出申请人
-            dispatch.set("inuser", map.get("recieveUser"));//调入负责人
             dispatch.set("dispatchdate", jsonObject.getDate("sendDate"));//调出日期
             dispatch.set("assetunit", map.get("outOrgId"));//调出组织
             dispatch.set("inassetunit", map.get("orgId"));//调入组织
@@ -207,14 +226,27 @@ public class DispatchMidController implements Serializable {
             dispatch.set("currency", 1);//币种
             dispatch.set("currencyrate", 1);//结算汇率
             //制单信息
-            dispatch.set("creator", map.get("sendUser"));//创建人
             dispatch.set("createtime", jsonObject.getDate("sendDate"));//创建时间
-            dispatch.set("modifier", map.get("recieveUser"));//修改人
             dispatch.set("modifytime", jsonObject.getDate("sendDate"));//修改时间
-            dispatch.set("auditor", map.get("recieveUser"));//审核人
             dispatch.set("auditdate", jsonObject.getDate("sendDate"));//审核时间
             dispatch.set("billstatus", "A");//暂存
-            dispatch.set("appliant", map.get("sendUser"));//调拨申请人
+            //调出方向
+            if("0".equals(direction)){
+                dispatch.set("outuser", map.get("sendUser"));//调出申请人
+                dispatch.set("inuser", map.get("recieveUser"));//调入负责人
+                dispatch.set("creator", map.get("sendUser"));//创建人
+                dispatch.set("modifier", map.get("sendUser"));//修改人
+                dispatch.set("auditor", map.get("sendUser"));//审核人
+                dispatch.set("appliant", map.get("sendUser"));//调拨申请人
+            }//调入方向
+            else if ("1".equals(direction)) {
+                dispatch.set("outuser", map.get("recieveUser"));//调出申请人
+                dispatch.set("inuser", map.get("sendUser"));//调入负责人
+                dispatch.set("creator", map.get("recieveUser"));//创建人
+                dispatch.set("modifier", map.get("recieveUser"));//修改人
+                dispatch.set("auditor", map.get("recieveUser"));//审核人
+                dispatch.set("appliant", map.get("recieveUser"));//调拨申请人
+            }
             //单据体
             //根据资产编号查询实物卡片
             QFilter cardFilter = new QFilter("number", QCP.equals,nckd_card_real_code);
@@ -249,20 +281,29 @@ public class DispatchMidController implements Serializable {
             //单据头
             changeDept.set("org", orgInfo);//核算组织
             changeDept.set("changedate", jsonObject.getDate("sendDate"));//记账日期
-            changeDept.set("appliantid", getUser(jsonObject.getString("sendUser")));//变更申请人
             changeDept.set("remark", jsonObject.getString("reason"));//调出原因
             changeDept.set("sourcetype", 2);//来源方式(5:API生成)
             changeDept.set("changetype", queryChangeType(Long.parseLong("733953285719123968")));//变更类型,默认部门变更
             changeDept.set("chtypedetail", "1");//变更类型明细默认实物变更1
             changeDept.set("voucherflag", "A");//记账标识默认无需记账A
             //制单信息
-            changeDept.set("creator", getUser(jsonObject.getString("sendUser")));//创建人
             changeDept.set("createtime", jsonObject.getDate("sendDate"));//创建时间
-            changeDept.set("modifier", getUser(jsonObject.getString("recieveUser")));//修改人
             changeDept.set("modifytime", jsonObject.getDate("sendDate"));//修改时间
-            changeDept.set("auditor", getUser(jsonObject.getString("recieveUser")));//审核人
             changeDept.set("auditdate", jsonObject.getDate("sendDate"));//审核时间
             changeDept.set("billstatus", "A");//默认审核
+            //调出方向
+            if("0".equals(direction)){
+                changeDept.set("creator", getUser(jsonObject.getString("sendUser")));//创建人
+                changeDept.set("modifier", getUser(jsonObject.getString("sendUser")));//修改人
+                changeDept.set("auditor", getUser(jsonObject.getString("sendUser")));//审核人
+                changeDept.set("appliantid", getUser(jsonObject.getString("sendUser")));//变更申请人
+            }//调入方向
+            else if ("1".equals(direction)) {
+                changeDept.set("creator", getUser(jsonObject.getString("recieveUser")));//创建人
+                changeDept.set("modifier", getUser(jsonObject.getString("recieveUser")));//修改人
+                changeDept.set("auditor", getUser(jsonObject.getString("recieveUser")));//审核人
+                changeDept.set("appliantid", getUser(jsonObject.getString("recieveUser")));//变更申请人
+            }
             //单据体
             //根据资产编号查询实物卡片
             QFilter cardFilter = new QFilter("number", QCP.equals,nckd_card_real_code);
@@ -289,7 +330,7 @@ public class DispatchMidController implements Serializable {
                     entry1.set("fincard1", fin);//财务卡片
                 }
                 if (ObjectUtils.isEmpty(cardInfo.getDynamicObject("headuseperson")) ||
-                    ObjectUtils.isNotEmpty(cardInfo.getDynamicObject("headuseperson")) && map.get("user").equals(cardInfo.getDynamicObject("headuseperson").getLong("id"))) {
+                    ObjectUtils.isNotEmpty(cardInfo.getDynamicObject("headuseperson")) && !map.get("user").equals(cardInfo.getDynamicObject("headuseperson").getLong("id"))) {
                     String beforevalue = cardInfo.getDynamicObject("headuseperson") == null ? "" : String.valueOf(cardInfo.getDynamicObject("headuseperson").getLong("id"));
                     DynamicObject entry2 = fieldentry.addNew();
                     entry2.set("realcard1", cardInfo);//资产编码
@@ -326,6 +367,48 @@ public class DispatchMidController implements Serializable {
                 OperationResult submitResult = OperationServiceHelper.executeOperate("submit", "fa_change_dept",saveResult.getSuccessPkIds().toArray(),OperateOption.create());
                 OperationResult auditResult = OperationServiceHelper.executeOperate("audit", "fa_change_dept",submitResult.getSuccessPkIds().toArray(),OperateOption.create());
             }
+        } //生成业务处理单
+        else if ("2".equals(dispatchType)) {
+            DynamicObject busProcess = BusinessDataServiceHelper.newDynamicObject("nckd_ywcld");
+            String nckd_card_real_code = jsonObject.getString("nckd_card_real_code");
+            nckd_card_real_code = "A00100101900240700007";
+            DynamicObject orgInfo = queryOrg(map.get("orgId"));
+            busProcess.set("nckd_bizdate", jsonObject.getDate("sendDate"));//业务日期
+            busProcess.set("nckd_detailtype", "D");//业务类型 D:报废
+            busProcess.set("nckd_costcompany", map.get("orgId"));//资产组织
+            busProcess.set("nckd_textfield1", jsonObject.getString("reason"));//摘要事由
+            busProcess.set("nckd_applierv", getUser(jsonObject.getString("sendUser")));//制单人
+
+            //制单信息
+            busProcess.set("creator", getUser(jsonObject.getString("sendUser")));//创建人
+            busProcess.set("createtime", jsonObject.getDate("sendDate"));//创建时间
+            busProcess.set("modifier", getUser(jsonObject.getString("sendUser")));//修改人
+            busProcess.set("modifytime", jsonObject.getDate("sendDate"));//修改时间
+            busProcess.set("auditor", getUser(jsonObject.getString("sendUser")));//审核人
+            busProcess.set("auditdate", jsonObject.getDate("sendDate"));//审核时间
+            busProcess.set("billstatus", "A");//状态
+            //单据体
+            //根据资产编号查询实物卡片
+            QFilter cardFilter = new QFilter("number", QCP.equals,nckd_card_real_code);
+            cardFilter.and("isbak",  QCP.equals, "0");
+            DynamicObject[] card = BusinessDataServiceHelper.load("fa_card_real","id",new QFilter[] {cardFilter});
+            for (int c = 0; c < card.length; c++) {
+                DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(card[c].getPkValue(), card[c].getDynamicObjectType().getName());
+                //创建报废明细分录
+                DynamicObjectCollection entryEntity = busProcess.getDynamicObjectCollection("nckd_entryentity6");
+                DynamicObject entry1 = entryEntity.addNew();
+                entry1.set("nckd_basedatafield", cardInfo);//资产编码
+                Integer count = Integer.valueOf(jsonObject.getJSONArray("asset").getJSONObject(0).getString("count"));
+                entry1.set("nckd_integerfield", count);//报废数量
+            }
+            //执行保存-提交-审核
+            OperationResult saveResult = SaveServiceHelper.saveOperate("nckd_ywcld", new DynamicObject[]{busProcess}, OperateOption.create());
+            if (saveResult.isSuccess()){
+                //生单后反写中间表,防止反复生单
+                OncePush(jsonObject.getString("billno"));
+                OperationResult submitResult = OperationServiceHelper.executeOperate("submit", "nckd_ywcld",saveResult.getSuccessPkIds().toArray(),OperateOption.create());
+                OperationResult auditResult = OperationServiceHelper.executeOperate("audit", "nckd_ywcld",submitResult.getSuccessPkIds().toArray(),OperateOption.create());
+            }
         }
 
     }
@@ -344,6 +427,9 @@ public class DispatchMidController implements Serializable {
             return orgId;
         }//组织对照表查询不到,查询组织表
         else {
+            if (StringUtils.isEmpty(eOrgId)) {
+                return null;
+            }
             QFilter filter = new QFilter("id", QCP.equals,Long.parseLong(eOrgId));
             DynamicObject[] org = BusinessDataServiceHelper.load("bos_org","id",new QFilter[] {filter});
             if (org.length > 0) {
@@ -375,28 +461,63 @@ public class DispatchMidController implements Serializable {
      * @param jsonObject,map
      * @return String
      */
-    private String Control (JSONObject jsonObject, HashMap<String , Long> map) {
-        //查询人员
-        DynamicObject sendUser = getUser(jsonObject.getString("sendUser"));//调出申请人
-        DynamicObject recieveUser = getUser(jsonObject.getString("recieveUser"));//调入负责人
-        DynamicObject user = getUser(jsonObject.getString("user"));//调入使用人
-        if (ObjectUtils.isEmpty(sendUser) || ObjectUtils.isEmpty(recieveUser) || ObjectUtils.isEmpty(user)) {
-            return "人员信息转换失败";
-        }
-        map.put("sendUser", sendUser.getLong("id"));
-        map.put("recieveUser", recieveUser.getLong("id"));
-        map.put("user", user.getLong("id"));
-
-        //查询组织
-        Long outOrgId = getOrg(jsonObject.getString("outOrgId"));//调出组织
-        Long orgId = getOrg(jsonObject.getString("orgId"));//调入组织
-        Long inDeptId = getOrg(jsonObject.getString("inDeptId"));//调入部门
-        if (ObjectUtils.isEmpty(outOrgId) || ObjectUtils.isEmpty(orgId) || ObjectUtils.isEmpty(inDeptId)) {
-            return "组织信息转换失败";
+    private String Control(JSONObject jsonObject, HashMap<String , Long> map) {
+        String dispatchType = jsonObject.getString("dispatchType");
+        if ("0".equals(dispatchType)) {
+            //查询人员
+            DynamicObject sendUser = getUser(jsonObject.getString("sendUser"));//调出申请人
+            DynamicObject recieveUser = getUser(jsonObject.getString("recieveUser"));//调入负责人
+            if (ObjectUtils.isEmpty(sendUser) || ObjectUtils.isEmpty(recieveUser)) {
+                return "人员信息转换失败";
+            }
+            map.put("sendUser", sendUser.getLong("id"));
+            map.put("recieveUser", recieveUser.getLong("id"));
+            //查询组织
+            Long outOrgId = getOrg(jsonObject.getString("outOrgId"));//调出组织
+            Long orgId = getOrg(jsonObject.getString("orgId"));//调入组织
+            Long inDeptId = getOrg(jsonObject.getString("inDeptId"));//调入部门
+            if (ObjectUtils.isEmpty(outOrgId) || ObjectUtils.isEmpty(orgId) || ObjectUtils.isEmpty(inDeptId)) {
+                return "组织信息转换失败";
+            }
+            map.put("outOrgId", outOrgId);
+            map.put("orgId", orgId);
+            map.put("inDeptId", inDeptId);
+            return null;
+        } else if ("1".equals(dispatchType)) {
+            //查询人员
+            DynamicObject sendUser = getUser(jsonObject.getString("sendUser"));//调出申请人
+            DynamicObject recieveUser = getUser(jsonObject.getString("recieveUser"));//调入负责人
+            DynamicObject user = getUser(jsonObject.getString("user"));//调入使用人
+            if (ObjectUtils.isEmpty(sendUser) || ObjectUtils.isEmpty(recieveUser) || ObjectUtils.isEmpty(user)) {
+                return "人员信息转换失败";
+            }
+            map.put("sendUser", sendUser.getLong("id"));
+            map.put("recieveUser", recieveUser.getLong("id"));
+            map.put("user", user.getLong("id"));
+            //查询组织
+            Long orgId = getOrg(jsonObject.getString("orgId"));//调入组织
+            Long inDeptId = getOrg(jsonObject.getString("inDeptId"));//调入部门
+            if (ObjectUtils.isEmpty(orgId) || ObjectUtils.isEmpty(inDeptId)) {
+                return "组织信息转换失败";
+            }
+            map.put("orgId", orgId);
+            map.put("inDeptId", inDeptId);
+            return null;
+        }else if ("2".equals(dispatchType)) {
+            //查询人员
+            DynamicObject sendUser = getUser(jsonObject.getString("sendUser"));//调出申请人
+            if (ObjectUtils.isEmpty(sendUser)) {
+                return "人员信息转换失败";
+            }
+            map.put("sendUser", sendUser.getLong("id"));
+            //查询组织
+            Long orgId = getOrg(jsonObject.getString("orgId"));//资产组织
+            if (ObjectUtils.isEmpty(orgId)) {
+                return "组织信息转换失败";
+            }
+            map.put("orgId", orgId);
+            return null;
         }
-        map.put("outOrgId", outOrgId);
-        map.put("orgId", orgId);
-        map.put("inDeptId", inDeptId);
         return null;
     }
 

+ 1 - 1
src/main/java/kd/imc/rim/common/helper/RecognitionCheckHelperEx.java

@@ -737,7 +737,7 @@ public class RecognitionCheckHelperEx {
 
     }
 
-    public JSONArray bindAttachInvoice(JSONArray targetArray, JSONObject businessParam) {
+    public JSONArray bindAttachInvoice(JSONArray targetArray, JSONObject businessParam, Map<String, Long> invoiceTypeMap) {
         JSONArray attachArray = new JSONArray();
         if (targetArray.size() == 0) {
             return attachArray;

+ 0 - 202
src/main/java/kd/imc/rim/common/invoice/collector/InvoiceCollectTaskNew.java

@@ -1,202 +0,0 @@
-package kd.imc.rim.common.invoice.collector;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import kd.bos.context.RequestContext;
-import kd.bos.dataentity.utils.ObjectUtils;
-import kd.bos.dataentity.utils.StringUtils;
-import kd.bos.logging.Log;
-import kd.bos.logging.LogFactory;
-import kd.bos.mvc.cache.PageCache;
-import kd.bos.orm.util.CollectionUtils;
-import kd.imc.rim.common.invoice.recognition.impl.RecognitionProgress;
-import kd.imc.rim.common.invoice.recognition.impl.RecognitionProgressError;
-import kd.imc.rim.common.invoice.recognition.listener.IRecognitionListener;
-import kd.imc.rim.common.invoice.recognition.listener.RecognitionListenerResult;
-import kd.imc.rim.common.service.EInvoiceZipXmlDealService;
-import kd.imc.rim.common.service.ElectAccVoucherService;
-import kd.imc.rim.common.service.ExcelInvoiceUploadService;
-import kd.imc.rim.common.service.RecognitionCheckServiceEx;
-import kd.imc.rim.common.utils.FileUtils;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-public class InvoiceCollectTaskNew implements Runnable, IRecognitionListener {
-    private static Log logger = LogFactory.getLog(InvoiceCollectTaskNew.class);
-    private RequestContext rc;
-    private String pageId;
-    private List<Map<String, String>> fileUrls;
-    private RecognitionProgress recognitionProgress;
-    private JSONObject businessParam;
-
-    public InvoiceCollectTaskNew(RequestContext rc, String pageId, List<Map<String, String>> fileUrls, JSONObject businessParam) {
-        this.rc = rc;
-        this.pageId = pageId;
-        this.fileUrls = fileUrls;
-        this.businessParam = businessParam;
-        this.recognitionProgress = new RecognitionProgress();
-        Object[] urls = new Object[fileUrls.size()];
-        int i = 0;
-
-        for(Iterator var7 = fileUrls.iterator(); var7.hasNext(); ++i) {
-            Map<String, String> map = (Map)var7.next();
-            urls[i] = map.get("url");
-        }
-
-        this.recognitionProgress.setUrls(urls);
-        this.recognitionProgress.setProgress(1);
-        this.recognitionProgress.setUnHandleSize(fileUrls.size());
-    }
-
-    public void run() {
-        RequestContext.copyAndSet(this.rc);
-        this.doTask();
-    }
-
-    private void doTask() {
-        PageCache pageCache = new PageCache(this.pageId);
-        long taskStart = System.currentTimeMillis();
-        int size = this.fileUrls.size();
-
-        for(int i = 0; i < size; ++i) {
-            Map<String, String> map = (Map)this.fileUrls.get(i);
-            long start = System.currentTimeMillis();
-            String url = (String)map.get("url");
-            String fileName = (String)map.get("name");
-            String seqStr = (String)map.get("seq");
-
-            try {
-                if (StringUtils.isEmpty(fileName)) {
-                    fileName = url.substring(url.lastIndexOf(47) + 1);
-                }
-
-                this.recognitionProgress.setHandleUrl(url);
-                pageCache.put("progress", JSONObject.toJSONString(this.recognitionProgress));
-                long recognitionStart = System.currentTimeMillis();
-                this.businessParam.put("pageId", this.pageId);
-                this.businessParam.put("uploadIndex", start + (long)i);
-                Long orgId;
-                if (this.businessParam.get("orgId") == null) {
-                    orgId = RequestContext.get().getOrgId();
-                } else {
-                    orgId = (Long)this.businessParam.get("orgId");
-                }
-
-                JSONObject invoiceResult = new JSONObject();
-                boolean isZipXmlEI = FileUtils.checkFileType(fileName, new String[]{"zip", "xml"});
-                if (isZipXmlEI) {
-                    invoiceResult = EInvoiceZipXmlDealService.analysisAndCheckSave(url, fileName, orgId, this.businessParam, this);
-                }
-
-                boolean isNeedDeal = FileUtils.checkFileType(fileName, new String[]{"zip", "ofd", "xml"});
-                if (isNeedDeal && !"0000".equals(invoiceResult.getString("errcode"))) {
-                    invoiceResult = ElectAccVoucherService.dealVoucher(url, fileName, orgId, this.businessParam, this);
-                }
-
-                String xbrlErrCode = invoiceResult.getString("errcode");
-                boolean dealResult = StringUtils.isEmpty(xbrlErrCode) || !xbrlErrCode.equals("0000");
-                boolean isZip = FileUtils.checkFileType(fileName, new String[]{"zip"});
-                if (dealResult && !isZip) {
-                    if (FileUtils.isExcel(fileName)) {
-                        invoiceResult = ExcelInvoiceUploadService.getInstance().uploadExcelInvoice(url, fileName, this, this.businessParam);
-                    } else {
-                        invoiceResult = RecognitionCheckServiceEx.getInstance().recognitionCheckInvoice(url, fileName, this, this.businessParam);
-                    }
-                }
-
-                logger.info(url + "RecognitionCheckServiceEx识别结果:" + invoiceResult);
-                logger.info(String.format("文件%s中发票识别与查验完毕 共耗时%s", fileName, System.currentTimeMillis() - recognitionStart));
-                if (null == this.recognitionProgress.getRecognitionProgressErrors()) {
-                    this.recognitionProgress.setRecognitionProgressErrors(new ArrayList());
-                }
-
-                if (!"0000".equals(invoiceResult.getString("errcode"))) {
-                    String errdescription = "识别异常,请重试";
-                    if (StringUtils.isNotEmpty(invoiceResult.getString("description"))) {
-                        errdescription = invoiceResult.getString("description");
-                    }
-
-                    this.recognitionProgress.getRecognitionProgressErrors().add(new RecognitionProgressError(url, errdescription));
-                } else {
-                    JSONArray recognitionData = invoiceResult.getJSONArray("data");
-                    if (recognitionData != null) {
-                        for(int k = 0; k < recognitionData.size(); ++k) {
-                            JSONObject invoiceInfo = recognitionData.getJSONObject(k);
-                            if (invoiceInfo != null) {
-                                Object isFalse = invoiceInfo.get("isFalse");
-                                if (isFalse != null) {
-                                    String snapshotUrl = invoiceInfo.getString("pageUrl");
-                                    String pageIndex = invoiceInfo.getString("pageIndex");
-                                    StringBuilder description = new StringBuilder();
-                                    description.append(fileName).append('第').append(pageIndex).append("页识别失败,请重试");
-                                    this.recognitionProgress.getRecognitionProgressErrors().add(new RecognitionProgressError(snapshotUrl, description.toString()));
-                                }
-                            }
-                        }
-                    }
-
-                    JSONObject tips = invoiceResult.getJSONObject("tips");
-                    if (!ObjectUtils.isEmpty(tips) && FileUtils.isExcel(fileName)) {
-                        RecognitionProgressError recognitionProgressError = new RecognitionProgressError();
-                        recognitionProgressError.setUrl(url);
-                        recognitionProgressError.setTipDescription(tips.getString("tipDescription"));
-                        this.recognitionProgress.getRecognitionProgressErrors().add(recognitionProgressError);
-                    }
-                }
-
-                BigDecimal a = new BigDecimal(i + 1);
-                BigDecimal b = new BigDecimal(size);
-                int progress = a.divide(b, 2, 4).multiply(new BigDecimal("100")).intValue();
-                if (progress != 100) {
-                    this.recognitionProgress.setProgress(progress);
-                }
-            } catch (Throwable var31) {
-                if (!FileUtils.isExcel(fileName)) {
-                    if (null == this.recognitionProgress.getRecognitionProgressErrors()) {
-                        this.recognitionProgress.setRecognitionProgressErrors(new ArrayList());
-                    }
-
-                    this.recognitionProgress.getRecognitionProgressErrors().add(new RecognitionProgressError(url, var31.getMessage()));
-                }
-            } finally {
-                this.recognitionProgress.setUnHandleSize(size - i - 1);
-                pageCache.put("progress", JSONObject.toJSONString(this.recognitionProgress));
-                logger.info(String.format("文件%s第%s页,InvoiceCollectTask统计信息-共%s个,耗时%s", fileName, i + 1, size, System.currentTimeMillis() - start));
-            }
-        }
-
-        this.recognitionProgress.setProgress(100);
-        PageCache pageCacheEnd = new PageCache(this.pageId);
-        pageCacheEnd.put("progress", JSONObject.toJSONString(this.recognitionProgress));
-        logger.info(String.format("%s任务统计信息总耗时%s", this.rc.getTraceId(), System.currentTimeMillis() - taskStart));
-    }
-
-    public void handle(RecognitionListenerResult recognitionListenerResult) {
-        PageCache pageCache = new PageCache(this.pageId);
-        String fileUrl = recognitionListenerResult.getFileUrl();
-        this.recognitionProgress.setHandleUrl(fileUrl);
-        if (StringUtils.isNotEmpty(recognitionListenerResult.getErrDescription())) {
-            logger.info(fileUrl + "识别失败/中断," + recognitionListenerResult.getErrDescription());
-            this.recognitionProgress.setHandleUrlIndex(recognitionListenerResult.getRecognitionIndex());
-            this.recognitionProgress.setHandleUrlErrorDescription(recognitionListenerResult.getErrDescription());
-            pageCache.put("progress", JSONObject.toJSONString(this.recognitionProgress));
-            pageCache.put("task_" + fileUrl, "0");
-        } else {
-            int index = recognitionListenerResult.getRecognitionIndex();
-            logger.info(fileUrl + "第" + index + "页识别完成:" + recognitionListenerResult.getRecognitionInvoice().toJSONString());
-            this.recognitionProgress.setHandleUrlIndex(index);
-            this.recognitionProgress.setHandleUrlSize(recognitionListenerResult.getRecognitionSize());
-            pageCache.put("progress", JSONObject.toJSONString(this.recognitionProgress));
-            pageCache.put("task_" + fileUrl, recognitionListenerResult.getRecognitionSize() + "");
-            pageCache.put("task_" + fileUrl + "_" + index, recognitionListenerResult.getRecognitionInvoice().toJSONString());
-            if (!CollectionUtils.isEmpty(recognitionListenerResult.getImportFailInvoice())) {
-                pageCache.put("failed_task_" + fileUrl + "_" + index, recognitionListenerResult.getImportFailInvoice().toJSONString());
-            }
-        }
-
-    }
-}

+ 185 - 30
src/main/java/kd/imc/rim/common/invoice/recognition/impl/RecognitionCheckTaskEx.java

@@ -8,28 +8,36 @@ package kd.imc.rim.common.invoice.recognition.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Callable;
 import kd.bos.context.RequestContext;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.dataentity.resource.ResManager;
 import kd.bos.dataentity.utils.StringUtils;
 import kd.bos.dlock.DLock;
 import kd.bos.logging.Log;
 import kd.bos.logging.LogFactory;
+import kd.bos.orm.query.QFilter;
 import kd.bos.orm.util.CollectionUtils;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import kd.imc.rim.common.constant.InputInvoiceTypeEnum;
 import kd.imc.rim.common.constant.ResultContant;
 import kd.imc.rim.common.invoice.fpzs.FpzsMainService;
 import kd.imc.rim.common.invoice.recognition.listener.IRecognitionListener;
-import kd.imc.rim.common.service.EInvoiceZipXmlDealService;
-import kd.imc.rim.common.service.ElectAccVoucherService;
-import kd.imc.rim.common.service.ExcelInvoiceUploadService;
-import kd.imc.rim.common.service.RecognitionCheckServiceEx;
+import kd.imc.rim.common.service.*;
+import kd.imc.rim.common.utils.BigDecimalUtil;
 import kd.imc.rim.common.utils.CacheHelper;
 import kd.imc.rim.common.utils.FileUtils;
 import kd.imc.rim.common.utils.MD5;
 import org.apache.commons.lang3.tuple.Pair;
 
 public class RecognitionCheckTaskEx implements Callable<JSONObject> {
-    private static Log logger = LogFactory.getLog(RecognitionCheckTaskEx.class);
+    private static Log logger = LogFactory.getLog(RecognitionCheckTask.class);
     private static int cache_time_out = 1800;
     private JSONObject businessParam;
     private Map<String, Object> customParam;
@@ -41,6 +49,23 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
     public static final String waiting = "waiting";
     public static final String success = "success";
     public static final String fail = "fail";
+    protected static final List<String> telGoodNames = new ArrayList<String>(12) {
+        private static final long serialVersionUID = 2608083843312492007L;
+
+        {
+            this.add("电信服务");
+            this.add("基础电信服务");
+            this.add("语音通话服务");
+            this.add("出租或出售网络元素");
+            this.add("增值电信服务");
+            this.add("短信和彩信服务");
+            this.add("电子数据和信息的传输及应用服务");
+            this.add("互联网接入服务");
+            this.add("广播电视信号传输服务");
+            this.add("卫星电视信号落地转接服务");
+            this.add("其他增值电信服务");
+        }
+    };
 
     public RecognitionCheckTaskEx(RequestContext ctx, String source, String pageId, JSONObject businessParam, Map<String, Object> customParam, String url, String fileName) {
         saveCacheFile(pageId, url, "waiting");
@@ -54,7 +79,7 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
     }
 
     public JSONObject call() throws Exception {
-        logger.info("begin RecognitionCheckTaskEx :{},{}", this.url, this.fileName);
+        logger.info("begin RecognitionCheckTask :{},{}", this.url, this.fileName);
 
         try {
             RequestContext.copyAndSet(this.ctx);
@@ -63,21 +88,33 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
             } else {
                 JSONObject invoiceResult = new JSONObject();
                 Long orgId = RequestContext.get().getOrgId();
+                long rim_user;
                 if (this.customParam != null) {
                     try {
-                        orgId = (Long)this.customParam.get("orgId");
+                        rim_user = BigDecimalUtil.transDecimal(this.customParam.get("orgId")).longValue();
+                        if (rim_user > 0L) {
+                            orgId = rim_user;
+                        }
                     } catch (Exception var12) {
                     }
                 }
 
-                boolean isZipXmlEI = FileUtils.checkFileType(this.fileName, new String[]{"zip", "xml"});
-                if (isZipXmlEI) {
-                    invoiceResult = EInvoiceZipXmlDealService.analysisAndCheckSave(this.url, this.fileName, orgId, this.businessParam, (IRecognitionListener)null);
+                if (this.businessParam != null) {
+                    rim_user = BigDecimalUtil.transDecimal(this.businessParam.get("rim_user")).longValue();
+                    if (rim_user < 1L) {
+                        this.businessParam.put("rim_user", RequestContext.get().getCurrUserId());
+                    }
                 }
 
-                boolean isNeedDeal = FileUtils.checkFileType(this.fileName, new String[]{"zip", "ofd", "xml"});
-                if (isNeedDeal && !"0000".equals(invoiceResult.getString("errcode"))) {
-                    invoiceResult = ElectAccVoucherService.dealVoucher(this.url, this.fileName, orgId, this.businessParam, (IRecognitionListener)null);
+                boolean isNeedDeal = FileUtils.checkFileType(this.fileName, new String[]{"zip", "ofd", "pdf"});
+                if (isNeedDeal) {
+                    ElectAccVoucherServiceEx electAccVoucherService = new ElectAccVoucherServiceEx();
+                    invoiceResult = electAccVoucherService.dealVoucher(this.url, this.fileName, orgId, this.businessParam, (IRecognitionListener)null);
+                }
+
+                boolean isZipXmlEI = FileUtils.checkFileType(this.fileName, new String[]{"zip", "xml"});
+                if (isZipXmlEI && !"0000".equals(invoiceResult.getString("errcode"))) {
+                    invoiceResult = EInvoiceZipXmlDealService.analysisAndCheckSave(this.url, this.fileName, orgId, this.businessParam, (IRecognitionListener)null);
                 }
 
                 String xbrlErrCode = invoiceResult.getString("errcode");
@@ -87,14 +124,15 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
                     if (FileUtils.isExcel(this.fileName)) {
                         invoiceResult = ExcelInvoiceUploadService.getInstance().uploadExcelInvoice(this.url, this.fileName, (IRecognitionListener)null, this.businessParam);
                     } else {
-                        logger.info("RecognitionCheckTaskEx识别url:{}{}", this.fileName, this.url);
+                        logger.info("RecognitionCheckTask识别url:{}{}", this.fileName, this.url);
                         invoiceResult = RecognitionCheckServiceEx.getInstance().recognitionCheckInvoice(this.url, this.fileName, (IRecognitionListener)null, this.businessParam);
                     }
                 }
 
-                logger.info("发票助手本地上传最终数据返回:" + invoiceResult);
+                logger.info("发票助手本地上传最终数据返回:{}-{}", this.pageId, invoiceResult);
                 if (ResultContant.isSuccess(invoiceResult)) {
                     JSONArray invoiceArray = invoiceResult.getJSONArray("data");
+                    classOfInvoice(invoiceArray);
                     JSONArray failInvoiceArray = invoiceResult.getJSONArray("failData");
                     JSONArray attachArray = invoiceResult.getJSONArray("attach");
                     if (!CollectionUtils.isEmpty(failInvoiceArray)) {
@@ -124,13 +162,128 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
                 return invoiceResult;
             }
         } catch (Throwable var13) {
-            logger.info("RecognitionCheckTaskEx throwable:{}", var13);
+            logger.info("RecognitionCheckTask throwable:{}", var13);
             saveCacheFile(this.pageId, this.url, "fail");
-            saveCacheCause(this.pageId, this.url, "fail", "程序错误");
+            saveCacheCause(this.pageId, this.url, "fail", ResManager.loadKDString("程序错误", "RecognitionCheckTask_0", "imc-rim-common", new Object[0]));
             return new JSONObject();
         }
     }
 
+    public static void classOfInvoice(JSONArray invoiceArray) {
+        if (invoiceArray != null) {
+            for(int i = 0; i < invoiceArray.size(); ++i) {
+                JSONObject invoice = invoiceArray.getJSONObject(i);
+                Long invoiceType = invoice.getLong("invoiceType");
+                if (InputInvoiceTypeEnum.needClassOfInvoice(invoiceType)) {
+                    boolean telFlag = telType(invoice);
+                    boolean childFlag = childType(invoice);
+                    if (telFlag && childFlag) {
+                        setInvoiceClass(invoice, "11", "9");
+                    } else if (telFlag) {
+                        setInvoiceClass(invoice, "9");
+                    } else if (childFlag) {
+                        setInvoiceClass(invoice, "11");
+                    }
+                }
+            }
+
+        }
+    }
+
+    private static boolean childType(JSONObject invoice) {
+        boolean flag = false;
+        Long invoiceType = invoice.getLong("invoiceType");
+        if (InputInvoiceTypeEnum.FINANCIAL_INVOICE.getCode().equals(invoiceType)) {
+            String invoicingPartyName = invoice.getString("invoicingPartyName");
+            if (StringUtils.isNotEmpty(invoicingPartyName) && invoicingPartyName.contains("幼儿园")) {
+                flag = true;
+            }
+        } else if (InputInvoiceTypeEnum.ORDINARY_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ORDINARY_PAPER.getCode().equals(invoiceType) || InputInvoiceTypeEnum.GENERAL_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ELECTRIC_ORDINARY.getCode().equals(invoiceType)) {
+            JSONArray items = invoice.getJSONArray("items");
+            if (items == null) {
+                return false;
+            }
+
+            for(int i = 0; i < items.size(); ++i) {
+                JSONObject item = items.getJSONObject(i);
+                String goodName = item.getString("goodsName");
+                if (StringUtils.isNotEmpty(goodName) && goodName.contains("保教费")) {
+                    flag = true;
+                    break;
+                }
+            }
+        }
+
+        return flag;
+    }
+
+    private static boolean telType(JSONObject invoice) {
+        Long invoiceType = invoice.getLong("invoiceType");
+        boolean telFlag = false;
+        if (InputInvoiceTypeEnum.ORDINARY_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.SPECIAL_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ORDINARY_PAPER.getCode().equals(invoiceType) || InputInvoiceTypeEnum.SPECIAL_PAPER.getCode().equals(invoiceType) || InputInvoiceTypeEnum.TOLL_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ELECTRIC_ORDINARY.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ELECTRIC_SPECIAL.getCode().equals(invoiceType) || InputInvoiceTypeEnum.GENERAL_ELECTRON.getCode().equals(invoiceType)) {
+            JSONArray items = invoice.getJSONArray("items");
+            if (items == null) {
+                return false;
+            }
+
+            boolean flag = false;
+
+            for(int i = 0; i < items.size(); ++i) {
+                JSONObject item = items.getJSONObject(i);
+                String goodName = item.getString("goodsName");
+                Iterator var8 = telGoodNames.iterator();
+
+                while(var8.hasNext()) {
+                    String s = (String)var8.next();
+                    if (goodName.contains(s)) {
+                        telFlag = true;
+                        flag = true;
+                        break;
+                    }
+                }
+
+                if (flag) {
+                    break;
+                }
+            }
+        }
+
+        return telFlag;
+    }
+
+    private static void setInvoiceClass(JSONObject invoice, String... classType) {
+        Long mainId = invoice.getLong("mainId");
+        DynamicObject invoices = BusinessDataServiceHelper.loadSingle("rim_invoice", "id, mul_class, ext_info", new QFilter[]{new QFilter("id", "=", mainId)});
+        if (invoices != null) {
+            String mulClassStr = String.join(",", classType);
+            String extInfo = invoices.getString("ext_info");
+            JSONObject extObject = new JSONObject();
+            if (StringUtils.isNotEmpty(extInfo)) {
+                try {
+                    extObject = JSONObject.parseObject(extInfo);
+                } catch (Exception var13) {
+                    extObject = new JSONObject();
+                }
+            }
+
+            extObject.put("sys_mulclass", mulClassStr);
+            invoices.set("ext_info", extObject.toString());
+            DynamicObjectCollection mul_class = invoices.getDynamicObjectCollection("mul_class");
+            if (CollectionUtils.isEmpty(mul_class)) {
+                String[] var8 = classType;
+                int var9 = classType.length;
+
+                for(int var10 = 0; var10 < var9; ++var10) {
+                    String typeStr = var8[var10];
+                    DynamicObject classInfo = mul_class.addNew();
+                    classInfo.set("fbasedataid_id", typeStr);
+                    SaveServiceHelper.save(new DynamicObject[]{invoices});
+                }
+            }
+        }
+
+    }
+
     public JSONObject getBusinessParam() {
         return this.businessParam;
     }
@@ -187,7 +340,7 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
             return null;
         } else {
             String cacheKey = "scaner_cause_" + pageId;
-            DLock lock = DLock.create("lock_" + cacheKey, "刷新卡片锁");
+            DLock lock = DLock.create("lock_" + cacheKey, ResManager.loadKDString("刷新卡片锁", "RecognitionCheckTask_1", "imc-rim-common", new Object[0]));
             Throwable var6 = null;
 
             JSONObject var10;
@@ -203,7 +356,6 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
                 } while(!lock.tryLock(100L));
 
 
-
                 try {
                     String cache;
                     if ("remove".equals(operate)) {
@@ -262,7 +414,7 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
             return null;
         } else {
             String cacheKey = "scaner_" + pageId;
-            DLock lock = DLock.create("lock_" + cacheKey, "刷新卡片锁");
+            DLock lock = DLock.create("lock_" + cacheKey, ResManager.loadKDString("刷新卡片锁", "RecognitionCheckTask_1", "imc-rim-common", new Object[0]));
             Throwable var5 = null;
 
             try {
@@ -271,6 +423,8 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
                 while(times < 10) {
                     ++times;
                     if (lock.tryLock(100L)) {
+                        long starttime = System.currentTimeMillis();
+
 
                         try {
                             String cache;
@@ -288,10 +442,10 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
                                 obj = JSON.parseObject(cache);
                             }
 
-                            JSONObject var9;
+                            JSONObject var11;
                             if ("query".equals(operate)) {
-                                var9 = obj;
-                                return var9;
+                                var11 = obj;
+                                return var11;
                             }
 
                             if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(operate)) {
@@ -299,23 +453,24 @@ public class RecognitionCheckTaskEx implements Callable<JSONObject> {
                                 CacheHelper.put(cacheKey, obj.toJSONString(), cache_time_out);
                             }
 
-                            var9 = obj;
-                            return var9;
+                            var11 = obj;
+                            return var11;
                         } finally {
+                            logger.info("cacheFile总耗时:{}-{}", pageId, System.currentTimeMillis() - starttime);
                             lock.unlock();
                         }
                     }
                 }
-            } catch (Throwable var28) {
-                var5 = var28;
-                throw var28;
+            } catch (Throwable var30) {
+                var5 = var30;
+                throw var30;
             } finally {
                 if (lock != null) {
                     if (var5 != null) {
                         try {
                             lock.close();
-                        } catch (Throwable var26) {
-                            var5.addSuppressed(var26);
+                        } catch (Throwable var28) {
+                            var5.addSuppressed(var28);
                         }
                     } else {
                         lock.close();

+ 453 - 0
src/main/java/kd/imc/rim/common/service/ElectAccVoucherServiceEx.java

@@ -0,0 +1,453 @@
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+package kd.imc.rim.common.service;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.Future;
+import kd.bos.context.RequestContext;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.resource.ResManager;
+import kd.bos.dataentity.utils.ObjectUtils;
+import kd.bos.db.tx.TX;
+import kd.bos.db.tx.TXHandle;
+import kd.bos.dlock.DLock;
+import kd.bos.fileservice.FileServiceFactory;
+import kd.bos.logging.Log;
+import kd.bos.logging.LogFactory;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.QueryServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import kd.bos.threads.ThreadPool;
+import kd.bos.threads.ThreadPools;
+import kd.bos.util.StringUtils;
+import kd.imc.rim.common.constant.InputInvoiceTypeEnum;
+import kd.imc.rim.common.constant.ResultContant;
+import kd.imc.rim.common.constant.XbrlTypeConstant;
+import kd.imc.rim.common.helper.ElectAccVoucherHelper;
+import kd.imc.rim.common.helper.RecognitionCheckHelper;
+import kd.imc.rim.common.invoice.collector.InvoiceCollectService;
+import kd.imc.rim.common.invoice.recognition.listener.IRecognitionListener;
+import kd.imc.rim.common.invoice.recognition.listener.RecognitionListenerResult;
+import kd.imc.rim.common.invoice.recognitionnew.task.FileUploadAndSignTask;
+import kd.imc.rim.common.invoice.save.InvoiceSaveService;
+import kd.imc.rim.common.message.exception.MsgException;
+import kd.imc.rim.common.utils.*;
+import kd.imc.rim.common.utils.extract.ZipExtractUtil;
+import kd.imc.rim.file.utils.FileConvertUtils;
+import kd.imc.rim.common.utils.FileUtilsEx;
+
+public class ElectAccVoucherServiceEx {
+    private static Log logger = LogFactory.getLog(ElectAccVoucherService.class);
+    private static final String awsRecognitionImpl = "kd.imc.rim.common.invoice.recognitionnew.impl.AwsRecognitionService";
+    private static ThreadPool xbrlUploadThreadPool = ThreadPools.newFixedThreadPool("xbrlUploadThreadPool", 10);
+    private ElectAccVoucherHelper electAccVoucherHelper = new ElectAccVoucherHelper();
+
+    public ElectAccVoucherServiceEx() {
+    }
+
+    public JSONObject dealVoucher(String fileUrl, String fileName, Object orgId, JSONObject businessParam, IRecognitionListener recognitionListener) throws IOException {
+        JSONObject result = new JSONObject();
+        boolean isVoucherOrg = checkOrg(orgId);
+        if (!isVoucherOrg) {
+            result.put("errcode", "0004");
+            result.put("description", ResManager.loadKDString("非电子会计凭证试点企业", "ElectAccVoucherService_0", "imc-rim-common", new Object[0]));
+            return result;
+        } else if (!StringUtils.isEmpty(fileUrl) && !StringUtils.isEmpty(fileName)) {
+            logger.info("电子会计凭证解析开始:{}", fileName);
+            return this.extracted(fileUrl, fileName, orgId, businessParam, recognitionListener);
+        } else {
+            return result;
+        }
+    }
+
+    private JSONObject extracted(String fileUrl, String fileName, Object orgId, JSONObject businessParam, IRecognitionListener recognitionListener) throws IOException {
+        JSONObject result = new JSONObject();
+        Map<String, String> configMap = ImcConfigUtil.getValue("rim_recog_check");
+        String recognitionImplStr = (String)configMap.get("rimpl");
+        boolean isAwsRecognition = StringUtils.isEmpty(recognitionImplStr) || "kd.imc.rim.common.invoice.recognitionnew.impl.AwsRecognitionService".equals(recognitionImplStr);
+        RecognitionCheckHelper recognitionCheckHelper = new RecognitionCheckHelper();
+        FormFileEntity fileEntity = recognitionCheckHelper.getFormFileEntity(fileUrl, fileName);
+
+        try {
+            InputStream fileInputStream = FileServiceFactory.getAttachmentFileService().getInputStream(fileEntity.getFileUrl());
+            Throwable var13 = null;
+
+            try {
+                byte[] fileByte = FileUtilsEx.getByte(fileInputStream);
+                String fileType = FileUtilsEx.getFileType(fileName);
+                Future<JSONObject> xbrlUploadSubmit = null;
+                if (!"zip".equalsIgnoreCase(fileType)) {
+                    xbrlUploadSubmit = xbrlUploadThreadPool.submit(new FileUploadAndSignTask(fileEntity.getFileUrl(), fileByte, fileEntity.getFileName(), fileEntity.getFileType(), fileEntity.getFileHash(), fileEntity.getSignatureFlag(), RequestContext.get()));
+                }
+
+                JSONObject checkZipFileResult = this.checkZipFile(fileByte, fileType);
+                if (Objects.nonNull(checkZipFileResult)) {
+                    JSONObject var66 = checkZipFileResult;
+                    return var66;
+                } else {
+                    long startTime = System.currentTimeMillis();
+                    JSONObject var67;
+                    if (isAwsRecognition) {
+                        result = this.electAccVoucherHelper.getByAwsAPI(orgId, fileByte, fileName);
+                    } else {
+                        result = this.electAccVoucherHelper.getByAnalysis(fileType, fileByte);
+                        boolean signPassFlag = result.getBoolean("signPassFlag");
+                        if (!signPassFlag) {
+                            result.put("errcode", "0004");
+                            result.put("description", ResManager.loadKDString("电子会计凭证验签不通过", "ElectAccVoucherService_1", "imc-rim-common", new Object[0]));
+                            var67 = result;
+                            return var67;
+                        }
+                    }
+
+                    if (!"0000".equals(result.getString("errcode"))) {
+                        var67 = result;
+                        return var67;
+                    } else {
+                        String xbrlInfo = result.getString("xbrlInfo");
+                        JSONObject resultInvoice = this.electAccVoucherHelper.toInvoiceJson(xbrlInfo, orgId);
+                        if (resultInvoice == null) {
+                            result.put("errcode", "0005");
+                            result.put("description", ResManager.loadKDString("电子会计凭证转换失败", "ElectAccVoucherService_2", "imc-rim-common", new Object[0]));
+                            JSONObject var68 = result;
+                            return var68;
+                        } else {
+                            String voucherFileUrl = getVoucherFileUrl(fileType, fileByte, xbrlInfo);
+                            if (resultInvoice.containsKey("isUploadOriginal") && !resultInvoice.getBoolean("isUploadOriginal") && xbrlUploadSubmit != null) {
+                                uploadGet(xbrlUploadSubmit, resultInvoice);
+                            }
+
+                            if (resultInvoice.containsKey("isUploadOriginal") && resultInvoice.getBoolean("isUploadOriginal")) {
+                                resultInvoice.put("originalState", "1");
+                            } else if (!"zip".equalsIgnoreCase(fileType)) {
+                                resultInvoice.put("originalState", "1");
+                                resultInvoice.put("originalTime", new Date());
+                            } else {
+                                resultInvoice.put("originalState", "0");
+                            }
+
+                            String serialNo = resultInvoice.getString("serialNo");
+                            if (StringUtils.isEmpty(serialNo)) {
+                                serialNo = UUID.randomUUID();
+                                resultInvoice.put("serialNo", serialNo);
+                            }
+
+                            if ("zip".equalsIgnoreCase(fileType)) {
+                                resultInvoice.put("isZipFile", Boolean.TRUE);
+                            }
+
+                            resultInvoice.put("fileType", FileUtilsEx.convertFileTypeNum(fileType));
+                            resultInvoice.put("fileName", fileName);
+                            TXHandle h = TX.required();
+                            Throwable var26 = null;
+
+                            try {
+                                String errorMsg;
+                                try {
+                                    String xbrlType = resultInvoice.getString("xbrlType");
+                                    errorMsg = resultInvoice.getString("invoiceDate");
+                                    Long invoiceType = resultInvoice.getLong("invoiceType");
+                                    String xbrlName = this.getTargetName(serialNo, xbrlType, invoiceType, errorMsg);
+                                    if (xbrlName == null) {
+                                        xbrlName = fileName;
+                                    }
+
+                                    saveVoucher(serialNo, xbrlName, voucherFileUrl, xbrlType);
+                                    resultInvoice = this.saveInvoice(businessParam, resultInvoice, fileUrl, fileByte);
+                                } catch (Throwable var60) {
+                                    logger.info("保存电子会计凭证出错:{}", var60);
+                                    h.markRollback();
+                                    errorMsg = ResManager.loadKDString("电子会计凭证保存异常或者发票数据保存异常,请联系管理员", "ElectAccVoucherService_9", "imc-rim-common", new Object[0]);
+                                    if (var60 instanceof MsgException) {
+                                        errorMsg = ((MsgException)var60).getErrorMsg();
+                                    }
+
+                                    resultInvoice.put("errorMsg", errorMsg);
+                                    if (businessParam != null && "1".equals(businessParam.getString("throwSaveError"))) {
+                                        throw var60;
+                                    }
+                                }
+                            } catch (Throwable var61) {
+                                var26 = var61;
+                                throw var61;
+                            } finally {
+                                if (h != null) {
+                                    if (var26 != null) {
+                                        try {
+                                            h.close();
+                                        } catch (Throwable var59) {
+                                            var26.addSuppressed(var59);
+                                        }
+                                    } else {
+                                        h.close();
+                                    }
+                                }
+
+                            }
+
+                            if (resultInvoice.get("mainId") != null) {
+                                DynamicObject invoiceObject = BusinessDataServiceHelper.loadSingle(resultInvoice.get("mainId"), "rim_invoice");
+                                String invoiceType = resultInvoice.getString("invoiceType");
+                                InvoiceSaveService service = InvoiceSaveService.newInstance(invoiceType);
+                                if (service != null) {
+                                    service.setMainInvoiceInfo(invoiceObject);
+                                    SaveServiceHelper.save(new DynamicObject[]{invoiceObject});
+                                }
+                            }
+
+                            RecognitionCheckService.setInvoiceSeq(resultInvoice, businessParam, 0, 0);
+                            result.put("errcode", "0000");
+                            result.put("description", ResManager.loadKDString("操作成功", "ElectAccVoucherService_8", "imc-rim-common", new Object[0]));
+                            JSONArray resultArray = new JSONArray();
+                            resultInvoice.put("fileType", FileUtilsEx.convertFileTypeNum(FileUtils.getFileType(fileName)));
+                            resultArray.add(resultInvoice);
+                            result.put("data", resultArray);
+                            RecognitionListenerResult listener = new RecognitionListenerResult(fileUrl, fileName, 1, 1, resultArray);
+                            if (recognitionListener != null) {
+                                recognitionListener.handle(listener);
+                            }
+
+                            logger.info("电子会计凭证总耗时:{}", System.currentTimeMillis() - startTime);
+                            return result;
+                        }
+                    }
+                }
+            } catch (Throwable var63) {
+                var13 = var63;
+                throw var63;
+            } finally {
+                if (fileInputStream != null) {
+                    if (var13 != null) {
+                        try {
+                            fileInputStream.close();
+                        } catch (Throwable var58) {
+                            var13.addSuppressed(var58);
+                        }
+                    } else {
+                        fileInputStream.close();
+                    }
+                }
+
+            }
+        } catch (Throwable var65) {
+            logger.info("解析电子会计凭证出错:{}", var65);
+            result.put("errcode", "0002");
+            result.put("description", ResManager.loadKDString("解析电子会计凭证出错", "ElectAccVoucherService_4", "imc-rim-common", new Object[0]));
+            return result;
+        }
+    }
+
+    private String getTargetName(String serialNo, String xbrlType, Long invoiceType, String invoiceDate) {
+        String prefix = "";
+        if (StringUtils.isNotEmpty(invoiceDate)) {
+            invoiceDate = invoiceDate.replaceAll("-", "");
+        }
+
+        if (XbrlTypeConstant.AIR_ELE.getCode().equals(xbrlType)) {
+            prefix = "atr_issuer_";
+        } else if (XbrlTypeConstant.BANK_RECEIPT.getCode().equals(xbrlType)) {
+            prefix = "bker_issuer_";
+        } else if (XbrlTypeConstant.BANK_STATEMENT.getCode().equals(xbrlType)) {
+            prefix = "bkrs_issuer_";
+        } else if (XbrlTypeConstant.FINANCIAL.getCode().equals(xbrlType)) {
+            prefix = "efi_issuer_";
+        } else if (XbrlTypeConstant.TRAIN_ELE.getCode().equals(xbrlType)) {
+            prefix = "rai_issuer_";
+        } else if (XbrlTypeConstant.COVERINGWARRANT.getCode().equals(xbrlType)) {
+            prefix = "ntrev_gpm_issuer_";
+        } else if (XbrlTypeConstant.E_VAT.getCode().equals(xbrlType)) {
+            if (InputInvoiceTypeEnum.ORDINARY_ELECTRON.getCode().equals(invoiceType)) {
+                prefix = "inv_ord_issuer_";
+            } else {
+                prefix = "inv_spcl_issuer_";
+            }
+        }
+
+        return StringUtils.isEmpty(prefix) ? null : prefix + invoiceDate + '_' + serialNo + ".xml";
+    }
+
+    private JSONObject checkZipFile(byte[] fileByte, String fileType) {
+        if ("zip".equalsIgnoreCase(fileType)) {
+            int fileLimit = 2;
+            Map<String, String> zipFileMap = ZipExtractUtil.extractFileForXml(fileByte);
+            if (zipFileMap.isEmpty()) {
+                return ResultContant.createJSONObject("0002", ResManager.loadKDString("解析zip压缩包为空", "ElectAccVoucherService_5", "imc-rim-common", new Object[0]));
+            }
+
+            if (zipFileMap.size() != fileLimit) {
+                return ResultContant.createJSONObject("0003", String.format(ResManager.loadKDString("解析zip压缩包只包含%1$s个文件", "ElectAccVoucherService_6", "imc-rim-common", new Object[0]), zipFileMap.size()));
+            }
+
+            Iterator var5 = zipFileMap.entrySet().iterator();
+
+            while(var5.hasNext()) {
+                Map.Entry<String, String> map = (Map.Entry)var5.next();
+                String key = (String)map.getKey();
+                boolean checkFileType = FileUtils.checkFileType(key, new String[]{"xml", "sign"});
+                if (!checkFileType) {
+                    return ResultContant.createJSONObject("0003", ResManager.loadKDString("解析zip压缩包只能包含xml/sign文件", "ElectAccVoucherService_7", "imc-rim-common", new Object[0]));
+                }
+            }
+        }
+
+        return null;
+    }
+
+    private JSONObject saveInvoice(JSONObject businessParam, JSONObject resultInvoice, String fileUrl, byte[] fileByte) {
+        Long tax_org = null;
+        if (null != businessParam) {
+            resultInvoice.putAll(businessParam);
+            tax_org = businessParam.getLong("tax_org");
+        }
+
+        if (!ObjectUtils.isEmpty(tax_org)) {
+            resultInvoice.put("tax_org", tax_org);
+        }
+
+        InvoiceCollectService invoiceCollectService = new InvoiceCollectService();
+        String fileHash = FileConvertUtils.getSHA256(fileByte);
+        if (StringUtils.isEmpty(resultInvoice.getString("serialNo"))) {
+            resultInvoice.put("serialNo", UUID.randomUUID());
+        }
+
+        DLock lock = DLock.create(resultInvoice.getString("invoiceNo") + "saveVoucher", "saveVoucherLock");
+        Throwable var9 = null;
+
+        try {
+            if (lock.tryLock(10000L)) {
+                if (!resultInvoice.containsKey("checkStatus")) {
+                    resultInvoice.put("checkStatus", "1");
+                }
+
+                resultInvoice = invoiceCollectService.saveInvoice(resultInvoice, fileUrl, fileHash);
+                CacheHelper.put(resultInvoice.getString("invoiceNo") + "saveVoucher", resultInvoice.toJSONString(), 10000);
+            } else {
+                JSONObject cacheObject = JSON.parseObject(CacheHelper.get(resultInvoice.getString("invoiceNo") + "saveVoucher"));
+                if (cacheObject != null) {
+                    resultInvoice = cacheObject;
+                    CacheHelper.remove(cacheObject.getString("invoiceNo") + "saveVoucher");
+                }
+            }
+        } catch (Throwable var18) {
+            var9 = var18;
+            throw var18;
+        } finally {
+            if (lock != null) {
+                if (var9 != null) {
+                    try {
+                        lock.close();
+                    } catch (Throwable var17) {
+                        var9.addSuppressed(var17);
+                    }
+                } else {
+                    lock.close();
+                }
+            }
+
+        }
+
+        return resultInvoice;
+    }
+
+    public static boolean checkOrg(Object orgId) {
+        boolean isVoucherOrg = false;
+
+        try {
+            if (orgId != null) {
+                DynamicObject orgObject = BusinessDataServiceHelper.loadSingle(orgId, "bdm_org");
+                if (orgObject != null && "1".equals(orgObject.get("epinfo.isvoucher"))) {
+                    isVoucherOrg = true;
+                }
+            }
+        } catch (Throwable var3) {
+            logger.info("获取企业电子会计凭证开关出错:{}", var3);
+            isVoucherOrg = false;
+        }
+
+        return isVoucherOrg;
+    }
+
+    private static String getVoucherFileUrl(String fileType, byte[] fileByte, String xbrlInfo) throws IOException {
+        String fileUploadUrl;
+        if ("zip".equalsIgnoreCase(fileType)) {
+            fileUploadUrl = FileConvertUtils.upload(fileByte, fileType);
+        } else {
+            ByteArrayInputStream xbrlStream = new ByteArrayInputStream(xbrlInfo.getBytes(StandardCharsets.UTF_8));
+            Throwable var5 = null;
+
+            try {
+                fileUploadUrl = FileConvertUtils.upload(FileUtils.getByte(xbrlStream), "xml");
+            } catch (Throwable var14) {
+                var5 = var14;
+                throw var14;
+            } finally {
+                if (xbrlStream != null) {
+                    if (var5 != null) {
+                        try {
+                            xbrlStream.close();
+                        } catch (Throwable var13) {
+                            var5.addSuppressed(var13);
+                        }
+                    } else {
+                        xbrlStream.close();
+                    }
+                }
+
+            }
+        }
+
+        return fileUploadUrl;
+    }
+
+    private static void uploadGet(Future<JSONObject> xbrlUploadSubmit, JSONObject resultInvoice) {
+        try {
+            JSONObject result = (JSONObject)xbrlUploadSubmit.get();
+            if (result != null) {
+                resultInvoice.put("imageUrl", result.getString("imageUrl"));
+                resultInvoice.put("ofdUrl", result.getString("ofdUrl"));
+                resultInvoice.put("pdfUrl", result.getString("pdfUrl"));
+                resultInvoice.put("snapshotUrl", result.getString("imageUrl"));
+            }
+        } catch (Exception var3) {
+            logger.info("电子会计凭证文件上传出错:{}", var3);
+        }
+
+    }
+
+    public static void saveVoucher(String serialNo, String xbrlName, String fileUploadUrl, String xbrlType) {
+        DynamicObject voucherObject = QueryServiceHelper.queryOne("rim_invoice_voucher", "id, serial_no, xbrl_name, xbrl_url, xbrl_type, receive_xbrl_url, receive_xbrl_name, create_time, update_time", new QFilter[]{new QFilter("serial_no", "=", serialNo)});
+        if (voucherObject == null) {
+            voucherObject = BusinessDataServiceHelper.newDynamicObject("rim_invoice_voucher");
+            voucherObject.set("serial_no", serialNo);
+            voucherObject.set("xbrl_name", xbrlName);
+            voucherObject.set("xbrl_url", fileUploadUrl);
+            voucherObject.set("xbrl_type", xbrlType);
+            voucherObject.set("receive_xbrl_url", "");
+            voucherObject.set("receive_xbrl_name", "");
+            voucherObject.set("create_time", new Date());
+            voucherObject.set("update_time", new Date());
+        } else {
+            voucherObject = BusinessDataServiceHelper.loadSingle(voucherObject.get("id"), "rim_invoice_voucher");
+            voucherObject.set("xbrl_name", xbrlName);
+            voucherObject.set("xbrl_url", fileUploadUrl);
+            voucherObject.set("xbrl_type", xbrlType);
+            voucherObject.set("update_time", new Date());
+        }
+
+        SaveServiceHelper.save(new DynamicObject[]{voucherObject});
+    }
+}

+ 125 - 70
src/main/java/kd/imc/rim/common/service/RecognitionCheckServiceEx.java

@@ -1,10 +1,33 @@
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
 package kd.imc.rim.common.service;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
 import kd.bos.context.RequestContext;
+import kd.bos.dataentity.resource.ResManager;
 import kd.bos.dataentity.utils.ObjectUtils;
 import kd.bos.dataentity.utils.StringUtils;
 import kd.bos.fileservice.FileServiceFactory;
@@ -15,7 +38,7 @@ import kd.bos.threads.ThreadPools;
 import kd.imc.rim.common.constant.CheckContant;
 import kd.imc.rim.common.constant.InputInvoiceTypeEnum;
 import kd.imc.rim.common.constant.InvoiceUploadErrorType;
-
+import kd.imc.rim.common.helper.RecognitionCheckHelper;
 import kd.imc.rim.common.helper.RecognitionCheckHelperEx;
 import kd.imc.rim.common.invoice.collector.InvoiceCollectService;
 import kd.imc.rim.common.invoice.model.ConvertFieldUtil;
@@ -26,25 +49,14 @@ import kd.imc.rim.common.invoice.save.InvoiceSaveService;
 import kd.imc.rim.common.message.exception.MsgException;
 import kd.imc.rim.common.utils.*;
 import kd.imc.rim.common.utils.itextpdf.UrlServiceUtils;
-import kd.imc.rim.file.model.FileConvertResult;
+import kd.imc.rim.file.utils.FileConvertUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.compress.utils.Lists;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
-import java.util.*;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.stream.Collectors;
-
 public class RecognitionCheckServiceEx {
     private static RecognitionCheckServiceEx instance = null;
-    private static Log logger = LogFactory.getLog(RecognitionCheckServiceEx.class);
-    private RecognitionCheckHelperEx recognitionCheckHelper = new RecognitionCheckHelperEx();
+    private static Log logger = LogFactory.getLog(RecognitionCheckService.class);
+    private RecognitionCheckHelperEx RecognitionCheckHelperEx = new RecognitionCheckHelperEx();
     private InvoiceCollectService invoiceCollectService = new InvoiceCollectService();
     private static Integer recheckorginPage = 999123413;
     private static ThreadPool uploadThreadPool = ThreadPools.newFixedThreadPool("recognitionUploadThread_2", Runtime.getRuntime().availableProcessors() + 1);
@@ -53,8 +65,8 @@ public class RecognitionCheckServiceEx {
     }
 
     public static RecognitionCheckServiceEx getInstance() {
-        Class var0 = RecognitionCheckServiceEx.class;
-        synchronized(RecognitionCheckServiceEx.class) {
+        Class var0 = RecognitionCheckService.class;
+        synchronized(RecognitionCheckService.class) {
             if (instance == null) {
                 instance = new RecognitionCheckServiceEx();
             }
@@ -65,6 +77,7 @@ public class RecognitionCheckServiceEx {
 
     public JSONObject recognitionCheckInvoice(String fileUrl, String fileName, IRecognitionListener recognitionListener, JSONObject businessParam) {
         logger.info("识别查验fileName:{},businessParam:{}", fileName, businessParam);
+        fileName = kd.imc.rim.common.utils.FileUtilsEx.truncateFileName(fileName, 50);
         this.markDeleteByVerifySave(businessParam);
         boolean isCheck = this.getCheckFlag(businessParam);
         return this.extracted_new(fileUrl, fileName, recognitionListener, businessParam, isCheck);
@@ -89,14 +102,14 @@ public class RecognitionCheckServiceEx {
         JSONArray attachResult;
         try {
             long fileStartTime = System.currentTimeMillis();
-            FormFileEntity fileEntity = this.recognitionCheckHelper.getFormFileEntity(fileUrl, fileName);
+            FormFileEntity fileEntity = this.RecognitionCheckHelperEx.getFormFileEntity(fileUrl, fileName);
             if (!fileEntity.getSuccess()) {
                 this.handle(recognitionListener, listener);
                 return InvoiceUploadErrorType.getSplitErrorResult();
             }
 
             int totalPage = CollectionUtils.isEmpty(fileEntity.getSubFileList()) ? 1 : fileEntity.getSubFileList().size();
-            Map<String, Object> extMap = this.recognitionCheckHelper.getRecognitionCheckExtMap(businessParam);
+            Map<String, Object> extMap = this.RecognitionCheckHelperEx.getRecognitionCheckExtMap(businessParam);
             String originalStateDefault = fileEntity.getOriginalStateDefault();
             if ("1".equals(originalStateDefault)) {
                 extMap.put("originalStateDefault", originalStateDefault);
@@ -104,13 +117,13 @@ public class RecognitionCheckServiceEx {
 
             String fileType = fileEntity.getFileType();
             Map<Integer, Object> subFileFutureMap = this.syncUploadSubFile(fileEntity);
-            logger.info("RecognitionCheckServiceEx 文件解析耗时:{}", System.currentTimeMillis() - fileStartTime);
+            logger.info("RecognitionCheckService 文件解析耗时:{}", System.currentTimeMillis() - fileStartTime);
 
             List recognitionResultList;
             try {
                 long recognitionStartTime = System.currentTimeMillis();
-                recognitionResultList = this.recognitionCheckHelper.recognitionInvoiceFile(fileEntity, extMap);
-                logger.info("RecognitionCheckServiceEx 识别总耗时:{}", System.currentTimeMillis() - recognitionStartTime);
+                recognitionResultList = this.RecognitionCheckHelperEx.recognitionInvoiceFile(fileEntity, extMap);
+                logger.info("RecognitionCheckService 识别总耗时:{}", System.currentTimeMillis() - recognitionStartTime);
                 this.checkOriginal(fileEntity, subFileFutureMap, recognitionResultList);
                 finalResult = JSONObject.parseArray(JSONObject.toJSONString(recognitionResultList));
             } catch (Throwable var26) {
@@ -122,14 +135,12 @@ public class RecognitionCheckServiceEx {
                 logger.info("识别程序错误:", var26);
                 return InvoiceUploadErrorType.getRecognitionErrorResult();
             }
-            //改了的地方
-            isCheck=false;
 
             if (isCheck && recognitionResultList.size() > 0) {
                 try {
                     long checkStartTime = System.currentTimeMillis();
-                    List<JSONObject> checkResultList = this.recognitionCheckHelper.checkInvoiceByRecognitionInfo(recognitionResultList, extMap);
-                    logger.info("RecognitionCheckServiceEx 查验总耗时:{}", System.currentTimeMillis() - checkStartTime);
+                    List<JSONObject> checkResultList = this.RecognitionCheckHelperEx.checkInvoiceByRecognitionInfo(recognitionResultList, extMap);
+                    logger.info("RecognitionCheckService 查验总耗时:{}", System.currentTimeMillis() - checkStartTime);
                     finalResult = JSONObject.parseArray(JSONObject.toJSONString(checkResultList));
                 } catch (Throwable var25) {
                     this.handle(recognitionListener, listener);
@@ -143,6 +154,7 @@ public class RecognitionCheckServiceEx {
             fileBaseInfo.put("fileUrl", fileUrl);
             fileBaseInfo.put("fileName", fileName);
             fileBaseInfo.put("size", fileEntity.getFileSize());
+            fileBaseInfo.put("fileHash", fileEntity.getFileHash());
             finalResult = this.putFileInfo(fileBaseInfo, finalResult, subFileFutureMap, originalStateDefault);
             attachResult = this.dealSaleList(finalResult, businessParam);
             boolean isHandleAttach = attachResult.size() > 0 && finalResult.size() == 0;
@@ -153,6 +165,7 @@ public class RecognitionCheckServiceEx {
 
             try {
                 if (fileBaseInfo.get("totalPage") == null) {
+                    totalPage = this.getTotalPage(finalResult, attachResult);
                     fileBaseInfo.put("totalPage", totalPage);
                 }
 
@@ -163,24 +176,24 @@ public class RecognitionCheckServiceEx {
                 logger.info("发票保存错误:", var24);
             }
         } catch (IOException var27) {
-            logger.info("RecognitionCheckServiceEx IOException :{}", var27);
+            logger.info("RecognitionCheckService IOException :{}", var27);
             this.handle(recognitionListener, listener);
             return InvoiceUploadErrorType.getSplitErrorResult();
         } catch (MsgException var28) {
-            logger.info("RecognitionCheckServiceEx MsgException :{}", var28);
+            logger.info("RecognitionCheckService MsgException :{}", var28);
             this.handle(recognitionListener, listener);
             JSONObject errorInfo = new JSONObject();
             errorInfo.put("errcode", var28.getErrorCode());
             errorInfo.put("description", var28.getMessage());
             return errorInfo;
         } catch (Throwable var29) {
-            logger.info("RecognitionCheckServiceEx BaseErrorResult Throwable:{}", var29);
+            logger.info("RecognitionCheckService BaseErrorResult Throwable:{}", var29);
             this.handle(recognitionListener, listener);
             return InvoiceUploadErrorType.getBaseErrorResult();
         }
 
         boolean resultFlag = finalResult.size() != 0 || attachResult.size() != 0;
-        logger.info("RecognitionCheckServiceEx 识别查验入库总耗时:{}", System.currentTimeMillis() - startTime);
+        logger.info("RecognitionCheckService 识别查验入库总耗时:{}", System.currentTimeMillis() - startTime);
         if (resultFlag) {
             return InvoiceUploadErrorType.getSuccessResult(finalResult, attachResult);
         } else {
@@ -206,17 +219,12 @@ public class RecognitionCheckServiceEx {
 
             for(i = 1; i < recognitionResultList.size(); ++i) {
                 JSONObject invoice = (JSONObject)recognitionResultList.get(i);
-                Long invoiceType1 = invoice.getLong("invoiceType");
-                if (InputInvoiceTypeEnum.OTHER_INVOICE.getCode().equals(invoiceType1)) {
-                    String title = invoice.getString("title");
-                    boolean saleTitle = !StringUtils.isEmpty(title) && title.indexOf("清单") > 0;
-                    if (!saleTitle) {
-                        return;
-                    }
+                if (!RecognitionCheckHelper.isSalePage(invoice)) {
+                    return;
                 }
             }
 
-            FileUploadAndSignTask task = new FileUploadAndSignTask(fileEntity.getFileUrl(), (byte[])null, "pdf", true, RequestContext.get());
+            FileUploadAndSignTask task = new FileUploadAndSignTask(fileEntity.getFileUrl(), (byte[])null, fileEntity.getFileName(), "pdf", fileEntity.getFileHash(), true, RequestContext.get());
             task.setSignOnly(true);
             Future<JSONObject> subUploadFuture = uploadThreadPool.submit(task);
             subFileFutureMap.put(recheckorginPage, subUploadFuture);
@@ -224,6 +232,24 @@ public class RecognitionCheckServiceEx {
 
     }
 
+    private int getTotalPage(JSONArray finalResult, JSONArray attachArray) {
+        Set<Integer> pageNumSet = new HashSet(8);
+        int i;
+        if (finalResult != null && !finalResult.isEmpty()) {
+            for(i = 0; i < finalResult.size(); ++i) {
+                pageNumSet.add(finalResult.getJSONObject(i).getInteger("pageNo"));
+            }
+        }
+
+        if (attachArray != null && !attachArray.isEmpty()) {
+            for(i = 0; i < attachArray.size(); ++i) {
+                pageNumSet.add(attachArray.getJSONObject(i).getInteger("pageNo"));
+            }
+        }
+
+        return pageNumSet.size();
+    }
+
     private void handleAttach(JSONArray attachResult, IRecognitionListener recognitionListener, String fileUrl, String fileName, int totalPage) {
         if (attachResult != null && attachResult.size() != 0) {
             if (recognitionListener != null) {
@@ -250,14 +276,15 @@ public class RecognitionCheckServiceEx {
         if (finalResult.size() == 0) {
             return new JSONArray();
         } else {
-            JSONArray targetArray = this.recognitionCheckHelper.getTargetArray(finalResult);
-            finalResult.removeAll(targetArray);
             Map<String, String> configMap = ImcConfigUtil.getValue("rim_recog_check");
             String isDealSaleList = (String)configMap.get("is_dealsalelist");
             if ("0".equals(isDealSaleList)) {
                 return new JSONArray();
             } else {
-                JSONArray attachArray = this.recognitionCheckHelper.bindAttachInvoice(targetArray, businessParam);
+                JSONArray targetArray = this.RecognitionCheckHelperEx.getTargetArray(finalResult);
+                finalResult.removeAll(targetArray);
+                Map<String, Long> invoiceTypeMap = this.getInvoiceTypeMapAndRemoveFinancialDetail(finalResult);
+                JSONArray attachArray = this.RecognitionCheckHelperEx.bindAttachInvoice(targetArray, businessParam, invoiceTypeMap);
                 List<String> finishList = Lists.newArrayList();
                 if (attachArray.size() > 0) {
                     for(int i = 0; i < attachArray.size(); ++i) {
@@ -269,7 +296,7 @@ public class RecognitionCheckServiceEx {
                             StringBuilder attachNo = new StringBuilder();
                             attachNo.append(invoiceCode).append('_').append(invoiceNo);
                             if (!finishList.contains(attachNo.toString())) {
-                                JSONObject numObject = this.recognitionCheckHelper.calcSaleListComplete(invoiceCode, invoiceNo, attachNo.toString());
+                                JSONObject numObject = this.RecognitionCheckHelperEx.calcSaleListComplete(invoiceCode, invoiceNo, attachNo.toString());
                                 int salelistSum = numObject.getInteger("salelistSum");
                                 if (salelistSum == 0) {
                                     salelistSum = attachInfo.getInteger("page_sum");
@@ -288,6 +315,40 @@ public class RecognitionCheckServiceEx {
         }
     }
 
+    private Map<String, Long> getInvoiceTypeMapAndRemoveFinancialDetail(JSONArray finalResult) {
+        Map<String, Long> invoiceTypeMap = new HashMap(8);
+        boolean notFINANCIAL = false;
+
+        for(int i = 0; i < finalResult.size(); ++i) {
+            JSONObject invoiceInfo = finalResult.getJSONObject(i);
+            Long invoiceType = invoiceInfo.getLong("invoiceType");
+            if (!InputInvoiceTypeEnum.OTHER_INVOICE.getCode().equals(invoiceType)) {
+                invoiceTypeMap.put(StringUtils.trimToEmpty(invoiceInfo.getString("invoiceCode")) + StringUtils.trimToEmpty(invoiceInfo.getString("invoiceNo")), invoiceType);
+            } else if (!InputInvoiceTypeEnum.FINANCIAL_INVOICE.getCode().equals(invoiceType) && !InputInvoiceTypeEnum.OTHER_INVOICE.getCode().equals(invoiceType)) {
+                notFINANCIAL = true;
+            }
+        }
+
+        if (invoiceTypeMap.size() > 0 && !notFINANCIAL) {
+            List<JSONObject> list = new ArrayList(8);
+
+            for(int i = 0; i < finalResult.size(); ++i) {
+                JSONObject invoiceInfo = finalResult.getJSONObject(i);
+                Long invoiceType = invoiceInfo.getLong("invoiceType");
+                String title = invoiceInfo.getString("title");
+                if (!RecognitionCheckHelper.isSalePage(invoiceInfo) && InputInvoiceTypeEnum.OTHER_INVOICE.getCode().equals(invoiceType) && StringUtils.isNotEmpty(title) && title.indexOf("明细") > 0) {
+                    list.add(invoiceInfo);
+                }
+            }
+
+            if (!list.isEmpty()) {
+                finalResult.removeAll(list);
+            }
+        }
+
+        return invoiceTypeMap;
+    }
+
     public void handle(IRecognitionListener recognitionListener, RecognitionListenerResult listener) {
         if (recognitionListener != null) {
             recognitionListener.handle(listener);
@@ -331,7 +392,9 @@ public class RecognitionCheckServiceEx {
 
         for(int i = 0; i < finalResult.size(); ++i) {
             JSONObject invoiceInfo = (JSONObject)finalResult.get(i);
+            Long invoiceType = invoiceInfo.getLong("invoiceType");
             invoiceInfo.put("fileName", fileBaseInfo.get("fileName"));
+            invoiceInfo.put("fileHash", fileBaseInfo.get("fileHash"));
             int pageNo = (Integer)invoiceInfo.get("pageNo");
             Object feature = subFileFutureMap.get(pageNo);
             if (feature != null) {
@@ -344,17 +407,17 @@ public class RecognitionCheckServiceEx {
                     }
                 }
 
-                String path;
                 if (fileReuslt != null) {
-                    path = fileReuslt.getString("isOriginal");
+                    String isOriginal = fileReuslt.getString("isOriginal");
                     if (!"1".equals(invoiceInfo.getString("originalState"))) {
-                        if ("true".equals(path)) {
+                        if ("true".equals(isOriginal)) {
                             invoiceInfo.put("originalState", "1");
                         } else {
                             invoiceInfo.put("originalState", "0");
                         }
                     }
 
+                    invoiceInfo.put("subFileName", fileReuslt.getString("subFileName"));
                     invoiceInfo.put("snapshotUrl", fileReuslt.getString("snapshotUrl"));
                     invoiceInfo.put("imageUrl", fileReuslt.getString("imageUrl"));
                     invoiceInfo.put("ofdUrl", fileReuslt.getString("ofdUrl"));
@@ -374,32 +437,12 @@ public class RecognitionCheckServiceEx {
                     }
 
                     invoiceInfo.put("synConvert", fileReuslt.getString("synConvert"));
-                } else if (!StringUtils.isEmpty(updateFileUrl)) {
-                    path = FileUploadUtils.getSnapshotPathByUploadUrl(updateFileUrl);
-                    String imageUrl = path + ".jpg";
-                    if ("pdf".equals(updateFileType)) {
-                        invoiceInfo.put("pdfUrl", updateFileUrl);
-                        invoiceInfo.put("snapshotUrl", imageUrl);
-                        invoiceInfo.put("imageUrl", imageUrl);
-                        invoiceInfo.put("synConvert", true);
-                        invoiceInfo.put("fileType", "1");
-                        FileUploadAndSignTask.saveFileAws(new FileConvertResult(), updateFileUrl, "1");
-                    } else if ("ofd".equals(updateFileType)) {
-                        invoiceInfo.put("ofdUrl", updateFileUrl);
-                        invoiceInfo.put("pdfUrl", path + ".pdf");
-                        invoiceInfo.put("snapshotUrl", imageUrl);
-                        invoiceInfo.put("imageUrl", imageUrl);
-                        invoiceInfo.put("synConvert", true);
-                        invoiceInfo.put("fileType", "4");
-                        FileUploadAndSignTask.saveFileAws(new FileConvertResult(), updateFileUrl, "4");
-                    } else {
-                        invoiceInfo.put("snapshotUrl", updateFileUrl);
-                        invoiceInfo.put("imageUrl", updateFileUrl);
-                    }
+                } else {
+                    invoiceInfo.put("synConvert", true);
                 }
 
                 logger.info("获取文件处理结果等待时长{},{}", System.currentTimeMillis() - start, fileReuslt);
-                if (returnFirst) {
+                if (returnFirst && !InputInvoiceTypeEnum.HGJKS.getCode().equals(invoiceType)) {
                     JSONArray finalResult2 = new JSONArray();
                     invoiceInfo.put("originalState", "1");
                     finalResult2.add(invoiceInfo);
@@ -465,6 +508,7 @@ public class RecognitionCheckServiceEx {
             result.put("fileType", "2");
             result.put("imageUrl", fileFile.getFileUrl());
             result.put("snapshotUrl", fileFile.getFileUrl());
+            result.put("subFileName", fileFile.getFileName());
             return result;
         } else {
             try {
@@ -473,7 +517,11 @@ public class RecognitionCheckServiceEx {
 
                 try {
                     byte[] streamByte = FileUtils.getByte(fileInputStream);
-                    subUploadFuture = uploadThreadPool.submit(new FileUploadAndSignTask(fileFile.getFileUrl(), streamByte, fileFile.getFileType(), fileFile.getSignatureFlag(), context));
+                    if (StringUtils.isEmpty(fileFile.getFileHash())) {
+                        fileFile.setFileHash(FileConvertUtils.getSHA256(streamByte));
+                    }
+
+                    subUploadFuture = uploadThreadPool.submit(new FileUploadAndSignTask(fileFile.getFileUrl(), streamByte, fileFile.getFileName(), fileFile.getFileType(), fileFile.getFileHash(), fileFile.getSignatureFlag(), context));
                 } catch (Throwable var16) {
                     var6 = var16;
                     throw var16;
@@ -573,6 +621,12 @@ public class RecognitionCheckServiceEx {
 
                         this.invoiceCollectService.saveInvoice(invoiceInfo, fileUrl, fileHash);
                     } catch (Exception var28) {
+                        String errorMsg = ResManager.loadKDString("发票数据保存异常,请联系管理员", "RecognitionCheckService_0", "imc-rim-common", new Object[0]);
+                        if (var28 instanceof MsgException) {
+                            errorMsg = ((MsgException)var28).getErrorMsg();
+                        }
+
+                        invoiceInfo.put("errorMsg", errorMsg);
                         mayErrorResult.add(invoiceInfo);
                     }
 
@@ -580,7 +634,7 @@ public class RecognitionCheckServiceEx {
                     Map<String, String> configMap = ImcConfigUtil.getValue("rim_recog_check");
                     String isDealSaleList = (String)configMap.get("is_dealsalelist");
                     if ("1".equals(isSaleListInvoice) && !"0".equals(isDealSaleList)) {
-                        this.recognitionCheckHelper.dealInvoiceAttachRelation(invoiceInfo);
+                        this.RecognitionCheckHelperEx.dealInvoiceAttachRelation(invoiceInfo);
                     }
 
                     logger.info("发票助手本地上传保存发票后的数据:" + invoiceInfo);
@@ -659,6 +713,7 @@ public class RecognitionCheckServiceEx {
         if (businessParam != null) {
             isCheck = !"1".equals(businessParam.getString("notCheck"));
         }
+
         if (!isCheck) {
             businessParam.put("errcode", "4999");
             businessParam.put("description", CheckContant.getCheckResultDesc("4999"));

+ 867 - 0
src/main/java/kd/imc/rim/common/utils/FileUtilsEx.java

@@ -0,0 +1,867 @@
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by FernFlower decompiler)
+//
+
+package kd.imc.rim.common.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.MessageDigest;
+import java.sql.ResultSet;
+import java.util.Date;
+import kd.bos.cache.CacheFactory;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.db.DB;
+import kd.bos.db.DBRoute;
+import kd.bos.db.ResultSetHandler;
+import kd.bos.fileservice.FileService;
+import kd.bos.fileservice.FileServiceFactory;
+import kd.bos.logging.Log;
+import kd.bos.logging.LogFactory;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.QueryServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+public class FileUtilsEx {
+    private static Log logger = LogFactory.getLog(HttpUtil.class);
+    public static final String FILE_TYPE_PDF = "pdf";
+    public static final String FILE_TYPE_OFD = "ofd";
+    public static final String FILE_TYPE_JPG = "jpg";
+    public static final String FILE_TYPE_XML = "xml";
+    private static final String USER_DIR = "user.dir";
+    private static final String FILE_TEMP = "fileTemp";
+    public static final String BASE_UPLOAD_ABS_PATH;
+
+    public FileUtilsEx() {
+    }
+
+    public static boolean isImage(String fileType) {
+        return "png".equalsIgnoreCase(fileType) || "bmp".equalsIgnoreCase(fileType) || "jpg".equalsIgnoreCase(fileType) || "jpeg".equalsIgnoreCase(fileType) || "webp".equalsIgnoreCase(fileType);
+    }
+
+    public static String getSHA256(InputStream file) {
+        Object var2;
+        try {
+            MessageDigest MD5 = MessageDigest.getInstance("SHA-256");
+            byte[] buffer = new byte[8192];
+
+            int length;
+            while((length = file.read(buffer)) != -1) {
+                MD5.update(buffer, 0, length);
+            }
+
+            String var4 = new String(Hex.encodeHex(MD5.digest()));
+            return var4;
+        } catch (Exception var14) {
+            var2 = null;
+        } finally {
+            try {
+                if (file != null) {
+                    file.close();
+                }
+            } catch (IOException var13) {
+            }
+
+        }
+
+        return (String)var2;
+    }
+
+    public static String downLoadAndUpload(String fileUrl) {
+        return downLoadAndUpload(fileUrl, (String)null);
+    }
+
+    public static InputStream getInputStreamByGet(String url) throws ClientProtocolException, IOException {
+        return getInputStreamByGet(url, 60000, 60000);
+    }
+
+    private static InputStream getInputStreamByGet(String url, int connectionTimeout, int readTimeout) throws ClientProtocolException, IOException {
+        String proxy = HttpUtil.getProxy(url, (String)null);
+        CloseableHttpClient httpclient = HttpUtil.getConnection(proxy, false, connectionTimeout, readTimeout);
+        HttpGet httpGet = HttpUtil.getHttpGet(HttpUtil.replaceUrl(url));
+        CloseableHttpResponse response = httpclient.execute(httpGet);
+        return response.getEntity().getContent();
+    }
+
+    public static String downLoadAndUploadTemp(String fileUrl, String fileName) {
+        String tempSavePath = "";
+        if (!StringUtils.isEmpty(fileUrl) && fileUrl.indexOf("http") == 0) {
+            AwsFpyService service = AwsFpyService.newInstance();
+            HttpClient client = HttpUtil.getConnection(service.getProxy(), false);
+            HttpGet get = HttpUtil.getHttpGet(HttpUtil.replaceUrl(fileUrl));
+            CloseableHttpResponse response = null;
+
+            try {
+                long start = System.currentTimeMillis();
+                response = (CloseableHttpResponse)client.execute(get);
+                int statusCode = response.getStatusLine().getStatusCode();
+                if (200 == statusCode) {
+                    String fileType = "";
+                    fileType = getSuffixFromDisposition(response);
+                    if (StringUtils.isEmpty(fileType)) {
+                        fileType = getSuffixFromContentType(response);
+                    }
+
+                    HttpEntity entity = response.getEntity();
+                    if (StringUtils.isEmpty(fileName)) {
+                        fileName = UUID.randomUUIDZero() + '.' + fileType;
+                    } else if (fileName.indexOf(46) < 0) {
+                        fileName = fileName + '.' + fileType;
+                    }
+
+                    tempSavePath = CacheFactory.getCommonCacheFactory().getTempFileCache().saveAsUrl(fileName, entity.getContent(), 5000);
+                } else {
+                    if (302 == statusCode) {
+                        Header header = response.getFirstHeader("location");
+                        String newUrl = header.getValue();
+                        logger.info("重定向:" + newUrl);
+                        String var12 = downLoadAndUpload(newUrl, fileName);
+                        return var12;
+                    }
+
+                    logger.error(String.format("下载文件失败[%s]%s", statusCode, fileUrl));
+                }
+
+                logger.info(String.format("下载文件耗时[%s]%s", System.currentTimeMillis() - start, fileUrl));
+            } catch (IOException var28) {
+                logger.error("下载文件失败" + fileUrl, var28);
+            } finally {
+                if (response != null) {
+                    try {
+                        response.close();
+                    } catch (IOException var27) {
+                    }
+                }
+
+                try {
+                    get.abort();
+                    get.releaseConnection();
+                } catch (Exception var26) {
+                }
+
+            }
+
+            return tempSavePath;
+        } else {
+            return fileUrl;
+        }
+    }
+
+    public static String downLoadAndUpload(String fileUrl, String fileName) {
+        return (String)downLoadAndUpload(fileUrl, fileName, true, false);
+    }
+
+    public static JSONObject downLoadAndUploadWithFileType(String fileUrl, String fileName) {
+        return (JSONObject)downLoadAndUpload(fileUrl, fileName, true, true);
+    }
+
+    public static String downLoadAndUpload(String fileUrl, String fileName, boolean proxy) {
+        return (String)downLoadAndUpload(fileUrl, fileName, proxy, false);
+    }
+
+    public static Object downLoadAndUpload(String fileUrl, String fileName, boolean proxy, boolean needFileType) {
+        String tempSavePath = "";
+        String urlFileType = "";
+        if (!StringUtils.isEmpty(fileUrl) && fileUrl.indexOf("http") == 0) {
+            String fileId = MD5.md5Hex(fileUrl);
+            JSONObject pathAndType;
+            if (needFileType) {
+                pathAndType = queryFilePathAndType(fileId);
+                if (pathAndType != null) {
+                    return pathAndType;
+                }
+            } else {
+                String path = queryFilePath(fileId);
+                if (!StringUtils.isEmpty(path)) {
+                    return path;
+                }
+            }
+
+            pathAndType = null;
+            AwsFpyService service = AwsFpyService.newInstance();
+            CloseableHttpClient client;
+            if (proxy) {
+                client = HttpUtil.getConnection(service.getProxy(), false);
+            } else {
+                client = HttpUtil.getConnection((String)null, false);
+            }
+
+            HttpGet get = HttpUtil.getHttpGet(HttpUtil.replaceUrl(fileUrl));
+            CloseableHttpResponse response1 = null;
+            CloseableHttpResponse response302 = null;
+
+            try {
+                urlFileType = getFileType(fileUrl);
+                if (!StringUtils.isEmpty(urlFileType) && !"do".equals(urlFileType)) {
+                    fileName = UUID.randomUUIDZero() + '.' + urlFileType;
+                }
+
+                long start = System.currentTimeMillis();
+                response1 = (CloseableHttpResponse)client.execute(get);
+                int statusCode1 = response1.getStatusLine().getStatusCode();
+                if (200 == statusCode1) {
+                    Pair<String, String> pair = dealResponse(response1, fileName, fileUrl);
+                    tempSavePath = (String)pair.getLeft();
+                    if (StringUtils.isNotEmpty((String)pair.getRight())) {
+                        urlFileType = (String)pair.getRight();
+                    }
+                } else if (302 == statusCode1) {
+                    Header header = response1.getFirstHeader("location");
+                    String newUrl = header.getValue();
+                    logger.info("重定向:" + newUrl);
+                    if (StringUtils.isEmpty(fileName)) {
+                        urlFileType = getFileType(newUrl);
+                        if (!StringUtils.isEmpty(urlFileType)) {
+                            fileName = UUID.randomUUIDZero() + '.' + urlFileType;
+                        }
+                    }
+
+                    HttpGet newget = HttpUtil.getHttpGet(HttpUtil.replaceUrl(newUrl));
+                    response302 = (CloseableHttpResponse)client.execute(newget);
+                    int statusCode2 = response302.getStatusLine().getStatusCode();
+                    if (200 == statusCode2) {
+                        Pair<String, String> pair = dealResponse(response302, fileName, newUrl);
+                        tempSavePath = (String)pair.getLeft();
+                        if (StringUtils.isNotEmpty((String)pair.getRight())) {
+                            urlFileType = (String)pair.getRight();
+                        }
+                    } else {
+                        logger.error("下载文件失败302[{}]{}:{}", new Object[]{statusCode2, newUrl, JSON.toJSONString(response302)});
+                    }
+                } else {
+                    logger.error("下载文件失败[{}]{}:{}", new Object[]{statusCode1, fileUrl, JSON.toJSONString(response1)});
+                }
+
+                logger.info("下载文件耗时[{}]{}", System.currentTimeMillis() - start, fileUrl);
+            } catch (IOException var36) {
+                logger.error("下载文件失败" + fileUrl, var36);
+            } finally {
+                if (response1 != null) {
+                    try {
+                        response1.close();
+                    } catch (IOException var35) {
+                    }
+                }
+
+                if (response302 != null) {
+                    try {
+                        response302.close();
+                    } catch (IOException var34) {
+                    }
+                }
+
+                try {
+                    get.abort();
+                    get.releaseConnection();
+                } catch (Exception var33) {
+                }
+
+            }
+
+            if (!StringUtils.isEmpty(tempSavePath)) {
+                saveFilePath(fileUrl, tempSavePath, fileId, urlFileType);
+            }
+
+            if (needFileType) {
+                JSONObject result = new JSONObject();
+                result.put("file_url", tempSavePath);
+                result.put("file_type", urlFileType);
+                return result;
+            } else {
+                return tempSavePath;
+            }
+        } else if (needFileType) {
+            JSONObject result = new JSONObject();
+            result.put("file_url", fileUrl);
+            return result;
+        } else {
+            return fileUrl;
+        }
+    }
+
+    public static Pair<String, byte[]> downLoadFileToByte(String fileUrl, String fileName) {
+        return downLoadFileToByte(fileUrl, fileName, true);
+    }
+
+    public static Pair<String, byte[]> downLoadFileToByte(String fileUrl, String fileName, boolean proxy) {
+        logger.info("downLoadFileToByte,fileUrl:{}, fileName:{}", fileUrl, fileName);
+        if (!StringUtils.isEmpty(fileUrl) && fileUrl.indexOf("http") == 0) {
+            byte[] fileByte = null;
+            String urlFileType = "";
+            HttpClient client = null;
+            AwsFpyService service = AwsFpyService.newInstance();
+            if (proxy) {
+                client = HttpUtil.getConnection(service.getProxy(), false);
+            } else {
+                client = HttpUtil.getConnection((String)null, false);
+            }
+
+            HttpGet get = HttpUtil.getHttpGet(HttpUtil.replaceUrl(fileUrl));
+            CloseableHttpResponse response1 = null;
+            CloseableHttpResponse response302 = null;
+
+            try {
+                urlFileType = getFileType(fileUrl);
+                if (!StringUtils.isEmpty(urlFileType) && !"do".equals(urlFileType)) {
+                    fileName = UUID.randomUUIDZero() + '.' + urlFileType;
+                }
+
+                long start = System.currentTimeMillis();
+                response1 = (CloseableHttpResponse)client.execute(get);
+                int statusCode1 = response1.getStatusLine().getStatusCode();
+                if (200 == statusCode1) {
+                    HttpEntity entity1 = response1.getEntity();
+                    fileByte = getByte(entity1.getContent());
+                    if (StringUtils.isEmpty(urlFileType)) {
+                        urlFileType = getSuffixFromDisposition(response1);
+                    }
+                } else if (302 == statusCode1) {
+                    Header header = response1.getFirstHeader("location");
+                    String newUrl = header.getValue();
+                    logger.info("重定向:" + newUrl);
+                    if (StringUtils.isEmpty(fileName)) {
+                        urlFileType = getFileType(newUrl);
+                    }
+
+                    HttpGet newget = HttpUtil.getHttpGet(HttpUtil.replaceUrl(newUrl));
+                    response302 = (CloseableHttpResponse)client.execute(newget);
+                    int statusCode2 = response302.getStatusLine().getStatusCode();
+                    if (200 == statusCode2) {
+                        HttpEntity entity2 = response302.getEntity();
+                        fileByte = getByte(entity2.getContent());
+                        if (StringUtils.isEmpty(urlFileType)) {
+                            urlFileType = getSuffixFromDisposition(response302);
+                        }
+                    } else {
+                        logger.error("下载文件失败302[{}]{}:{}", new Object[]{statusCode2, newUrl, JSON.toJSONString(response302)});
+                    }
+                } else {
+                    logger.error("下载文件失败[{}]{}:{}", new Object[]{statusCode1, fileUrl, JSON.toJSONString(response1)});
+                }
+
+                logger.info("下载文件耗时[{}]{}", System.currentTimeMillis() - start, fileUrl);
+            } catch (IOException var34) {
+                logger.error("下载文件失败" + fileUrl, var34);
+            } finally {
+                if (response1 != null) {
+                    try {
+                        response1.close();
+                    } catch (IOException var33) {
+                    }
+                }
+
+                if (response302 != null) {
+                    try {
+                        response302.close();
+                    } catch (IOException var32) {
+                    }
+                }
+
+                try {
+                    get.abort();
+                    get.releaseConnection();
+                } catch (Exception var31) {
+                }
+
+            }
+
+            return Pair.of(urlFileType, fileByte);
+        } else {
+            return null;
+        }
+    }
+
+    private static Pair<String, String> dealResponse(CloseableHttpResponse response, String fileName, String fileUrl) throws UnsupportedOperationException, IOException {
+        String fileType = getSuffixFromDisposition(response);
+        if (StringUtils.isEmpty(fileType)) {
+            fileType = getSuffixFromContentType(response);
+            if ("ofd".equals(fileType)) {
+                String fileTypeFromName = getFileType(fileName);
+                if (!StringUtils.isEmpty(fileType)) {
+                    fileType = fileTypeFromName;
+                }
+            }
+        }
+
+        HttpEntity entity = response.getEntity();
+        if (StringUtils.isEmpty(fileName)) {
+            fileName = UUID.randomUUIDZero() + '.' + fileType;
+        } else if (fileName.indexOf(46) < 0) {
+            fileName = fileName + '.' + fileType;
+        }
+
+        if (StringUtils.isEmpty(fileType) && fileName.indexOf(46) < 0) {
+            logger.error("文件类型错误取消上传:" + fileUrl);
+            return Pair.of(((Object)null).toString(), fileType);
+        } else {
+            byte[] fileByte = getByte(entity.getContent());
+            ByteArrayInputStream bs = new ByteArrayInputStream(fileByte);
+            Throwable var7 = null;
+
+            Pair var9;
+            try {
+                String url = FileUploadUtils.upload(FileUploadUtils.getInvoiceDir("invoice") + fileName, fileName, bs);
+                var9 = Pair.of(url, fileType);
+            } catch (Throwable var18) {
+                var7 = var18;
+                throw var18;
+            } finally {
+                if (bs != null) {
+                    if (var7 != null) {
+                        try {
+                            bs.close();
+                        } catch (Throwable var17) {
+                            var7.addSuppressed(var17);
+                        }
+                    } else {
+                        bs.close();
+                    }
+                }
+
+            }
+
+            return var9;
+        }
+    }
+
+    public static void saveFilePath(String fileUrl, String attachPath, String fileId, String urlFileType) {
+        try {
+            DynamicObject downResult = BusinessDataServiceHelper.newDynamicObject("rim_download_file");
+            downResult.set("fileid", fileId);
+            downResult.set("http_url", fileUrl);
+            downResult.set("file_url", attachPath);
+            downResult.set("create_time", new Date());
+            downResult.set("file_type", convertFileType(urlFileType));
+            SaveServiceHelper.save(new DynamicObject[]{downResult});
+        } catch (Exception var5) {
+        }
+
+    }
+
+    public static String convertFileType(String fileType) {
+        logger.info("下载文件类型{}", fileType);
+        if (!"1".equals(fileType) && !"pdf".equals(fileType)) {
+            if (!"4".equals(fileType) && !"ofd".equals(fileType)) {
+                return !"9".equals(fileType) && !"xml".equals(fileType) ? "jpg" : "xml";
+            } else {
+                return "ofd";
+            }
+        } else {
+            return "pdf";
+        }
+    }
+
+    public static String convertFileTypeNum(String fileType) {
+        if (!"1".equals(fileType) && !"pdf".equals(fileType)) {
+            if (!"4".equals(fileType) && !"ofd".equals(fileType)) {
+                return !"9".equals(fileType) && !"xml".equals(fileType) ? "2" : "9";
+            } else {
+                return "4";
+            }
+        } else {
+            return "1";
+        }
+    }
+
+    public static String queryFilePath(String fileId) {
+        if (!StringUtils.isEmpty(fileId)) {
+            QFilter filter = new QFilter("fileid", "=", fileId);
+            DynamicObject obj = QueryServiceHelper.queryOne("rim_download_file", "id,file_url", new QFilter[]{filter});
+            if (obj != null && !StringUtils.isEmpty(obj.getString("file_url"))) {
+                return obj.getString("file_url");
+            }
+        }
+
+        return null;
+    }
+
+    public static JSONObject queryFilePathAndType(String fileId) {
+        if (!StringUtils.isEmpty(fileId)) {
+            JSONObject result = new JSONObject();
+            QFilter filter = new QFilter("fileid", "=", fileId);
+            DynamicObject obj = QueryServiceHelper.queryOne("rim_download_file", "id,file_url,file_type", new QFilter[]{filter});
+            if (obj != null && !StringUtils.isEmpty(obj.getString("file_url"))) {
+                result.put("file_url", obj.getString("file_url"));
+                result.put("file_type", obj.getString("file_type"));
+                return result;
+            }
+        }
+
+        return null;
+    }
+
+    private static String getSuffixFromDisposition(CloseableHttpResponse response) {
+        Header[] headers = response.getHeaders("Content-Disposition");
+        if (headers == null) {
+            headers = response.getHeaders("content-disposition");
+        }
+
+        if (headers != null) {
+            Header[] var2 = headers;
+            int var3 = headers.length;
+
+            for(int var4 = 0; var4 < var3; ++var4) {
+                Header header = var2[var4];
+                String value = header.getValue().replace("\"", "");
+                logger.info("getSuffixFromDisposition headervalue:{}", value);
+                int nameIndex = value.indexOf("filename");
+                if (nameIndex > 0 && value.length() > 10) {
+                    String fileName = value.substring(nameIndex + 10, value.length());
+                    fileName = fileName.replace(";", "");
+                    if (fileName.lastIndexOf(46) > 0) {
+                        return fileName.substring(fileName.lastIndexOf(46) + 1);
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    private static String getSuffixFromContentType(CloseableHttpResponse response) {
+        Header[] headers = response.getHeaders("Content-Type");
+        if (headers != null) {
+            Header[] var2 = headers;
+            int var3 = headers.length;
+
+            for(int var4 = 0; var4 < var3; ++var4) {
+                Header header = var2[var4];
+                if (header.getValue().indexOf("pdf") > 0) {
+                    return "pdf";
+                }
+
+                if (header.getValue().indexOf("octet") > 0) {
+                    return "ofd";
+                }
+
+                if (header.getValue().indexOf("image/png") >= 0) {
+                    return "png";
+                }
+
+                if (header.getValue().indexOf("image/gif") >= 0) {
+                    return "gif";
+                }
+
+                if (header.getValue().indexOf("image") >= 0) {
+                    return "jpg";
+                }
+            }
+        }
+
+        return null;
+    }
+
+    public static ByteArrayOutputStream cloneInputStream(InputStream input) {
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            byte[] buffer = new byte[1024];
+
+            int len;
+            while((len = input.read(buffer)) > -1) {
+                baos.write(buffer, 0, len);
+            }
+
+            baos.flush();
+            return baos;
+        } catch (IOException var4) {
+            logger.error("获取开票人异常:" + var4.getMessage(), var4);
+            return null;
+        }
+    }
+
+    public static boolean isExcel(String fileName) {
+        return checkFileType(fileName, "xls", "xlsx");
+    }
+
+    public static boolean checkFileType(String fileName, String... types) {
+        if (fileName != null && types != null && types.length >= 1) {
+            String fileType = getFileType(fileName);
+            if ("".equals(fileType)) {
+                return false;
+            } else {
+                String[] var3 = types;
+                int var4 = types.length;
+
+                for(int var5 = 0; var5 < var4; ++var5) {
+                    String str = var3[var5];
+                    if (fileType.equalsIgnoreCase(str)) {
+                        return true;
+                    }
+                }
+
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+
+    public static String getFileType(String fileName) {
+        try {
+            URL url = new URL(fileName);
+            return FilenameUtils.getExtension(url.getPath());
+        } catch (MalformedURLException var2) {
+            return FilenameUtils.getExtension(fileName);
+        }
+    }
+
+    public static String getRealPath(String fileId) {
+        if (StringUtils.isEmpty(fileId)) {
+            return "";
+        } else {
+            String path = "";
+
+            try {
+                String sql = "select fpath from t_bas_filepathmapping where FFILEID = ? ";
+                path = (String)DB.query(DBRoute.base, sql, new String[]{fileId}, new ResultSetHandler<String>() {
+                    public String handle(ResultSet rs) throws Exception {
+                        String path;
+                        for(path = ""; rs.next(); path = rs.getString("fpath")) {
+                        }
+
+                        return path;
+                    }
+                });
+            } catch (Exception var3) {
+                logger.info("查询真实地址失败:" + var3);
+            }
+
+            return path;
+        }
+    }
+
+    public static Pair<String, byte[]> getFileContent(String fileUrl) {
+        return getFileContent(fileUrl, Boolean.TRUE);
+    }
+
+    public static Pair<String, byte[]> getFileContent(String fileUrl, Boolean proxy) {
+        if (StringUtils.isEmpty(fileUrl)) {
+            return null;
+        } else if (fileUrl.indexOf("http") != 0) {
+            FileService service = FileServiceFactory.getAttachmentFileService();
+            if (service.exists(fileUrl)) {
+                String fileType = getFileType(fileUrl);
+                if (StringUtils.isEmpty(fileType)) {
+                    String path = getRealPath(fileUrl);
+                    fileType = getFileType(path);
+                }
+
+                return Pair.of(fileType, getByte(service.getInputStream(fileUrl)));
+            } else {
+                logger.info("文件不存在:" + fileUrl);
+                return null;
+            }
+        } else {
+            AwsFpyService service = AwsFpyService.newInstance();
+            HttpClient client = HttpUtil.getConnection(proxy ? service.getProxy() : null, false);
+            HttpGet get = HttpUtil.getHttpGet(HttpUtil.replaceUrl(fileUrl));
+            CloseableHttpResponse response = null;
+            CloseableHttpResponse response302 = null;
+
+            Pair var10;
+            try {
+                long start = System.currentTimeMillis();
+                response = (CloseableHttpResponse)client.execute(get);
+                int statusCode = response.getStatusLine().getStatusCode();
+                if (200 != statusCode) {
+                    if (302 == statusCode) {
+                        Header header = response.getFirstHeader("location");
+                        String newUrl = header.getValue();
+                        logger.info("重定向:" + newUrl);
+                        HttpGet get302 = HttpUtil.getHttpGet(HttpUtil.replaceUrl(newUrl));
+                        response302 = (CloseableHttpResponse)client.execute(get302);
+                        int statusCode302 = response302.getStatusLine().getStatusCode();
+                        if (200 == statusCode302) {
+                            Pair var14 = getContentFromResonse(fileUrl, response302);
+                            return var14;
+                        }
+
+                        logger.error(String.format("下载文件失败302[%s]%s:%s", statusCode, newUrl, JSON.toJSONString(response302)));
+                    }
+
+                    logger.info("下载文件耗时[{}]{},{}", new Object[]{System.currentTimeMillis() - start, statusCode, fileUrl});
+                    return null;
+                }
+
+                var10 = getContentFromResonse(fileUrl, response);
+            } catch (IOException var38) {
+                logger.error("下载文件失败" + fileUrl, var38);
+                return null;
+            } finally {
+                if (response != null) {
+                    try {
+                        response.close();
+                    } catch (IOException var37) {
+                    }
+                }
+
+                if (response302 != null) {
+                    try {
+                        response302.close();
+                    } catch (IOException var36) {
+                    }
+                }
+
+                try {
+                    get.abort();
+                    get.releaseConnection();
+                } catch (Exception var35) {
+                }
+
+            }
+
+            return var10;
+        }
+    }
+
+    private static Pair<String, byte[]> getContentFromResonse(String fileUrl, CloseableHttpResponse response) throws IOException {
+        String fileType = getSuffixFromDisposition(response);
+        if (StringUtils.isEmpty(fileType)) {
+            fileType = getSuffixFromContentType(response);
+            if ("ofd".equals(fileType)) {
+                fileType = getFileType(fileUrl);
+                if (StringUtils.isEmpty(fileType)) {
+                    fileType = "ofd";
+                }
+            }
+        }
+
+        HttpEntity entity = response.getEntity();
+        return Pair.of(fileType, getByte(entity.getContent()));
+    }
+
+    public static byte[] getAttachmentByte(String savePath) {
+        FileService service = FileServiceFactory.getAttachmentFileService();
+
+        try {
+            InputStream bos = service.getInputStream(savePath);
+            Throwable var3 = null;
+
+            byte[] var4;
+            try {
+                var4 = getByte(bos);
+            } catch (Throwable var14) {
+                var3 = var14;
+                throw var14;
+            } finally {
+                if (bos != null) {
+                    if (var3 != null) {
+                        try {
+                            bos.close();
+                        } catch (Throwable var13) {
+                            var3.addSuppressed(var13);
+                        }
+                    } else {
+                        bos.close();
+                    }
+                }
+
+            }
+
+            return var4;
+        } catch (IOException var16) {
+            return null;
+        }
+    }
+
+    public static byte[] getByte(InputStream inputStream) {
+        try {
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            Throwable var2 = null;
+
+            try {
+                byte[] buffer = new byte[1024];
+//                Boolean len = false;
+                int len;
+                while((len = inputStream.read(buffer)) != -1) {
+                    bos.write(buffer, 0, len);
+                }
+
+                byte[] var5 = bos.toByteArray();
+                return var5;
+            } catch (Throwable var15) {
+                var2 = var15;
+                throw var15;
+            } finally {
+                if (bos != null) {
+                    if (var2 != null) {
+                        try {
+                            bos.close();
+                        } catch (Throwable var14) {
+                            var2.addSuppressed(var14);
+                        }
+                    } else {
+                        bos.close();
+                    }
+                }
+
+            }
+        } catch (IOException var17) {
+            return null;
+        }
+    }
+
+    public static String encodeBase64File(InputStream inputFile) throws Exception {
+        if (inputFile == null) {
+            return null;
+        } else {
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            byte[] buffer = new byte[4096];
+//            int n = false;
+
+            int n;
+            while(-1 != (n = inputFile.read(buffer))) {
+                output.write(buffer, 0, n);
+            }
+
+            String retStr = Base64.encodeBase64String(output.toByteArray());
+            return retStr;
+        }
+    }
+
+    public static String truncateFileName(String fileName, int maxLength) {
+        if (StringUtils.isEmpty(fileName)) {
+            return fileName;
+        } else if (fileName.length() <= maxLength) {
+            return fileName;
+        } else {
+            int dotIndex = fileName.lastIndexOf(46);
+            String extension = "";
+            String nameWithoutExtension;
+            if (dotIndex != -1) {
+                nameWithoutExtension = fileName.substring(0, dotIndex);
+                extension = fileName.substring(dotIndex);
+            } else {
+                nameWithoutExtension = fileName;
+            }
+
+            int availableLength = maxLength - extension.length();
+            return availableLength <= 0 ? "" : nameWithoutExtension.substring(0, Math.min(availableLength, nameWithoutExtension.length())) + extension;
+        }
+    }
+
+    static {
+        BASE_UPLOAD_ABS_PATH = System.getProperty("user.dir") + File.separator + "fileTemp" + File.separator;
+    }
+}

+ 0 - 1
src/main/java/kd/imc/rim/formplugin/collector/InvoiceCollectPluginEx.java

@@ -13,7 +13,6 @@ import kd.bos.orm.util.CollectionUtils;
 import kd.bos.threads.ThreadPools;
 import kd.bos.util.StringUtils;
 import kd.imc.rim.common.constant.CollectTypeEnum;
-import kd.imc.rim.common.invoice.collector.InvoiceCollectTask;
 import kd.imc.rim.common.invoice.collector.InvoiceCollectTaskNew;
 import kd.imc.rim.common.service.DialogService;
 import kd.imc.rim.common.utils.BigDecimalUtil;