package com.uas.platform.b2b.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.uas.platform.b2b.dao.BarSendNotifyDao;
import com.uas.platform.b2b.model.BarSendNotify;
import com.uas.platform.b2b.service.BarSendNotifyService;
import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.Status;

@Service
public class BarSendNotifyServiceImpl implements BarSendNotifyService{
	@Autowired
	private BarSendNotifyDao barSendNotifyDao;

	@Override
	public List<BarSendNotify> findNotUpload() {
		return barSendNotifyDao.findByCustUUAndSendStatus(SystemSession.getUser().getEnterprise().getUu(),(short) Status.NOT_UPLOAD.value());
	}

	@Override
	public void onUploadSuccess(String[] idArray) {
		for(String id : idArray) {
			 List<BarSendNotify> bsns= barSendNotifyDao.findBySsid(Long.parseLong(id));
			if(bsns.size()>0) {
				for(BarSendNotify bsnotify : bsns ) {
					bsnotify.setSendStatus((short) Status.DOWNLOADED.value());
					barSendNotifyDao.save(bsnotify);
				}
			}
		}
	}

}
