📄 accountprofileserviceimp.java
字号:
package com.jdon.jivejdon.service.imp.account;
import java.awt.image.BufferedImage;
import org.apache.struts.upload.FormFile;
import com.jdon.controller.events.EventModel;
import com.jdon.jivejdon.dao.AccountProfileDao;
import com.jdon.jivejdon.model.AccountProfile;
import com.jdon.jivejdon.service.AccountProfileService;
import com.jdon.jivejdon.service.AccountService;
import com.jdon.jivejdon.util.ImageUtils;
import com.jdon.jivejdon.util.ToolsUtil;
public class AccountProfileServiceImp implements AccountProfileService {
private AccountProfileDao accountProfileDao;
private AccountService accountService;
public AccountProfileServiceImp(AccountService accountService, AccountProfileDao accountProfileDao) {
this.accountProfileDao = accountProfileDao;
this.accountService = accountService;
}
public AccountProfile getAccountProfile(Long priofileId) {
return accountProfileDao.getAccountProfile(priofileId);
}
public void updateAccountProfile(EventModel em) {
AccountProfile accountProfile = (AccountProfile)em.getModelIF();
FormFile theFile = accountProfile.getTheFile();
AccountProfile profileInSession = getAccountProfile(accountProfile.getPriofileId());
profileInSession.setAddress(accountProfile.getAddress());
if(theFile != null && theFile.getFileSize()!=0){
try {
String hashFileName = ToolsUtil.hash(accountProfile.getPriofileId().toString());
String uploadFileName = theFile.getFileName();
int extInt = uploadFileName.lastIndexOf(".");
String extension = uploadFileName.substring(extInt+1);
int type = ImageUtils.IMAGE_UNKNOWN;
if (extension.equals("jpg") || extension.equals("jpeg")) {
type = ImageUtils.IMAGE_JPEG;
}
else if (extension.equals("gif") || extension.equals("png")) {
type = ImageUtils.IMAGE_PNG;
}
if (type != ImageUtils.IMAGE_UNKNOWN) {
String saveTempFileName = accountProfile.getContextPath()+"upload/image/" + hashFileName + "." + extension;
ImageUtils.saveUploadedFile(theFile,saveTempFileName);
BufferedImage image = ImageUtils.resizeImage(saveTempFileName, type, 120, 140);
String saveFileName = accountProfile.getContextPath()+"/upload/image/" + hashFileName + "." + extension;
ImageUtils.saveImage(image, saveFileName, type);
profileInSession.setImagePath("/upload/image/" + hashFileName + "." + extension);
accountProfileDao.updateAccountProfile(profileInSession);
}
}catch(Exception ex){
ex.printStackTrace();
}
}else {
try {
accountProfileDao.updateAccountProfile(profileInSession);
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -