package com.microservices.pms.journals.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.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.pms.journals.domain.PmsJournals;
import com.microservices.pms.journals.domain.vo.*;
import com.microservices.pms.journals.service.IPmsJournalsService;
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-11-01
 */
@RestController
@RequestMapping("/{enterpriseIdentifier}/pmsJournals")
@Api(tags = "项目管理-评论相关接口")
public class PmsJournalsController extends BaseController
{
    @Autowired
    private IPmsJournalsService pmsJournalsService;

    /**
     * 查询评论列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询评论列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前记录起始索引", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "Integer")
    })
    public GenericsAjaxResult<PmsJournalsDataTableVo> list(@Validated PmsJournalsSearchVo pmsJournalsSearchVo)
    {
        startPage();
        List<PmsJournalsParentDataVo> list = pmsJournalsService.selectPmsJournalsList(pmsJournalsSearchVo.toPmsJournals());
        return genericsSuccess(PmsJournalsDataTableVo.toPmsJournalsDataTableVo(getDataTable(list)));
    }

    /**
     * 获取评论功能详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取评论详细信息")
    public GenericsAjaxResult<PmsJournals> getInfo(@PathVariable("id") Long id)
    {
        return genericsSuccess(pmsJournalsService.selectPmsJournalsById(id));
    }

    /**
     * 添加评论
     */
    @Log(title = "评论功能", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "添加评论")
    public AjaxResult add(@RequestBody @Validated PmsJournalsInputVo pmsJournalsInputVo)
    {
        return toAjax(pmsJournalsService.insertPmsJournals(pmsJournalsInputVo.toPmsJournals()));
    }

    /**
     * 修改评论功能
     */
    @Log(title = "评论功能", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改评论")
    public AjaxResult edit(@RequestBody@Validated PmsJournalsUpdateVo pmsJournalsUpdateVo)
    {
        return toAjax(pmsJournalsService.updatePmsJournals(pmsJournalsUpdateVo.toPmsJournals()));
    }

    /**
     * 删除评论功能
     */
    @Log(title = "评论功能", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    @ApiOperation(value = "删除评论")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(pmsJournalsService.deletePmsJournalsById(id));
    }
}
