mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
:art:简化代码
This commit is contained in:
parent
d4bc91a102
commit
49d73f003f
@ -5,7 +5,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
|
|||||||
import cn.binarywang.wx.miniapp.bean.cloud.*;
|
import cn.binarywang.wx.miniapp.bean.cloud.*;
|
||||||
import cn.binarywang.wx.miniapp.bean.cloud.request.WxCloudSendSmsV2Request;
|
import cn.binarywang.wx.miniapp.bean.cloud.request.WxCloudSendSmsV2Request;
|
||||||
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
|
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
|
||||||
import cn.binarywang.wx.miniapp.util.JoinerUtils;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
@ -37,6 +37,8 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Cloud.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WxMaCloudServiceImpl implements WxMaCloudService {
|
public class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||||
|
private static final Joiner blankJoiner = Joiner.on("").skipNulls();
|
||||||
|
|
||||||
private final WxMaService wxMaService;
|
private final WxMaService wxMaService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,7 +57,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
|||||||
@Override
|
@Override
|
||||||
public List<String> add(String collection, List list) throws WxErrorException {
|
public List<String> add(String collection, List list) throws WxErrorException {
|
||||||
String jsonData = WxMaGsonBuilder.create().toJson(list);
|
String jsonData = WxMaGsonBuilder.create().toJson(list);
|
||||||
String query = JoinerUtils.blankJoiner.join(
|
String query = blankJoiner.join(
|
||||||
"db.collection('", collection, "')",
|
"db.collection('", collection, "')",
|
||||||
".add({data: ", jsonData, "})");
|
".add({data: ", jsonData, "})");
|
||||||
|
|
||||||
@ -79,7 +81,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
|||||||
@Override
|
@Override
|
||||||
public String add(String collection, Object obj) throws WxErrorException {
|
public String add(String collection, Object obj) throws WxErrorException {
|
||||||
String jsonData = WxMaGsonBuilder.create().toJson(obj);
|
String jsonData = WxMaGsonBuilder.create().toJson(obj);
|
||||||
String query = JoinerUtils.blankJoiner.join(
|
String query = blankJoiner.join(
|
||||||
"db.collection('", collection, "')",
|
"db.collection('", collection, "')",
|
||||||
".add({data: ", jsonData, "})");
|
".add({data: ", jsonData, "})");
|
||||||
|
|
||||||
@ -110,7 +112,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer delete(String collection, String whereJson) throws WxErrorException {
|
public Integer delete(String collection, String whereJson) throws WxErrorException {
|
||||||
String query = JoinerUtils.blankJoiner.join(
|
String query = blankJoiner.join(
|
||||||
"db.collection('", collection, "')",
|
"db.collection('", collection, "')",
|
||||||
".where(", whereJson, ").remove()");
|
".where(", whereJson, ").remove()");
|
||||||
|
|
||||||
@ -140,7 +142,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxCloudDatabaseUpdateResult update(String collection, String whereJson, String updateJson) throws WxErrorException {
|
public WxCloudDatabaseUpdateResult update(String collection, String whereJson, String updateJson) throws WxErrorException {
|
||||||
String query = JoinerUtils.blankJoiner.join(
|
String query = blankJoiner.join(
|
||||||
"db.collection('", collection, "')",
|
"db.collection('", collection, "')",
|
||||||
".where(", whereJson, ").update({data:", updateJson, " })");
|
".where(", whereJson, ").update({data:", updateJson, " })");
|
||||||
|
|
||||||
@ -183,7 +185,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
|||||||
if (null == skip) {
|
if (null == skip) {
|
||||||
skip = 0;
|
skip = 0;
|
||||||
}
|
}
|
||||||
String query = JoinerUtils.blankJoiner.join(
|
String query = blankJoiner.join(
|
||||||
"db.collection('", collection, "')",
|
"db.collection('", collection, "')",
|
||||||
".where(", whereJson, ")", orderBySb.toString(), ".skip(", skip, ").limit(", limit, ").get()");
|
".where(", whereJson, ")", orderBySb.toString(), ".skip(", skip, ").limit(", limit, ").get()");
|
||||||
|
|
||||||
@ -221,7 +223,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long count(String collection, String whereJson) throws WxErrorException {
|
public Long count(String collection, String whereJson) throws WxErrorException {
|
||||||
String query = JoinerUtils.blankJoiner.join(
|
String query = blankJoiner.join(
|
||||||
"db.collection('", collection, "')",
|
"db.collection('", collection, "')",
|
||||||
".where(", whereJson, ").count()");
|
".where(", whereJson, ").count()");
|
||||||
|
|
||||||
@ -415,7 +417,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
|||||||
@Override
|
@Override
|
||||||
public WxCloudSendSmsV2Result sendSmsV2(WxCloudSendSmsV2Request request) throws WxErrorException {
|
public WxCloudSendSmsV2Result sendSmsV2(WxCloudSendSmsV2Request request) throws WxErrorException {
|
||||||
// 如果没有指定云环境ID,取默认云环境ID
|
// 如果没有指定云环境ID,取默认云环境ID
|
||||||
if (request.getEnv() == null){
|
if (request.getEnv() == null) {
|
||||||
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
|
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
|
||||||
request.setEnv(cloudEnv);
|
request.setEnv(cloudEnv);
|
||||||
}
|
}
|
||||||
|
@ -1,253 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2019,sunnybs.
|
|
||||||
* All Rights Reserved.
|
|
||||||
* <p>
|
|
||||||
* Project Name:yigou
|
|
||||||
*/
|
|
||||||
package cn.binarywang.wx.miniapp.util;
|
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ClassName: JoinerUtils <br/>
|
|
||||||
* Description: 字符串连接器 <br/>
|
|
||||||
* Date: 2019年10月18日 下午1:42:59 <br/>
|
|
||||||
*
|
|
||||||
* @author <a href="https://gitee.com/esunego_hunan/weixin-java-tools">wsp</a>
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class JoinerUtils {
|
|
||||||
private static final String NULL = "null";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 空白连接器,忽略null
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.blankJoiner.join("a", "b", "c");
|
|
||||||
* <b>result : </b>abc
|
|
||||||
*
|
|
||||||
* JoinerUtils.blankJoiner.join("a", null, "c");
|
|
||||||
* <b>result : </b>ac
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner blankJoiner = Joiner.on("").skipNulls();
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 空白连接器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.blankJoinerWithNull.join("a", "b", "c");
|
|
||||||
* <b>result : </b>abc
|
|
||||||
*
|
|
||||||
* JoinerUtils.blankJoinerWithNull.join("a", null, "c");
|
|
||||||
* <b>result : </b>anullc
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner blankJoinerWithNull = Joiner.on("").useForNull(NULL);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 空格连接器,忽略null
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.spaceJoiner.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a b c
|
|
||||||
*
|
|
||||||
* JoinerUtils.spaceJoiner.join("a", null, "c");
|
|
||||||
* <b>result : </b>a c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner spaceJoiner = Joiner.on(" ").skipNulls();
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 空格连接器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.spaceJoinerWithNull.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a b c
|
|
||||||
*
|
|
||||||
* JoinerUtils.spaceJoinerWithNull.join("a", null, "c");
|
|
||||||
* <b>result : </b>a null c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner spaceJoinerWithNull = Joiner.on(" ").useForNull(NULL);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 逗号分隔符连接器,忽略null
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.commaJoiner.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a,b,c
|
|
||||||
*
|
|
||||||
* JoinerUtils.commaJoiner.join("a", null, "c");
|
|
||||||
* <b>result : </b>a,c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner commaJoiner = Joiner.on(",").skipNulls();
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 逗号分隔符连接器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.commaJoinerWithNull.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a,b,c
|
|
||||||
*
|
|
||||||
* JoinerUtils.commaJoinerWithNull.join("a", null, "c");
|
|
||||||
* <b>result : </b>a,null,c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner commaJoinerWithNull = Joiner.on(",").useForNull(NULL);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 等号分隔符连接器,忽略null
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.equalJoiner.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a=b=c
|
|
||||||
*
|
|
||||||
* JoinerUtils.equalJoiner.join("a", null, "c");
|
|
||||||
* <b>result : </b>a=c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner equalJoiner = Joiner.on("=").skipNulls();
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 等号分隔符连接器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.equalJoinerWithNull.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a=b=c
|
|
||||||
*
|
|
||||||
* JoinerUtils.equalJoinerWithNull.join("a", null, "c");
|
|
||||||
* <b>result : </b>a=null=c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner equalJoinerWithNull = Joiner.on("=").useForNull(NULL);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 竖线分隔符连接器,忽略null
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.vLineJoiner.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a|b|c
|
|
||||||
*
|
|
||||||
* JoinerUtils.vLineJoiner.join("a", null, "c");
|
|
||||||
* <b>result : </b>a|c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner vLineJoiner = Joiner.on("|").skipNulls();
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 竖线分隔符连接器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.vLineJoinerWithNull.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a|b|c
|
|
||||||
*
|
|
||||||
* JoinerUtils.vLineJoinerWithNull.join("a", null, "c");
|
|
||||||
* <b>result : </b>a|null|c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner vLineJoinerWithNull = Joiner.on("|").useForNull(NULL);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 中横线分隔符连接器,忽略null
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.hLineJoiner.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a-b-c
|
|
||||||
*
|
|
||||||
* JoinerUtils.hLineJoiner.join("a", null, "c");
|
|
||||||
* <b>result : </b>a-c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner hLineJoiner = Joiner.on("-").skipNulls();
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 中横线分隔符连接器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.hLineJoinerWithNull.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a-b-c
|
|
||||||
*
|
|
||||||
* JoinerUtils.hLineJoinerWithNull.join("a", null, "c");
|
|
||||||
* <b>result : </b>a-null-c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner hLineJoinerWithNull = Joiner.on("-").useForNull(NULL);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 下划线分隔符连接器,忽略null
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.underlineJoiner.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a_b_c
|
|
||||||
*
|
|
||||||
* JoinerUtils.underlineJoiner.join("a", null, "c");
|
|
||||||
* <b>result : </b>a_c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner underlineJoiner = Joiner.on("_").skipNulls();
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 下划线分隔符连接器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.underlineJoinerWithNull.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a_b_c
|
|
||||||
*
|
|
||||||
* JoinerUtils.underlineJoinerWithNull.join("a", null, "c");
|
|
||||||
* <b>result : </b>a_null_c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner underlineJoinerWithNull = Joiner.on("_").useForNull(NULL);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 斜线分隔符连接器,忽略null
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.pathJoiner.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a/b/c
|
|
||||||
*
|
|
||||||
* JoinerUtils.pathJoiner.join("a", null, "c");
|
|
||||||
* <b>result : </b>a/c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner pathJoiner = Joiner.on("/").skipNulls();
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 斜线分隔符连接器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* JoinerUtils.pathJoinerWithNull.join("a", "b", "c");
|
|
||||||
* <b>result : </b>a/b/c
|
|
||||||
*
|
|
||||||
* JoinerUtils.pathJoinerWithNull.join("a", null, "c");
|
|
||||||
* <b>result : </b>a/null/c
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public static final Joiner pathJoinerWithNull = Joiner.on("/").useForNull(NULL);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user