wanghaiwu před 2 týdny
rodič
revize
2371565672

+ 159 - 0
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/form/ErDailyReimburseExtBotpUpPlugin.java

@@ -0,0 +1,159 @@
+package nckd.jimin.jyyy.fi.plugin.form;
+
+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.form.events.BeforeDoOperationEventArgs;
+import kd.bos.logging.Log;
+import kd.bos.logging.LogFactory;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.fi.er.business.utils.ErCommonUtils;
+import kd.fi.er.formplugin.botp.up.PublicReimburseBotpUpPlugin;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 对公报销单(nckd_er_publicreimbur_ext),处理上拉费用申请过滤问题
+ * @author wanghaiwu_kd
+ * @date 2025/06/19
+ */
+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) {
+        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");
+
+        DynamicObject item = (DynamicObject) this.getModel().getValue("nckd_expenseitem");
+
+        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");
+            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);
+                    }
+                }
+            }
+        } else {
+            super.beforeDoOperation(args);
+        }
+    }
+
+    @Override
+    protected Object getBillList(boolean includeApplierAndProjectOwer) {
+        Object billlists = super.getBillList(includeApplierAndProjectOwer);
+
+        List<Map<String, Object>> billlists1 = (List<Map<String, Object>>) billlists;
+        List<String> billNoList = new ArrayList<>();
+
+        String entityName = "";
+        for(Map<String, Object> map : billlists1){
+            entityName = (String)map.get("formtype");
+            billNoList.add((String)map.get("billno"));
+        }
+
+        if("er_dailyapplybill".equals(entityName)) {
+            DynamicObjectCollection collection = (DynamicObjectCollection)this.getModel().getValue("nckd_payviewtypemul");
+            List<Long> idList = (List)collection.stream().mapToLong((x) -> {
+                return x.getLong("fbasedataid_id");
+            }).boxed().collect(Collectors.toList());
+
+            QFilter viewTypeFilter = new QFilter("nckd_payviewtype.id", QCP.in, idList);
+
+            DynamicObject[] items = BusinessDataServiceHelper.load("er_expenseitemedit", "id", viewTypeFilter.toArray());
+
+            List<Long> itemIds = (List) Arrays.stream(items).map((o) -> {
+                return o.getLong("id");
+            }).collect(Collectors.toList());
+
+            QFilter qFilter = new QFilter("billno", QCP.in, billNoList);
+            String selectFileds = "billno, nckd_expenseitem, nckd_project, nckd_acctitem, nckd_isrelapj, nckd_payviewtypemul";
+
+            List<String> removeApplys = new ArrayList<>();
+            DynamicObject[] applys = BusinessDataServiceHelper.load(entityName, selectFileds, qFilter.toArray());
+            for(DynamicObject apply : applys){
+                boolean needRemove = false;
+
+                Long itemId = apply.getDynamicObject("nckd_expenseitem").getLong("id");
+
+                //过滤费用项目
+                if(!itemIds.contains(itemId)){
+                    needRemove = true;
+                }
+
+                //过滤项目/核算项目
+                if(checkproject){
+                    Long projectid = apply.getDynamicObject(filter_projectfield) == null ? 0L : apply.getDynamicObject(filter_projectfield).getLong("id");
+                    if( projectid.compareTo(filter_projectid) != 0) {
+                        needRemove = true;
+                    }
+                }
+
+                if(needRemove){
+                    removeApplys.add(apply.getString("billno"));
+                }
+            }
+
+            for(int i = billlists1.size()-1; i >= 0; i--){
+                Map<String, Object> map = billlists1.get(i);
+                String billno = (String)map.get("billno");
+
+                if(removeApplys.contains(billno)){
+                    ((List<?>) billlists).remove(i);
+                }
+            }
+        }
+
+
+        return billlists;
+    }
+}