From a86cb0d5102d4893f68ec061c5aab84205038125 Mon Sep 17 00:00:00 2001 From: chengyufei <1932574737@qq.com> Date: Wed, 19 Jul 2023 18:11:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=A2=84=E8=AE=A1?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E6=97=B6=E9=97=B41.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../task/controller/TaskController.java | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/task/controller/TaskController.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/task/controller/TaskController.java index f378790..6e8d9bf 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/task/controller/TaskController.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/task/controller/TaskController.java @@ -400,8 +400,9 @@ public class TaskController extends JeecgController { workTime += (millisecond / DAYTIME) * DAYWORKTIME; millisecond = millisecond % DAYTIME; - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); + SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm:ss"); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); String time = dateFormat.format(new Date()); String start = sdf1.format(startTime); @@ -481,6 +482,84 @@ public class TaskController extends JeecgController { } } + /** + * 计算预计结束时间 + * @param task + * @return + */ + @GetMapping("/estimateTime") + public Result calculating(Task task){ + if (task.getStartTime() == null || task.getExpectedDuration() == null) + return Result.error("参数不足,无法计算预计结束时间"); + Date date = null; + try { + date = estimateTime(task.getStartTime(), task.getExpectedDuration()); + } catch (ParseException e) { + throw new RuntimeException(e); + } + return Result.OK(date); + } + + /** + * 计算预计结束时间方法 + * @param startTime + * @param expectedDuration + * @return + */ + private Date estimateTime(Date startTime, Double expectedDuration) throws ParseException { + long millisecond = (long) (expectedDuration * 60 * 60 * 1000); + //整天偏移量 + int offset = (int) (millisecond / DAYWORKTIME); + //剩余工作量 + millisecond = millisecond % DAYWORKTIME; + + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + + String time = dateFormat.format(startTime); + String time1 = time + MORINGSTART; + String time2 = time + MORINGEND; + String time3 = time + AFTERNOONSTART; + String time4 = time + AFTERNOONEND; + Date date3 = sdf.parse(time3); + Date date2 = sdf.parse(time2); + Date date1 = sdf.parse(time1); + Date date4 = sdf.parse(time4); + + long tempTime = 0; + if (startTime.compareTo(date1) <= 0) + startTime = date1; //任务发布在8点半之前,修正时间 + if (startTime.compareTo(date2) < 0){ + //上午发布任务 + tempTime = date2.getTime() - startTime.getTime(); + if (tempTime >= millisecond) + return new Date(startTime.getTime() + millisecond + DAYTIME*offset); //预计上午结束,直接偏移剩余时间 + //上午剩余时间全部工作,时间进行修正到下午工作开始时间 + millisecond -= tempTime; + startTime = date3; + } + + if (startTime.compareTo(date3) <= 0) + startTime = date3; //任务是下午发布且在2点半之前,修正时间 + if (startTime.compareTo(date4) < 0){ + //下午发布任务 + tempTime = date4.getTime() - startTime.getTime(); + if (tempTime >= millisecond) + return new Date(startTime.getTime() + millisecond + DAYTIME*offset); + } + //时间修正,天数偏移量加1,到这里有两中情况,1、白天工作时间不足抵消 2、下午6点之后发布任务 + offset ++; + startTime = date1; + + tempTime = date2.getTime() - date1.getTime(); + if (tempTime >= millisecond) + return new Date(startTime.getTime() + millisecond + DAYTIME*offset); + //上午偏移不足,下午一定够,因为不会跨两天 + millisecond -= tempTime; + return new Date(startTime.getTime() + millisecond + DAYTIME*offset); + } + /** * 通过id删除 * From afde28d93dad86f1287a9c1eb4e2e14d91fca2a6 Mon Sep 17 00:00:00 2001 From: zjh <10930829+zheng-jinhao1209@user.noreply.gitee.com> Date: Wed, 19 Jul 2023 19:08:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AF=BC=E5=87=BAbug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/common/system/base/controller/JeecgController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java index 3834ef8..0821941 100644 --- a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java +++ b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java @@ -45,7 +45,7 @@ public class JeecgController> { S service; @Value("${jeecg.path.upload}") - private String upLoadPath; + protected String upLoadPath; /** * 导出excel @@ -154,7 +154,7 @@ public class JeecgController> { * * @return */ - private String getId(T item) { + protected String getId(T item) { try { return PropertyUtils.getProperty(item, "id").toString(); } catch (Exception e) {