package com.zehong.web.controller.supervise;

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

import com.zehong.common.core.domain.entity.SysUser;
import com.zehong.common.utils.SecurityUtils;
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.THiddenTroubleInfo;
import com.zehong.system.service.ITHiddenTroubleInfoService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;

/**
 * 燃气隐患Controller
 *
 * @author zehong
 * @date 2022-03-31
 */
@RestController
@RequestMapping("/system/info")
public class THiddenTroubleInfoSController extends BaseController
{
    @Autowired
    private ITHiddenTroubleInfoService tHiddenTroubleInfoService;

    /**
     * 查询燃气隐患列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(THiddenTroubleInfo tHiddenTroubleInfo)
    {
        //获取用户信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        tHiddenTroubleInfo.setBeyondEnterpriseId(user.getDeptId());
        startPage();
        List<THiddenTroubleInfo> list = tHiddenTroubleInfoService.selectTHiddenTroubleInfoList(tHiddenTroubleInfo);
        return getDataTable(list);
    }

    /**
     * 导出燃气隐患列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "燃气隐患", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(THiddenTroubleInfo tHiddenTroubleInfo)
    {
        List<THiddenTroubleInfo> list = tHiddenTroubleInfoService.selectTHiddenTroubleInfoExcelList(tHiddenTroubleInfo);
        ExcelUtil<THiddenTroubleInfo> util = new ExcelUtil<THiddenTroubleInfo>(THiddenTroubleInfo.class);
        return util.exportExcel(list, "燃气隐患数据");
    }

    /**
     * 获取燃气隐患详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{hiddenTroubleId}")
    public AjaxResult getInfo(@PathVariable("hiddenTroubleId") Long hiddenTroubleId)
    {
        return AjaxResult.success(tHiddenTroubleInfoService.selectTHiddenTroubleInfoById(hiddenTroubleId));
    }

    /**
     * 新增燃气隐患
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "燃气隐患", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody THiddenTroubleInfo tHiddenTroubleInfo)
    {
        //获取用户信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        tHiddenTroubleInfo.setBeyondEnterpriseId(user.getDeptId());
        tHiddenTroubleInfo.setReportPerson(user.getNickName());
        SimpleDateFormat dateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        tHiddenTroubleInfo.setReportTime(dateTime.format(new Date()));
        return toAjax(tHiddenTroubleInfoService.insertTHiddenTroubleInfo(tHiddenTroubleInfo));
    }

    /**
     * 修改燃气隐患
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "燃气隐患", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody THiddenTroubleInfo tHiddenTroubleInfo)
    {
        //查询燃气信息是否有修改 如果有值证明没有修改  如果没有值证明已经修改
        THiddenTroubleInfo tHiddenTroubleInfo1 = tHiddenTroubleInfoService.selectDetails(tHiddenTroubleInfo);
        if (tHiddenTroubleInfo1==null){
            tHiddenTroubleInfo.setHiddenTroubleDealStatus("1");
        }
        return toAjax(tHiddenTroubleInfoService.updateTHiddenTroubleInfo(tHiddenTroubleInfo));
    }

    /**
     * 删除燃气隐患
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "燃气隐患", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hiddenTroubleIds}")
    public AjaxResult remove(@PathVariable Long[] hiddenTroubleIds)
    {
        return toAjax(tHiddenTroubleInfoService.deleteTHiddenTroubleInfoByIds(hiddenTroubleIds));
    }
}
