首页>代码>spring+spring mvc+hibernate开发工程财务管理辅助系统>/FMS/src/com/mvc/controller/content/FileController.java
package com.mvc.controller.content;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.mvc.controller.base.BaseController;
import com.mvc.framework.constant.GlobalConstant;
import com.mvc.pageModel.base.Grid;
import com.mvc.pageModel.base.Json;
import com.mvc.pageModel.base.PageFilter;
import com.mvc.pageModel.base.SessionInfo;
import com.mvc.service.content.FileServiceI;
import com.mvc.utils.CacheUtils;
import com.mvc.utils.ExportUtils;

@Controller
@RequestMapping("/files")
public class FileController extends BaseController{
	@Autowired
	private FileServiceI fileServiceI;
	
	@RequestMapping("/index")
	public String index() {
		return "/content/file";
	}
	
	@RequestMapping("/dataGrid")
	@ResponseBody
	public Grid dataGrid(String file_name,String remark,HttpSession session,PageFilter ph) {
		Grid grid = new Grid();
		try
		{
			SessionInfo sessionInfo = (SessionInfo) session.getAttribute(GlobalConstant.SESSION_INFO);
			Map<String,Object> result=fileServiceI.dataGrid(file_name,remark,sessionInfo.getOrgId(),ph);
			List<Map<String,Object>> viewList=(List<Map<String, Object>>) result.get("rows");
			grid.setRows(viewList);
			grid.setTotal(Long.parseLong(result.get("total").toString()));
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return grid;
	}
	@RequestMapping("/add")
	@ResponseBody
	public Json add(@RequestParam MultipartFile upFile,String remark,HttpSession session) {
		Json json=new Json();
		try
		{
			SessionInfo sessionInfo = (SessionInfo) session.getAttribute(GlobalConstant.SESSION_INFO);
			fileServiceI.add(upFile,remark,sessionInfo.getId(),sessionInfo.getOrgId());
			json.setSuccess(true);
			json.setMsg("发布成功!");
		}
		catch(Exception e)
		{
			e.printStackTrace();
			json.setSuccess(false);
			json.setMsg("发布失败!");
		}
		return json;
	}
	
	@RequestMapping("/deleteFile")
	@ResponseBody
	public Json deleteFile(String id,HttpSession session) {
		Json json=new Json();
		try
		{
			fileServiceI.delete(id);
			json.setSuccess(true);
			json.setMsg("删除成功!");
		}
		catch(Exception e)
		{
			e.printStackTrace();
			json.setSuccess(false);
			json.setMsg("删除失败!");
		}
		return json;
	}
	
	@RequestMapping(value = "/queryFile")
	@ResponseBody
	public Json queryFile(int id,HttpSession session,HttpServletRequest request) {
		Json j = new Json();
		try {
			SessionInfo sessionInfo = (SessionInfo) session.getAttribute(GlobalConstant.SESSION_INFO);
			Map<String,Object> map=fileServiceI.getFilePathById(id);
			//System.out.println("######下载路径:"+filePath);
			j.setSuccess(true);
			j.setMsg("查询成功!");
			CacheUtils.cacheMe("file_"+sessionInfo.getId(), map.get("file_path"));
			CacheUtils.cacheMe("name_"+sessionInfo.getId(), map.get("file_name"));
		} catch (Exception e) {
			e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}
	
	@RequestMapping(value = "/exportFile") 
	@ResponseBody
	public void exportFile(HttpSession session,HttpServletResponse response) {
		SessionInfo sessionInfo = (SessionInfo) session.getAttribute(GlobalConstant.SESSION_INFO);
		String filePath=(String) CacheUtils.getCache("file_"+sessionInfo.getId());
		String fileName=(String) CacheUtils.getCache("name_"+sessionInfo.getId());
		ExportUtils.download_fb(filePath, fileName, response);
	}
}
最近下载更多
qiaoxiansheng  LV6 2023年8月8日
zhaoyangwfd  LV17 2022年11月29日
1083912911  LV4 2022年4月18日
getset  LV8 2022年3月25日
dchengl7300  LV3 2021年12月15日
wanglinddad  LV54 2021年9月23日
1029162867  LV13 2021年6月7日
窗边的小豆豆  LV1 2021年5月7日
lizhoutao  LV11 2020年12月11日
caochengbo  LV6 2020年11月1日
最近浏览更多
educationAAA  LV4 4月18日
荣》Cowboy  LV12 4月11日
fff2003  LV6 2023年12月23日
WBelong  LV7 2023年12月11日
fesfefe  LV13 2023年10月20日
qiaoxiansheng  LV6 2023年8月8日
dzlwindy  LV8 2023年6月29日
1083912911  LV4 2023年6月28日
chenhs 2023年6月20日
暂无贡献等级
6389181  LV7 2023年6月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友