package com.steerinfo.baseinfo.meterbasebeltmaterialpm.service.impl;

import com.steerinfo.baseinfo.combaseinfo.mapper.ComBaseInfoMapper;
import com.steerinfo.baseinfo.meterbasebeltmaterialpm.mapper.MeterBaseBeltMaterialPmMapper;
import com.steerinfo.baseinfo.meterbasebeltmaterialpm.model.MeterBaseBeltMaterialPm;
import com.steerinfo.baseinfo.meterbasebeltmaterialpm.service.IMeterBaseBeltMaterialPmService;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.pretrack.prebeltscale.model.PreBeltScale;
import com.steerinfo.util.CommonPage;
import org.springframework.stereotype.Service;

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

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

    @Resource
    private MeterBaseBeltMaterialPmMapper meterBaseBeltMaterialPmMapper;

    @Resource
    private ComBaseInfoMapper comBaseInfoMapper;

    @Override
    protected IBaseMapper<MeterBaseBeltMaterialPm, String> getMapper() {
        return meterBaseBeltMaterialPmMapper;
    }

    @Override
    public int doAddMaterialPm(MeterBaseBeltMaterialPm model) {
        try{
            String maxID = comBaseInfoMapper.getConfigID("METER_BASE_BELT_MATERIAL_PM","MATERIAL_PM_CODE");
            model.setMaterialPmCode(maxID);
            return  meterBaseBeltMaterialPmMapper.insertSelective(model);
        }catch (Exception ex){
            throw ex;
        }
    }

    @Override
    public int updateMaterialPm(MeterBaseBeltMaterialPm model) {
        try{
            return  meterBaseBeltMaterialPmMapper.updateByPrimaryKeySelective(model);
        }catch (Exception ex){
            throw ex;
        }
    }

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

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

    @Override
    public List<MeterBaseBeltMaterialPm> doQueryByBeltType(CommonPage<PreBeltScale> model ) {
        HashMap<String, Object> obj = new HashMap<>();
        obj.put("scaleName", model.getMemo1());//A或者B
        if (model.getParam() != null) {
            obj.put("baseSpotNo", model.getParam().getBaseSpotNo());
            obj.put("valueFlag", model.getParam().getValueFlag());
            obj.put("matterNo", model.getParam().getProductNo());//物料名称
        }

        return meterBaseBeltMaterialPmMapper.doQueryByBeltType(obj);
    }
}
