package com.willalp.web.controller.control;

import com.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.page.TableDataInfo;
import com.willalp.common.enums.BusinessType;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.control.domain.HsControlUsenoConfig;
import com.willalp.control.service.IHsControlUsenoConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 空开设备号口配置Controller
 *
 * @author willalp
 * @date 2022-02-21
 */
@RestController
@RequestMapping("/control/useNoConfig")
public class HsControlUsenoConfigController extends BaseController {
    @Autowired
    private IHsControlUsenoConfigService hsControlUsenoConfigService;

    /**
     * 查询空开设备号口配置列表
     */
    @PreAuthorize("@ss.hasPermi('control:useNoConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsControlUsenoConfig hsControlUsenoConfig) {
        startPage();
        List<HsControlUsenoConfig> list = hsControlUsenoConfigService.selectHsControlUsenoConfigList(hsControlUsenoConfig);
        return getDataTable(list);
    }

    /**
     * 导出空开设备号口配置列表
     */
    @PreAuthorize("@ss.hasPermi('control:useNoConfig:export')")
    @Log(title = "空开设备号口配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsControlUsenoConfig hsControlUsenoConfig) {
        List<HsControlUsenoConfig> list = hsControlUsenoConfigService.selectHsControlUsenoConfigList(hsControlUsenoConfig);
        ExcelUtil<HsControlUsenoConfig> util = new ExcelUtil<HsControlUsenoConfig>(HsControlUsenoConfig.class);
        return util.exportExcel(list, "空开设备号口配置数据");
    }

    /**
     * 获取空开设备号口配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:useNoConfig:query')")
    @GetMapping(value = "/{useNoId}")
    public AjaxResult getInfo(@PathVariable("useNoId") Long useNoId) {
        return AjaxResult.success(hsControlUsenoConfigService.getById(useNoId));
    }

    /**
     * 新增空开设备号口配置
     */
    @PreAuthorize("@ss.hasPermi('control:useNoConfig:add')")
    @Log(title = "空开设备号口配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsControlUsenoConfig hsControlUsenoConfig) {
        hsControlUsenoConfig.setCreateBy(SecurityUtils.getUsername());
        hsControlUsenoConfig.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsControlUsenoConfigService.save(hsControlUsenoConfig));
    }

    /**
     * 修改空开设备号口配置
     */
    @PreAuthorize("@ss.hasPermi('control:useNoConfig:edit')")
    @Log(title = "空开设备号口配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsControlUsenoConfig hsControlUsenoConfig) {
        hsControlUsenoConfig.setUpdateBy(SecurityUtils.getUsername());
        hsControlUsenoConfig.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsControlUsenoConfigService.updateById(hsControlUsenoConfig));
    }

    /**
     * 删除空开设备号口配置
     */
    @PreAuthorize("@ss.hasPermi('control:useNoConfig:remove')")
    @Log(title = "空开设备号口配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{useNoIds}")
    public AjaxResult remove(@PathVariable Long[] useNoIds) {
        return toAjax(hsControlUsenoConfigService.removeByIds(Arrays.asList(useNoIds)));
    }
}
