Commit 5e97f62f47d0ad6fd9f2cdb3d8ef2ac690c09011

Authored by Liu Haoyu
1 parent bb33dcc2

问题处理;

src/main/java/com/objecteye/common/GeneralContent.java
... ... @@ -33,6 +33,8 @@ public class GeneralContent {
33 33 */
34 34 public final static Map<String, String> DOCKER_SH_OUT_MAP = new HashMap<>();
35 35  
  36 + public final static Map<String, String> DOCKER_CONFIG_PARAMS_MAP = new HashMap<>();
  37 +
36 38 static {
37 39 MODULE_MAP.put("arp_cache", "/shell_files/arp_cache.sh");
38 40 MODULE_MAP.put("bandwidth", "/shell_files/bandwidth.sh");
... ... @@ -80,5 +82,19 @@ public class GeneralContent {
80 82 DOCKER_SH_OUT_MAP.put("9", "容器不存在");
81 83 DOCKER_SH_OUT_MAP.put("10", "端口已经被占用");
82 84 DOCKER_SH_OUT_MAP.put("11", "未知错误");
  85 +
  86 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_car_win_detect_config", "车窗检测");
  87 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_recg_config", "车型识别");
  88 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_plate_det_recg_config", "车牌检测识别");
  89 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_color_config", "车辆颜色识别");
  90 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_pendant_det_config", "车辆属性识别");
  91 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_illegal_config", "车违规行为检测");
  92 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_feature_config", "车辆特征提取");
  93 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_special_config", "特殊品类车型识别");
  94 + DOCKER_CONFIG_PARAMS_MAP.put("gpuId", "显卡号");
  95 + DOCKER_CONFIG_PARAMS_MAP.put("log", "日志");
  96 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_image_quality_config", "车辆图像清晰度识别");
  97 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_motor_tricycle_analysis_config", "摩托车是否载人/摩托车驾驶人是否戴头盔/农用车是否载人");
  98 + DOCKER_CONFIG_PARAMS_MAP.put("vehicle_stain_vp_config", "车牌是否遮挡");
83 99 }
84 100 }
... ...
src/main/java/com/objecteye/service/IBackGroundService.java
... ... @@ -99,4 +99,9 @@ public interface IBackGroundService {
99 99 * @return 操作状态
100 100 */
101 101 JSONObject serviceAction(Integer configId, String action);
  102 +
  103 + /**
  104 + * 每分钟更新一次所有服务的状态
  105 + */
  106 + void serviceStatusUpdater();
102 107 }
... ...
src/main/java/com/objecteye/service/impl/BackGroundServiceImpl.java
... ... @@ -230,41 +230,29 @@ public class BackGroundServiceImpl implements IBackGroundService {
230 230 public JSONObject sdkController(Map<String, Object> requestMap) {
231 231 String configId = (String) requestMap.get("configId");
232 232 String uri = "/vehicle/loadConfig";
233   - String configItemName = "ip,port";
  233 + String configItemName = "http,port";
234 234 List<SyServiceConfigItem> syServiceConfigItems =
235 235 syServiceConfigItemMapper.selectByExample(SyServiceConfigItemExample.newAndCreateCriteria()
236 236 .andConfigIdEqualTo(Integer.valueOf(configId)).andItemNameIn(Arrays.asList(configItemName.split(",")))
237 237 .example());
238   - String ip = null;
  238 + String http = null;
239 239 String port = null;
240 240 for (SyServiceConfigItem syServiceConfigItem : syServiceConfigItems) {
241   - if ("ip".equals(syServiceConfigItem.getItemName())) {
242   - ip = syServiceConfigItem.getItemValue();
  241 + if ("http".equals(syServiceConfigItem.getItemName())) {
  242 + http = syServiceConfigItem.getItemValue();
243 243 } else if ("port".equals(syServiceConfigItem.getItemName())) {
244 244 port = syServiceConfigItem.getItemValue();
245 245 }
246 246 }
247 247 JSONObject resultObj = new JSONObject();
248   - if (ip == null || port == null) {
  248 + if (http == null || port == null) {
249 249 resultObj.put("error", "服务配置缺少ip或端口信息");
250 250 return resultObj;
251 251 }
252   - String params = "vehicle_car_win_detect_config," +
253   - "vehicle_recg_config," +
254   - "vehicle_plate_det_recg_config," +
255   - "vehicle_color_config," +
256   - "vehicle_pendant_det_config," +
257   - "vehicle_illegal_config," +
258   - "vehicle_feature_config," +
259   - "vehicle_special_config," +
260   - "gpuId," +
261   - "log," +
262   - "vehicle_image_quality_config," +
263   - "vehicle_motor_tricycle_analysis_config,port," +
264   - "vehicle_stain_vp_config";
  252 +
265 253 List<String> errorList = new ArrayList<>();
266 254 Map<String, String> restRequestMap = new HashMap<>();
267   - for (String param : params.split(",")) {
  255 + for (String param : GeneralContent.DOCKER_CONFIG_PARAMS_MAP.keySet()) {
268 256 if (!requestMap.containsKey(param)) {
269 257 errorList.add(param + "参数不能为空");
270 258 } else {
... ... @@ -276,7 +264,7 @@ public class BackGroundServiceImpl implements IBackGroundService {
276 264 return resultObj;
277 265 }
278 266  
279   - ResponseEntity<String> responseEntity = restTemplate.postForEntity(ip + ":" + port + uri, restRequestMap, String.class);
  267 + ResponseEntity<String> responseEntity = restTemplate.postForEntity(http + ":" + port + uri, restRequestMap, String.class);
280 268 resultObj = JSON.parseObject(responseEntity.getBody());
281 269 return resultObj;
282 270 }
... ... @@ -369,7 +357,7 @@ public class BackGroundServiceImpl implements IBackGroundService {
369 357 @Override
370 358 public PageResult serviceQuery(Integer currentPage, Integer pageVolume) {
371 359 List<SyServiceConfig> syServiceConfigs = syServiceConfigMapper.selectByExample(SyServiceConfigExample.newAndCreateCriteria()
372   - .example().page(currentPage, currentPage));
  360 + .example().page(currentPage, pageVolume));
373 361 long total = syServiceConfigMapper.countByExample(SyServiceConfigExample.newAndCreateCriteria().example());
374 362 if (total == 0) {
375 363 return new PageResult<>(0, new ArrayList<>());
... ... @@ -390,7 +378,7 @@ public class BackGroundServiceImpl implements IBackGroundService {
390 378 vSyServiceMainTable.setUpdateTime(DateUtil.format(new Date(syServiceConfig.getUpdateTime()), "yyyy-MM-dd HH:mm:ss"));
391 379 vSyServiceMainTable.setConfigId(syServiceConfig.getId());
392 380  
393   - String ip = null;
  381 + String http = null;
394 382 String port = null;
395 383 List<String> otherParams = new ArrayList<>();
396 384 for (SyServiceConfigItem syServiceConfigItem : configItems) {
... ... @@ -400,18 +388,19 @@ public class BackGroundServiceImpl implements IBackGroundService {
400 388 vSyServiceMainTable.setGpuId(itemValue);
401 389 } else if ("port".equals(itemName)) {
402 390 port = itemValue;
403   - } else if ("ip".equals(itemName)) {
404   - ip = itemValue;
  391 + } else if ("http".equals(itemName)) {
  392 + http = itemValue;
405 393 } else {
406   - otherParams.add(itemName);
  394 + otherParams.add(GeneralContent.DOCKER_CONFIG_PARAMS_MAP.get(itemName));
407 395 }
408 396 }
409   - vSyServiceMainTable.setPort(ip + ":" + port);
  397 + vSyServiceMainTable.setPort(http + ":" + port);
410 398 vSyServiceMainTable.setItems(String.join(",", otherParams));
411   - vSyServiceMainTable.setStatus((String) redisTemplate.opsForHash().get(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, syServiceConfig.getId()));
  399 + String status = (String) redisTemplate.opsForHash().get(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, syServiceConfig.getId());
  400 + vSyServiceMainTable.setStatus(status == null ? "0" : status);
412 401 resultList.add(vSyServiceMainTable);
413 402 }
414   - return new PageResult<>((int) Math.ceil((double) total / pageVolume), resultList);
  403 + return new PageResult<>(total, resultList);
415 404 }
416 405  
417 406 /**
... ... @@ -435,6 +424,21 @@ public class BackGroundServiceImpl implements IBackGroundService {
435 424 }
436 425  
437 426 /**
  427 + * 每分钟更新一次所有服务的状态
  428 + */
  429 + @Override
  430 + @Scheduled(fixedRate = 60 * 1000)
  431 + public void serviceStatusUpdater() {
  432 + List<SyServiceConfig> syServiceConfigs = syServiceConfigMapper.selectByExample(SyServiceConfigExample.newAndCreateCriteria().example());
  433 + for (SyServiceConfig syServiceConfig : syServiceConfigs) {
  434 + if (syServiceConfig == null) {
  435 + continue;
  436 + }
  437 + serviceAction(syServiceConfig.getId(), "status");
  438 + }
  439 + }
  440 +
  441 + /**
438 442 * sysv.sh [stop|restart|status|load] {[containerId]}
439 443 *
440 444 * @param configId 服务配置主键
... ... @@ -478,9 +482,9 @@ public class BackGroundServiceImpl implements IBackGroundService {
478 482 redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "1");
479 483 } else if ("status".equals(action)) {
480 484 if ("0".equals(resultCode)) {
481   - redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "0");
482   - } else {
483 485 redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "1");
  486 + } else {
  487 + redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "0");
484 488 }
485 489 }
486 490 if ("0".equals(resultCode)) {
... ... @@ -488,7 +492,6 @@ public class BackGroundServiceImpl implements IBackGroundService {
488 492 } else {
489 493 resultObj.put("error", resultMsg);
490 494 }
491   -
492 495 }
493 496 }
494 497 return resultObj;
... ...
src/main/java/com/objecteye/service/impl/UserServiceImpl.java
... ... @@ -78,7 +78,7 @@ public class UserServiceImpl implements IUserService {
78 78 SyUserExample baseExample = SyUserExample.newAndCreateCriteria().andUsernameEqualTo(username).example();
79 79 List<SyUser> syUsers = syUserMapper.selectByExample(baseExample.page(currentPage, currentPage));
80 80 long total = syUserMapper.countByExample(baseExample);
81   - return new PageResult<>((long) Math.ceil((double) total / pageVolume), syUsers);
  81 + return new PageResult<>(total, syUsers);
82 82 }
83 83  
84 84 /**
... ...