package com.cirs.biz.controller;

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

import com.cirs.biz.domain.FactoryScore;
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.cirs.common.annotation.Log;
import com.cirs.common.core.controller.BaseController;
import com.cirs.common.core.domain.AjaxResult;
import com.cirs.common.enums.BusinessType;
import com.cirs.biz.domain.TMarkingrecord;
import com.cirs.biz.service.ITMarkingrecordService;
import com.cirs.common.utils.poi.ExcelUtil;
import com.cirs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 打分记录Controller
 * 
 * @author allen
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/biz/markingrecord")
public class TMarkingrecordController extends BaseController
{
    @Autowired
    private ITMarkingrecordService tMarkingrecordService;

    /**
     * 查询打分记录列表
     */
    @PreAuthorize("@ss.hasPermi('biz:markingrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMarkingrecord tMarkingrecord)
    {
        startPage();
        List<TMarkingrecord> list = tMarkingrecordService.selectTMarkingrecordList(tMarkingrecord);
        return getDataTable(list);
    }

    /**
     * 导出打分记录列表
     */
    @PreAuthorize("@ss.hasPermi('biz:markingrecord:export')")
    @Log(title = "打分记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMarkingrecord tMarkingrecord)
    {
        List<TMarkingrecord> list = tMarkingrecordService.selectTMarkingrecordList(tMarkingrecord);
        ExcelUtil<TMarkingrecord> util = new ExcelUtil<TMarkingrecord>(TMarkingrecord.class);
        util.exportExcel(response, list, "打分记录数据");
    }

    /**
     * 获取打分记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:markingrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tMarkingrecordService.selectTMarkingrecordById(id));
    }

    /**
     * 新增打分记录
     */
    @PreAuthorize("@ss.hasPermi('biz:markingrecord:add')")
    @Log(title = "打分记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMarkingrecord tMarkingrecord)
    {
        return toAjax(tMarkingrecordService.insertTMarkingrecord(tMarkingrecord));
    }

    /**
     * 修改打分记录
     */
    @PreAuthorize("@ss.hasPermi('biz:markingrecord:edit')")
    @Log(title = "打分记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMarkingrecord tMarkingrecord)
    {
        return toAjax(tMarkingrecordService.updateTMarkingrecord(tMarkingrecord));
    }

    /**
     * 删除打分记录
     */
    @PreAuthorize("@ss.hasPermi('biz:markingrecord:remove')")
    @Log(title = "打分记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMarkingrecordService.deleteTMarkingrecordByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('biz:markingrecord:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TMarkingrecord> util = new ExcelUtil<TMarkingrecord>(TMarkingrecord.class);
        List<TMarkingrecord> markingrecordList = util.importExcel(file.getInputStream());

        String operName = getUsername();
        String message = tMarkingrecordService.importMarkingrecord(markingrecordList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<TMarkingrecord> util = new ExcelUtil<TMarkingrecord>(TMarkingrecord.class);
        util.importTemplateExcel(response, "训练集数据");
    }
}
