Merge branches 'dev' and 'test' of http://git.estsh.com/i3-IMPP/i3plus-core into test

yun-zuoyi
wei.peng 6 years ago
commit 524b953025

@ -168,4 +168,10 @@ public interface IPersonnelService {
@ApiOperation(value = "刷新用户岗位") @ApiOperation(value = "刷新用户岗位")
void refreshUpdateRefSysUserInfoPositionRdd(Long positionId); void refreshUpdateRefSysUserInfoPositionRdd(Long positionId);
/**
*
* @return
*/
@ApiOperation(value = "根据组织代码查询组织信息")
SysOrganize getSysOrganizeByCode(String code);
} }

@ -1,10 +1,44 @@
package cn.estsh.i3plus.core.apiservice.controller.base; package cn.estsh.i3plus.core.apiservice.controller.base;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
import cn.estsh.i3plus.platform.common.tool.FileTool;
import cn.estsh.i3plus.platform.common.tool.ZipTool;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords; import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.model.common.ExportDataModel;
import cn.estsh.i3plus.pojo.platform.bean.SysOrderNoRule;
import cn.estsh.impp.framework.base.controller.BaseCommonController; import cn.estsh.impp.framework.base.controller.BaseCommonController;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import java.io.*;
import java.util.*;
import org.springframework.web.method.HandlerMethod;
import springfox.documentation.spring.web.json.Json;
import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletResponse;
/** /**
* @Description : * @Description :
@ -17,4 +51,82 @@ import org.springframework.web.bind.annotation.RestController;
@Api(description = "通用功能服务") @Api(description = "通用功能服务")
@RequestMapping(PlatformConstWords.BASE_URL +"/common") @RequestMapping(PlatformConstWords.BASE_URL +"/common")
public class CoreCommonController extends BaseCommonController { public class CoreCommonController extends BaseCommonController {
@Autowired
private EntityManager entityManager;
@Resource(name="redisRes")
private ImppRedis redisRes;
@Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping;
@PostMapping("/test-mapping")
@ApiOperation("根据路径寻找Controller")
public ResultBean exportData(ExportDataModel exportDataModel, HttpServletResponse response){
try {
ValidatorBean.beginValid(exportDataModel)
.notNull("className",exportDataModel.getClassName())
.notNull("exportData",exportDataModel.getExportData());
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
Class entityClass = Class.forName(exportDataModel.getClassName());
String[] colName = new String[ExcelTool.getColName(entityClass).size()];
ExcelTool.getColName(entityClass).keySet().toArray(colName);
List dataList = JSONArray.parseArray(exportDataModel.getExportData(), entityClass);
// 数据校验
if (colName == null || colName.length == 0) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode())
.setErrorDetail("导出列不能为空")
.build();
}
// 将excel导出至临时文件夹
File excelFile = new File(System.getProperty("java.io.tmpdir") + File.separator + entityClass.getSimpleName()+".xls");
excelFile.createNewFile();
excelTool.exportData(excelFile, dataList, entityClass, colName);
InputStream targetStream = new DataInputStream(new FileInputStream(excelFile));
response.setContentType("application/octet-stream;");
response.setHeader("Content-Disposition", "attachment;fileName=" + excelFile.getName()); // 设置文件名
response.addHeader("Pargam", "no-cache");
response.addHeader("Cache-Control", "no-cache");
BufferedInputStream bis = null;
OutputStream os = null;
try {
bis = new BufferedInputStream(targetStream);
os = response.getOutputStream();
byte[] buffer = new byte[1024];
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
os.close();
bis.close();
targetStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
excelFile.delete();
return ResultBean.success("导出成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
} }

@ -743,4 +743,22 @@ public class PersonnelController extends CoreBaseController {
} }
} }
} }
/**
* code
* @param code
* @return
*/
@GetMapping(value = "/organize/get-code")
@ApiOperation(value = "根据组织code查询对应的组织信息", notes = "根据组织code查询对应的组织信息")
public ResultBean<SysOrganize> getSysOrganizeByCode(String code){
try{
SysOrganize sysOrganize = personnelService.getSysOrganizeByCode(code);
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(sysOrganize);
}catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep);
}catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
} }

@ -315,9 +315,7 @@ public class SysConfigController extends CoreBaseController {
mailUtil.send(); mailUtil.send();
return ResultBean.success("测试邮件已发送").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()); return ResultBean.success("测试邮件已发送").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch(MessagingException messageExcep){ } catch(ImppBusiException busExcep){
return ResultBean.fail("邮件配置错误:" + messageExcep.getMessage());
}catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep); return ResultBean.fail(busExcep);
}catch(Exception e){ }catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); return ImppExceptionBuilder.newInstance().buildExceptionResult(e);

@ -76,7 +76,7 @@ public class MessageMailQueueReceiver {
// 判断是否为系统紧急提示 微服注册状态提示 // 判断是否为系统紧急提示 微服注册状态提示
mailUtil.setTo(sysConfigService.getSysConfigByCode(PlatformConstWords.CONTACT_MAIL).getConfigValue()); mailUtil.setTo(sysConfigService.getSysConfigByCode(PlatformConstWords.CONTACT_MAIL).getConfigValue());
// 次数过于频繁 // 次数过于频繁
// mailUtil.send(); mailUtil.send();
} else if (msg.getMessageReceiverType().intValue() == ImppEnumUtil.MESSAGE_RECEIVER_TYPE.EXTERNAL.getValue()) { } else if (msg.getMessageReceiverType().intValue() == ImppEnumUtil.MESSAGE_RECEIVER_TYPE.EXTERNAL.getValue()) {
//判断是否为外部邮件 //判断是否为外部邮件

@ -1064,6 +1064,11 @@ public class PersonnelServiceService implements IPersonnelService {
} }
} }
@Override
public SysOrganize getSysOrganizeByCode(String code) {
return organizeRDao.getByProperty("organizeCode", code);
}
/*********************************** 检查方法封装 ***********************************/ /*********************************** 检查方法封装 ***********************************/
/** /**

@ -177,6 +177,12 @@ public class SysRoleService implements ISysRoleService {
} }
} }
// 冗余信息
for (SysRole role : roleList) {
role.setModuleNumber(moduleListRdd.size());
role.setMenuNumber(featuresListRdd.size());
}
refRoleMenuRDao.saveAll(refs); refRoleMenuRDao.saveAll(refs);
roleRDao.saveAll(roleList); roleRDao.saveAll(roleList);
}else { }else {

@ -1,16 +1,24 @@
package cn.estsh.i3plus.core.apiservice.util; package cn.estsh.i3plus.core.apiservice.util;
import cn.estsh.i3plus.core.api.iservice.busi.ISysConfigService; 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.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 com.sun.mail.smtp.SMTPAddressFailedException;
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;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.mail.Address;
import javax.mail.*; import javax.mail.AuthenticationFailedException;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException; import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
@ -21,7 +29,7 @@ import java.util.Properties;
/** /**
* @Description : * @Description :
* @Reference : * @Reference :
* @Author : yunhao * @Author : yunhaoo
* @CreateDate : 2018-11-14 19:24 * @CreateDate : 2018-11-14 19:24
* @Modify: * @Modify:
**/ **/
@ -39,7 +47,7 @@ public class MailUtil {
private String content = ""; private String content = "";
private String smtpHost = ""; private String smtpHost = "";
private int smtpPort = 25; private int smtpPort = 25;
private String content_type = ""; private String contentType = "";
private String smtpUser = ""; private String smtpUser = "";
private String smtpPassword = ""; private String smtpPassword = "";
@ -48,37 +56,55 @@ public class MailUtil {
@Autowired @Autowired
private ISysConfigService sysConfigService; private ISysConfigService sysConfigService;
// 初始化服务器邮箱参数 /**
*
* @return
*/
public MailUtil init() { public MailUtil init() {
// 查询是否开启邮件服务器 try {
SysConfig sysConfig = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_SWITCH); // 查询是否开启邮件服务器
if(sysConfig != null) { SysConfig sysConfig = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_SWITCH);
this.mailSwitch = Integer.parseInt(sysConfig.getConfigValue()); if (sysConfig != null) {
this.smtpHost = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_HOST).getConfigValue(); this.mailSwitch = Integer.parseInt(sysConfig.getConfigValue());
this.smtpPort = Integer.parseInt(sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_PORT).getConfigValue()); this.smtpHost = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_HOST).getConfigValue();
this.from = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_USER).getConfigValue(); this.smtpPort = Integer.parseInt(sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_PORT).getConfigValue());
this.nick = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_NICK).getConfigValue(); this.from = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_USER).getConfigValue();
this.smtpUser = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_USER).getConfigValue(); this.nick = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_NICK).getConfigValue();
this.smtpPassword = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_PASSWORD).getConfigValue(); this.smtpUser = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_USER).getConfigValue();
this.isAuthenticationSMTP = true; this.smtpPassword = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_PASSWORD).getConfigValue();
} else{ this.isAuthenticationSMTP = true;
this.mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(); } else {
this.mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
}
return this;
} catch (Exception e){
LOGGER.error("邮箱配置初始化失败!", e.getMessage());
return new MailUtil();
} }
return this;
} }
// 初始化服务器邮箱参数 /**
*
* @param mailConfig
* @return
*/
public MailUtil init(MailConfig mailConfig) { public MailUtil init(MailConfig mailConfig) {
this.mailSwitch = mailConfig.getMailSwitch(); try {
this.smtpHost = mailConfig.getMailHost(); this.mailSwitch = mailConfig.getMailSwitch();
this.smtpPort = mailConfig.getMailPort(); this.smtpHost = mailConfig.getMailHost();
this.from = mailConfig.getMailUser(); this.smtpPort = mailConfig.getMailPort();
this.nick = mailConfig.getMailNick(); this.from = mailConfig.getMailUser();
this.smtpUser = mailConfig.getMailUser(); this.nick = mailConfig.getMailNick();
this.smtpPassword = mailConfig.getMailPassword(); this.smtpUser = mailConfig.getMailUser();
this.isAuthenticationSMTP = true; this.smtpPassword = mailConfig.getMailPassword();
this.isAuthenticationSMTP = true;
return this;
return this;
} catch (Exception e){
LOGGER.error("邮箱配置初始化失败!", e.getMessage());
return new MailUtil();
}
} }
/** /**
@ -105,10 +131,10 @@ public class MailUtil {
/** /**
* *
* *
* @param Emails Email * @param emails Email
*/ */
public void setTo(String[] Emails) { public void setTo(String[] emails) {
this.to = getAddress(Emails); this.to = getAddress(emails);
} }
/** /**
@ -125,10 +151,10 @@ public class MailUtil {
/** /**
* *
* *
* @param Emails * @param emails
*/ */
public void setCC(String[] Emails) { public void setCC(String[] emails) {
this.cc = getAddress(Emails); this.cc = getAddress(emails);
} }
/** /**
@ -155,7 +181,7 @@ public class MailUtil {
* @param contentType CommonConstWords.MAIL_MODE_TEXTMAIL_MODE_HTML * @param contentType CommonConstWords.MAIL_MODE_TEXTMAIL_MODE_HTML
*/ */
public void setContentType(String contentType) { public void setContentType(String contentType) {
this.content_type = contentType; this.contentType = contentType;
} }
private Address[] getAddress(String[] add) { private Address[] getAddress(String[] add) {
@ -173,7 +199,8 @@ public class MailUtil {
/** /**
* *
*/ */
public void send() throws UnsupportedEncodingException, MessagingException { public void send() {
try{
// 是否开启邮箱配置 // 是否开启邮箱配置
if(this.mailSwitch != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()){ if(this.mailSwitch != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()){
return; return;
@ -210,7 +237,7 @@ public class MailUtil {
// 消息主体内容 处理 // 消息主体内容 处理
this.content = this.content == null ? "" : this.content; this.content = this.content == null ? "" : this.content;
msg.setContent(this.content, this.content_type); msg.setContent(this.content, this.contentType);
msg.saveChanges(); msg.saveChanges();
if (this.isAuthenticationSMTP) { if (this.isAuthenticationSMTP) {
@ -222,5 +249,39 @@ public class MailUtil {
Transport.send(msg, msg.getAllRecipients()); Transport.send(msg, msg.getAllRecipients());
} }
LOGGER.info("邮件发送成功"); LOGGER.info("邮件发送成功");
} catch (SMTPAddressFailedException e){
LOGGER.error(e.getClass() + "\t" + e.getMessage());
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getCode())
.setErrorDetail(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getDescription())
.setErrorSolution("请重新设置收件人")
.build();
} catch (AuthenticationFailedException e){
LOGGER.error(e.getClass() + "\t" + e.getMessage());
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getCode())
.setErrorDetail(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getDescription())
.setErrorSolution("请重新设置账号或密码")
.build();
} catch (MessagingException e){
LOGGER.error(e.getClass() + "\t" + e.getMessage());
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode())
.setErrorDetail(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getDescription())
.setErrorSolution("请重新设置邮件服务器地址或端口")
.build();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode())
.setErrorDetail(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getDescription())
.setErrorSolution("请重新设置邮件服务器地址或端口")
.build();
}
} }
} }

@ -1,12 +1,15 @@
package cn.estsh.i3plus.core.apiservice.util; package cn.estsh.i3plus.core.apiservice.util;
import cn.estsh.i3plus.core.apiservice.serviceimpl.busi.TestBase; import cn.estsh.i3plus.core.apiservice.serviceimpl.busi.TestBase;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil; import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
import cn.estsh.i3plus.pojo.platform.bean.MailConfig;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import static cn.estsh.i3plus.core.apiservice.controller.busi.SysUserInfoController.LOGGER;
/** /**
* @Description : * @Description :
@ -22,15 +25,24 @@ public class TestMailUtil extends TestBase {
@Test @Test
public void TestSendMail(){ public void TestSendMail(){
mailUtil.setTo("yunhao.wang@estsh.com"); MailConfig mailConfig = new MailConfig();
mailUtil.setSubject("中文"); mailConfig.setMailSwitch(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
mailUtil.setContentType(ImppEnumUtil.MESSAGE_TYPE_CONTENT.HTML.getDescription()); mailConfig.setMailHost("smtphm.qiye.163.com");
mailUtil.setBody("内容"); mailConfig.setMailPort(25);
mailConfig.setMailNick("");
mailConfig.setMailUser("impp.dev@sss.com");
mailConfig.setMailPassword("Aa135790s");
MailUtil mailUtil = new MailUtil();
try { try {
mailUtil.send(); mailUtil.setTo("yunhao.wang@estsh.com");
} catch (UnsupportedEncodingException e) { mailUtil.setBody("zhenw");
e.printStackTrace(); mailUtil.setSubject("title");
} catch (MessagingException e) { mailUtil.setContentType(ImppEnumUtil.MESSAGE_TYPE_CONTENT.HTML.getDescription());
mailUtil.init(mailConfig).send();
} catch (Exception e){
LOGGER.error(e.getCause()+"");
// LOGGER.error(e.);
e.printStackTrace(); e.printStackTrace();
} }

Loading…
Cancel
Save