package com.ruoyi.web.controller.invest;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.invest.service.ITProjectCirculationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.invest.domain.TProjectReview;
import com.ruoyi.invest.service.ITProjectReviewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评审记录Controller
 * 
 * @author zjc
 * @date 2024-04-02
 */
@Api(tags = "评审记录")
@RestController
@RequestMapping("/invest/review")
public class TProjectReviewController extends BaseController
{
    @Autowired
    private ITProjectReviewService tProjectReviewService;

    @Autowired
    private ITProjectCirculationService tProjectCirculationService;

    /**
     * 查询评审记录列表
     */
    @ApiOperation("查询评审记录列表")
    @GetMapping("/list")
    public TableDataInfo list(TProjectReview tProjectReview)
    {
        startPage();
        List<TProjectReview> list = tProjectReviewService.selectTProjectReviewList(tProjectReview);
        return getDataTable(list);
    }

    /**
     * 导出评审记录列表
     */
    @ApiOperation("导出评审记录列表")
    @Log(title = "评审记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProjectReview tProjectReview)
    {
        List<TProjectReview> list = tProjectReviewService.selectTProjectReviewList(tProjectReview);
        ExcelUtil<TProjectReview> util = new ExcelUtil<TProjectReview>(TProjectReview.class);
        util.exportExcel(response, list, "评审记录数据");
    }

    /**
     * 获取评审记录详细信息
     */
    @ApiOperation("获取评审记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tProjectReviewService.selectTProjectReviewById(id));
    }

    /**
     * 新增评审记录
     */
    @ApiOperation("新增评审记录")
    @Log(title = "评审记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProjectReview tProjectReview)
    {
        tProjectReview.setCreateBy(getNickName());
        tProjectReview.setReviewPerson(getNickName());
        tProjectReview.setReviewPersonId(getUserId().toString());

        // todo 增加上传评审意见记录
        tProjectCirculationService.insertTProjectCirculation(tProjectReview.getProjectPoolId(),"上传评估考察意见",getNickName());

        return toAjax(tProjectReviewService.insertTProjectReview(tProjectReview));
    }

    /**
     * 修改评审记录
     */
    @ApiOperation("修改评审记录")
    @Log(title = "评审记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProjectReview tProjectReview)
    {
        return toAjax(tProjectReviewService.updateTProjectReview(tProjectReview));
    }

    /**
     * 删除评审记录
     */
    @ApiOperation("删除评审记录")
    @Log(title = "评审记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tProjectReviewService.deleteTProjectReviewByIds(ids));
    }
}
