package org.fouram.core.base.controller;

import java.io.FileNotFoundException;

import javax.servlet.http.HttpServletResponse;

import org.fouram.core.base.model.PageData;
import org.fouram.core.util.ConfConfig;
import org.fouram.core.util.FileDownload;
import org.fouram.core.util.Tools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 图片下载
 */
@Controller
@RequestMapping({ "/download" })
public class DownloadController extends BaseController {

	/**
	 * 下载图片
	 */
	@RequestMapping({ "/file" })
	public void file(HttpServletResponse response) throws Exception {
		PageData pd = new PageData();
		pd = getPageData();
		String imgpath = pd.getString("path");
		if (Tools.isEmpty(imgpath)) {
			return;
		}
		String fileName = imgpath.substring(imgpath.lastIndexOf("/"), imgpath.length());
		try {
			FileDownload.fileDownload(response, ConfConfig.getConfigString("fileUpload.baseFolder") + imgpath,
					fileName);
		} catch (FileNotFoundException e) {
			System.out.println(imgpath + "文件不存在！");
		}
	}
}
