package com.hotent.enterpriseDeclare.controller.opinion;

import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.model.CommonResult;
import com.hotent.constant.BaseConstant;
import com.hotent.project.manager.CostProjectTaskPreliminaryOpinionManager;
import com.hotent.project.model.CostProjectTaskPreliminaryOpinion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 成本审核意见控制器（包含初步意见、反馈意见、结论意见）
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-01-27
 */
@Api(tags = "成本审核意见管理")
@RestController
@RequestMapping("/api/enterprise/opinion")
@ApiGroup(group = {ApiGroupConsts.GROUP_COST})
public class CostProjectTaskPreliminaryOpinionController {

    @Autowired
    private CostProjectTaskPreliminaryOpinionManager opinionManager;

    /**
     * 根据任务ID获取审核意见
     */
    @GetMapping(value = "/getByTaskId")
    @ApiOperation(value = "根据任务ID获取审核意见", httpMethod = "GET", notes = "根据任务ID获取审核意见（包含初步意见、反馈意见、结论意见）")
    public CommonResult<CostProjectTaskPreliminaryOpinion> getByTaskId(@RequestParam String taskId) {
        CostProjectTaskPreliminaryOpinion opinion = opinionManager.getByTaskId(taskId);
        return CommonResult.<CostProjectTaskPreliminaryOpinion>ok().value(opinion);
    }

    /**
     * 新增或更新审核意见
     */
    @PostMapping(value = "/save")
    @ApiOperation(value = "新增或更新审核意见", httpMethod = "POST", notes = "新增或更新审核意见（包含初步意见、反馈意见、结论意见）")
    public CommonResult<String> save(@RequestBody CostProjectTaskPreliminaryOpinion opinion) {
        opinionManager.createOrUpdate(opinion);
        return CommonResult.<String>ok().value("保存成功");
    }

    /**
     * 删除审核意见
     */
    @PostMapping(value = "/delete")
    @ApiOperation(value = "删除审核意见", httpMethod = "POST", notes = "删除审核意见")
    public CommonResult<String> delete(@RequestParam String id) {
        CostProjectTaskPreliminaryOpinion opinion = opinionManager.getById(id);
        if (opinion != null) {
            opinion.setIsDeleted(BaseConstant.DELETE_FLAG);
            opinionManager.updateById(opinion);
        }
        return CommonResult.<String>ok().value("删除成功");
    }
}

