xuhy
4 天以前 1b09f886a2c8dc47c4945dace5bd649a7b4ef0ad
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TEarlyWarningController.java
@@ -1,9 +1,27 @@
package com.ruoyi.web.controller.api;
import com.ruoyi.common.annotation.Log;
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.enums.BusinessType;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TaskListQuery;
import com.ruoyi.system.query.TaskWarningQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.system.TaskListVO;
import com.ruoyi.system.vo.system.TaskWarningVO;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
 * <p>
@@ -17,6 +35,117 @@
@RestController
@RequestMapping("/t-early-warning")
public class TEarlyWarningController {
    @Resource
    private TTaskCleanService taskCleanerService;
    @Resource
    private TTaskDetailService taskDetailService;
    @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 TDictDataService dictDataService;
    @Resource
    private TokenService tokenService;
    @Resource
    private TEarlyWarningService earlyWarningService;
    @ApiOperation(value = "任务预警分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TaskWarningVO>> pageList(@RequestBody TaskWarningQuery query) {
        List<SysUser> sysUsers = sysUserService.selectAllList();
        List<TLocation> locationList = locationService.list();
        List<TTask> taskList = taskCleanerService.list();
        if (StringUtils.hasLength(query.getDeptName())){
            List<String> projectIds = projectDeptService.lambdaQuery().like(TProjectDept::getProjectName, query.getDeptName()).list()
                    .stream().map(TProjectDept::getId).collect(Collectors.toList());
            List<String> deptIds = deptService.lambdaQuery().like(TDept::getDeptName, query.getDeptName()).list()
                    .stream().map(TDept::getId).collect(Collectors.toList());
            projectIds.addAll(deptIds);
            if (projectIds.isEmpty()){
                return R.ok(new PageInfo<>());
            }
            if (StringUtils.hasLength(query.getPhonenumber())){
                List<Long> patrolInspectorIds = sysUsers.stream().filter(sysUser ->
                        sysUser.getPhonenumber().equals(query.getPhonenumber())
                                && projectIds.contains(sysUser.getDeptId())
                ).map(SysUser::getUserId).collect(Collectors.toList());
                if (patrolInspectorIds.isEmpty()){
                    return R.ok(new PageInfo<>());
                }
                query.setPatrolInspectorIds(patrolInspectorIds);
            }
        }
        if (StringUtils.hasLength(query.getPhonenumber())){
            List<Long> patrolInspectorIds = sysUsers.stream().filter(sysUser ->
                    sysUser.getPhonenumber().equals(query.getPhonenumber())
            ).map(SysUser::getUserId).collect(Collectors.toList());
            if (!query.getPatrolInspectorIds().isEmpty()){
                // 取交集
                patrolInspectorIds = patrolInspectorIds.stream().filter(query.getPatrolInspectorIds()::contains).collect(Collectors.toList());
            }
            query.setPatrolInspectorIds(patrolInspectorIds);
            if (patrolInspectorIds.isEmpty()){
                return R.ok(new PageInfo<>());
            }
        }
        if (StringUtils.hasLength(query.getLocationType())){
            List<String> collect = locationList.stream().filter(
                    e -> e.getLocationType().equals(query.getLocationType())
                    ).map(TLocation::getId)
                    .collect(Collectors.toList());
            if (collect.isEmpty()){
                return R.ok(new PageInfo<>());
            }
            query.setLocationIds(collect);
        }
        if (StringUtils.hasLength(query.getLocationName())){
            List<String> collect = locationList.stream().filter(e -> e.getLocationName().contains(query.getLocationName())).map(TLocation::getId)
                    .collect(Collectors.toList());
            if (collect.isEmpty()){
                query.setLocationIds(collect);
                return R.ok(new PageInfo<>());
            }else{
                collect = collect.stream().filter(query.getLocationIds()::contains).collect(Collectors.toList());
                if (collect.isEmpty()){
                    return R.ok(new PageInfo<>());
                }
                query.setLocationIds(collect);
            }
        }
        if (query.getPatrolInspectorIds()!=null && !query.getPatrolInspectorIds().isEmpty()){
            taskList = taskList.stream().filter(task -> query.getPatrolInspectorIds().contains(Long.valueOf(task.getPatrolInspector()))).collect(Collectors.toList());
            if (taskList.isEmpty()){
                return R.ok(new PageInfo<>());
            }
        }
        if (query.getLocationIds()!=null && !query.getLocationIds().isEmpty()){
            taskList = taskList.stream().filter(task -> query.getLocationIds().contains(task.getLocationId())).collect(Collectors.toList());
            if (taskList.isEmpty()){
                return R.ok(new PageInfo<>());
            }
        }
        query.setTaskIds(taskList.stream().map(TTask::getId).collect(Collectors.toList()));
        return R.ok(earlyWarningService.pageList(query));
    }
    @Log(title = "预警删除", businessType = BusinessType.DELETE)
    @ApiOperation(value = "预警删除")
    @DeleteMapping(value = "/delete")
    public R<Boolean> edit(@RequestParam String id) {
        earlyWarningService.removeById(id);
        return R.ok();
    }
}