package com.steerinfo.pretrack.prebeltscale.service.impl;

import com.steerinfo.baseinfo.combaseinfo.mapper.ComBaseInfoMapper;
import com.steerinfo.baseinfo.meterbasecustomersupplier.mapper.MeterBaseCustomerSupplierMapper;
import com.steerinfo.baseinfo.meterbasecustomersupplier.model.MeterBaseCustomerSupplier;
import com.steerinfo.baseinfo.meterbasecustomersupplier.service.IMeterBaseCustomerSupplierService;
import com.steerinfo.baseinfo.meterbasematterinfo.mapper.MeterBaseMatterInfoMapper;
import com.steerinfo.baseinfo.meterbasematterinfo.model.MeterBaseMatterInfo;
import com.steerinfo.baseinfo.meterbasematterinfo.service.IMeterBaseMatterInfoService;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.pretrack.prebeltscale.mapper.PreBeltScaleMapper;
import com.steerinfo.pretrack.prebeltscale.model.PreBeltScale;
import com.steerinfo.pretrack.prebeltscale.service.IPreBeltScaleService;
import com.steerinfo.pretrack.pretrackscale.model.PreTrackScale;
import com.steerinfo.util.CommonPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

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

    @Resource
    private PreBeltScaleMapper preBeltScaleMapper;

    @Resource
    private ComBaseInfoMapper comBaseInfoMapper;
    //物料服务
    @Resource
    MeterBaseMatterInfoMapper meterBaseMatterInfoMapper;

    @Resource
    MeterBaseCustomerSupplierMapper supplierMapper;

    @Override
    protected IBaseMapper<PreBeltScale, String> getMapper() {
        return preBeltScaleMapper;
    }

    //预报新增
    @Override
    public int doAddBeltScalePrediction(PreBeltScale model) {
        try{
            String maxID = comBaseInfoMapper.getConfigID("PRE_BELT_SCALE","PREDICTION_NO");
            model.setPredictionNo(maxID);
            model.setCreateTime(new Date());
            return  preBeltScaleMapper.insertSelective(model);
        }catch (Exception ex){
            throw ex;
        }
    }

    @Override
    public int updateScalePrediction(PreBeltScale model) {
        try{
            model.setUpdateTime(new Date());
            return  preBeltScaleMapper.updateByPrimaryKeySelective(model);
        }catch (Exception ex){
            throw ex;
        }
    }

    @Override
    public List<PreBeltScale> doQueryLikeInfo(CommonPage<PreBeltScale> model) {
        HashMap<String, Object> obj = new HashMap<>();
        obj.put("startTime", model.getStartTime());
        obj.put("endTime", model.getEndTime());
        if (model.getParam().getProductName() != null) {
            obj.put("productName", model.getParam().getProductName());
        }
        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().getForwardingUnitName() != null) {
            obj.put("forwardingUnitName", model.getParam().getForwardingUnitName());
        }
        if (model.getParam().getReceivingUintName() != null) {
            obj.put("receivingUintName", model.getParam().getReceivingUintName());
        }
        if (model.getParam().getBaseSpotName() != null) {
            obj.put("baseSpotName", model.getParam().getBaseSpotName());
        }
        if (model.getParam().getBaseSpotNo() != null) {
            obj.put("baseSpotNo", model.getParam().getBaseSpotNo());
        }
        if (model.getParam().getShipNo() != null) {
            obj.put("shipNo", model.getParam().getShipNo());
        }
        if (model.getParam().getValueFlag() != null) {
            obj.put("valueFlag", model.getParam().getValueFlag());
        }
        if (model.getParam().getPredictionNo() != null) {
            obj.put("predictionNo", model.getParam().getPredictionNo());
        }
        return preBeltScaleMapper.doQueryLikeInfo(obj);
    }

    @Override
    public List<PreBeltScale> doQuerylike(CommonPage<PreBeltScale> model) {
        HashMap<String, Object> obj = new HashMap<>();
        obj.put("startTime", model.getStartTime());
        obj.put("endTime", model.getEndTime());
        if (model.getParam().getProductName() != null) {
            obj.put("productName", model.getParam().getProductName());
        }
        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().getForwardingUnitName() != null) {
            obj.put("forwardingUnitName", model.getParam().getForwardingUnitName());
        }
        if (model.getParam().getReceivingUintName() != null) {
            obj.put("receivingUintName", model.getParam().getReceivingUintName());
        }
        if (model.getParam().getBaseSpotName() != null) {
            obj.put("baseSpotName", model.getParam().getBaseSpotName());
        }
        if (model.getParam().getShipNo() != null) {
            obj.put("shipNo", model.getParam().getShipNo());
        }
        if (model.getParam().getValueFlag() != null) {
            obj.put("valueFlag", model.getParam().getValueFlag());
        }
        return preBeltScaleMapper.doQuerylike(obj);
    }

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

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

}
