TLocationCheckController.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. package com.szwl.controller;
  2. import cn.hutool.core.util.IdUtil;
  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.szwl.model.bo.R;
  7. import com.szwl.model.bo.ResponseModel;
  8. import com.szwl.model.entity.TLocationCheck;
  9. import com.szwl.service.TAdminService;
  10. import com.szwl.service.TLocationCheckService;
  11. import com.szwl.util.WhoIsUtil;
  12. import io.swagger.annotations.ApiOperation;
  13. import org.apache.commons.lang.StringUtils;
  14. import org.springframework.web.bind.annotation.*;
  15. import java.util.*;
  16. /**
  17. * <p>
  18. * 前端控制器
  19. * </p>
  20. *
  21. * @author wuhs
  22. * @since 2023-12-11
  23. */
  24. @RestController
  25. @RequestMapping("/tLocationCheck")
  26. public class TLocationCheckController {
  27. TLocationCheckService locationCheckService;
  28. TAdminService adminService;
  29. public TLocationCheckController(TLocationCheckService locationCheckService,
  30. TAdminService adminService) {
  31. this.locationCheckService = locationCheckService;
  32. this.adminService = adminService;
  33. }
  34. @ApiOperation(value = "获取定位信息")
  35. @GetMapping("/getLocInfo")
  36. public ResponseModel<?> getLocInfo(String clientId) {
  37. if (StringUtils.isEmpty(clientId)) {
  38. return R.fail("设备id不能为空");
  39. }
  40. // 根据设备id查询位置信息
  41. LambdaQueryWrapper<TLocationCheck> lqw = Wrappers.lambdaQuery();
  42. lqw.eq(TLocationCheck::getClientId, clientId);
  43. TLocationCheck locationCheck = locationCheckService.getOne(lqw);
  44. if (Objects.nonNull(locationCheck)) {
  45. HashMap<String, String> locationMap = new HashMap<>();
  46. String country = locationCheck.getCountry();
  47. String username = locationCheck.getUsername();
  48. String name = locationCheck.getName();
  49. String phone = locationCheck.getPhone();
  50. String longitude = locationCheck.getLongitude();
  51. String latitude = locationCheck.getLatitude();
  52. String addr = locationCheck.getAddr();
  53. String modUsername = locationCheck.getModUsername();
  54. String modName = locationCheck.getModName();
  55. String modPhone = locationCheck.getModPhone();
  56. String message = locationCheck.getMessage();
  57. locationMap.put("country", country); // 录入国家
  58. locationMap.put("username", username); // 账号用户名
  59. locationMap.put("name", name); // 录入人姓名
  60. locationMap.put("phone", phone); // 录入人电话
  61. locationMap.put("longitude", longitude); // 经度
  62. locationMap.put("latitude", latitude); // 纬度
  63. locationMap.put("address", addr); // 反编译的地址
  64. locationMap.put("modUsername", modUsername); // 修改人账号
  65. locationMap.put("modName", modName); // 修改人姓名
  66. locationMap.put("modPhone", modPhone); // 修改人电话
  67. locationMap.put("message", message); // 修改原因
  68. return R.ok(locationMap);
  69. }
  70. return R.fail("地区信息未录入");
  71. }
  72. @ApiOperation(value = "根据ip校验clientId设备定位")
  73. @PostMapping("/ipCheck")
  74. public ResponseModel<?> ipCheck(@RequestParam String clientId, @RequestParam String ip) {
  75. if (StringUtils.isBlank(clientId) || StringUtils.isBlank(ip)) {
  76. return R.fail("参数不能为空");
  77. }
  78. // 根据 clientId 查设备的 location,country
  79. LambdaQueryWrapper<TLocationCheck> lqw = Wrappers.lambdaQuery();
  80. lqw.eq(TLocationCheck::getClientId, clientId);
  81. TLocationCheck locationCheck = locationCheckService.getOne(lqw);
  82. if (Objects.isNull(locationCheck)) {
  83. return R.fail("生产部未录入改设备的位置信息");
  84. }
  85. locationCheck.setIp(ip);
  86. locationCheck.setModifyTime(new Date());
  87. String addr = WhoIsUtil.getLocByIp(ip);
  88. String result = locationCheckService.locCheckNoMsg(locationCheck, clientId, addr);
  89. if ("fail".equals(result)) {
  90. locationCheck.setErr("不匹配");
  91. }
  92. locationCheckService.updateById(locationCheck);
  93. return R.ok(result);
  94. }
  95. @ApiOperation(value = "修改定位信息")
  96. @PostMapping("/updateLocInfo")
  97. public ResponseModel<?> updateLocInfo(@RequestBody TLocationCheck locationCheck) {
  98. if (Objects.isNull(locationCheck)) {
  99. return R.fail("参数不能为空");
  100. }
  101. // 售后部同事修改的信息:姓名,电话,username,clientId,国家
  102. String modUsername = locationCheck.getModUsername();
  103. Set<String> allowedUsernames = new HashSet<>(
  104. Arrays.asList("shouhoumi", "sysMgtAcc", "jiang123", "ethan"));
  105. if (!allowedUsernames.contains(modUsername)) {
  106. return R.fail("该账号无权修改");
  107. }
  108. String modName = locationCheck.getModName();
  109. String modPhone = locationCheck.getModPhone();
  110. String clientId = locationCheck.getClientId();
  111. String country = locationCheck.getCountry();
  112. String message = locationCheck.getMessage();
  113. if (Objects.isNull(clientId)) {
  114. return R.fail("设备唯一码不能为空");
  115. }
  116. LambdaQueryWrapper<TLocationCheck> wrapper = Wrappers.lambdaQuery();
  117. wrapper.eq(TLocationCheck::getClientId, clientId);
  118. List<TLocationCheck> checks = locationCheckService.list(wrapper);
  119. TLocationCheck tLocationCheck = checks.get(0);
  120. tLocationCheck.setModifyTime(new Date());
  121. tLocationCheck.setModName(modName);
  122. tLocationCheck.setModPhone(modPhone);
  123. tLocationCheck.setModUsername(modUsername);
  124. tLocationCheck.setClientId(clientId);
  125. tLocationCheck.setCountry(country);
  126. tLocationCheck.setMessage(message);
  127. locationCheckService.updateById(tLocationCheck);
  128. return R.ok("修改成功");
  129. }
  130. @ApiOperation(value = "录入定位信息")
  131. @PostMapping("/inputLocInfo")
  132. public ResponseModel<?> inputLocInfo(@RequestBody TLocationCheck locationCheck) {
  133. if (Objects.isNull(locationCheck)) {
  134. return R.fail("参数不能为空");
  135. }
  136. String name = locationCheck.getName();
  137. String phone = locationCheck.getPhone();
  138. String username = locationCheck.getUsername();
  139. String clientId = locationCheck.getClientId();
  140. String country = locationCheck.getCountry(); // 国家
  141. if (Objects.isNull(clientId)) {
  142. return R.fail("设备唯一码不能为空");
  143. }
  144. LambdaQueryWrapper<TLocationCheck> wrapper = Wrappers.lambdaQuery();
  145. wrapper.eq(TLocationCheck::getClientId, clientId);
  146. List<TLocationCheck> checks = locationCheckService.list(wrapper);
  147. if (checks.size() > 0) {
  148. return R.fail("此设备信息已录入");
  149. }
  150. Set<String> allowedUsers = new HashSet<>(
  151. Arrays.asList("sysMgtAcc", "jiang123", "shouhou121", "shouhou369", "shouhou397",
  152. "shouhoumi", "zhl123", "ethan", "debugUser"));
  153. if (!allowedUsers.contains(username)) {
  154. return R.fail("该账号无权操作");
  155. }
  156. TLocationCheck tLocationCheck = new TLocationCheck();
  157. String uuid = IdUtil.simpleUUID();
  158. tLocationCheck.setId(uuid);
  159. tLocationCheck.setCreateTime(new Date());
  160. tLocationCheck.setName(name);
  161. tLocationCheck.setPhone(phone);
  162. tLocationCheck.setUsername(username);
  163. tLocationCheck.setClientId(clientId);
  164. tLocationCheck.setCountry(country);
  165. locationCheckService.save(tLocationCheck);
  166. return R.ok("设备出厂信息录入成功");
  167. }
  168. }