package com.zhiwei.service;

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

import org.bson.Document;
import org.springframework.stereotype.Service;

import com.zhiwei.util.MongoConnection;
import com.zw.entity.ExcelsUrl;

/**
 * 文件更新service
 * 
 * @author admin
 *
 */
@Service
public class Services {

	private static MongoConnection con = new MongoConnection();

	public List<ExcelsUrl> findAll() {
		List<Document> list = con.find("financePush", "excelPath");
		List<ExcelsUrl> result = new ArrayList<>();
		for (Document doc : list) {
			ExcelsUrl eUrl = new ExcelsUrl();
			eUrl.setType(doc.getString("type"));
			eUrl.setName(doc.getString("name"));
			eUrl.setUrl(doc.getString("url"));
			result.add(eUrl);
		}
		return result;
	}

	public void insert(ExcelsUrl eUrl) {
		Document doc = new Document();
		System.out.println(eUrl);
		doc.append("name", eUrl.getName());
		doc.append("url", eUrl.getUrl());
		doc.append("type", eUrl.getType());
		con.insertDb("financePush", "excelPath", doc);
	}

	public String getPath(String name) {
		return con.findOne("financePush", "excelPath", name);
	}
}
