diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/GuaranteeConDateFormPlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/GuaranteeConDateFormPlugin.java index 5cd7fa3..69d461b 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/GuaranteeConDateFormPlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/GuaranteeConDateFormPlugin.java @@ -1,17 +1,19 @@ package shkd.sys.sys.plugin.form; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.LocaleString; import kd.bos.form.control.Button; import kd.bos.form.control.events.BeforeItemClickEvent; import kd.bos.form.events.AfterDoOperationEventArgs; import kd.bos.form.events.BeforeClosedEvent; +import kd.bos.form.field.ComboEdit; +import kd.bos.form.field.ComboItem; import kd.bos.form.plugin.AbstractFormPlugin; +import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.EventObject; -import java.util.HashMap; +import java.util.*; /** * @FileName GuaranteeConDateFormPlugin @@ -32,7 +34,7 @@ public class GuaranteeConDateFormPlugin extends AbstractFormPlugin { String enddateString = (String) end;//上次的结束日期 try { Date enddate = sdf.parse(enddateString); - Date quarterEndDate = getQuarterEndDate(enddate);//获取季末最后一天 + Date quarterEndDate = getQuarterEndDate(getNextDay(enddate));//获取季末最后一天 this.getModel().setValue("shkd_startdate", getNextDay(enddate)); this.getModel().setValue("shkd_enddate", quarterEndDate); } catch (ParseException ex) { @@ -78,6 +80,7 @@ public class GuaranteeConDateFormPlugin extends AbstractFormPlugin { if (operateKey.equals("do")) { Date shkd_startdate = (Date) this.getModel().getValue("shkd_startdate"); Date shkd_enddate = (Date) this.getModel().getValue("shkd_enddate"); + BigDecimal shkd_generalfeerate = (BigDecimal) this.getModel().getValue("shkd_generalfeerate"); // 指定日期格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 转换成字符串 @@ -85,6 +88,7 @@ public class GuaranteeConDateFormPlugin extends AbstractFormPlugin { String enddate = sdf.format(shkd_enddate); this.getPageCache().put("shkd_startdate", startdate); this.getPageCache().put("shkd_enddate", enddate); + this.getPageCache().put("shkd_jtfeerate", shkd_generalfeerate.toString()); this.getPageCache().put("btnok", "true"); } this.getView().close(); @@ -98,8 +102,10 @@ public class GuaranteeConDateFormPlugin extends AbstractFormPlugin { if ("true".equals(btnok)){ String shkd_startdate = this.getPageCache().get("shkd_startdate"); String shkd_enddate = this.getPageCache().get("shkd_enddate"); + String shkd_jtfeerate = this.getPageCache().get("shkd_jtfeerate"); map.put("shkd_startdate",shkd_startdate); map.put("shkd_enddate",shkd_enddate); + map.put("shkd_jtfeerate",shkd_jtfeerate); this.getView().returnDataToParent(map); }else { this.getView().returnDataToParent(null); @@ -109,8 +115,8 @@ public class GuaranteeConDateFormPlugin extends AbstractFormPlugin { /* - * 获取季末最后一天方法 - * */ + * 获取季末最后一天方法 + * */ public Date getQuarterEndDate(Date enddate) { // 使用 Calendar 来处理日期 Calendar calendar = Calendar.getInstance(); diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/GuaranteeContractFeeDetailPlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/GuaranteeContractFeeDetailPlugin.java index 21a5527..440a09d 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/GuaranteeContractFeeDetailPlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/GuaranteeContractFeeDetailPlugin.java @@ -6,14 +6,18 @@ import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.form.CloseCallBack; import kd.bos.form.FormShowParameter; import kd.bos.form.ShowType; +import kd.bos.form.events.AfterDoOperationEventArgs; import kd.bos.form.events.BeforeDoOperationEventArgs; import kd.bos.form.events.ClosedCallBackEvent; import kd.bos.form.operate.AbstractOperate; +import kd.bos.servicehelper.operation.SaveServiceHelper; import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -24,6 +28,8 @@ import java.util.stream.Collectors; **/ public class GuaranteeContractFeeDetailPlugin extends AbstractBillPlugIn { + public static final List entryop = Arrays.asList("newentryjt", "deleteentryjt","newentryyt","deleteentryyt"); + // 指定日期格式 private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); @@ -70,11 +76,19 @@ public class GuaranteeContractFeeDetailPlugin extends AbstractBillPlugIn { } } + @Override + public void afterDoOperation(AfterDoOperationEventArgs e) { + super.afterDoOperation(e); + String operateKey = e.getOperateKey(); + if (Arrays.asList("deleteentryjt","deleteentryyt").contains(operateKey)){ + SaveServiceHelper.save(new DynamicObject[]{this.getModel().getDataEntity(true)}); + } + } @Override public void closedCallBack(ClosedCallBackEvent e){ String actionId = e.getActionId(); - if ("jt".equals(actionId)){ + if ("jt".equals(actionId)){//计提 Object returnData = e.getReturnData(); if (returnData == null) return; System.out.println(returnData); @@ -86,7 +100,7 @@ public class GuaranteeContractFeeDetailPlugin extends AbstractBillPlugIn { .collect(Collectors.toList()); int index = this.getModel().createNewEntryRow("shkd_jtentry"); this.getModel().setValue("shkd_jtfeerate",this.getModel().getValue("generalfeerate"),index);//费率(%) - this.getModel().setValue("shkd_jtfeeamt", BigDecimal.valueOf(123),index);//费用金额 +// this.getModel().setValue("shkd_jtfeeamt", BigDecimal.valueOf(123),index);//费用金额 Date shkd_startdate; Date shkd_enddate; try { @@ -98,9 +112,14 @@ public class GuaranteeContractFeeDetailPlugin extends AbstractBillPlugIn { this.getModel().setValue("shkd_jtstartdate",shkd_startdate,index); this.getModel().setValue("shkd_jtenddate",shkd_enddate,index); this.getModel().setValue("shkd_jtfeepaydate",getNextDay(shkd_enddate),index); + String shkd_jtfeerate = (String) map.get("shkd_jtfeerate"); + BigDecimal fl = BigDecimal.valueOf(Double.parseDouble(shkd_jtfeerate)); + this.getModel().setValue("shkd_jtfeerate",fl,index);//费率 //计算金额 - - } else if ("yt".equals(actionId)) { + BigDecimal getbalance = getbalance(shkd_startdate, shkd_enddate, gstatus,fl); + this.getModel().setValue("shkd_jtcsfy",getbalance,index); + SaveServiceHelper.save(new DynamicObject[]{this.getModel().getDataEntity(true)}); + } else if ("yt".equals(actionId)) {//预提 Object returnData = e.getReturnData(); if (returnData == null) return; System.out.println(returnData); @@ -114,6 +133,44 @@ public class GuaranteeContractFeeDetailPlugin extends AbstractBillPlugIn { } } + private BigDecimal getbalance(Date shkd_startdate, Date shkd_enddate, List gstatus, BigDecimal fl) { + BigDecimal zero = BigDecimal.ZERO; + for (DynamicObject dynamicObject : gstatus) { + Date gdebtstartdate = dynamicObject.getDate("gdebtstartdate");//债务开始日期 + Date gdebtenddate = dynamicObject.getDate("gdebtenddate");//债务结束日期 + // 获取最大开始日期和最小结束日期 + Date overlapStartDate = (gdebtstartdate.after(shkd_startdate)) ? gdebtstartdate : shkd_startdate; + Date overlapEndDate = (gdebtenddate.before(shkd_enddate)) ? gdebtenddate : shkd_enddate; + long convert; + // 判断是否有重叠 + if (overlapStartDate.before(overlapEndDate)) { + // 计算重叠的天数 + long diffInMillis = overlapEndDate.getTime() - overlapStartDate.getTime(); + convert = TimeUnit.DAYS.convert(diffInMillis, TimeUnit.MILLISECONDS); + }else { + convert=0; + } + + //计算金额 责任金额(计息本金)*费率(利率)/360*计息天数 + BigDecimal flBigDecimal=fl.divide(BigDecimal.valueOf(100),6,RoundingMode.HALF_UP); + if (convert==0){ + continue; + }else { + BigDecimal gdebtbalance = dynamicObject.getBigDecimal("gdebtbalance"); + BigDecimal divide = (gdebtbalance.multiply(flBigDecimal)). + divide(BigDecimal.valueOf(360), 6, RoundingMode.HALF_UP). + multiply(BigDecimal.valueOf(convert)); + zero=zero.add(divide); + } + } + return zero; + + } + + + /* + * 获取第二天 + * */ public Date getNextDay(Date enddate) { // 使用 Calendar 来处理日期 Calendar calendar = Calendar.getInstance(); @@ -125,4 +182,12 @@ public class GuaranteeContractFeeDetailPlugin extends AbstractBillPlugIn { // 返回加一天后的日期 return calendar.getTime(); } + + /* + * 获取两个日期相差天数 + * */ + public static long calculateDebtDuration(Date gdebtstartdate, Date gdebtenddate) { + long diffInMillis = gdebtenddate.getTime() - gdebtstartdate.getTime(); + return TimeUnit.DAYS.convert(diffInMillis, TimeUnit.MILLISECONDS); + } }