package com.zd.laboratory.controller;

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.laboratory.domain.LabOnepc;
import com.zd.laboratory.service.ILabOnepcService;
import com.zd.laboratory.service.ILabSafeClasstypeService;
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;

/**
 * 一体机设备勾选Controller
 *
 * @author zd
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/onepc")
public class LabOnepcController extends BaseController {
    @Autowired
    private ILabOnepcService labOnepcService;

    @Autowired
    private ILabSafeClasstypeService labSafeClasstypeService;

    /**
     * 查询一体机设备勾选列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_ONEPC + PerFun.LIST)
    @GetMapping("/list")
    public TableDataInfo list(LabOnepc labOnepc) {
        startPage();
        List<LabOnepc> list = labOnepcService.selectLabOnepcList(labOnepc);
        return getDataTable(list);
    }

    /**
     * 导出一体机设备勾选列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_ONEPC + PerFun.EXPORT)
    @Log(title = "一体机设备勾选", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabOnepc labOnepc) throws IOException {
        List<LabOnepc> list = labOnepcService.selectLabOnepcList(labOnepc);
        ExcelUtil<LabOnepc> util = new ExcelUtil<LabOnepc>(LabOnepc.class);
        util.exportExcel(response, list, "一体机设备勾选数据");
    }

    /**
     * 获取一体机设备勾选详细信息
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_ONEPC + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(labOnepcService.selectLabOnepcById(id));
    }

    /**
     * 新增一体机设备勾选
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_ONEPC + PerFun.ADD)
    @Log(title = "一体机设备勾选", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabOnepc labOnepc) {
        return toAjax(labOnepcService.insertLabOnepc(labOnepc));
    }

    /**
     * 修改一体机设备勾选
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_ONEPC + PerFun.EDIT)
    @Log(title = "一体机设备勾选", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabOnepc labOnepc) {
        return toAjax(labOnepcService.updateLabOnepc(labOnepc));
    }

    /**
     * 删除一体机设备勾选
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_ONEPC + PerFun.REMOVE)
    @Log(title = "一体机设备勾选", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(labOnepcService.deleteLabOnepcByIds(ids));
    }


//    /**
//     * 一体机获取实验室安全制度
//     */
//    @GetMapping("/safesystem")
//    public AjaxResult safeSystem(@Param("subjectId") Long subjectId) {
//        return AjaxResult.success(labSafeClasstypeService.safeSystemById(subjectId));
//    }
}
