12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author wuhs
- * @since 2023-12-11
- */
- @Service
- public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper, TLocationCheck> implements TLocationCheckService {
- // TLocationCheckService locationCheckService;
- //
- // public TLocationCheckServiceImpl(TLocationCheckService locationCheckService) {
- // this.locationCheckService = locationCheckService;
- // }
- private static final String appid = "07784f5fedb508046c841b391005b7de";
- @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);
- }
- }
- String phone = "18620242721";
- String messages = "【申泽部门】设备编号:" + clientId + ",所在ip与设定位置不符,请及时查看。";
- if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
- YunPianSms.sendSms(appid, messages, phone);
- return "fail";
- }
- return "success";
- }
- }
|