diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/common/HttpResult.java b/sec-beidou/src/main/java/com/imdroid/beidou/common/HttpResult.java index 150e7936..7c545821 100644 --- a/sec-beidou/src/main/java/com/imdroid/beidou/common/HttpResult.java +++ b/sec-beidou/src/main/java/com/imdroid/beidou/common/HttpResult.java @@ -32,6 +32,9 @@ public class HttpResult implements Serializable { public static String failed() { return result(HTTP_RSP_FAILED, "failed"); } + public static String failed(String msg) { + return result(HTTP_RSP_FAILED, msg); + } public static HttpResult success(Object data) { return new HttpResult(HTTP_RSP_OK, "ok", data); diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssDeviceController.java b/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssDeviceController.java index 08c0157a..fc86b8e9 100644 --- a/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssDeviceController.java +++ b/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssDeviceController.java @@ -161,10 +161,16 @@ public class GnssDeviceController extends BasicController{ tenantQueryWrapper.eq("name", device.getTenantname()); Tenant tenant = tenantMapper.selectOne(tenantQueryWrapper); if(tenant==null) return HttpResult.result(2, "invalid tenant"); + device.setTenantid(tenant.getId()); device.setUpdatetime(LocalDateTime.now()); device.setUpdateuser((String) session.getAttribute("login_user")); + if(device.getDeviceid().contains("-")){ + //批量增加 + return addBatch(session, device); + } + // 检测该对象是否已存在 QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("deviceid",device.getDeviceid()); @@ -211,6 +217,35 @@ public class GnssDeviceController extends BasicController{ } } + String addBatch(HttpSession session, GnssDevice devices){ + String ids = devices.getDeviceid(); + int pos = ids.indexOf("-"); + if(pos == -1){ + return HttpResult.failed("批量增加错误:设备编号格式错误"); + } + try { + int beginId = Integer.parseInt(ids.substring(0, pos)); + int endId = Integer.parseInt(ids.substring(pos + 1)); + devices.setCreatetime(LocalDateTime.now()); + devices.setCreateuser((String) session.getAttribute("login_user")); + devices.setSyn(false); + for(int id=beginId; id<=endId; id++){ + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("deviceid",id); + GnssDevice old_device = gnssDeviceMapper.selectOne(wrapper); + if(old_device != null) continue; + devices.setId(null); + devices.setDeviceid(String.valueOf(id)); + gnssDeviceMapper.insert(devices); + } + } + catch (Exception e){ + return HttpResult.failed("批量增加错误:"+e.getMessage()); + } + updateBasicGroupAssociatedNum(devices,null); + return HttpResult.ok(); + } + @PostMapping("/gnss/device/init_loc") @ResponseBody public JSONObject initLoc(@RequestParam String deviceid){ diff --git a/sec-beidou/src/main/resources/templates/page/table/gnss_add_dev.html b/sec-beidou/src/main/resources/templates/page/table/gnss_add_dev.html index a1b37c1e..73be45ea 100644 --- a/sec-beidou/src/main/resources/templates/page/table/gnss_add_dev.html +++ b/sec-beidou/src/main/resources/templates/page/table/gnss_add_dev.html @@ -21,7 +21,7 @@
- +