package com.zehong.web.controller.gasBottleTrack;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.zehong.system.domain.TGasBottleInfo;
import com.zehong.system.service.ITGasBottleInfoService;
import org.apache.poi.ss.formula.functions.T;
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.TSafeCheckRecord;
import com.zehong.system.service.ITSafeCheckRecordService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;

/**
 * 安检记录Controller
 *
 * @author zehong
 * @date 2023-08-21
 */
@RestController
@RequestMapping("/safe/record")
public class TSafeCheckRecordController extends BaseController
{
    @Autowired
    private ITSafeCheckRecordService tSafeCheckRecordService;



    /**
     * 查询安检记录列表
     */
    @PreAuthorize("@ss.hasPermi('safe:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSafeCheckRecord tSafeCheckRecord)
    {
        startPage();
        List<TSafeCheckRecord> list = tSafeCheckRecordService.selectTSafeCheckRecordList(tSafeCheckRecord);
        return getDataTable(list);
    }

    /**
     * 导出安检记录列表
     */
    @PreAuthorize("@ss.hasPermi('safe:record:export')")
    @Log(title = "安检记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSafeCheckRecord tSafeCheckRecord)
    {
        List<TSafeCheckRecord> list = tSafeCheckRecordService.selectTSafeCheckRecordList(tSafeCheckRecord);
        ExcelUtil<TSafeCheckRecord> util = new ExcelUtil<TSafeCheckRecord>(TSafeCheckRecord.class);
        return util.exportExcel(list, "安检记录数据");
    }

    /**
     * 获取安检记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('safe:record:query')")
    @GetMapping(value = "/{safeCheckId}")
    public AjaxResult getInfo(@PathVariable("safeCheckId") Long safeCheckId)
    {
        return AjaxResult.success(tSafeCheckRecordService.selectTSafeCheckRecordById(safeCheckId));
    }

    /**
     * 新增安检记录
     */
    @Log(title = "安检记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSafeCheckRecord tSafeCheckRecord)
    {
        return toAjax(tSafeCheckRecordService.insertTSafeCheckRecord(tSafeCheckRecord));
    }


    /**
     * 安检记录添加 微信小程序调用接口
     */
    @PostMapping("/addInfo")
    public AjaxResult addInfo(@RequestBody TSafeCheckRecord tSafeCheckRecord) throws ParseException {
        DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date date = fmt.parse(tSafeCheckRecord.getSafeCheckDates());
        tSafeCheckRecord.setSafeCheckDate(date);

        return toAjax(tSafeCheckRecordService.insertTSafeCheckRecord(tSafeCheckRecord));
    }


    /**
     * 修改安检记录
     */
    @PreAuthorize("@ss.hasPermi('safe:record:edit')")
    @Log(title = "安检记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSafeCheckRecord tSafeCheckRecord)
    {
        return toAjax(tSafeCheckRecordService.updateTSafeCheckRecord(tSafeCheckRecord));
    }

    /**
     * 删除安检记录
     */
    @PreAuthorize("@ss.hasPermi('safe:record:remove')")
    @Log(title = "安检记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{safeCheckIds}")
    public AjaxResult remove(@PathVariable Long[] safeCheckIds)
    {
        return toAjax(tSafeCheckRecordService.deleteTSafeCheckRecordByIds(safeCheckIds));
    }
}
