package com.zehong.web.controller.gasBottleTrack;

import java.util.List;

import com.zehong.system.domain.TGasBottleInfo;
import org.springframework.security.access.prepost.PreAuthorize;
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.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.enums.BusinessType;
import com.zehong.system.domain.TGasUserInfo;
import com.zehong.system.service.ITGasUserInfoService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 燃气用户Controller
 * 
 * @author zehong
 * @date 2023-08-17
 */
@RestController
@RequestMapping("/gasUser/info")
public class TGasUserInfoController extends BaseController
{
    @Autowired
    private ITGasUserInfoService tGasUserInfoService;

    /**
     * 查询燃气用户列表
     */
    @PreAuthorize("@ss.hasPermi('gasUser:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TGasUserInfo tGasUserInfo)
    {
        startPage();
        List<TGasUserInfo> list = tGasUserInfoService.selectTGasUserInfoList(tGasUserInfo);
        return getDataTable(list);
    }

    @GetMapping("/gasUserInfoList")
    public AjaxResult gasUserInfoList(TGasUserInfo tGasUserInfo){
        List<TGasUserInfo> list = tGasUserInfoService.selectTGasUserInfoList(tGasUserInfo);
        return AjaxResult.success(list);
    }

    /**
     * 导出燃气用户列表
     */
    @PreAuthorize("@ss.hasPermi('gasUser:info:export')")
    @Log(title = "燃气用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TGasUserInfo tGasUserInfo)
    {
        List<TGasUserInfo> list = tGasUserInfoService.selectTGasUserInfoList(tGasUserInfo);
        ExcelUtil<TGasUserInfo> util = new ExcelUtil<TGasUserInfo>(TGasUserInfo.class);
        return util.exportExcel(list, "燃气用户数据");
    }

    /**
     * 获取燃气用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('gasUser:info:query')")
    @GetMapping(value = "/{gasUserId}")
    public AjaxResult getInfo(@PathVariable("gasUserId") Long gasUserId)
    {
        return AjaxResult.success(tGasUserInfoService.selectTGasUserInfoById(gasUserId));
    }

    /**
     * 新增燃气用户
     */
    @PreAuthorize("@ss.hasPermi('gasUser:info:add')")
    @Log(title = "燃气用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TGasUserInfo tGasUserInfo)
    {
        return toAjax(tGasUserInfoService.insertTGasUserInfo(tGasUserInfo));
    }

    /**
     * 修改燃气用户
     */
    @PreAuthorize("@ss.hasPermi('gasUser:info:edit')")
    @Log(title = "燃气用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TGasUserInfo tGasUserInfo)
    {
        return toAjax(tGasUserInfoService.updateTGasUserInfo(tGasUserInfo));
    }

    /**
     * 删除燃气用户
     */
    @PreAuthorize("@ss.hasPermi('gasUser:info:remove')")
    @Log(title = "燃气用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gasUserIds}")
    public AjaxResult remove(@PathVariable Long[] gasUserIds)
    {
        return toAjax(tGasUserInfoService.deleteTGasUserInfoByIds(gasUserIds));
    }

    /**
     * 燃气用户导入
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasPermi('gasUser:info:import')")
    @Log(title = "燃气用户导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TGasUserInfo> util = new ExcelUtil<>(TGasUserInfo.class);
        List<TGasUserInfo> tGasUserInfoList = util.importExcel(file.getInputStream());
        String message = tGasUserInfoService.importTGasUserInfo(tGasUserInfoList, updateSupport);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate(){
        ExcelUtil<TGasUserInfo> util = new ExcelUtil<>(TGasUserInfo.class);
        return util.importTemplateExcel("燃气用户数据");
    }
}
