package com.zehong.web.controller.gasBottleTrack;

import com.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.core.page.TableDataInfo;
import com.zehong.common.enums.BusinessType;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.system.domain.BaseInfoStatistics;
import com.zehong.system.domain.TGasStorageStationInfo;
import com.zehong.system.service.ITGasStorageStationInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 储配站信息Controller
 * 
 * @author zehong
 * @date 2023-08-14
 */
@RestController
@RequestMapping("/gasBottleTrack/storageStationManage")
public class TGasStorageStationInfoController extends BaseController
{
    @Autowired
    private ITGasStorageStationInfoService tGasStorageStationInfoService;

    /**
     * 查询储配站信息列表
     */
    @PreAuthorize("@ss.hasPermi('gasBottleTrack:storageStationManage:list')")
    @GetMapping("/list")
    public TableDataInfo list(TGasStorageStationInfo tGasStorageStationInfo)
    {
        startPage();
        List<TGasStorageStationInfo> list = tGasStorageStationInfoService.selectTGasStorageStationInfoList(tGasStorageStationInfo);
        return getDataTable(list);
    }

    @GetMapping("/gasStorageStationList")
    public AjaxResult gasStorageStationList(TGasStorageStationInfo tGasStorageStationInfo){
        List<TGasStorageStationInfo> list = tGasStorageStationInfoService.selectTGasStorageStationInfoList(tGasStorageStationInfo);
        return AjaxResult.success(list);
    }

    /**
     * 导出储配站信息列表
     */
    @PreAuthorize("@ss.hasPermi('gasBottleTrack:storageStationManage::export')")
    @Log(title = "储配站信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TGasStorageStationInfo tGasStorageStationInfo)
    {
        List<TGasStorageStationInfo> list = tGasStorageStationInfoService.selectTGasStorageStationInfoList(tGasStorageStationInfo);
        ExcelUtil<TGasStorageStationInfo> util = new ExcelUtil<TGasStorageStationInfo>(TGasStorageStationInfo.class);
        return util.exportExcel(list, "储配站信息数据");
    }

    /**
     * 获取储配站信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('gasBottleTrack:storageStationManage:query')")
    @GetMapping(value = "/{stationId}")
    public AjaxResult getInfo(@PathVariable("stationId") Long stationId)
    {
        return AjaxResult.success(tGasStorageStationInfoService.selectTGasStorageStationInfoById(stationId));
    }

    /**
     * 新增储配站信息
     */
    @PreAuthorize("@ss.hasPermi('gasBottleTrack:storageStationManage:add')")
    @Log(title = "储配站信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TGasStorageStationInfo tGasStorageStationInfo)
    {
        return toAjax(tGasStorageStationInfoService.insertTGasStorageStationInfo(tGasStorageStationInfo));
    }

    /**
     * 修改储配站信息
     */
    @PreAuthorize("@ss.hasPermi('gasBottleTrack:storageStationManage:edit')")
    @Log(title = "储配站信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TGasStorageStationInfo tGasStorageStationInfo)
    {
        return toAjax(tGasStorageStationInfoService.updateTGasStorageStationInfo(tGasStorageStationInfo));
    }

    /**
     * 删除储配站信息
     */
    @PreAuthorize("@ss.hasPermi('gasBottleTrack:storageStationManage:remove')")
    @Log(title = "储配站信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stationIds}")
    public AjaxResult remove(@PathVariable Long[] stationIds)
    {
        return toAjax(tGasStorageStationInfoService.deleteTGasStorageStationInfoByIds(stationIds));
    }

    /**
     * 储配站导入
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasPermi('gasBottleTrack:storageStationManage:import')")
    @Log(title = "储配站维护", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TGasStorageStationInfo> util = new ExcelUtil<>(TGasStorageStationInfo.class);
        List<TGasStorageStationInfo> tGasStorageStationInfoList = util.importExcel(file.getInputStream());
        String message = tGasStorageStationInfoService.importTGasStorageStationInfo(tGasStorageStationInfoList, updateSupport);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate(){
        ExcelUtil<TGasStorageStationInfo> util = new ExcelUtil<>(TGasStorageStationInfo.class);
        return util.importTemplateExcel("储配站数据");
    }

    /**
     * 基础信息统计
     * @param stationId 储配站id
     * @return
     */
    @GetMapping("/baseInfoStatistics")
    public TableDataInfo baseInfoStatistics(@RequestParam(value = "stationId",required = false) Long stationId){
        startPage();
        return getDataTable(tGasStorageStationInfoService.baseInfoStatistics(stationId));
    }

    @GetMapping("/baseInfoStatisticsExport")
    public AjaxResult baseInfoStatisticsExport(@RequestParam(value = "stationId",required = false) Long stationId)
    {
        List<BaseInfoStatistics> statistics = tGasStorageStationInfoService.baseInfoStatistics(stationId);
        ExcelUtil<BaseInfoStatistics> util = new ExcelUtil<>(BaseInfoStatistics.class);
        return util.exportExcel(statistics, "基础信息数据");
    }
}
