|
@@ -0,0 +1,197 @@
|
|
|
|
+package com.szwl.controller;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
+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.bo.ResponseModel;
|
|
|
|
+import com.szwl.model.entity.TAdmin;
|
|
|
|
+import com.szwl.model.entity.TLocationCheck;
|
|
|
|
+import com.szwl.model.utils.YunPianSms;
|
|
|
|
+import com.szwl.service.TAdminService;
|
|
|
|
+import com.szwl.service.TLocationCheckService;
|
|
|
|
+import com.szwl.util.WhoIsUtil;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 前端控制器
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author wuhs
|
|
|
|
+ * @since 2023-12-06
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/tLocationCheck")
|
|
|
|
+public class TLocationCheckController {
|
|
|
|
+
|
|
|
|
+ TLocationCheckService locationCheckService;
|
|
|
|
+ TAdminService adminService;
|
|
|
|
+
|
|
|
|
+ public TLocationCheckController(TLocationCheckService locationCheckService, TAdminService adminService) {
|
|
|
|
+ this.locationCheckService = locationCheckService;
|
|
|
|
+ this.adminService = adminService;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "根据ip校验clientId设备位置")
|
|
|
|
+ @PostMapping("/ipCheck")
|
|
|
|
+ public ResponseModel<?> ipCheck(@RequestParam String clientId, @RequestParam String ip) throws IOException {
|
|
|
|
+ if (StringUtils.isBlank(clientId) || StringUtils.isBlank(ip)) {
|
|
|
|
+ return R.fail("参数不能为空");
|
|
|
|
+ }
|
|
|
|
+ // 根据 clientId 查设备的 location,country
|
|
|
|
+ LambdaQueryWrapper<TLocationCheck> lqw = Wrappers.lambdaQuery();
|
|
|
|
+ lqw.eq(TLocationCheck::getClientId, clientId);
|
|
|
|
+ TLocationCheck locationCheck = locationCheckService.getOne(lqw);
|
|
|
|
+ if (Objects.isNull(locationCheck)) {
|
|
|
|
+ return R.fail("生产部未录入改设备的位置信息");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String s = WhoIsUtil.getLocByIp(ip);
|
|
|
|
+
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
+ JsonNode jsonNode = objectMapper.readTree(s);
|
|
|
|
+ String pro = jsonNode.get("pro").asText();
|
|
|
|
+ String proCode = jsonNode.get("proCode").asText();
|
|
|
|
+ String city = jsonNode.get("city").asText();
|
|
|
|
+ String cityCode = jsonNode.get("cityCode").asText();
|
|
|
|
+ String region = jsonNode.get("region").asText();
|
|
|
|
+ String regionCode = jsonNode.get("regionCode").asText();
|
|
|
|
+ String regionNames = jsonNode.get("regionNames").asText();
|
|
|
|
+ String addr = jsonNode.get("addr").asText();
|
|
|
|
+ String err = jsonNode.get("err").asText();
|
|
|
|
+
|
|
|
|
+ locationCheck.setIp(ip);
|
|
|
|
+ locationCheck.setPro(pro);
|
|
|
|
+ locationCheck.setProCode(proCode);
|
|
|
|
+ locationCheck.setCity(city);
|
|
|
|
+ locationCheck.setCityCode(cityCode);
|
|
|
|
+ locationCheck.setRegion(region);
|
|
|
|
+ locationCheck.setRegionCode(regionCode);
|
|
|
|
+ locationCheck.setRegionNames(regionNames);
|
|
|
|
+ locationCheck.setAddr(addr);
|
|
|
|
+ locationCheck.setErr(err);
|
|
|
|
+
|
|
|
|
+ locationCheckService.saveOrUpdate(locationCheck);
|
|
|
|
+
|
|
|
|
+ String result = locationCheckService.locCheckMsg(locationCheck, clientId, ip, s);
|
|
|
|
+
|
|
|
|
+ return R.ok(result);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "修改录入的位置信息")
|
|
|
|
+ @PostMapping("/updateLocInfo")
|
|
|
|
+ public ResponseModel<?> updateLocInfo(@RequestBody TLocationCheck locationCheck) {
|
|
|
|
+ if (Objects.isNull(locationCheck)) {
|
|
|
|
+ return R.fail("参数不能为空");
|
|
|
|
+ }
|
|
|
|
+// String phone = locationCheck.getPhone();
|
|
|
|
+// String username = locationCheck.getUsername();
|
|
|
|
+// String clientId = locationCheck.getClientId();
|
|
|
|
+// String name = locationCheck.getName();
|
|
|
|
+// String location = locationCheck.getLocation();
|
|
|
|
+// String country = locationCheck.getCountry();
|
|
|
|
+//
|
|
|
|
+// if (Objects.isNull(clientId)) {
|
|
|
|
+// return R.fail("设备唯一码不能为空");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// LambdaQueryWrapper<TAdmin> lqw = Wrappers.lambdaQuery();
|
|
|
|
+// lqw.eq(TAdmin::getUsername, username);
|
|
|
|
+// TAdmin admin = adminService.getOne(lqw);
|
|
|
|
+// if (Objects.isNull(admin)) {
|
|
|
|
+// return R.fail("adminId账号不存在");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// LambdaQueryWrapper<TLocationCheck> wrapper = Wrappers.lambdaQuery();
|
|
|
|
+// wrapper.eq(TLocationCheck::getClientId,clientId);
|
|
|
|
+// List<TLocationCheck> checks = locationCheckService.list(wrapper);
|
|
|
|
+// TLocationCheck tLocationCheck = checks.get(0);
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// Long adminId = admin.getId();
|
|
|
|
+//// String phone1 = admin.getPhone();
|
|
|
|
+//// if (!Objects.equals(phone1, phone)) {
|
|
|
|
+//// return R.fail("手机号码有误");
|
|
|
|
+//// }
|
|
|
|
+// String name1 = admin.getName();
|
|
|
|
+// if (!Objects.equals(name1, name)) {
|
|
|
|
+// return R.fail("姓名有误");
|
|
|
|
+// }
|
|
|
|
+return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "录入位置信息")
|
|
|
|
+ @PostMapping("/inputLocInfo")
|
|
|
|
+ public ResponseModel<?> inputLocInfo(@RequestBody TLocationCheck locationCheck) {
|
|
|
|
+ if (Objects.isNull(locationCheck)) {
|
|
|
|
+ return R.fail("参数不能为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String phone = locationCheck.getPhone();
|
|
|
|
+ String username = locationCheck.getUsername();
|
|
|
|
+ String clientId = locationCheck.getClientId();
|
|
|
|
+ String name = locationCheck.getName();
|
|
|
|
+ String location = locationCheck.getLocation();
|
|
|
|
+ String country = locationCheck.getCountry();
|
|
|
|
+
|
|
|
|
+ if (Objects.isNull(clientId)) {
|
|
|
|
+ return R.fail("设备唯一码不能为空");
|
|
|
|
+ }
|
|
|
|
+ LambdaQueryWrapper<TLocationCheck> wrapper = Wrappers.lambdaQuery();
|
|
|
|
+ wrapper.eq(TLocationCheck::getClientId,clientId);
|
|
|
|
+ List<TLocationCheck> checks = locationCheckService.list(wrapper);
|
|
|
|
+ if (checks.size() > 0) {
|
|
|
|
+ return R.fail("此设备信息已录入");
|
|
|
|
+ }
|
|
|
|
+ LambdaQueryWrapper<TAdmin> lqw = Wrappers.lambdaQuery();
|
|
|
|
+ lqw.eq(TAdmin::getUsername, username);
|
|
|
|
+ TAdmin admin = adminService.getOne(lqw);
|
|
|
|
+ if (Objects.isNull(admin)) {
|
|
|
|
+ return R.fail("adminId账号不存在");
|
|
|
|
+ }
|
|
|
|
+ Long adminId = admin.getId();
|
|
|
|
+// String phone1 = admin.getPhone();
|
|
|
|
+// if (!Objects.equals(phone1, phone)) {
|
|
|
|
+// return R.fail("手机号码有误");
|
|
|
|
+// }
|
|
|
|
+ String name1 = admin.getName();
|
|
|
|
+ if (!Objects.equals(name1, name)) {
|
|
|
|
+ return R.fail("姓名有误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TLocationCheck tLocationCheck = new TLocationCheck();
|
|
|
|
+// String uuid = IdUtil.randomUUID();
|
|
|
|
+ String uuid = IdUtil.simpleUUID();
|
|
|
|
+ tLocationCheck.setId(uuid);
|
|
|
|
+ tLocationCheck.setAdminId(adminId);
|
|
|
|
+ tLocationCheck.setPhone(phone);
|
|
|
|
+ tLocationCheck.setUsername(username);
|
|
|
|
+ tLocationCheck.setClientId(clientId);
|
|
|
|
+ tLocationCheck.setName(name);
|
|
|
|
+ tLocationCheck.setLocation(location);
|
|
|
|
+ tLocationCheck.setCountry(country);
|
|
|
|
+
|
|
|
|
+ locationCheckService.save(tLocationCheck);
|
|
|
|
+
|
|
|
|
+ return R.ok("设备出厂信息录入成功");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|