package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.iot.domain.PmProject;
import com.usky.iot.service.PmProjectService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 项目表 前端控制器
 * </p>
 *
 * @author fu
 * @since 2024-05-20
 */
@RestController
@RequestMapping("/pmProject")
public class PmProjectController {
    @Autowired
    private PmProjectService pmProjectService;

    /**
     * 查询项目名（下拉框）
     *
     * @return
     */
    @GetMapping("/projects")
    public ApiResult<List<PmProject>> queryProjectName() {
        return ApiResult.success(pmProjectService.queryProject());
    }

    /**
     * 分页
     *
     * @param projectName
     * @param projectType
     * @param projectStatus
     * @param projectAscription
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public ApiResult<CommonPage<PmProject>> pageList(@RequestParam(value = "projectName", required = false, defaultValue = "") String projectName,
                                                     @RequestParam(value = "projectType", required = false, defaultValue = "0") Integer projectType,
                                                     @RequestParam(value = "projectStatus", required = false, defaultValue = "0") Integer projectStatus,
                                                     @RequestParam(value = "projectAscription", required = false, defaultValue = "0") Integer projectAscription,
                                                     @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(pmProjectService.projectList(projectName, projectType, projectStatus, projectAscription, pageNum, pageSize));
    }

    /**
     * 统计
     *
     * @return
     */
    @GetMapping("/counting")
    public ApiResult<Map<String, Integer>> count() {
        return ApiResult.success(pmProjectService.sum());
    }

    /**
     * 新增、编辑项目
     *
     * @param pmProject
     */
    @PostMapping("/add")
    public void add(@RequestBody PmProject pmProject) {
        pmProjectService.addProject(pmProject);
    }

    /**
     * 删除
     *
     * @param projectId 项目id
     */
    @GetMapping("/del")
    public void del(@RequestParam Integer projectId) {
        pmProjectService.delProject(projectId);
    }

    /**
     * 人员、项目下拉
     *
     * @param identifying
     * @return
     */
    @GetMapping("/userOrProject")
    public ApiResult<List<Map<String, Object>>> userOrProject(@RequestParam(value = "identifying", required = false) Integer identifying) {
        return ApiResult.success(pmProjectService.userOrProject(identifying));
    }

}

