package com.ruoyi.project.production.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.production.domain.TMonthlyQualityComment;
import com.ruoyi.project.production.service.ITMonthlyQualityCommentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 质量月报评价Controller
 *
 * @author ssy
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/production/comment")
public class TMonthlyQualityCommentController extends BaseController
{
    @Autowired
    private ITMonthlyQualityCommentService tMonthlyQualityCommentService;

    /**
     * 提交质量月报评价
     */
    @PutMapping("/submitComment")
    public AjaxResult submitComment(@RequestBody TMonthlyQualityComment tMonthlyQualityComment)
    {
        TMonthlyQualityComment result = tMonthlyQualityCommentService.selectTMonthlyQualityCommentByTypeAndDate(tMonthlyQualityComment);
        if (result != null) {
            result.setQualityComment(tMonthlyQualityComment.getQualityComment());
            tMonthlyQualityCommentService.updateTMonthlyQualityComment(result);
        } else {
            tMonthlyQualityCommentService.insertTMonthlyQualityComment(tMonthlyQualityComment);
        }
        return AjaxResult.success();
    }

    /**
     * 获取质量月报评价详细信息
     */
    @GetMapping("/getComment")
    public AjaxResult getComment(TMonthlyQualityComment tMonthlyQualityComment)
    {
        return AjaxResult.success(tMonthlyQualityCommentService.selectTMonthlyQualityCommentByTypeAndDate(tMonthlyQualityComment));
    }

    /**
     * 查询质量月报评价列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TMonthlyQualityComment tMonthlyQualityComment)
    {
        startPage();
        List<TMonthlyQualityComment> list = tMonthlyQualityCommentService.selectTMonthlyQualityCommentList(tMonthlyQualityComment);
        return getDataTable(list);
    }

    /**
     * 导出质量月报评价列表
     */
    @Log(title = "质量月报评价", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMonthlyQualityComment tMonthlyQualityComment)
    {
        List<TMonthlyQualityComment> list = tMonthlyQualityCommentService.selectTMonthlyQualityCommentList(tMonthlyQualityComment);
        ExcelUtil<TMonthlyQualityComment> util = new ExcelUtil<TMonthlyQualityComment>(TMonthlyQualityComment.class);
        return util.exportExcel(list, "comment");
    }

    /**
     * 获取质量月报评价详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMonthlyQualityCommentService.selectTMonthlyQualityCommentById(id));
    }

    /**
     * 新增质量月报评价
     */
    @Log(title = "质量月报评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMonthlyQualityComment tMonthlyQualityComment)
    {
        return toAjax(tMonthlyQualityCommentService.insertTMonthlyQualityComment(tMonthlyQualityComment));
    }

    /**
     * 修改质量月报评价
     */
    @Log(title = "质量月报评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMonthlyQualityComment tMonthlyQualityComment)
    {
        return toAjax(tMonthlyQualityCommentService.updateTMonthlyQualityComment(tMonthlyQualityComment));
    }

    /**
     * 删除质量月报评价
     */
    @Log(title = "质量月报评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMonthlyQualityCommentService.deleteTMonthlyQualityCommentByIds(ids));
    }
}
