完成用户账号不足5元短信发送提示
This commit is contained in:
parent
d48ba4bb9f
commit
fcb7e469cd
@ -33,4 +33,9 @@ public class ServiceNameConstants
|
||||
*/
|
||||
public static final String XHPC_ORDER ="xhpc-order";
|
||||
|
||||
/**
|
||||
* 通用服务
|
||||
*/
|
||||
public static final String XHPC_GENERAL = "xhpc-general";
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package com.xhpc.common.api;
|
||||
|
||||
import com.xhpc.common.api.factory.SmsFallbackFactory;
|
||||
import com.xhpc.common.core.constant.ServiceNameConstants;
|
||||
import com.xhpc.common.core.domain.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* program: ruoyi
|
||||
* User: HongYun
|
||||
* Date:2021-08-16 16
|
||||
*/
|
||||
@FeignClient(contextId = "smsService",value = ServiceNameConstants.XHPC_GENERAL, fallbackFactory = SmsFallbackFactory.class)
|
||||
public interface SmsService {
|
||||
|
||||
@PostMapping("/send")
|
||||
R sendNotice(String phone, String content);
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.xhpc.common.api.factory;
|
||||
|
||||
import com.xhpc.common.api.PowerPileService;
|
||||
import com.xhpc.common.api.SmsService;
|
||||
import com.xhpc.common.core.domain.R;
|
||||
import com.xhpc.common.data.down.StartChargingData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
|
||||
/**
|
||||
* program: ruoyi
|
||||
* User: HongYun
|
||||
* Date:2021-08-16 17
|
||||
*/
|
||||
public class SmsFallbackFactory implements FallbackFactory<SmsService> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SmsFallbackFactory.class);
|
||||
@Override
|
||||
public SmsService create(Throwable cause) {
|
||||
logger.error("充电订单服务调用失败:{} //fallback", cause.getMessage());
|
||||
return new SmsService() {
|
||||
@Override
|
||||
public R sendNotice(String phone, String content) {
|
||||
|
||||
return R.fail("短信发送失败:" +cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -40,4 +40,9 @@ public class XhpcSmsController extends BaseController {
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/send")
|
||||
public void send(String phone , String content){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -31,5 +31,12 @@ public interface IXhpcSmsService {
|
||||
*/
|
||||
AjaxResult send(String phone, String content, String random);
|
||||
|
||||
/**
|
||||
* Send a notice, when user's account is less than 5 yuan.
|
||||
* @param phone
|
||||
* @param content
|
||||
*/
|
||||
void sendNotice(String phone,String content);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -124,6 +124,29 @@ public class XhpcSmsServiceImpl implements IXhpcSmsService{
|
||||
return i+"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendNotice(String phone, String content) {
|
||||
|
||||
XhpcSms xhpcSms = new XhpcSms();
|
||||
try {
|
||||
String req = HttpUtils.postFormData(URL,null,assembleSmsReq(phone,content));
|
||||
JSONObject json = JSONObject.parseObject(req);
|
||||
xhpcSms.setPhone(phone);
|
||||
xhpcSms.setContent(content);
|
||||
xhpcSms.setCreateTime(new Date());
|
||||
xhpcSms.setRemark(req);
|
||||
String ok = json.getString("ok");
|
||||
if("true".equals(ok)) {
|
||||
xhpcSms.setStatus(0);
|
||||
}else {
|
||||
xhpcSms.setStatus(1);
|
||||
}
|
||||
xhpcSmsMapper.addXhpcSms(xhpcSms);
|
||||
} catch (Exception e) {
|
||||
xhpcSms.setStatus(3);
|
||||
xhpcSmsMapper.addXhpcSms(xhpcSms);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
@ -2,11 +2,13 @@ package com.xhpc.pp.logic;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xhpc.common.api.PileOrderService;
|
||||
import com.xhpc.common.api.SmsService;
|
||||
import com.xhpc.common.data.redis.CacheRealtimeData;
|
||||
import com.xhpc.common.data.up.RealtimeData;
|
||||
import com.xhpc.pp.tx.ServiceParameter;
|
||||
import com.xhpc.pp.tx.ServiceResult;
|
||||
import com.xhpc.pp.tx.logic.ServiceLogic;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -29,6 +31,10 @@ import static com.xhpc.pp.utils.security.HexUtils.toBits;
|
||||
@Component("RealtimeDataLogic")
|
||||
public class RealtimeDataLogic implements ServiceLogic {
|
||||
|
||||
|
||||
@Autowired
|
||||
private SmsService smsService;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(RealtimeDataLogic.class);
|
||||
|
||||
public static final String[] stable = {"离线", "故障", "空闲", "充电"};
|
||||
@ -38,6 +44,7 @@ public class RealtimeDataLogic implements ServiceLogic {
|
||||
@Autowired
|
||||
private PileOrderService pileOrderService;
|
||||
|
||||
|
||||
@Override
|
||||
public ServiceResult service(ServiceParameter sp) throws Exception {
|
||||
|
||||
@ -103,6 +110,7 @@ public class RealtimeDataLogic implements ServiceLogic {
|
||||
String tel = (String) cacheOrder.get("tel");
|
||||
if (alerted == null && tel != null) {
|
||||
// todo send sms
|
||||
smsService.sendNotice(tel,"【小华充电】尊敬的用户,你的账户余额小于5元,为不影响您的正常充电,请您尽快充值交费,谢谢。");
|
||||
cacheOrder.put("alerted", "true");
|
||||
}
|
||||
}
|
||||
@ -124,6 +132,8 @@ public class RealtimeDataLogic implements ServiceLogic {
|
||||
return new ServiceResult(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private CacheRealtimeData translate(RealtimeData realtimeData) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException, InstantiationException {
|
||||
|
||||
Class<CacheRealtimeData> crdclz = CacheRealtimeData.class;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user