编写统计工单数量的算法
This commit is contained in:
@@ -56,7 +56,8 @@ public class MybatisPlusConfig {
|
|||||||
"sys_tenant",
|
"sys_tenant",
|
||||||
"sys_dictionary",
|
"sys_dictionary",
|
||||||
"sys_dictionary_data",
|
"sys_dictionary_data",
|
||||||
"apps_test_data"
|
"apps_test_data",
|
||||||
|
"oa_task_count"
|
||||||
).contains(tableName);
|
).contains(tableName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,32 +1,24 @@
|
|||||||
package com.gxwebsoft.oa.controller;
|
package com.gxwebsoft.oa.controller;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import cn.hutool.core.date.DateField;
|
import cn.hutool.core.date.DateField;
|
||||||
|
import cn.hutool.core.date.DateRange;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
|
||||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
|
||||||
import com.gxwebsoft.common.core.utils.MyQrCodeUtil;
|
import com.gxwebsoft.common.core.utils.MyQrCodeUtil;
|
||||||
import com.gxwebsoft.common.core.web.BaseController;
|
import com.gxwebsoft.common.core.web.*;
|
||||||
import com.gxwebsoft.common.system.entity.Role;
|
import com.gxwebsoft.common.system.entity.Role;
|
||||||
import com.gxwebsoft.oa.entity.TaskCount;
|
|
||||||
import com.gxwebsoft.oa.entity.TaskRecord;
|
|
||||||
import com.gxwebsoft.oa.service.TaskCountService;
|
|
||||||
import com.gxwebsoft.oa.service.TaskRecordService;
|
|
||||||
import com.gxwebsoft.oa.service.TaskService;
|
|
||||||
import com.gxwebsoft.oa.entity.Task;
|
|
||||||
import com.gxwebsoft.oa.param.TaskParam;
|
|
||||||
import com.gxwebsoft.common.core.web.ApiResult;
|
|
||||||
import com.gxwebsoft.common.core.web.PageResult;
|
|
||||||
import com.gxwebsoft.common.core.web.PageParam;
|
|
||||||
import com.gxwebsoft.common.core.web.BatchParam;
|
|
||||||
import com.gxwebsoft.common.system.entity.User;
|
import com.gxwebsoft.common.system.entity.User;
|
||||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
import com.gxwebsoft.oa.entity.Task;
|
||||||
|
import com.gxwebsoft.oa.entity.TaskCount;
|
||||||
|
import com.gxwebsoft.oa.param.TaskParam;
|
||||||
|
import com.gxwebsoft.oa.service.TaskCountService;
|
||||||
|
import com.gxwebsoft.oa.service.TaskService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -103,8 +95,8 @@ public class TaskController extends BaseController {
|
|||||||
@ApiOperation("修改任务记录表")
|
@ApiOperation("修改任务记录表")
|
||||||
@PutMapping()
|
@PutMapping()
|
||||||
public ApiResult<?> update(@RequestBody Task task) {
|
public ApiResult<?> update(@RequestBody Task task) {
|
||||||
task.setLoginUserId(getLoginUserId());
|
|
||||||
if (taskService.updateById(task)) {
|
if (taskService.updateById(task)) {
|
||||||
|
// 更新统计表
|
||||||
taskService.updateCount(task);
|
taskService.updateCount(task);
|
||||||
return success("修改成功");
|
return success("修改成功");
|
||||||
}
|
}
|
||||||
@@ -173,9 +165,41 @@ public class TaskController extends BaseController {
|
|||||||
return success("操作成功", qrCode);
|
return success("操作成功", qrCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron="*/2 * * * * *")
|
|
||||||
|
/**
|
||||||
|
* 每日清零
|
||||||
|
*/
|
||||||
|
@Scheduled(cron="0 0 0 * * ?")
|
||||||
|
public void todayTask() {
|
||||||
|
System.out.println("每日清零任务 = ");
|
||||||
|
final boolean update = taskCountService.update(new LambdaUpdateWrapper<TaskCount>().set(TaskCount::getToday, 0));
|
||||||
|
System.out.println("update = " + update);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本月清零
|
||||||
|
*/
|
||||||
|
@Scheduled(cron="0 0 1 * * ?")
|
||||||
|
public void monthTask() {
|
||||||
|
taskCountService.update(new LambdaUpdateWrapper<TaskCount>().set(TaskCount::getMonth, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每年清零
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 0 1 * ?")
|
||||||
|
public void yearTask(){
|
||||||
|
taskCountService.update(new LambdaUpdateWrapper<TaskCount>().set(TaskCount::getYear, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时结算已解决待确认的工单的任务
|
||||||
|
* 1个小时内没有用户再次提交新的回复则自动结算
|
||||||
|
* 时间间隔2分钟执行一次
|
||||||
|
*/
|
||||||
|
@Scheduled(cron="*/1 * * * * *")
|
||||||
public void updateProgressTask() {
|
public void updateProgressTask() {
|
||||||
System.out.println("定时任务开始 = " + DateUtil.now());
|
System.out.println("定时任务开始:updateProgressTask = " + DateUtil.now());
|
||||||
TaskParam taskParam = new TaskParam();
|
TaskParam taskParam = new TaskParam();
|
||||||
taskParam.setProgress(TOBECONFIRMED);
|
taskParam.setProgress(TOBECONFIRMED);
|
||||||
taskParam.setLimit(10L);
|
taskParam.setLimit(10L);
|
||||||
@@ -185,17 +209,20 @@ public class TaskController extends BaseController {
|
|||||||
}
|
}
|
||||||
final List<Task> list = result.getList();
|
final List<Task> list = result.getList();
|
||||||
if (!CollectionUtils.isEmpty(list)) {
|
if (!CollectionUtils.isEmpty(list)) {
|
||||||
list.forEach(d -> {
|
list.forEach(task -> {
|
||||||
try {
|
try {
|
||||||
|
System.out.println("task = " + task);
|
||||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
Date newDate = DateUtil.offset(d.getUpdateTime(), DateField.MINUTE, 1);
|
Date newDate = DateUtil.offset(task.getUpdateTime(), DateField.MINUTE, 1);
|
||||||
Date date1 = df.parse(newDate.toString());
|
Date date1 = df.parse(newDate.toString());
|
||||||
Date date2 = df.parse(DateUtil.now());
|
Date date2 = df.parse(DateUtil.now());
|
||||||
if(date2.after(date1)){
|
final boolean after = date2.after(date1);
|
||||||
d.setProgress(COMPLETED);
|
if(after){
|
||||||
d.setStatus(TASK_STATUS_1);
|
// 更新工单状态
|
||||||
taskService.updateByIdAll(d);
|
task.setProgress(COMPLETED);
|
||||||
System.out.println("已解决的工单半个小时未确认则自动确认 = " + d.getTaskId());
|
task.setStatus(TASK_STATUS_1);
|
||||||
|
taskService.updateByIdAll(task);
|
||||||
|
System.out.println("已解决的工单半个小时未确认则自动确认 = " + task.getTaskId());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -203,5 +230,4 @@ public class TaskController extends BaseController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ public class Task implements Serializable {
|
|||||||
@ApiModelProperty(value = "状态, 0待处理, 1已完成")
|
@ApiModelProperty(value = "状态, 0待处理, 1已完成")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "结算状态")
|
||||||
|
private Integer isSettled;
|
||||||
|
|
||||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||||
@TableLogic
|
@TableLogic
|
||||||
private Integer deleted;
|
private Integer deleted;
|
||||||
|
|||||||
@@ -103,29 +103,4 @@ public class TaskCountServiceImpl extends ServiceImpl<TaskCountMapper, TaskCount
|
|||||||
return param.getOne(baseMapper.selectListRel(param));
|
return param.getOne(baseMapper.selectListRel(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 每日清零
|
|
||||||
*/
|
|
||||||
// @Scheduled(cron="0 0 0 * * ?")
|
|
||||||
// public void todayTask() {
|
|
||||||
// System.out.println("每日清零任务 = ");
|
|
||||||
// update(new LambdaUpdateWrapper<TaskCount>().set(TaskCount::getToday, 0));
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 本月清零
|
|
||||||
*/
|
|
||||||
// @Scheduled(cron="0 0 1 * * ?")
|
|
||||||
// public void monthTask() {
|
|
||||||
// update(new LambdaUpdateWrapper<TaskCount>().set(TaskCount::getMonth, 0));
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 每年清零
|
|
||||||
*/
|
|
||||||
// @Scheduled(cron = "0 0 0 1 * ?")
|
|
||||||
// public void yearTask(){
|
|
||||||
// update(new LambdaUpdateWrapper<TaskCount>().set(TaskCount::getYear, 0));
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.gxwebsoft.oa.service.impl;
|
package com.gxwebsoft.oa.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.date.*;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@@ -137,18 +138,96 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
|
||||||
@Override
|
@Override
|
||||||
public void updateCount(Task task) {
|
public void updateCount(Task param) {
|
||||||
|
final Task task = getById(param.getTaskId());
|
||||||
|
// 当前时间 2023-11-04 21:47:16
|
||||||
|
final String now = DateUtil.now();
|
||||||
|
// 今天日期 2023-11-04
|
||||||
|
final String today = DateUtil.today();
|
||||||
|
// 今天开始的时间 2023-11-04 00:00:00
|
||||||
|
final DateTime dayStart = DateUtil.beginOfDay(DateUtil.date());
|
||||||
|
// 今天结束的时间 2023-11-04 00:00:00
|
||||||
|
final DateTime dayEnd = DateUtil.offsetDay(dayStart, 1);
|
||||||
|
// 当前月份的开始时间 2023-11-01 00:00:00
|
||||||
|
final DateTime monthStart = DateUtil.beginOfMonth(DateUtil.date());
|
||||||
|
// 当期月份的结束时间 2023-12-01 00:00:00
|
||||||
|
final DateTime monthEnd = DateUtil.offsetMonth(monthStart, 1);
|
||||||
|
// 今年的开始时间
|
||||||
|
final DateTime yearStart = DateUtil.beginOfYear(DateUtil.date());
|
||||||
|
// 获取年的值
|
||||||
|
final int year = DateUtil.year(yearStart);
|
||||||
|
// 是否闰年
|
||||||
|
final boolean leapYear = DateUtil.isLeapYear(year);
|
||||||
|
// 获取今年的总天数
|
||||||
|
int daysByYear = leapYear ? 366 : 365;
|
||||||
|
// 今年的结束时间
|
||||||
|
final DateTime yearEnd = DateUtil.offsetDay(yearStart, daysByYear);
|
||||||
|
// 创建日期范围生成器
|
||||||
|
DateRange range = DateUtil.range(monthStart, monthEnd, DateField.MONTH);
|
||||||
|
|
||||||
|
// 查询待处理的工单总数量
|
||||||
|
final int pendingTasks = count(new LambdaQueryWrapper<Task>().eq(Task::getStatus, TASK_STATUS_0));
|
||||||
|
// 查询今日已处理的工单数量
|
||||||
|
final int todayTasks = count(new LambdaQueryWrapper<Task>().between(Task::getUpdateTime, dayStart, dayEnd).eq(Task::getStatus,TASK_STATUS_1));
|
||||||
|
// 查询本月已处理的工单数量
|
||||||
|
final int monthTasks = count(new LambdaQueryWrapper<Task>().between(Task::getUpdateTime, monthStart, monthEnd).eq(Task::getStatus,TASK_STATUS_1));
|
||||||
|
// 查询本年已处理的工单总数量
|
||||||
|
final int yearTasks = count(new LambdaQueryWrapper<Task>().between(Task::getUpdateTime, yearStart, yearEnd).eq(Task::getStatus, TASK_STATUS_1));
|
||||||
|
// 查询公司总处理工单数量
|
||||||
|
final int totalTasks = count(new LambdaQueryWrapper<Task>().eq(Task::getStatus, TASK_STATUS_1));
|
||||||
|
|
||||||
|
// 查询当前登录用户待处理的工单数量
|
||||||
|
final int userPendingTasks = count(new LambdaQueryWrapper<Task>().eq(Task::getStatus, TASK_STATUS_1).eq(Task::getUserId,task.getUserId()));
|
||||||
|
// 查询当前登录用户今日已处理的工单数量
|
||||||
|
final int userTodayTasks = count(new LambdaQueryWrapper<Task>().between(Task::getUpdateTime,dayStart,dayEnd).eq(Task::getStatus, TASK_STATUS_1).eq(Task::getUserId,task.getUserId()));
|
||||||
|
// 查询当前登录用户本月已处理的工单数量
|
||||||
|
final int userMonthTasks = count(new LambdaQueryWrapper<Task>().between(Task::getUpdateTime,monthStart,monthEnd).eq(Task::getStatus, TASK_STATUS_1).eq(Task::getUserId,task.getUserId()));
|
||||||
|
// 查询当前登录用户本年已处理的工单数量
|
||||||
|
final int userYearTasks = count(new LambdaQueryWrapper<Task>().between(Task::getUpdateTime,yearStart,yearEnd).eq(Task::getStatus, TASK_STATUS_1).eq(Task::getUserId,task.getUserId()));
|
||||||
|
// 查询当前登录用户已处理的总工单数量
|
||||||
|
final int userTotalTasks = count(new LambdaQueryWrapper<Task>().eq(Task::getStatus, TASK_STATUS_1).eq(Task::getUserId,task.getUserId()));
|
||||||
|
|
||||||
|
// 查询受理人待处理的工单数量
|
||||||
|
final int commanderPendingTasks = count(new LambdaQueryWrapper<Task>().eq(Task::getStatus, TASK_STATUS_0).eq(Task::getCommander,task.getCommander()));
|
||||||
|
// 查询受理人今日已处理的工单数量
|
||||||
|
final int commanderTodayTasks = count(new LambdaQueryWrapper<Task>().between(Task::getUpdateTime,dayStart,dayEnd).eq(Task::getStatus, TASK_STATUS_1).eq(Task::getCommander,task.getCommander()));
|
||||||
|
// 查询受理人本月已处理的工单数量
|
||||||
|
final int commanderMonthTasks = count(new LambdaQueryWrapper<Task>().between(Task::getUpdateTime,monthStart,monthEnd).eq(Task::getStatus, TASK_STATUS_1).eq(Task::getCommander,task.getCommander()));
|
||||||
|
// 查询受理人本年已处理的工单数量
|
||||||
|
final int commanderYearTasks = count(new LambdaQueryWrapper<Task>().between(Task::getUpdateTime,yearStart,yearEnd).eq(Task::getStatus, TASK_STATUS_1).eq(Task::getCommander,task.getCommander()));
|
||||||
|
// 查询受理人已处理的总工单数量
|
||||||
|
final int commanderTotalTasks = count(new LambdaQueryWrapper<Task>().eq(Task::getStatus, TASK_STATUS_1).eq(Task::getCommander,task.getCommander()));
|
||||||
|
|
||||||
// 统计项目发起人
|
// 统计项目发起人
|
||||||
TaskCount user = taskCountService.getByUserId(task.getLoginUserId());
|
TaskCount user = taskCountService.getByUserId(task.getUserId());
|
||||||
user.setPending(count(new LambdaQueryWrapper<Task>().eq(Task::getStatus, 0).eq(Task::getUserId,task.getLoginUserId())));
|
user.setPending(userPendingTasks);
|
||||||
|
user.setToday(userTodayTasks);
|
||||||
|
user.setMonth(userMonthTasks);
|
||||||
|
user.setYear(userYearTasks);
|
||||||
|
user.setTotal(userTotalTasks);
|
||||||
taskCountService.updateById(user);
|
taskCountService.updateById(user);
|
||||||
|
if(!user.getUserId().equals(task.getCommander())){
|
||||||
// 统计项目受理人
|
// 统计项目受理人
|
||||||
TaskCount commander = taskCountService.getByUserId(task.getCommander());
|
TaskCount commander = taskCountService.getByUserId(task.getCommander());
|
||||||
commander.setPending(count(new LambdaQueryWrapper<Task>().eq(Task::getStatus,0).eq(Task::getCommander,task.getCommander())));
|
if(commander != null){
|
||||||
|
commander.setPending(commanderPendingTasks);
|
||||||
|
commander.setToday(commanderTodayTasks);
|
||||||
|
commander.setMonth(commanderMonthTasks);
|
||||||
|
commander.setYear(commanderYearTasks);
|
||||||
|
commander.setTotal(commanderTotalTasks);
|
||||||
taskCountService.updateById(commander);
|
taskCountService.updateById(commander);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// 统计公司数据
|
||||||
|
final TaskCount company = taskCountService.getByUserId(0);
|
||||||
|
company.setPending(pendingTasks);
|
||||||
|
company.setToday(todayTasks);
|
||||||
|
company.setMonth(monthTasks);
|
||||||
|
company.setYear(yearTasks);
|
||||||
|
company.setTotal(totalTasks);
|
||||||
|
taskCountService.updateById(company);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<Task> pageRelAll(TaskParam param) {
|
public PageResult<Task> pageRelAll(TaskParam param) {
|
||||||
@@ -162,4 +241,5 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|||||||
public void updateByIdAll(Task task) {
|
public void updateByIdAll(Task task) {
|
||||||
baseMapper.updateByTaskId(task);
|
baseMapper.updateByTaskId(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user