package com.ankaibei.workFlow.webadmin.ankaibei.controller;

import com.ankaibei.workFlow.common.core.annotation.NoAuthInterface;
import com.ankaibei.workFlow.common.core.object.TokenData;
import com.ankaibei.workFlow.webadmin.ankaibei.api.ProjectInfoApi;
import com.ankaibei.workFlow.webadmin.ankaibei.enums.CodeEnum;
import com.ankaibei.workFlow.webadmin.ankaibei.service.impl.FileUtil;
import com.ankaibei.workFlow.webadmin.ankaibei.vo.ProjectInfoVo;
import com.ankaibei.workFlow.webadmin.ankaibei.vo.ResMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import java.io.IOException;
import java.util.List;

/**
 * @author lwq
 * @version 1.0
 * @description: 项目管理
 * @date 2022/9/14 11:06
 */
@RestController
@RequestMapping("/project")
public class ProjectInfoController {

    @Autowired
    private ProjectInfoApi projectInfoApi;

    @Resource
    private FileUtil fileUtil;

    private final ServletContext context;

    public ProjectInfoController(ServletContext context) {
        this.context = context;
    }


    /**
     * 查询项目
     *
     * @param projectInfoVo
     * @return ResMsg
     */
    @RequestMapping("/findProjectInfo")
    public ResMsg findProjectInfo(@RequestBody ProjectInfoVo projectInfoVo) {

        return projectInfoApi.findProjectInfo(projectInfoVo);
    }

    /**
     * 查询项目--项目名称模糊查询
     *
     * @param projectName
     * @return ResMsg
     */
    @NoAuthInterface
    @RequestMapping("/findProjectInfoAll")
    public ResMsg findProjectInfoAll(@RequestParam String projectName) {
        return projectInfoApi.findProjectInfoAll(projectName);
    }

    /**
     * 查询项目详情
     *
     * @param projectInfoVo
     * @return ResMsg
     */
    @RequestMapping("/findProjectParticulars")
    public ResMsg findProjectParticulars(@RequestBody ProjectInfoVo projectInfoVo) {

        return projectInfoApi.findProjectParticulars(projectInfoVo);
    }

    /**
     * 项目数量趋势图(当月)
     *
     * @param
     * @return ResMsg
     */
    @RequestMapping("/findProjectNumber")
    public ResMsg findProjectNumber() {

        return projectInfoApi.findProjectNumber();
    }

    /**
     * 项目对应所属公司的数量分布图(当月)
     *
     * @param
     * @return ResMsg
     */
    @RequestMapping("/substepOfProjectNum")
    public ResMsg substepOfProjectNum() {
        return projectInfoApi.substepOfProjectNum();
    }

    /**
     * 项目数量趋势图(上月)
     *
     * @param
     * @return ResMsg
     */
    @RequestMapping("/findLastMonthProjectNumber")
    public ResMsg findLastMonthProjectNumber() {

        return projectInfoApi.findLastMonthProjectNumber();
    }

    /**
     * 项目对应所属公司的数量分布图(当月)
     *
     * @param
     * @return ResMsg
     */
    @RequestMapping("/substepOfProjectNumAtLastMonth")
    public ResMsg substepOfProjectNumAtLastMonth() {
        return projectInfoApi.substepOfProjectNumAtLastMonth();
    }

    /**
     * 查询附件信息
     *
     * @param projectInfoVo
     * @return ResMsg
     */
    @RequestMapping("/findAccesoryInfo")
    public ResMsg findAccesoryInfo(@RequestBody ProjectInfoVo projectInfoVo) {

        return projectInfoApi.findAccesoryInfo(projectInfoVo);
    }


    /**
     * 查询当前登录人负责的项目
     *
     * @param
     * @return ResMsg
     */
    @RequestMapping("/findPrincipalProject")
    public ResMsg findPrincipalProject() {
        return projectInfoApi.findPrincipalProject(TokenData.takeFromRequest().getUserId());
    }


    /**
     * 编辑项目
     *
     * @param projectInfoVo
     * @return ResMsg
     */
    @RequestMapping("/updateProject")
    public ResMsg updateProject(@RequestBody ProjectInfoVo projectInfoVo) {

        return projectInfoApi.updateProject(projectInfoVo);
    }

    /**
     * 删除项目
     *
     * @param projectInfoVos
     * @return ResMsg
     */
    @RequestMapping("/deleteProject")
    public ResMsg deleteProject(@RequestBody List<ProjectInfoVo> projectInfoVos) {

        return projectInfoApi.deleteProjects(projectInfoVos);
    }

    /**
     * 新建项目
     *
     * @param projectInfoVo
     * @return ResMsg
     */
    @RequestMapping("/addProject")
    public ResMsg addProject(@RequestBody ProjectInfoVo projectInfoVo) {


        return projectInfoApi.addProject(projectInfoVo);
    }

    /**
     * 文件上传
     *
     * @param
     * @return ResMsg
     */
    @RequestMapping("/upload")
    public ResMsg upload(MultipartFile upload) throws IOException {


        return new ResMsg(CodeEnum.OK, fileUtil.uploadOne(upload));
    }

}
