文件上传优化

字段删除异常
日志添加索引
yun-zuoyi
汪云昊 6 years ago
parent 7110affac4
commit d2cfe8e675

@ -80,7 +80,7 @@ public interface ISysFileService {
* @param file
*/
@ApiOperation(value = "上传文件资源",notes = "上传文件资源")
SysFile uploadFile(Object file,SysFile sysFile) throws Exception;
SysFile uploadFile(Object file,SysFile sysFile, String userName) throws Exception;
/**
*

@ -162,14 +162,14 @@ public class SysDictionaryController extends CoreBaseController{
.setErrorDetail("字典不存在")
.setErrorSolution("请重新选择")
.build();
}else if(!childList.isEmpty()){
}else if(childList!= null && !childList.isEmpty()){
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
.setErrorDetail("无法删除,存在子级字典:" + childList.get(0).getName())
.setErrorSolution("请重新选择")
.build();
} else if(sysDictionary.getIsDefault().intValue() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
} else if(sysDictionary.getIsDefaultVal() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())

@ -13,6 +13,7 @@ import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.platform.bean.SysDictionary;
import cn.estsh.i3plus.pojo.platform.bean.SysFile;
import cn.estsh.impp.framework.base.controller.CoreBaseController;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.fastdfs.FastDFSClient;
@ -66,9 +67,7 @@ public class SysFileController extends CoreBaseController{
try {
// 条件验证
ValidatorBean.beginValid(sysFile)
.notNull("id", sysFile.getId())
.notNull("fileSoftType", sysFile.getFileSoftType())
.notNull("name", sysFile.getName());
.notNull("fileSoftType", sysFile.getFileSoftType());
sysFileService.updateSysFile(sysFile);
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
@ -262,7 +261,7 @@ public class SysFileController extends CoreBaseController{
.build();
}
SysFile fileDb = sysFileService.uploadFile(file,sysFile);
SysFile fileDb = sysFileService.uploadFile(file,sysFile, AuthUtil.getSessionUser().getUserName());
return ResultBean.success("上传成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(fileDb);
}catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep);

@ -1,6 +1,9 @@
package cn.estsh.i3plus.core.apiservice.serviceimpl.busi;
import cn.estsh.i3plus.core.api.iservice.busi.ISysFileService;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.tool.BeanCopyTool;
import cn.estsh.i3plus.platform.common.tool.FileTool;
import cn.estsh.i3plus.platform.common.tool.StringTool;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
@ -12,11 +15,11 @@ import cn.estsh.i3plus.pojo.platform.repository.SysDictionaryRepository;
import cn.estsh.i3plus.pojo.platform.repository.SysFileRepository;
import cn.estsh.i3plus.pojo.platform.sqlpack.CoreHqlPack;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
import cn.estsh.impp.framework.boot.fastdfs.FastDFSClient;
import cn.estsh.impp.framework.boot.fastdfs.FastDFSFile;
import com.mchange.lang.IntegerUtils;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -69,6 +72,17 @@ public class SysFileServiceImpl implements ISysFileService {
@ApiOperation(value = "更新资源信息")
public void updateSysFile(SysFile sysFile) {
LOGGER.info("文件资源 SYS_FILE :{}", sysFile);
SysFile originSysFile = sysFileRDao.getById(sysFile.getId());
if(originSysFile == null){
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
.setErrorDetail(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getDescription())
.setErrorSolution("请重新选择")
.build();
}
// 文件代码唯一校验
if (sysFile.getFileCode() != null) {
List list = sysFileRDao.findByHqlWhere(CoreHqlPack.packHqlSysFileCode(sysFile));
if (list != null && list.size() > 0) {
@ -81,7 +95,9 @@ public class SysFileServiceImpl implements ISysFileService {
}
}
sysFileRDao.update(sysFile);
BeanCopyTool.beanCopy(sysFile, originSysFile);
sysFileRDao.update(originSysFile);
}
@Override
@ -134,8 +150,10 @@ public class SysFileServiceImpl implements ISysFileService {
@Override
@ApiOperation(value = "上传文件资源", notes = "上传文件资源")
public SysFile uploadFile(Object file,SysFile sysFile) throws Exception {
public SysFile uploadFile(Object file,SysFile sysFile, String userName) throws Exception {
sysFile = uploadFastDfs(file, sysFile);
ConvertBean.serviceModelInitialize(sysFile, userName);
return insertSysFile(sysFile);
}

@ -4,7 +4,6 @@ import cn.estsh.i3plus.core.api.iservice.busi.ISysConfigService;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
import cn.estsh.i3plus.pojo.platform.bean.MailConfig;
import cn.estsh.i3plus.pojo.platform.bean.SysConfig;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
@ -38,8 +37,8 @@ public class MailUtil {
public static final Logger LOGGER = LoggerFactory.getLogger(MailUtil.class);
// 收件人
private Address[] to = null;
private Address[] cc = null;
private Address[] to = new Address[]{};
private Address[] cc = new Address[]{};
private int mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
private String from = "";
private String nick = "";
@ -58,6 +57,7 @@ public class MailUtil {
/**
*
*
* @return
*/
public MailUtil init() {
@ -77,7 +77,7 @@ public class MailUtil {
this.mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
}
return this;
} catch (Exception e){
} catch (Exception e) {
LOGGER.error("邮箱配置初始化失败!", e.getMessage());
return new MailUtil();
}
@ -86,6 +86,7 @@ public class MailUtil {
/**
*
*
* @param mailConfig
* @return
*/
@ -101,7 +102,7 @@ public class MailUtil {
this.isAuthenticationSMTP = true;
return this;
} catch (Exception e){
} catch (Exception e) {
LOGGER.error("邮箱配置初始化失败!", e.getMessage());
return new MailUtil();
}
@ -184,13 +185,18 @@ public class MailUtil {
this.contentType = contentType;
}
/**
*
* @param add
* @return
*/
private Address[] getAddress(String[] add) {
Address[] a = new Address[add.length];
for (int i = 0; i < add.length; i++) {
try {
a[i] = new InternetAddress(add[i]);
} catch (AddressException ex) {
LOGGER.error("邮箱地址错误!",ex.getMessage());
LOGGER.error("【" + add[i] + "】邮箱地址错误!", ex.getMessage());
}
}
return a;
@ -200,57 +206,57 @@ public class MailUtil {
*
*/
public void send() {
try{
// 是否开启邮箱配置
if(this.mailSwitch != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()){
return;
}
Properties server = new Properties();
server.put("mail.smtp.port", String.valueOf(this.smtpPort));
server.put("mail.smtp.host", this.smtpHost);
if (this.isAuthenticationSMTP) {
server.put("mail.smtp.auth", "true");
}
try {
// 是否开启邮箱配置
if (this.mailSwitch != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
return;
}
Properties server = new Properties();
server.put("mail.smtp.port", String.valueOf(this.smtpPort));
server.put("mail.smtp.host", this.smtpHost);
if (this.isAuthenticationSMTP) {
server.put("mail.smtp.auth", "true");
}
Session conn = Session.getInstance(server, null);
Session conn = Session.getInstance(server, null);
MimeMessage msg = new MimeMessage(conn);
if (nick != null && !"".equals(nick)) {
nick = MimeUtility.encodeText(nick, MimeUtility.mimeCharset("gb2312"), null);
msg.setSubject(nick);
msg.setFrom(new InternetAddress(nick + " <" + from + ">"));
} else {
msg.setFrom(new InternetAddress(this.from));
}
// 收件人
if (this.to != null) {
msg.setRecipients(Message.RecipientType.TO, this.to);
}
// 抄送
if (this.cc != null) {
msg.setRecipients(Message.RecipientType.CC, this.cc);
}
MimeMessage msg = new MimeMessage(conn);
if (nick != null && !"".equals(nick)) {
nick = MimeUtility.encodeText(nick, MimeUtility.mimeCharset("gb2312"), null);
msg.setSubject(nick);
msg.setFrom(new InternetAddress(nick + " <" + from + ">"));
} else {
msg.setFrom(new InternetAddress(this.from));
}
// 收件人
if (this.to != null) {
msg.setRecipients(Message.RecipientType.TO, this.to);
}
// 抄送
if (this.cc != null) {
msg.setRecipients(Message.RecipientType.CC, this.cc);
}
msg.setSubject(MimeUtility.encodeText(this.title, MimeUtility.mimeCharset("gb2312"), null));
msg.setSubject(this.title);
msg.setSubject(MimeUtility.encodeText(this.title, MimeUtility.mimeCharset("gb2312"), null));
msg.setSubject(this.title);
// 消息主体内容 处理
this.content = this.content == null ? "" : this.content;
// 消息主体内容 处理
this.content = this.content == null ? "" : this.content;
msg.setContent(this.content, this.contentType);
msg.setContent(this.content, this.contentType);
msg.saveChanges();
if (this.isAuthenticationSMTP) {
Transport transport = conn.getTransport("smtp");
transport.connect(this.smtpHost, this.smtpUser, this.smtpPassword);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
} else {
Transport.send(msg, msg.getAllRecipients());
}
LOGGER.info("邮件发送成功");
msg.saveChanges();
if (this.isAuthenticationSMTP) {
Transport transport = conn.getTransport("smtp");
transport.connect(this.smtpHost, this.smtpUser, this.smtpPassword);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
} else {
Transport.send(msg, msg.getAllRecipients());
}
LOGGER.info("邮件发送成功");
} catch (SMTPAddressFailedException e){
} catch (SMTPAddressFailedException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage());
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
@ -258,7 +264,7 @@ public class MailUtil {
.setErrorDetail(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getDescription())
.setErrorSolution("请重新设置收件人")
.build();
} catch (AuthenticationFailedException e){
} catch (AuthenticationFailedException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage());
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
@ -266,7 +272,7 @@ public class MailUtil {
.setErrorDetail(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getDescription())
.setErrorSolution("请重新设置账号或密码")
.build();
} catch (MessagingException e){
} catch (MessagingException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage());
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())

Loading…
Cancel
Save