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

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.mapper.YjTotalPoolWarnValueMapper;
import org.jeecg.modules.warningThreshold.params.YjTorqueWarnValuePageParams;
import org.jeecg.modules.warningThreshold.params.YjTotalPoolWarnValuePageParams;
import org.jeecg.modules.warningThreshold.service.YjTotalPoolWarnValueService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 总池体积预警阈值;(yj_total_pool_warn_value)表服务实现类
 * @author : http://www.chiner.pro
 * @date : 2025-1-7
 */
@Service
public class YjTotalPoolWarnValueServiceImpl extends ServiceImpl<YjTotalPoolWarnValueMapper, YjTotalPoolWarnValue> implements YjTotalPoolWarnValueService {


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

    @Override
    public  List<YjTotalPoolWarnValue> getListByJh(String jh){
        QueryWrapper<YjTotalPoolWarnValue> wrapper=new QueryWrapper<>();
        wrapper.lambda().eq(YjTotalPoolWarnValue::getJh,jh);
        List<YjTotalPoolWarnValue> list = this.list(wrapper);
        if(list.size()==0){
            list = createList(jh);
            this.saveBatch(list);
        }
        return list;
    }

    public List<YjTotalPoolWarnValue> createList(String jh){
        List<YjTotalPoolWarnValue> list =new ArrayList<>();
        YjTotalPoolWarnValue model=new YjTotalPoolWarnValue();
        model.setJh(jh);
        model.setWarnType("井漏");
        model.setBitdepth(BigDecimal.valueOf(500));
        model.setPittotalWarn(BigDecimal.valueOf(-2));
        model.setRanteWarn(BigDecimal.valueOf(-1));

        YjTotalPoolWarnValue model1=new YjTotalPoolWarnValue();
        model1.setJh(jh);
        model1.setWarnType("溢流");
        model1.setBitdepth(BigDecimal.valueOf(500));
        model1.setPittotalWarn(BigDecimal.valueOf(1));
        model1.setRanteWarn(BigDecimal.valueOf(0.5));
        list.add(model);
        list.add(model1);
        return list;
    }

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