Skip to content

Commit

Permalink
Merge pull request niefy#54 from niefy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
niefy committed Dec 20, 2020
2 parents 852c8c8 + e8d1d23 commit 0f2f443
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<aliyun.oss.version>3.9.1</aliyun.oss.version>
<qcloud.cos.version>5.6.24</qcloud.cos.version>
<swagger.version>3.0.0</swagger.version>
<fastjson.version>1.2.75</fastjson.version>
<fastjson.version>1.2.9</fastjson.version>
<lombok.version>1.18.16</lombok.version>
<weixin-java.version>4.0.0</weixin-java.version>
</properties>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/github/niefy/common/utils/IPUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public static String getIpAddr(HttpServletRequest request) {
String ip = null;
try {
ip = request.getHeader("x-forwarded-for");
if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
if (!StringUtils.hasText(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
if (!StringUtils.hasText(ip) || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
if (!StringUtils.hasText(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
if (!StringUtils.hasText(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
if (!StringUtils.hasText(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
} catch (Exception e) {
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/github/niefy/config/MybatisPlusConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.github.niefy.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -12,11 +15,18 @@
public class MybatisPlusConfig {

/**
* 分页插件
* 分页插件,一缓和二缓遵循mybatis的规则
*/
@Bean
public MybatisPlusInterceptor paginationInterceptor() {
return new MybatisPlusInterceptor();
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}

@Bean
public ConfigurationCustomizer configurationCustomizer() {
return configuration -> configuration.setUseDeprecatedExecutor(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public R getQuestions(String type,
if (articleType == null) {
return R.error("文章类型有误");
}
if (StringUtils.isEmpty(keywords)) {
if (!StringUtils.hasText(keywords)) {
return R.error("关键词不得为空");
}
List<Article> articles = articleService.search(articleType, category, keywords);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public R getShareSignature(HttpServletRequest request, HttpServletResponse respo
this.wxMpService.switchoverTo(appid);
// 1.拼接url(当前网页的URL,不包含#及其后面部分)
String wxShareUrl = request.getHeader(Constant.WX_CLIENT_HREF_HEADER);
if (StringUtils.isEmpty(wxShareUrl)) {
if (!StringUtils.hasText(wxShareUrl)) {
return R.error("header中缺少"+Constant.WX_CLIENT_HREF_HEADER+"参数,微信分享加载失败");
}
wxShareUrl = wxShareUrl.split("#")[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public WxUser(WxMpUser wxMpUser,String appid) {
this.tagidList=JSONArray.parseArray(JSONObject.toJSONString(wxMpUser.getTagIds()));
this.subscribeScene=wxMpUser.getSubscribeScene();
String qrScene = wxMpUser.getQrScene();
this.qrSceneStr= StringUtils.isEmpty(qrScene) ? wxMpUser.getQrSceneStr() : qrScene;
this.qrSceneStr= !StringUtils.hasText(qrScene) ? wxMpUser.getQrSceneStr() : qrScene;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> co

msgReplyService.tryAutoReply(appid, true, wxMessage.getFromUser(), wxMessage.getEvent());

if (!StringUtils.isEmpty(wxMessage.getEventKey())) {// 处理特殊事件,如用户扫描带参二维码关注
if (StringUtils.hasText(wxMessage.getEventKey())) {// 处理特殊事件,如用户扫描带参二维码关注
msgReplyService.tryAutoReply(appid, true, wxMessage.getFromUser(), wxMessage.getEventKey());
}
return null;
Expand All @@ -50,7 +50,7 @@ protected WxMpXmlOutMessage handleSpecial(WxMpXmlMessage wxMessage) {
String appid = WxMpConfigStorageHolder.get();
userService.refreshUserInfo(wxMessage.getFromUser(),appid);
msgReplyService.tryAutoReply(appid, true, wxMessage.getFromUser(), wxMessage.getEvent());
if (!StringUtils.isEmpty(wxMessage.getEventKey())) {
if (StringUtils.hasText(wxMessage.getEventKey())) {
msgReplyService.tryAutoReply(appid, true, wxMessage.getFromUser(), wxMessage.getEventKey());
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public PageUtils queryPage(Map<String, Object> params) {
new Query<Article>().getPage(params),
new QueryWrapper<Article>()
.select(LIST_FILEDS)
.eq(!StringUtils.isEmpty(type), "type", type)
.like(!StringUtils.isEmpty(category), "category", category)
.like(!StringUtils.isEmpty(subCategory), "sub_category", subCategory)
.like(!StringUtils.isEmpty(title), "title", title)
.eq(StringUtils.hasText(type), "type", type)
.like(StringUtils.hasText(category), "category", category)
.like(StringUtils.hasText(subCategory), "sub_category", subCategory)
.like(StringUtils.hasText(title), "title", title)
);

return new PageUtils(page);
Expand Down Expand Up @@ -114,7 +114,7 @@ public boolean save(Article article) {
@Override
public IPage<Article> getArticles(String title, int page) {
return this.page(new Page<Article>(page, PageSizeConstant.PAGE_SIZE_SMALL),
new QueryWrapper<Article>().like(!StringUtils.isEmpty("title"), "title", title)
new QueryWrapper<Article>().like(StringUtils.hasText("title"), "title", title)
.select(LIST_FILEDS)
.orderBy(true, false, "update_time"));
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public List<Article> search(ArticleTypeEnum articleType, String category, String
return this.list(new QueryWrapper<Article>()
.select(LIST_FILEDS)
.eq("type", articleType.getValue())
.eq(!StringUtils.isEmpty(category), "category", category)
.eq(StringUtils.hasText(category), "category", category)
.and(i -> i.like("summary", keywords).or().like("title", keywords)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public PageUtils queryPage(Map<String, Object> params) {
IPage<MsgReplyRule> page = this.page(
new Query<MsgReplyRule>().getPage(params),
new QueryWrapper<MsgReplyRule>()
.eq(!StringUtils.isEmpty(appid), "appid", appid)
.eq(StringUtils.hasText(appid), "appid", appid)
.or()
.apply("appid is null or appid = ''")
.like(!StringUtils.isEmpty(matchValue), "match_value", matchValue)
.like(StringUtils.hasText(matchValue), "match_value", matchValue)
.orderByDesc("update_time")
);

Expand Down Expand Up @@ -93,7 +93,7 @@ public List<MsgReplyRule> getValidRules() {
public List<MsgReplyRule> getMatchedRules(String appid, boolean exactMatch, String keywords) {
LocalTime now = LocalTime.now();
return this.getValidRules().stream()
.filter(rule->StringUtils.isEmpty(rule.getAppid()) || appid.equals(rule.getAppid())) // 检测是否是对应公众号的规则,如果appid为空则为通用规则
.filter(rule->!StringUtils.hasText(rule.getAppid()) || appid.equals(rule.getAppid())) // 检测是否是对应公众号的规则,如果appid为空则为通用规则
.filter(rule->null == rule.getEffectTimeStart() || rule.getEffectTimeStart().toLocalTime().isBefore(now))// 检测是否在有效时段,effectTimeStart为null则一直有效
.filter(rule->null == rule.getEffectTimeEnd() || rule.getEffectTimeEnd().toLocalTime().isAfter(now)) // 检测是否在有效时段,effectTimeEnd为null则一直有效
.filter(rule->isMatch(exactMatch || rule.isExactMatch(),rule.getMatchValue().split(","),keywords)) //检测是否符合匹配规则
Expand All @@ -111,7 +111,7 @@ public List<MsgReplyRule> getMatchedRules(String appid, boolean exactMatch, Stri
* @return
*/
public static boolean isMatch(boolean exactMatch, String[] ruleWords, String checkWords) {
if (StringUtils.isEmpty(checkWords)) {
if (!StringUtils.hasText(checkWords)) {
return false;
}
for (String words : ruleWords) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void replyMiniProgram(String toUser, String miniProgramInfoJson) throws W
@Override
public void replyMsgMenu(String toUser, String msgMenusJson) throws WxErrorException {
JSONObject json = JSON.parseObject(msgMenusJson);
List<WxMpKefuMessage.MsgMenu> msgMenus = json.getJSONArray("list").toJavaList(WxMpKefuMessage.MsgMenu.class);
List<WxMpKefuMessage.MsgMenu> msgMenus = JSON.parseArray(json.getString("list"),WxMpKefuMessage.MsgMenu.class);
wxMpService.getKefuService().sendKefuMessage(
WxMpKefuMessage.MSGMENU()
.toUser(toUser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public PageUtils queryPage(Map<String, Object> params) {
IPage<MsgTemplate> page = this.page(
new Query<MsgTemplate>().getPage(params),
new QueryWrapper<MsgTemplate>()
.eq(!StringUtils.isEmpty(appid), "appid", appid)
.like(!StringUtils.isEmpty(title), "title", title)
.like(!StringUtils.isEmpty(name), "name", name)
.eq(StringUtils.hasText(appid), "appid", appid)
.like(StringUtils.hasText(title), "title", title)
.like(StringUtils.hasText(name), "name", name)
);

return new PageUtils(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public PageUtils queryPage(Map<String, Object> params) {
IPage<TemplateMsgLog> page = this.page(
new Query<TemplateMsgLog>().getPage(params),
new QueryWrapper<TemplateMsgLog>()
.eq(!StringUtils.isEmpty(appid), "appid", appid)
.eq(StringUtils.hasText(appid), "appid", appid)
);

return new PageUtils(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PageUtils queryPage(Map<String, Object> params) {
IPage<WxAccount> page = this.page(
new Query<WxAccount>().getPage(params),
new QueryWrapper<WxAccount>()
.like(!StringUtils.isEmpty(name), "name", name)
.like(StringUtils.hasText(name), "name", name)
);

return new PageUtils(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.github.niefy.modules.wx.dao.WxMsgMapper;
import com.github.niefy.modules.wx.entity.WxMsg;
import com.github.niefy.modules.wx.service.WxMsgService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.Map;
Expand All @@ -28,10 +28,10 @@ public PageUtils queryPage(Map<String, Object> params) {
IPage<WxMsg> page = this.page(
new Query<WxMsg>().getPage(params),
new QueryWrapper<WxMsg>()
.eq(!org.springframework.util.StringUtils.isEmpty(appid), "appid", appid)
.in(StringUtils.isNotEmpty(msgTypes),"msg_type", Arrays.asList(msgTypes.split(",")))
.eq(StringUtils.isNotEmpty(openid),"openid",openid)
.ge(StringUtils.isNotEmpty(startTime),"create_time",startTime)
.eq(StringUtils.hasText(appid), "appid", appid)
.in(StringUtils.hasText(msgTypes),"msg_type", Arrays.asList(msgTypes.split(",")))
.eq(StringUtils.hasText(openid),"openid",openid)
.ge(StringUtils.hasText(startTime),"create_time",startTime)
);

return new PageUtils(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public PageUtils queryPage(Map<String, Object> params) {
IPage<WxQrCode> page = this.page(
new Query<WxQrCode>().getPage(params),
new QueryWrapper<WxQrCode>()
.eq(!StringUtils.isEmpty(appid), "appid", appid)
.like(!StringUtils.isEmpty(sceneStr), "scene_str", sceneStr)
.eq(StringUtils.hasText(appid), "appid", appid)
.like(StringUtils.hasText(sceneStr), "scene_str", sceneStr)
);

return new PageUtils(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public IPage<WxUser> queryPage(Map<String, Object> params) {
return this.page(
new Query<WxUser>().getPage(params),
new QueryWrapper<WxUser>()
.eq(!StringUtils.isEmpty(appid), "appid", appid)
.eq(!StringUtils.isEmpty(openid), "openid", openid)
.like(!StringUtils.isEmpty(nickname), "nickname", nickname)
.eq(!StringUtils.isEmpty(city), "city", city)
.eq(!StringUtils.isEmpty(qrSceneStr), "qrSceneStr", qrSceneStr)
.eq(StringUtils.hasText(appid), "appid", appid)
.eq(StringUtils.hasText(openid), "openid", openid)
.like(StringUtils.hasText(nickname), "nickname", nickname)
.eq(StringUtils.hasText(city), "city", city)
.eq(StringUtils.hasText(qrSceneStr), "qrSceneStr", qrSceneStr)
);
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public void syncWxUsers(String appid) {
List<String> openids = wxMpUserList.getOpenids();
this.syncWxUsers(openids,appid);
nextOpenid=wxMpUserList.getNextOpenid();
hasMore=!StringUtils.isEmpty(nextOpenid) && wxMpUserList.getCount()>=10000;
hasMore=StringUtils.hasText(nextOpenid) && wxMpUserList.getCount()>=10000;
}
} catch (WxErrorException e) {
logger.error("同步公众号粉丝出错:",e);
Expand Down

0 comments on commit 0f2f443

Please sign in to comment.