package org.jeecg.modules.warningThreshold.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xkcoding.http.util.StringUtil;
import org.jeecg.modules.warningThreshold.entity.YjTorqueWarnValue;
import org.jeecg.modules.warningThreshold.entity.YjTotalPoolWarnValue;
import org.jeecg.modules.warningThreshold.entity.YjWohWarnValue;
import org.jeecg.modules.warningThreshold.mapper.YjWohWarnValueMapper;
import org.jeecg.modules.warningThreshold.params.YjTorqueWarnValuePageParams;
import org.jeecg.modules.warningThreshold.params.YjWohWarnValuePageParams;
import org.jeecg.modules.warningThreshold.service.YjWohWarnValueService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 钩载预警阈值管理;(yj_woh_warn_value)表服务实现类
 * @author : http://www.chiner.pro
 * @date : 2025-1-7
 */
@Service
public class YjWohWarnValueServiceImpl extends ServiceImpl<YjWohWarnValueMapper, YjWohWarnValue> implements YjWohWarnValueService {


    @Override
    public Page<YjWohWarnValue> page(YjWohWarnValuePageParams pageParams){
        QueryWrapper<YjWohWarnValue> wrapper = new QueryWrapper<>();
        if(StringUtil.isNotEmpty(pageParams.getJh())){
            wrapper.lambda().like(YjWohWarnValue::getJh,pageParams.getJh());
        }
        wrapper.lambda().orderByAsc(YjWohWarnValue::getJh);
        Page<YjWohWarnValue> page = new Page<>(pageParams.getPageNo(), pageParams.getPageSize());
        return  this.page(page, wrapper);
    }

    @Override
    public YjWohWarnValue getOneDataByJh(String jh){
        QueryWrapper<YjWohWarnValue> wrapper=new QueryWrapper<>();
        wrapper.lambda().eq(YjWohWarnValue::getJh,jh);
        YjWohWarnValue one = this.getOne(wrapper);
        if(ObjectUtil.isEmpty(one)){
            one = createModel(jh);
            this.save(one);
        }
        return one;
    }

    public YjWohWarnValue createModel(String jh){
        YjWohWarnValue model=new YjWohWarnValue();
        model.setJh(jh);
        model.setBitdepth(BigDecimal.valueOf(500));
        model.setRodWeight(BigDecimal.valueOf(7.73));
        model.setSustainWoh(BigDecimal.valueOf(100));
        model.setActivityOne(BigDecimal.valueOf(100));
        model.setActivityTwo(BigDecimal.valueOf(30));
        return model;
    }

    @Override
    public void saveOrUpd(YjWohWarnValue model){
        this.saveOrUpdate(model);
    }



}
