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.BarPackageDao;
import com.uas.platform.b2b.model.BarPackage;
import com.uas.platform.b2b.service.BarPackageService;
import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.Status;

@Service
public class BarPackageServiceImpl implements BarPackageService {

	@Autowired
	private BarPackageDao barPackageDao;

	@Override
	public List<BarPackage> findNotUpload() {
		List<BarPackage> list = barPackageDao.findBySendStatusAndCustUU((short) Status.NOT_UPLOAD.value(),
				SystemSession.getUser().getEnterprise().getUu());
		return list;
	}

	@Override
	public void onUploadSuccess(String[] idArray) {
		for (String id : idArray) {
			if(id != "") {
				BarPackage packages = barPackageDao.findOne(Long.parseLong(id));
				if (packages != null) {
					packages.setSendStatus((short) Status.DOWNLOADED.value());
					barPackageDao.save(packages);
				}
			}
		}
	}
}
