package com.zd.chemical.controller;

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

import com.zd.chemical.domain.vo.HxpChemicalJoinCabinetListVo;
import com.zd.chemical.domain.vo.HxpChemicalJoinCabinetSearch;
import com.zd.chemical.domain.vo.HxpChemicalJoinCabinetVo;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.SecurityUtils;
import com.zd.common.core.web.domain.ResultData;
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.chemical.domain.HxpChemicalJoinCabinet;
import com.zd.chemical.service.IHxpChemicalJoinCabinetService;
import com.zd.common.core.web.controller.BaseController;
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 liubo
 * @date 2022-06-16
 */
@RestController
@Api(tags = "【化学品和机柜关联】")
@RequestMapping("/hxpChemicalJoinCabinet")
public class HxpChemicalJoinCabinetController extends BaseController {
    @Autowired
    private IHxpChemicalJoinCabinetService hxpChemicalJoinCabinetService;

    /**
     * 查询化学品和机柜关联列表
     */
    @PreAuthorize(hasPermi = PerPrefix.HPX_CHEMICAL+ PerFun.JOINLIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询化学品和机柜关联列表")
    public TableDataInfo<HxpChemicalJoinCabinetListVo> list(HxpChemicalJoinCabinetSearch hxpChemicalJoinCabinetSearch) {
        startPage();
        List<HxpChemicalJoinCabinetListVo> list = hxpChemicalJoinCabinetService.selectHxpChemicalJoinCabinetList(hxpChemicalJoinCabinetSearch);
        return getDataTable(list);
    }

    @GetMapping("/queryByUser")
    @ApiOperation(value = "查询化学品和机柜关联列表")
    public TableDataInfo<HxpChemicalJoinCabinetListVo> queryByUser(HxpChemicalJoinCabinetSearch hxpChemicalJoinCabinetSearch) {
        startPage();
        hxpChemicalJoinCabinetSearch.setUserId(SecurityUtils.getUserId());
        List<HxpChemicalJoinCabinetListVo> list = hxpChemicalJoinCabinetService.selectHxpChemicalJoinCabinetList(hxpChemicalJoinCabinetSearch);
        return getDataTable(list);
    }

    /**
     * 导出化学品和机柜关联列表
     */
    @ApiOperation(value = "导出化学品和机柜关联列表")
    @Log(title = "化学品和机柜关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HxpChemicalJoinCabinetSearch hxpChemicalJoinCabinetSearch) throws IOException {
        List<HxpChemicalJoinCabinetListVo> list = hxpChemicalJoinCabinetService.selectHxpChemicalJoinCabinetList(hxpChemicalJoinCabinetSearch);
        ExcelUtil<HxpChemicalJoinCabinetListVo> util = new ExcelUtil<HxpChemicalJoinCabinetListVo>(HxpChemicalJoinCabinetListVo.class);
        util.exportExcel(response, list, "化学品和机柜关联数据");
    }

    /**
     * 获取化学品和机柜关联详细信息
     */
    @ApiOperation(value = "获取化学品和机柜关联详细信息")
    @GetMapping(value = "/{id}")
    public ResultData<HxpChemicalJoinCabinet> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(hxpChemicalJoinCabinetService.selectHxpChemicalJoinCabinetById(id));
    }

    /**
     * 获取化学品和机柜关联详细信息(根据化学品id查询列表)
     */
    @ApiOperation(value = "获取化学品和机柜关联详细信息")
    @GetMapping(value = "/selByChemical/{id}")
    public ResultData<HxpChemicalJoinCabinetVo> selByChemical(@PathVariable("id") Long id) {
        return ResultData.success(hxpChemicalJoinCabinetService.selByChemical(id));
    }

    /**
     * 新增化学品和机柜关联
     */
    @ApiOperation(value = "新增化学品和机柜关联")
    @Log(title = "化学品和机柜关联", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody HxpChemicalJoinCabinetVo hxpChemicalJoinCabinetVo) {
        return ResultData.result(hxpChemicalJoinCabinetService.insertHxpChemicalJoinCabinet(hxpChemicalJoinCabinetVo));
    }

    /**
     * 修改化学品和机柜关联
     */
    @ApiOperation(value = "修改化学品和机柜关联")
    @Log(title = "化学品和机柜关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody HxpChemicalJoinCabinet hxpChemicalJoinCabinet) {
        return ResultData.result(hxpChemicalJoinCabinetService.updateHxpChemicalJoinCabinet(hxpChemicalJoinCabinet));
    }

    /**
     * 删除化学品和机柜关联
     */
    @ApiOperation(value = "删除化学品和机柜关联")
    @Log(title = "化学品和机柜关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids) {
        return ResultData.result(hxpChemicalJoinCabinetService.deleteHxpChemicalJoinCabinetByIds(ids));
    }


    /**
     * 删除化学品和机柜关联(根据化学品id)
     */
    @ApiOperation(value = "删除化学品和机柜关联(根据化学品id)")
    @Log(title = "化学品和机柜关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/delByChemical/{ids}")
    public ResultData delByChemical(@PathVariable Long[] ids) {
        return ResultData.result(hxpChemicalJoinCabinetService.delByChemical(ids));
    }
}
