/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.watermeter.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.StringUtil;
import com.tofly.common.oauth.exception.ToflyDeniedException;
import com.tofly.watermeter.em.AbnormalEnum;
import com.tofly.watermeter.entity.Readabnormal;
import com.tofly.watermeter.service.ReadabnormalService;
import org.springframework.stereotype.Service;
import com.tofly.watermeter.mapper.ReadabnormalMapper;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * 抄表异常算法配置表
 *
 * @author wangjieliu
 * @date Wed Dec 01 00:00:00 CST 2021
 */
@Service("readabnormalService")
public class ReadabnormalServiceImpl extends ServiceImpl<ReadabnormalMapper, Readabnormal> implements ReadabnormalService {

    @Override
    public ResultRespone saveAbnormalArith(Readabnormal readabnormal) {
        String typeCode = readabnormal.getTypeCode();
        Long type = readabnormal.getType();
        String typeName = readabnormal.getTypeName();
        String modelName = readabnormal.getModelName();
        if (StringUtil.isEmpty(typeCode) || StringUtil.isNull(type) || StringUtil.isEmpty(typeName) || StringUtil.isEmpty(modelName)) {
            return ResultRespone.failed(false, "请选择异常类型");
        }
        String ysxzBmS = readabnormal.getYsxzBm();
        String sbkjBmS = readabnormal.getSbkjBm();
        Float fiducialValue = readabnormal.getFiducialValue();//基准值 属于阈值
        Float nosediveValue = readabnormal.getNosediveValue();//水量突降值，突降值不算在阈值范围中，后面改成比例了
        Float ratio = readabnormal.getRatio();//比列
        Float minAverageValue = readabnormal.getMinAverageValue();//最小平均基准值 属于阈值
        Integer count = readabnormal.getCount();//次数
        String firstRead = readabnormal.getFirstRead();//首次抄表情况：0：首次抄表水量为0；1：首次非正常方式抄表
        String isYearorchain = readabnormal.getIsYearorchain();//主要用于水量微幅波动模型；0：同比；1：环比
        String isUpordown = readabnormal.getIsUpordown();//主要用于水量微幅波动模型；0：升；1：降


        //1水量突变模型
        if (AbnormalEnum.SLTJMX.getTypeCode().equals(typeCode) || AbnormalEnum.SLTSMX.getTypeCode().equals(typeCode)) {
            if (StringUtil.isEmpty(ysxzBmS)) {
                return ResultRespone.failed(false, "请选择用水性质");
            } else if (StringUtil.isEmpty(sbkjBmS)) {
                return ResultRespone.failed(false, "请选择水表口径");
            } else if (StringUtil.isNull(minAverageValue)) {
                return ResultRespone.failed(false, "最小平均基准值");
            } else if (StringUtil.isNull(nosediveValue)) {
                return ResultRespone.failed(false, "请输入突降值");//后面改成使用比例比较
            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));
            List<String> sbkjList = Arrays.asList(sbkjBmS.split(","));
            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                for (String sbkjBm1 : sbkjList) {
                    //查询是否有想用的算法配置
                    Readabnormal isExist = this.getOne(Wrappers.<Readabnormal>lambdaQuery().eq(Readabnormal::getType, type)
                            .eq(Readabnormal::getYsxzBm, ysxzBm1).eq(Readabnormal::getSbkjBm, sbkjBm1).select(Readabnormal::getId));
                    if (StringUtil.isNotNull(isExist)) {
                        throw new ToflyDeniedException("已存在相同的配置");
                    }
                    if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                        if (AbnormalEnum.SLTJMX.getTypeCode().equals(typeCode)) {
                            readabnormal.setDescribe("水量突降模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，本次用水量大于等于基准值：" + minAverageValue + "，且小于等于突降值：" + nosediveValue + "%");
                        } else {
                            readabnormal.setDescribe("水量突升模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，本次用水量大于等于基准值：" + minAverageValue + "，且大于等于突降值：" + nosediveValue + "%");
                        }
                    }
                    readabnormal.setSbkjBm(sbkjBm1);
                    readabnormal.setYsxzBm(ysxzBm1);
                    this.save(readabnormal);
                }
            }
        }
        //2同比升模型 //3同比降模型 //4环比升 //5环比降
        else if (AbnormalEnum.TBSMX.getTypeCode().equals(typeCode) || AbnormalEnum.TBJMX.getTypeCode().equals(typeCode)
                || AbnormalEnum.HBSMX.getTypeCode().equals(typeCode) || AbnormalEnum.HBJMX.getTypeCode().equals(typeCode)) {
            if (StringUtil.isEmpty(ysxzBmS)) {
                return ResultRespone.failed(false, "请选择用水性质");
            } else if (StringUtil.isEmpty(sbkjBmS)) {
                return ResultRespone.failed(false, "请选择水表口径");
            } else if (StringUtil.isNull(minAverageValue)) {
                return ResultRespone.failed(false, "请输入最小水量平均基准值");
            } else if (StringUtil.isNull(ratio)) {
                return ResultRespone.failed(false, "请输入比例");
            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));
            List<String> sbkjList = Arrays.asList(sbkjBmS.split(","));
            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                for (String sbkjBm1 : sbkjList) {
                    //查询是否有想用的算法配置
                    Readabnormal isExist = this.getOne(Wrappers.<Readabnormal>lambdaQuery().eq(Readabnormal::getType, type)
                            .eq(Readabnormal::getYsxzBm, ysxzBm1).eq(Readabnormal::getSbkjBm, sbkjBm1)
                            .select(Readabnormal::getId));
                    if (StringUtil.isNotNull(isExist)) {
                        throw new ToflyDeniedException("已存在相同的配置");
                    }
                    if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                        if (AbnormalEnum.TBSMX.getTypeCode().equals(typeCode)) {
                            readabnormal.setDescribe("同比升比列模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前三年同月水量平均值超过最小水量平均基准值：" + minAverageValue + "，且同比升比例超过：" + ratio + "%");
                        } else if (AbnormalEnum.TBJMX.getTypeCode().equals(typeCode)) {
                            readabnormal.setDescribe("同比降比列模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前三年同月水量平均值超过最小水量平均基准值：" + minAverageValue + "，且同比降比例超过：" + ratio + "%");
                        } else if (AbnormalEnum.HBSMX.getTypeCode().equals(typeCode)) {
                            readabnormal.setDescribe("环比升比列模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前三次水量平均值超过最小水量平均基准值：" + minAverageValue + "，且环比升比例超过：" + ratio + "%");
                        } else if (AbnormalEnum.HBJMX.getTypeCode().equals(typeCode)) {
                            readabnormal.setDescribe("环比降比列模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前三次水量平均值超过最小水量平均基准值：" + minAverageValue + "，且环比降比例超过：" + ratio + "%");
                        }
                    }
                    readabnormal.setYsxzBm(ysxzBm1);
                    readabnormal.setSbkjBm(sbkjBm1);
                    this.save(readabnormal);
                }
            }
        }
        //6 0水量模型
        else if (AbnormalEnum.LSLMX.getTypeCode().equals(typeCode)) {
            if (StringUtil.isEmpty(ysxzBmS)) {
                return ResultRespone.failed(false, "请选择用水性质");
            } else if (StringUtil.isEmpty(sbkjBmS)) {
                return ResultRespone.failed(false, "请选择水表口径");
            } else if (StringUtil.isNull(count)) {
                return ResultRespone.failed(false, "请输入次数");
            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));
            List<String> sbkjList = Arrays.asList(sbkjBmS.split(","));
            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                for (String sbkjBm1 : sbkjList) {
                    //查询是否有想用的算法配置
                    Readabnormal isExist = this.getOne(Wrappers.<Readabnormal>lambdaQuery().eq(Readabnormal::getType, type)
                            .eq(Readabnormal::getYsxzBm, ysxzBm1).eq(Readabnormal::getSbkjBm, sbkjBm1).select(Readabnormal::getId));
                    if (StringUtil.isNotNull(isExist)) {
                        throw new ToflyDeniedException("已存在相同的配置");
                    }
                    if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                        readabnormal.setDescribe("0水量模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前" + count + "次抄表水量为0；且本次抄表水量也为0");
                    }
                    readabnormal.setYsxzBm(ysxzBm1);
                    readabnormal.setSbkjBm(sbkjBm1);
                    this.save(readabnormal);
                }
            }
        }
        //7换表 //8估水
        else if (AbnormalEnum.HBMX.getTypeCode().equals(typeCode) || AbnormalEnum.GSMX.getTypeCode().equals(typeCode)) {
            //查询是否有想用的算法配置
            Readabnormal isExist = this.getOne(Wrappers.<Readabnormal>lambdaQuery().eq(Readabnormal::getType, type).select(Readabnormal::getId));
            if (StringUtil.isNotNull(isExist)) {
                throw new ToflyDeniedException("已存在相同的配置");
            }
            if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                if (AbnormalEnum.HBMX.getTypeCode().equals(typeCode)) {
                    readabnormal.setDescribe("换表信息模型：在上次抄表后，本次抄表前，水表进行了更换操作");
                } else if (AbnormalEnum.GSMX.getTypeCode().equals(typeCode)) {
                    readabnormal.setDescribe("估水信息模型：因各种原因进行估水方式抄表");
                }
            }
            this.save(readabnormal);
        }
        //9水量微幅波动
        else if (AbnormalEnum.SLWFBDMX.getTypeCode().equals(typeCode)) {
            if (StringUtil.isEmpty(ysxzBmS)) {
                return ResultRespone.failed(false, "请选择用水性质");
            } else if (StringUtil.isEmpty(sbkjBmS)) {
                return ResultRespone.failed(false, "请选择水表口径");
            } else if (StringUtil.isNull(fiducialValue)) {
                return ResultRespone.failed(false, "请输入基准值");
            } else if (StringUtil.isNull(ratio)) {
                return ResultRespone.failed(false, "请输入比例");
            } else if (!"0".equals(isYearorchain) && !"1".equals(isYearorchain)) {
                return ResultRespone.failed(false, "请选择同比环比");
            } else if (!"0".equals(isUpordown) && !"1".equals(isUpordown)) {
                return ResultRespone.failed(false, "请选择升/降比例");
            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));
            List<String> sbkjList = Arrays.asList(sbkjBmS.split(","));
            String isUpordownName = baseMapper.getIsUpordownName(isUpordown);
            String isYearorchainName = baseMapper.getIsYearorchainName(isYearorchain);
            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                for (String sbkjBm1 : sbkjList) {
                    //查询是否有想用的算法配置
                    Readabnormal isExist = this.getOne(Wrappers.<Readabnormal>lambdaQuery().eq(Readabnormal::getType, type)
                            .eq(Readabnormal::getYsxzBm, ysxzBm1).eq(Readabnormal::getSbkjBm, sbkjBm1)
                            .eq(Readabnormal::getIsUpordown, isUpordown).eq(Readabnormal::getIsYearorchain, isYearorchain)
                            .select(Readabnormal::getId));
                    if (StringUtil.isNotNull(isExist)) {
                        throw new ToflyDeniedException("已存在相同的配置");
                    }
                    if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                        readabnormal.setDescribe("水量微幅波动模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，本次用水量超过基准值：" + fiducialValue + "，且" + isYearorchainName + isUpordownName + "超过：" + ratio + "%");
                    }
                    readabnormal.setYsxzBm(ysxzBm1);
                    readabnormal.setSbkjBm(sbkjBm1);
                    this.save(readabnormal);
                }
            }
        }
        //10水量连续上升 //11水量连续下降
        else if (AbnormalEnum.SLLXSSMX.getTypeCode().equals(typeCode) || AbnormalEnum.SLLXXJMX.getTypeCode().equals(typeCode)) {
            if (StringUtil.isNull(count)) {
                return ResultRespone.failed(false, "请输入次数");
            }
            //查询是否有想用的算法配置
            Readabnormal isExist = this.getOne(Wrappers.<Readabnormal>lambdaQuery().eq(Readabnormal::getType, type)
                    .select(Readabnormal::getId));
            if (StringUtil.isNotNull(isExist)) {
                throw new ToflyDeniedException("已存在相同的配置");
            }
            if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                if (AbnormalEnum.SLLXSSMX.getTypeCode().equals(typeCode)) {
                    readabnormal.setDescribe("水量连续上升模型：水量连续" + count + "次及以上持续上升");
                } else if (AbnormalEnum.SLLXXJMX.getTypeCode().equals(typeCode)) {
                    readabnormal.setDescribe("水量连续下降模型：水量连续" + count + "次及以上持续下降");
                }
            }
            this.save(readabnormal);
        }
        //12首次水量
        else if (AbnormalEnum.SCSLMX.getTypeCode().equals(typeCode)) {
            String firstReadName = baseMapper.getFirstReadName(firstRead);
            if (!"0".equals(firstRead) && !"1".equals(firstRead)) {
                return ResultRespone.failed(false, "请选择首次抄表情况");
            }
            //查询是否有想用的算法配置
            Readabnormal isExist = this.getOne(Wrappers.<Readabnormal>lambdaQuery().eq(Readabnormal::getType, type)
                    .eq(Readabnormal::getFirstRead, firstRead).select(Readabnormal::getId));
            if (StringUtil.isNotNull(isExist)) {
                throw new ToflyDeniedException("已存在相同的配置");
            }
            if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                readabnormal.setDescribe("首次水量模型：" + firstReadName);
            }
            this.save(readabnormal);
        }
        //13连续水量相同
        else if (AbnormalEnum.LXSLXTMX.getTypeCode().equals(typeCode)) {
            if (StringUtil.isNull(count)) {
                return ResultRespone.failed(false, "请输入次数");
            }
            //查询是否有想用的算法配置
            Readabnormal isExist = this.getOne(Wrappers.<Readabnormal>lambdaQuery().eq(Readabnormal::getType, type).select(Readabnormal::getId));
            if (StringUtil.isNotNull(isExist)) {
                throw new ToflyDeniedException("已存在相同的配置");
            }
            if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                readabnormal.setDescribe("连续水量相同模型：连续" + count + "次及以上抄表水量相同");
            }
            this.save(readabnormal);
        } else {
            return ResultRespone.failed(false, "请正确选择算法模型类型");
        }
        return ResultRespone.success(true, "成功");
    }

    @Override
    public ResultRespone saveAbnormalArith2(Readabnormal readabnormal) {
        String typeCode = readabnormal.getTypeCode();
        Long type = readabnormal.getType();
        String typeName = readabnormal.getTypeName();
        String modelName = readabnormal.getModelName();
        if (StringUtil.isEmpty(typeCode) || StringUtil.isNull(type) || StringUtil.isEmpty(typeName) || StringUtil.isEmpty(modelName)) {
            return ResultRespone.failed(false, "请选择异常类型");
        }
        String ysxzBmS = readabnormal.getYsxzBm();
        String sbkjBm1 = readabnormal.getSbkjBm();
        Float fiducialValue = readabnormal.getFiducialValue();//基准值 属于阈值
//        Float nosediveValue = readabnormal.getNosediveValue();//水量突降值，突降值不算在阈值范围中，后面改成比例了
        Float ratio = readabnormal.getRatio();//比列
        Float minAverageValue = readabnormal.getMinAverageValue();//最小平均基准值 属于阈值
        Integer count = readabnormal.getCount();//次数
        String isYearorchain = readabnormal.getIsYearorchain();//主要用于水量微幅波动模型；0：同比；1：环比
        String isUpordown = readabnormal.getIsUpordown();//主要用于水量微幅波动模型；0：升；1：降
        //1水量突变模型
        if (AbnormalEnum.SLTJMX.getTypeCode().equals(typeCode) || AbnormalEnum.SLTSMX.getTypeCode().equals(typeCode)) {
//            if (StringUtil.isEmpty(ysxzBmS)) {
//                return ResultRespone.failed(false, "请选择用水性质");
//            } else if (StringUtil.isEmpty(sbkjBmS)) {
//                return ResultRespone.failed(false, "请选择水表口径");
//            }
//            else if (StringUtil.isNull(minAverageValue)) {
//                return ResultRespone.failed(false, "最小平均基准值");
//            } else if (StringUtil.isNull(nosediveValue)) {
//                return ResultRespone.failed(false, "请输入突降值");是比例值
//            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));
            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                    if (AbnormalEnum.SLTJMX.getTypeCode().equals(typeCode)) {
                        readabnormal.setDescribe("水量突降模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，本次用水量大于等于最小平均基准值：" + minAverageValue + "，且突降比例大于等于值：" + ratio + "%");
                    } else {
                        readabnormal.setDescribe("水量突升模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，本次用水量大于等于最小平均基准值：" + minAverageValue + "，且突升比例大于等于值：" + ratio + "%");
                    }
                }
                readabnormal.setSbkjBm(sbkjBm1);
                readabnormal.setYsxzBm(ysxzBm1);
                this.save(readabnormal);

            }
        }
        //2同比升模型 //3同比降模型 //4环比升 //5环比降
        else if (AbnormalEnum.TBSMX.getTypeCode().equals(typeCode) || AbnormalEnum.TBJMX.getTypeCode().equals(typeCode)
                || AbnormalEnum.HBSMX.getTypeCode().equals(typeCode) || AbnormalEnum.HBJMX.getTypeCode().equals(typeCode)) {
//            if (StringUtil.isEmpty(ysxzBmS)) {
//                return ResultRespone.failed(false, "请选择用水性质");
//            } else if (StringUtil.isEmpty(sbkjBmS)) {
//                return ResultRespone.failed(false, "请选择水表口径");
//            } else if (StringUtil.isNull(minAverageValue)) {
//                return ResultRespone.failed(false, "请输入最小水量平均基准值");
//            } else if (StringUtil.isNull(ratio)) {
//                return ResultRespone.failed(false, "请输入比例");
//            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));

            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                    if (AbnormalEnum.TBSMX.getTypeCode().equals(typeCode)) {
                        readabnormal.setDescribe("同比升比列模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前三年同月水量平均值超过最小水量平均基准值：" + minAverageValue + "，且同比升比例超过：" + ratio + "%");
                    } else if (AbnormalEnum.TBJMX.getTypeCode().equals(typeCode)) {
                        readabnormal.setDescribe("同比降比列模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前三年同月水量平均值超过最小水量平均基准值：" + minAverageValue + "，且同比降比例超过：" + ratio + "%");
                    } else if (AbnormalEnum.HBSMX.getTypeCode().equals(typeCode)) {
                        readabnormal.setDescribe("环比升比列模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前三次水量平均值超过最小水量平均基准值：" + minAverageValue + "，且环比升比例超过：" + ratio + "%");
                    } else if (AbnormalEnum.HBJMX.getTypeCode().equals(typeCode)) {
                        readabnormal.setDescribe("环比降比列模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前三次水量平均值超过最小水量平均基准值：" + minAverageValue + "，且环比降比例超过：" + ratio + "%");
                    }
                }
                readabnormal.setYsxzBm(ysxzBm1);
                readabnormal.setSbkjBm(sbkjBm1);
                this.save(readabnormal);

            }
        }
        //6 0水量模型
        else if (AbnormalEnum.LSLMX.getTypeCode().equals(typeCode)) {
//            if (StringUtil.isEmpty(ysxzBmS)) {
//                return ResultRespone.failed(false, "请选择用水性质");
//            } else if (StringUtil.isEmpty(sbkjBmS)) {
//                return ResultRespone.failed(false, "请选择水表口径");
//            } else if (StringUtil.isNull(count)) {
//                return ResultRespone.failed(false, "请输入次数");
//            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));

            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                    readabnormal.setDescribe("0水量模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，前" + count + "次抄表水量为0；且本次抄表水量也为0");
                }
                readabnormal.setYsxzBm(ysxzBm1);
                readabnormal.setSbkjBm(sbkjBm1);
                this.save(readabnormal);

            }
        }
        //9水量微幅波动
        else if (AbnormalEnum.SLWFBDMX.getTypeCode().equals(typeCode)) {
//            if (StringUtil.isEmpty(ysxzBmS)) {
//                return ResultRespone.failed(false, "请选择用水性质");
//            } else if (StringUtil.isEmpty(sbkjBmS)) {
//                return ResultRespone.failed(false, "请选择水表口径");
//            } else if (StringUtil.isNull(fiducialValue)) {
//                return ResultRespone.failed(false, "请输入基准值");
//            } else if (StringUtil.isNull(ratio)) {
//                return ResultRespone.failed(false, "请输入比例");
//            } else if (!"0".equals(isYearorchain) && !"1".equals(isYearorchain)) {
//                return ResultRespone.failed(false, "请选择同比环比");
//            } else if (!"0".equals(isUpordown) && !"1".equals(isUpordown)) {
//                return ResultRespone.failed(false, "请选择升/降比例");
//            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));
            String isUpordownName = baseMapper.getIsUpordownName(isUpordown);
            String isYearorchainName = baseMapper.getIsYearorchainName(isYearorchain);
            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                    if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                        readabnormal.setDescribe("水量微幅波动模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，本次用水量超过基准值：" + fiducialValue + "，且" + isYearorchainName + isUpordownName + "不超过：" + ratio + "%");
                    }
                    readabnormal.setYsxzBm(ysxzBm1);
                    readabnormal.setSbkjBm(sbkjBm1);
                    this.save(readabnormal);
            }
        }
        //10水量连续上升 //11水量连续下降
        else if (AbnormalEnum.SLLXSSMX.getTypeCode().equals(typeCode) || AbnormalEnum.SLLXXJMX.getTypeCode().equals(typeCode)) {
//            if (StringUtil.isNull(count)) {
//                return ResultRespone.failed(false, "请输入次数");
//            }
//            if (StringUtil.isEmpty(ysxzBmS)) {
//                return ResultRespone.failed(false, "请选择用水性质");
//            } else if (StringUtil.isEmpty(sbkjBmS)) {
//                return ResultRespone.failed(false, "请选择水表口径");
//            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));
            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                    if (AbnormalEnum.SLLXSSMX.getTypeCode().equals(typeCode)) {
                        readabnormal.setDescribe("水量连续上升模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，水量连续" + count + "次及以上持续上升");
                    } else if (AbnormalEnum.SLLXXJMX.getTypeCode().equals(typeCode)) {
                        readabnormal.setDescribe("水量连续下降模型：" + ysxzName + "，水表口径：" + sbkjBm1 + "，水量连续" + count + "次及以上持续下降");
                    }
                }
                readabnormal.setYsxzBm(ysxzBm1);
                readabnormal.setSbkjBm(sbkjBm1);
                this.save(readabnormal);
            }
        }
        //13连续水量相同
        else if (AbnormalEnum.LXSLXTMX.getTypeCode().equals(typeCode)) {
//            if (StringUtil.isNull(count)) {
//                return ResultRespone.failed(false, "请输入次数");
//            }
            List<String> ysxzList = Arrays.asList(ysxzBmS.split(","));
            for (String ysxzBm1 : ysxzList) {
                //查询用水性质
                String ysxzName = baseMapper.getYsxzName(ysxzBm1);
                if (StringUtil.isEmpty(readabnormal.getDescribe())) {
                    readabnormal.setDescribe("连续水量相同模型："  + ysxzName + "，水表口径：" + sbkjBm1 + "，连续" + count + "次及以上抄表水量相同");
                }
                readabnormal.setYsxzBm(ysxzBm1);
                readabnormal.setSbkjBm(sbkjBm1);
                this.save(readabnormal);
            }
        } else {
            return ResultRespone.failed(false, "请正确选择算法模型类型");
        }
        return ResultRespone.success(true, "成功");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultRespone updateAbnormalArith(Readabnormal readabnormal) {
        Long id = readabnormal.getId();
        if (StringUtil.isNull(id)) {
            throw new ToflyDeniedException("算法配置ID必传");
        }
        boolean flag = this.removeById(id);
        if (flag) {
            saveAbnormalArith(readabnormal);
        }
        return ResultRespone.success(true, "成功");
    }
}
