package com.ssm.manage.service.impl;

import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.core.utils.SnowflakeUtil;
import com.ssm.manage.dao.SsmCashAccountDao;
import com.ssm.manage.entity.CashAccountList;
import com.ssm.manage.entity.CashList;
import com.ssm.manage.entity.ServiceOrders;
import com.ssm.manage.query.RechargeAccountRequest;
import com.ssm.manage.service.SsmCashAccountSrevice;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Random;

@Service
public class SsmCashAccountServiceImpl extends BaseServiceImpl<CashAccountList> implements SsmCashAccountSrevice {
    @Autowired
    private SsmCashAccountDao dao;

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

    @Override
    @Transactional(rollbackFor=Exception.class)
    public int add(CashAccountList cashAccountList, CashList cashList) {
        int i = 0;

            cashAccountList.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());


            cashAccountList.setCashId(cashList.getId());
            cashAccountList.setCashNum(cashList.getCashNum());
            cashAccountList.setInputDate(cashList.getCashDate());
            i = dao.saveNotNull(cashAccountList);

        return i;
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public int add(CashAccountList cashAccountList, ServiceOrders serviceOrders) {
        int i = 0;

            cashAccountList.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());


            cashAccountList.setCashId(serviceOrders.getId());
            cashAccountList.setCashNum(serviceOrders.getSettlementNum());
            cashAccountList.setInputDate(serviceOrders.getDocDate());
            i = dao.saveNotNull(cashAccountList);

        return i;
    }
}
