package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.SrsAddRecord;
import com.srs.comprehensive.domain.SrsStuYearS;
import com.srs.comprehensive.domain.Vo.CphRecord;
import com.srs.comprehensive.service.ISrsAddRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 加分规则记录Controller
 * 
 * @author srs
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/system/record")
public class SrsAddRecordController extends BaseController
{
    @Autowired
    private ISrsAddRecordService srsAddRecordService;

    @GetMapping("/listOwnRecord")
    public TableDataInfo listOwnRecord(){
        startPage();
        String stuNo = getUsername();
        List<CphRecord> list = srsAddRecordService.listOwnRecord(stuNo);
        return getDataTable(list);
    }


    /**
     * 查询加分规则记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrsAddRecord srsAddRecord)
    {
        startPage();
        List<SrsAddRecord> list = srsAddRecordService.selectSrsAddRecordList(srsAddRecord);
        return getDataTable(list);
    }

    /**
     * 查询本人申请的加分
     */
    @GetMapping("/selectApp")
    public AjaxResult selectApp(Long id){
        SrsAddRecord srsAddRecord = new SrsAddRecord();
        srsAddRecord.setRuleId(id);
        srsAddRecord.setApplicant(getUserId());
        return success(srsAddRecordService.selectSrsAddRecordList(srsAddRecord));
    }



    /**
     * 导出【加分规则记录】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "【导出】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsAddRecord srsAddRecord)
    {
        List<SrsAddRecord> list = srsAddRecordService.selectSrsAddRecordList(srsAddRecord);
        ExcelUtil<SrsAddRecord> util = new ExcelUtil<SrsAddRecord>(SrsAddRecord.class);
        util.exportExcel(response, list, "【加分规则记录】数据");
    }

    /**
     * 获取【加分规则记录】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(srsAddRecordService.selectSrsAddRecordById(id));
    }

    /**
     * 新增【加分规则记录】
     */
//    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "新增【加分规则记录】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsAddRecord srsAddRecord)
    {
        return toAjax(srsAddRecordService.insertSrsAddRecord(srsAddRecord));
    }

    /**
     * 修改【加分规则记录】
     */
//    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "修改【加分规则记录】", businessType = BusinessType.UPDATE)
    @PostMapping("/delete")
    public AjaxResult edit(@RequestBody SrsAddRecord srsAddRecord)
    {
        return toAjax(srsAddRecordService.updateSrsAddRecord(srsAddRecord));
    }

    /**
     * 删除【加分规则记录】
     */
//    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "删除【加分规则记录】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)//将url中的数据绑定到ids中
    {
        return toAjax(srsAddRecordService.deleteSrsAddRecordByIds(ids));
    }

//    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "修改删除【加分规则记录】", businessType = BusinessType.DELETE)
    @PostMapping("/delete/{ids}")//修改删除字段
    public AjaxResult removes(@PathVariable Long ids){
        return toAjax(srsAddRecordService.updateSrsAddRecordDelFlag(ids));
    }
}
