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

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.baseinfo.meterbasehistaredata.model.MeterBaseHisTareData;
import com.steerinfo.baseinfo.meterbasehistaredata.mapper.MeterBaseHisTareDataMapper;
import com.steerinfo.baseinfo.meterbasehistaredata.service.IMeterBaseHisTareDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.HashMap;
import java.util.List;

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

    @Autowired
    private MeterBaseHisTareDataMapper meterBaseHisTareDataMapper;

    @Override
    protected IBaseMapper<MeterBaseHisTareData, String> getMapper() {
        return meterBaseHisTareDataMapper;
    }

    @Override
    public String Recovery(MeterBaseHisTareData model)
    {
        try {
            HashMap<String, Object> obj = new HashMap<>();
            obj.put("valueFlag","0");
            obj.put("carNo",model.getCarNo());
            obj.put("dataNo",model.getDataNo());
            List<MeterBaseHisTareData> list=meterBaseHisTareDataMapper.selectByParameters(obj);
            if ( ! list.isEmpty()){
                return "该车号已存在有效数据，无法启用！";
            }
            model.setId(model.getId());
            model.setValueFlag("0");
            meterBaseHisTareDataMapper.updateByPrimaryKey(model);
        } catch (Exception ex) {
            ex.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return "操作异常，请联系管理员";
        }
        return "";
    }

    @Override
    public String abolish(MeterBaseHisTareData model)
    {
        try {
            model.setId(model.getId());
            model.setValueFlag("1");
            meterBaseHisTareDataMapper.updateByPrimaryKey(model);
        } catch (Exception ex) {
            ex.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return "操作异常，请联系管理员";
        }
        return "";
    }
}
