TLocationCheckServiceImpl.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package com.szwl.service.impl;
  2. import com.szwl.model.entity.TLocationCheck;
  3. import com.szwl.mapper.TLocationCheckMapper;
  4. import com.szwl.model.utils.YunPianSms;
  5. import com.szwl.service.TLocationCheckService;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import org.apache.commons.lang.StringUtils;
  8. import org.springframework.stereotype.Service;
  9. import java.io.IOException;
  10. import java.util.StringTokenizer;
  11. /**
  12. * <p>
  13. * 服务实现类
  14. * </p>
  15. *
  16. * @author wuhs
  17. * @since 2023-12-25
  18. */
  19. @Service
  20. public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper, TLocationCheck> implements TLocationCheckService {
  21. private static final String appid = "07784f5fedb508046c841b391005b7de";
  22. @Override
  23. public String locCheckNoMsg(TLocationCheck locationCheck, String clientId, String addr) {
  24. String country = locationCheck.getCountry();
  25. if (StringUtils.isEmpty(country)) {
  26. return "国家不能为空";
  27. }
  28. boolean containsUserInput = isAddressInCountryList(addr, country);
  29. if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
  30. return "fail";
  31. }
  32. return "success";
  33. }
  34. @Override
  35. public String locCheckMsg(TLocationCheck locationCheck, String clientId, String addr) throws IOException {
  36. String country = locationCheck.getCountry();
  37. if (StringUtils.isEmpty(country)) {
  38. return "国家不能为空";
  39. }
  40. boolean containsUserInput = isAddressInCountryList(addr, country);
  41. String phone = "18620242721";
  42. // String phone1 = "13631231970"; // 基哥
  43. String phone2 = "15018460394"; // 龙
  44. String messages = "【申泽部门】设备编号:" + clientId + ",所在ip与设定位置不符,请及时查看。";
  45. if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
  46. YunPianSms.sendSms(appid, messages, phone);
  47. YunPianSms.sendSms(appid, messages, phone2);
  48. return "fail";
  49. }
  50. return "success";
  51. }
  52. public static boolean isAddressInCountryList(String addr, String country) {
  53. // 使用StringTokenizer分割国家字符串
  54. StringTokenizer tokenizer = new StringTokenizer(country, "、");
  55. // 循环遍历国家列表
  56. while (tokenizer.hasMoreTokens()) {
  57. String singleCountry = tokenizer.nextToken();
  58. // 如果地址包含当前国家,则返回true
  59. if (addr.contains(singleCountry)) {
  60. return true;
  61. }
  62. }
  63. // 如果没有找到匹配的国家,则返回false
  64. return false;
  65. }
  66. @Override
  67. public String schLocCheck(TLocationCheck locationCheck, String clientId, String addr) {
  68. String country = locationCheck.getCountry();
  69. if (StringUtils.isEmpty(country)) {
  70. return "国家不能为空";
  71. }
  72. boolean containsUserInput = isAddressInCountryList(addr, country);
  73. if (!containsUserInput) { // 不包含,返回设备编号
  74. return "{" + clientId + "}";
  75. }
  76. return "";
  77. }
  78. @Override
  79. public void schSendMsg(String locErrorEq) throws IOException {
  80. String phone = "18620242721";
  81. // String phone1 = "13631231970"; // 基哥
  82. String phone2 = "15018460394"; // 龙
  83. String messages = "【申泽部门】设备编号:" + locErrorEq + ",所在ip与设定位置不符,请及时查看。";
  84. YunPianSms.sendSms(appid, messages, phone);
  85. // YunPianSms.sendSms(appid, messages, phone1);
  86. YunPianSms.sendSms(appid, messages, phone2);
  87. }
  88. }