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
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"));
//			switch (doc.getString("name")) {
//				case "key":eUrl.setGo("http://192.168.0.245:8080/change4weixin/finance/upExcel");;
//				case "longSource":eUrl.setGo("http://192.168.0.245:8080/change4weixin/finance/upExcel");
//				case "lessSource":eUrl.setGo("http://192.168.0.245:8080/change4weixin/finance/upExcel");
//			}
			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);
	}
}
