package com.zksy.web.controller.manhole;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksy.base.service.TerminalFaultService;
import com.zksy.common.annotation.Anonymous;
import com.zksy.common.core.controller.BaseController;
import com.zksy.common.core.domain.AjaxResult;
import com.zksy.common.core.domain.AjaxResult2;
import com.zksy.manhole.dto.in.TerminalFaultHandleInDTO;
import com.zksy.manhole.dto.in.TerminalFaultPageInDTO;
import com.zksy.manhole.dto.out.TerminalFaultOutDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 窨井盖监测系统-故障管理Controller
 * 
 * @author xianggx
 * @date 2026-05-06
 */
@RestController
@RequestMapping("/manhole/terminalFault")
@Api(tags = "窨井盖监测系统-故障管理")
public class TerminalFaultController extends BaseController
{
    @Autowired
    private TerminalFaultService terminalFaultService;

    /**
     * 分页查询终端故障列表
     */
    @Anonymous
    @PostMapping(value = "/findByPage")
    @ApiOperation(value = "分页查询终端故障列表")
    public AjaxResult2<Page<TerminalFaultOutDTO>> findByPage(@RequestBody TerminalFaultPageInDTO pageInDTO)
    {
        return AjaxResult2.success(terminalFaultService.findByPage(pageInDTO));
    }

    /**
     * 获取终端故障详情
     */
    @Anonymous
    @GetMapping(value = "/getById/{id}")
    @ApiOperation(value = "获取终端故障详情")
    public AjaxResult2<TerminalFaultOutDTO> getById(@PathVariable("id") Long id)
    {
        TerminalFaultOutDTO outDTO = terminalFaultService.getDetailById(id);
        if(outDTO == null){
            return AjaxResult2.error("故障ID不存在");
        }
        return AjaxResult2.success(outDTO);
    }

    /**
     * 处置终端故障
     */
    @Anonymous
    @PostMapping(value = "/handleFault")
    @ApiOperation(value = "处置终端故障")
    public AjaxResult handleFault(@RequestBody TerminalFaultHandleInDTO inDTO)
    {
        boolean result = terminalFaultService.handleFault(inDTO);
        return result ? AjaxResult.success("处置成功", result)
                : AjaxResult.error("处置失败", result);
    }
}
