package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TSosSolve;
import com.ruoyi.system.service.ITSosSolveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * SOS预警处理Controller
 * 
 * @author zhengjie
 * @date 2023-09-08
 */
@RestController
@RequestMapping("/system/solve")
public class TSosSolveController extends BaseController
{
    @Autowired
    private ITSosSolveService tSosSolveService;

    /**
     * 查询SOS预警处理列表
     */
    @PreAuthorize("@ss.hasPermi('system:solve:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSosSolve tSosSolve)
    {
        startPage();
        List<TSosSolve> list = tSosSolveService.selectTSosSolveList(tSosSolve);
        for (TSosSolve salve : list){
            if (StringUtils.isNull(salve.getSolve_status())){
                salve.setSolve_status(0);
            }
            salve.setAlarmMsg("SOS紧急求助：" + salve.getName() + "于" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,salve.getCreatetime()) + "发起SOS紧急求助");
        }
        return getDataTable(list);
    }

    /**
     * 导出SOS预警处理列表
     */
    @PreAuthorize("@ss.hasPermi('system:solve:export')")
    @Log(title = "SOS预警处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSosSolve tSosSolve)
    {
        List<TSosSolve> list = tSosSolveService.selectTSosSolveList(tSosSolve);
        ExcelUtil<TSosSolve> util = new ExcelUtil<TSosSolve>(TSosSolve.class);
        util.exportExcel(response, list, "SOS预警处理数据");
    }

    /**
     * 获取SOS预警处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:solve:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(tSosSolveService.selectTSosSolveById(id));
    }

    /**
     * 新增SOS预警处理
     */
    @PreAuthorize("@ss.hasPermi('system:solve:add')")
    @Log(title = "SOS预警处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSosSolve tSosSolve)
    {
        return toAjax(tSosSolveService.insertTSosSolve(tSosSolve));
    }

    /**
     * 修改SOS预警处理
     */
    @PreAuthorize("@ss.hasPermi('system:solve:edit')")
    @Log(title = "SOS预警处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSosSolve tSosSolve)
    {
        return toAjax(tSosSolveService.updateTSosSolve(tSosSolve));
    }

    /**
     * 删除SOS预警处理
     */
    @PreAuthorize("@ss.hasPermi('system:solve:remove')")
    @Log(title = "SOS预警处理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tSosSolveService.deleteTSosSolveByIds(ids));
    }
}
