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

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.meterwork.meterworkcomparespot.model.MeterWorkCompareSpot;
import com.steerinfo.meterwork.meterworkcomparespot.mapper.MeterWorkCompareSpotMapper;
import com.steerinfo.meterwork.meterworkcomparespot.service.IMeterWorkCompareSpotService;
import com.steerinfo.meterwork.meterworkcomparespotscale.mapper.MeterWorkCompareSpotScaleMapper;
import com.steerinfo.meterwork.meterworkcomparespotscale.model.MeterWorkCompareSpotScale;
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.HashMap;
import java.util.List;
import java.util.Map;

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

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

    @Override
    protected IBaseMapper<MeterWorkCompareSpot, String> getMapper() {
        return meterWorkCompareSpotMapper;
    }

    @Override
    public String isExistWithinOneHour(String carNo) {
        return meterWorkCompareSpotMapper.isExistWithinHour(1,carNo,"1");
    }

    public int updateByPrimaryKey(MeterWorkCompareSpot spot){
       return meterWorkCompareSpotMapper.updateByPrimaryKey(spot);
    }

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

    @Override
    public void insert(MeterWorkCompareSpot spot) {
        meterWorkCompareSpotMapper.insertSelective(spot);
    }

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

    @Override
    public List<MeterWorkCompareSpot> queryAll() {
        return meterWorkCompareSpotMapper.queryAll();
    }

    @Override
    public List<MeterWorkCompareSpot> queryByCompareType(String type) {

        return meterWorkCompareSpotMapper.queryByCompareType(type);
    }

    @Override
    public PageList<MeterWorkCompareSpot> queryDESCForPage(HashMap parmas, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<MeterWorkCompareSpot> rows = this.meterWorkCompareSpotMapper.selectByParametersDESC(parmas);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }

}
