Browse Source

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

ld_lixh 8 years ago
parent
commit
7d7356edcf

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

@@ -0,0 +1,72 @@
+package com.xt.js.gkaq.web.ctl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletRequest;
+
+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.web.model.BloBModel;
+import com.xt.js.gkaq.web.service.BloBService;
+import com.xt.js.gkaq.web.vo.BloBVo;
+import com.yuanxd.tools.utils.WebJsonResult;
+
+@Controller
+@RequestMapping(value = "/blob", produces = "application/json; charset=utf-8")
+public class BlobCtl extends BaseCtl {
+    @Autowired
+    private BloBService bloBService;
+    /**
+     * 保存人员证书
+     * @param request
+     * @param fileName
+     * @return
+     * @throws IOException
+     */
+    @RequestMapping("saveBlob")
+    @ResponseBody
+    public WebJsonResult saveBlob (HttpServletRequest request, String fileName,BloBVo vo){
+    	String webpath = request.getSession().getServletContext().getRealPath("/uplod");//程序路径
+    	BloBModel model = new BloBModel();
+    	//保存的文件名是否为空
+    	if (fileName != null && !"".equals(fileName)) {
+	    	String filepath = webpath + "/" + fileName;
+	    	File file = new File(filepath);
+			try {
+				InputStream inputStream = new FileInputStream(file);
+				byte[] data = FileUtil.inputStreamToByte(inputStream);
+		    	//判断是修改还是添加
+		    	if (vo.getId() != null && !"".equals(vo.getId())) {
+		    		model = bloBService.findById(vo.getId());
+		        	model.setValue(data);
+		        	model.setSzd(vo.getSzd());
+		        	bloBService.update(model);
+		    	} else {
+		    		model.setValue(data);
+		        	model.setSzd(vo.getSzd());
+		        	bloBService.add(model);
+		    	}
+		    	//释放读取的文件流的自由
+		    	inputStream.close();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+	    	//删除文件
+	    	FileUtil.filedelete(webpath + "/"+fileName);
+    	}
+    	//设置参数返回值
+    	WebJsonResult jsonResult = new WebJsonResult();
+    	jsonResult.setAttr("zsnr",model.getId());
+    	jsonResult.setSuccess(true);
+    	return jsonResult;
+    }
+  
+}