package com.ruoyi.project.business.controller.train;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.annotation.DataUpdateCheck;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.domain.train.TtTrainTarget;
import com.ruoyi.project.business.domain.vo.train.TrainParticipantReq;
import com.ruoyi.project.business.domain.vo.train.TtTrainTargetVo;
import com.ruoyi.project.business.service.ITtTrainTargetService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

/**
 * 考核对象Controller
 *
 * @author ruoyi
 * @date 2024-06-18
 */
@RestController
@RequestMapping("/train/target")
@RequiredArgsConstructor
public class TtTrainTargetController extends BaseController {
    private final ITtTrainTargetService ttTrainTargetService;

    /**
     * 查询考核对象列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TtTrainTarget ttTrainTarget) {
        startPage();
        List<TtTrainTargetVo> list = ttTrainTargetService.selectTtTrainTargetList(ttTrainTarget);
        return getDataTable(list);
    }

    /**
     * 导出考核对象列表
     */
    @Log(title = "考核对象", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainParticipantReq req) {
//        List<TtTrainTarget> list = ttTrainTargetService.selectTtTrainTargetList(req);
//        ExcelUtil<TtTrainTarget> util = new ExcelUtil<TtTrainTarget>(TtTrainTarget.class);
//        util.exportExcel(response, list, "考核对象数据");
    }

    /**
     * 获取考核对象详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ttTrainTargetService.selectTtTrainTargetById(id));
    }

    /**
     * 新增考核对象
     */
    @Log(title = "考核对象", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TtTrainTarget ttTrainTarget) {
        return toAjax(ttTrainTargetService.insertTtTrainTarget(ttTrainTarget));
    }

    /**
     * 修改考核
     */
    @Log(title = "考核对象", businessType = BusinessType.UPDATE)
    @PutMapping
    @DataUpdateCheck(key="id",tableName = "tt_train_target")
    public AjaxResult edit(@RequestBody TtTrainTarget ttTrainTarget) {
        return toAjax(ttTrainTargetService.updateTtTrainTarget(ttTrainTarget));
    }

    /**
     * 修改学院培训状态
     */
    @Log(title = "考核对象", businessType = BusinessType.UPDATE)
    @PutMapping("/editTargetStatus")
    @DataUpdateCheck(key="id",tableName = "tt_train_target")
    public AjaxResult editTargetStatus(@RequestBody TtTrainTarget ttTrainTarget) {
        return toAjax(ttTrainTargetService.updateEditTargetStatus(ttTrainTarget));
    }


    /**
     * 删除考核对象
     */
    @Log(title = "考核对象", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ttTrainTargetService.deleteTtTrainTargetByIds(ids));
    }
}
