コード例 #1
0
  @SuppressWarnings("unchecked")
  @RequestMapping(value = "client/version/view")
  public String viewVersionInfo(Model model)
      throws JsonParseException, JsonMappingException, IOException {

    for (ClientTypeEnum clientType : ClientTypeEnum.values()) {

      for (OsTypeEnum osType : OsTypeEnum.values()) {
        String finalKey =
            clientHelper.toFinalKey(clientType.toString().charAt(0), osType.toString().charAt(0));
        Map<String, Object> para = new HashMap<String, Object>();
        para.put("key", finalKey);
        List<KeyValueEntity> keyValues = keyValueDao.select("selectByKey", para);

        if (CollectionUtils.isNotEmpty(keyValues)) {
          KeyValueEntity entity = keyValues.get(0);
          Map<String, String> value = mapper.readValue(entity.getValue(), Map.class);

          model.addAttribute(
              ClientHelper.ATTR_CURRENT_VERSION, value.get(ClientHelper.ATTR_CURRENT_VERSION));
          model.addAttribute(
              ClientHelper.ATTR_CURRENT_VERSION_INFO,
              value.get(ClientHelper.ATTR_CURRENT_VERSION_INFO));
          model.addAttribute(
              ClientHelper.ATTR_REQUIRED_VERSION, value.get(ClientHelper.ATTR_REQUIRED_VERSION));

          model.addAttribute(finalKey, value);
        }
      }
    }

    return ("client/version");
  }
コード例 #2
0
  @RequestMapping(value = "client/version/update")
  public ModelAndView updateVersionInfo(
      Model model,
      @RequestParam String currentVersion,
      @RequestParam String requiredVersion,
      @RequestParam String currentVersionInfo,
      @RequestParam char osType,
      @RequestParam char clientType)
      throws JsonGenerationException, JsonMappingException, IOException {

    if (StringUtils.isBlank(currentVersion) || StringUtils.isBlank(requiredVersion)) {
      return new ModelAndView(new RedirectView("/client/version/view.controller"));
    }

    String finalKey = clientHelper.toFinalKey(clientType, osType);
    Map<String, Object> para = new HashMap<String, Object>();
    para.put("key", finalKey);
    List<KeyValueEntity> keyValues = keyValueDao.select("selectByKey", para);

    if (CollectionUtils.isEmpty(keyValues)) {
      Map<String, String> value = new HashMap<String, String>();
      value.put(ClientHelper.ATTR_CURRENT_VERSION, currentVersion);
      value.put(ClientHelper.ATTR_CURRENT_VERSION_INFO, currentVersionInfo);
      value.put(ClientHelper.ATTR_REQUIRED_VERSION, requiredVersion);

      KeyValueEntity entity = new KeyValueEntity();
      entity.setKey(finalKey);
      entity.setValue(mapper.writeValueAsString(value));
      entity.setAddTime(new Date());
      entity.setUpdateTime(new Date());
      keyValueDao.add("addKeyValue", entity);

    } else {
      Map<String, String> value = new HashMap<String, String>();
      value.put(ClientHelper.ATTR_CURRENT_VERSION, currentVersion);
      value.put(ClientHelper.ATTR_CURRENT_VERSION_INFO, currentVersionInfo);
      value.put(ClientHelper.ATTR_REQUIRED_VERSION, requiredVersion);

      KeyValueEntity entity = keyValues.get(0);
      entity.setValue(mapper.writeValueAsString(value));
      entity.setUpdateTime(new Date());
      keyValueDao.update("updateById", entity);
    }

    model.addAttribute(ClientHelper.ATTR_CURRENT_VERSION, currentVersion);
    model.addAttribute(ClientHelper.ATTR_CURRENT_VERSION_INFO, currentVersionInfo);
    model.addAttribute(ClientHelper.ATTR_REQUIRED_VERSION, requiredVersion);

    return new ModelAndView(new RedirectView("/client/version/view.controller"));
  }