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.PmsProjectIssuesInputVo;
import com.microservices.pms.project.domain.vo.PmsProjectIssuesSearchVo;
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;



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

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

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

    /**
     * 删除项目周报
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam( "周报id数组，为-1时删除全部")@PathVariable Long[] ids, @ApiParam( "项目Id")@RequestParam(name = "pmProjectId") Long pmProjectId)
    {

        JSONObject result = pmsProjectIssuesService.deletePmsProjectIssueByIds(ids, pmProjectId);
        return success(result);
    }

    /**
     * 查看项目周报
     */
    @GetMapping("/{id}")
    public AjaxResult query(@PathVariable("id") Long id, @ApiParam( "项目Id")@RequestParam(name = "pmProjectId") Long pmProjectId)
    {

        JSONObject result = pmsProjectIssuesService.selectPmsProjectIssueById(id, pmProjectId);
        return success(result);
    }
}
