package com.tofly.watermeter.custom.controller.meterBusiness;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.StringUtil;
import com.tofly.watermeter.entity.Watermeter;
import com.tofly.watermeter.service.WatermeterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author FlashWJL
 * @date 2021/3/24 10:00
 */
@RestController
@AllArgsConstructor
@RequestMapping("/location")
@Api(tags = "表务--水表位置管理")
public class SbLocationController {

    private final WatermeterService watermeterService;

    @GetMapping("/getBySbbh")
    @ApiOperation(value = "根据水表编号查询位置")
    public ResultRespone getSbLocation(String sbbh, String yhbh) {
        Watermeter info = watermeterService.getOne(Wrappers.<Watermeter>lambdaQuery().eq(StringUtil.isNotEmpty(sbbh), Watermeter::getSid, sbbh)
                .eq(StringUtil.isNotEmpty(yhbh), Watermeter::getYhbh, yhbh)
                .eq(Watermeter::getStatus, "1"));
        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("暂无位置信息");
        }
        return ResultRespone.success(info);
    }

    @GetMapping("/getLocation")
    @ApiOperation(value = "查询水表位置")
    public ResultRespone getLocation() {
        List<Watermeter> info = watermeterService.list(Wrappers.<Watermeter>lambdaQuery().eq(Watermeter::getStatus, "1"));
        return ResultRespone.success(info);
    }

    @GetMapping("getRepInfo")
    @ApiOperation("根据sid获取水表采集信息")
    public ResultRespone getRepInfo(String sid) {
        return ResultRespone.success(watermeterService.getWaterInfo(sid));
    }

}
