From 864353f2303ffb89c72b7bbc0a0a2552c2e7c8ed Mon Sep 17 00:00:00 2001 From: zengweihai Date: Sat, 30 Nov 2024 14:33:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E5=AF=9F=E6=B1=87=E6=80=BB=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formplugin/DynamicExamPageFormPlugin.java | 262 ++++++++++++++++++ .../listplugin/ExamTaskSummaryListPlugin.java | 137 +++++++++ 2 files changed, 399 insertions(+) create mode 100644 main/java/shkd/repc/resm/formplugin/DynamicExamPageFormPlugin.java create mode 100644 main/java/shkd/repc/resm/listplugin/ExamTaskSummaryListPlugin.java diff --git a/main/java/shkd/repc/resm/formplugin/DynamicExamPageFormPlugin.java b/main/java/shkd/repc/resm/formplugin/DynamicExamPageFormPlugin.java new file mode 100644 index 0000000..f63bd79 --- /dev/null +++ b/main/java/shkd/repc/resm/formplugin/DynamicExamPageFormPlugin.java @@ -0,0 +1,262 @@ +package shkd.repc.resm.formplugin; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.entity.LocaleString; +import kd.bos.entity.EntryType; +import kd.bos.entity.MainEntityType; +import kd.bos.entity.datamodel.events.GetEntityTypeEventArgs; +import kd.bos.entity.property.IntegerProp; +import kd.bos.entity.property.TextProp; +import kd.bos.exception.ErrorCode; +import kd.bos.exception.KDException; +import kd.bos.form.FormShowParameter; +import kd.bos.form.control.Control; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.events.LoadCustomControlMetasArgs; +import kd.bos.form.events.OnGetControlArgs; +import kd.bos.form.field.IntegerEdit; +import kd.bos.form.field.TextEdit; +import kd.bos.form.plugin.AbstractFormPlugin; +import kd.bos.isc.util.misc.Hash; +import kd.bos.metadata.entity.commonfield.IntegerField; +import kd.bos.metadata.entity.commonfield.TextField; +import kd.bos.metadata.form.control.EntryAp; +import kd.bos.metadata.form.control.EntryFieldAp; +import kd.sdk.plugin.Plugin; + +import java.math.BigDecimal; +import java.util.*; + +/** + * 动态考察汇总表单插件 + */ +public class DynamicExamPageFormPlugin extends AbstractFormPlugin implements Plugin { + + + + + HashMap supOfUserGrade;//供应商对应人员评分 + HashMap userNames;//人员及属性集合 + + /** + * todo 1: + * 向前端浏览器界面发送指令,输出动态控件的元数据,从而实现控件能展示的效果 + * 加载显示单据控件,能显示元数据,对应的数据模型没有与之进行绑定 + * + * @param e + */ + @Override + public void loadCustomControlMetas(LoadCustomControlMetasArgs e) { + super.loadCustomControlMetas(e); + //获取单据传参 + FormShowParameter formShowParameter = (FormShowParameter) e.getSource(); + if (null != formShowParameter) { + Map customParams = formShowParameter.getCustomParams(); + supOfUserGrade = (HashMap) customParams.get("supOfUserGrade"); + userNames = (HashMap) customParams.get("userNames"); + } + + EntryAp dynamicEntryAp = this.createDynamicEntryAp(); + Map mapEntry = new HashMap(); + mapEntry.put("id", "qeug_entryentity");//映射单据中的单据体 + mapEntry.put("columns", dynamicEntryAp.createControl().get("columns")); + e.getItems().add(mapEntry); + } + + /** + * todo 2: + * 向界面主实体模型,动态注册新的属性对象,存储动态添加的字段值,从而达到控件能赋值的目的,能根据标识来进行赋值了,而不会报空指针的错误 + * + * @param e + */ + @Override + public void getEntityType(GetEntityTypeEventArgs e) { + super.getEntityType(e); + MainEntityType oldMainType = e.getOriginalEntityType();//取原始的主实体 + //复制主实体 + MainEntityType newMainType = null; + try { + newMainType = (MainEntityType) oldMainType.clone(); + } catch (CloneNotSupportedException exp) { + throw new KDException(exp, new ErrorCode("LoadCustomControlMetasSample", exp.getMessage())); + } + //获取单据传参 + FormShowParameter formShowParameter = this.getView().getFormShowParameter(); + if (null != formShowParameter) { + supOfUserGrade = new HashMap(); + userNames = new HashMap(); + Map customParams = formShowParameter.getCustomParams(); + JSONObject supOfUserGrade_json = (JSONObject) customParams.get("supOfUserGrade"); + for (String key : supOfUserGrade_json.keySet()) { + JSONObject userByGrade = (JSONObject) supOfUserGrade_json.get(key);//获取人员对应成绩集合 + HashMap userGraderMap = new HashMap<>(); + for (String userName : userByGrade.keySet()) { + BigDecimal grade = (BigDecimal) userByGrade.get(userName); + userGraderMap.put(userName,grade); + } + supOfUserGrade.put(key,userGraderMap); + + } + JSONObject userNameColl = (JSONObject) customParams.get("userNames"); + for (String userName : userNameColl.keySet()) { + HashMap userPropertyMap = new HashMap<>(); + JSONObject userProperty = (JSONObject) userNameColl.get(userName); + for (String propertyName : userProperty.keySet()) { + String content = (String) userProperty.get(propertyName); + userPropertyMap.put(propertyName,content); + } + userNames.put(userName,userPropertyMap); + } + } + //为自定义的单据体字段,向主实体注册相应数据 + this.registerDynamicProps(newMainType); + //回传给主实体 + e.setNewEntityType(newMainType); + } + + /** + * todo 3:向后台视图模型,输出动态控件的编程模型实例,并侦听控件的事件 + * + * @param e + */ + @Override + public void onGetControl(OnGetControlArgs e) { + super.onGetControl(e); + String key = e.getKey(); + if (key.startsWith("qeug_supplier")){ + TextEdit textEdit = new TextEdit(); + textEdit.setKey(key);//设置字段标识 + textEdit.setEntryKey("qeug_entryentity");//设置分录标识 + textEdit.setView(this.getView());//设置视图 + e.setControl(textEdit); + } else if (key.startsWith("grade_")) { + IntegerEdit decimalEdit = new IntegerEdit(); + decimalEdit.setKey(key); + decimalEdit.setEntryKey("qeug_entryentity"); + decimalEdit.setView(this.getView());//设置视图 + e.setControl(decimalEdit); + } + } + + + /** + * todo 4:是向后台视图模型,添加动态字段的控件编辑模型,后台赋值后需要展示到前端表单上,目的是控件值能显示 + * + * @param e + */ + @Override + public void beforeBindData(EventObject e) { + super.beforeBindData(e); + EntryAp dynamicEntryAp = this.createDynamicEntryAp(); + EntryGrid qeug_entryentity = this.getView().getControl("qeug_entryentity"); + List items = dynamicEntryAp.buildRuntimeControl().getItems(); + for (Control item : items) { + item.setView(this.getView()); + qeug_entryentity.getItems().add(item); + } + } + + /** + * 页面加载完毕后渲染页面数据 + * @param e + */ + @Override + public void afterBindData(EventObject e) { + super.afterBindData(e); + DynamicObjectCollection qeug_entryentity = this.getModel().getEntryEntity("qeug_entryentity"); + for (Object key : supOfUserGrade.keySet()) { + DynamicObject addNew = qeug_entryentity.addNew(); + //供应商名称赋值 + addNew.set("qeug_supplier",key); + HashMap userGrades = (HashMap) supOfUserGrade.get(key);//人员对象对应考察得分 + for (String userName : userGrades.keySet()) { + BigDecimal grade = userGrades.get(userName); + addNew.set("grade_"+userName,grade); + } + } + this.getView().updateView("qeug_entryentity"); + } + + + /** + * 动态加载考察汇总单据体控件 + * @return + */ + public EntryAp createDynamicEntryAp() { + EntryAp entryAp = new EntryAp(); + entryAp.setKey("entryAp"); + entryAp.setShowSeq(true); + + this.createSupplierNameFileAp(entryAp); + this.createUserNamesFileAp(entryAp); + return entryAp; + } + + /** + *加载该供应商名称单据体字段控件 + * @param entryAp + */ + public void createSupplierNameFileAp(EntryAp entryAp) { + EntryFieldAp apMat = new EntryFieldAp(); + apMat.setId("qeug_supplier"); + apMat.setKey("qeug_supplier"); + apMat.setName(new LocaleString("供应商")); + apMat.setLock("new,edit,view,submit,audit");//设置锁定性 + TextField textField = new TextField(); + textField.setId("qeug_supplier"); + textField.setKey("qeug_supplier"); + apMat.setField(textField); + entryAp.getItems().add(apMat); + } + + public void createUserNamesFileAp(EntryAp entryAp) { + for (Object key : userNames.keySet()) { + HashMap value = (HashMap) userNames.get(key); + EntryFieldAp apMat = new EntryFieldAp(); + String username = value.get("username"); + String name = value.get("name"); + apMat.setId("grade_"+username); + apMat.setKey("grade_"+username); + apMat.setName(new LocaleString(name)); + apMat.setLock("new,edit,view,submit,audit");//设置锁定性 + IntegerField integerField = new IntegerField(); + integerField.setScale(2); + integerField.setZeroShow(true); + apMat.setField(integerField); + entryAp.getItems().add(apMat); + } + } + + public void registerDynamicProps(MainEntityType newMainType){ + //获取当前单据体实体 + EntryType entryType = (EntryType) newMainType.getAllEntities().get("qeug_entryentity");//单据体标识 + this.createSupplierNameProps(entryType); + this.createUserNamesProps(entryType); + } + + public void createSupplierNameProps(EntryType entryType) { + TextProp textProp = new TextProp(); + textProp.setName("qeug_supplier");//字段标识 + textProp.setDisplayName(new LocaleString("供应商")); + textProp.setDbIgnore(true); + entryType.registerSimpleProperty(textProp); + } + public void createUserNamesProps(EntryType entryType) { + for (Object key : userNames.keySet()) { + HashMap value = (HashMap)userNames.get(key); + String username = value.get("username"); + String name = value.get("name"); + IntegerProp integerProp = new IntegerProp(); + integerProp.setName("grade_"+username); + integerProp.setDisplayName(new LocaleString(name));//标题 + integerProp.setScale(2); + integerProp.setZeroShow(true); + entryType.registerSimpleProperty(integerProp); + } + } + + +} \ No newline at end of file diff --git a/main/java/shkd/repc/resm/listplugin/ExamTaskSummaryListPlugin.java b/main/java/shkd/repc/resm/listplugin/ExamTaskSummaryListPlugin.java new file mode 100644 index 0000000..3d10fdb --- /dev/null +++ b/main/java/shkd/repc/resm/listplugin/ExamTaskSummaryListPlugin.java @@ -0,0 +1,137 @@ +package shkd.repc.resm.listplugin; + +import com.alibaba.fastjson.JSONArray; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.datamodel.ListSelectedRowCollection; +import kd.bos.form.FormShowParameter; +import kd.bos.form.ShowType; +import kd.bos.form.StyleCss; +import kd.bos.form.events.AfterDoOperationEventArgs; +import kd.bos.isc.util.misc.Hash; +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.botp.BFTrackerServiceHelper; +import kd.sdk.plugin.Plugin; +import kd.tmc.tm.business.validate.business.BusinessUnauditOpValidator; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +/** + * 标准单据列表插件 + */ +public class ExamTaskSummaryListPlugin extends AbstractListPlugin implements Plugin { + + @Override + public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) { + super.afterDoOperation(afterDoOperationEventArgs); + String operateKey = afterDoOperationEventArgs.getOperateKey(); + if ("viewsummary".equals(operateKey)){ + ListSelectedRowCollection selectedRows = getSelectedRows(); + if (selectedRows.size() > 1){ + this.getView().showTipNotification("只能选择一条数据查看项目汇总"); + }else { + String projectName = ""; + Object primaryKeyValue = selectedRows.get(0).getPrimaryKeyValue();//获取当前考察结果主键 + DynamicObject resm_examtask_summary = BusinessDataServiceHelper.loadSingle(primaryKeyValue, "resm_examtask_summary"); + DynamicObject evaltask = resm_examtask_summary.getDynamicObject("evaltask"); + long evalTaskId = evaltask.getLong("id"); + QFilter qFilter = new QFilter("plandetails.evaltask.id", QCP.equals, evalTaskId); + DynamicObject examPlan = BusinessDataServiceHelper.loadSingle("resm_investigationplan", qFilter.toArray()); + DynamicObject qeug_project = examPlan.getDynamicObject("qeug_project");//考察计划的项目 + if (qeug_project != null){ + projectName = qeug_project.getString("name"); + } + DynamicObjectCollection plandetails = examPlan.getDynamicObjectCollection("plandetails");//计划详情-分为多个考察任务 + HashMap> supOfUserGrade = new HashMap>();//供应商对应人员评分:key为供应商名称,value为对应供应商考察成绩情况 + HashMap> userNames = new HashMap>();//人员及属性集合:用于构建单据字段 + for (DynamicObject plandetail : plandetails) {//循环多条考察任务 + String suppliersource = plandetail.getString("suppliersource");//供应商来源:区分正式供应商和潜在供应商 + HashSet userNamesNow = new HashSet();//当前任务人员主键集合 + ArrayList userDys = new ArrayList<>();//当前任务人员对象集合:存放当前考察任务对应的考察人员对象 + DynamicObject suppliername = plandetail.getDynamicObject("suppliername");//供应商对象 + Object sup_pkValue = suppliername.getPkValue();//供应商主键 + String supName = suppliername.getString("name"); + DynamicObject evaltask_l = plandetail.getDynamicObject("evaltask");//考察任务 + long evaltask_lPk = evaltask_l.getLong("id");//考察任务主键 + DynamicObject resm_exam_task = BusinessDataServiceHelper.loadSingle(evaltask_lPk, "resm_exam_task");//完整考察任务数据 + String evaloObject = resm_exam_task.getString("evalobject");//考察对象:区分角色或者人员 + boolean isRoleEval = StringUtils.equals("roleeval", evaloObject); + DynamicObjectCollection entry_evaldetail = resm_exam_task.getDynamicObjectCollection("entry_evaldetail"); + DynamicObject evalDetailRow = entry_evaldetail.get(0); + //todo:查询对应任务人员权重配置 + DynamicObject myEval = BusinessDataServiceHelper.loadSingle("resm_evaluator", "evalentryid,entry_evaluator.user,entry_evaluator.role", new QFilter[]{new QFilter("evalentryid", "=", String.valueOf(evalDetailRow.getPkValue()))}); + if (myEval != null) { + DynamicObjectCollection entryentity = myEval.getDynamicObjectCollection("entry_evaluator"); + for(int k = 0; k < entryentity.size(); k++) { + DynamicObject evaluatorEntryRow = (DynamicObject)entryentity.get(k); + if (isRoleEval) { +// evaluatorSet.add((Long)evaluatorEntryRow.getDynamicObject("role").getPkValue()); +// evaluatorTempSet.add((Long)evaluatorEntryRow.getDynamicObject("role").getPkValue()); + } else { + Long userPk = (Long) evaluatorEntryRow.getDynamicObject("user").getPkValue(); + DynamicObject bos_user = BusinessDataServiceHelper.loadSingle(userPk, "bos_user"); + if (bos_user != null){ + String name = bos_user.getString("name"); + String username = bos_user.getString("username"); + HashMap userProperty = new HashMap<>(); + userProperty.put("name",name); + userProperty.put("username",username); + userNames.put(username,userProperty);//添加进入人员属性中 + userNamesNow.add(userPk);//添加进入当前人员主键集合 + userDys.add(bos_user);//添加进入当前人员对象集合 + } + } + } + } + QFilter myexam_QF = new QFilter("evaltask.id",QCP.equals,evaltask_lPk);//考察任务id + myexam_QF.and("creator.id",QCP.in,userNamesNow);//当前考察人 + if ("resm_regsupplier".equals(suppliersource)){//潜在供应商 + myexam_QF.and("evalsupplier.id",QCP.equals,sup_pkValue); + }else {//正式供应商 + myexam_QF.and("evaloffsupplier.id",QCP.equals,sup_pkValue); + } + //查询出该考察任务关联的我的考察 + DynamicObject[] resm_myexams = BusinessDataServiceHelper.load("resm_myexam", "creator,evalscore", myexam_QF.toArray()); + //todo:开始构建供应商对应人员评分 + HashMap userGrades = new HashMap();//人员成绩:key为人员用户名,value为人员分数 + if (resm_myexams.length > 0){ + for (DynamicObject resm_myexam : resm_myexams) { + DynamicObject creator = resm_myexam.getDynamicObject("creator");//当前考察人 + BigDecimal evalscore = resm_myexam.getBigDecimal("evalscore");//考察得分 + String username = creator.getString("username");//人员用户名 + userGrades.put(username,evalscore); + } + }else { + //我的考察还未下达时,先赋值0; + for (DynamicObject userDy : userDys) { + String username = userDy.getString("username"); + userGrades.put(username,BigDecimal.ZERO); + } + } + supOfUserGrade.put(supName,userGrades); + } + //todo: 构建传参 + FormShowParameter formShowParameter = new FormShowParameter(); + formShowParameter.setFormId("qeug_dynamicexampage"); + formShowParameter.setCaption(projectName+"供应商评分汇总表"); + formShowParameter.setCustomParam("supOfUserGrade",supOfUserGrade); + formShowParameter.setCustomParam("userNames",userNames); + formShowParameter.getOpenStyle().setShowType(ShowType.Modal); +// StyleCss inlineStyleCss = new StyleCss(); +// inlineStyleCss.setHeight("600"); +// inlineStyleCss.setWidth("1000"); +// formShowParameter.getOpenStyle().setInlineStyleCss(inlineStyleCss); + getView().showForm(formShowParameter); + + } + } + } +} \ No newline at end of file