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

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.baseinfo.meterbasediffrelation.model.MeterBaseDiffRelation;
import com.steerinfo.baseinfo.meterbasediffrelation.mapper.MeterBaseDiffRelationMapper;
import com.steerinfo.baseinfo.meterbasediffrelation.service.IMeterBaseDiffRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

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

    @Autowired
    private MeterBaseDiffRelationMapper meterBaseDiffRelationMapper;

    @Override
    protected IBaseMapper<MeterBaseDiffRelation, String> getMapper() {
        return meterBaseDiffRelationMapper;
    }

    @Override
    public String checkandadd(List<MeterBaseDiffRelation> models){
     try {
         if (models == null || models.size() < 1) {
             return "请传入参数!";
         }
         for (MeterBaseDiffRelation model:models) {
             String no = meterBaseDiffRelationMapper.GetNewID();
             model.setDiffRelationNo(new SimpleDateFormat("yyyyMMdd").format(new Date()) + no);
             model.setCreateTime(new Date());
             meterBaseDiffRelationMapper.insert(model);
         }
     } catch (Exception ex) {
        ex.printStackTrace();
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return "操作异常，请联系管理员";
    }
        return "";
    }
}
