Commit 39f52a61 authored by 黎博's avatar 黎博

新增Json结果类以及修改消息发送所有接口

parent be3a2b46
...@@ -3,15 +3,27 @@ package cn.qg.qaplatform.controller.stools; ...@@ -3,15 +3,27 @@ package cn.qg.qaplatform.controller.stools;
import cn.qg.qaplatform.config.SwitchDataSource; import cn.qg.qaplatform.config.SwitchDataSource;
import cn.qg.qaplatform.entity.stools.MsgSendVo; import cn.qg.qaplatform.entity.stools.MsgSendVo;
import cn.qg.qaplatform.entity.stools.MsgTemplate; import cn.qg.qaplatform.entity.stools.MsgTemplate;
import cn.qg.qaplatform.entity.stools.PhoneNoWhiteList;
import cn.qg.qaplatform.entity.zdata.XjfqGenProcessVo;
import cn.qg.qaplatform.service.stools.MsgService; import cn.qg.qaplatform.service.stools.MsgService;
import cn.qg.qaplatform.service.stools.PhoneNoWhiteListService;
import cn.qg.qaplatform.service.zdata.xyqb.XyqbBasicQueryService;
import cn.qg.qaplatform.utils.HttpClientUtils;
import cn.qg.qaplatform.utils.JsonResult; import cn.qg.qaplatform.utils.JsonResult;
import cn.qg.qaplatform.utils.Result;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jayway.jsonpath.JsonPath;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -19,11 +31,18 @@ import java.util.Map; ...@@ -19,11 +31,18 @@ import java.util.Map;
* @author libo * @author libo
* 2021-08-13 * 2021-08-13
*/ */
@Slf4j
@CrossOrigin @CrossOrigin
@RestController @RestController
@RequestMapping("/msg") @RequestMapping("/msg")
public class MsgController { public class MsgController {
@Autowired
XyqbBasicQueryService xyqbBasicQueryService;
@Autowired
PhoneNoWhiteListService phoneNoWhiteListService;
@Autowired @Autowired
MsgService msgService; MsgService msgService;
...@@ -33,8 +52,44 @@ public class MsgController { ...@@ -33,8 +52,44 @@ public class MsgController {
* @return * @return
*/ */
@PostMapping("/send/push") @PostMapping("/send/push")
public JsonResult sendPush(@RequestBody MsgSendVo msgSendVo) { public Result sendPush(@RequestBody MsgSendVo msgSendVo) {
return JsonResult.success(msgService.sendPush(msgSendVo.getNamespace(), msgSendVo.getPhoneNo(), msgSendVo.getContentId(), msgSendVo.getContentArgs())); String namespace = msgSendVo.getNamespace();
String phoneNo = msgSendVo.getPhoneNo();
String contentId = msgSendVo.getContentId();
List<String> contentArgs = msgSendVo.getContentArgs();
XjfqGenProcessVo xjfqGenProcessVo = xyqbBasicQueryService.getUserInfoByPhoneNo(namespace, phoneNo);
String userId;
if (xjfqGenProcessVo == null) {
log.info("用户中心查不到手机号{},因此本次不发送push.", phoneNo);
return Result.buildErrorStateResult("用户中心无此手机号,无法发送push", false);
} else {
userId = xjfqGenProcessVo.getUserId();
}
String url = "https://msgapi-" + namespace + ".liangkebang.net/middle_office/send/message/appPush";
List<Map<String, Object>> paramList = new ArrayList<>();
Map<String, Object> sendMap = new HashMap<>();
sendMap.put("merchantId", "3");
sendMap.put("phoneNo", phoneNo);
sendMap.put("userIds", userId);
sendMap.put("contentId", contentId);
if (contentArgs != null && contentArgs.size() > 0) {
sendMap.put("contentArgs", contentArgs);
}
paramList.add(sendMap);
Map<String, Object> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
log.info("开始发送push,url:{}, 参数:{}", url, paramList);
try {
JSONObject response = HttpClientUtils.doPostJson(url, JSON.toJSONString(paramList), headers);
log.info("发送收到响应:{}", response);
if (!JsonPath.read(response, "$.code").equals("0")) {
return Result.buildErrorStateResult("发送失败,请检查msg服务!", false);
}
} catch (Exception e) {
e.printStackTrace();
return Result.buildErrorStateResult("发送异常,请检查msg服务是否正常!", false);
}
return Result.buildSuccessResult("发送成功!", true);
} }
/** /**
...@@ -43,8 +98,44 @@ public class MsgController { ...@@ -43,8 +98,44 @@ public class MsgController {
* @return * @return
*/ */
@PostMapping("/send/stationLetter") @PostMapping("/send/stationLetter")
public JsonResult sendStationLetter(@RequestBody MsgSendVo msgSendVo) { public Result sendStationLetter(@RequestBody MsgSendVo msgSendVo) {
return JsonResult.success(msgService.sendStationLetter(msgSendVo.getNamespace(), msgSendVo.getPhoneNo(), msgSendVo.getContentId(), msgSendVo.getContentArgs())); String namespace = msgSendVo.getNamespace();
String phoneNo = msgSendVo.getPhoneNo();
String contentId = msgSendVo.getContentId();
List<String> contentArgs = msgSendVo.getContentArgs();
XjfqGenProcessVo xjfqGenProcessVo = xyqbBasicQueryService.getUserInfoByPhoneNo(namespace, phoneNo);
String userId;
if (xjfqGenProcessVo == null) {
log.info("用户中心查不到手机号{},因此本次不发送站内信.", phoneNo);
return Result.buildErrorStateResult("用户中心无此手机号,无法发送站内信", false);
} else {
userId = xjfqGenProcessVo.getUserId();
}
String url = "https://msgapi-" + namespace + ".liangkebang.net/middle_office/send/message/stationLetter";
List<Map<String, Object>> paramList = new ArrayList<>();
Map<String, Object> sendMap = new HashMap<>();
sendMap.put("merchantId", "3");
sendMap.put("phoneNo", phoneNo);
sendMap.put("userIds", userId);
sendMap.put("contentId", contentId);
if (contentArgs != null && contentArgs.size() > 0) {
sendMap.put("contentArgs", contentArgs);
}
paramList.add(sendMap);
Map<String, Object> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
log.info("开始发送站内信,url:{}, 参数:{}", url, paramList);
try {
JSONObject response = HttpClientUtils.doPostJson(url, JSON.toJSONString(paramList), headers);
log.info("收到响应:{}", response);
if (!JsonPath.read(response, "$.code").equals("0")) {
return Result.buildErrorStateResult("发送失败,请检查msg服务!", false);
}
} catch (Exception e) {
e.printStackTrace();
return Result.buildErrorStateResult("发送异常,请检查msg服务是否正常!", false);
}
return Result.buildSuccessResult("发送成功", true);
} }
/** /**
...@@ -53,19 +144,87 @@ public class MsgController { ...@@ -53,19 +144,87 @@ public class MsgController {
* @return * @return
*/ */
@PostMapping("/send/quick") @PostMapping("/send/quick")
public JsonResult sendMsgQuick(@RequestBody MsgSendVo msgSendVo) { public Result sendMsgQuick(@RequestBody MsgSendVo msgSendVo) {
return JsonResult.success(msgService.sendMsgQuick(msgSendVo.getNamespace(), msgSendVo.getPhoneNo(), msgSendVo.getContentId(), msgSendVo.getContentArgs())); String namespace = msgSendVo.getNamespace();
String phoneNo = msgSendVo.getPhoneNo();
String contentId = msgSendVo.getContentId();
List<String> contentArgs = msgSendVo.getContentArgs();
phoneNoWhiteListService.handlePhoneNoWhiteList(namespace, phoneNo);
XjfqGenProcessVo xjfqGenProcessVo = xyqbBasicQueryService.getUserInfoByPhoneNo(namespace, phoneNo);
String userId;
if (xjfqGenProcessVo == null) {
log.info("用户中心查不到手机号{},因此本次不发送短信.", phoneNo);
return Result.buildErrorStateResult("用户中心未找到该手机号,短信不进行发送!", false);
} else {
userId = xjfqGenProcessVo.getUserId();
}
String url = "https://msgapi-" + namespace + ".liangkebang.net/middle_office/send/message/quick";
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("merchantId", "3");
paramsMap.put("phoneNo", phoneNo);
paramsMap.put("userIds", userId);
paramsMap.put("contentId", contentId);
if (contentArgs != null && contentArgs.size() > 0) {
paramsMap.put("contentArgs", contentArgs);
}
Map<String, Object> headers = new HashMap<>();
log.info("开始发送行业短信,url:{}, 参数:{}", url, paramsMap);
try {
JSONObject response = HttpClientUtils.doPostJson(url, JSON.toJSONString(paramsMap), headers);
log.info("收到响应:{}", response);
if (!JsonPath.read(response, "$.code").equals("0")) {
return Result.buildErrorStateResult("发送失败,请检查msg服务!", false);
}
} catch (Exception e) {
e.printStackTrace();
return Result.buildErrorStateResult("发送异常,请检查msg服务!", false);
}
return Result.buildSuccessResult("发送成功!", true);
} }
/**
* 发送营销短信
* @param msgSendVo
* @return
*/
@PostMapping("/send/market") @PostMapping("/send/market")
public JsonResult sendMsgMarket(@RequestBody MsgSendVo msgSendVo) { public Result sendMsgMarket(@RequestBody MsgSendVo msgSendVo) {
return JsonResult.success(msgService.sendMsgQuick(msgSendVo.getNamespace(), msgSendVo.getPhoneNo(), msgSendVo.getContentId(), msgSendVo.getContentArgs())); String namespace = msgSendVo.getNamespace();
String phoneNo = msgSendVo.getPhoneNo();
String contentId = msgSendVo.getContentId();
List<String> contentArgs = msgSendVo.getContentArgs();
phoneNoWhiteListService.handlePhoneNoWhiteList(namespace, phoneNo);
String url = "https://msgapi-" + namespace + ".liangkebang.net/middle_office/send/message/market";
Map<String, Object> paramsMap = new HashMap<>();
Map<String, Object> headers = new HashMap<>();
paramsMap.put("merchantId", "3");
paramsMap.put("phoneNo", phoneNo);
paramsMap.put("contentId", contentId);
paramsMap.put("platformId", "8");
if (contentArgs != null && contentArgs.size() > 0) {
paramsMap.put("contentArgs", contentArgs);
}
List<Map<String, Object>> paramList = new ArrayList<>();
paramList.add(paramsMap);
headers.put("Content-Type", "application/json");
log.info("开始发送营销短信,url:{}, 参数:{}", url, paramList);
try {
JSONObject response = HttpClientUtils.doPostJson(url, JSON.toJSONString(paramList), headers);
log.info("收到响应:{}", response);
if (!JsonPath.read(response, "$.code").equals("0")) {
return Result.buildErrorStateResult("发送失败,请检查msg服务!", false);
}
} catch (Exception e) {
e.printStackTrace();
return Result.buildErrorStateResult("发送异常,请检查msg服务!", false);
}
return Result.buildSuccessResult("发送成功!", true);
} }
/** /**
* 获取短信模板列表 * 获取短信模板列表
* @param namespace * @param namespace 环境
* @param templateType * @param templateType 模板类型
* @param pageNum * @param pageNum
* @param pageSize * @param pageSize
* @return * @return
......
...@@ -7,25 +7,4 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -7,25 +7,4 @@ import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List; import java.util.List;
public interface MsgService extends IService<MsgTemplate> { public interface MsgService extends IService<MsgTemplate> {
/**
* 发送push
*/
boolean sendPush(String namespace, String phoneNo, String contentId, List<String> contentArgs);
/**
* 发送站内信
*/
boolean sendStationLetter(String namespace, String phoneNo, String contentId, List<String> contentArgs);
/**
* 发送行业短信
*/
boolean sendMsgQuick(String namespace, String phoneNo, String contentId, List<String> contentArgs);
/**
* 发送营销短信
*/
boolean sendMsgMarket(String namespace, String phoneNo, String contentId, List<String> contentArgs);
} }
package cn.qg.qaplatform.service.stools;
import cn.qg.qaplatform.entity.stools.PhoneNoWhiteList;
import com.baomidou.mybatisplus.extension.service.IService;
public interface PhoneNoWhiteListService extends IService<PhoneNoWhiteList> {
void handlePhoneNoWhiteList(String namespace, String phoneNo);
}
package cn.qg.qaplatform.service.stools.impl; package cn.qg.qaplatform.service.stools.impl;
import cn.qg.qaplatform.config.SwitchDataSource;
import cn.qg.qaplatform.entity.stools.MsgTemplate; import cn.qg.qaplatform.entity.stools.MsgTemplate;
import cn.qg.qaplatform.entity.stools.PhoneNoWhiteList;
import cn.qg.qaplatform.entity.zdata.XjfqGenProcessVo;
import cn.qg.qaplatform.mapper.stools.MsgMapper; import cn.qg.qaplatform.mapper.stools.MsgMapper;
import cn.qg.qaplatform.mapper.stools.PhoneNoWhiteListMapper;
import cn.qg.qaplatform.service.stools.MsgService; import cn.qg.qaplatform.service.stools.MsgService;
import cn.qg.qaplatform.service.zdata.xyqb.XyqbBasicQueryService;
import cn.qg.qaplatform.utils.HttpClientUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jayway.jsonpath.JsonPath;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service @Service
public class MsgServiceImpl extends ServiceImpl<MsgMapper, MsgTemplate> implements MsgService { public class MsgServiceImpl extends ServiceImpl<MsgMapper, MsgTemplate> implements MsgService {
@Autowired
XyqbBasicQueryService xyqbBasicQueryService;
@Autowired
PhoneNoWhiteListMapper phoneNoWhiteListMapper;
/**
* 发送push
*/
@Override
public boolean sendPush(String namespace, String phoneNo, String contentId, List<String> contentArgs) {
XjfqGenProcessVo xjfqGenProcessVo = xyqbBasicQueryService.getUserInfoByPhoneNo(namespace, phoneNo);
String userId;
if (xjfqGenProcessVo == null) {
log.info("用户中心查不到手机号{},因此本次不发送短信.", phoneNo);
return false;
} else {
userId = xjfqGenProcessVo.getUserId();
}
String url = "https://msgapi-" + namespace + ".liangkebang.net/middle_office/send/message/appPush";
List<Map<String, Object>> paramList = new ArrayList<>();
Map<String, Object> sendMap = new HashMap<>();
sendMap.put("merchantId", "3");
sendMap.put("phoneNo", phoneNo);
sendMap.put("userIds", userId);
sendMap.put("contentId", contentId);
if (contentArgs != null && contentArgs.size() > 0) {
sendMap.put("contentArgs", contentArgs);
}
paramList.add(sendMap);
Map<String, Object> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
log.info("开始发送push,url:{}, 参数:{}", url, paramList);
JSONObject response = HttpClientUtils.doPostJson(url, JSON.toJSONString(paramList), headers);
log.info("收到响应:{}", response);
return JsonPath.read(response, "$.code").equals("0");
}
/**
* 发送站内信
*/
@Override
public boolean sendStationLetter(String namespace, String phoneNo, String contentId, List<String> contentArgs) {
XjfqGenProcessVo xjfqGenProcessVo = xyqbBasicQueryService.getUserInfoByPhoneNo(namespace, phoneNo);
String userId;
if (xjfqGenProcessVo == null) {
log.info("用户中心查不到手机号{},因此本次不发送短信.", phoneNo);
return false;
} else {
userId = xjfqGenProcessVo.getUserId();
}
String url = "https://msgapi-" + namespace + ".liangkebang.net/middle_office/send/message/stationLetter";
List<Map<String, Object>> paramList = new ArrayList<>();
Map<String, Object> sendMap = new HashMap<>();
sendMap.put("merchantId", "3");
sendMap.put("phoneNo", phoneNo);
sendMap.put("userIds", userId);
sendMap.put("contentId", contentId);
if (contentArgs != null && contentArgs.size() > 0) {
sendMap.put("contentArgs", contentArgs);
}
paramList.add(sendMap);
Map<String, Object> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
log.info("开始发送站内信,url:{}, 参数:{}", url, paramList);
JSONObject response = HttpClientUtils.doPostJson(url, JSON.toJSONString(paramList), headers);
log.info("收到响应:{}", response);
return JsonPath.read(response, "$.code").equals("0");
}
/**
* 发送行业短信
*/
@Override
public boolean sendMsgQuick(String namespace, String phoneNo, String contentId, List<String> contentArgs) {
handlePhoneNoWhiteList(namespace, phoneNo);
XjfqGenProcessVo xjfqGenProcessVo = xyqbBasicQueryService.getUserInfoByPhoneNo(namespace, phoneNo);
String userId;
if (xjfqGenProcessVo == null) {
log.info("用户中心查不到手机号{},因此本次不发送短信.", phoneNo);
return false;
} else {
userId = xjfqGenProcessVo.getUserId();
}
String url = "https://msgapi-" + namespace + ".liangkebang.net/middle_office/send/message/quick";
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("merchantId", "3");
paramsMap.put("phoneNo", phoneNo);
paramsMap.put("userIds", userId);
paramsMap.put("contentId", contentId);
if (contentArgs != null && contentArgs.size() > 0) {
paramsMap.put("contentArgs", contentArgs);
}
Map<String, Object> headers = new HashMap<>();
log.info("开始发送营销短信,url:{}, 参数:{}", url, paramsMap);
JSONObject response = HttpClientUtils.doPostJson(url, JSON.toJSONString(paramsMap), headers);
log.info("收到响应:{}", response);
return JsonPath.read(response, "$.code").equals("0");
}
/**
* 发送营销短信
*/
@Override
public boolean sendMsgMarket(String namespace, String phoneNo, String contentId, List<String> contentArgs) {
handlePhoneNoWhiteList(namespace, phoneNo);
SwitchDataSource.dataSourceSwitch(namespace, "msg");
QueryWrapper<PhoneNoWhiteList> whiteListQueryWrapper = new QueryWrapper<>();
whiteListQueryWrapper.eq("phone_no", phoneNo);
PhoneNoWhiteList phoneNoWhite = phoneNoWhiteListMapper.selectOne(whiteListQueryWrapper);
if (phoneNoWhite == null) {
log.info("该手机号不在白名单:{},先将其添加到手机号白名单.", phoneNo);
PhoneNoWhiteList phoneNoWhiteListEntity = new PhoneNoWhiteList();
phoneNoWhiteListEntity.setPhoneNo(phoneNo);
phoneNoWhiteListEntity.setUserName(phoneNo);
phoneNoWhiteListEntity.setListType("1");
phoneNoWhiteListEntity.setDeleted(0);
phoneNoWhiteListMapper.insert(phoneNoWhiteListEntity);
} else {
log.info("{}该手机号已在手机号白名单.", phoneNo);
}
String url = "https://msgapi-" + namespace + ".liangkebang.net/middle_office/send/message/market";
Map<String, Object> paramsMap = new HashMap<>();
Map<String, Object> headers = new HashMap<>();
paramsMap.put("merchantId", "3");
paramsMap.put("phoneNo", phoneNo);
paramsMap.put("contentId", contentId);
paramsMap.put("platformId", "8");
if (contentArgs != null && contentArgs.size() > 0) {
paramsMap.put("contentArgs", contentArgs);
}
List<Map<String, Object>> paramList = new ArrayList<>();
paramList.add(paramsMap);
headers.put("Content-Type", "application/json");
log.info("开始发送营销短信,url:{}, 参数:{}", url, paramList);
JSONObject response = HttpClientUtils.doPostJson(url, JSON.toJSONString(paramList), headers);
log.info("收到响应:{}", response);
return JsonPath.read(response, "$.code").equals("0");
}
/**
* 判断是否在白名单,如果不在,则添加到短信白名单
* @param namespace 环境
* @param phoneNo 手机号
*/
public void handlePhoneNoWhiteList(String namespace, String phoneNo) {
SwitchDataSource.dataSourceSwitch(namespace, "msg");
QueryWrapper<PhoneNoWhiteList> whiteListQueryWrapper = new QueryWrapper<>();
whiteListQueryWrapper.eq("phone_no", phoneNo);
PhoneNoWhiteList phoneNoWhite = phoneNoWhiteListMapper.selectOne(whiteListQueryWrapper);
if (phoneNoWhite == null) {
log.info("该手机号不在白名单:{},先将其添加到手机号白名单.", phoneNo);
PhoneNoWhiteList phoneNoWhiteListEntity = new PhoneNoWhiteList();
phoneNoWhiteListEntity.setPhoneNo(phoneNo);
phoneNoWhiteListEntity.setUserName("测试");
phoneNoWhiteListEntity.setListType("1");
phoneNoWhiteListEntity.setDeleted(0);
phoneNoWhiteListMapper.insert(phoneNoWhiteListEntity);
} else {
log.info("{}该手机号已在手机号白名单.", phoneNo);
}
}
} }
package cn.qg.qaplatform.service.stools.impl;
import cn.qg.qaplatform.config.SwitchDataSource;
import cn.qg.qaplatform.entity.stools.PhoneNoWhiteList;
import cn.qg.qaplatform.mapper.stools.PhoneNoWhiteListMapper;
import cn.qg.qaplatform.service.stools.PhoneNoWhiteListService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class PhoneNoWhiteListServiceImpl extends ServiceImpl<PhoneNoWhiteListMapper, PhoneNoWhiteList> implements PhoneNoWhiteListService {
@Autowired
PhoneNoWhiteListMapper phoneNoWhiteListMapper;
/**
* 判断是否在白名单,如果不在,则添加到短信白名单
* @param namespace 环境
* @param phoneNo 手机号
*/
@Override
public void handlePhoneNoWhiteList(String namespace, String phoneNo) {
SwitchDataSource.dataSourceSwitch(namespace, "msg");
QueryWrapper<PhoneNoWhiteList> whiteListQueryWrapper = new QueryWrapper<>();
whiteListQueryWrapper.eq("phone_no", phoneNo);
PhoneNoWhiteList phoneNoWhite = phoneNoWhiteListMapper.selectOne(whiteListQueryWrapper);
if (phoneNoWhite == null) {
log.info("该手机号不在白名单:{},先将其添加到手机号白名单.", phoneNo);
PhoneNoWhiteList phoneNoWhiteListEntity = new PhoneNoWhiteList();
phoneNoWhiteListEntity.setPhoneNo(phoneNo);
phoneNoWhiteListEntity.setUserName("测试");
phoneNoWhiteListEntity.setListType("1");
phoneNoWhiteListEntity.setDeleted(0);
phoneNoWhiteListMapper.insert(phoneNoWhiteListEntity);
} else {
log.info("{}该手机号已在手机号白名单.", phoneNo);
}
}
}
package cn.qg.qaplatform.utils;
import lombok.Data;
import java.io.Serializable;
@Data
public class Result<T> implements Serializable {
private static final Long SUCCESS_CODE = 0L;
private static final String SUCCESS_MSG = "SUCCESS";
private static final Long ERROR_STATE_CODE = 1L;
private static final Long SUCCESS_BUSSINESS_CODE = 0L;
private static final Long ERROR_BUSSINESS_CODE = 1L;
private static final long serialVersionUID = -1L;
public static final Long API_INVOKE_UNEXPECTED_RESULT_CODE = 2L;
public static final String ZERO_FILL_TEMPLATE = "%04d";
private String msg = "";
// 0成功,1失败
private String code = "0000";
// 业务错误码
private String businessCode = "0000";
// 业务状态码
private String businessFlag = "0000";
private Object data = null;
public Result() {
}
/**
* @param msg
* @param code
* @param data
*/
public Result(String msg, Long code, Object data) {
this.msg = msg;
this.code = String.format(ZERO_FILL_TEMPLATE, code);
this.data = data;
}
public Result(String msg, Long code, Object data, Long businessCode) {
this.msg = msg;
this.code = String.format(ZERO_FILL_TEMPLATE, code);
this.data = data;
this.businessCode = String.format(ZERO_FILL_TEMPLATE, businessCode);
}
public Result(String msg, Long code, Object data, Long businessFlag, Long businessCode) {
this.msg = msg;
this.code = String.format(ZERO_FILL_TEMPLATE, code);
this.data = data;
this.businessCode = String.format(ZERO_FILL_TEMPLATE, businessCode);
this.businessFlag = String.format(ZERO_FILL_TEMPLATE, businessFlag);
}
/**
* 构造成功的Result
*
* @param msg String
* @param data Object
* @return Result
*/
public static Result buildSuccessResult(String msg, Object data) {
return new Result(msg, SUCCESS_CODE, data, SUCCESS_BUSSINESS_CODE);
}
public static Result buildSuccessResult(Object data) {
return new Result(SUCCESS_MSG, SUCCESS_CODE, data, SUCCESS_BUSSINESS_CODE);
}
public static Result buildSuccessResult(String msg, Object data, Long bussinessId) {
return new Result(msg, SUCCESS_CODE, data, bussinessId);
}
public static Result buildSuccessResult(String msg, Object data, Long businessFlag, Long bussinessCode) {
return new Result(msg, SUCCESS_CODE, data, businessFlag, bussinessCode);
}
/**
* 构造状态不正确的Result
*
* @param msg String
* @param data Object
* @return Result
*/
public static Result buildErrorStateResult(String msg, Object data) {
return new Result(msg, SUCCESS_CODE, data, ERROR_BUSSINESS_CODE);
}
public static Result buildErrorStateResult(String msg, Object data, Long busniessId) {
return new Result(msg, SUCCESS_CODE, data, busniessId);
}
public static Result buildFatalErrorStateResult(String msg, Object data, Long busniessId) {
return new Result(msg, ERROR_STATE_CODE, data, busniessId);
}
public static Result buildFatalErrorStateResult(String msg, Object data) {
return new Result(msg, ERROR_STATE_CODE, data, 1L);
}
public static Result buildApiInvokeUnexpectedResult(String msg, Object data) {
return new Result(msg, SUCCESS_CODE, data, API_INVOKE_UNEXPECTED_RESULT_CODE);
}
public Result(Object data) {
this.data = data;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getBusinessCode() {
return businessCode;
}
public void setBusinessCode(String businessCode) {
this.businessCode = businessCode;
}
public String getBusinessFlag() {
return businessFlag;
}
public void setBusinessFlag(String businessFlag) {
this.businessFlag = businessFlag;
}
@Override
public String toString() {
return "Result{" + "businessCode='" + businessCode + '\'' + ", code='" + code + '\'' + ", data=" + data
+ ",businessFlag=" + businessFlag + '}';
}
public boolean isSuccess() {
return "0000".equals(code) && "0000".equals(businessCode);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment