package cn.com.countrygarden.bi.main.service.dataMigration.impl;

import cn.com.countrygarden.bi.main.dao.dataMigration.DispatchRecordMapper;
import cn.com.countrygarden.bi.main.model.dataMigration.DispatchRecord;
import cn.com.countrygarden.bi.main.service.dataMigration.DispatchRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by ADMS on 2018/9/18.
 */
@Service
public class DispatchRecordServiceImpl implements DispatchRecordService{
    @Autowired
    private DispatchRecordMapper dispatchRecordMapper;

    @Override
    @Transactional
    public Long insert(DispatchRecord dispatchRecord) {
        dispatchRecordMapper.insert(dispatchRecord);
        return dispatchRecord.getDispatchRecordId();
    }

    @Override
    @Transactional
    public int update(Long id, Date endDate, Long endSignId) {
        int count = dispatchRecordMapper.update(id, endDate, endSignId);
        return count;
    }

    @Override
    public List<DispatchRecord> select(Date startDate, Date endDate) {
        List<DispatchRecord> dispatchRecords = dispatchRecordMapper.select(startDate, endDate);
        return dispatchRecords;
    }

    @Override
    public Integer selectMaxBatchCode(String interfaceCode) {
        Integer batchCode = dispatchRecordMapper.findMaxBatchCode(interfaceCode);
        if (batchCode == null) {
            batchCode = 0;
        }
        return batchCode;
    }
}
