package com.ruoyi.web.controller.api;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.WorkBenchesDTO;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.DataStatisticsQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.system.*;
import com.ruoyi.web.util.OssUploadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
*
* 任务申诉 前端控制器
*
*
* @author xiaochen
* @since 2025-05-28
*/
@Api(tags = "工作台")
@RestController
@RequestMapping("/workbenches")
public class WorkbenchesController {
@Resource
private TTaskCleanService taskCleanService;
@Resource
private TLocationTypeService locationTypeService;
@Resource
private TLocationService locationService;
@Resource
private TProjectDeptService projectDeptService;
@Resource
private TTaskDetailService tTaskDetailService;
@Resource
private TDeptService deptService;
@Resource
private ISysUserService sysUserService;
@Resource
private TokenService tokenService;
@Resource
private TAppealService appealService;
@Resource
private TDictDataService dictDataService;
@PostMapping("/data")
@ApiOperation(value = "工作台", tags = "工作台")
public R data(@RequestBody WorkBenchesDTO dto) {
return R.ok();
}
@ApiOperation(value = "查询部门 项目部列表 不分页")
@GetMapping(value = "/listDepts")
public R> listDepts() {
Long userId = tokenService.getLoginUser().getUserId();
SysUser sysUser = sysUserService.selectUserById(userId);
List parent = projectDeptService.lambdaQuery().eq(TProjectDept::getParentId, "0").list();
List child = projectDeptService.lambdaQuery().ne(TProjectDept::getParentId, "0").list();
List res = new ArrayList<>();
DeptNoLimitVO deptNoLimitVO2 = new DeptNoLimitVO();
deptNoLimitVO2.setDeptName("公司");
res.add(deptNoLimitVO2);
if (sysUser.getDeptType()==1){
parent = parent.stream().filter(e -> e.getId().equals(sysUser.getDeptId())).collect(Collectors.toList());
}
for (DeptNoLimitVO re : res) {
if (re.getDeptName().equals("项目部")) {
List deptNoLimitVOS = new ArrayList<>();
for (TProjectDept tProjectDept : parent) {
DeptNoLimitParentVO deptNoLimitVO = new DeptNoLimitParentVO();
deptNoLimitVO.setDeptName(tProjectDept.getProjectName());
deptNoLimitVO.setDeptId(tProjectDept.getId());
List collect = child.stream().filter(e -> e.getParentId().equals(tProjectDept.getId())).collect(Collectors.toList());
List deptNoLimitChildVOS = new ArrayList<>();
for (TProjectDept projectDept : collect) {
DeptNoLimitChildVO deptNoLimitChildVO = new DeptNoLimitChildVO();
deptNoLimitChildVO.setDeptName(projectDept.getProjectName());
deptNoLimitChildVO.setDeptId(projectDept.getId());
deptNoLimitChildVOS.add(deptNoLimitChildVO);
}
deptNoLimitVO.setDeptChild(deptNoLimitChildVOS);
deptNoLimitVOS.add(deptNoLimitVO);
}
re.setDeptChild(deptNoLimitVOS);
}
}
return R.ok(res);
}
@ApiOperation(value = "查询片区")
@GetMapping(value = "/queryProject")
public R> queryProject() {
Integer deptType = tokenService.getLoginUser().getUser().getDeptType();
String deptId = tokenService.getLoginUser().getUser().getDeptId();
Long userId = tokenService.getLoginUser().getUserId();
List projectDeptList = new ArrayList<>();
if(userId != 1L){
if (deptType == 1) {
// 查询片区
TProjectDept projectDept = projectDeptService.getById(deptId);
// 查询项目部
TProjectDept parent = projectDeptService.getById(projectDept.getParentId());
List children = new ArrayList<>();
children.add(projectDept);
parent.setChildren(children);
projectDeptList.add(parent);
}else {
projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getStatus,1)
.eq(TProjectDept::getParentId,0));
// 查询片区
projectDeptList.forEach(projectDept -> {
List children = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getParentId, projectDept.getId()));
projectDept.setChildren(children);
});
}
}else {
projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getStatus,1)
.eq(TProjectDept::getParentId,0));
// 查询片区
projectDeptList.forEach(projectDept -> {
List children = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getParentId, projectDept.getId()));
projectDept.setChildren(children);
});
}
return R.ok(projectDeptList);
}
@ApiOperation(value = "通过片区id查询点位类型")
@GetMapping(value = "/queryLocationByProjectId")
public R> queryLocationByProjectId(@RequestParam(value = "projectId") String projectId) {
List locationTypes = new ArrayList<>();
// 通过片区id查询点位
List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
.eq(TLocation::getProjectId, projectId));
if(CollectionUtils.isEmpty(locationList)){
return R.ok(locationTypes);
}
List typeIds = locationList.stream().map(TLocation::getLocationType).collect(Collectors.toList());
locationTypes = locationTypeService.list(Wrappers.lambdaQuery(TLocationType.class)
.in(TLocationType::getId, typeIds));
return R.ok(locationTypes);
}
@ApiOperation(value = "任务情况")
@PostMapping(value = "/taskSituation")
public R> taskSituation(@RequestBody DataStatisticsQuery query) {
Integer deptType = tokenService.getLoginUser().getUser().getDeptType();
String deptId = tokenService.getLoginUser().getUser().getDeptId();
Long userId = tokenService.getLoginUser().getUserId();
// 查询所有点位
List locations = locationService.list();
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
if (userId != 1L) {
// 查询点位类型
if(StringUtils.isNotEmpty(query.getLocationTypeId())){
// 查询点位
List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
.in(TLocation::getLocationType, query.getLocationTypeId()));
if(!CollectionUtils.isEmpty(locationList)){
List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList());
wrapper.in(TTask::getLocationId, locationIds);
}
}
List taskList = new ArrayList<>();
if (deptType == 1) {
// 项目部人员
List projectIds = new ArrayList<>();
projectIds.add(deptId);
query.setProjectId(projectIds);
}else {
// 公司人员
// 查询自己的任务列表
taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)
.eq(TTask::getPatrolInspector, userId));
if(CollectionUtils.isEmpty(query.getProjectId())){
// 查询所有项目部的任务列表
List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getStatus, 1)
.ne(TProjectDept::getParentId, 0));
if(!CollectionUtils.isEmpty(tProjectDeptList)){
List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
wrapper.in(TTask::getProjectId, projectIds);
}
}
}
// 查询片区
if(!CollectionUtils.isEmpty(query.getProjectId())){
wrapper.in(TTask::getProjectId, query.getProjectId());
}
List list = taskCleanService.list(wrapper);
if(CollectionUtils.isEmpty(list)){
return R.ok();
}
if(!CollectionUtils.isEmpty(taskList)){
list.addAll(taskList);
}
List result = list.stream().filter(task -> task.getStatus() == 3).collect(Collectors.toList());
for (TTask task : result) {
TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null);
if(Objects.nonNull(tLocation)) {
task.setLocationName(tLocation.getLocationName());
}
}
return R.ok(result);
}else {
// 超级管理员
// 查询点位类型
if(StringUtils.isNotEmpty(query.getLocationTypeId())){
// 查询点位
List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
.in(TLocation::getLocationType, query.getLocationTypeId()));
if(!CollectionUtils.isEmpty(locationList)){
List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList());
wrapper.in(TTask::getLocationId, locationIds);
}
}
// 超级管理员 查询所有的任务列表
List taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class));
if(CollectionUtils.isEmpty(query.getProjectId())){
// 查询所有项目部的任务列表
List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getStatus, 1)
.ne(TProjectDept::getParentId, 0));
if(!CollectionUtils.isEmpty(tProjectDeptList)){
List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
wrapper.in(TTask::getProjectId, projectIds);
}
}
// 查询片区
if(!CollectionUtils.isEmpty(query.getProjectId())){
wrapper.in(TTask::getProjectId, query.getProjectId());
}
List list = taskCleanService.list(wrapper);
if(CollectionUtils.isEmpty(list)){
return R.ok();
}
if(!CollectionUtils.isEmpty(taskList)){
list.addAll(taskList);
}
List result = list.stream().filter(task -> task.getStatus() == 3).collect(Collectors.toList());
for (TTask task : result) {
TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null);
if(Objects.nonNull(tLocation)) {
task.setLocationName(tLocation.getLocationName());
}
}
return R.ok(result);
}
}
@ApiOperation(value = "今日预警")
@PostMapping(value = "/todayWarning")
public R> todayWarning(@RequestBody DataStatisticsQuery query) {
Integer deptType = tokenService.getLoginUser().getUser().getDeptType();
String deptId = tokenService.getLoginUser().getUser().getDeptId();
Long userId = tokenService.getLoginUser().getUserId();
// 查询所有点位
List locations = locationService.list();
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
String startTime = LocalDate.now() + " 00:00:00";
String endTime = LocalDate.now() + " 23:59:59";
wrapper.between(TTask::getImplementTime, startTime, endTime);
if (userId != 1L) {
// 查询点位类型
if(StringUtils.isNotEmpty(query.getLocationTypeId())){
// 查询点位
List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
.in(TLocation::getLocationType, query.getLocationTypeId()));
if(!CollectionUtils.isEmpty(locationList)){
List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList());
wrapper.in(TTask::getLocationId, locationIds);
}
}
List taskList = new ArrayList<>();
if (deptType == 1) {
// 项目部人员
List projectIds = new ArrayList<>();
projectIds.add(deptId);
query.setProjectId(projectIds);
}else {
// 公司人员
// 查询自己的任务列表
taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)
.eq(TTask::getPatrolInspector, userId));
if(CollectionUtils.isEmpty(query.getProjectId())){
// 查询所有项目部的任务列表
List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getStatus, 1)
.ne(TProjectDept::getParentId, 0));
if(!CollectionUtils.isEmpty(tProjectDeptList)){
List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
wrapper.in(TTask::getProjectId, projectIds);
}
}
}
// 查询片区
if(!CollectionUtils.isEmpty(query.getProjectId())){
wrapper.in(TTask::getProjectId, query.getProjectId());
}
List list = taskCleanService.list(wrapper);
if(CollectionUtils.isEmpty(list)){
return R.ok();
}
if(!CollectionUtils.isEmpty(taskList)){
list.addAll(taskList);
}
List result = list.stream().filter(task -> task.getStatus() == 2).collect(Collectors.toList());
List tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
if(CollectionUtils.isEmpty(tasks)){
for (TTask task : result) {
TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null);
if(Objects.nonNull(tLocation)) {
task.setLocationName(tLocation.getLocationName());
}
}
return R.ok(result);
}
List taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList());
List taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class)
.in(TTaskDetail::getTaskId, taskIds)
.orderByDesc(TTaskDetail::getCreateTime));
for (TTask task : list) {
TTaskDetail tTaskDetail = taskDetails.stream().filter(taskDetail -> taskDetail.getTaskId().equals(task.getId())).findFirst().orElse(null);
if(Objects.nonNull(tTaskDetail)){
if(tTaskDetail.getClearStatus() == 2){
result.add(task);
}
}
}
for (TTask task : result) {
TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null);
if(Objects.nonNull(tLocation)) {
task.setLocationName(tLocation.getLocationName());
}
}
return R.ok(result);
}else {
// 超级管理员
// 查询点位类型
if(StringUtils.isNotEmpty(query.getLocationTypeId())){
// 查询点位
List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
.in(TLocation::getLocationType, query.getLocationTypeId()));
if(!CollectionUtils.isEmpty(locationList)){
List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList());
wrapper.in(TTask::getLocationId, locationIds);
}
}
// 超级管理员 查询所有的任务列表
List taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class));
if(CollectionUtils.isEmpty(query.getProjectId())){
// 查询所有项目部的任务列表
List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getStatus, 1)
.ne(TProjectDept::getParentId, 0));
if(!CollectionUtils.isEmpty(tProjectDeptList)){
List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
wrapper.in(TTask::getProjectId, projectIds);
}
}
// 查询片区
if(!CollectionUtils.isEmpty(query.getProjectId())){
wrapper.in(TTask::getProjectId, query.getProjectId());
}
List list = taskCleanService.list(wrapper);
if(CollectionUtils.isEmpty(list)){
return R.ok();
}
if(!CollectionUtils.isEmpty(taskList)){
list.addAll(taskList);
}
List result = list.stream().filter(task -> task.getStatus() == 2).collect(Collectors.toList());
List tasks = list.stream().filter(task -> task.getStatus() != 1 && task.getStatus() != 2).collect(Collectors.toList());
if(CollectionUtils.isEmpty(tasks)){
for (TTask task : result) {
TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null);
if(Objects.nonNull(tLocation)) {
task.setLocationName(tLocation.getLocationName());
}
}
return R.ok(result);
}
List taskIds = tasks.stream().map(TTask::getId).collect(Collectors.toList());
List taskDetails = tTaskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class)
.in(TTaskDetail::getTaskId, taskIds)
.orderByDesc(TTaskDetail::getCreateTime));
for (TTask task : list) {
TTaskDetail tTaskDetail = taskDetails.stream().filter(taskDetail -> taskDetail.getTaskId().equals(task.getId())).findFirst().orElse(null);
if(Objects.nonNull(tTaskDetail)){
if(tTaskDetail.getClearStatus() == 2){
result.add(task);
}
}
}
for (TTask task : result) {
TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null);
if(Objects.nonNull(tLocation)) {
task.setLocationName(tLocation.getLocationName());
}
}
return R.ok(result);
}
}
@ApiOperation(value = "待审核任务")
@PostMapping(value = "/pendingAuditTasks")
public R> pendingAuditTasks(@RequestBody DataStatisticsQuery query) {
Integer deptType = tokenService.getLoginUser().getUser().getDeptType();
String deptId = tokenService.getLoginUser().getUser().getDeptId();
Long userId = tokenService.getLoginUser().getUserId();
// 查询所有点位
List locations = locationService.list();
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
if (userId != 1L) {
// 查询点位类型
if(StringUtils.isNotEmpty(query.getLocationTypeId())){
// 查询点位
List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
.in(TLocation::getLocationType, query.getLocationTypeId()));
if(!CollectionUtils.isEmpty(locationList)){
List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList());
wrapper.in(TTask::getLocationId, locationIds);
}
}
List taskList = new ArrayList<>();
if (deptType == 1) {
// 项目部人员
List projectIds = new ArrayList<>();
projectIds.add(deptId);
query.setProjectId(projectIds);
}else {
// 公司人员
// 查询自己的任务列表
taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)
.eq(TTask::getPatrolInspector, userId));
if(CollectionUtils.isEmpty(query.getProjectId())){
// 查询所有项目部的任务列表
List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getStatus, 1)
.ne(TProjectDept::getParentId, 0));
if(!CollectionUtils.isEmpty(tProjectDeptList)){
List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
wrapper.in(TTask::getProjectId, projectIds);
}
}
}
// 查询片区
if(!CollectionUtils.isEmpty(query.getProjectId())){
wrapper.in(TTask::getProjectId, query.getProjectId());
}
List list = taskCleanService.list(wrapper);
if(CollectionUtils.isEmpty(list)){
return R.ok();
}
if(!CollectionUtils.isEmpty(taskList)){
list.addAll(taskList);
}
List result = list.stream().filter(task -> task.getStatus() == 3).collect(Collectors.toList());
for (TTask task : result) {
TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null);
if(Objects.nonNull(tLocation)) {
task.setLocationName(tLocation.getLocationName());
}
}
return R.ok(result);
}else {
// 超级管理员
// 查询点位类型
if(StringUtils.isNotEmpty(query.getLocationTypeId())){
// 查询点位
List locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
.in(TLocation::getLocationType, query.getLocationTypeId()));
if(!CollectionUtils.isEmpty(locationList)){
List locationIds = locationList.stream().map(TLocation::getId).collect(Collectors.toList());
wrapper.in(TTask::getLocationId, locationIds);
}
}
// 超级管理员 查询所有的任务列表
List taskList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class));
if(CollectionUtils.isEmpty(query.getProjectId())){
// 查询所有项目部的任务列表
List tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getStatus, 1)
.ne(TProjectDept::getParentId, 0));
if(!CollectionUtils.isEmpty(tProjectDeptList)){
List projectIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
wrapper.in(TTask::getProjectId, projectIds);
}
}
// 查询片区
if(!CollectionUtils.isEmpty(query.getProjectId())){
wrapper.in(TTask::getProjectId, query.getProjectId());
}
List list = taskCleanService.list(wrapper);
if(CollectionUtils.isEmpty(list)){
return R.ok();
}
if(!CollectionUtils.isEmpty(taskList)){
list.addAll(taskList);
}
List result = list.stream().filter(task -> task.getStatus() == 3).collect(Collectors.toList());
for (TTask task : result) {
TLocation tLocation = locations.stream().filter(location -> location.getId().equals(task.getLocationId())).findFirst().orElse(null);
if(Objects.nonNull(tLocation)) {
task.setLocationName(tLocation.getLocationName());
}
}
return R.ok(result);
}
}
@ApiOperation(value = "保洁质量汇总")
@PostMapping(value = "/cleaningQualitySummary")
public R