Kaynağa Gözat

git-svn-id: https://192.168.57.71/svn/jsgkj@1313 931142cf-59ea-a443-aa0e-51397b428577

ld_lixh 8 yıl önce
ebeveyn
işleme
a7009302f5

+ 91 - 0
gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/web/ctl/FileUtilCtl.java

@@ -0,0 +1,91 @@
+package com.xt.js.gkaq.web.ctl;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.BeanUtils;
+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.ResponseBody;
+
+import com.xt.js.gkaq.common.BaseCtl;
+import com.xt.js.gkaq.common.util.FileUtil;
+import com.xt.js.gkaq.frame.service.CodeService;
+import com.xt.js.gkaq.web.model.BloBModel;
+import com.xt.js.gkaq.web.model.BwInfoModel;
+import com.xt.js.gkaq.web.model.BwModel;
+import com.xt.js.gkaq.web.model.FjbModel;
+import com.xt.js.gkaq.web.service.BloBService;
+import com.xt.js.gkaq.web.service.BwService;
+import com.xt.js.gkaq.web.service.FjbService;
+import com.xt.js.gkaq.web.vo.BloBVo;
+import com.xt.js.gkaq.web.vo.BwVo;
+import com.yuanxd.tools.pagehelper.PageHelper;
+import com.yuanxd.tools.pagehelper.PageInfo;
+import com.yuanxd.tools.utils.WebJsonResult;
+
+@Controller
+@RequestMapping(value = "/fileUtil", produces = "application/json; charset=utf-8")
+public class FileUtilCtl extends BaseCtl {
+    @Autowired
+    private BloBService bloBService;
+    @Autowired
+    private FjbService fjbService;
+    
+    /**
+     * 文件上传
+     * @param vo
+     * @return
+     * @throws IOException 
+     * @throws IllegalStateException 
+     */
+    @RequestMapping("saveFile")
+    @ResponseBody
+    public WebJsonResult saveFile ( HttpServletRequest request,BloBVo vo){
+		try {
+			//文件上传,获得保存到服务器的自定义文件名
+			String filename = FileUtil.fileUp(request);
+			WebJsonResult jsonResult = new WebJsonResult();
+	    	jsonResult.setAttr("filename",filename);
+	    	jsonResult.setSuccess(true);
+	    	return jsonResult;
+		} catch (IllegalStateException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+     	return null;
+    	
+    }
+    /**
+     * 文件下载
+     * @param id
+     * @return
+     */
+    @RequestMapping("fileDow")
+    @ResponseBody
+    public void fileDow (HttpServletRequest request,HttpServletResponse response,String id,String fjid) {
+    	BloBModel model = bloBService.findById(id);//文件的二进制内容
+    	FjbModel fjbmodel = fjbService.findById(fjid);//文件的附件信息
+    	String wjm = fjbmodel.getWjm();//文件名称
+    	byte[] value = model.getValue();//二进制文件
+    	FileUtil.fileDownLoad(request,response,value,wjm);//文件下载
+    }
+    /**
+     * 删除附件在服务器上的数据
+     * @param request
+     * @param filename
+     * @return
+     */
+    @RequestMapping("delFile")
+    @ResponseBody
+    public WebJsonResult delFile (HttpServletRequest request,String filename) {
+    	String path = request.getSession().getServletContext().getRealPath("/uplod");//程序路径
+    	FileUtil.filedelete(path+"/"+filename);
+    	return success();
+    }
+}