mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
:art:简化代码
This commit is contained in:
@@ -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.request.WxCloudSendSmsV2Request;
|
||||
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.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
@@ -37,6 +37,8 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Cloud.*;
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||
private static final Joiner blankJoiner = Joiner.on("").skipNulls();
|
||||
|
||||
private final WxMaService wxMaService;
|
||||
|
||||
@Override
|
||||
@@ -55,7 +57,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||
@Override
|
||||
public List<String> add(String collection, List list) throws WxErrorException {
|
||||
String jsonData = WxMaGsonBuilder.create().toJson(list);
|
||||
String query = JoinerUtils.blankJoiner.join(
|
||||
String query = blankJoiner.join(
|
||||
"db.collection('", collection, "')",
|
||||
".add({data: ", jsonData, "})");
|
||||
|
||||
@@ -79,7 +81,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||
@Override
|
||||
public String add(String collection, Object obj) throws WxErrorException {
|
||||
String jsonData = WxMaGsonBuilder.create().toJson(obj);
|
||||
String query = JoinerUtils.blankJoiner.join(
|
||||
String query = blankJoiner.join(
|
||||
"db.collection('", collection, "')",
|
||||
".add({data: ", jsonData, "})");
|
||||
|
||||
@@ -110,7 +112,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||
|
||||
@Override
|
||||
public Integer delete(String collection, String whereJson) throws WxErrorException {
|
||||
String query = JoinerUtils.blankJoiner.join(
|
||||
String query = blankJoiner.join(
|
||||
"db.collection('", collection, "')",
|
||||
".where(", whereJson, ").remove()");
|
||||
|
||||
@@ -140,7 +142,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||
|
||||
@Override
|
||||
public WxCloudDatabaseUpdateResult update(String collection, String whereJson, String updateJson) throws WxErrorException {
|
||||
String query = JoinerUtils.blankJoiner.join(
|
||||
String query = blankJoiner.join(
|
||||
"db.collection('", collection, "')",
|
||||
".where(", whereJson, ").update({data:", updateJson, " })");
|
||||
|
||||
@@ -183,7 +185,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||
if (null == skip) {
|
||||
skip = 0;
|
||||
}
|
||||
String query = JoinerUtils.blankJoiner.join(
|
||||
String query = blankJoiner.join(
|
||||
"db.collection('", collection, "')",
|
||||
".where(", whereJson, ")", orderBySb.toString(), ".skip(", skip, ").limit(", limit, ").get()");
|
||||
|
||||
@@ -221,7 +223,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||
|
||||
@Override
|
||||
public Long count(String collection, String whereJson) throws WxErrorException {
|
||||
String query = JoinerUtils.blankJoiner.join(
|
||||
String query = blankJoiner.join(
|
||||
"db.collection('", collection, "')",
|
||||
".where(", whereJson, ").count()");
|
||||
|
||||
@@ -415,7 +417,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||
@Override
|
||||
public WxCloudSendSmsV2Result sendSmsV2(WxCloudSendSmsV2Request request) throws WxErrorException {
|
||||
// 如果没有指定云环境ID,取默认云环境ID
|
||||
if (request.getEnv() == null){
|
||||
if (request.getEnv() == null) {
|
||||
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
|
||||
request.setEnv(cloudEnv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user