package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.TEarlyWarning;
import com.ruoyi.system.domain.TRailSolve;
import com.ruoyi.system.domain.TSosSolve;
import com.ruoyi.system.service.ITEarlyWarningService;
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.TFallSolve;
import com.ruoyi.system.service.ITFallSolveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 跌倒告警Controller
 *
 * @author zhengjie
 * @date 2023-09-09
 */
@RestController
@RequestMapping("/system/fallsolve")
public class TFallSolveController extends BaseController {
    @Autowired
    private ITFallSolveService tFallSolveService;
    @Autowired
    private ITEarlyWarningService itEarlyWarningService;

    /**
     * 查询跌倒告警列表
     */
    @PreAuthorize("@ss.hasPermi('system:fallsolve:list')")
    @GetMapping("/list")
    public TableDataInfo list(TEarlyWarning earlyWarning) {
        startPage();
        List<TEarlyWarning> tEarlyWarnings = itEarlyWarningService.selectTEarlyWarningList_FALLSOLVE(earlyWarning);
        return getDataTable(tEarlyWarnings);
    }

    /**
     * 导出跌倒告警列表
     */
    @PreAuthorize("@ss.hasPermi('system:fallsolve:export')")
    @Log(title = "跌倒告警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TFallSolve tFallSolve) {
        List<TFallSolve> list = tFallSolveService.selectTFallSolveList(tFallSolve);
        ExcelUtil<TFallSolve> util = new ExcelUtil<TFallSolve>(TFallSolve.class);
        util.exportExcel(response, list, "跌倒告警数据");
    }

    /**
     * 获取跌倒告警详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fallsolve:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(tFallSolveService.selectTFallSolveById(id));
    }

    /**
     * 新增跌倒告警
     */
    @PreAuthorize("@ss.hasPermi('system:fallsolve:add')")
    @Log(title = "跌倒告警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TEarlyWarning earlyWarning) {
        if (earlyWarning != null && earlyWarning.getId() != null) {
            return toAjax(itEarlyWarningService.updateTEarlyWarning(earlyWarning));
        } else {
            return toAjax(itEarlyWarningService.insertTEarlyWarning(earlyWarning));
        }
    }

    /**
     * 修改跌倒告警
     */
    @PreAuthorize("@ss.hasPermi('system:fallsolve:edit')")
    @Log(title = "跌倒告警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TFallSolve tFallSolve) {
        return toAjax(tFallSolveService.updateTFallSolve(tFallSolve));
    }

    /**
     * 删除跌倒告警
     */
    @PreAuthorize("@ss.hasPermi('system:fallsolve:remove')")
    @Log(title = "跌倒告警", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(tFallSolveService.deleteTFallSolveByIds(ids));
    }
}
