merge
This commit is contained in:
@@ -13,7 +13,12 @@ import java.util.Date;
|
||||
@Data
|
||||
public class EmailModel {
|
||||
public EmailModel() {
|
||||
//默认值
|
||||
this.serverHost = "smtp.163.com";
|
||||
this.serverPort = 25;
|
||||
this.protocol = "smtp";
|
||||
this.auth = true;
|
||||
this.fromEmail="xwbing2009@163.com";
|
||||
this.password = "xwbing900417";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,8 +61,8 @@ public class EmailModel {
|
||||
* 邮件内容
|
||||
*/
|
||||
private String centent;
|
||||
/**
|
||||
* 邮件附件的文件名
|
||||
*/
|
||||
private String[] attachFileNames;
|
||||
// /**
|
||||
// * 邮件附件的文件名
|
||||
// */
|
||||
// private String[] attachFileNames;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
package com.xwbing.domain.entity.sys;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* 说明: 系统配置
|
||||
@@ -19,23 +14,23 @@ import javax.validation.constraints.Pattern;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Entity(name = "system_config")
|
||||
@ApiModel
|
||||
public class SysConfig extends BaseEntity {
|
||||
private static final long serialVersionUID = -7587016038432881980L;
|
||||
public static String table = "system_config";
|
||||
@NotBlank(message = "配置项的code不能为空")
|
||||
@Length(min = 1, max = 50, message = "code长度为1-50")
|
||||
@ApiModelProperty(value = "配置项的code", example = "email_config", required = true)
|
||||
/**
|
||||
* 配置项的code
|
||||
*/
|
||||
private String code;
|
||||
@NotBlank(message = "配置项的value不能为空")
|
||||
@ApiModelProperty(value = "配置项的值", example = "{}", required = true)
|
||||
/**
|
||||
* 配置项的值
|
||||
*/
|
||||
private String value;
|
||||
@NotBlank(message = "配置项的name不能为空")
|
||||
@Length(min = 1, max = 20, message = "value长度为1-20")
|
||||
@ApiModelProperty(value = "配置项的描述(名称)", example = "邮箱配置", required = true)
|
||||
/**
|
||||
* 配置项的描述(名称)
|
||||
*/
|
||||
private String name;
|
||||
@NotBlank(message = "是否启用不能为空")
|
||||
@Pattern(regexp = "[Y|N]", message = "是否启用格式为Y|N")
|
||||
@ApiModelProperty(value = "是否启用(Y|N)", example = "Y", required = true)
|
||||
/**
|
||||
* 是否启用(Y|N)
|
||||
*/
|
||||
private String enable;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.xwbing.service.sys;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.constant.CommonConstant;
|
||||
import com.xwbing.domain.entity.model.EmailModel;
|
||||
import com.xwbing.domain.entity.sys.SysConfig;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2018/4/10 17:58
|
||||
* 作者: xiangwb
|
||||
* 说明: 公共配置信息
|
||||
*/
|
||||
@Service
|
||||
public class CommonConfigService {
|
||||
@Resource
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
/**
|
||||
* 添加邮箱配置
|
||||
*
|
||||
* @param emailModel
|
||||
* @return
|
||||
*/
|
||||
public RestMessage saveOrUpdateEmail(EmailModel emailModel) {
|
||||
SysConfig sysConfig = sysConfigService.getByCode(CommonConstant.EMAIL_KEY);
|
||||
if (sysConfig == null) {
|
||||
sysConfig = new SysConfig();
|
||||
sysConfig.setName("邮箱配置");
|
||||
sysConfig.setCode(CommonConstant.EMAIL_KEY);
|
||||
sysConfig.setEnable(CommonConstant.IS_ENABLE);
|
||||
sysConfig.setValue(JSON.toJSONString(emailModel));
|
||||
return sysConfigService.save(sysConfig);
|
||||
} else {
|
||||
sysConfig.setValue(JSON.toJSONString(emailModel));
|
||||
return sysConfigService.update(sysConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取邮箱信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public EmailModel getEmail() {
|
||||
SysConfig sysConfig = sysConfigService.getByCode(CommonConstant.EMAIL_KEY);
|
||||
if (sysConfig == null) {
|
||||
return new EmailModel();
|
||||
} else {
|
||||
String value = sysConfig.getValue();
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return new EmailModel();
|
||||
} else {
|
||||
return JSONObject.parseObject(value, EmailModel.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.xwbing.service.sys;
|
||||
|
||||
import com.xwbing.domain.entity.sys.SysConfig;
|
||||
import com.xwbing.exception.BusinessException;
|
||||
import com.xwbing.domain.repository.sys.SysConfigRepository;
|
||||
import com.xwbing.exception.BusinessException;
|
||||
import com.xwbing.util.PassWordUtil;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@@ -34,8 +34,8 @@ public class EmailUtil {
|
||||
throw new UtilException("发送邮件主机不能为空");
|
||||
}
|
||||
String protocol = emailModel.getProtocol();
|
||||
if(protocol==null || "".equals(protocol.trim())){
|
||||
protocol="smtp";
|
||||
if (protocol == null || "".equals(protocol.trim())) {
|
||||
protocol = "smtp";
|
||||
}
|
||||
props.setProperty("mail.transport.protocol", protocol);// 使用的协议(JavaMail规范要求)
|
||||
props.setProperty("mail.smtp.host", serverHost); // 发件人的邮箱的
|
||||
@@ -83,8 +83,8 @@ public class EmailUtil {
|
||||
multipart.addBodyPart(html);
|
||||
message.setContent(multipart);
|
||||
Date sendTime = emailModel.getSendTime();
|
||||
if(sendTime==null){
|
||||
sendTime=new Date();
|
||||
if (sendTime == null) {
|
||||
sendTime = new Date();
|
||||
}
|
||||
message.setSentDate(sendTime);// 设置显示的发件时间
|
||||
message.saveChanges();// 保存邮件
|
||||
@@ -138,7 +138,7 @@ public class EmailUtil {
|
||||
// emailModel.setSendTime();默认当前时间
|
||||
emailModel.setFromEmail("xwbing2009@163.com");
|
||||
emailModel.setToEmail("786461501@qq.com,xiangwb@drore.com");
|
||||
emailModel.setAttachFileNames(null);
|
||||
// emailModel.setAttachFileNames(null);
|
||||
emailModel.setPassword("xwbing900417");
|
||||
emailModel.setSubject("测试邮件");
|
||||
emailModel.setCentent("邮件功能测试,请勿回复");
|
||||
|
||||
@@ -2,23 +2,16 @@ package com.xwbing.controller.sys;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.domain.entity.sys.SysConfig;
|
||||
import com.xwbing.domain.entity.vo.ListSysConfigVo;
|
||||
import com.xwbing.domain.entity.model.EmailModel;
|
||||
import com.xwbing.domain.entity.vo.RestMessageVo;
|
||||
import com.xwbing.domain.entity.vo.SysConfigVo;
|
||||
import com.xwbing.service.sys.SysConfigService;
|
||||
import com.xwbing.service.sys.CommonConfigService;
|
||||
import com.xwbing.util.JsonResult;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 说明: 系统配置控制层
|
||||
@@ -30,72 +23,22 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/config/")
|
||||
public class SysConfigControl {
|
||||
private final Logger logger = LoggerFactory.getLogger(SysConfigControl.class);
|
||||
@Resource
|
||||
private SysConfigService sysConfigService;
|
||||
private CommonConfigService commonConfigService;
|
||||
|
||||
@LogInfo("新增系统配置信息")
|
||||
@ApiOperation(value = "新增", notes = "新增系统配置信息", response = RestMessageVo.class)
|
||||
@PostMapping("save")
|
||||
public JSONObject save(@RequestBody @Valid SysConfig sysConfig) {
|
||||
String logMsg = "新增系统配置信息";
|
||||
logger.info(logMsg);
|
||||
RestMessage result = sysConfigService.save(sysConfig);
|
||||
return JsonResult.toJSONObj(result);
|
||||
@LogInfo("获取邮箱配置信息")
|
||||
@ApiOperation(value = "获取邮箱配置信息", response = RestMessageVo.class)
|
||||
@GetMapping("getEmail")
|
||||
public JSONObject getEmail() {
|
||||
EmailModel email = commonConfigService.getEmail();
|
||||
return JsonResult.toJSONObj(email, "");
|
||||
}
|
||||
|
||||
@LogInfo("根据code删除系统配置信息")
|
||||
@ApiOperation(value = "删除", notes = "根据code删除系统配置信息", response = RestMessageVo.class)
|
||||
@GetMapping("removeByCode")
|
||||
public JSONObject removeByCode(@RequestParam String code) {
|
||||
String logMsg = "删除系统配置信息";
|
||||
logger.info(logMsg + " code:{}", code);
|
||||
if (StringUtils.isEmpty(code)) {
|
||||
return JsonResult.toJSONObj("code不能为空");
|
||||
}
|
||||
RestMessage result = sysConfigService.removeByCode(code);
|
||||
return JsonResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
@LogInfo("修改系统配置信息")
|
||||
@ApiOperation(value = "修改", notes = "修改系统配置信息", response = RestMessageVo.class)
|
||||
@PostMapping("update")
|
||||
public JSONObject update(@RequestBody @Valid SysConfig sysConfig) {
|
||||
String logMsg = "修改系统配置信息";
|
||||
logger.info(logMsg);
|
||||
if (StringUtils.isEmpty(sysConfig.getCode())) {
|
||||
return JsonResult.toJSONObj("配置项的code不能为空");
|
||||
}
|
||||
RestMessage result = sysConfigService.update(sysConfig);
|
||||
return JsonResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
@LogInfo("根据key查找系统配置信息")
|
||||
@ApiOperation(value = "查找", notes = "根据key查找系统配置信息", response = SysConfigVo.class)
|
||||
@GetMapping("getByCode")
|
||||
public JSONObject getByCode(@RequestParam String code) {
|
||||
String logMsg = "根据code查找系统配置信息";
|
||||
logger.info(logMsg + " code:{}", code);
|
||||
if (StringUtils.isEmpty(code)) {
|
||||
return JsonResult.toJSONObj("code不能为空");
|
||||
}
|
||||
SysConfig one = sysConfigService.getByCode(code);
|
||||
if (one == null) {
|
||||
return JsonResult.toJSONObj("该配置不存在");
|
||||
}
|
||||
return JsonResult.toJSONObj(one, "");
|
||||
}
|
||||
|
||||
@LogInfo("根据是否启用查找配置列表")
|
||||
@ApiOperation(value = "查找列表", notes = "根据是否启用查找配置列表", response = ListSysConfigVo.class)
|
||||
@GetMapping("listByEnable")
|
||||
public JSONObject listByEnable(@RequestParam String enable) {
|
||||
String logMsg = "根据是否启用查找配置列表";
|
||||
logger.info(logMsg + " enable:{}", enable);
|
||||
if (StringUtils.isEmpty(enable)) {
|
||||
return JsonResult.toJSONObj("是否启用不能为空");
|
||||
}
|
||||
List<SysConfig> byEnable = sysConfigService.listByEnable(enable);
|
||||
return JsonResult.toJSONObj(byEnable, "");
|
||||
@LogInfo("添加修改邮箱配置信息")
|
||||
@ApiOperation(value = "添加修改邮箱配置信息", response = RestMessageVo.class)
|
||||
@PostMapping("saveOrUpdateEmail")
|
||||
public JSONObject saveOrUpdateEmail(@RequestBody EmailModel emailModel) {
|
||||
RestMessage restMessage = commonConfigService.saveOrUpdateEmail(emailModel);
|
||||
return JsonResult.toJSONObj(restMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user