package com.ssm.manage.service.impl;

import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.core.utils.SnowflakeUtil;
import com.ssm.manage.dao.SsmCashDownloadRecordDao;
import com.ssm.manage.entity.CashDownloadRecord;
import com.ssm.manage.service.SsmCashDownloadRecordService;
import lombok.extern.slf4j.Slf4j;
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.Random;

@Service
@Slf4j
public class SsmCashDownloadRecordServiceImpl extends BaseServiceImpl<CashDownloadRecord> implements SsmCashDownloadRecordService {
    @Autowired
    private SsmCashDownloadRecordDao dao;

    @Override
    public SsmCashDownloadRecordDao getDao() {
        return dao;
    }

    @Transactional(rollbackFor=Exception.class)
    @Override
    public int addRecord(CashDownloadRecord cashDownloadRecord) {
        cashDownloadRecord.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
        cashDownloadRecord.setDownloadTime(new Date());
        return dao.saveNotNull(cashDownloadRecord);
    }
}
