package com.microservices.pms.product.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.domain.GenericsAjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.pms.product.domain.vo.PmsProductPlanDataVo;
import com.microservices.pms.product.domain.vo.PmsProductPlanInputVo;
import com.microservices.pms.product.domain.vo.PmsProductPlanSearchVo;
import com.microservices.pms.product.domain.vo.PmsProductPlanUpdateVo;
import com.microservices.pms.product.service.IPmsProductPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 产品计划Controller
 *
 * @author microservices
 * @date 2023-10-10
 */
@RestController
@Api(tags = "项目管理-产品计划相关接口")
@RequestMapping("/{enterpriseIdentifier}/pmsProductPlan")
@ApiImplicitParams({
        @ApiImplicitParam(name = "enterpriseIdentifier", value = "企业标识", paramType = "path", dataType = "String")
})
public class PmsProductPlanController extends BaseController
{
    @Autowired
    private IPmsProductPlanService pmsProductPlanService;

    /**
     * 查询产品计划列表
     */
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping("/list")
    @ApiOperation(value = "查询产品计划列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前记录起始索引", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "orderByColumn", value = "排序列（开始时间：startTime，结束时间：endTime，产品需求数：productRequirementCount，优先级：priorityId）", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc,默认asc", paramType = "query", dataType = "String")
    })
    public GenericsTableDataInfo<PmsProductPlanDataVo> list(@Validated PmsProductPlanSearchVo pmsProductPlanSearchVo)
    {
        return pmsProductPlanService.selectPmsProductPlanList(pmsProductPlanSearchVo.toPmsProductPlan());
    }

    /**
     * 获取产品计划详细信息
     */
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取产品计划详细信息")
    public GenericsAjaxResult<PmsProductPlanDataVo> getInfo(@PathVariable("id") Long id)
    {
        return genericsSuccess(pmsProductPlanService.selectPmsProductPlanDataById(id));
    }

    /**
     * 新增产品计划
     */
    @RequiresPermissions("pms:pmsProductPlan:add")
    @Log(title = "产品计划", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增产品计划")
    public AjaxResult add(@RequestBody @Validated PmsProductPlanInputVo pmsProductPlanInputVo)
    {
        return success(pmsProductPlanService.insertPmsProductPlan(pmsProductPlanInputVo.toPmsProductPlan()));
    }

    /**
     * 修改产品计划
     */
    @RequiresPermissions("pms:pmsProductPlan:edit")
    @Log(title = "产品计划", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改产品计划")
    public AjaxResult edit(@RequestBody @Validated PmsProductPlanUpdateVo pmsProductPlanUpdateVo)
    {
        return toAjax(pmsProductPlanService.updatePmsProductPlan(pmsProductPlanUpdateVo.toPmsProductPlan()));
    }

    /**
     * 删除产品计划
     */
    @RequiresPermissions("pms:pmsProductPlan:remove")
    @Log(title = "产品计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value = "删除产品计划")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsProductPlanService.deletePmsProductPlanByIds(ids));
    }
}
