package com.jsowell.web.controller.pile;

import com.jsowell.common.annotation.Log;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.core.page.TableDataInfo;
import com.jsowell.common.enums.BusinessType;
import com.jsowell.common.util.poi.ExcelUtil;
import com.jsowell.pile.domain.PileFirmwareInfo;
import com.jsowell.pile.service.IPileFirmwareInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 充电桩固件信息Controller
 *
 * @author jsowell
 * @date 2023-06-28
 */
@RestController
@RequestMapping("/pile/firmware")
public class PileFirmwareInfoController extends BaseController {
    @Autowired
    private IPileFirmwareInfoService pileFirmwareInfoService;

    /**
     * 查询充电桩固件信息列表
     */
    @PreAuthorize("@ss.hasPermi('pile:firmware:list')")
    @GetMapping("/list")
    public TableDataInfo list(PileFirmwareInfo pileFirmwareInfo) {
        startPage();
        List<PileFirmwareInfo> list = pileFirmwareInfoService.selectPileFirmwareInfoList(pileFirmwareInfo);
        return getDataTable(list);
    }

    /**
     * 导出充电桩固件信息列表
     */
    @PreAuthorize("@ss.hasPermi('pile:firmware:export')")
    @Log(title = "充电桩固件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PileFirmwareInfo pileFirmwareInfo) {
        List<PileFirmwareInfo> list = pileFirmwareInfoService.selectPileFirmwareInfoList(pileFirmwareInfo);
        ExcelUtil<PileFirmwareInfo> util = new ExcelUtil<PileFirmwareInfo>(PileFirmwareInfo.class);
        util.exportExcel(response, list, "充电桩固件信息数据");
    }

    /**
     * 获取充电桩固件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('pile:firmware:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(pileFirmwareInfoService.selectPileFirmwareInfoById(id));
    }

    /**
     * 新增充电桩固件信息
     */
    @PreAuthorize("@ss.hasPermi('pile:firmware:add')")
    @Log(title = "充电桩固件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PileFirmwareInfo pileFirmwareInfo) {
        return toAjax(pileFirmwareInfoService.insertPileFirmwareInfo(pileFirmwareInfo));
    }

    /**
     * 修改充电桩固件信息
     */
    @PreAuthorize("@ss.hasPermi('pile:firmware:edit')")
    @Log(title = "充电桩固件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PileFirmwareInfo pileFirmwareInfo) {
        return toAjax(pileFirmwareInfoService.updatePileFirmwareInfo(pileFirmwareInfo));
    }

    /**
     * 删除充电桩固件信息
     */
    @PreAuthorize("@ss.hasPermi('pile:firmware:remove')")
    @Log(title = "充电桩固件信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pileFirmwareInfoService.deletePileFirmwareInfoByIds(ids));
    }
}
