package com.zksy.web.controller.manhole;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksy.base.service.MaintenanceTaskService;
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.MaintenanceTaskDispatchInDTO;
import com.zksy.manhole.dto.in.MaintenanceTaskPageInDTO;
import com.zksy.manhole.dto.in.MaintenanceTaskProcessInDTO;
import com.zksy.manhole.dto.out.MaintenanceTaskOutDTO;
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/maintenanceTask")
@Api(tags = "窨井盖监测系统-运维任务管理")
public class MaintenanceTaskController extends BaseController
{
    @Autowired
    private MaintenanceTaskService maintenanceTaskService;

    /**
     * 分页查询运维任务列表
     */
    @Anonymous
    @PostMapping(value = "/findByPage")
    @ApiOperation(value = "分页查询运维任务列表")
    public AjaxResult2<Page<MaintenanceTaskOutDTO>> findByPage(@RequestBody MaintenanceTaskPageInDTO pageInDTO)
    {
        return AjaxResult2.success(maintenanceTaskService.findByPage(pageInDTO));
    }

    /**
     * 获取运维任务详情
     */
    @Anonymous
    @GetMapping(value = "/getById/{id}")
    @ApiOperation(value = "获取运维任务详情")
    public AjaxResult2<MaintenanceTaskOutDTO> getById(@PathVariable("id") Long id)
    {
        MaintenanceTaskOutDTO outDTO = maintenanceTaskService.getDetailById(id);
        if(outDTO == null){
            return AjaxResult2.error("运维任务ID不存在");
        }
        return AjaxResult2.success(outDTO);
    }

    /**
     * 批量下发运维任务
     */
    @Anonymous
    @PostMapping(value = "/batchDispatch")
    @ApiOperation(value = "批量下发运维任务")
    public AjaxResult batchDispatch(@RequestBody MaintenanceTaskDispatchInDTO inDTO)
    {
        boolean result = maintenanceTaskService.batchDispatch(inDTO);
        return result ? AjaxResult.success("下发成功", result)
                : AjaxResult.error("下发失败", result);
    }

    /**
     * 处理运维任务
     */
    @Anonymous
    @PostMapping(value = "/processTask")
    @ApiOperation(value = "处理运维任务")
    public AjaxResult processTask(@RequestBody MaintenanceTaskProcessInDTO inDTO)
    {
        boolean result = maintenanceTaskService.processTask(inDTO);
        return result ? AjaxResult.success("处理成功", result)
                : AjaxResult.error("处理失败", result);
    }
}
