Ejemplo n.º 1
0
 public static MediaUploadResult upload(String accessToken, String type, File file)
     throws OApiException {
   String url = Env.OAPI_HOST + "/media/upload?" + "access_token=" + accessToken + "&type=" + type;
   JSONObject response = HttpHelper.uploadMedia(url, file);
   if (!response.containsKey("type")
       || !response.containsKey("media_id")
       || response.containsKey("created_at")) {
     return JSON.parseObject(response.toJSONString(), MediaUploadResult.class);
   } else {
     throw new OApiResultException("type or media_id or create_at");
   }
 }
Ejemplo n.º 2
0
 private static String extractResult(String jsonStr) {
   JSONObject jsonObject = JSON.parseObject(jsonStr);
   if (jsonObject != null && jsonObject.containsKey(RESULTS)) {
     return jsonObject.get(RESULTS).toString();
   }
   return null;
 }
Ejemplo n.º 3
0
 /**
  * 发货通知
  *
  * @param access_token
  * @param openid
  * @param transid
  * @param out_trade_no
  * @return
  * @throws IOException
  * @throws NoSuchProviderException
  * @throws NoSuchAlgorithmException
  * @throws KeyManagementException
  * @throws InterruptedException
  * @throws ExecutionException
  */
 public static boolean delivernotify(
     String access_token, String openid, String transid, String out_trade_no)
     throws IOException, ExecutionException, InterruptedException {
   Map<String, String> paras = new HashMap<String, String>();
   paras.put("appid", ConfKit.get("AppId"));
   paras.put("openid", openid);
   paras.put("transid", transid);
   paras.put("out_trade_no", out_trade_no);
   paras.put("deliver_timestamp", (System.currentTimeMillis() / 1000) + "");
   paras.put("deliver_status", "1");
   paras.put("deliver_msg", "ok");
   // 签名
   String app_signature = deliverSign(paras);
   paras.put("app_signature", app_signature);
   paras.put("sign_method", "sha1");
   String json =
       HttpKit.post(DELIVERNOTIFY_URL.concat(access_token), JSONObject.toJSONString(paras));
   if (StringUtils.isNotBlank(json)) {
     JSONObject object = JSONObject.parseObject(json);
     if (object.containsKey("errcode")) {
       int errcode = object.getIntValue("errcode");
       return errcode == 0;
     }
   }
   return false;
 }
Ejemplo n.º 4
0
 private List<Score> generateProblemScore(
     JSONObject jsonInfoObj, String entityId, WeixinUser weixinUser, EntityAccount entityAccount) {
   // 获取问题
   Score score = null;
   List<Score> scoreList = new ArrayList<Score>();
   JSONObject jsonObj = null;
   // 实体用户信息
   if (jsonInfoObj.containsKey("problemScore")) {
     JSONArray jsonArray = jsonInfoObj.getJSONArray("problemScore");
     Integer var = null;
     if (!CollectionUtils.isEmpty(jsonArray)) {
       for (Object obj : jsonArray) {
         jsonObj = (JSONObject) obj;
         score = new Score();
         score.setId(CommonUtil.GeneGUID());
         score.setAppraisalId(entityId);
         score.setProblemId(jsonObj.getString("id"));
         var = jsonObj.getInteger("score");
         score.setScore((var == null ? 0 : var));
         score.setOpinion(jsonObj.getString("opinion"));
         score.setRaterId(weixinUser.getUserid());
         score.setRaterName(weixinUser.getName());
         score.setUserId(entityAccount.getAccountId());
         score.setUserName(entityAccount.getAccountName());
         scoreList.add(score);
       }
     }
   }
   return scoreList;
 }
  private static boolean readConfig(String component) {
    FileSystem fs = FileSystemWrapper.instance();
    String path = fs.getRealPath(component + CONFIG_EXT);
    FileReader fr = null;
    boolean ret = false;
    try {
      fr = new FileReader(new File(path));
      String content = NetUtils.readStreamAsString(fr);
      int start = content.indexOf("{");
      int end = content.lastIndexOf("}");
      if ((start != -1) && (end != -1) && (end > start + 1)) {
        String body = content.substring(start + 1, end);
        if (SystemUtils.isNotEmptyString(body)) {
          start = body.indexOf("[");
          end = body.indexOf("]");
          if ((start != -1) && (end != -1)) {
            String config = body.substring(start, end + 1);
            JSONArray defs = JSONArray.parseArray(config);
            int len = defs.size();
            for (int i = 0; i < len; i++) {
              JSONObject o = defs.getJSONObject(i);
              String name = o.containsKey(STR_NAME) ? o.getString(STR_NAME) : null;
              if (null != name && !"".equals(name)) {
                ExtendTypeDef etd =
                    new ExtendTypeDef(
                        name, o.containsKey(STR_EDITOR) ? o.getString(STR_EDITOR) : null);
                extendTypeDefs.put(name, etd);
              }
            }

            ret = true;
          }
        }
      }
      return ret;
    } catch (Exception e) {
      throw UIException.create(e, UIMessages.READ_COMPONENT_CONFIG_ERROR2, component, path);
    } finally {
      try {
        if (fr != null) fr.close();
      } catch (IOException e) {
      }
    }
  }
Ejemplo n.º 6
0
 private Set<Object> getRealValues(String expression, JSONObject user) {
   Matcher m = pattern.matcher(expression);
   Set<Object> realValues = new HashSet<>();
   if (m.find()) {
     String field = m.group().substring(1, m.group().length() - 1);
     if (user.containsKey(field)) {
       realValues.add(user.get(field));
     } else if (user.containsKey(field.split("\\.")[0])) {
       realValues.addAll(
           user.getJSONArray(field.split("\\.")[0])
               .stream()
               .map(obj -> (JSONObject) obj)
               .filter(json -> json.containsKey(field.split("\\.")[1]))
               .map(json -> json.get(field.split("\\.")[1]))
               .collect(Collectors.toSet()));
     }
   } else {
     realValues.add(expression);
   }
   return realValues;
 }
 /**
  * @param dealerId
  * @throws BusinessException
  */
 @Override
 public void addTrialErpDealerBuyService(String dealerId) throws BusinessException {
   Map<String, Object> params = Maps.newHashMap();
   DealerInfo dealerInfo = dealerInfoService.selectByPrimaryKey(dealerId);
   UserInfo dealerUserm = userInfoService.selectByPrimaryKey(dealerId);
   params.put("dealerId", dealerId);
   params.put("dealerName", dealerInfo.getDealerName());
   params.put("dealerMobile", dealerUserm.getUserMobile());
   params.put("dealerUser", dealerInfo.getDealerUser());
   params.put(
       "dealerMail",
       StringUtils.isEmpty(dealerUserm.getUserMail())
           ? "*****@*****.**"
           : dealerUserm.getUserMail());
   params.put(
       "dealerSex",
       dealerInfo.getDealerGender() == null ? 1 : (dealerInfo.getDealerGender() == 2 ? 1 : 0));
   params.put("dealerKey", dealerId);
   params.put(
       "outOfTime",
       com.zttx.web.utils.CalendarUtils.addDay(
           com.zttx.web.utils.CalendarUtils.getCurrentLong(), 60));
   params.put("userName", dealerUserm.getUserMobile());
   JSONObject _resJson = AppParameterUtils.getErpTrailJSONObject(params);
   if (_resJson == null
       || !_resJson.containsKey("code")
       || _resJson.getIntValue("code") != 121000) {
     throw new BusinessException("ERP 接口调用失败");
   }
   DealerBuyService _dealerBuyService =
       this.findBy(dealerId, CommonConstant.WebServiceItems.SERVICE_SYSTEM_STIALERP);
   if (_dealerBuyService != null) {
     throw new BusinessException("ERP试用服务已经开通,请刷页面!");
   }
   _dealerBuyService = new DealerBuyService();
   _dealerBuyService.setBeginTime(CalendarUtils.getCurrentLong());
   _dealerBuyService.setEndTime(
       CalendarUtils.addDay(com.zttx.web.utils.CalendarUtils.getCurrentLong(), 60));
   _dealerBuyService.setBuyTime(CalendarUtils.getCurrentLong());
   _dealerBuyService.setServiceId(CommonConstant.WebServiceItems.SERVICE_SYSTEM_STIALERP);
   _dealerBuyService.setServicerCate(Short.valueOf("1"));
   _dealerBuyService.setChargType(Short.valueOf("1"));
   _dealerBuyService.setBuyMoney(BigDecimal.ZERO);
   _dealerBuyService.setRefrenceId(SerialnoUtils.buildPrimaryKey());
   _dealerBuyService.setDealerId(dealerId);
   this.insertSelective(_dealerBuyService);
   // DealerInfo的服务起起时间
   dealerInfo.setBeginTime(CalendarUtils.getCurrentLong());
   dealerInfo.setEndTime(
       CalendarUtils.addDay(com.zttx.web.utils.CalendarUtils.getCurrentLong(), 60));
   dealerInfoService.updateByPrimaryKeySelective(dealerInfo);
 }
Ejemplo n.º 8
0
 private List<ProblemTemplate> generateProblemTemplate(JSONObject jsonInfoObj, String entityId) {
   // 获取问题
   ProblemTemplate problemTemplate = null;
   List<ProblemTemplate> problemTemplateList = new ArrayList<ProblemTemplate>();
   JSONObject jsonObj = null;
   // 实体用户信息
   if (jsonInfoObj.containsKey("problemList")) {
     JSONArray jsonArray = jsonInfoObj.getJSONArray("problemList");
     if (!CollectionUtils.isEmpty(jsonArray)) {
       for (Object obj : jsonArray) {
         jsonObj = (JSONObject) obj;
         problemTemplate = new ProblemTemplate();
         problemTemplate.setId(CommonUtil.GeneGUID());
         problemTemplate.setAppraisalId(entityId);
         problemTemplate.setQuota(jsonObj.getString("quota"));
         problemTemplate.setStandard(jsonObj.getString("standard"));
         problemTemplate.setScores(jsonObj.getInteger("score"));
         problemTemplateList.add(problemTemplate);
       }
     }
   }
   return problemTemplateList;
 }
Ejemplo n.º 9
0
  @RequestMapping(value = "/flash/item/list/v2", method = RequestMethod.GET)
  @ResponseBody
  public JSONObject getFlashList(
      @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset,
      @RequestParam(value = "limit", required = false, defaultValue = "21") Integer limit,
      @RequestParam(value = "babystatus", required = false, defaultValue = "0") int babyStatus,
      @RequestParam(value = "gender", required = false, defaultValue = "0") int gender,
      @RequestParam(value = "edc", required = false) String edc,
      @RequestParam(value = "birthday", required = false) String birthday,
      @RequestParam(value = "isset", required = false, defaultValue = "true") boolean isset) {

    JSONObject jo =
        itemServiceApiV2Proxy.getFlashList(isset, babyStatus, gender, edc, birthday, offset, limit);
    UserAccessInfo userAccessInfo = HehuaRequestContext.getUserAccessInfo();
    userAccessInfo.setEvent("snap");
    int status = jo.containsKey("data") ? 0 : -1;
    userAccessInfo.setStatus(status);
    userAccessInfo.setPreganancy(babyStatus);
    userAccessInfo.setBabyGender(gender);
    userAccessInfo.setBabyBirthday(birthday);
    userAccessInfo.setEdc(edc);
    flumeEventLogger.info(userAccessInfo.toString());
    return jo;
  }
Ejemplo n.º 10
0
  public static SysUser jsonToObject(JSONObject jsonObject) {
    SysUser model = new SysUser();

    if (jsonObject.containsKey("actorId")) {
      model.setActorId(jsonObject.getString("actorId"));
    }
    if (jsonObject.containsKey("account")) {
      model.setActorId(jsonObject.getString("account"));
    }
    if (jsonObject.containsKey("name")) {
      model.setName(jsonObject.getString("name"));
    }

    if (jsonObject.containsKey("evection")) {
      model.setEvection(jsonObject.getIntValue("evection"));
    }

    if (jsonObject.containsKey("gender")) {
      model.setGender(jsonObject.getIntValue("gender"));
    }

    if (jsonObject.containsKey("userType")) {
      model.setUserType(jsonObject.getIntValue("userType"));
    }

    if (jsonObject.containsKey("accountType")) {
      model.setAccountType(jsonObject.getIntValue("accountType"));
    }

    if (jsonObject.containsKey("dumpFlag")) {
      model.setDumpFlag(jsonObject.getIntValue("dumpFlag"));
    }

    if (jsonObject.containsKey("createDate")) {
      model.setCreateDate(jsonObject.getDate("createDate"));
    }

    if (jsonObject.containsKey("createBy")) {
      model.setCreateBy(jsonObject.getString("createBy"));
    }
    if (jsonObject.containsKey("updateBy")) {
      model.setUpdateBy(jsonObject.getString("updateBy"));
    }
    if (jsonObject.containsKey("updateDate")) {
      model.setUpdateDate(jsonObject.getDate("updateDate"));
    }

    if (jsonObject.containsKey("lastLoginTime")) {
      model.setLastLoginTime(jsonObject.getDate("lastLoginTime"));
    }

    if (jsonObject.containsKey("lastLoginIP")) {
      model.setLastLoginIP(jsonObject.getString("lastLoginIP"));
    }

    if (jsonObject.containsKey("remark")) {
      model.setRemark(jsonObject.getString("remark"));
    }

    if (jsonObject.containsKey("deptId")) {
      model.setDeptId(jsonObject.getInteger("deptId"));
    }

    if (jsonObject.containsKey("mail")) {
      model.setMail(jsonObject.getString("mail"));
    }

    if (jsonObject.containsKey("mobile")) {
      model.setMobile(jsonObject.getString("mobile"));
    }

    if (jsonObject.containsKey("telephone")) {
      model.setTelephone(jsonObject.getString("telephone"));
    }

    if (jsonObject.containsKey("headship")) {
      model.setHeadship(jsonObject.getString("headship"));
    }

    if (jsonObject.containsKey("superiorIds")) {
      model.setSuperiorIds(jsonObject.getString("superiorIds"));
    }

    if (jsonObject.containsKey("status")) {
      model.setStatus(jsonObject.getString("status"));
    }

    if (jsonObject.containsKey("adminFlag")) {
      model.setAdminFlag(jsonObject.getString("adminFlag"));
    }

    if (jsonObject.containsKey("userRoles")) {
      JSONArray array = jsonObject.getJSONArray("userRoles");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysUserRole r = SysUserRoleJsonFactory.jsonToObject(json);
          model.getUserRoles().add(r);
        }
      }
    }

    if (jsonObject.containsKey("roles")) {
      JSONArray array = jsonObject.getJSONArray("roles");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysRole r = SysRoleJsonFactory.jsonToObject(json);
          model.getRoles().add(r);
        }
      }
    }

    if (jsonObject.containsKey("functions")) {
      JSONArray array = jsonObject.getJSONArray("functions");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysFunction r = SysFunctionJsonFactory.jsonToObject(json);
          model.getFunctions().add(r);
        }
      }
    }

    if (jsonObject.containsKey("apps")) {
      JSONArray array = jsonObject.getJSONArray("apps");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysApplication r = SysApplicationJsonFactory.jsonToObject(json);
          model.getApps().add(r);
        }
      }
    }

    return model;
  }
Ejemplo n.º 11
0
  /**
   * * 创建用户默认规则
   *
   * @param root
   * @return
   * @throws Exception
   */
  @RequestMapping(
      value = "/alarmRule/modify",
      method = RequestMethod.POST,
      produces = "application/json; charset=UTF-8")
  @ResponseBody
  public String modifyAppAlarmRule(
      HttpServletRequest request, ModelMap root, @RequestBody String jsonStr) throws Exception {
    HttpSession session = request.getSession();
    String uid = (String) session.getAttribute("uid");

    JSONObject reJson = new JSONObject();

    if (StringUtil.isBlank(uid)) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
      return reJson.toJSONString();
    }

    JSONObject json = JSON.parseObject(jsonStr);
    if (!json.containsKey("isGlobal")) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到isGlobal参数信息");
    }
    String isGlobal = json.getString("isGlobal");
    if (!json.containsKey("period")) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到告警间隔参数信息");
    }
    String period = json.getString("period");
    if (!json.containsKey("todoType")) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到操作类型参数信息");
    }
    String ruleId = json.getString("ruleId");
    if (!json.containsKey("ruleId")) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到告警规则参数信息");
    }
    String todoType = json.getString("todoType");
    String mailTo = null;
    String mailCc = null;
    if (Constants.TODO_TYPE_0.equals(todoType)) {
      if (!json.containsKey("mailTo")) {
        reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
        reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到邮件发送人信息");
        return reJson.toJSONString();
      }
      mailTo = json.getString("mailTo").replace("\n", "");
      if (json.containsKey("mailCc")) {
        mailCc = json.getString("mailCc").replace("\n", "");
      }
    } else if (Constants.TODO_TYPE_1.equals(todoType)) {
      if (!json.containsKey("urlCall")) {
        reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
        reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到回调接口信息");
        return reJson.toJSONString();
      }
    } else {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未定义告警操作类型");
      return reJson.toJSONString();
    }

    AlarmRuleMVO ruleMVO = new AlarmRuleMVO();
    ruleMVO.setRuleId(ruleId);
    ruleMVO.setTodoType(todoType);
    ConfigArgs configArgs = new ConfigArgs();
    configArgs.setPeriod(json.getInteger("period"));
    MailInfo mailInfo = new MailInfo();
    if (json.containsKey("mailCc") && !StringUtil.isBlank(json.getString("mailCc"))) {
      mailInfo.setMailCc(json.getString("mailCc").toString().trim().split(","));
    }
    mailInfo.setMailTo(json.getString("mailTo").toString().trim().split(","));
    configArgs.setMailInfo(mailInfo);
    ruleMVO.setConfigArgs(configArgs);

    try {
      ruleMVO = alarmRuleSer.modifyAlarmRule(ruleMVO);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_OK);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "操作成功");

    } catch (Exception e) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "创建告警规则失败");
      e.printStackTrace();
    }
    return reJson.toJSONString();
  }
Ejemplo n.º 12
0
  /**
   * * 创建用户默认规则
   *
   * @param root
   * @return
   * @throws Exception
   */
  @RequestMapping(
      value = "/alarmRule/create",
      method = RequestMethod.POST,
      produces = "application/json; charset=UTF-8")
  @ResponseBody
  public String createAppAlarmRule(
      HttpServletRequest request, ModelMap root, @RequestBody String jsonStr) throws Exception {
    HttpSession session = request.getSession();
    String uid = (String) session.getAttribute("uid");

    JSONObject reJson = new JSONObject();

    if (StringUtil.isBlank(uid)) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
      return reJson.toJSONString();
    }

    JSONObject json = JSON.parseObject(jsonStr);
    if (!json.containsKey("isGlobal")) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到isGlobal参数信息");
      return reJson.toJSONString();
    }
    String isGlobal = json.getString("isGlobal");
    if (!json.containsKey("period")) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到告警间隔参数信息");
      return reJson.toJSONString();
    }
    String period = json.getString("period");
    if (!json.containsKey("todoType")) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到操作类型参数信息");
      return reJson.toJSONString();
    }
    String todoType = json.getString("todoType");

    String mailTo = null;
    String mailCc = null;
    if (Constants.TODO_TYPE_0.equals(todoType)) {
      if (!json.containsKey("mailTo")) {
        reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
        reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到邮件发送人信息");
        return reJson.toJSONString();
      }
      mailTo = json.getString("mailTo").replace("\n", "");
      if (json.containsKey("mailCc")) {
        mailCc = json.getString("mailCc").replace("\n", "");
      }
    } else if (Constants.TODO_TYPE_1.equals(todoType)) {
      if (!json.containsKey("urlCall")) {
        reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
        reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到回调接口信息");
        return reJson.toJSONString();
      }
    } else {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未定义告警操作类型");
      return reJson.toJSONString();
    }

    AlarmRuleMVO srchRuleMVO = new AlarmRuleMVO();
    srchRuleMVO.setUid(uid);
    srchRuleMVO.setSts(Constants.STR_VAL_A);
    srchRuleMVO.setIsGlobal(isGlobal);

    // 判断是否为全局规则
    if (Constants.IS_GLOBAL_FALG_1.equals(isGlobal)) {
      srchRuleMVO = alarmRuleSer.queryUserDefaultAlarmRule(srchRuleMVO);
      if (srchRuleMVO != null && !StringUtil.isBlank(srchRuleMVO.getRuleId())) {
        reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
        reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "默认告警规则已经存在");
        return reJson.toJSONString();
      }
    } else {
      if (!json.containsKey("appId")) {
        reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
        reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "未找到appId参数信息");
        return reJson.toJSONString();
      } else {
        srchRuleMVO.setAppId(json.getString("appId"));
        srchRuleMVO = alarmRuleSer.queryAppAlarmRule(srchRuleMVO);
        if (srchRuleMVO != null && !StringUtil.isBlank(srchRuleMVO.getRuleId())) {
          reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
          reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "当前应用已经存在告警规则");
          return reJson.toJSONString();
        }
      }
    }

    AlarmRuleMVO ruleMVO = new AlarmRuleMVO();
    ruleMVO.setUid(uid);
    ruleMVO.setAppId(json.getString("appId"));
    ruleMVO.setSts(Constants.STR_VAL_A);
    ruleMVO.setIsGlobal(isGlobal);
    ruleMVO.setTodoType(todoType);
    JSONObject confArgs = new JSONObject();
    confArgs.put("period", period);
    if (Constants.TODO_TYPE_0.equals(todoType)) {
      // 设置邮件相关的信息
      JSONObject mailInfo = new JSONObject();

      String[] mailToList = mailTo.split(Constants.MAIL_SPLIT_CHAR);

      if (!StringUtil.isBlank(mailCc)) {
        String[] mailCcList = mailCc.split(Constants.MAIL_SPLIT_CHAR);
        mailInfo.put("mailCc", mailCcList);
      }

      mailInfo.put("mailTo", mailToList);
      confArgs.put("mailInfo", mailInfo);
    } else if (Constants.TODO_TYPE_1.equals(todoType)) {
      // 设置接口相关的信息
      JSONObject urlInfo = new JSONObject();
      urlInfo.put("urlCall", json.getString("urlCall"));
      confArgs.put("urlInfo", urlInfo);
    }

    ConfigArgs configArgs = new ConfigArgs();
    configArgs.setPeriod(json.getInteger("period"));
    MailInfo mailInfo = new MailInfo();
    if (json.containsKey("mailCc") && !StringUtil.isBlank(json.getString("mailCc"))) {
      mailInfo.setMailCc(json.getString("mailCc").toString().trim().split(","));
    }
    mailInfo.setMailTo(json.getString("mailTo").toString().trim().split(","));
    configArgs.setMailInfo(mailInfo);
    ruleMVO.setConfigArgs(configArgs);

    try {
      ruleMVO = alarmRuleSer.createAlarmRule(ruleMVO);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_OK);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "操作成功");

    } catch (Exception e) {
      reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
      reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "创建告警规则失败");
      e.printStackTrace();
    }
    return reJson.toJSONString();
  }
Ejemplo n.º 13
0
  public static Purchase jsonToObject(JSONObject jsonObject) {
    Purchase model = new Purchase();
    if (jsonObject.containsKey("purchaseid")) {
      model.setPurchaseid(jsonObject.getLong("purchaseid"));
    }
    if (jsonObject.containsKey("purchaseno")) {
      model.setPurchaseno(jsonObject.getString("purchaseno"));
    }
    if (jsonObject.containsKey("area")) {
      model.setArea(jsonObject.getString("area"));
    }
    if (jsonObject.containsKey("company")) {
      model.setCompany(jsonObject.getString("company"));
    }
    if (jsonObject.containsKey("dept")) {
      model.setDept(jsonObject.getString("dept"));
    }
    if (jsonObject.containsKey("post")) {
      model.setPost(jsonObject.getString("post"));
    }
    if (jsonObject.containsKey("appuser")) {
      model.setAppuser(jsonObject.getString("appuser"));
    }
    if (jsonObject.containsKey("appdate")) {
      model.setAppdate(jsonObject.getDate("appdate"));
    }
    if (jsonObject.containsKey("purchasesum")) {
      model.setPurchasesum(jsonObject.getDouble("purchasesum"));
    }
    if (jsonObject.containsKey("status")) {
      model.setStatus(jsonObject.getInteger("status"));
    }
    if (jsonObject.containsKey("processname")) {
      model.setProcessname(jsonObject.getString("processname"));
    }
    if (jsonObject.containsKey("processinstanceid")) {
      model.setProcessinstanceid(jsonObject.getLong("processinstanceid"));
    }
    if (jsonObject.containsKey("wfstatus")) {
      model.setWfstatus(jsonObject.getLong("wfstatus"));
    }
    if (jsonObject.containsKey("createBy")) {
      model.setCreateBy(jsonObject.getString("createBy"));
    }
    if (jsonObject.containsKey("createDate")) {
      model.setCreateDate(jsonObject.getDate("createDate"));
    }
    if (jsonObject.containsKey("updateDate")) {
      model.setUpdateDate(jsonObject.getDate("updateDate"));
    }
    if (jsonObject.containsKey("updateBy")) {
      model.setUpdateBy(jsonObject.getString("updateBy"));
    }

    return model;
  }