mirror of
https://github.com/dqjdda/Aurora.git
synced 2018-11-06 05:33:29 +00:00
邮件发送细节优化
This commit is contained in:
@@ -1,23 +1,16 @@
|
||||
package me.aurora.app.rest.system;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.aurora.annotation.Log;
|
||||
import me.aurora.repository.spec.LogSpec;
|
||||
import org.slf4j.Logger;
|
||||
import me.aurora.service.SysLogService;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -43,7 +36,7 @@ public class SysLogController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有日志s
|
||||
* 查询所有日志
|
||||
* @param username
|
||||
* @param method
|
||||
* @param operation
|
||||
@@ -60,7 +53,6 @@ public class SysLogController {
|
||||
@RequestParam(value = "location",required = false) String location,
|
||||
@RequestParam(value = "page",defaultValue = "1")Integer page,
|
||||
@RequestParam(value = "limit",defaultValue = "10")Integer limit){
|
||||
|
||||
log.warn("REST request to findAll Log");
|
||||
Sort sort = new Sort(Sort.Direction.DESC,"createTime");
|
||||
Pageable pageable = PageRequest.of(page-1,limit,sort);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class WeatherController {
|
||||
String data = HttpUtils.sendPost(AuroraConstant.MEIZU_WEATHER_URL, "cityIds=" + areaId);
|
||||
return ResponseEntity.ok(data);
|
||||
} catch (Exception e) {
|
||||
log.error("查询天气失败", e);
|
||||
log.error("查询天气失败", e.getMessage());
|
||||
return ResponseEntity.error("查询天气失败,请联系网站管理员!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import me.aurora.domain.vo.EmailVo;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
/**
|
||||
* @author 郑杰
|
||||
@@ -33,5 +34,6 @@ public interface EmailService {
|
||||
* @param emailVo
|
||||
* @param emailConfig
|
||||
*/
|
||||
@Async
|
||||
void send(EmailVo emailVo, EmailConfig emailConfig) throws Exception;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import me.aurora.service.EmailService;
|
||||
import me.aurora.util.EncryptHelper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author 郑杰
|
||||
@@ -35,6 +36,7 @@ public class EmailServiceImpl implements EmailService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public EmailConfig findById(Long id) {
|
||||
EmailConfig emailConfig = emailRepo.findById(id).get();
|
||||
return emailConfig;
|
||||
@@ -62,6 +64,13 @@ public class EmailServiceImpl implements EmailService {
|
||||
}
|
||||
//是否ssl方式发送
|
||||
account.setStartttlsEnable(emailConfig.getSslEnable());
|
||||
|
||||
String content = emailVo.getContent() + "<p style=\"text-align: right;\">\n" +
|
||||
" <span style=\"color: rgb(0, 112, 192);\"><br/></span>\n" +
|
||||
"</p>\n" +
|
||||
"<h4 style=\"text-align: right;\">\n" +
|
||||
" <span style=\"color: rgb(0, 112, 192);\">------邮件来自</span><a href=\"http://xiswl.xyz\" target=\"_blank\" style=\"text-decoration: underline;\"><span style=\"color: rgb(0, 112, 192);\">Aurora</span></a><span style=\"color: rgb(0, 112, 192); text-decoration: none;\"></span><span style=\"color: rgb(0, 112, 192);\">的测试</span>\n" +
|
||||
"</h4>";
|
||||
/**
|
||||
* 发送
|
||||
*/
|
||||
@@ -69,7 +78,7 @@ public class EmailServiceImpl implements EmailService {
|
||||
MailUtil.send(account,
|
||||
emailVo.getTos(),
|
||||
emailVo.getSubject(),
|
||||
emailVo.getContent(),
|
||||
content,
|
||||
emailVo.getIsHtml());
|
||||
}catch (Exception e){
|
||||
throw new AuroraException(HttpStatus.HTTP_INTERNAL_ERROR,e.getMessage());
|
||||
|
||||
@@ -64,6 +64,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Map getMenuInfo(MenuSpec menuSpec, Pageable pageable) {
|
||||
Page<Menu> menuPage = menuRepo.findAll(menuSpec,pageable);
|
||||
Page<MenuDTO> menuDTOS = menuPage.map(menuMapper::toDto);
|
||||
@@ -71,12 +72,14 @@ public class MenuServiceImpl implements MenuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<Menu> findAllMenus() {
|
||||
Integer level = 1;
|
||||
return menuRepo.findAllByLevel(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Menu findByPId(Integer pid) {
|
||||
Menu menu = menuRepo.findById(pid.longValue()).get();
|
||||
ValidationUtil.isNull(menu,"pid:"+pid+"is not find");
|
||||
@@ -128,6 +131,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Menu findById(Long id) {
|
||||
Menu menu = menuRepo.findById(id).get();
|
||||
ValidationUtil.isNull(menu,"id:"+id+"is not find");
|
||||
|
||||
@@ -49,6 +49,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Permission findById(Long id) {
|
||||
Permission permission = permissionRepo.findById(id).get();
|
||||
ValidationUtil.isNull(permission,"id:"+id+"is not find");
|
||||
@@ -78,6 +79,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<Permission> getAll() {
|
||||
return permissionRepo.findAll();
|
||||
}
|
||||
@@ -104,11 +106,13 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<Permission> findByPid(int pid) {
|
||||
return permissionRepo.findByPid(pid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<Permission> findByRoles(Set<Role> roles) {
|
||||
return permissionRepo.findByRoles(roles);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class PictureServiceImpl implements PictureService {
|
||||
private PictureMapper pictureMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Map getPictureInfo(PictureSpec pictureSpec, Pageable pageable) {
|
||||
Page<Picture> picturePage = pictureRepo.findAll(pictureSpec,pageable);
|
||||
Page<PictureDto> pictureDtos = picturePage.map(pictureMapper::toDto);
|
||||
@@ -90,6 +91,7 @@ public class PictureServiceImpl implements PictureService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Picture findById(Long id) {
|
||||
Picture picture = pictureRepo.findById(id).get();
|
||||
ValidationUtil.isNull(picture,"id:"+id+"is not find");
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -46,11 +48,13 @@ public class RoleServiceImpl implements RoleService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<Role> getAllRole() {
|
||||
return roleRepo.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Map getRoleInfo(RoleSpec roleSpec, Pageable pageable) {
|
||||
Page<Role> roles = roleRepo.findAll(roleSpec,pageable);
|
||||
Page<RoleDTO> roleDTOS = roles.map(roleMapper::toDto);
|
||||
@@ -67,6 +71,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Role findById(Long id) {
|
||||
Role role = roleRepo.findById(id).get();
|
||||
ValidationUtil.isNull(role,"id:"+id+"is not find");
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -37,6 +38,7 @@ public class SysLogServiceImpl implements SysLogService {
|
||||
private SysLogMapper sysLogMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Map getLogInfo(LogSpec logSpec, Pageable pageable) {
|
||||
Page<SysLog> sysLogPage = sysLogRepo.findAll(logSpec,pageable);
|
||||
Page<SysLogDTO> sysLogDTOS = sysLogPage.map(sysLogMapper::toDto);
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
@@ -44,6 +45,7 @@ public class UserServiceImpl implements UserService {
|
||||
private RoleService roleService;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public User findById(Long id) {
|
||||
User user = userRepo.findById(id).get();
|
||||
ValidationUtil.isNull(user,"id:"+id+"is not find");
|
||||
@@ -51,16 +53,19 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public User findByUsername(String userName) {
|
||||
return userRepo.findByUsername(userName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public User findByEmail(String email) {
|
||||
return userRepo.findByEmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Map getUsersInfo(UserSpec userSpec, Pageable pageable) {
|
||||
Page<User> users = userRepo.findAll(userSpec,pageable);
|
||||
List<UserDTO> userDTOS = new ArrayList<>();
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package me.aurora.service.query;
|
||||
|
||||
public class SysLogQueryService {
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package me.aurora.util;
|
||||
|
||||
/**
|
||||
* 常用接口
|
||||
* @author 郑杰
|
||||
* @date 2018/09/29 12:52:06
|
||||
* 常用接口
|
||||
*/
|
||||
public class AuroraConstant {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user