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.DateUtils;
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.query.TaskSituationQuery;
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.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
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 ISysUserService sysUserService;
@Resource
private TokenService tokenService;
@Resource
private TDictDataService dictDataService;
@Resource
private TCleanerService cleanerService;
@Resource
private TLeaveService leaveService;
@Resource
private TEarlyWarningService earlyWarningService;
@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);
if("0".equals(projectDept.getParentId())){
// 查询项目部
List childProjectDept = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
.eq(TProjectDept::getStatus,1)
.eq(TProjectDept::getParentId,projectDept.getId()));
projectDept.setChildren(childProjectDept);
projectDeptList.add(projectDept);
}else {
// 查询项目部
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() {
List locationTypes = locationTypeService.list();
return R.ok(locationTypes);
}
@ApiOperation(value = "顶部数量统计")
@PostMapping(value = "/topQuantityStatistics")
public R