From cfae1e292f1372265168f5bf1f2505140f652e07 Mon Sep 17 00:00:00 2001 From: zhangzhiguo <17621308561@163.com> Date: Wed, 27 Nov 2024 13:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E9=94=80=E8=B0=83=E6=95=B4=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fs/plugin/form/AnnualBudgetPlugin.java | 64 ++++ .../fs/plugin/form/DailyreimbursPlugin.java | 340 ++++++++++++++++++ .../ReimbursementCheckAttachmentPlugin.java | 43 +++ .../fs/plugin/form/UserHomeConfPlugin.java | 57 +++ .../fs/plugin/form/UserVisitSetPlugin.java | 52 +++ 5 files changed, 556 insertions(+) create mode 100644 code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/AnnualBudgetPlugin.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/DailyreimbursPlugin.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ReimbursementCheckAttachmentPlugin.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/UserHomeConfPlugin.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/UserVisitSetPlugin.java diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/AnnualBudgetPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/AnnualBudgetPlugin.java new file mode 100644 index 0000000..52a0ef7 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/AnnualBudgetPlugin.java @@ -0,0 +1,64 @@ +package zcgj.zcdev.zcdev.fs.plugin.form; + +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.bill.BillShowParameter; +import kd.bos.bill.OperationStatus; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.entity.datamodel.IDataModel; +import kd.bos.entity.operate.Save; +import kd.bos.entity.operate.Submit; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.sdk.plugin.Plugin; + +import java.text.SimpleDateFormat; + +/** + * 单据界面插件 + * 人员年度预算单界面插件 + */ +public class AnnualBudgetPlugin extends AbstractBillPlugIn implements Plugin { + + //开发商标识 + private static final String prefix ="zcgj"; + + @Override + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + Object source = args.getSource(); + if((args.getSource() instanceof Submit) || (args.getSource() instanceof Save)){ + String operateKey = null; + // 根据类型进行安全转换 + if (source instanceof Submit) { + operateKey = ((Submit) source).getOperateKey(); + } else if (source instanceof Save) { + operateKey = ((Save) source).getOperateKey(); + } + //重写返回的数据 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy"); + if("submit".equals(operateKey) || "save".equals(operateKey)){ + BillShowParameter bsp=(BillShowParameter)this.getView().getFormShowParameter(); + if(bsp.getStatus()== OperationStatus.ADDNEW){ + IDataModel model = this.getModel(); + Object year = model.getValue(prefix+"_year"); + DynamicObject user = (DynamicObject)model.getValue(prefix+"_user"); + long userId = user.getLong("id"); + QFilter[] filterArray = new QFilter[2]; + filterArray[0] = new QFilter(prefix+"_user", QCP.equals, userId); + filterArray[1] = new QFilter(prefix+"_year", QCP.equals, year); + DynamicObject[] logsToApprove = BusinessDataServiceHelper.load(prefix+"_annual_budget", "id",filterArray ); + if(logsToApprove!=null && logsToApprove.length>0){ + String formattedDate = dateFormat.format(year); + String message = String.format("当前员工%s年度预算已存在", formattedDate); + this.getView().showErrorNotification(message); + //取消提交操作 + args.setCancel(true); + } + } + } + } + super.beforeDoOperation(args); + } + +} \ No newline at end of file diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/DailyreimbursPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/DailyreimbursPlugin.java new file mode 100644 index 0000000..e83ffcf --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/DailyreimbursPlugin.java @@ -0,0 +1,340 @@ +package zcgj.zcdev.zcdev.fs.plugin.form; + +import kd.bos.algo.DataSet; +import kd.bos.algo.Row; +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.entity.datamodel.IDataModel; +import kd.bos.entity.operate.Submit; +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.QueryServiceHelper; +import kd.sdk.plugin.Plugin; +import zcgj.zcdev.zcdev.fs.plugin.task.WorkTask; + +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.Month; +import java.time.ZoneId; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAdjusters; +import java.util.Date; + +/** + * 费用报销单探亲检查插件 + */ +public class DailyreimbursPlugin extends AbstractBillPlugIn implements Plugin { + private static final Log log = LogFactory.getLog(DailyreimbursPlugin.class); + //开发商标识 + private static final String prefix ="zcgj"; + + @Override + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + try{ + if((args.getSource() instanceof Submit) ){ + Submit source = (Submit)args.getSource(); + if(source.getOperateKey().equals("submit") ){ + IDataModel model = this.getModel(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy"); + //报销人 + DynamicObject applier = (DynamicObject)this.getModel().getValue("applier"); + long applierId = applier.getLong("id"); + //获取休假开始时间 + Date startTime = (Date)model.getValue(prefix + "_holiday_start_time"); + Date endTime = (Date)model.getValue(prefix + "_holiday_end_time"); + //获取是否探亲 + //如果时探亲,则进行逻辑判断 + Boolean isVisit = (Boolean)model.getValue(prefix+"_is_visit"); + + if(isVisit){ + //探亲类型 1:探望父母,2:探望配偶 + String visitType = (String)model.getValue(prefix + "_visit_type"); + + //获取当前人的探亲假配置 + QFilter[] visitSetFilterArray = new QFilter[1]; + visitSetFilterArray[0] = new QFilter(prefix+"_user", QCP.equals, applierId); + DynamicObject dynamicObject = QueryServiceHelper.queryOne( prefix+"_user_visit_set", + "id,zcgj_visit_times as visitTime,zcgj_visit_days as visitDays,zcgj_married_status as marriedStatus," + + "zcgj_married_parents_year as marriedParentsYear,zcgj_married_parents_time as marriedParentsTime," + + "zcgj_married_spouse_year as marriedSpouseYear,zcgj_married_spouse_time as marriedSpouseTime," + + "zcgj_unmarried_parents_y as unmarriedParentsYear,zcgj_unmarried_parents_t as unmarriedParentsTime",visitSetFilterArray); + if(dynamicObject == null){ + this.getView().showErrorNotification("请设置人员探亲配置信息!"); + //取消提交操作 + args.setCancel(true); + return; + } + + //探亲次数 + int visitTime = 0; + //探亲年限 + int visitYear = 0; + + //总年探亲天数 + int visitDays =dynamicObject.getInt("visitDays"); + //婚姻状况,1:已婚,2:未婚 + int marriedStatus =dynamicObject.getInt("marriedStatus"); + //已婚探望父母年限 + int marriedParentsYear =dynamicObject.getInt("marriedParentsYear"); + //已婚探望父母次数 + int marriedParentsTime =dynamicObject.getInt("marriedParentsTime"); + //已婚探望配偶年限 + int marriedSpouseYear =dynamicObject.getInt("marriedSpouseYear"); + //已婚探望配偶次数 + int marriedSpouseTime =dynamicObject.getInt("marriedSpouseTime"); + //未婚探望父母年限 + int unmarriedParentsYear =dynamicObject.getInt("unmarriedParentsYear"); + //未婚探望父母次数 + int unmarriedParentsTime =dynamicObject.getInt("unmarriedParentsTime"); + + if(visitDays == 0 ){ + this.getView().showErrorNotification("人员探亲配置探亲假天数为空!"); + //取消提交操作 + args.setCancel(true); + return; + } + if(marriedStatus == 1 ){ // 已婚 + if(marriedParentsYear == 0 ){ + this.getView().showErrorNotification("人员探亲配置已婚探望父母年限为空!"); + //取消提交操作 + args.setCancel(true); + return; + } + if(marriedParentsTime == 0 ){ + this.getView().showErrorNotification("人员探亲配置已婚探望父母次数为空!"); + //取消提交操作 + args.setCancel(true); + return; + } + if(marriedSpouseYear == 0 ){ + this.getView().showErrorNotification("人员探亲配置已婚探望配偶年限为空!"); + //取消提交操作 + args.setCancel(true); + return; + } + if(marriedSpouseTime == 0 ){ + this.getView().showErrorNotification("人员探亲配置已婚探望配偶次数为空!"); + //取消提交操作 + args.setCancel(true); + return; + } + //如果是探望父母 + if("1".equals(visitType)){ + visitYear = marriedParentsYear; + visitTime = marriedParentsTime; + }else + //如果是探望配偶 + if("2".equals(visitType)){ + visitTime = marriedSpouseTime; + visitYear = marriedSpouseYear; + } + }else if (marriedStatus == 2) { // 未婚 + if(!"1".equals(visitType)){ + this.getView().showErrorNotification("未婚状态下探亲类型只能选择探望父母!"); + //取消提交操作 + args.setCancel(true); + return; + } + if(unmarriedParentsYear == 0 ){ + this.getView().showErrorNotification("人员探亲配置未婚探望父母年限为空!"); + //取消提交操作 + args.setCancel(true); + return; + } + if(unmarriedParentsTime == 0 ){ + this.getView().showErrorNotification("人员探亲配置未婚探望父母次数为空!"); + //取消提交操作 + args.setCancel(true); + return; + } + + visitTime = unmarriedParentsTime; + visitYear = unmarriedParentsYear; + } + + Date firstDayOfYear = getFirstDayOfYear(startTime); + //年限开始时间 + LocalDate firstDayYearsAgo = getFirstDayYearsAgo(dateToLocalDate(startTime), visitYear); + Date lastDayOfYear = getLastDayOfYear(startTime); + + // 查询条件 + QFilter[] filterArray = new QFilter[4]; + //查询申请人下的今年的探亲差旅单据 + filterArray[0] = new QFilter(prefix+"_holiday_start_time", QCP.large_equals, firstDayOfYear); + filterArray[1] = new QFilter(prefix+"_holiday_start_time", QCP.less_equals, lastDayOfYear); + filterArray[2] = new QFilter("applier", QCP.equals, applierId); + filterArray[3] = new QFilter(prefix+"_is_visit", QCP.equals, true); + DataSet dateSet = QueryServiceHelper.queryDataSet( + this.getClass().getName(), + "er_dailyreimbursebill", + "id,billno,zcgj_holiday_start_time as startTime,zcgj_holiday_end_time as endTime", + filterArray, null + ); + //使用请假总天数 + long allHolidayCount = 0; + //使用请假总次数 + int holidayCount = 0; + for (Row itemRow : dateSet) { + String string = itemRow.getString("billno"); + Date startTimeVal = itemRow.getDate("startTime"); + Date endTimeVal = itemRow.getDate("endTime"); + long dayCount = ChronoUnit.DAYS.between(dateToLocalDate(startTimeVal), dateToLocalDate(endTimeVal)); + allHolidayCount+=dayCount; + holidayCount++; + System.out.println(string); + } + //剩余次数 + int remainderTimes = visitTime-holidayCount; + //剩余天数 + long remainderDays = visitDays-allHolidayCount; + //判断剩余天数和本次请假天数 + long nowDays = ChronoUnit.DAYS.between(dateToLocalDate(startTime),dateToLocalDate(endTime))+1; + + String message = String.format("您在%s年到%s年中已用%d次探亲休假,剩余%d次探亲休假,已用%d天探亲天数,剩余%d天探亲天数。本次休假天数%d天。" + ,firstDayYearsAgo.getYear(),dateFormat.format(startTime),holidayCount,remainderTimes, + allHolidayCount,remainderDays,nowDays); + if((remainderTimes > 0) && (remainderDays >= 0) &&((remainderDays - nowDays) >=0)){ + this.getView().showTipNotification(message); + }else{ + this.getView().showErrorNotification("探亲次数或探亲天数不足!"+message); + //取消提交操作 + args.setCancel(true); + return; + } + } + //判断是否来往家居地 + Boolean isHome = (Boolean)model.getValue(prefix+"_is_home"); + if(isHome){ + //获取当前人的往来家居地配置 + QFilter[] visitSetFilterArray = new QFilter[1]; + visitSetFilterArray[0] = new QFilter(prefix+"_user", QCP.equals, applierId); + DataSet homeDataSet = QueryServiceHelper.queryDataSet( + this.getClass().getName(), + prefix+"_user_home_conf", + "id,zcgj_month_times as monthTime", + visitSetFilterArray, null + ); + Integer monthTime = null; + for (Row row : homeDataSet) { + monthTime = row.getInteger("monthTime"); + } + //获取申请日期 + Date bizdate = (Date)model.getValue( "bizdate"); + + //获取申请人在月份的单据量 + LocalDate firstDayOfMonth = getFirstDayOfMonth(bizdate); + LocalDate lastDayOfMonth = getLastDayOfMonth(bizdate); + QFilter[] filterArray = new QFilter[4]; + //查询申请人下的今年的探亲差旅单据 + filterArray[0] = new QFilter("bizdate", QCP.large_equals, firstDayOfMonth); + filterArray[1] = new QFilter("bizdate", QCP.less_equals, lastDayOfMonth); + filterArray[2] = new QFilter("applier", QCP.equals, applierId); + filterArray[3] = new QFilter(prefix+"_is_home", QCP.equals, true); + DataSet dateSet = QueryServiceHelper.queryDataSet( + this.getClass().getName(), + "er_dailyreimbursebill", + "id,billno,zcgj_holiday_start_time as startTime,zcgj_holiday_end_time as endTime,zcgj_is_home as ishome", + filterArray, null + ); + int goHomeCount = 0; + for (Row row : dateSet) { + Boolean ishome = row.getBoolean("ishome"); + System.out.println(row.getString("billno")); + if(ishome){ + goHomeCount++; + } + } + if(monthTime != null && monthTime != 0){ + int monthVal = firstDayOfMonth.getMonth().getValue(); + String message = String.format("请知悉:您每月共有%d次往来家居地报销次数,在%d月中已进行过%d次来往家居地报销。",monthTime,monthVal,goHomeCount); + //this.getView().showSuccessNotification(message); + this.getView().showTipNotification(message); + } + + } + } + } + + super.beforeDoOperation(args); + }catch (Exception e){ + log.error(e.getMessage()); + this.getView().showErrorNotification("系统异常"); + } + } + + + /** + * 将 java.util.Date 转换为 java.time.LocalDate + * @param date java.util.Date + * @return java.time.LocalDate + */ + public static LocalDate dateToLocalDate(Date date) { + if (date == null) { + throw new IllegalArgumentException("日期不能为 null"); + } + return date.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + } + + /** + * 获取指定日期所在年份的第一天 + * @param date java.util.Date + * @return java.util.Date + */ + public static Date getFirstDayOfYear(Date date) { + LocalDate localDate = dateToLocalDate(date); + LocalDate firstDayOfYear = LocalDate.of(localDate.getYear(), Month.JANUARY, 1); + return Date.from(firstDayOfYear.atStartOfDay(ZoneId.systemDefault()).toInstant()); + } + + /** + * 获取指定日期所在年份的最后一天 + * @param date java.util.Date + * @return java.util.Date + */ + public static Date getLastDayOfYear(Date date) { + LocalDate localDate = dateToLocalDate(date); + LocalDate lastDayOfYear = LocalDate.of(localDate.getYear(), Month.DECEMBER, 31); + return Date.from(lastDayOfYear.atStartOfDay(ZoneId.systemDefault()).toInstant()); + } + + /** + * 获取指定日期所在月份的第一天 + * @param date 指定日期 + * @return LocalDate 所在月份的第一天 + */ + public static LocalDate getFirstDayOfMonth(Date date) { + LocalDate localDate = dateToLocalDate(date); + return localDate.with(TemporalAdjusters.firstDayOfMonth()); + } + + /** + * 获取指定日期所在月份的最后一天 + * @param date 指定日期 + * @return LocalDate 所在月份的最后一天 + */ + public static LocalDate getLastDayOfMonth(Date date) { + LocalDate localDate = dateToLocalDate(date); + return localDate.with(TemporalAdjusters.lastDayOfMonth()); + } + + /** + * 获取指定年限-1年前的第一天 + * @param date 指定日期 + * @param years 年限值 + * @return LocalDate 年限-1年前的第一天 + */ + public static LocalDate getFirstDayYearsAgo(LocalDate date, int years) { + if (date == null) { + throw new IllegalArgumentException("日期不能为空"); + } + if (years < 1) { + throw new IllegalArgumentException("年限值必须大于等于 1"); + } + return LocalDate.of(date.getYear() - (years - 1), Month.JANUARY, 1); + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ReimbursementCheckAttachmentPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ReimbursementCheckAttachmentPlugin.java new file mode 100644 index 0000000..1c8e929 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/ReimbursementCheckAttachmentPlugin.java @@ -0,0 +1,43 @@ +package zcgj.zcdev.zcdev.fs.plugin.form; + +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.entity.datamodel.IDataModel; +import kd.bos.entity.operate.Submit; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.sdk.plugin.Plugin; + +import java.text.SimpleDateFormat; + +/** + * 报销单附件控制插件 + * 差旅报销、费用报销、对公报销 + */ +public class ReimbursementCheckAttachmentPlugin extends AbstractBillPlugIn implements Plugin { + + //开发商标识 + private static final String prefix ="zcgj"; + + @Override + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + //zcgj_attachmentcount + Object source = args.getSource(); + if(args.getSource() instanceof Submit){ + // 根据类型进行安全转换 + String operateKey = ((Submit) source).getOperateKey(); + //重写返回的数据 + if("submit".equals(operateKey)){ + //提交时校验附件是否必填 + IDataModel model = this.getModel(); + int attachmentcount = Integer.parseInt(model.getValue(prefix+"_attachmentcount")+""); + if(attachmentcount == 0){ + this.getView().showErrorNotification("请上传附件"); + //取消提交操作 + args.setCancel(true); + } + + } + } + super.beforeDoOperation(args); + } + +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/UserHomeConfPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/UserHomeConfPlugin.java new file mode 100644 index 0000000..f01dd6e --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/UserHomeConfPlugin.java @@ -0,0 +1,57 @@ +package zcgj.zcdev.zcdev.fs.plugin.form; + +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.bill.BillShowParameter; +import kd.bos.bill.OperationStatus; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.entity.datamodel.IDataModel; +import kd.bos.entity.operate.Save; +import kd.bos.entity.operate.Submit; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.sdk.plugin.Plugin; + +import java.text.SimpleDateFormat; + +/** + * 来往家居地配置界面插件 + */ +public class UserHomeConfPlugin extends AbstractBillPlugIn implements Plugin { + + //开发商标识 + private static final String prefix ="zcgj"; + + @Override + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + Object source = args.getSource(); + if((args.getSource() instanceof Submit) || (args.getSource() instanceof Save)){ + String operateKey = null; + // 根据类型进行安全转换 + if (source instanceof Submit) { + operateKey = ((Submit) source).getOperateKey(); + } else if (source instanceof Save) { + operateKey = ((Save) source).getOperateKey(); + } + //重写返回的数据 + if("submit".equals(operateKey) || "save".equals(operateKey)){ + BillShowParameter bsp=(BillShowParameter)this.getView().getFormShowParameter(); + if(bsp.getStatus()== OperationStatus.ADDNEW){ + IDataModel model = this.getModel(); + DynamicObject user = (DynamicObject)model.getValue(prefix+"_user"); + long userId = user.getLong("id"); + QFilter[] filterArray = new QFilter[1]; + filterArray[0] = new QFilter(prefix+"_user", QCP.equals, userId); + DynamicObject[] logsToApprove = BusinessDataServiceHelper.load(prefix+"_user_home_conf", "id",filterArray ); + if(logsToApprove!=null && logsToApprove.length>0){ + this.getView().showErrorNotification("当前员工的配置已存在"); + //取消提交操作 + args.setCancel(true); + } + } + } + } + super.beforeDoOperation(args); + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/UserVisitSetPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/UserVisitSetPlugin.java new file mode 100644 index 0000000..f11ae39 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/UserVisitSetPlugin.java @@ -0,0 +1,52 @@ +package zcgj.zcdev.zcdev.fs.plugin.form; + +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.bill.BillShowParameter; +import kd.bos.bill.OperationStatus; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.entity.operate.Save; +import kd.bos.entity.operate.Submit; +import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.sdk.plugin.Plugin; + +/** + * 人员探亲配置界面插件 + */ +public class UserVisitSetPlugin extends AbstractBillPlugIn implements Plugin { + //开发商标识 + private static final String prefix ="zcgj"; + + @Override + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + Object source = args.getSource(); + if((args.getSource() instanceof Submit) || (args.getSource() instanceof Save)){ + String operateKey = null; + // 根据类型进行安全转换 + if (source instanceof Submit) { + operateKey = ((Submit) source).getOperateKey(); + } else if (source instanceof Save) { + operateKey = ((Save) source).getOperateKey(); + } + if("submit".equals(operateKey) || "save".equals(operateKey)){ + BillShowParameter bsp=(BillShowParameter)this.getView().getFormShowParameter(); + if(bsp.getStatus()!=OperationStatus.ADDNEW){ + DynamicObject user = (DynamicObject)this.getModel().getValue(prefix+"_user"); + long userId = user.getLong("id"); + QFilter[] filterArray = new QFilter[1]; + filterArray[0] = new QFilter(prefix+"_user", QCP.equals, userId); + DynamicObject[] logsToApprove = BusinessDataServiceHelper.load(prefix+"_user_visit_set", "id",filterArray ); + if(logsToApprove!=null && logsToApprove.length>0){ + this.getView().showErrorNotification("无法添加,当前员工的配置信息已存在"); + //取消提交操作 + args.setCancel(true); + } + } + + } + } + super.beforeDoOperation(args); + } +}