package com.zd.laboratory.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
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.LabCheckRecord;
import com.zd.laboratory.domain.vo.LabCheckRecordReleaseVO;
import com.zd.laboratory.domain.vo.LabCheckRecordVO;
import com.zd.laboratory.service.ILabCheckMachineMsgService;
import com.zd.laboratory.service.ILabCheckRecordService;
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.LabCheckRecordRelease;
import com.zd.laboratory.service.ILabCheckRecordReleaseService;
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.swagger.config.Knife4jConfiguration;

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

/**
 * 检查发布关系Controller
 *
 * @author zd
 * @date 2022-02-17
 */
@RestController
@Api(tags = "【检查发布关系】")
@RequestMapping("/release")
public class LabCheckRecordReleaseController extends BaseController
{
    @Autowired
    private ILabCheckRecordReleaseService labCheckRecordReleaseService;
    @Autowired
    private ILabCheckRecordService labCheckRecordService;


    /**
     * 查询检查发布关系列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_RELEASE + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询检查发布关系列表")
    public TableDataInfo<LabCheckRecordRelease> list(LabCheckRecordRelease labCheckRecordRelease)
    {
        startPage();
        List<LabCheckRecordRelease> list = labCheckRecordReleaseService.selectLabCheckRecordReleaseList(labCheckRecordRelease);
        return getDataTable(list);
    }

    /**
     * 导出检查发布关系列表
     */
    @ApiOperation(value = "导出检查发布关系列表")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_RELEASE + PerFun.EXPORT)
    @Log(title = "检查发布关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabCheckRecordRelease labCheckRecordRelease) throws IOException
    {
        List<LabCheckRecordRelease> list = labCheckRecordReleaseService.selectLabCheckRecordReleaseList(labCheckRecordRelease);
        ExcelUtil<LabCheckRecordRelease> util = new ExcelUtil<LabCheckRecordRelease>(LabCheckRecordRelease.class);
        util.exportExcel(response, list, "检查发布关系数据");
    }

    /**
     * 获取检查发布关系详细信息
     */
    @ApiOperation(value = "获取检查发布关系详细信息")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_RELEASE + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabCheckRecordRelease> getInfo(@PathVariable("id") Long id)
    {
        return ResultData.success(labCheckRecordReleaseService.selectLabCheckRecordReleaseById(id));
    }

    /**
     * 新增检查发布关系
     */
    @ApiOperation(value = "新增检查发布关系")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_RELEASE + PerFun.ADD)
    @Log(title = "检查发布关系", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabCheckRecordRelease labCheckRecordRelease)
    {

        return ResultData.result(labCheckRecordReleaseService.insertLabCheckRecordRelease(labCheckRecordRelease));
    }

    /**
     * 修改检查发布关系
     */
    @ApiOperation(value = "修改检查发布关系")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_RELEASE + PerFun.EDIT)
    @Log(title = "检查发布关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabCheckRecordRelease labCheckRecordRelease)
    {
        return  ResultData.result(labCheckRecordReleaseService.updateLabCheckRecordRelease(labCheckRecordRelease));
    }

    /**
     * 删除检查发布关系
     */
    @ApiOperation(value = "删除检查发布关系")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_RELEASE + PerFun.REMOVE)
    @Log(title = "检查发布关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids)
    {
        return ResultData.result(labCheckRecordReleaseService.deleteLabCheckRecordReleaseByIds(ids));
    }

    /***
     * 查询检查记录是否已发布，传入检查记录id
     * @param labCheckRecordRelease
     * @return
     */
    @GetMapping("/listExist")
    @ApiOperation(value = "查询检查发布关系列表")
    public TableDataInfo<LabCheckRecordRelease> listExist(LabCheckRecordRelease labCheckRecordRelease)
    {
        List<LabCheckRecordRelease> list = labCheckRecordReleaseService.selectLabCheckRecordReleaseListExist(labCheckRecordRelease);
        return getDataTable(list);
    }

    /****
     * 首页安全检查发布列表查询
     * @param labCheckRecordReleaseVO
     * @return
     */
    @GetMapping("/indexListRelease")
    @ApiOperation(value = "查询检查发布关系列表")
    public TableDataInfo<LabCheckRecordReleaseVO> selectListByParameter(LabCheckRecordReleaseVO labCheckRecordReleaseVO)
    {
        startPage();
        List<LabCheckRecordReleaseVO> list = labCheckRecordReleaseService.selectListByParameter(labCheckRecordReleaseVO);
        return getDataTable(list);
    }

    /****
     * PC端检查发布 列表查询
     * @param labCheckRecordReleaseVO
     * @return
     */
    @GetMapping("/listRelease")
    @ApiOperation(value = "查询检查发布关系列表")
    public TableDataInfo<LabCheckRecordReleaseVO> listRelease(LabCheckRecordReleaseVO labCheckRecordReleaseVO)
    {
        startPage();
        List<LabCheckRecordReleaseVO> list = labCheckRecordReleaseService.selectListByParameter(labCheckRecordReleaseVO);
        return getDataTable(list);
    }

    /***
     * PC端检查发布列 详情
     * @param labCheckRecordVO
     * @return
     */
   /* @GetMapping("/listReleaseDetals")
    public TableDataInfo<LabCheckRecordVO> indexGetCheckDetals(LabCheckRecordVO labCheckRecordVO)
    {
        startPage();
        List<LabCheckRecordVO> list = labCheckRecordService.selectLabCheckRecordIndexDetals(labCheckRecordVO);
        return getDataTable(list);
    }*/

}
