package com.steerinfo.meterwork.meterworkcalibrationbranch.service.impl;

import com.steerinfo.baseinfo.meterbasecalibranumrel.mapper.MeterBaseCalibraNumRelMapper;
import com.steerinfo.baseinfo.meterbasecalibranumrel.model.MeterBaseCalibraNumRel;
import com.steerinfo.baseinfo.meterbasemutualdiff.mapper.MeterBaseMutualDiffMapper;
import com.steerinfo.baseinfo.meterbasemutualdiff.model.MeterBaseMutualDiff;
import com.steerinfo.baseinfo.meterbasescalerange.mapper.MeterBaseScaleRangeMapper;
import com.steerinfo.baseinfo.meterbasescalerange.model.MeterBaseScaleRange;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.meterworkcalibrationbranch.mapper.MeterWorkCalibrationBranchMapper;
import com.steerinfo.meterwork.meterworkcalibrationbranch.model.MeterWorkCalibrationBranch;
import com.steerinfo.meterwork.meterworkcalibrationbranch.service.IMeterWorkCalibrationBranchService;
import com.steerinfo.meterwork.meterworkcalibrationmain.mapper.MeterWorkCalibrationMainMapper;
import com.steerinfo.meterwork.meterworkcalibrationmain.model.MeterWorkCalibrationMain;
import com.steerinfo.util.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * MeterWorkCalibrationBranch服务实现：
 * @author generator
 * @version 1.0-SNAPSHORT 2020-09-25 02:54
 * 类描述
 * 修订历史：
 * 日期：2020-09-25
 * 作者：generator
 * 参考：
 * 描述：MeterWorkCalibrationBranch服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "meterWorkCalibrationBranchService")
public class MeterWorkCalibrationBranchServiceImpl extends BaseServiceImpl<MeterWorkCalibrationBranch, String> implements IMeterWorkCalibrationBranchService {

    @Resource
    private MeterBaseMutualDiffMapper meterBaseMutualDiffMapper;

    @Resource
    private MeterWorkCalibrationBranchMapper meterWorkCalibrationBranchMapper;

    @Resource
    private MeterBaseCalibraNumRelMapper meterBaseCalibraNumRelMapper;

    @Resource
    private MeterWorkCalibrationMainMapper meterWorkCalibrationMainMapper;

    @Resource
    private MeterBaseScaleRangeMapper meterBaseScaleRangeMapper;


    @Override
    protected IBaseMapper<MeterWorkCalibrationBranch, String> getMapper() {
        return meterWorkCalibrationBranchMapper;
    }



    @Override
    @Transactional(rollbackFor=Exception.class)
    public PageList<MeterWorkCalibrationBranch> getByMainNo(String calibrationMainNo,Integer pageNum, Integer pageSize)
    {
        if (calibrationMainNo == null && calibrationMainNo.equals("")) {
            throw new MarkerMetException(500,"校秤编号为空！！");
        }
        PageHelper.startPage(pageNum, pageSize);
        List<MeterWorkCalibrationBranch> rows = meterWorkCalibrationBranchMapper.getByMainNo(calibrationMainNo);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }


    /**
     * 较秤计量
     * @param mwcm 较秤计量主表
     * @param model 较秤计量从表
     * @return
     */
    @Override
    public  RESTfulResult doSaveWf(MeterWorkCalibrationMain mwcm,MeterWorkCalibrationBranch model){
        RESTfulResult rm = new RESTfulResult();
        mwcm.setCalibrationMainTime(new Date());
        model.setCreateTime(new Date());
        //判断校秤成功or失败
        switch (model.getCalibrationTypeNo()) {
            case "001005001": //自检
                rm = self(mwcm,model);
                break;
            case "001005002": //互检
                rm = mutual(mwcm,model);
                break;
            case "001005003": //砝码检
                rm = weights(mwcm,model);
                break;
            case "001005004"://巡检
                rm = inspection(mwcm,model);
                break;
            default:
                break;
        }
        return rm;
    }

    //砝码检判断成功or失败
    public  RESTfulResult weights(MeterWorkCalibrationMain mwcm,MeterWorkCalibrationBranch model){
        RESTfulResult rm = new RESTfulResult();
        //1、判断该次校秤是否成功
//        HashMap<String, Object> obj = new HashMap<>();
//        obj.put("baseSpotNo", model.getBaseSpotNo());
//        obj.put("baseSpotName", model.getBaseSpotName());
//        MeterBaseScaleRange mbsr = meterBaseScaleRangeMapper.selectWeight(obj);
//        if (Double.parseDouble(model.getCalibrationWeight() ) >= mbsr.getCounterWeight().doubleValue() - mbsr.getCounterWeightDiff().doubleValue() &&
//                Double.parseDouble(model.getCalibrationWeight() ) <= mbsr.getCounterWeight().doubleValue() + mbsr.getCounterWeightDiff().doubleValue()){
//            model.setValueFlag("1");//成功
//        }else{
//            model.setValueFlag("2");//失败
//        }
        //砝码检保存即视为成功
        model.setValueFlag("1");//成功
        List<MeterWorkCalibrationMain> list = insertOrUpdate(mwcm);
        String braNo = addCalibration(list,mwcm,model);
        rm.setMessage(braNo);
        return rm;
    }

    /**
     * 互检判断成功or失败
     * @param mwcm
     * @param model
     * @return
     */
    public  RESTfulResult  mutual(MeterWorkCalibrationMain mwcm,MeterWorkCalibrationBranch model){
        RESTfulResult rm = new RESTfulResult();
        //单双秤生效是由发起校秤一方决定，，，先判断对比计量点是否存在数据
        HashMap<String, Object> obj1 = new HashMap<>();
        obj1.put("baseSpotNo", mwcm.getBaseContrastSpotNo());
        obj1.put("baseSpotName", mwcm.getBaseContrastSpotName());
        obj1.put("calibrationTypeNo", model.getCalibrationTypeNo());
        obj1.put("calibrationTypeName", model.getCalibrationTypeName());
        obj1.put("baseSpotNoContrast", model.getBaseSpotNo());
        obj1.put("carNo", model.getCarNo());
        obj1.put("valueFlag", "1"); //成功
        List<MeterWorkCalibrationBranch>  list1 = meterWorkCalibrationBranchMapper.selectForJudge(obj1);
        HashMap<String, Object> obj = new HashMap<>();
        if (list1.size() > 0){
            //若对比点存在数据则对比点为主
            obj.put("baseSpotNo",list1.get(0).getBaseSpotNo());
            obj.put("spotTypeNo", list1.get(0).getSpotTypeNo());
            obj.put("calibrationTypeNo", list1.get(0).getCalibrationTypeNo());
        }else {
            obj.put("baseSpotNo",mwcm.getBaseSpotNo());
            obj.put("spotTypeNo", mwcm.getSpotTypeNo());
            obj.put("calibrationTypeNo", mwcm.getCalibrationTypeNo());
        }
        //1、判断单个生效还是同时生效
        List<MeterBaseCalibraNumRel>  mbcnr = meterBaseCalibraNumRelMapper.selectByParameters(obj);
        if (mbcnr.size() > 0 && StringUtils.isNotEmpty(mbcnr.get(0).getMutualStrategyNo())){
           if (mbcnr.get(0).getMutualStrategyNo().equals("001030001")){
               rm = mutualDouble(mwcm,model);
           }
           if (mbcnr.get(0).getMutualStrategyNo().equals("001030002")){
               rm = mutualSingle(mwcm,model);
           }
        }else {
            rm = mutualSingle(mwcm,model);
        }
        return rm;
    }

    /**
     * self 自检保存逻辑
     * @param mwcm
     * @param model
     * @return
     */
    public RESTfulResult self(MeterWorkCalibrationMain mwcm,MeterWorkCalibrationBranch model){
        RESTfulResult rm = new RESTfulResult();
        //1、判断主表是否有数据,(该条数据是否为第一条)
        List<MeterWorkCalibrationMain> list = insertOrUpdate(mwcm);
        //2、判断本次校秤是否成功
        if (list.isEmpty()){
            model.setValueFlag("1");//成功
        }else {
            HashMap<String, Object> obj = new HashMap<>();
            obj.put("calibrationMainNo", list.get(0).getCalibrationMainNo());
            List<MeterWorkCalibrationBranch> mwcbs = meterWorkCalibrationBranchMapper.selectByParameters(obj);
            //取得自检的最大差值
            HashMap<String, Object> obj1 = new HashMap<>();
            obj1.put("baseSpotNo", list.get(0).getBaseSpotNo());
            List<MeterBaseScaleRange> mbsrs = meterBaseScaleRangeMapper.selectByParameters(obj1);
            if(mbsrs.size() > 0 && mbsrs.get(0).getSelfWeightDiff() != null){
                Double a = Double.parseDouble(model.getCalibrationWeight());
                Double b = Double.parseDouble(mwcbs.get(0).getCalibrationWeight());
                if (Math.round(a-b) <= mbsrs.get(0).getSelfWeightDiff().doubleValue()){
                    model.setValueFlag("1");//成功
                }else {
                    model.setValueFlag("2");//失败
                }
            }else {
                model.setValueFlag("1");//成功
            }
        }
        //3、对数据进行保存
        String braNo = addCalibration(list,mwcm,model);
        rm.setMessage(braNo);
        return rm;
    }

    //巡检
    public  RESTfulResult inspection(MeterWorkCalibrationMain mwcm,MeterWorkCalibrationBranch model) {
        RESTfulResult rm = new RESTfulResult();
       //1、巡检直接判断成功
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String afl = formatter.format(model.getCreateTime());
        //2、主表数据
        String no = meterWorkCalibrationMainMapper.getNewID(afl);
        mwcm.setCalibrationMainNo(afl+no);
        mwcm.setValueFlag("2");//校秤成功
        mwcm.setCalibrationActNum(1);
        mwcm.setCalibrationNum(1);
        meterWorkCalibrationMainMapper.insertSelective(mwcm);
        //3、次表数据
        String no1 = meterWorkCalibrationBranchMapper.getNewID(afl);
        model.setCalibrationBranchNo(afl+no1);
        model.setCalibrationMainNo(mwcm.getCalibrationMainNo());
        model.setValueFlag("1");//成功
        meterWorkCalibrationBranchMapper.insertSelective(model);
        rm.setMessage(model.getCalibrationBranchNo());
        return rm;
    }

    //判断主表新增还是修改
    public List<MeterWorkCalibrationMain>  insertOrUpdate(MeterWorkCalibrationMain mwcm){
        HashMap<String, Object> obj = new HashMap<>();
        obj.put("baseSpotNo", mwcm.getBaseSpotNo());
        obj.put("baseSpotName", mwcm.getBaseSpotName());
        obj.put("calibrationTypeNo", mwcm.getCalibrationTypeNo());
        obj.put("calibrationTypeName", mwcm.getCalibrationTypeName());
        obj.put("valueFlag", "3"); //正在校秤
        obj.put("calibrationMainTime",mwcm.getCalibrationMainTime());
        List<MeterWorkCalibrationMain>  list = meterWorkCalibrationMainMapper.selectForFlag(obj);
        return list;
    }

    /**
     * 判断后保存数据
     * @param list 主表的数据，若存在则list不为空；若不存在，则list为空
     * @param mwcm 当次的较秤主表的数据
     * @param model 当次的较秤从表的数据
     * @return
     */
    public String addCalibration(List<MeterWorkCalibrationMain> list,MeterWorkCalibrationMain mwcm,MeterWorkCalibrationBranch model){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String afl = formatter.format(model.getCreateTime());
        if (list.isEmpty()){
            //1、新增
            String no = meterWorkCalibrationMainMapper.getNewID(afl);
            mwcm.setCalibrationMainNo(afl+no);
            //1.1补充数据
            if (model.getValueFlag().equals("2")) {
                mwcm.setCalibrationActNum(0);
            }else {
                mwcm.setCalibrationActNum(1);
            }
            mwcm.setCalibrationMainTime(model.getCreateTime());
            mwcm.setValueFlag("3");
            //1.2查询匹配的计量次数
            HashMap<String, Object> obj = new HashMap<>();
            obj.put("baseSpotNo", model.getBaseSpotNo());
            obj.put("baseSpotName", model.getBaseSpotName());
            obj.put("spotTypeNo", model.getSpotTypeNo());
            obj.put("spotTypeName", model.getSpotTypeName());
            obj.put("calibrationTypeNo", model.getCalibrationTypeNo());
            obj.put("calibrationTypeName", model.getCalibrationTypeName());
            List<MeterBaseCalibraNumRel>  mbcns = meterBaseCalibraNumRelMapper.selectByParameters(obj);
            //配置为空直接判断失败或者成功
            if( mbcns.isEmpty() ){
                if ( model.getValueFlag().equals("1")){
                    mwcm.setValueFlag("2");//校秤成功
                }else{
                    mwcm.setValueFlag("1");//校秤失败
                }
                mwcm.setCalibrationNum(1);
            }else{
                mwcm.setCalibrationNum(mbcns.get(0).getCalibrationNum());
                //判断有效次数和实际次数
                if (model.getValueFlag().equals("2")) {
                    mwcm.setValueFlag("1");
                }else{
                    if (mwcm.getCalibrationActNum() >= mwcm.getCalibrationNum()){
                        mwcm.setValueFlag("2");
                    }else {
                        mwcm.setValueFlag("3");
                    }
                }
            }
            meterWorkCalibrationMainMapper.insertSelective(mwcm);
            model.setCalibrationMainNo(mwcm.getCalibrationMainNo());
        }else {
            //修改
            if (model.getValueFlag().equals("2")) {
                list.get(0).setValueFlag("1");
            }else {
                list.get(0).setCalibrationActNum(list.get(0).getCalibrationActNum()+1);
                if (list.get(0).getCalibrationActNum() >= list.get(0).getCalibrationNum()){
                    list.get(0).setValueFlag("2");
                }else {
                    list.get(0).setValueFlag("3");
                }
            }
            list.get(0).setCalibrationMainTime(model.getCreateTime());
             meterWorkCalibrationMainMapper.updateByPrimaryKeySelective(list.get(0));
            model.setCalibrationMainNo(list.get(0).getCalibrationMainNo());
        }
        String no1 = meterWorkCalibrationBranchMapper.getNewID(afl);
        model.setCalibrationBranchNo(afl+no1);
        meterWorkCalibrationBranchMapper.insert(model);
        return model.getCalibrationBranchNo();
    }

    /**
     * 单个生效的互检
     * @param mwcm 检验主表数据
     * @param model 检验从表数据
     * @return
     */
    private RESTfulResult mutualSingle(MeterWorkCalibrationMain mwcm,MeterWorkCalibrationBranch model){
        RESTfulResult rm = new RESTfulResult();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String afl = formatter.format(model.getCreateTime());
        //1.取得对比点,判断对比点有没有数据
        String braNo = "";
        HashMap<String, Object> obj1 = new HashMap<>();
        obj1.put("baseSpotNo", mwcm.getBaseContrastSpotNo());
        obj1.put("baseSpotName", mwcm.getBaseContrastSpotName());
        obj1.put("calibrationTypeNo", model.getCalibrationTypeNo());
        obj1.put("calibrationTypeName", model.getCalibrationTypeName());
        obj1.put("baseSpotNoContrast", model.getBaseSpotNo());
        obj1.put("carNo", model.getCarNo());
        obj1.put("valueFlag", "1"); //成功
        List<MeterWorkCalibrationBranch>  list1 = meterWorkCalibrationBranchMapper.selectForJudge(obj1);
        //判断校秤是否成功
        if(list1.isEmpty()){
            //互检的第一次
            mwcm.setValueFlag("3");//主表:正在校秤
            model.setValueFlag("1");//次表:成功
            List<MeterWorkCalibrationMain> list = insertOrUpdate(mwcm);
            braNo = addCalibration(list,mwcm,model);
            rm.setMessage(braNo);
            return rm;
        }else{
            //取得互检差值的数据,判断是否符合要求
            HashMap<String, Object> obj2= new HashMap<>();
            obj2.put("baseSpotNo", mwcm.getBaseSpotNo());
            obj2.put("baseContrastSpotNo", mwcm.getBaseContrastSpotNo());
            List<MeterBaseMutualDiff>  mbmds = meterBaseMutualDiffMapper.selectDiffWeight(obj2);
            Float a = Float.parseFloat(model.getCalibrationWeight() )- Float.parseFloat(list1.get(0).getCalibrationWeight());
            Float b = Math.abs(a);
            if (b <= mbmds.get(0).getDiffWeight().floatValue()){
                model.setValueFlag("1");//成功
            }else {
                model.setValueFlag("2");//失败
            }
            //互检改写主表的值
            HashMap<String, Object> obj3 = new HashMap<>();
            obj3.put("baseSpotNo", mwcm.getBaseContrastSpotNo());
            obj3.put("baseSpotName", mwcm.getBaseContrastSpotName());
            obj3.put("calibrationTypeNo", model.getCalibrationTypeNo());
            obj3.put("calibrationTypeName", model.getCalibrationTypeName());
            obj3.put("valueFlag", "3"); //正在校秤
            List<MeterWorkCalibrationMain>  list2 = meterWorkCalibrationMainMapper.selectByParameters(obj3);
            if (!list2.isEmpty()) {
                MeterWorkCalibrationMain contrast = list2.get(0);
                if (model.getValueFlag().equals("1"))//成功
                {
                    contrast.setCalibrationActNum(contrast.getCalibrationActNum() + 1);
                    contrast.setBaseSuccContSpotNo(model.getBaseSpotNo());
                    contrast.setBaseSuccConSpotName(model.getBaseSpotName());
                }
                if (contrast.getCalibrationActNum() >= contrast.getCalibrationNum()){
                    contrast.setValueFlag("2");
                }else {
                    contrast.setValueFlag("1");
                }
                contrast.setCalibrationMainTime(mwcm.getCalibrationMainTime());
                meterWorkCalibrationMainMapper.updateByPrimaryKeySelective(contrast);
                model.setCalibrationMainNo(contrast.getCalibrationMainNo());
                //获取比对校秤计量编号
                HashMap<String, Object> obj4 = new HashMap<>();
                obj4.put("calibrationMainNo", model.getCalibrationMainNo());
                obj4.put("baseSpotNo", contrast.getBaseSpotNo());
                List<MeterWorkCalibrationBranch> list3 = meterWorkCalibrationBranchMapper.selectByParameters(obj4);
                if (list3.size() > 0){
                    model.setCalibrContrastBranchNo(list3.get(0).getCalibrationBranchNo());
                }
                list3.get(0).setCalibrContrastBranchNo(model.getCalibrationBranchNo());
                meterWorkCalibrationBranchMapper.updateByPrimaryKeySelective(list3.get(0));
            }
            String no1 = meterWorkCalibrationBranchMapper.getNewID(afl);
            model.setCalibrationBranchNo(afl+no1);
            meterWorkCalibrationBranchMapper.insert(model);
            if(model.getValueFlag().equals("2")){
                MeterWorkCalibrationBranch mwcb = meterWorkCalibrationBranchMapper.selectByPrimaryKey(model.getCalibrContrastBranchNo());
                rm.setData(mwcb);
            }
        }
        rm.setMessage(model.getCalibrationBranchNo());
        return rm;
    }

    //同时生效的互检
    private RESTfulResult mutualDouble(MeterWorkCalibrationMain mwcm,MeterWorkCalibrationBranch model){
        RESTfulResult rm = new RESTfulResult();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String afl = formatter.format(model.getCreateTime());
        //1.取得对比点,判断对比点有没有数据
        String braNo = "";
        HashMap<String, Object> obj1 = new HashMap<>();
        obj1.put("baseSpotNo", mwcm.getBaseContrastSpotNo());
        obj1.put("baseSpotName", mwcm.getBaseContrastSpotName());
        obj1.put("calibrationTypeNo", model.getCalibrationTypeNo());
        obj1.put("calibrationTypeName", model.getCalibrationTypeName());
        obj1.put("baseSpotNoContrast", model.getBaseSpotNo());
        obj1.put("carNo", model.getCarNo());
        obj1.put("valueFlag", "1"); //成功
        List<MeterWorkCalibrationBranch>  list1 = meterWorkCalibrationBranchMapper.selectForJudge(obj1);
        //判断校秤是否成功
        if(list1.isEmpty()){
            //互检的第一次
            mwcm.setValueFlag("3");//主表:正在校秤
            model.setValueFlag("1");//次表:成功
            List<MeterWorkCalibrationMain> list = insertOrUpdate(mwcm);
            braNo = addCalibration(list,mwcm,model);
            rm.setMessage(braNo);
            return rm;
        }else{
            //取得互检差值的数据,判断是否符合要求
            HashMap<String, Object> obj2= new HashMap<>();
            obj2.put("baseSpotNo", mwcm.getBaseSpotNo());
            obj2.put("baseContrastSpotNo", mwcm.getBaseContrastSpotNo());
            List<MeterBaseMutualDiff>  mbmds = meterBaseMutualDiffMapper.selectDiffWeight(obj2);
            Float a = Float.parseFloat(model.getCalibrationWeight() )- Float.parseFloat(list1.get(0).getCalibrationWeight());
            Float b = Math.abs(a);
            if (b <= mbmds.get(0).getDiffWeight().floatValue()){
                model.setValueFlag("1");//成功
            }else {
                model.setValueFlag("2");//失败
            }
            //互检改写主表的值
            HashMap<String, Object> obj3 = new HashMap<>();
            obj3.put("baseSpotNo", mwcm.getBaseContrastSpotNo());
            obj3.put("baseSpotName", mwcm.getBaseContrastSpotName());
            obj3.put("calibrationTypeNo", model.getCalibrationTypeNo());
            obj3.put("calibrationTypeName", model.getCalibrationTypeName());
            obj3.put("valueFlag", "3"); //正在校秤
            List<MeterWorkCalibrationMain>  list2 = meterWorkCalibrationMainMapper.selectByParameters(obj3);
            MeterWorkCalibrationMain contrast = list2.get(0);
            if (!list2.isEmpty()) {
                contrast.setBaseContrastSpotNo(model.getBaseSpotNo());
                contrast.setBaseContrastSpotName(model.getBaseSpotName());
                if (model.getValueFlag().equals("1"))//成功
                {
                    contrast.setCalibrationActNum(contrast.getCalibrationActNum() + 1);
                    contrast.setBaseSuccContSpotNo(model.getBaseSpotNo());
                    contrast.setBaseSuccConSpotName(model.getBaseSpotName());
                }
                if (contrast.getCalibrationActNum() >= contrast.getCalibrationNum()){
                    contrast.setValueFlag("2");
                }else {
                    contrast.setValueFlag("1");
                }

                contrast.setCalibrationMainTime(mwcm.getCalibrationMainTime());
                meterWorkCalibrationMainMapper.updateByPrimaryKeySelective(contrast);
                model.setCalibrationMainNo(contrast.getCalibrationMainNo());
                //获取比对校秤计量编号
                HashMap<String, Object> obj4 = new HashMap<>();
                obj4.put("calibrationMainNo", model.getCalibrationMainNo());
                obj4.put("baseSpotNo", contrast.getBaseSpotNo());
                List<MeterWorkCalibrationBranch> list3 = meterWorkCalibrationBranchMapper.selectByParameters(obj4);
                if (list3.size() > 0){
                    model.setCalibrContrastBranchNo(list3.get(0).getCalibrationBranchNo());
                }
                list3.get(0).setCalibrContrastBranchNo(model.getCalibrationBranchNo());
                meterWorkCalibrationBranchMapper.updateByPrimaryKeySelective(list3.get(0));
            }
            String no1 = meterWorkCalibrationBranchMapper.getNewID(afl);
            model.setCalibrationBranchNo(afl+no1);
            meterWorkCalibrationBranchMapper.insert(model);

            //因为是同时生效，再为对比点生成相应的数据，（一条主表，两条次表）
            //1、主表数据
            MeterWorkCalibrationMain another = mwcm;
            String no = meterWorkCalibrationMainMapper.getNewID(afl);
            another.setCalibrationMainNo(afl+no);
            another.setCalibrationNum(contrast.getCalibrationNum());
            another.setCalibrationActNum(contrast.getCalibrationActNum());
            another.setValueFlag(contrast.getValueFlag());
            if (contrast.getValueFlag().equals("2")){
                another.setBaseSuccContSpotNo(contrast.getBaseSpotNo());
                another.setBaseSuccConSpotName(contrast.getBaseSpotName());
            }
            meterWorkCalibrationMainMapper.insertSelective(another);
            //2、次表数据
            HashMap<String, Object> obj5 = new HashMap<>();
            obj5.put("calibrationMainNo", model.getCalibrationMainNo());
            List<MeterWorkCalibrationBranch> list3 = meterWorkCalibrationBranchMapper.selectByParameters(obj5);
            if (list3.size() > 0){
                for (int i = 0 ; i < list3.size(); i++)
                {
                    String newBra = meterWorkCalibrationBranchMapper.getNewID(afl);
                    list3.get(i).setCalibrationBranchNo(afl+newBra);
                    list3.get(i).setCalibrationMainNo(mwcm.getCalibrationMainNo());
                    list3.get(i).setCalibrContrastBranchNo("");
                    if(i != 0){
                        list3.get(i).setCalibrContrastBranchNo(list3.get(i-1).getCalibrationBranchNo());
                    }
                    meterWorkCalibrationBranchMapper.insertSelective(list3.get(i));
                }
            }
        }
        rm.setMessage(model.getCalibrationBranchNo());
        return rm;
    }

    @Override
    public List<MeterWorkCalibrationBranch> selectForMutual(MeterWorkCalibrationBranch model){
        HashMap<String, Object> obj = new HashMap<>();
        obj.put("baseSpotNo", model.getBaseSpotNo());
        obj.put("carNo", model.getCarNo());
        List<MeterWorkCalibrationBranch> list = meterWorkCalibrationBranchMapper.selectForMutual(obj);
        return list;
    }


}
