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.web.controller.BaseController;
import com.zd.common.core.web.domain.ResultData;
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.LabMold;
import com.zd.laboratory.service.ILabMoldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 实验室类型Controller
 *
 * @author liubo
 * @date 2022-05-17
 */
@RestController
@Api(tags = "【实验室类型】")
@RequestMapping("/labMold")
public class LabMoldController extends BaseController {
    @Autowired
    private ILabMoldService labMoldService;

    /**
     * 查询实验室类型列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询实验室类型列表", notes = "权限字符：" + PerPrefix.LABORATORY_CLASSTYPE + PerFun.LIST)
    public TableDataInfo<LabMold> list(LabMold labMold) {
        startPage();
        List<LabMold> list = labMoldService.selectLabMoldList(labMold);
        return getDataTable(list);
    }

    /**
     * 查询实验室类型下拉框
     */
    @PostMapping("/queryOption")
    @ApiOperation(value = "查询实验室类型下拉列表")
    public List<LabMold> queryOption(@RequestBody LabMold labMold) {
        List<LabMold> list = labMoldService.selectLabMoldList(labMold);
        return list;
    }


    /**
     * 获取实验室类型详细信息
     */
    @ApiOperation(value = "获取实验室类型详细信息", notes = "权限字符：" + PerPrefix.LABORATORY_CLASSTYPE + PerFun.QUERY)
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabMold> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(labMoldService.selectLabMoldById(id));
    }

    /**
     * 新增实验室类型
     */
    @ApiOperation(value = "新增实验室类型", notes = "权限字符：" + PerPrefix.LABORATORY_CLASSTYPE + PerFun.ADD)
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.ADD)
    @Log(title = "实验室类型", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabMold labMold) {
        return ResultData.result(labMoldService.insertLabMold(labMold));
    }

    /**
     * 修改实验室类型
     */
    @ApiOperation(value = "修改实验室类型", notes = "权限字符：" + PerPrefix.LABORATORY_CLASSTYPE + PerFun.EDIT)
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.EDIT)
    @Log(title = "实验室类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabMold labMold) {
        return ResultData.result(labMoldService.updateLabMold(labMold));
    }

    /**
     * 删除实验室类型
     */
    @ApiOperation(value = "删除实验室类型", notes = "权限字符：" + PerPrefix.LABORATORY_CLASSTYPE + PerFun.REMOVE)
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_CLASSTYPE + PerFun.REMOVE)
    @Log(title = "实验室类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids) {
        return ResultData.result(labMoldService.deleteLabMoldByIds(ids));
    }
}
