package com.szwl.service.impl;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.szwl.model.bo.R;
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 javax.annotation.Resource;
import java.io.IOException;
import java.util.Objects;
/**
*
* 服务实现类
*
*
* @author wuhs
* @since 2023-12-25
*/
@Service
public class TLocationCheckServiceImpl extends ServiceImpl implements TLocationCheckService {
// TLocationCheckService locationCheckService;
//
// public TLocationCheckServiceImpl(TLocationCheckService locationCheckService) {
// this.locationCheckService = locationCheckService;
// }
private static final String appid = "07784f5fedb508046c841b391005b7de";
@Override
public String locCheckNoMsg(TLocationCheck locationCheck, String clientId, String addr) {
String location = locationCheck.getLocation();
String country = locationCheck.getCountry();
if (StringUtils.isEmpty(country)) {
return "国家不能为空";
}
// 如果 pro,city,addr 中都不包含 country 或者 location,就是异常,发短信通知
boolean containsUserInput = true;
// location 为空 / 不为空
if (StringUtils.isEmpty(location)) {
containsUserInput = addr.contains(country);
} else {
containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
}
if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
return "fail";
}
return "success";
}
@Override
public String locCheckMsg(TLocationCheck locationCheck, String clientId, String addr) throws IOException {
String location = locationCheck.getLocation();
String country = locationCheck.getCountry();
if (StringUtils.isEmpty(country)) {
return "国家不能为空";
}
// ObjectMapper objectMapper = new ObjectMapper();
// JsonNode jsonNode = objectMapper.readTree(s);
// String addr = jsonNode.get("addr").asText();
// 如果 pro,city,addr 中都不包含 country 或者 location,就是异常,发短信通知
boolean containsUserInput = true;
// location 为空 / 不为空
// country 是中国 / 不是中国
if (StringUtils.isEmpty(location)) {
if (country.equals("中国")) {
return "国内必须精确到省市";
} else {
containsUserInput = addr.contains(country);
}
} else {
if (country.equals("中国")) {
containsUserInput = addr.contains(location);
} else {
containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
}
}
String phone = "18620242721";
String messages = "【申泽部门】设备编号:" + clientId + ",所在ip与设定位置不符,请及时查看。";
if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
YunPianSms.sendSms(appid, messages, phone);
return "fail";
}
return "success";
}
@Override
public String schLocCheck(TLocationCheck locationCheck, String clientId, String addr) {
String location = locationCheck.getLocation();
String country = locationCheck.getCountry();
if (StringUtils.isEmpty(country)) {
return "国家不能为空";
}
boolean containsUserInput = true;
// location 为空 / 不为空
// country 是中国 / 不是中国
if (StringUtils.isEmpty(location)) {
if (country.equals("中国")) {
return "国内必须精确到省";
} else {
containsUserInput = addr.contains(country);
}
} else {
if (country.equals("中国")) {
containsUserInput = addr.contains(location);
} else {
containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
}
}
if (!containsUserInput) { // 不包含,返回设备编号
return "{" + clientId + "}";
}
return "";
}
@Override
public void schSendMsg(String locErrorEq) throws IOException {
String phone = "18620242721";
String messages = "【申泽部门】设备编号:" + locErrorEq + ",所在ip与设定位置不符,请及时查看。";
YunPianSms.sendSms(appid, messages, phone);
}
}