日期:2014-05-19 浏览次数:20729 次
package com.webapp.model.service.impl; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import javax.imageio.ImageIO; import javax.jws.WebService; import org.directwebremoting.annotations.Param; import org.directwebremoting.annotations.RemoteMethod; import org.directwebremoting.annotations.RemoteProxy; import org.directwebremoting.spring.SpringCreator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGEncodeParam; import com.sun.image.codec.jpeg.JPEGImageEncoder; import com.webapp.model.businessobject.Errorfeedback; import com.webapp.model.dao.ErrorfeedbackDao; import com.webapp.model.service.ErrorfeedbackService; import com.webapp.model.service.GridJsonDataService; import com.webapp.model.service.UsersService; import com.webapp.model.service.UtilService; import com.webapp.util.GuidCreator; @Service @WebService(endpointInterface = "com.webapp.model.service.ErrorfeedbackService") @RemoteProxy(creator = SpringCreator.class, creatorParams = @Param(name = "beanName", value = "errorfeedbackServiceImpl"), name = "ErrorfeedbackService") public class ErrorfeedbackServiceImpl implements ErrorfeedbackService { @Autowired private ErrorfeedbackDao errorfeedbackDao; @Autowired private UsersService usersService; @Autowired private UtilService utilService; @RemoteMethod public String saveErrorfeedback(Errorfeedback errorfeedback){ GuidCreator guid = new GuidCreator(); String typeStr = errorfeedback.getPicture().substring(errorfeedback.getPicture().lastIndexOf(".")+1); if(!"jpg".equals(typeStr) && !"png".equals(typeStr) && !"gif".equals(typeStr) && !"bmp".equals(typeStr)){ return "typeError"; }else{ // errorfeedback.setPicture(errorfeedback.getPicture().substring(errorfeedback.getPicture().lastIndexOf("\\"))); System.out.println("图片路径:"+errorfeedback.getPicture()); System.out.println("E:\\testCreateImg"); String picPath = ""; try { picPath = LoadImageToServer(errorfeedback.getPicture(),"E:\\testCreateImg"); if(picPath != null && !"".equals(picPath)){ errorfeedback.setPicture(picPath); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } errorfeedback.setGid(guid.createNewGuid(3)); errorfeedback.setSubmitby(utilService.getCurrentUser().getGid()); errorfeedback.setSubmitTime(new Date()); // try { // Image image = ImageIO.read(new File(errorfeedback.getPicture())); // errorfeedback.setPicture(new String(imageToBytes(image, "jpg"))); // } catch (Exception e) { // // TODO: handle exception // } this.errorfeedbackDao.save(errorfeedback); return "true"; } public String LoadImageToServer(String filePath,String serverPath) throws Exception { String resultPath = ""; //上传后图片所在的路径 FileOutputStream out = null; //文件输出流 try { //验证图片上传的格式是否正确 File f = new File(filePath); if (!f.isFile()) { throw new Exception(" 不是图片文件!"); } if (f != null && f.ex