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 = "刷新用户岗位")
void refreshUpdateRefSysUserInfoPositionRdd(Long positionId);
/**
*
* @return
*/
@ApiOperation(value = "根据组织代码查询组织信息")
SysOrganize getSysOrganizeByCode(String code);
}

@ -1,10 +1,44 @@
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.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.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.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.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 :
@ -17,4 +51,82 @@ import org.springframework.web.bind.annotation.RestController;
@Api(description = "通用功能服务")
@RequestMapping(PlatformConstWords.BASE_URL +"/common")
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();
return ResultBean.success("测试邮件已发送").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch(MessagingException messageExcep){
return ResultBean.fail("邮件配置错误:" + messageExcep.getMessage());
}catch(ImppBusiException busExcep){
} catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep);
}catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);

@ -76,7 +76,7 @@ public class MessageMailQueueReceiver {
// 判断是否为系统紧急提示 微服注册状态提示
mailUtil.setTo(sysConfigService.getSysConfigByCode(PlatformConstWords.CONTACT_MAIL).getConfigValue());
// 次数过于频繁
// mailUtil.send();
mailUtil.send();
} 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);
roleRDao.saveAll(roleList);
}else {

@ -1,16 +1,24 @@
package cn.estsh.i3plus.core.apiservice.util;
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;
import com.sun.mail.smtp.SMTPAddressFailedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.mail.*;
import javax.mail.Address;
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.InternetAddress;
import javax.mail.internet.MimeMessage;
@ -21,7 +29,7 @@ import java.util.Properties;
/**
* @Description :
* @Reference :
* @Author : yunhao
* @Author : yunhaoo
* @CreateDate : 2018-11-14 19:24
* @Modify:
**/
@ -39,7 +47,7 @@ public class MailUtil {
private String content = "";
private String smtpHost = "";
private int smtpPort = 25;
private String content_type = "";
private String contentType = "";
private String smtpUser = "";
private String smtpPassword = "";
@ -48,11 +56,15 @@ public class MailUtil {
@Autowired
private ISysConfigService sysConfigService;
// 初始化服务器邮箱参数
/**
*
* @return
*/
public MailUtil init() {
try {
// 查询是否开启邮件服务器
SysConfig sysConfig = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_SWITCH);
if(sysConfig != null) {
if (sysConfig != null) {
this.mailSwitch = Integer.parseInt(sysConfig.getConfigValue());
this.smtpHost = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_HOST).getConfigValue();
this.smtpPort = Integer.parseInt(sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_PORT).getConfigValue());
@ -61,14 +73,24 @@ public class MailUtil {
this.smtpUser = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_USER).getConfigValue();
this.smtpPassword = sysConfigService.getSysConfigByCode(PlatformConstWords.MAIL_PASSWORD).getConfigValue();
this.isAuthenticationSMTP = true;
} else{
} else {
this.mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
}
return this;
} catch (Exception e){
LOGGER.error("邮箱配置初始化失败!", e.getMessage());
return new MailUtil();
}
}
// 初始化服务器邮箱参数
/**
*
* @param mailConfig
* @return
*/
public MailUtil init(MailConfig mailConfig) {
try {
this.mailSwitch = mailConfig.getMailSwitch();
this.smtpHost = mailConfig.getMailHost();
this.smtpPort = mailConfig.getMailPort();
@ -79,6 +101,10 @@ public class MailUtil {
this.isAuthenticationSMTP = true;
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) {
this.to = getAddress(Emails);
public void setTo(String[] emails) {
this.to = getAddress(emails);
}
/**
@ -125,10 +151,10 @@ public class MailUtil {
/**
*
*
* @param Emails
* @param emails
*/
public void setCC(String[] Emails) {
this.cc = getAddress(Emails);
public void setCC(String[] emails) {
this.cc = getAddress(emails);
}
/**
@ -155,7 +181,7 @@ public class MailUtil {
* @param contentType CommonConstWords.MAIL_MODE_TEXTMAIL_MODE_HTML
*/
public void setContentType(String contentType) {
this.content_type = contentType;
this.contentType = contentType;
}
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()){
return;
@ -210,7 +237,7 @@ public class MailUtil {
// 消息主体内容 处理
this.content = this.content == null ? "" : this.content;
msg.setContent(this.content, this.content_type);
msg.setContent(this.content, this.contentType);
msg.saveChanges();
if (this.isAuthenticationSMTP) {
@ -222,5 +249,39 @@ public class MailUtil {
Transport.send(msg, msg.getAllRecipients());
}
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;
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.platform.bean.MailConfig;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import javax.mail.MessagingException;
import java.io.UnsupportedEncodingException;
import static cn.estsh.i3plus.core.apiservice.controller.busi.SysUserInfoController.LOGGER;
/**
* @Description :
@ -22,15 +25,24 @@ public class TestMailUtil extends TestBase {
@Test
public void TestSendMail(){
MailConfig mailConfig = new MailConfig();
mailConfig.setMailSwitch(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
mailConfig.setMailHost("smtphm.qiye.163.com");
mailConfig.setMailPort(25);
mailConfig.setMailNick("");
mailConfig.setMailUser("impp.dev@sss.com");
mailConfig.setMailPassword("Aa135790s");
MailUtil mailUtil = new MailUtil();
try {
mailUtil.setTo("yunhao.wang@estsh.com");
mailUtil.setSubject("中文");
mailUtil.setBody("zhenw");
mailUtil.setSubject("title");
mailUtil.setContentType(ImppEnumUtil.MESSAGE_TYPE_CONTENT.HTML.getDescription());
mailUtil.setBody("内容");
try {
mailUtil.send();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (MessagingException e) {
mailUtil.init(mailConfig).send();
} catch (Exception e){
LOGGER.error(e.getCause()+"");
// LOGGER.error(e.);
e.printStackTrace();
}

Loading…
Cancel
Save