mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-06-25 14:37:40 +08:00
优化工具类的命名
This commit is contained in:
@@ -2,14 +2,13 @@ package com.mdd.front;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.enums.HttpEnum;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.utils.RedisUtil;
|
||||
import com.mdd.common.utils.StringUtil;
|
||||
import com.mdd.common.utils.YmlUtil;
|
||||
import com.mdd.common.util.RedisUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.YmlUtils;
|
||||
import com.mdd.front.config.FrontConfig;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -46,8 +45,8 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
||||
token = FrontConfig.frontendTokenKey + token;
|
||||
List<String> notLoginUri = Arrays.asList(FrontConfig.notLoginUri);
|
||||
if (notLoginUri.contains(request.getRequestURI())) {
|
||||
if (StringUtil.isNotEmpty(token)) {
|
||||
Object uid = RedisUtil.get(token);
|
||||
if (StringUtils.isNotEmpty(token)) {
|
||||
Object uid = RedisUtils.get(token);
|
||||
if (uid != null) {
|
||||
Integer userId = Integer.parseInt(uid.toString());
|
||||
LikeFrontThreadLocal.put("userId", userId);
|
||||
@@ -57,21 +56,21 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
// Token是否为空
|
||||
if (StringUtils.isBlank(token)) {
|
||||
if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(token)) {
|
||||
AjaxResult<Object> result = AjaxResult.failed(HttpEnum.TOKEN_EMPTY.getCode(), HttpEnum.TOKEN_EMPTY.getMsg());
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Token是否过期
|
||||
if (!RedisUtil.exists(token)) {
|
||||
if (!RedisUtils.exists(token)) {
|
||||
AjaxResult<Object> result = AjaxResult.failed(HttpEnum.TOKEN_INVALID.getCode(), HttpEnum.TOKEN_INVALID.getMsg());
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 用户信息缓存
|
||||
Object uid = RedisUtil.get(token);
|
||||
Object uid = RedisUtils.get(token);
|
||||
Integer userId = Integer.parseInt(uid.toString());
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,sn,username,nickname,mobile,is_disable,is_delete")
|
||||
@@ -93,10 +92,10 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
// 令牌自动续签
|
||||
int tokenRenewTime = Integer.parseInt(YmlUtil.get("like.token-renew-time"));
|
||||
if (RedisUtil.ttl(token) < tokenRenewTime) {
|
||||
long tokenValidTime = Long.parseLong(YmlUtil.get("like.token-valid-time"));
|
||||
RedisUtil.expire(token, tokenValidTime);
|
||||
int tokenRenewTime = Integer.parseInt(YmlUtils.get("like.token-renew-time"));
|
||||
if (RedisUtils.ttl(token) < tokenRenewTime) {
|
||||
long tokenValidTime = Long.parseLong(YmlUtils.get("like.token-valid-time"));
|
||||
RedisUtils.expire(token, tokenValidTime);
|
||||
}
|
||||
|
||||
// 写入本地线程
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.mdd.front.config;
|
||||
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
import com.mdd.common.utils.YmlUtil;
|
||||
import com.mdd.common.util.YmlUtils;
|
||||
import com.mdd.front.LikeFrontInterceptor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.lang.NonNull;
|
||||
@@ -43,7 +43,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
*/
|
||||
@Override
|
||||
public void addResourceHandlers(@NonNull ResourceHandlerRegistry registry) {
|
||||
String directory = YmlUtil.get("like.upload-directory");
|
||||
String directory = YmlUtils.get("like.upload-directory");
|
||||
registry.addResourceHandler("/"+ GlobalConfig.publicPrefix +"/**")
|
||||
.addResourceLocations("file:" + directory);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.system.SystemLogSmsMapper;
|
||||
import com.mdd.common.plugin.notice.NoticeDriver;
|
||||
import com.mdd.common.plugin.notice.NoticeParams;
|
||||
import com.mdd.common.utils.StringUtil;
|
||||
import com.mdd.common.utils.ToolsUtil;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.ToolsUtils;
|
||||
import com.mdd.front.validate.commons.SmsValidate;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -49,7 +49,7 @@ public class SmsController {
|
||||
.orderByDesc("id")
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtil.isNotNull(systemLogSms)) {
|
||||
if (StringUtils.isNotNull(systemLogSms)) {
|
||||
if (systemLogSms.getCreateTime() >= (System.currentTimeMillis() / 1000 - 60)){
|
||||
throw new OperateException("操作频繁,请稍后再试!");
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class SmsController {
|
||||
.setScene(smsValidate.getScene())
|
||||
.setMobile(smsValidate.getMobile())
|
||||
.setParams(new String[] {
|
||||
"code:" + ToolsUtil.randomInt(4)
|
||||
"code:" + ToolsUtils.randomInt(4)
|
||||
});
|
||||
|
||||
(new NoticeDriver()).handle(params);
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.mdd.common.enums.AlbumEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.plugin.storage.StorageDriver;
|
||||
import com.mdd.common.plugin.storage.UploadFilesVo;
|
||||
import com.mdd.common.utils.StringUtil;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -42,7 +42,7 @@ public class UploadController {
|
||||
}
|
||||
|
||||
String folder = "image";
|
||||
if (StringUtil.isNotEmpty(request.getParameter("dir"))) {
|
||||
if (StringUtils.isNotEmpty(request.getParameter("dir"))) {
|
||||
folder += "/" + request.getParameter("dir");
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import com.mdd.common.entity.article.ArticleCollect;
|
||||
import com.mdd.common.mapper.article.ArticleCategoryMapper;
|
||||
import com.mdd.common.mapper.article.ArticleCollectMapper;
|
||||
import com.mdd.common.mapper.article.ArticleMapper;
|
||||
import com.mdd.common.utils.StringUtil;
|
||||
import com.mdd.common.utils.TimeUtil;
|
||||
import com.mdd.common.utils.UrlUtil;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import com.mdd.common.util.UrlUtils;
|
||||
import com.mdd.front.service.IArticleService;
|
||||
import com.mdd.front.validate.commons.PageValidate;
|
||||
import com.mdd.front.vo.article.ArticleCateVo;
|
||||
@@ -101,8 +101,8 @@ public class ArticleServiceImpl implements IArticleService {
|
||||
ArticleListedVo vo = new ArticleListedVo();
|
||||
BeanUtils.copyProperties(article, vo);
|
||||
vo.setCollect(false);
|
||||
vo.setImage(UrlUtil.toAbsoluteUrl(article.getImage()));
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(article.getCreateTime()));
|
||||
vo.setImage(UrlUtils.toAbsoluteUrl(article.getImage()));
|
||||
vo.setCreateTime(TimeUtils.timestampToDate(article.getCreateTime()));
|
||||
list.add(vo);
|
||||
|
||||
ids.add(article.getId());
|
||||
@@ -156,8 +156,8 @@ public class ArticleServiceImpl implements IArticleService {
|
||||
ArticleDetailVo vo = new ArticleDetailVo();
|
||||
BeanUtils.copyProperties(article, vo);
|
||||
vo.setCollect(articleCollect != null);
|
||||
vo.setImage(UrlUtil.toAbsoluteUrl(article.getImage()));
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(article.getCreateTime()));
|
||||
vo.setImage(UrlUtils.toAbsoluteUrl(article.getImage()));
|
||||
vo.setCreateTime(TimeUtils.timestampToDate(article.getCreateTime()));
|
||||
|
||||
article.setVisit(article.getVisit() + 1);
|
||||
articleMapper.updateById(article);
|
||||
@@ -192,8 +192,8 @@ public class ArticleServiceImpl implements IArticleService {
|
||||
mpjQueryWrapper);
|
||||
|
||||
for (ArticleCollectVo vo : iPage.getRecords()) {
|
||||
vo.setImage(UrlUtil.toAbsoluteUrl(vo.getImage()));
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(vo.getCreateTime()));
|
||||
vo.setImage(UrlUtils.toAbsoluteUrl(vo.getImage()));
|
||||
vo.setCreateTime(TimeUtils.timestampToDate(vo.getCreateTime()));
|
||||
}
|
||||
|
||||
return PageResult.iPageHandle(iPage);
|
||||
@@ -214,7 +214,7 @@ public class ArticleServiceImpl implements IArticleService {
|
||||
.eq("user_id", userId)
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtil.isNotNull(articleCollect)) {
|
||||
if (StringUtils.isNotNull(articleCollect)) {
|
||||
articleCollect.setIsDelete(0);
|
||||
articleCollect.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
articleCollectMapper.updateById(articleCollect);
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.mdd.common.mapper.article.ArticleMapper;
|
||||
import com.mdd.common.mapper.DecoratePageMapper;
|
||||
import com.mdd.common.mapper.DecorateTabbarMapper;
|
||||
import com.mdd.common.mapper.setting.HotSearchMapper;
|
||||
import com.mdd.common.utils.*;
|
||||
import com.mdd.common.util.*;
|
||||
import com.mdd.front.service.IIndexService;
|
||||
import com.mdd.front.validate.commons.PageValidate;
|
||||
import com.mdd.front.vo.article.ArticleListedVo;
|
||||
@@ -69,14 +69,14 @@ public class IndexServiceImpl implements IIndexService {
|
||||
map.put("title", article.getTitle());
|
||||
map.put("intro", article.getIntro());
|
||||
map.put("summary", article.getSummary());
|
||||
map.put("image", UrlUtil.toAbsoluteUrl(article.getImage()));
|
||||
map.put("image", UrlUtils.toAbsoluteUrl(article.getImage()));
|
||||
map.put("author", article.getAuthor());
|
||||
map.put("visit", article.getVisit());
|
||||
map.put("createTime", TimeUtil.timestampToDate(article.getCreateTime()));
|
||||
map.put("createTime", TimeUtils.timestampToDate(article.getCreateTime()));
|
||||
articleList.add(map);
|
||||
}
|
||||
|
||||
response.put("domain", UrlUtil.domain());
|
||||
response.put("domain", UrlUtils.domain());
|
||||
response.put("pages", decoratePage.getPageData());
|
||||
response.put("article", articleList);
|
||||
return response;
|
||||
@@ -121,42 +121,42 @@ public class IndexServiceImpl implements IIndexService {
|
||||
for (DecorateTabbar tab: decorateTabbars) {
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("name", tab.getName());
|
||||
map.put("selected", UrlUtil.toAbsoluteUrl(tab.getSelected()));
|
||||
map.put("unselected", UrlUtil.toAbsoluteUrl(tab.getUnselected()));
|
||||
map.put("selected", UrlUtils.toAbsoluteUrl(tab.getSelected()));
|
||||
map.put("unselected", UrlUtils.toAbsoluteUrl(tab.getUnselected()));
|
||||
map.put("link", tab.getLink());
|
||||
tabs.add(map);
|
||||
}
|
||||
|
||||
// 导航颜色
|
||||
String tabbarStyle = ConfigUtil.get("tabbar", "style", "{}");
|
||||
String tabbarStyle = ConfigUtils.get("tabbar", "style", "{}");
|
||||
|
||||
// 登录配置
|
||||
Map<String, Object> loginMap = new LinkedHashMap<>();
|
||||
Map<String, String> loginConfig = ConfigUtil.get("login");
|
||||
loginMap.put("loginWay", ArrayUtil.stringToListAsInt(loginConfig.getOrDefault("loginWay", ""), ","));
|
||||
Map<String, String> loginConfig = ConfigUtils.get("login");
|
||||
loginMap.put("loginWay", ArrayUtils.stringToListAsInt(loginConfig.getOrDefault("loginWay", ""), ","));
|
||||
loginMap.put("forceBindMobile", Integer.parseInt(loginConfig.getOrDefault("forceBindMobile", "0")));
|
||||
loginMap.put("openAgreement", Integer.parseInt(loginConfig.getOrDefault("openAgreement", "0")));
|
||||
loginMap.put("openOtherAuth", Integer.parseInt(loginConfig.getOrDefault("openOtherAuth", "0")));
|
||||
loginMap.put("autoLoginAuth", ArrayUtil.stringToListAsInt(loginConfig.getOrDefault("autoLoginAuth", ""), ","));
|
||||
loginMap.put("autoLoginAuth", ArrayUtils.stringToListAsInt(loginConfig.getOrDefault("autoLoginAuth", ""), ","));
|
||||
|
||||
// 网址信息
|
||||
Map<String, Object> websiteMap = new LinkedHashMap<>();
|
||||
Map<String, String> websiteConfig = ConfigUtil.get("website");
|
||||
Map<String, String> websiteConfig = ConfigUtils.get("website");
|
||||
websiteMap.put("name", websiteConfig.getOrDefault("shopName", "LikeAdmin"));
|
||||
websiteMap.put("logo", UrlUtil.toAbsoluteUrl(websiteConfig.getOrDefault("shopLogo", "")));
|
||||
websiteMap.put("logo", UrlUtils.toAbsoluteUrl(websiteConfig.getOrDefault("shopLogo", "")));
|
||||
|
||||
// H5配置
|
||||
Map<String, Object> h5Map = new LinkedHashMap<>();
|
||||
Map<String, String> h5Config = ConfigUtil.get("h5_channel");
|
||||
Map<String, String> h5Config = ConfigUtils.get("h5_channel");
|
||||
h5Map.put("status", Integer.parseInt(h5Config.getOrDefault("status", "0")));
|
||||
h5Map.put("close", Integer.parseInt(h5Config.getOrDefault("close", "0")));
|
||||
h5Map.put("url", h5Config.getOrDefault("url", "0"));
|
||||
h5Map.put("accessLink", RequestUtil.uri());
|
||||
h5Map.put("accessLink", RequestUtils.uri());
|
||||
|
||||
// 响应数据
|
||||
response.put("version", GlobalConfig.version);
|
||||
response.put("domain", UrlUtil.domain());
|
||||
response.put("style", ToolsUtil.jsonToMap(tabbarStyle));
|
||||
response.put("domain", UrlUtils.domain());
|
||||
response.put("style", ToolsUtils.jsonToMap(tabbarStyle));
|
||||
response.put("tabbar", tabs);
|
||||
response.put("login", loginMap);
|
||||
response.put("website", websiteMap);
|
||||
@@ -173,7 +173,7 @@ public class IndexServiceImpl implements IIndexService {
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> policy(String type) {
|
||||
Map<String, String> map = ConfigUtil.getMap("protocol", type);
|
||||
Map<String, String> map = ConfigUtils.getMap("protocol", type);
|
||||
if (map == null) {
|
||||
Map<String, String> m = new LinkedHashMap<>();
|
||||
m.put("name", "");
|
||||
@@ -191,7 +191,7 @@ public class IndexServiceImpl implements IIndexService {
|
||||
*/
|
||||
@Override
|
||||
public List<String> hotSearch() {
|
||||
String isHotSearch = ConfigUtil.get("search", "isHotSearch", "0");
|
||||
String isHotSearch = ConfigUtils.get("search", "isHotSearch", "0");
|
||||
|
||||
List<String> list = new LinkedList<>();
|
||||
if (Integer.parseInt(isHotSearch) == 1) {
|
||||
@@ -234,8 +234,8 @@ public class IndexServiceImpl implements IIndexService {
|
||||
|
||||
for (ArticleListedVo vo : iPage.getRecords()) {
|
||||
vo.setCollect(false);
|
||||
vo.setImage(UrlUtil.toAbsoluteUrl(vo.getImage()));
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(vo.getCreateTime()));
|
||||
vo.setImage(UrlUtils.toAbsoluteUrl(vo.getImage()));
|
||||
vo.setCreateTime(TimeUtils.timestampToDate(vo.getCreateTime()));
|
||||
}
|
||||
|
||||
return PageResult.iPageHandle(iPage);
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.user.UserAuthMapper;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.utils.*;
|
||||
import com.mdd.common.util.*;
|
||||
import com.mdd.front.config.FrontConfig;
|
||||
import com.mdd.front.service.ILoginService;
|
||||
import com.mdd.front.validate.UserRegisterValidate;
|
||||
@@ -59,8 +59,8 @@ public class LoginServiceImpl implements ILoginService {
|
||||
Assert.isNull(model, "账号已存在,换一个吧!");
|
||||
|
||||
Integer sn = this.randMakeSn();
|
||||
String salt = ToolsUtil.randomString(5);
|
||||
String pwd = ToolsUtil.makeMd5(userRegisterValidate.getPassword()+salt);
|
||||
String salt = ToolsUtils.randomString(5);
|
||||
String pwd = ToolsUtils.makeMd5(userRegisterValidate.getPassword()+salt);
|
||||
|
||||
User user = new User();
|
||||
user.setSn(sn);
|
||||
@@ -93,7 +93,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
Integer client = Integer.parseInt(params.getOrDefault("client", "1"));
|
||||
|
||||
try {
|
||||
WxMaService wxMaService = WeChatUtil.mnp();
|
||||
WxMaService wxMaService = WeChatUtils.mnp();
|
||||
WxMaJscode2SessionResult sessionResult = wxMaService.getUserService().getSessionInfo(code);
|
||||
String openId = sessionResult.getOpenid();
|
||||
String uniId = sessionResult.getUnionid();
|
||||
@@ -107,14 +107,14 @@ public class LoginServiceImpl implements ILoginService {
|
||||
|
||||
User user = null;
|
||||
Integer userId;
|
||||
if (StringUtil.isNotNull(userAuth)) {
|
||||
if (StringUtils.isNotNull(userAuth)) {
|
||||
user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.eq("id", userAuth.getUserId())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
if (StringUtil.isNull(user)) {
|
||||
if (StringUtils.isNull(user)) {
|
||||
Integer sn = this.randMakeSn();
|
||||
User model = new User();
|
||||
model.setSn(sn);
|
||||
@@ -123,7 +123,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
model.setUsername("u"+sn);
|
||||
model.setSex(Integer.parseInt(gender));
|
||||
model.setChannel(client);
|
||||
model.setLastLoginIp(IpUtil.getHostIp());
|
||||
model.setLastLoginIp(IpUtils.getHostIp());
|
||||
model.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
model.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
@@ -131,7 +131,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
user = model;
|
||||
userId = model.getId();
|
||||
|
||||
if (StringUtil.isNull(userAuth)) {
|
||||
if (StringUtils.isNull(userAuth)) {
|
||||
UserAuth auth = new UserAuth();
|
||||
auth.setUserId(model.getId());
|
||||
auth.setOpenid(openId);
|
||||
@@ -144,27 +144,27 @@ public class LoginServiceImpl implements ILoginService {
|
||||
} else {
|
||||
// 更新微信标识
|
||||
userId = user.getId();
|
||||
if (StringUtil.isEmpty(userAuth.getUnionid()) && StringUtil.isNotEmpty(sessionResult.getUnionid())) {
|
||||
if (StringUtils.isEmpty(userAuth.getUnionid()) && StringUtils.isNotEmpty(sessionResult.getUnionid())) {
|
||||
userAuth.setUnionid(sessionResult.getUnionid());
|
||||
userAuthMapper.updateById(userAuth);
|
||||
}
|
||||
|
||||
// 更新用户信息
|
||||
if (StringUtil.isEmpty(user.getAvatar()) && StringUtil.isNotEmpty(avatarUrl)) {
|
||||
if (StringUtils.isEmpty(user.getAvatar()) && StringUtils.isNotEmpty(avatarUrl)) {
|
||||
user.setAvatar(avatarUrl);
|
||||
user.setNickname(nickName);
|
||||
user.setSex(Integer.parseInt(gender));
|
||||
}
|
||||
|
||||
// 更新登录信息
|
||||
user.setLastLoginIp(IpUtil.getHostIp());
|
||||
user.setLastLoginIp(IpUtils.getHostIp());
|
||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
String token = ToolsUtil.makeToken();
|
||||
int tokenValidTime = Integer.parseInt(YmlUtil.get("like.token-valid-time"));
|
||||
RedisUtil.set(FrontConfig.frontendTokenKey+token, userId, tokenValidTime);
|
||||
String token = ToolsUtils.makeToken();
|
||||
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"));
|
||||
RedisUtils.set(FrontConfig.frontendTokenKey+token, userId, tokenValidTime);
|
||||
|
||||
LoginTokenVo vo = new LoginTokenVo();
|
||||
vo.setId(userId);
|
||||
@@ -192,13 +192,13 @@ public class LoginServiceImpl implements ILoginService {
|
||||
|
||||
// 校验验证码
|
||||
int typeCode = NoticeEnum.SMS_LOGIN_CODE.getCode();
|
||||
Object smsCode = RedisUtil.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtil.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
Object smsCode = RedisUtils.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtils.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
// 删除验证码
|
||||
RedisUtil.del(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
RedisUtils.del(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
|
||||
// 查询手机号
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
@@ -211,13 +211,13 @@ public class LoginServiceImpl implements ILoginService {
|
||||
Assert.isFalse(user.getIsDisable() != 0, "账号已禁用!");
|
||||
|
||||
// 更新登录信息
|
||||
user.setLastLoginIp(IpUtil.getHostIp());
|
||||
user.setLastLoginIp(IpUtils.getHostIp());
|
||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(user);
|
||||
|
||||
String token = ToolsUtil.makeToken();
|
||||
int tokenValidTime = Integer.parseInt(YmlUtil.get("like.token-valid-time"));
|
||||
RedisUtil.set(FrontConfig.frontendTokenKey+token, user.getId(), tokenValidTime);
|
||||
String token = ToolsUtils.makeToken();
|
||||
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"));
|
||||
RedisUtils.set(FrontConfig.frontendTokenKey+token, user.getId(), tokenValidTime);
|
||||
|
||||
LoginTokenVo vo = new LoginTokenVo();
|
||||
vo.setId(user.getId());
|
||||
@@ -247,18 +247,18 @@ public class LoginServiceImpl implements ILoginService {
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(user, "账号不存在!");
|
||||
String pwd = ToolsUtil.makeMd5(password+user.getSalt());
|
||||
String pwd = ToolsUtils.makeMd5(password+user.getSalt());
|
||||
Assert.isFalse(!pwd.equals(user.getPassword()), "账号或密码错误!");
|
||||
Assert.isFalse(user.getIsDisable() != 0, "账号已被禁用!");
|
||||
|
||||
// 更新登录信息
|
||||
user.setLastLoginIp(IpUtil.getHostIp());
|
||||
user.setLastLoginIp(IpUtils.getHostIp());
|
||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(user);
|
||||
|
||||
String token = ToolsUtil.makeToken();
|
||||
int tokenValidTime = Integer.parseInt(YmlUtil.get("like.token-valid-time"))+1;
|
||||
RedisUtil.set(FrontConfig.frontendTokenKey+token, user.getId(), tokenValidTime-1);
|
||||
String token = ToolsUtils.makeToken();
|
||||
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"))+1;
|
||||
RedisUtils.set(FrontConfig.frontendTokenKey+token, user.getId(), tokenValidTime-1);
|
||||
|
||||
LoginTokenVo vo = new LoginTokenVo();
|
||||
vo.setId(user.getId());
|
||||
@@ -279,7 +279,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
String code = params.get("code");
|
||||
|
||||
try {
|
||||
WxMpService wxMpService = WeChatUtil.official();
|
||||
WxMpService wxMpService = WeChatUtils.official();
|
||||
WxOAuth2AccessToken wxOAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(code);
|
||||
String uniId = wxOAuth2AccessToken.getUnionId();
|
||||
String openId = wxOAuth2AccessToken.getOpenId();
|
||||
@@ -293,14 +293,14 @@ public class LoginServiceImpl implements ILoginService {
|
||||
|
||||
Integer userId;
|
||||
User user = null;
|
||||
if (StringUtil.isNotNull(userAuth)) {
|
||||
if (StringUtils.isNotNull(userAuth)) {
|
||||
user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.eq("is_delete", 0)
|
||||
.eq("id", userAuth.getUserId())
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
if (StringUtil.isNull(user)) {
|
||||
if (StringUtils.isNull(user)) {
|
||||
Integer sn = this.randMakeSn();
|
||||
User model = new User();
|
||||
model.setSn(sn);
|
||||
@@ -309,7 +309,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
model.setUsername("u"+sn);
|
||||
model.setChannel(ClientEnum.OA.getCode());
|
||||
model.setSex(0);
|
||||
model.setLastLoginIp(IpUtil.getHostIp());
|
||||
model.setLastLoginIp(IpUtils.getHostIp());
|
||||
model.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
model.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
@@ -317,7 +317,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
userId = model.getId();
|
||||
user = model;
|
||||
|
||||
if (StringUtil.isNull(userAuth)) {
|
||||
if (StringUtils.isNull(userAuth)) {
|
||||
UserAuth auth = new UserAuth();
|
||||
auth.setUserId(model.getId());
|
||||
auth.setUnionid(unionId);
|
||||
@@ -330,20 +330,20 @@ public class LoginServiceImpl implements ILoginService {
|
||||
} else {
|
||||
// 更新微信标识
|
||||
userId = user.getId();
|
||||
if (StringUtil.isEmpty(userAuth.getUnionid()) && StringUtil.isNotEmpty(unionId)) {
|
||||
if (StringUtils.isEmpty(userAuth.getUnionid()) && StringUtils.isNotEmpty(unionId)) {
|
||||
userAuth.setUnionid(unionId);
|
||||
userAuthMapper.updateById(userAuth);
|
||||
}
|
||||
|
||||
// 更新登录信息
|
||||
user.setLastLoginIp(IpUtil.getHostIp());
|
||||
user.setLastLoginIp(IpUtils.getHostIp());
|
||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
String token = ToolsUtil.makeToken();
|
||||
int tokenValidTime = Integer.parseInt(YmlUtil.get("like.token-valid-time"))+1;
|
||||
RedisUtil.set(FrontConfig.frontendTokenKey+token, userId, tokenValidTime-1);
|
||||
String token = ToolsUtils.makeToken();
|
||||
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"))+1;
|
||||
RedisUtils.set(FrontConfig.frontendTokenKey+token, userId, tokenValidTime-1);
|
||||
|
||||
LoginTokenVo vo = new LoginTokenVo();
|
||||
vo.setId(user.getId());
|
||||
@@ -364,7 +364,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
*/
|
||||
@Override
|
||||
public String codeUrl(String url) {
|
||||
WxMpService wxMpService = WeChatUtil.official();
|
||||
WxMpService wxMpService = WeChatUtils.official();
|
||||
WxMpOAuth2ServiceImpl wxMpOAuth2Service = new WxMpOAuth2ServiceImpl(wxMpService);
|
||||
return wxMpOAuth2Service.buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
|
||||
}
|
||||
@@ -386,13 +386,13 @@ public class LoginServiceImpl implements ILoginService {
|
||||
|
||||
// 校验验证码
|
||||
int typeCode = NoticeEnum.SMS_FORGOT_PASSWORD_CODE.getCode();
|
||||
Object smsCode = RedisUtil.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtil.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
Object smsCode = RedisUtils.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtils.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
// 删除验证码
|
||||
RedisUtil.del(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
RedisUtils.del(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
|
||||
// 查询手机号
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
@@ -404,8 +404,8 @@ public class LoginServiceImpl implements ILoginService {
|
||||
// 验证账号
|
||||
Assert.notNull(user, "账号不存在!");
|
||||
|
||||
String salt = ToolsUtil.randomString(5);
|
||||
String pwd = ToolsUtil.makeMd5(password.trim()+salt);
|
||||
String salt = ToolsUtils.randomString(5);
|
||||
String pwd = ToolsUtils.makeMd5(password.trim()+salt);
|
||||
|
||||
// 更新密码
|
||||
user.setPassword(pwd);
|
||||
@@ -423,7 +423,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
private Integer randMakeSn() {
|
||||
Integer sn;
|
||||
while (true) {
|
||||
sn = Integer.parseInt(ToolsUtil.randomInt(8));
|
||||
sn = Integer.parseInt(ToolsUtils.randomInt(8));
|
||||
User snModel = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,sn,username")
|
||||
.eq("sn", sn)
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.user.UserAuthMapper;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.utils.*;
|
||||
import com.mdd.common.util.*;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
import com.mdd.front.service.IUserService;
|
||||
import com.mdd.front.validate.UserBindMobileValidate;
|
||||
@@ -57,10 +57,10 @@ public class UserServiceImpl implements IUserService {
|
||||
UserCenterVo vo = new UserCenterVo();
|
||||
BeanUtils.copyProperties(user, vo);
|
||||
if (user.getAvatar().equals("")) {
|
||||
String avatar = ConfigUtil.get("user", "defaultAvatar", "");
|
||||
vo.setAvatar(UrlUtil.toAbsoluteUrl(avatar));
|
||||
String avatar = ConfigUtils.get("user", "defaultAvatar", "");
|
||||
vo.setAvatar(UrlUtils.toAbsoluteUrl(avatar));
|
||||
} else {
|
||||
vo.setAvatar(UrlUtil.toAbsoluteUrl(user.getAvatar()));
|
||||
vo.setAvatar(UrlUtils.toAbsoluteUrl(user.getAvatar()));
|
||||
}
|
||||
|
||||
return vo;
|
||||
@@ -92,13 +92,13 @@ public class UserServiceImpl implements IUserService {
|
||||
vo.setIsBindMnp(userAuth != null);
|
||||
vo.setVersion(GlobalConfig.version);
|
||||
vo.setSex(user.getSex());
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(user.getCreateTime()));
|
||||
vo.setCreateTime(TimeUtils.timestampToDate(user.getCreateTime()));
|
||||
|
||||
if (!user.getAvatar().equals("")) {
|
||||
vo.setAvatar(UrlUtil.toAbsoluteUrl(user.getAvatar()));
|
||||
vo.setAvatar(UrlUtils.toAbsoluteUrl(user.getAvatar()));
|
||||
} else {
|
||||
String avatar = ConfigUtil.get("user", "defaultAvatar", "");
|
||||
vo.setAvatar(UrlUtil.toAbsoluteUrl(avatar));
|
||||
String avatar = ConfigUtils.get("user", "defaultAvatar", "");
|
||||
vo.setAvatar(UrlUtils.toAbsoluteUrl(avatar));
|
||||
}
|
||||
|
||||
return vo;
|
||||
@@ -120,7 +120,7 @@ public class UserServiceImpl implements IUserService {
|
||||
case "avatar":
|
||||
User avatarUser = new User();
|
||||
avatarUser.setId(userId);
|
||||
avatarUser.setAvatar(UrlUtil.toRelativeUrl(value));
|
||||
avatarUser.setAvatar(UrlUtils.toRelativeUrl(value));
|
||||
avatarUser.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(avatarUser);
|
||||
break;
|
||||
@@ -131,11 +131,11 @@ public class UserServiceImpl implements IUserService {
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtil.isNotNull(usernameUser) && !usernameUser.getId().equals(userId)) {
|
||||
if (StringUtils.isNotNull(usernameUser) && !usernameUser.getId().equals(userId)) {
|
||||
throw new OperateException("账号已被使用!");
|
||||
}
|
||||
|
||||
if (StringUtil.isNotNull(usernameUser) && usernameUser.getUsername().equals(value)) {
|
||||
if (StringUtils.isNotNull(usernameUser) && usernameUser.getUsername().equals(value)) {
|
||||
throw new OperateException("新账号与旧账号一致,修改失败!");
|
||||
}
|
||||
|
||||
@@ -183,14 +183,14 @@ public class UserServiceImpl implements IUserService {
|
||||
|
||||
if (!user.getPassword().equals("")) {
|
||||
Assert.notNull(oldPassword, "oldPassword参数缺失");
|
||||
String oldPwd = ToolsUtil.makeMd5(oldPassword.trim() + user.getSalt());
|
||||
String oldPwd = ToolsUtils.makeMd5(oldPassword.trim() + user.getSalt());
|
||||
if (!oldPwd.equals(user.getPassword())) {
|
||||
throw new OperateException("原密码不正确!");
|
||||
}
|
||||
}
|
||||
|
||||
String salt = ToolsUtil.randomString(5);
|
||||
String pwd = ToolsUtil.makeMd5(password.trim()+salt);
|
||||
String salt = ToolsUtils.randomString(5);
|
||||
String pwd = ToolsUtils.makeMd5(password.trim()+salt);
|
||||
|
||||
User u = new User();
|
||||
u.setId(userId);
|
||||
@@ -215,8 +215,8 @@ public class UserServiceImpl implements IUserService {
|
||||
|
||||
// 校验验证码
|
||||
int typeCode = type.equals("bind") ? NoticeEnum.SMS_BIND_MOBILE_CODE.getCode() : NoticeEnum.SMS_CHANGE_MOBILE_CODE.getCode() ;
|
||||
Object smsCode = RedisUtil.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtil.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
Object smsCode = RedisUtils.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtils.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public class UserServiceImpl implements IUserService {
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtil.isNotNull(user) && user.getId().equals(userId)) {
|
||||
if (StringUtils.isNotNull(user) && user.getId().equals(userId)) {
|
||||
throw new OperateException("手机号已被其它账号绑定!");
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ public class UserServiceImpl implements IUserService {
|
||||
*/
|
||||
@Override
|
||||
public void mnpMobile(String code) {
|
||||
Map<String, String> config = ConfigUtil.get("mp_channel");
|
||||
Map<String, String> config = ConfigUtils.get("mp_channel");
|
||||
WxMaService wxMaService = new WxMaServiceImpl();
|
||||
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
|
||||
wxConfig.setSecret(config.getOrDefault("appSecret", ""));
|
||||
|
||||
Reference in New Issue
Block a user