Skip to content

Commit

Permalink
refactor: 重构系统管理相关代码,规范化接口返回
Browse files Browse the repository at this point in the history
  • Loading branch information
moxi624 committed Oct 15, 2020
1 parent ccee016 commit d3fa07c
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String getList(@Validated({GetList.class}) @RequestBody LinkVO linkVO, Bi
// 参数校验
ThrowableUtils.checkParamArgument(result);
log.info("获取友链列表");
return ResultUtil.result(SysConf.SUCCESS, linkService.getPageList(linkVO));
return ResultUtil.successWithData(linkService.getPageList(linkVO));
}

@AvoidRepeatableCommit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String getList(@Validated({GetList.class}) @RequestBody SysDictDataVO sys
// 参数校验
ThrowableUtils.checkParamArgument(result);
log.info("获取字典数据列表");
return ResultUtil.result(SysConf.SUCCESS, sysDictDataService.getPageList(sysDictDataVO));
return ResultUtil.successWithData(sysDictDataService.getPageList(sysDictDataVO));
}

@AvoidRepeatableCommit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String getList(@Validated({GetList.class}) @RequestBody SysDictTypeVO sys
// 参数校验
ThrowableUtils.checkParamArgument(result);
log.info("获取字典类型列表");
return ResultUtil.result(SysConf.SUCCESS, sysDictTypeService.getPageList(sysDictTypeVO));
return ResultUtil.successWithData(sysDictTypeService.getPageList(sysDictTypeVO));
}

@AvoidRepeatableCommit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String getList(@Validated({GetList.class}) @RequestBody SysParamsVO SysPa
// 参数校验
ThrowableUtils.checkParamArgument(result);
log.info("获取参数配置列表");
return ResultUtil.result(SysConf.SUCCESS, sysParamsService.getPageList(SysParamsVO));
return ResultUtil.successWithData(sysParamsService.getPageList(SysParamsVO));
}

@AvoidRepeatableCommit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SystemConfigRestApi {
@ApiOperation(value = "获取系统配置", notes = "获取系统配置")
@GetMapping("/getSystemConfig")
public String getSystemConfig() {
return ResultUtil.result(SysConf.SUCCESS, systemConfigService.getConfig());
return ResultUtil.successWithData(systemConfigService.getConfig());
}

@AuthorityVerify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class SystemRestApi {
@ApiOperation(value = "获取我的信息", notes = "获取我的信息")
@GetMapping("/getMe")
public String getMe() {
return ResultUtil.result(SysConf.SUCCESS, adminService.getMe());
return ResultUtil.successWithData(adminService.getMe());
}

@AuthorityVerify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class WebConfigRestApi {
@ApiOperation(value = "获取网站配置", notes = "获取网站配置")
@GetMapping("/getWebConfig")
public String getWebConfig() {
return ResultUtil.result(SysConf.SUCCESS, webConfigService.getWebConfig());
return ResultUtil.successWithData(webConfigService.getWebConfig());
}

@AuthorityVerify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ public class MailListener {
@RabbitListener(queues = "mogu.email")
public void sendMail(Map<String, String> map) {
if (map != null) {
try {
sendMailUtils.sendEmail(
map.get("receiver"),
map.get("text")
);
} catch (MessagingException e) {
log.error("发送邮件失败!");
}
sendMailUtils.sendEmail(
map.get("receiver"),
map.get("text")
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,33 @@ public class SendMailUtils {
* @param receiver
* @param text
*/
public void sendEmail(String receiver, String text) throws MessagingException {
//创建一个复杂的消息邮件
MimeMessage mimeMessage = mailSender.createMimeMessage();
public void sendEmail(String receiver, String text) {
try{
//创建一个复杂的消息邮件
MimeMessage mimeMessage = mailSender.createMimeMessage();

//multipart:true
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
//multipart:true
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);

helper.setSubject("蘑菇博客");
helper.setSubject("蘑菇博客");

helper.setText(text, true);
//邮件接收人
helper.setTo(receiver);
helper.setText(text, true);
//邮件接收人
helper.setTo(receiver);

//邮件发送者
helper.setFrom(SENDER);
//邮件发送者
helper.setFrom(SENDER);

mailSender.send(mimeMessage);
mailSender.send(mimeMessage);

log.info("邮件发送成功");
/*添加邮件附件
String path = ""; //文件路径
String fileName = ""; //文件名
helper.addAttachment(fileName, new File(path));
*/
log.info("邮件发送成功");
/*添加邮件附件
String path = ""; //文件路径
String fileName = ""; //文件名
helper.addAttachment(fileName, new File(path));
*/
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public String login(@Validated({GetOne.class}) @RequestBody UserVO userVO, Bindi
if (!isOpenLoginType){
return ResultUtil.result(SysConf.ERROR, "后台未开启该登录方式!");
}

String userName = userVO.getUserName();
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.and(wrapper -> wrapper.eq(SQLConf.USER_NAME, userName).or().eq(SQLConf.EMAIL, userName));
Expand All @@ -82,11 +81,9 @@ public String login(@Validated({GetOne.class}) @RequestBody UserVO userVO, Bindi
if (user == null || EStatus.DISABLED == user.getStatus()) {
return ResultUtil.result(SysConf.ERROR, "用户不存在");
}

if (EStatus.FREEZE == user.getStatus()) {
return ResultUtil.result(SysConf.ERROR, "用户账号未激活");
}

if (StringUtils.isNotEmpty(user.getPassWord()) && user.getPassWord().equals(MD5Utils.string2MD5(userVO.getPassWord()))) {
// 更新登录信息
HttpServletRequest request = RequestHolder.getRequest();
Expand All @@ -107,7 +104,6 @@ public String login(@Validated({GetOne.class}) @RequestBody UserVO userVO, Bindi
}
// 生成token
String token = StringUtils.getUUID();

// 过滤密码
user.setPassWord("");
//将从数据库查询的数据缓存到redis中
Expand All @@ -123,6 +119,11 @@ public String login(@Validated({GetOne.class}) @RequestBody UserVO userVO, Bindi
@PostMapping("/register")
public String register(@Validated({Insert.class}) @RequestBody UserVO userVO, BindingResult result) {
ThrowableUtils.checkParamArgument(result);
// 判断是否开启登录方式
Boolean isOpenLoginType = webConfigService.isOpenLoginType(RedisConf.PASSWORD);
if (!isOpenLoginType){
return ResultUtil.result(SysConf.ERROR, "后台未开启注册功能!");
}
if (userVO.getUserName().length() < Constants.NUM_FIVE || userVO.getUserName().length() >= Constants.NUM_TWENTY || userVO.getPassWord().length() < Constants.NUM_FIVE || userVO.getPassWord().length() >= Constants.NUM_TWENTY) {
return ResultUtil.result(SysConf.ERROR, MessageConf.PARAM_INCORRECT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public String editAdmin(AdminVO adminVO) {
@Override
public String editMe(AdminVO adminVO) {
String adminUid = RequestHolder.getAdminUid();
if (StringUtils.isNotBlank(adminUid)) {
if (StringUtils.isEmpty(adminUid)) {
return ResultUtil.errorWithMessage(MessageConf.INVALID_TOKEN);
}
Admin admin = new Admin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class LinkServiceImpl extends SuperServiceImpl<LinkMapper, Link> implemen
private LinkMapper linkMapper;
@Autowired
private LinkService linkService;
@Autowired
@Resource
private PictureFeignClient pictureFeignClient;
@Autowired
private WebUtil webUtil;
Expand Down Expand Up @@ -92,7 +92,7 @@ public IPage<Link> getPageList(LinkVO linkVO) {
//获取图片
if (StringUtils.isNotEmpty(item.getFileUid())) {
List<String> pictureUidsTemp = StringUtils.changeStringToString(item.getFileUid(), Constants.SYMBOL_COMMA);
List<String> pictureListTemp = new ArrayList<String>();
List<String> pictureListTemp = new ArrayList<>();

pictureUidsTemp.forEach(picture -> {
pictureListTemp.add(pictureMap.get(picture));
Expand All @@ -118,7 +118,7 @@ public String addLink(LinkVO linkVO) {
link.setStatus(EStatus.ENABLE);
link.setUpdateTime(new Date());
link.insert();
return ResultUtil.result(SysConf.SUCCESS, MessageConf.INSERT_SUCCESS);
return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);
}

@Override
Expand All @@ -133,7 +133,7 @@ public String editLink(LinkVO linkVO) {
link.setFileUid(linkVO.getFileUid());
link.setUpdateTime(new Date());
link.updateById();
return ResultUtil.result(SysConf.SUCCESS, MessageConf.UPDATE_SUCCESS);
return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}

@Override
Expand All @@ -142,7 +142,7 @@ public String deleteLink(LinkVO linkVO) {
link.setStatus(EStatus.DISABLED);
link.setUpdateTime(new Date());
link.updateById();
return ResultUtil.result(SysConf.SUCCESS, MessageConf.DELETE_SUCCESS);
return ResultUtil.successWithMessage(MessageConf.DELETE_SUCCESS);
}

@Override
Expand All @@ -158,31 +158,31 @@ public String stickLink(LinkVO linkVO) {
List<Link> list = pageList.getRecords();
Link maxSort = list.get(0);
if (StringUtils.isEmpty(maxSort.getUid())) {
return ResultUtil.result(SysConf.ERROR, MessageConf.PARAM_INCORRECT);
return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
}
if (maxSort.getUid().equals(link.getUid())) {
return ResultUtil.result(SysConf.ERROR, MessageConf.OPERATION_FAIL);
return ResultUtil.errorWithMessage(MessageConf.OPERATION_FAIL);
}
Integer sortCount = maxSort.getSort() + 1;
link.setSort(sortCount);
link.setUpdateTime(new Date());
link.updateById();
return ResultUtil.result(SysConf.SUCCESS, MessageConf.OPERATION_SUCCESS);
return ResultUtil.successWithMessage(MessageConf.OPERATION_SUCCESS);
}

@Override
public String addLinkCount(String uid) {
if (StringUtils.isEmpty(uid)) {
return ResultUtil.result(SysConf.ERROR, MessageConf.PARAM_INCORRECT);
return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
}
Link link = linkService.getById(uid);
if (link != null) {
int count = link.getClickCount() + 1;
link.setClickCount(count);
link.updateById();
} else {
return ResultUtil.result(SysConf.ERROR, MessageConf.PARAM_INCORRECT);
return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
}
return ResultUtil.result(SysConf.SUCCESS, MessageConf.UPDATE_SUCCESS);
return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
Loading

0 comments on commit d3fa07c

Please sign in to comment.