package com.zd.exam.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.common.swagger.config.Knife4jConfiguration;
import com.zd.exam.domain.ElPassConfigdetail;
import com.zd.exam.domain.ElPassMarkconfig;
import com.zd.exam.domain.vo.ElPassMarkconfigVO;
import com.zd.exam.service.IElPassConfigdetailService;
import com.zd.exam.service.IElPassMarkconfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 信用合格分设置Controller
 *
 * @author zd
 * @date 2021-12-14
 */
@RestController
@Api(tags = "【信用合格分设置】")
//作者手动加入 ，在接口上加作者@ApiOperationSupport(author = "XXX")
@ApiSupport(author = Knife4jConfiguration.Author.CYL)
@RequestMapping("/markconfig")
public class ElPassMarkconfigController extends BaseController
{
    @Autowired
    private IElPassMarkconfigService elPassMarkconfigService;
    @Autowired
    private IElPassConfigdetailService elPassConfigdetailService;

    /**
     * 查询信用合格分设置列表  "exam:markconfig:list"
     */
    @PreAuthorize(hasPermi = PerPrefix.EXAM_MARKCONFIG+ PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询信用合格分设置列表",notes="权限字符："+PerPrefix.EXAM_MARKCONFIG+ PerFun.LIST)
    public TableDataInfo<ElPassMarkconfigVO> list(ElPassMarkconfig elPassMarkconfig)
    {
        startPage();
        List<ElPassMarkconfigVO> list = elPassMarkconfigService.selectElPassMarkconfigList(elPassMarkconfig);
        return getDataTable(list);
    }

    /**
     * 导出信用合格分设置列表  "exam:markconfig:export"
     */
    @ApiOperation(value = "导出信用合格分设置列表",notes="权限字符："+PerPrefix.EXAM_MARKCONFIG+ PerFun.EXPORT)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_MARKCONFIG+ PerFun.EXPORT)
    @Log(title = "信用合格分设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElPassMarkconfig elPassMarkconfig) throws IOException
    {
        List<ElPassMarkconfigVO> list = elPassMarkconfigService.selectElPassMarkconfigList(elPassMarkconfig);
        ExcelUtil<ElPassMarkconfigVO> util = new ExcelUtil<ElPassMarkconfigVO>(ElPassMarkconfigVO.class);
        util.exportExcel(response, list, "信用合格分设置数据");
    }

    /**
     * 获取信用合格分设置详细信息  "exam:markconfig:query"
     */
    @ApiOperation(value = "获取信用合格分设置详细信息",notes="权限字符："+PerPrefix.EXAM_MARKCONFIG+ PerFun.QUERY)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_MARKCONFIG+ PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(elPassMarkconfigService.selectElPassMarkconfigById(id));
    }

    /**
     * 新增信用合格分设置  "exam:markconfig:add"
     */
    @ApiOperation(value = "新增信用合格分设置" ,notes="权限字符："+PerPrefix.EXAM_MARKCONFIG+ PerFun.ADD)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_MARKCONFIG+ PerFun.ADD)
    @Log(title = "信用合格分设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElPassMarkconfig elPassMarkconfig)
    {
        return toAjax(elPassMarkconfigService.insertElPassMarkconfig(elPassMarkconfig));
    }


    /**
     * 新增信用合格分和详情  "exam:markconfig:add"
     */
    @ApiOperation(value = "新增信用合格分和详情" ,notes="权限字符："+PerPrefix.EXAM_MARKCONFIG+ PerFun.ADD)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_MARKCONFIG+ PerFun.ADD)
    @Log(title = "信用合格分设置", businessType = BusinessType.INSERT)
    @PostMapping("/addpassmark")
    public AjaxResult addPassMark(@RequestBody ElPassMarkconfigVO elPassMarkconfigVO)
    {
        return toAjax(elPassMarkconfigService.addPassMark(elPassMarkconfigVO));
    }


    /**
     * 修改信用合格分设置  "exam:markconfig:edit"
     */
    @ApiOperation(value = "修改信用合格分设置" ,notes="权限字符："+PerPrefix.EXAM_MARKCONFIG+ PerFun.EDIT)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_MARKCONFIG+ PerFun.EDIT)
    @Log(title = "信用合格分设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElPassMarkconfig elPassMarkconfig)
    {
        return  toAjax(elPassMarkconfigService.updateElPassMarkconfig(elPassMarkconfig));
    }

    /**
     * 修改信用合格分和详情  "exam:markconfig:edit"
     */
    @ApiOperation(value = "修改信用合格分和详情" ,notes="权限字符："+PerPrefix.EXAM_MARKCONFIG+ PerFun.EDIT)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_MARKCONFIG+ PerFun.EDIT)
    @Log(title = "修改信用合格分和详情", businessType = BusinessType.UPDATE)
    @PostMapping("/editpassmark")
    public AjaxResult editPassMark(@RequestBody ElPassMarkconfigVO elPassMarkconfigVO)
    {
        return toAjax(elPassMarkconfigService.editPassMark(elPassMarkconfigVO));
    }

    /**
     * 删除信用合格分设置  "exam:markconfig:remove"
     */
    @ApiOperation(value = "删除信用合格分设置" ,notes="权限字符："+PerPrefix.EXAM_MARKCONFIG+ PerFun.REMOVE)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_MARKCONFIG+ PerFun.REMOVE)
    @Log(title = "信用合格分设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elPassMarkconfigService.deleteElPassMarkconfigByIds(ids));
    }

    /**
     * 获取信用合格分设置
     */
    @ApiOperation(value = "获取信用合格分设置")
    @RequestMapping("/getPointsConfig")
    public AjaxResult getPointsConfig(@RequestBody Map <String,Object> recoveryMap)
    {
        ElPassMarkconfig elPassMarkconfig = new ElPassMarkconfig();
        List<ElPassMarkconfigVO> list = elPassMarkconfigService.selectElPassMarkconfigList(elPassMarkconfig);
        for(ElPassMarkconfigVO passMarkconfig:list){
            ElPassConfigdetail passConfigdetail = new ElPassConfigdetail();
            passConfigdetail.setMarkconfigId(passMarkconfig.getId());
            List<ElPassConfigdetail> passConfigdetails = elPassConfigdetailService.selectElPassConfigdetailList(passConfigdetail);
            passMarkconfig.setConfigDetailList(passConfigdetails);
        }

        return AjaxResult.success(list.get(0));
    }
}
