wanghaiwu 2 долоо хоног өмнө
parent
commit
8caf87298c

+ 78 - 55
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/form/ErDailyReimburseExtBotpUpPlugin.java

@@ -26,68 +26,34 @@ import java.util.stream.Collectors;
  */
 public class ErDailyReimburseExtBotpUpPlugin extends PublicReimburseBotpUpPlugin {
     private static final Log log = LogFactory.getLog(ErDailyReimburseExtBotpUpPlugin.class);
-    private static boolean checkproject = false;
-    private static String filter_projectfield = "";
-    private static Long filter_projectid = 0L;
 
     public void beforeDoOperation(BeforeDoOperationEventArgs args) {
-
         Object source = args.getSource();
-
         String opKey = ((AbstractOperate)source).getOperateKey();
-        DynamicObject company = null;
-        if("addapplycheck".equals(opKey)) {
-            if (this.getControl("company") != null) {
-                company = (DynamicObject) this.getModel().getValue("company");
-            } else if (this.getView().getParentView().getControl("company") != null) {
-                company = (DynamicObject) this.getView().getParentView().getModel().getValue("company");
-            }
-            Long companyId = company == null ? null : (Long) company.getPkValue();
-            companyId = companyId != null ? companyId : RequestContext.get().getOrgId();
-            String controlproject = (String) ErCommonUtils.getEMParameter(companyId, "nckd_controlproject");
 
+        if("addapplycheck".equals(opKey)) {
             DynamicObject item = (DynamicObject) this.getModel().getValue("nckd_expenseitem");
+            String fieldKey = "";
 
             if (item == null) {
                 this.getView().showTipNotification(ResManager.loadKDString("请先选择费用类型。", "PublicReimburseBotpUpPlugin_0", "fi-er-formplugin", new Object[0]));
                 args.setCancel(true);
-            } else if ("1".equals(controlproject)) {
-                item = BusinessDataServiceHelper.loadSingle(item.getPkValue(), item.getDynamicObjectType().getName());
-
-                String isrelapjtype = item.getString("nckd_isrelapjtype");
+            } else if (checkProject(item, fieldKey)) {
+                //item = BusinessDataServiceHelper.loadSingle(item.getPkValue(), item.getDynamicObjectType().getName());
                 String pjtype = item.getString("nckd_pjtype");
-                String isrelapj = (String) this.getModel().getValue("nckd_isrelapj");
-
-                //必选
-                if ("1".equals(isrelapjtype) || ("2".equals(isrelapjtype) && "1".equals(isrelapj))) {
-                    //标准项目
-                    if ("project".equals(pjtype)) {
-                        if (this.getModel().getValue("nckd_project") == null) {
-                            this.getView().showTipNotification(ResManager.loadKDString("请先选择项目。", "PublicReimburseBotpUpPlugin_0", "fi-er-formplugin", new Object[0]));
-                            args.setCancel(true);
-                        } else {
-                            filter_projectfield = "nckd_project";
-                            filter_projectid = ((DynamicObject) this.getModel().getValue("nckd_project")).getLong("id");
-
-                            checkproject = true;
-
-                            super.beforeDoOperation(args);
-                        }
-                    }
-                    //核算项目
-                    else if ("acctitem".equals(pjtype)) {
-                        if (this.getModel().getValue("nckd_acctitem") == null) {
-                            this.getView().showTipNotification(ResManager.loadKDString("请先选择核算项目。", "PublicReimburseBotpUpPlugin_0", "fi-er-formplugin", new Object[0]));
-                            args.setCancel(true);
-                        } else {
-                            filter_projectfield = "nckd_acctitem";
-                            filter_projectid = ((DynamicObject) this.getModel().getValue("nckd_acctitem")).getLong("id");
-
-                            checkproject = true;
-
-                            super.beforeDoOperation(args);
-                        }
-                    }
+
+                //标准项目
+                if ("project".equals(pjtype)) {
+                    fieldKey = "nckd_project";
+                }
+                //核算项目
+                else if ("acctitem".equals(pjtype)) {
+                    fieldKey = "nckd_acctitem";
+                }
+
+                if (this.getModel().getValue(fieldKey) == null) {
+                    this.getView().showTipNotification(ResManager.loadKDString("请先选择项目。", "PublicReimburseBotpUpPlugin_0", "fi-er-formplugin", new Object[0]));
+                    args.setCancel(true);
                 } else {
                     super.beforeDoOperation(args);
                 }
@@ -99,6 +65,54 @@ public class ErDailyReimburseExtBotpUpPlugin extends PublicReimburseBotpUpPlugin
         }
     }
 
+    /**
+     * 判断是否需要校验项目/核算项目必填
+     * @return
+     */
+    private boolean checkProject(DynamicObject item, String fieldKey){
+        boolean needCheck = false;
+        DynamicObject company = null;
+        if (this.getControl("company") != null) {
+            company = (DynamicObject) this.getModel().getValue("company");
+        } else if (this.getView().getParentView().getControl("company") != null) {
+            company = (DynamicObject) this.getView().getParentView().getModel().getValue("company");
+        }
+        Long companyId = company == null ? null : (Long) company.getPkValue();
+        companyId = companyId != null ? companyId : RequestContext.get().getOrgId();
+        String controlproject = (String) ErCommonUtils.getEMParameter(companyId, "nckd_controlproject");
+
+        if("1".equals(controlproject)) {
+            item = BusinessDataServiceHelper.loadSingle(item.getPkValue(), item.getDynamicObjectType().getName());
+
+            String isrelapjtype = item.getString("nckd_isrelapjtype");
+            String pjtype = item.getString("nckd_pjtype");
+            String isrelapj = (String) this.getModel().getValue("nckd_isrelapj");
+
+            //必选
+            if ("1".equals(isrelapjtype) || ("2".equals(isrelapjtype) && "1".equals(isrelapj))) {
+                needCheck = true;
+
+                //标准项目
+                if ("project".equals(pjtype)) {
+                    fieldKey = "nckd_project";
+                }
+                //核算项目
+                else if ("acctitem".equals(pjtype)) {
+                    fieldKey = "nckd_acctitem";
+                }
+            }
+        }
+
+        log.info("needCheck:" + needCheck);
+
+        return needCheck;
+    }
+
+    /**
+     *
+     * @param includeApplierAndProjectOwer
+     * @return
+     */
     @Override
     protected Object getBillList(boolean includeApplierAndProjectOwer) {
         Object billlists = super.getBillList(includeApplierAndProjectOwer);
@@ -133,7 +147,15 @@ public class ErDailyReimburseExtBotpUpPlugin extends PublicReimburseBotpUpPlugin
             DynamicObject[] applys = BusinessDataServiceHelper.load(entityName, selectFileds, qFilter.toArray());
 
             log.info("itemIds:" + itemIds.toString());
-            log.info("checkproject:" + checkproject);
+
+            DynamicObject item = (DynamicObject) this.getModel().getValue("nckd_expenseitem");
+            String fieldKey = "";
+            boolean checkProject = checkProject(item, fieldKey);
+            Long curProjectId = 0L;
+            if(checkProject) {
+                curProjectId = ((DynamicObject) this.getModel().getValue(fieldKey)).getLong("id");
+            }
+
             for(DynamicObject apply : applys){
                 boolean needRemove = false;
 
@@ -147,9 +169,10 @@ public class ErDailyReimburseExtBotpUpPlugin extends PublicReimburseBotpUpPlugin
                 }
 
                 //过滤项目/核算项目
-                if(checkproject){
-                    Long projectid = apply.getDynamicObject(filter_projectfield) == null ? 0L : apply.getDynamicObject(filter_projectfield).getLong("id");
-                    if( projectid.compareTo(filter_projectid) != 0) {
+                if(checkProject){
+                    Long projectid = apply.getDynamicObject(fieldKey) == null ? 0L : apply.getDynamicObject(fieldKey).getLong("id");
+
+                    if( projectid > 0 && curProjectId > 0 && projectid.compareTo(curProjectId) != 0) {
                         needRemove = true;
                     }
                 }