package com.zehong.web.controller.gasBottleTrack;

import java.util.List;

import com.zehong.system.domain.TGasUserInfo;
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.TAirChargeRecord;
import com.zehong.system.service.ITAirChargeRecordService;
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-21
 */
@RestController
@RequestMapping("/charge/record")
public class TAirChargeRecordController extends BaseController
{
    @Autowired
    private ITAirChargeRecordService tAirChargeRecordService;

    /**
     * 查询充装记录列表
     */
    @PreAuthorize("@ss.hasPermi('charge:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAirChargeRecord tAirChargeRecord)
    {
        startPage();
        List<TAirChargeRecord> list = tAirChargeRecordService.selectTAirChargeRecordList(tAirChargeRecord);
        return getDataTable(list);
    }

    /**
     * 导出充装记录列表
     */
    @PreAuthorize("@ss.hasPermi('charge:record:export')")
    @Log(title = "充装记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TAirChargeRecord tAirChargeRecord)
    {
        List<TAirChargeRecord> list = tAirChargeRecordService.selectTAirChargeRecordList(tAirChargeRecord);
        ExcelUtil<TAirChargeRecord> util = new ExcelUtil<TAirChargeRecord>(TAirChargeRecord.class);
        return util.exportExcel(list, "充装记录数据");
    }

    /**
     * 获取充装记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('charge:record:query')")
    @GetMapping(value = "/{chargeRecordId}")
    public AjaxResult getInfo(@PathVariable("chargeRecordId") Long chargeRecordId)
    {
        return AjaxResult.success(tAirChargeRecordService.selectTAirChargeRecordById(chargeRecordId));
    }

    /**
     * 新增充装记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "充装记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAirChargeRecord tAirChargeRecord)
    {
        return toAjax(tAirChargeRecordService.insertTAirChargeRecord(tAirChargeRecord));
    }

    /**
     * 修改充装记录
     */
    @PreAuthorize("@ss.hasPermi('charge:record:edit')")
    @Log(title = "充装记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAirChargeRecord tAirChargeRecord)
    {
        return toAjax(tAirChargeRecordService.updateTAirChargeRecord(tAirChargeRecord));
    }

    /**
     * 删除充装记录
     */
    @PreAuthorize("@ss.hasPermi('charge:record:remove')")
    @Log(title = "充装记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chargeRecordIds}")
    public AjaxResult remove(@PathVariable Long[] chargeRecordIds)
    {
        return toAjax(tAirChargeRecordService.deleteTAirChargeRecordByIds(chargeRecordIds));
    }

    /**
     * 充装记录导入
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasPermi('charge:record:import')")
    @Log(title = "充装记录导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TAirChargeRecord> util = new ExcelUtil<>(TAirChargeRecord.class);
        List<TAirChargeRecord> airChargeRecordList = util.importExcel(file.getInputStream());
        String message = tAirChargeRecordService.importAirChargeRecordInfo(airChargeRecordList, updateSupport);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate(){
        ExcelUtil<TAirChargeRecord> util = new ExcelUtil<>(TAirChargeRecord.class);
        return util.importTemplateExcel("充装记录数据");
    }
}
