package com.zd.laboratory.controller;

import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.security.service.TokenService;
import com.zd.laboratory.domain.LabSecurityMaterialData;
import com.zd.laboratory.domain.LabSubject;
import com.zd.laboratory.domain.vo.LabSecurityMaterialDataVO;
import com.zd.laboratory.domain.vo.LabSecuritySubjectmaterialVO;
import com.zd.laboratory.service.ILabSecurityMaterialDataService;
import com.zd.system.api.domain.SysUser;
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.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.laboratory.domain.LabSecuritySubjectmaterial;
import com.zd.laboratory.service.ILabSecuritySubjectmaterialService;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.zd.common.core.web.page.TableDataInfo;

/**
 * 实验室和准入模板关系Controller
 *
 * @author zd
 * @date 2022-02-08
 */
@RestController
@Api(tags = "【实验室和准入模板关系】")
@RequestMapping("/subjectmaterial")
public class LabSecuritySubjectmaterialController extends BaseController
{
    @Autowired
    private ILabSecuritySubjectmaterialService labSecuritySubjectmaterialService;

    @Autowired
    private ILabSecurityMaterialDataService labSecurityMaterialDataService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询实验室和准入模板关系列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SUBJECTMATERIAL + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询实验室和准入模板关系列表")
    public TableDataInfo<LabSecuritySubjectmaterial> list(LabSecuritySubjectmaterial labSecuritySubjectmaterial)
    {
        startPage();
        List<LabSecuritySubjectmaterial> list = labSecuritySubjectmaterialService.selectLabSecuritySubjectmaterialList(labSecuritySubjectmaterial);
        return getDataTable(list);
    }

    /**
     * 导出实验室和准入模板关系列表
     */
    @ApiOperation(value = "导出实验室和准入模板关系列表")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SUBJECTMATERIAL + PerFun.EXPORT)
    @Log(title = "实验室和准入模板关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabSecuritySubjectmaterial labSecuritySubjectmaterial) throws IOException
    {
        List<LabSecuritySubjectmaterial> list = labSecuritySubjectmaterialService.selectLabSecuritySubjectmaterialList(labSecuritySubjectmaterial);
        ExcelUtil<LabSecuritySubjectmaterial> util = new ExcelUtil<LabSecuritySubjectmaterial>(LabSecuritySubjectmaterial.class);
        util.exportExcel(response, list, "实验室和准入模板关系数据");
    }

    /**
     * 获取实验室和准入模板关系详细信息
     */
    @ApiOperation(value = "获取实验室和准入模板关系详细信息")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SUBJECTMATERIAL + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabSecuritySubjectmaterial> getInfo(@PathVariable("id") Long id)
    {
        return ResultData.success(labSecuritySubjectmaterialService.selectLabSecuritySubjectmaterialById(id));
    }

    /**
     * 新增实验室和准入模板关系
     */
    @ApiOperation(value = "新增实验室和准入模板关系")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SUBJECTMATERIAL + PerFun.ADD)
    @Log(title = "实验室和准入模板关系", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabSecuritySubjectmaterial labSecuritySubjectmaterial)
    {
        return ResultData.result(labSecuritySubjectmaterialService.insertLabSecuritySubjectmaterial(labSecuritySubjectmaterial));
    }

    /**
     * 修改实验室和准入模板关系
     */
    @ApiOperation(value = "修改实验室和准入模板关系")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SUBJECTMATERIAL + PerFun.EDIT)
    @Log(title = "实验室和准入模板关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabSecuritySubjectmaterial labSecuritySubjectmaterial)
    {
        return  ResultData.result(labSecuritySubjectmaterialService.updateLabSecuritySubjectmaterial(labSecuritySubjectmaterial));
    }

    /**
     * 删除实验室和准入模板关系
     */
    @ApiOperation(value = "删除实验室和准入模板关系")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SUBJECTMATERIAL + PerFun.REMOVE)
    @Log(title = "实验室和准入模板关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids)
    {
        return ResultData.result(labSecuritySubjectmaterialService.deleteLabSecuritySubjectmaterialByIds(ids));
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增实验室和准入模板关系")
    @Log(title = "实验室和准入模板关系")
    @PostMapping("/addlist")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SUBJECTMATERIAL + PerFun.ADD)
    public ResultData addlist(@RequestBody LabSecuritySubjectmaterialVO labSecuritySubjectmaterialVO)
    {
        return ResultData.result(labSecuritySubjectmaterialService.addList(labSecuritySubjectmaterialVO));
    }

    /**
     * 获取模板
     * @return
     */
    @GetMapping("/listData")
    public AjaxResult  listData() {
        Map<String,Object> map = new HashMap<String,Object>();
         List<LabSecurityMaterialDataVO> listTeacher= labSecurityMaterialDataService.selectTemplateTeacherList();
         List<LabSecurityMaterialDataVO> listStudent= labSecurityMaterialDataService.selectTemplateStudentList();

        /* //教职工模板
        List<LabSecuritySubjectmaterialVO> listTeacher=  labSecuritySubjectmaterialService.selectTeacherList();
        //学生模板
        List<LabSecuritySubjectmaterialVO> listStudent=  labSecuritySubjectmaterialService.selectStudentList();*/
        map.put("listTeacher",listTeacher);
        map.put("listStudent",listStudent);
        return AjaxResult.success(map);
    }



}
