feat: 增加rabchaser的断网和恢复上网

dev
huangfeng 2 months ago
parent d259368e42
commit 6ab6bb2779

@ -44,6 +44,22 @@ public class SmsController extends BaseController {
return ResponseReult.success(obj);
}
@PostMapping("netDown")
@ApiOperation("断网")
@Log(title = "断网", type = "断网")
public ResponseReult<String> netDown(@RequestBody SmsModel model) {
service.netDown(model);
return ResponseReult.success("OK");
}
@PostMapping("netUp")
@ApiOperation("恢复上网")
@Log(title = "恢复上网", type = "恢复上网")
public ResponseReult<String> netUp(@RequestBody SmsModel model) {
service.netUp(model);
return ResponseReult.success("OK");
}
@GetMapping("getAuth")
@ApiOperation("查询授权")
public ResponseReult<HashMap<String, String>> getAuth() {

@ -95,4 +95,74 @@ public class SmsAdapter {
}
return result;
}
public void netDown(Integer type, List<String> iccidList) {
String net = "";
try {
if (Constants.NetType_Dahan.equals(type)) {
net = "dahan";
throw new ApiException("暂不支持大汉");
} else if (Constants.NetType_Rabchaser.equals(type)) {
net = "rabchaser";
List<String> list = new ArrayList<>();
for (String iccid : iccidList) {
list.add(iccid);
if (list.size() > 9) {
rabchaserApi.netDown(list);
list.clear();
try {
Thread.sleep(500);
} catch (InterruptedException ignore) {
}
}
}
if (list.size() > 0) {
rabchaserApi.netDown(list);
}
} else if (Constants.NetType_M2M10086.equals(type)) {
net = "m2m10086";
throw new ApiException("暂不支持公田m2m10086");
} else if (Constants.NetType_LWWLKJ.equals(type)) {
net = "lwwlkj";
throw new ApiException("暂不支持安徽");
}
} catch (ApiException e) {
throw new ApiException(net + e.getMessage());
}
}
public void netUp(Integer type, List<String> iccidList) {
String net = "";
try {
if (Constants.NetType_Dahan.equals(type)) {
net = "dahan";
throw new ApiException("暂不支持大汉");
} else if (Constants.NetType_Rabchaser.equals(type)) {
net = "rabchaser";
List<String> list = new ArrayList<>();
for (String iccid : iccidList) {
list.add(iccid);
if (list.size() > 9) {
rabchaserApi.netUp(list);
list.clear();
try {
Thread.sleep(500);
} catch (InterruptedException ignore) {
}
}
}
if (list.size() > 0) {
rabchaserApi.netUp(list);
}
} else if (Constants.NetType_M2M10086.equals(type)) {
net = "m2m10086";
throw new ApiException("暂不支持公田m2m10086");
} else if (Constants.NetType_LWWLKJ.equals(type)) {
net = "lwwlkj";
throw new ApiException("暂不支持安徽");
}
} catch (ApiException e) {
throw new ApiException(net + e.getMessage());
}
}
}

@ -85,4 +85,38 @@ public class RabchaserApi {
throw new ApiException("查询短信记录异常," + e.getMessage());
}
}
public void netDown(List<String> iccidList) {
String url = "/simCards/netDown";
try {
Map<String, String> headMap = this.signHead(url);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("iccid", iccidList);
String json = HttpClient.post(baseUrl + url, dataMap, headMap);
log.info("断网完成:" + json);
} catch (ApiException e) {
throw e;
} catch (Exception e) {
log.error("断网异常.", e);
throw new ApiException("断网异常," + e.getMessage());
}
}
public void netUp(List<String> iccidList) {
String url = "/simCards/netUp";
try {
Map<String, String> headMap = this.signHead(url);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("iccid", iccidList);
String json = HttpClient.post(baseUrl + url, dataMap, headMap);
log.info("恢复上网完成:" + json);
} catch (ApiException e) {
throw e;
} catch (Exception e) {
log.error("恢复上网异常.", e);
throw new ApiException("恢复上网异常," + e.getMessage());
}
}
}

@ -38,7 +38,28 @@ public class SmsServiceImpl implements SmsService {
List<String> rabchaserList = new ArrayList<>();
List<String> m2mList = new ArrayList<>();
List<String> lkjList = new ArrayList<>();
for (Integer termId : model.getTermIdList()) {
this.buildiccidList(dahanList, rabchaserList, m2mList, lkjList,
model.getTermIdList());
if (!CollectionUtils.isEmpty(dahanList)) {
smsAdapter.sendSms(Constants.NetType_Dahan, dahanList, model.getContent());
}
if (!CollectionUtils.isEmpty(rabchaserList)) {
smsAdapter.sendSms(Constants.NetType_Rabchaser, rabchaserList, model.getContent());
}
if (!CollectionUtils.isEmpty(m2mList)) {
smsAdapter.sendSms(Constants.NetType_M2M10086, m2mList, model.getContent());
}
if (!CollectionUtils.isEmpty(lkjList)) {
smsAdapter.sendSms(Constants.NetType_LWWLKJ, lkjList, model.getContent());
}
}
private void buildiccidList(List<String> dahanList, List<String> rabchaserList,
List<String> m2mList, List<String> lkjList,
List<Integer> termIdList) {
for (Integer termId : termIdList) {
Terminals term = newCacheService.getTerminal(termId);
if (term == null) {
throw new ApiException(termId + "该装置不存在");
@ -92,19 +113,6 @@ public class SmsServiceImpl implements SmsService {
throw new ApiException(termId + "该装置的运营商类型未配置");
}
}
if (!CollectionUtils.isEmpty(dahanList)) {
smsAdapter.sendSms(Constants.NetType_Dahan, dahanList, model.getContent());
}
if (!CollectionUtils.isEmpty(rabchaserList)) {
smsAdapter.sendSms(Constants.NetType_Rabchaser, rabchaserList, model.getContent());
}
if (!CollectionUtils.isEmpty(m2mList)) {
smsAdapter.sendSms(Constants.NetType_M2M10086, m2mList, model.getContent());
}
if (!CollectionUtils.isEmpty(lkjList)) {
smsAdapter.sendSms(Constants.NetType_LWWLKJ, lkjList, model.getContent());
}
}
@Override
@ -162,4 +170,52 @@ public class SmsServiceImpl implements SmsService {
throw new ApiException(termId + "该装置的运营商类型未配置");
}
}
@Override
public void netDown(SmsModel model) {
List<String> dahanList = new ArrayList<>();
List<String> rabchaserList = new ArrayList<>();
List<String> m2mList = new ArrayList<>();
List<String> lkjList = new ArrayList<>();
this.buildiccidList(dahanList, rabchaserList, m2mList, lkjList,
model.getTermIdList());
if (!CollectionUtils.isEmpty(dahanList)) {
smsAdapter.netDown(Constants.NetType_Dahan, dahanList);
}
if (!CollectionUtils.isEmpty(rabchaserList)) {
smsAdapter.netDown(Constants.NetType_Rabchaser, rabchaserList);
}
if (!CollectionUtils.isEmpty(m2mList)) {
smsAdapter.netDown(Constants.NetType_M2M10086, m2mList);
}
if (!CollectionUtils.isEmpty(lkjList)) {
smsAdapter.netDown(Constants.NetType_LWWLKJ, lkjList);
}
}
@Override
public void netUp(SmsModel model) {
List<String> dahanList = new ArrayList<>();
List<String> rabchaserList = new ArrayList<>();
List<String> m2mList = new ArrayList<>();
List<String> lkjList = new ArrayList<>();
this.buildiccidList(dahanList, rabchaserList, m2mList, lkjList,
model.getTermIdList());
if (!CollectionUtils.isEmpty(dahanList)) {
smsAdapter.netUp(Constants.NetType_Dahan, dahanList);
}
if (!CollectionUtils.isEmpty(rabchaserList)) {
smsAdapter.netUp(Constants.NetType_Rabchaser, rabchaserList);
}
if (!CollectionUtils.isEmpty(m2mList)) {
smsAdapter.netUp(Constants.NetType_M2M10086, m2mList);
}
if (!CollectionUtils.isEmpty(lkjList)) {
smsAdapter.netUp(Constants.NetType_LWWLKJ, lkjList);
}
}
}

@ -9,4 +9,8 @@ public interface SmsService {
void sendSms(SmsModel model);
SmsReturn listSms(Integer termId);
void netDown(SmsModel model);
void netUp(SmsModel model);
}

Loading…
Cancel
Save