From d2cfe8e675c6d4a4557f4d3fbc73dec0d0f413eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=AA=E4=BA=91=E6=98=8A?= Date: Sat, 29 Jun 2019 17:01:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20=E5=AD=97=E6=AE=B5=E5=88=A0=E9=99=A4=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=20=E6=97=A5=E5=BF=97=E6=B7=BB=E5=8A=A0=E7=B4=A2?= =?UTF-8?q?=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/api/iservice/busi/ISysFileService.java | 2 +- .../controller/busi/SysDictionaryController.java | 4 +- .../controller/busi/SysFileController.java | 7 +- .../serviceimpl/busi/SysFileServiceImpl.java | 24 ++++- .../i3plus/core/apiservice/util/MailUtil.java | 110 +++++++++++---------- 5 files changed, 85 insertions(+), 62 deletions(-) diff --git a/modules/i3plus-core-api/src/main/java/cn/estsh/i3plus/core/api/iservice/busi/ISysFileService.java b/modules/i3plus-core-api/src/main/java/cn/estsh/i3plus/core/api/iservice/busi/ISysFileService.java index 3d93785..1e902a1 100644 --- a/modules/i3plus-core-api/src/main/java/cn/estsh/i3plus/core/api/iservice/busi/ISysFileService.java +++ b/modules/i3plus-core-api/src/main/java/cn/estsh/i3plus/core/api/iservice/busi/ISysFileService.java @@ -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; /** * 根据文件代码获取文件信息 diff --git a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/busi/SysDictionaryController.java b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/busi/SysDictionaryController.java index 9c8ff11..995c3c2 100644 --- a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/busi/SysDictionaryController.java +++ b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/busi/SysDictionaryController.java @@ -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()) diff --git a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/busi/SysFileController.java b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/busi/SysFileController.java index 38af197..523fdd1 100644 --- a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/busi/SysFileController.java +++ b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/busi/SysFileController.java @@ -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); diff --git a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/serviceimpl/busi/SysFileServiceImpl.java b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/serviceimpl/busi/SysFileServiceImpl.java index bad01e6..2189ccb 100644 --- a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/serviceimpl/busi/SysFileServiceImpl.java +++ b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/serviceimpl/busi/SysFileServiceImpl.java @@ -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); } diff --git a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/util/MailUtil.java b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/util/MailUtil.java index f4b504c..6b00eae 100644 --- a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/util/MailUtil.java +++ b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/util/MailUtil.java @@ -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())