任务模块

dev_4newlayout
shiji 1 year ago
parent 7f99b77244
commit ceecd86aa3
  1. 54
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/task/controller/TaskController.java

@ -61,13 +61,13 @@ public class TaskController extends JeecgController<Task, ITaskService> {
private static final String ADMIN = "admin"; private static final String ADMIN = "admin";
private static final String FORMAT = "yyyy/MM/dd HH:mm:ss"; private static final String FORMAT = "yyyy/MM/dd HH:mm:ss";
private static final long DAYWORKTIME = 35*60*60*100*2; private static final long DAYWORKTIME = 35 * 60 * 60 * 100 * 2;
private static final long DAYTIME = 24*60*60*1000; private static final long DAYTIME = 24 * 60 * 60 * 1000;
private static final String MORINGSTART = " 08:30:00"; private static final String MORINGSTART = " 08:30:00";
private static final String MORINGEND = " 12:00:00"; private static final String MORINGEND = " 12:00:00";
private static final String AFTERNOONSTART = " 14:30:00"; private static final String AFTERNOONSTART = " 14:30:00";
private static final String AFTERNOONEND= " 18:00:00"; private static final String AFTERNOONEND = " 18:00:00";
@Resource @Resource
private IProjectxService iProjectxService; private IProjectxService iProjectxService;
@ -328,7 +328,9 @@ public class TaskController extends JeecgController<Task, ITaskService> {
avatars.append(byId.getAvatar()).append(","); avatars.append(byId.getAvatar()).append(",");
} }
if (avatars.length() != 0) {
avatars = new StringBuilder(avatars.substring(0, avatars.length() - 1)); avatars = new StringBuilder(avatars.substring(0, avatars.length() - 1));
}
e.setHeadpic(avatars.toString()); e.setHeadpic(avatars.toString());
} }
@ -350,6 +352,9 @@ public class TaskController extends JeecgController<Task, ITaskService> {
if (count > 0) { if (count > 0) {
return Result.error("名字不能重复"); return Result.error("名字不能重复");
} }
task.setUpdateTime(new Date());
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
task.setUpdateBy(user.getUsername());
taskService.save(task); taskService.save(task);
return Result.OK("添加成功!"); return Result.OK("添加成功!");
} }
@ -367,9 +372,11 @@ public class TaskController extends JeecgController<Task, ITaskService> {
taskService.updateById(task); taskService.updateById(task);
return Result.OK("编辑成功!"); return Result.OK("编辑成功!");
} }
/** /**
* 提交任务更新状态同时计算实际任务时长 * 提交任务更新状态同时计算实际任务时长
* 计算一整天之后算头和尾时间 * 计算一整天之后算头和尾时间
*
* @param task * @param task
* @return * @return
*/ */
@ -378,7 +385,7 @@ public class TaskController extends JeecgController<Task, ITaskService> {
public Result<?> updateWorkStatus(@RequestBody Task task) { public Result<?> updateWorkStatus(@RequestBody Task task) {
Date time = new Date(); Date time = new Date();
if (task.getWorkStatus() == 3){ if (task.getWorkStatus() == 3) {
//获取数据 //获取数据
Task oldTask = taskService.query().eq("id", task.getId()).one(); Task oldTask = taskService.query().eq("id", task.getId()).one();
Date startTime = oldTask.getStartTime(); Date startTime = oldTask.getStartTime();
@ -390,7 +397,7 @@ public class TaskController extends JeecgController<Task, ITaskService> {
} }
//设置更新数据 //设置更新数据
double realTimeHour = (double)realTime/(60*60*1000); double realTimeHour = (double) realTime / (60 * 60 * 1000);
realTimeHour = new BigDecimal(realTimeHour).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); realTimeHour = new BigDecimal(realTimeHour).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
task.setRealDuration(realTimeHour); task.setRealDuration(realTimeHour);
task.setSubmitTime(time); task.setSubmitTime(time);
@ -428,15 +435,15 @@ public class TaskController extends JeecgController<Task, ITaskService> {
Date date4 = sdf.parse(time4); Date date4 = sdf.parse(time4);
//从start往后推到end,要判断大量情况 //从start往后推到end,要判断大量情况
if (startTime.compareTo(endTime) > 0){ if (startTime.compareTo(endTime) > 0) {
//时间跨度两天,但总时间不超过24小时 //时间跨度两天,但总时间不超过24小时
if (startTime.compareTo(date1) <= 0) if (startTime.compareTo(date1) <= 0)
startTime = date1; //任务发布在8点前,从8点开始算 startTime = date1; //任务发布在8点前,从8点开始算
if (startTime.compareTo(date2) <= 0){ if (startTime.compareTo(date2) <= 0) {
//早上有工作时间 //早上有工作时间
workTime += date2.getTime() - startTime.getTime(); workTime += date2.getTime() - startTime.getTime();
//跨度两天,下午必有任务时间 //跨度两天,下午必有任务时间
workTime += DAYWORKTIME/2; workTime += DAYWORKTIME / 2;
//第二天下午必没有工作时间,判断第二天早上是否有部分工作时间 //第二天下午必没有工作时间,判断第二天早上是否有部分工作时间
if (endTime.compareTo(date1) > 0) if (endTime.compareTo(date1) > 0)
workTime += endTime.getTime() - date1.getTime(); //第二天早上有工作时间 workTime += endTime.getTime() - date1.getTime(); //第二天早上有工作时间
@ -450,24 +457,24 @@ public class TaskController extends JeecgController<Task, ITaskService> {
workTime += date4.getTime() - startTime.getTime(); workTime += date4.getTime() - startTime.getTime();
if (endTime.compareTo(date1) <= 0) if (endTime.compareTo(date1) <= 0)
return workTime; //第二天没有工作时间 return workTime; //第二天没有工作时间
if (endTime.compareTo(date2) <= 0){ if (endTime.compareTo(date2) <= 0) {
workTime += endTime.getTime() - date1.getTime(); //第二天上午有部分工作时间 workTime += endTime.getTime() - date1.getTime(); //第二天上午有部分工作时间
return workTime; //必然下午没有工作时间 return workTime; //必然下午没有工作时间
} }
workTime += DAYWORKTIME/2; //第二天上午工作时间占满 workTime += DAYWORKTIME / 2; //第二天上午工作时间占满
if (endTime.compareTo(date3) <= 0) if (endTime.compareTo(date3) <= 0)
return workTime; //下午没有工作时间 return workTime; //下午没有工作时间
if (endTime.compareTo(date4) >= 0) if (endTime.compareTo(date4) >= 0)
endTime = date4; //下午干满了 endTime = date4; //下午干满了
workTime += endTime.getTime() - date3.getTime(); workTime += endTime.getTime() - date3.getTime();
return workTime; return workTime;
}else { } else {
//时间跨度没有超过两天 //时间跨度没有超过两天
if (startTime.compareTo(date1) <= 0) if (startTime.compareTo(date1) <= 0)
startTime = date1; //发布任务在8点之前 startTime = date1; //发布任务在8点之前
if (startTime.compareTo(date2) <= 0){ if (startTime.compareTo(date2) <= 0) {
//上午发布的任务 //上午发布的任务
if (endTime.compareTo(date2) <= 0){ if (endTime.compareTo(date2) <= 0) {
//上午提交的任务 //上午提交的任务
workTime += endTime.getTime() - startTime.getTime(); workTime += endTime.getTime() - startTime.getTime();
return workTime; return workTime;
@ -478,7 +485,7 @@ public class TaskController extends JeecgController<Task, ITaskService> {
if (endTime.compareTo(date4) >= 0) if (endTime.compareTo(date4) >= 0)
endTime = date4; //时间偏移 endTime = date4; //时间偏移
workTime += endTime.getTime() - date3.getTime(); //下午工作时间 workTime += endTime.getTime() - date3.getTime(); //下午工作时间
}else { } else {
//下午发布的任务 //下午发布的任务
if (startTime.compareTo(date3) <= 0) if (startTime.compareTo(date3) <= 0)
startTime = date3; //12点之后,14点之前发布任务 startTime = date3; //12点之后,14点之前发布任务
@ -492,11 +499,12 @@ public class TaskController extends JeecgController<Task, ITaskService> {
/** /**
* 计算预计结束时间 * 计算预计结束时间
*
* @param task * @param task
* @return * @return
*/ */
@GetMapping("/estimateTime") @GetMapping("/estimateTime")
public Result<?> calculating(Task task){ public Result<?> calculating(Task task) {
if (task.getStartTime() == null || task.getExpectedDuration() == null) if (task.getStartTime() == null || task.getExpectedDuration() == null)
return Result.error("参数不足,无法计算预计结束时间"); return Result.error("参数不足,无法计算预计结束时间");
Date date = null; Date date = null;
@ -510,6 +518,7 @@ public class TaskController extends JeecgController<Task, ITaskService> {
/** /**
* 计算预计结束时间方法 * 计算预计结束时间方法
*
* @param startTime * @param startTime
* @param expectedDuration * @param expectedDuration
* @return * @return
@ -538,11 +547,11 @@ public class TaskController extends JeecgController<Task, ITaskService> {
long tempTime = 0; long tempTime = 0;
if (startTime.compareTo(date1) <= 0) if (startTime.compareTo(date1) <= 0)
startTime = date1; //任务发布在8点半之前,修正时间 startTime = date1; //任务发布在8点半之前,修正时间
if (startTime.compareTo(date2) < 0){ if (startTime.compareTo(date2) < 0) {
//上午发布任务 //上午发布任务
tempTime = date2.getTime() - startTime.getTime(); tempTime = date2.getTime() - startTime.getTime();
if (tempTime >= millisecond) if (tempTime >= millisecond)
return new Date(startTime.getTime() + millisecond + DAYTIME*offset); //预计上午结束,直接偏移剩余时间 return new Date(startTime.getTime() + millisecond + DAYTIME * offset); //预计上午结束,直接偏移剩余时间
//上午剩余时间全部工作,时间进行修正到下午工作开始时间 //上午剩余时间全部工作,时间进行修正到下午工作开始时间
millisecond -= tempTime; millisecond -= tempTime;
startTime = date3; startTime = date3;
@ -550,23 +559,24 @@ public class TaskController extends JeecgController<Task, ITaskService> {
if (startTime.compareTo(date3) <= 0) if (startTime.compareTo(date3) <= 0)
startTime = date3; //任务是下午发布且在2点半之前,修正时间 startTime = date3; //任务是下午发布且在2点半之前,修正时间
if (startTime.compareTo(date4) < 0){ if (startTime.compareTo(date4) < 0) {
//下午发布任务 //下午发布任务
tempTime = date4.getTime() - startTime.getTime(); tempTime = date4.getTime() - startTime.getTime();
if (tempTime >= millisecond) if (tempTime >= millisecond)
return new Date(startTime.getTime() + millisecond + DAYTIME*offset); return new Date(startTime.getTime() + millisecond + DAYTIME * offset);
} }
//时间修正,天数偏移量加1,到这里有两中情况,1、白天工作时间不足抵消 2、下午6点之后发布任务 //时间修正,天数偏移量加1,到这里有两中情况,1、白天工作时间不足抵消 2、下午6点之后发布任务
offset ++; offset++;
startTime = date1; startTime = date1;
tempTime = date2.getTime() - date1.getTime(); tempTime = date2.getTime() - date1.getTime();
if (tempTime >= millisecond) if (tempTime >= millisecond)
return new Date(startTime.getTime() + millisecond + DAYTIME*offset); return new Date(startTime.getTime() + millisecond + DAYTIME * offset);
//上午偏移不足,下午一定够,因为不会跨两天 //上午偏移不足,下午一定够,因为不会跨两天
millisecond -= tempTime; millisecond -= tempTime;
return new Date(startTime.getTime() + millisecond + DAYTIME*offset); return new Date(startTime.getTime() + millisecond + DAYTIME * offset);
} }
/** /**
* 通过id删除 * 通过id删除
* *

Loading…
Cancel
Save