package com.yfd.platform.modules.patroltask.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.patroltask.service.IDefectDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengsl
 * @since 2024-03-28
 */
@RestController
@RequestMapping("/patroltask/defect-device")
@Api(value = "DefectDeviceController", tags = "缺陷记录")
public class DefectDeviceController {

    @Resource
    private IDefectDeviceService defectDeviceService;

    @GetMapping("/getDefectDeviceList")
    @ApiOperation("查询缺陷数据")
    public ResponseResult getDefectDeviceList(Page<Map<String, Object>> page, String stationCode, String areaId,
                                              String bayId, String taskName, String deviceName,
                                              String patroldeviceName, String componentName, String recognitionType,
                                              String isDefectFlag, String startDate, String endDate) {
        if (StrUtil.isBlank(stationCode)) {
            return ResponseResult.error("未传变电站信息");
        }
        return defectDeviceService.getDefectDeviceList(page, stationCode, areaId, bayId, taskName, deviceName,
                patroldeviceName, componentName, recognitionType, isDefectFlag, startDate, endDate);
    }

    @PostMapping("/setDefectDevice")
    @ApiOperation("缺陷信息归入")
    public ResponseResult setDefectDevice(String ids) {
        boolean ok = defectDeviceService.setDefectDevice(ids);
        if (ok) {
            return ResponseResult.success();
        } else {
            return ResponseResult.error("归入失败");
        }

    }

    @GetMapping("/getDefectDeviceById")
    @ApiOperation("根据id获取缺陷信息")
    public ResponseResult getDefectDeviceById(String id) {
        return defectDeviceService.getDefectDeviceById(id);

    }

    @PostMapping("/deleteDefectDevice")
    @ApiOperation("缺陷信息删除")
    public ResponseResult deleteDefectDevice(String ids) {
        boolean ok = defectDeviceService.deleteDefectDevice(ids);
        if (ok) {
            return ResponseResult.success();
        } else {
            return ResponseResult.error("删除失败");
        }

    }

}
