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.basic.PageInfo;
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.model.*;
import com.ruoyi.system.query.DataStatisticsQuery;
import com.ruoyi.system.query.DataStatisticsRankQuery;
import com.ruoyi.system.query.InsepectorListQuery;
import com.ruoyi.system.query.PointDetailQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.system.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
*
* 数据大屏 前端控制器
*
*
* @author xiaochen
* @since 2025-05-28
*/
@Api(tags = "数据大屏")
@RestController
@RequestMapping("/statistics")
public class DataStatisticsController {
@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;
@Resource
private TEarlyWarningService earlyWarningService;
@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 = 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));
List locationTypes = locationTypeService.list();
return R.ok(locationTypes);
}
@ApiOperation(value = "数据概览")
@PostMapping(value = "/dataOverview")
public R