package com.ssm.manage.service.impl;

import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.manage.dao.SsmPayDao;
import com.ssm.manage.entity.PayList;
import com.ssm.manage.entity.SmsException;
import com.ssm.manage.mapper.PayListMapper;
import com.ssm.manage.query.StoreDailyRequest;
import com.ssm.manage.response.PayListVo;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.response.StoreDailyResponse;
import com.ssm.manage.service.SsmPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class SsmPayServiceImpl extends BaseServiceImpl<PayList> implements SsmPayService {
    @Autowired
    private SsmPayDao dao;

    @Autowired
    PayListMapper mapper;

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

    @Override
    @Transactional(rollbackFor=Exception.class)
    public int addPayList(List<PayList> payList) throws SmsException {
        int i = 0;
        for (PayList list : payList) {
            if(list.getPayDate()==null) {
                list.setPayDate(new Date());
            }
        }
        try {
            i = dao.addPayList(payList);
        }catch (Exception e){
            log.error("SsmPayServiceImpl.addPayList:",e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new SmsException(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
        }
        return 0;
    }

    @Override
    public List<PayListVo> selectByDay(String tab,List<Long> storeIds, Date startTime, Date endTime) {
        return dao.selectByDay(tab,storeIds,startTime,endTime);
    }

    @Override
    public void updateByNum(PayList list) {
        dao.updateByNum(list);
    }

    @Override
    public BigDecimal selectStoreDailys(StoreDailyRequest storeDailyRequest) {
        return dao.selectStoreDailys(storeDailyRequest);
    }

    @Override
    public List<PayList> selectList(List<String> courseNums) {
        return mapper.selectList(courseNums);
    }

    @Override
    public void updateIsCancelById(PayList list) {
        mapper.updateIsCancelById(list);
    }


}
