package com.szwl.service.impl;
import com.szwl.model.entity.TLocationCheck;
import com.szwl.mapper.TLocationCheckMapper;
import com.szwl.model.utils.YunPianSms;
import com.szwl.service.TLocationCheckService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.StringTokenizer;
/**
*
* 服务实现类
*
*
* @author wuhs
* @since 2023-12-25
*/
@Service
public class TLocationCheckServiceImpl extends ServiceImpl implements TLocationCheckService {
private static final String appid = "07784f5fedb508046c841b391005b7de";
@Override
public String locCheckNoMsg(TLocationCheck locationCheck, String clientId, String addr) {
String country = locationCheck.getCountry();
if (StringUtils.isEmpty(country)) {
return "国家不能为空";
}
boolean containsUserInput = isAddressInCountryList(addr, country);
if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
return "fail";
}
return "success";
}
@Override
public String locCheckMsg(TLocationCheck locationCheck, String clientId, String addr) throws IOException {
String country = locationCheck.getCountry();
if (StringUtils.isEmpty(country)) {
return "国家不能为空";
}
boolean containsUserInput = isAddressInCountryList(addr, country);
String phone = "18620242721";
// String phone1 = "13631231970"; // 基哥
String phone2 = "15018460394"; // 龙
String messages = "【申泽部门】设备编号:" + clientId + ",所在ip与设定位置不符,请及时查看。";
if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
YunPianSms.sendSms(appid, messages, phone);
YunPianSms.sendSms(appid, messages, phone2);
return "fail";
}
return "success";
}
public static boolean isAddressInCountryList(String addr, String country) {
// 使用StringTokenizer分割国家字符串
StringTokenizer tokenizer = new StringTokenizer(country, "、");
// 循环遍历国家列表
while (tokenizer.hasMoreTokens()) {
String singleCountry = tokenizer.nextToken();
// 如果地址包含当前国家,则返回true
if (addr.contains(singleCountry)) {
return true;
}
}
// 如果没有找到匹配的国家,则返回false
return false;
}
@Override
public String schLocCheck(TLocationCheck locationCheck, String clientId, String addr) {
String country = locationCheck.getCountry();
if (StringUtils.isEmpty(country)) {
return "国家不能为空";
}
boolean containsUserInput = isAddressInCountryList(addr, country);
if (!containsUserInput) { // 不包含,返回设备编号
return "{" + clientId + "}";
}
return "";
}
@Override
public void schSendMsg(String locErrorEq) throws IOException {
String phone = "18620242721";
// String phone1 = "13631231970"; // 基哥
String phone2 = "15018460394"; // 龙
String messages = "【申泽部门】设备编号:" + locErrorEq + ",所在ip与设定位置不符,请及时查看。";
YunPianSms.sendSms(appid, messages, phone);
// YunPianSms.sendSms(appid, messages, phone1);
YunPianSms.sendSms(appid, messages, phone2);
}
}