package com.microservices.pms.project.controller;

import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.pms.project.domain.vo.*;
import com.microservices.pms.project.service.IPmsIssueCompletionService;
import com.microservices.pms.project.service.PmsProjectIssuesService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.microservices.common.core.web.domain.AjaxResult.success;

/**
 * 项目周报Controller
 *
 * @author wanjia
 * @date 2023-10-13
 */
@RestController
@RequestMapping("/{enterpriseIdentifier}/pmsProjectWeeklyReport")
@Api(tags = "项目管理-项目周报相关接口")
@ApiImplicitParams({
        @ApiImplicitParam(name = "enterpriseIdentifier", value = "企业标识", paramType = "path", dataType = "String")
})
public class PmsProjectWeeklyReportController {

    @Autowired
    private PmsProjectIssuesService pmsProjectIssuesService;

    @Autowired
    private IPmsIssueCompletionService pmsIssueCompletionService;

    /**
     * 查询项目周报列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "项目周报列表")
    public AjaxResult list(@PathVariable String enterpriseIdentifier, PmsProjectIssuesSearchVo pmsProjectIssuesSearchVo)
    {
        pmsProjectIssuesSearchVo.setEnterpriseIdentifier(enterpriseIdentifier);
        JSONObject result = pmsProjectIssuesService.selectPmsProjectIssuesList(pmsProjectIssuesSearchVo);
        return success(result);
    }

    /**
     * 查询周报-个人工作项统计
     */
    @GetMapping("/personal")
    @ApiOperation(value = "周报-个人工作项统计")
    public AjaxResult getPersonalWeeklyReport(@PathVariable String enterpriseIdentifier, PmsPersonalWeeklyReportSearchVo pmsPersonalWeeklyReportSearchVo)
    {
        JSONObject result = pmsProjectIssuesService.getPersonalIssuesStatistics(enterpriseIdentifier, pmsPersonalWeeklyReportSearchVo);
        return success(result);
    }

    @GetMapping("/personalIssueList")
    @ApiOperation(value = "周报-个人工作项列表")
    public AjaxResult getPersonalIssueList(@PathVariable String enterpriseIdentifier, PmsPersonalWeeklyIssuesSearchVo pmsPersonalWeeklyIssuesSearchVo)
    {
        pmsPersonalWeeklyIssuesSearchVo.setEnterpriseIdentifier(enterpriseIdentifier);
        JSONObject result = pmsProjectIssuesService.getPersonalIssueList(pmsPersonalWeeklyIssuesSearchVo);
        return success(result);
    }

    /**
     * 查询周报-项目组工作项统计
     */
    @GetMapping("/projectTeam")
    @ApiOperation(value = "周报-项目组工作项统计")
    public AjaxResult getProjectTeamWeeklyReport(@PathVariable String enterpriseIdentifier, PmsTeamWeeklyReportSearchVo pmsTeamWeeklyReportSearchVo)
    {
        JSONObject result = pmsProjectIssuesService.getProjectTeamIssuesStatistics(enterpriseIdentifier, pmsTeamWeeklyReportSearchVo);
        return success(result);
    }

    @GetMapping("/projectIssueList")
    @ApiOperation(value = "周报-项目组工作项列表")
    public AjaxResult getProjectIssueList(@PathVariable String enterpriseIdentifier, PmsProjectIssuesSearchVo pmsProjectIssuesSearchVo)
    {
        pmsProjectIssuesSearchVo.setEnterpriseIdentifier(enterpriseIdentifier);
        JSONObject result = pmsProjectIssuesService.getProjectIssueList(pmsProjectIssuesSearchVo);
        return success(result);
    }

    /**
     * 新增项目项目周报
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增项目周报")
    public AjaxResult add(@PathVariable String enterpriseIdentifier, @RequestBody PmsProjectIssuesInputVo pmsProjectIssuesInputVo)
    {
        pmsProjectIssuesInputVo.setEnterpriseIdentifier(enterpriseIdentifier);
        JSONObject result = pmsProjectIssuesService.insertPmsProjectWeeklyReportIssues(pmsProjectIssuesInputVo);
        return success(result);
    }

    /**
     * 更新项目周报
     */
    @PostMapping("/edit/{id}")
    @ApiOperation(value = "编辑项目周报")
    public AjaxResult edit(@PathVariable("id") Long id, @RequestBody PmsProjectIssuesInputVo pmsProjectIssuesInputVo)
    {
        JSONObject result = pmsProjectIssuesService.updatePmsProjectWeeklyReportIssues(id, pmsProjectIssuesInputVo);
        return success(result);
    }

    /**
     * 删除项目周报
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除项目周报")
    public AjaxResult remove(@ApiParam( "周报id")@PathVariable Long id)
    {

        JSONObject result = pmsProjectIssuesService.deletePmsProjectWeeklyReportIssueByIds(id);
        return success(result);
    }

    /**
     * 查看项目周报
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查看项目周报")
    public AjaxResult query(@PathVariable String enterpriseIdentifier, @PathVariable("id") Long id)
    {

        JSONObject result = pmsProjectIssuesService.selectPmsProjectIssueByIdAndEnterPrise(id, enterpriseIdentifier);
        return success(result);
    }

    /**
     * 更新工作项完成情况
     */
    @PutMapping("/issueCompletion")
    @ApiOperation(value = "更新工作项完成情况")
    public AjaxResult issueCompletion(@RequestBody PmsProjectIssuesCompletionInputVo pmsProjectIssuesCompletionInputVo)
    {
        return success(pmsIssueCompletionService.saveOrUpdateCompletion(pmsProjectIssuesCompletionInputVo));
    }
}
