文件上传优化

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

@ -80,7 +80,7 @@ public interface ISysFileService {
* @param file * @param file
*/ */
@ApiOperation(value = "上传文件资源",notes = "上传文件资源") @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("字典不存在") .setErrorDetail("字典不存在")
.setErrorSolution("请重新选择") .setErrorSolution("请重新选择")
.build(); .build();
}else if(!childList.isEmpty()){ }else if(childList!= null && !childList.isEmpty()){
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode()) .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
.setErrorDetail("无法删除,存在子级字典:" + childList.get(0).getName()) .setErrorDetail("无法删除,存在子级字典:" + childList.get(0).getName())
.setErrorSolution("请重新选择") .setErrorSolution("请重新选择")
.build(); .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() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.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.SysDictionary;
import cn.estsh.i3plus.pojo.platform.bean.SysFile; import cn.estsh.i3plus.pojo.platform.bean.SysFile;
import cn.estsh.impp.framework.base.controller.CoreBaseController; 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.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.fastdfs.FastDFSClient; import cn.estsh.impp.framework.boot.fastdfs.FastDFSClient;
@ -66,9 +67,7 @@ public class SysFileController extends CoreBaseController{
try { try {
// 条件验证 // 条件验证
ValidatorBean.beginValid(sysFile) ValidatorBean.beginValid(sysFile)
.notNull("id", sysFile.getId()) .notNull("fileSoftType", sysFile.getFileSoftType());
.notNull("fileSoftType", sysFile.getFileSoftType())
.notNull("name", sysFile.getName());
sysFileService.updateSysFile(sysFile); sysFileService.updateSysFile(sysFile);
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()); return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
@ -262,7 +261,7 @@ public class SysFileController extends CoreBaseController{
.build(); .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); return ResultBean.success("上传成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(fileDb);
}catch(ImppBusiException busExcep){ }catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep); return ResultBean.fail(busExcep);

@ -1,6 +1,9 @@
package cn.estsh.i3plus.core.apiservice.serviceimpl.busi; package cn.estsh.i3plus.core.apiservice.serviceimpl.busi;
import cn.estsh.i3plus.core.api.iservice.busi.ISysFileService; 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.FileTool;
import cn.estsh.i3plus.platform.common.tool.StringTool; import cn.estsh.i3plus.platform.common.tool.StringTool;
import cn.estsh.i3plus.pojo.base.bean.ListPager; 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.repository.SysFileRepository;
import cn.estsh.i3plus.pojo.platform.sqlpack.CoreHqlPack; import cn.estsh.i3plus.pojo.platform.sqlpack.CoreHqlPack;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; 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.FastDFSClient;
import cn.estsh.impp.framework.boot.fastdfs.FastDFSFile; import cn.estsh.impp.framework.boot.fastdfs.FastDFSFile;
import com.mchange.lang.IntegerUtils; import com.mchange.lang.IntegerUtils;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -69,6 +72,17 @@ public class SysFileServiceImpl implements ISysFileService {
@ApiOperation(value = "更新资源信息") @ApiOperation(value = "更新资源信息")
public void updateSysFile(SysFile sysFile) { public void updateSysFile(SysFile sysFile) {
LOGGER.info("文件资源 SYS_FILE :{}", 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) { if (sysFile.getFileCode() != null) {
List list = sysFileRDao.findByHqlWhere(CoreHqlPack.packHqlSysFileCode(sysFile)); List list = sysFileRDao.findByHqlWhere(CoreHqlPack.packHqlSysFileCode(sysFile));
if (list != null && list.size() > 0) { 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 @Override
@ -134,8 +150,10 @@ public class SysFileServiceImpl implements ISysFileService {
@Override @Override
@ApiOperation(value = "上传文件资源", notes = "上传文件资源") @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); sysFile = uploadFastDfs(file, sysFile);
ConvertBean.serviceModelInitialize(sysFile, userName);
return insertSysFile(sysFile); 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.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords; import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; 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.MailConfig;
import cn.estsh.i3plus.pojo.platform.bean.SysConfig; import cn.estsh.i3plus.pojo.platform.bean.SysConfig;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
@ -38,8 +37,8 @@ public class MailUtil {
public static final Logger LOGGER = LoggerFactory.getLogger(MailUtil.class); public static final Logger LOGGER = LoggerFactory.getLogger(MailUtil.class);
// 收件人 // 收件人
private Address[] to = null; private Address[] to = new Address[]{};
private Address[] cc = null; private Address[] cc = new Address[]{};
private int mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(); private int mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
private String from = ""; private String from = "";
private String nick = ""; private String nick = "";
@ -58,6 +57,7 @@ public class MailUtil {
/** /**
* *
*
* @return * @return
*/ */
public MailUtil init() { public MailUtil init() {
@ -77,7 +77,7 @@ public class MailUtil {
this.mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(); this.mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
} }
return this; return this;
} catch (Exception e){ } catch (Exception e) {
LOGGER.error("邮箱配置初始化失败!", e.getMessage()); LOGGER.error("邮箱配置初始化失败!", e.getMessage());
return new MailUtil(); return new MailUtil();
} }
@ -86,6 +86,7 @@ public class MailUtil {
/** /**
* *
*
* @param mailConfig * @param mailConfig
* @return * @return
*/ */
@ -101,7 +102,7 @@ public class MailUtil {
this.isAuthenticationSMTP = true; this.isAuthenticationSMTP = true;
return this; return this;
} catch (Exception e){ } catch (Exception e) {
LOGGER.error("邮箱配置初始化失败!", e.getMessage()); LOGGER.error("邮箱配置初始化失败!", e.getMessage());
return new MailUtil(); return new MailUtil();
} }
@ -184,13 +185,18 @@ public class MailUtil {
this.contentType = contentType; this.contentType = contentType;
} }
/**
*
* @param add
* @return
*/
private Address[] getAddress(String[] add) { private Address[] getAddress(String[] add) {
Address[] a = new Address[add.length]; Address[] a = new Address[add.length];
for (int i = 0; i < add.length; i++) { for (int i = 0; i < add.length; i++) {
try { try {
a[i] = new InternetAddress(add[i]); a[i] = new InternetAddress(add[i]);
} catch (AddressException ex) { } catch (AddressException ex) {
LOGGER.error("邮箱地址错误!",ex.getMessage()); LOGGER.error("【" + add[i] + "】邮箱地址错误!", ex.getMessage());
} }
} }
return a; return a;
@ -200,9 +206,9 @@ public class MailUtil {
* *
*/ */
public void send() { public void send() {
try{ try {
// 是否开启邮箱配置 // 是否开启邮箱配置
if(this.mailSwitch != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()){ if (this.mailSwitch != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
return; return;
} }
Properties server = new Properties(); Properties server = new Properties();
@ -250,7 +256,7 @@ public class MailUtil {
} }
LOGGER.info("邮件发送成功"); LOGGER.info("邮件发送成功");
} catch (SMTPAddressFailedException e){ } catch (SMTPAddressFailedException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage()); LOGGER.error(e.getClass() + "\t" + e.getMessage());
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
@ -258,7 +264,7 @@ public class MailUtil {
.setErrorDetail(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getDescription()) .setErrorDetail(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getDescription())
.setErrorSolution("请重新设置收件人") .setErrorSolution("请重新设置收件人")
.build(); .build();
} catch (AuthenticationFailedException e){ } catch (AuthenticationFailedException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage()); LOGGER.error(e.getClass() + "\t" + e.getMessage());
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
@ -266,7 +272,7 @@ public class MailUtil {
.setErrorDetail(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getDescription()) .setErrorDetail(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getDescription())
.setErrorSolution("请重新设置账号或密码") .setErrorSolution("请重新设置账号或密码")
.build(); .build();
} catch (MessagingException e){ } catch (MessagingException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage()); LOGGER.error(e.getClass() + "\t" + e.getMessage());
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())

Loading…
Cancel
Save