package com.palmnest.service.dinner.manager.impl;

import com.palmnest.application.core.util.DateHelper;
import com.palmnest.application.dto.RechargeRecordDto;
import com.palmnest.dao.dinner.RechargeRecordDao;
import com.palmnest.model.dinner.RechargeRecord;
import com.palmnest.service.dinner.manager.RechargeRecordManager;
import com.palmnest.service.impl.GenericManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service("rechargeRecordManager")
public class RechargeRecordManagerImpl extends GenericManagerImpl<RechargeRecord, Long> implements RechargeRecordManager {


	private RechargeRecordDao rechargeRecordDao;

	@Autowired
	public void setRechargeRecordDao(RechargeRecordDao rechargeRecordDao) {
		this.rechargeRecordDao = rechargeRecordDao;
		this.dao = rechargeRecordDao;
	}

	@Override
	public List<RechargeRecordDto> findByOrgId(String orgId) {
		List<RechargeRecord>    list    = rechargeRecordDao.findByOrgId(orgId);
		List<RechargeRecordDto> dtoList = new ArrayList<RechargeRecordDto>();
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				RechargeRecord rr = list.get(i);
				if (rr != null) {
					String createTime = "";
					if (rr.getCreateTime() != null) {
						createTime = DateHelper.formatDate(rr.getCreateTime(), DateHelper.DATE_TIME_STRING);
					}
					RechargeRecordDto dto = new RechargeRecordDto(createTime, rr.getSumCount());
					dtoList.add(dto);
				}
			}
		}
		return dtoList;
	}
}
