package com.tofly.third.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.third.common.exception.BusinessException;
import com.tofly.third.entity.YhCbkxx;
import com.tofly.third.mapper.YhCbkxxMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;


@Slf4j
@Service
public class YhCbkxxService extends ServiceImpl<YhCbkxxMapper, YhCbkxx> {

    public YhCbkxx getCbkBySbbh(String bjbh) {
        if (StrUtil.isEmpty(bjbh)) {
            throw new BusinessException("水表编号不能为空");
        }

        LambdaQueryWrapper<YhCbkxx> queryWrapper = Wrappers.<YhCbkxx>lambdaQuery().eq(YhCbkxx::getSbbh, bjbh);
        return getOne(queryWrapper);
    }


    public void updateLjsl(String cbkid, BigDecimal jtzqljl) {
        if (cbkid == null) return;
        this.lambdaUpdate()
                .set(YhCbkxx::getLjsl, jtzqljl)
                .eq(YhCbkxx::getCbkid, cbkid)
                .update();
    }
}
