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.Logical;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.pms.product.domain.PmsProductModule;
import com.microservices.pms.product.domain.vo.*;
import com.microservices.pms.product.service.IPmsProductModuleService;
import com.microservices.pms.utils.PmsConstants;
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.*;

import java.util.List;

/**
 * 产品模块Controller
 * 
 * @author otto
 * @date 2023-10-10
 */
@RestController
@Api(tags = "项目管理-产品模块相关接口")
@RequestMapping("/{enterpriseIdentifier}/pmsProductModule")
@ApiImplicitParams({
        @ApiImplicitParam(name = "enterpriseIdentifier", value = "企业标识", paramType = "path", dataType = "String")
})
public class PmsProductModuleController extends BaseController
{
    @Autowired
    private IPmsProductModuleService pmsProductModuleService;

    /**
     * 查询产品模块树状列表
     */
    @RequiresPermissions(value = {"pms:pmsProduct:show"}, logical = Logical.OR)
    @GetMapping("/treeList")
    @ApiOperation(value = "查询产品模块树状列表")
    public GenericsAjaxResult<List<TreeSelect>> treeList(PmsProductModuleSearchVo pmsProductModuleSearchVo)
    {
        return genericsSuccess(pmsProductModuleService.selectPmsProductModuleTreeList(pmsProductModuleSearchVo.toPmsProductModule(), PmsConstants.PRODUCT_TAG_AND_MODULE_TYPE));
    }

    /**
     * 查询产品模块列表
     */
    @RequiresPermissions(value = {"pms:pmsProduct:show"}, logical = Logical.OR)
    @GetMapping("/list")
    @ApiOperation(value = "查询产品模块列表")
    public GenericsTableDataInfo<PmsProductModuleDataVo> list(PmsProductModuleSearchVo pmsProductModuleSearchVo)
    {
        startPage();
        return pmsProductModuleService.selectPmsProductModuleList(pmsProductModuleSearchVo.toPmsProductModule(), PmsConstants.PRODUCT_TAG_AND_MODULE_TYPE);
    }

    /**
     * 获取产品模块详细信息
     */
    @RequiresPermissions(value = {"pms:pmsProduct:show"}, logical = Logical.OR)
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取产品模块详细信息")
    public GenericsAjaxResult<PmsProductModule> getInfo(@PathVariable("id") Long id)
    {
        return genericsSuccess(pmsProductModuleService.selectPmsProductModuleById(id, false));
    }

    /**
     * 新增产品模块
     */
    @RequiresPermissions("pms:pmsProductModule:manage")
    @Log(title = "产品模块", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增产品模块")
    public AjaxResult add(@RequestBody @Validated PmsProductModuleInputVo pmsProductModule)
    {
        return success(pmsProductModuleService.insertPmsProductModule(pmsProductModule.toPmsProductModule(), PmsConstants.PRODUCT_TAG_AND_MODULE_TYPE));
    }

    /**
     * 修改产品模块
     */
    @RequiresPermissions("pms:pmsProductModule:manage")
    @Log(title = "产品模块", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改产品模块")
    public AjaxResult edit(@RequestBody @Validated PmsProductModuleUpdateVo pmsProductModuleUpdateVo)
    {
        return toAjax(pmsProductModuleService.updatePmsProductModule(pmsProductModuleUpdateVo.toPmsProductModule()));
    }

    /**
     * 删除产品模块
     */
    @RequiresPermissions("pms:pmsProductModule:manage")
    @Log(title = "产品模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    @ApiOperation(value = "删除产品模块")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(pmsProductModuleService.deletePmsProductModuleById(id));
    }
}
