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

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.meterwork.meterworkcomparespot.mapper.MeterWorkCompareSpotMapper;
import com.steerinfo.meterwork.meterworkcomparespot.model.MeterWorkCompareSpot;
import com.steerinfo.meterwork.meterworkcomparespotscale.model.MeterWorkCompareSpotScale;
import com.steerinfo.meterwork.meterworkcomparespotscale.mapper.MeterWorkCompareSpotScaleMapper;
import com.steerinfo.meterwork.meterworkcomparespotscale.service.IMeterWorkCompareSpotScaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

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

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

    @Autowired
    private MeterWorkCompareSpotScaleMapper meterWorkCompareSpotScaleMapper;
    @Autowired
    private MeterWorkCompareSpotMapper meterWorkCompareSpotMapper;

    @Override
    protected IBaseMapper<MeterWorkCompareSpotScale, String> getMapper() {
        return meterWorkCompareSpotScaleMapper;
    }

    @Override
    public String creatCompareSpotScaleId() {
        String id =   new SimpleDateFormat("yyyyMMdd").format(new Date()) + meterWorkCompareSpotScaleMapper.GetNewID();
        //System.out.println(id);
        return id;
    }

    @Override
    public String isExistWithinOneDay(String carNo) {
        return meterWorkCompareSpotScaleMapper.isExistWithinHour(24,carNo);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    public void creatSpotAndScale(MeterWorkCompareSpot spot, MeterWorkCompareSpotScale scale) {
        meterWorkCompareSpotScaleMapper.insertSelective(scale);
        meterWorkCompareSpotMapper.insertSelective(spot);
    }

    @Override
    public List<MeterWorkCompareSpotScale> getAllScaleNo() {
       return meterWorkCompareSpotScaleMapper.getAllScaleNo();
    }

    @Override
    public void updateByPrimaryKey(MeterWorkCompareSpotScale scale) {
        meterWorkCompareSpotScaleMapper.updateByPrimaryKeySelective(scale);
    }


}
