package cn.wisenergy.web.admin.controller.app;

import cn.wisenergy.common.utils.exception.Result;
import cn.wisenergy.model.app.WorkDept;
import cn.wisenergy.model.app.WorkProjectChange;
import cn.wisenergy.model.dto.DeptOfProjectAndOrderType;
import cn.wisenergy.model.dto.OrderChangeDto;
import cn.wisenergy.model.vo.CreateProjectVo;
import cn.wisenergy.model.vo.GetManagerProjectsVo;
import cn.wisenergy.model.vo.ModifyProjectVo;
import cn.wisenergy.service.WorkDeptService;
import cn.wisenergy.service.WorkProjectChangeService;
import cn.wisenergy.service.WorkProjectService;
import cn.wisenergy.web.admin.controller.common.BaseController;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: nh
 * @create: 2021-01-20 16:47
 **/
@RestController
@Api(tags = "项目模块")
@RequestMapping(value = "/work/project")
@Slf4j
public class WorkProjectController  extends BaseController {

    @Autowired
    private WorkProjectService workProjectService;

    @Autowired
    private WorkDeptService workDeptService;

    @Autowired
    private WorkProjectChangeService workProjectChangeService;

    @ApiOperation(value = "项目/商机基础信息", notes = "项目/商机基础信息", httpMethod = "POST")
    @ApiImplicitParam(name = "gmpv",value = "获取管理的项目/商机",dataType = "GetManagerProjectsVo")
    @PostMapping(value = "/getProject")
    public Result<PageInfo> getProject(@RequestBody GetManagerProjectsVo gmpv) {
        log.info("WorkProjectController[]getProject[]input.param.GetManagerProjectsVo:{}" + gmpv);
        PageInfo managerProjects = workProjectService.getManagerProjects(gmpv);
        return getResult(managerProjects);
    }

    @ApiOperation(value = "结束项目/商机", notes = "结束项目/商机", httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "管理员id",dataType = "int"),
            @ApiImplicitParam(name = "projectId",value = "项目id",dataType = "int")
    })
    @PutMapping(value = "/endProject")
    public Result<Boolean> endProject(Integer userId,Integer projectId) {
        log.info("WorkProjectController[]endProject[]input.param.userId:{},projectId:{}" + userId,projectId);
        Boolean aBoolean = workProjectService.endProject(userId,projectId);
        return getResult(aBoolean);
    }


    @ApiOperation(value = "编辑项目/商机", notes = "编辑项目/商机", httpMethod = "PUT")
    @ApiImplicitParam(name = "modifyProjectVo", value = "编辑内容", dataType = "ModifyProjectVo", required = true)
    @PutMapping(value = "/modifyProject")
    public Result<Boolean> modifyProject(@RequestBody ModifyProjectVo modifyProjectVo) {
        log.info("WorkProjectController[]endProject[]input.param.modifyProjectVo:{}" + modifyProjectVo);
        Boolean aBoolean = workProjectService.modifyProject(modifyProjectVo);
        return getResult(aBoolean);
    }

    @ApiOperation(value = "查看项目/商机详情", notes = "查看项目/商机详情", httpMethod = "GET")
    @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", required = true)
    @GetMapping(value = "/getProjectInfo")
    public Result<WorkProjectChange> getProjectInfo(Integer projectId) {
        log.info("WorkProjectController[]getProjectInfo[]input.param.projectId:{}" + projectId);
        List<WorkProjectChange> workProjectChanges = workProjectChangeService.getByProjectId(projectId);
        return getResult(workProjectChanges);
    }

    @ApiOperation(value = "新增项目/商机", notes = "新增项目/商机", httpMethod = "POST")
    @ApiImplicitParam(name = "createProjectVo",value = "添加项目Vo类",dataType = "CreateProjectVo",required = true)
    @PostMapping(value = "/addProject")
    public Result<Boolean> addProject(@RequestBody CreateProjectVo createProjectVo) {
        log.info("WorkProjectController[]addProject[]input.param.createProjectVo:{}" + createProjectVo);
        Boolean aBoolean = workProjectService.addProject(createProjectVo);
        return getResult(aBoolean);
    }

    @ApiOperation(value = "获取所管理项目的部门(项目/商机管理)", notes = "获取所管理项目的部门(项目/商机管理)")
    @ApiImplicitParam(name = "userId", value = "管理员id",required = true)
    @GetMapping("/getDeptOfProject")
    public Result<List<WorkDept>> getDeptOfProject(Integer userId) {
        log.info("WorkProjectController[]getDeptOfProject[]input.param.userId" + userId);
        List<WorkDept> deptOfProjectOfManager = workDeptService.getDeptOfProjectOfManager(userId);
        return getResult(deptOfProjectOfManager);
    }

    @ApiOperation(value = "查询所管理的项目和所属部门(工单变更管理)", notes = "查询所管理的项目和所属部门(工单变更管理)", httpMethod = "GET")
    @ApiImplicitParam(name = "userId", value = "管理员Id", dataType = "int", required = true)
    @GetMapping("/getProjectAndTypeAndDept")
    public Result getProjectAndOrderTypeAndDept(Integer userId) {
        log.info("WorkProjectController[]getProjectAndOrderTypeAndDept[]input.param.userId" + userId);
        OrderChangeDto orderChangeDto = workProjectService.getProjectAndOrderTypeAndDept(userId);
        return getResult(orderChangeDto);
    }

    @ApiOperation(value = "查询所管理的项目和所属部门(工单变更管理记录)", notes = "查询所管理的项目和所属部门(工单变更管理记录)", httpMethod = "GET")
    @ApiImplicitParam(name = "userId", value = "管理员Id", dataType = "int", required = true)
    @GetMapping("/getProjectOfFind")
    public Result getProjectOfFind(Integer userId) {
        log.info("WorkProjectController[]getProjectAndOrderTypeAndDept[]input.param.userId" + userId);
        List<DeptOfProjectAndOrderType> projectOfFind = workProjectService.getProjectOfFind(userId);
        return getResult(projectOfFind);
    }


}
