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

import com.steerinfo.baseinfo.combaseinfo.mapper.ComBaseInfoMapper;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.meterworkbeltscaleactual.mapper.MeterWorkBeltScaleActualMapper;
import com.steerinfo.meterwork.meterworkbeltscaleactual.model.MeterWorkBeltScaleActual;
import com.steerinfo.meterwork.meterworkbeltscaleactual.service.IMeterWorkBeltScaleActualService;
import com.steerinfo.util.CommonPage;
import org.springframework.stereotype.Service;

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

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

    @Resource
    private MeterWorkBeltScaleActualMapper meterWorkBeltScaleActualMapper;

    @Resource
    private ComBaseInfoMapper comBaseInfoMapper;

    @Override
    protected IBaseMapper<MeterWorkBeltScaleActual, String> getMapper() {
        return meterWorkBeltScaleActualMapper;
    }

    @Override
    public int doAddBeltScaleActual(MeterWorkBeltScaleActual model) {
        try{
            String maxID = comBaseInfoMapper.getConfigID("METER_WORK_BELT_SCALE_ACTUAL","ACTUAL_NO");
            model.setActualNo(maxID);
            model.setCreateTime(new Date());
            return  meterWorkBeltScaleActualMapper.insertSelective(model);
        }catch (Exception ex){
            throw ex;
        }
    }

    @Override
    public int updateBeltScaleActual(MeterWorkBeltScaleActual model) {
        if (model == null) {
            throw new MarkerMetException(500, "参数不允许为空!!");
        }
        try{
            if(model.getUpdateManName()!=null){
                model.setUpdateTime(new Date());
            }
            if(model.getFirstPrint()!=null){
                model.setFirstPrintTime(new Date());
            }else if(model.getSecondPrint()!=null){
                model.setSecondPrintTime(new Date());
            }
            return  meterWorkBeltScaleActualMapper.updateByPrimaryKeySelective(model);
        }catch (Exception ex){
            throw ex;
        }
    }

    @Override
    public List<MeterWorkBeltScaleActual> doQueryActualInfoFlags(MeterWorkBeltScaleActual model) {
        if (model == null) {
            throw new MarkerMetException(500, "参数不允许为空!!");
        }
        return meterWorkBeltScaleActualMapper.doQueryActualInfoFlags(model);
    }

    @Override
    public List<MeterWorkBeltScaleActual> doQueryMaxPno(MeterWorkBeltScaleActual model) {
        if (model == null) {
            throw new MarkerMetException(500, "参数不允许为空!!");
        }
        return meterWorkBeltScaleActualMapper.doQueryMaxPno(model);
    }

    @Override
    public List<MeterWorkBeltScaleActual> doQueryAndMultiple(CommonPage<MeterWorkBeltScaleActual> model) {
        HashMap<String, Object> obj = new HashMap<>();
        obj.put("startTime1", model.getStartTime());
        obj.put("endTime1", model.getEndTime());
        if (model.getParam().getProductName() != null) {
            obj.put("productName", model.getParam().getProductName());
        }
        if (model.getParam().getForwardingUnitName() != null) {
            obj.put("forwardingUnitName", model.getParam().getForwardingUnitName());
        }
        if (model.getParam().getNewMatName() != null) {
            obj.put("newMatName", model.getParam().getNewMatName());
        }
        if (model.getParam().getNewSupplier() != null) {
            obj.put("newSupplier", model.getParam().getNewSupplier());
        }
        if (model.getParam().getReceivingUintName() != null) {
            obj.put("receivingUintName", model.getParam().getReceivingUintName());
        }
        if (model.getParam().getShipNo() != null) {
            obj.put("shipNo", model.getParam().getShipNo());
        }
        if (model.getParam().getScaleName() != null) {
            obj.put("scaleName", model.getParam().getScaleName());
        }
        if (model.getParam().getBaseSpotNo() != null) {
            obj.put("baseSpotNo", model.getParam().getBaseSpotNo());
        }
        if (model.getParam().getValueFlag() != null) {
            obj.put("valueFlag", model.getParam().getValueFlag());
        }
        if (model.getParam().getMemo() != null) {
            obj.put("memo", model.getParam().getMemo());
        }
        if (model.getParam().getUnloadSite() != null) {
            obj.put("unloadSite", model.getParam().getUnloadSite());
        }
        if (model.getParam().getStartTime() != null) {
            obj.put("startTime", model.getParam().getStartTime());
        }
        if (model.getParam().getEndTime() != null) {
            obj.put("endTime", model.getParam().getEndTime());
        }
        if (model.getParam().getCheckTime() != null) {
            obj.put("checkTime", model.getParam().getCheckTime());
        }
        if (model.getParam().getCheckFlag() != null) {
            obj.put("checkFlag", model.getParam().getCheckFlag());
        }
        if (model.getParam().getOrderNo() != null) {
            obj.put("orderNo", model.getParam().getOrderNo());
        }
        return meterWorkBeltScaleActualMapper.doQueryAndMultiple(obj);
    }

    @Override
    public List<MeterWorkBeltScaleActual> doQueryActualInfoAndGroup(CommonPage<MeterWorkBeltScaleActual> model) {
        HashMap<String, Object> obj = new HashMap<>();
        obj.put("startTime1", model.getStartTime());
        obj.put("endTime1", model.getEndTime());
        if (model.getParam().getProductName() != null) {
            obj.put("productName", model.getParam().getProductName());
        }
        if (model.getParam().getForwardingUnitName() != null) {
            obj.put("forwardingUnitName", model.getParam().getForwardingUnitName());
        }
        if (model.getParam().getNewMatName() != null) {
            obj.put("newMatName", model.getParam().getNewMatName());
        }
        if (model.getParam().getNewSupplier() != null) {
            obj.put("newSupplier", model.getParam().getNewSupplier());
        }
        if (model.getParam().getReceivingUintName() != null) {
            obj.put("receivingUintName", model.getParam().getReceivingUintName());
        }
        if (model.getParam().getShipNo() != null) {
            obj.put("shipNo", model.getParam().getShipNo());
        }
        if (model.getParam().getBaseSpotName() != null) {
            obj.put("baseSpotName", model.getParam().getBaseSpotName());
        }
        if (model.getParam().getValueFlag() != null) {
            obj.put("valueFlag", model.getParam().getValueFlag());
        }
        if (model.getParam().getUnloadSite() != null) {
            obj.put("unloadSite", model.getParam().getUnloadSite());
        }
        if (model.getParam().getCheckFlag() != null) {
            obj.put("checkFlag", model.getParam().getCheckFlag());
        }
        if (model.getParam().getOrderNo() != null) {
            obj.put("orderNo", model.getParam().getOrderNo());
        }
       /* if (model.getParam().getStartTime() != null) {
            obj.put("startTime", model.getParam().getStartTime());
        }
        if (model.getParam().getEndTime() != null) {
            obj.put("endTime", model.getParam().getEndTime());
        }
        if (model.getParam().getCheckTime() != null) {
            obj.put("checkTime", model.getParam().getCheckTime());
        }*/
        return meterWorkBeltScaleActualMapper.doQueryActualInfoAndGroup(obj);
    }

    @Override
    public int doUpdateFlags_0(List<MeterWorkBeltScaleActual> list) {
        if (list == null) {
            throw new MarkerMetException(500, "参数不允许为空!!");
        }
        return meterWorkBeltScaleActualMapper.doUpdateFlags_0(list);
    }

    @Override
    public int doUpdateFlags_1(List<MeterWorkBeltScaleActual> list) {
        if (list == null) {
            throw new MarkerMetException(500, "参数不允许为空!!");
        }
        return meterWorkBeltScaleActualMapper.doUpdateFlags_1(list);
    }

    @Override
    public int doUpdateCheckFlags_0(List<MeterWorkBeltScaleActual> list) {
        if (list == null) {
            throw new MarkerMetException(500, "参数不允许为空!!");
        }
        return meterWorkBeltScaleActualMapper.doUpdateCheckFlags_0(list);
    }

    @Override
    public int doUpdateCheckFlags_1(List<MeterWorkBeltScaleActual> list) {
        if (list == null) {
            throw new MarkerMetException(500, "参数不允许为空!!");
        }
        return meterWorkBeltScaleActualMapper.doUpdateCheckFlags_1(list);
    }


}
