TLocationCheckServiceImpl.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.szwl.service.impl;
  2. import cn.hutool.http.HttpUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.fasterxml.jackson.core.JsonProcessingException;
  6. import com.fasterxml.jackson.databind.JsonNode;
  7. import com.fasterxml.jackson.databind.ObjectMapper;
  8. import com.szwl.model.bo.R;
  9. import com.szwl.model.entity.TLocationCheck;
  10. import com.szwl.mapper.TLocationCheckMapper;
  11. import com.szwl.model.utils.YunPianSms;
  12. import com.szwl.service.TLocationCheckService;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import org.apache.commons.lang.StringUtils;
  15. import org.springframework.stereotype.Service;
  16. import javax.annotation.Resource;
  17. import java.io.IOException;
  18. import java.util.Objects;
  19. /**
  20. * <p>
  21. * 服务实现类
  22. * </p>
  23. *
  24. * @author wuhs
  25. * @since 2023-12-25
  26. */
  27. @Service
  28. public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper, TLocationCheck> implements TLocationCheckService {
  29. // TLocationCheckService locationCheckService;
  30. //
  31. // public TLocationCheckServiceImpl(TLocationCheckService locationCheckService) {
  32. // this.locationCheckService = locationCheckService;
  33. // }
  34. private static final String appid = "07784f5fedb508046c841b391005b7de";
  35. @Override
  36. public String locCheckNoMsg(TLocationCheck locationCheck, String clientId, String addr) {
  37. String location = locationCheck.getLocation();
  38. String country = locationCheck.getCountry();
  39. if (StringUtils.isEmpty(country)) {
  40. return "国家不能为空";
  41. }
  42. // 如果 pro,city,addr 中都不包含 country 或者 location,就是异常,发短信通知
  43. boolean containsUserInput = true;
  44. // location 为空 / 不为空
  45. if (StringUtils.isEmpty(location)) {
  46. containsUserInput = addr.contains(country);
  47. } else {
  48. containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
  49. }
  50. if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
  51. return "fail";
  52. }
  53. return "success";
  54. }
  55. @Override
  56. public String locCheckMsg(TLocationCheck locationCheck, String clientId, String addr) throws IOException {
  57. String location = locationCheck.getLocation();
  58. String country = locationCheck.getCountry();
  59. if (StringUtils.isEmpty(country)) {
  60. return "国家不能为空";
  61. }
  62. // ObjectMapper objectMapper = new ObjectMapper();
  63. // JsonNode jsonNode = objectMapper.readTree(s);
  64. // String addr = jsonNode.get("addr").asText();
  65. // 如果 pro,city,addr 中都不包含 country 或者 location,就是异常,发短信通知
  66. boolean containsUserInput = true;
  67. // location 为空 / 不为空
  68. // country 是中国 / 不是中国
  69. if (StringUtils.isEmpty(location)) {
  70. if (country.equals("中国")) {
  71. return "国内必须精确到省市";
  72. } else {
  73. containsUserInput = addr.contains(country);
  74. }
  75. } else {
  76. if (country.equals("中国")) {
  77. containsUserInput = addr.contains(location);
  78. } else {
  79. containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
  80. }
  81. }
  82. String phone = "18620242721";
  83. String messages = "【申泽部门】设备编号:" + clientId + ",所在ip与设定位置不符,请及时查看。";
  84. if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
  85. YunPianSms.sendSms(appid, messages, phone);
  86. return "fail";
  87. }
  88. return "success";
  89. }
  90. @Override
  91. public String schLocCheck(TLocationCheck locationCheck, String clientId, String addr) {
  92. String location = locationCheck.getLocation();
  93. String country = locationCheck.getCountry();
  94. if (StringUtils.isEmpty(country)) {
  95. return "国家不能为空";
  96. }
  97. boolean containsUserInput = true;
  98. // location 为空 / 不为空
  99. // country 是中国 / 不是中国
  100. if (StringUtils.isEmpty(location)) {
  101. if (country.equals("中国")) {
  102. return "国内必须精确到省";
  103. } else {
  104. containsUserInput = addr.contains(country);
  105. }
  106. } else {
  107. if (country.equals("中国")) {
  108. containsUserInput = addr.contains(location);
  109. } else {
  110. containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
  111. }
  112. }
  113. if (!containsUserInput) { // 不包含,返回设备编号
  114. return "{" + clientId + "}";
  115. }
  116. return "";
  117. }
  118. @Override
  119. public void schSendMsg(String locErrorEq) throws IOException {
  120. String phone = "18620242721";
  121. String messages = "【申泽部门】设备编号:" + locErrorEq + ",所在ip与设定位置不符,请及时查看。";
  122. YunPianSms.sendSms(appid, messages, phone);
  123. }
  124. }