Java Code Examples for com.alibaba.fastjson.JSONArray#toJSON()

The following examples show how to use com.alibaba.fastjson.JSONArray#toJSON() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseDynamicService.java    From Jpom with MIT License 6 votes vote down vote up
/***
 *  过滤角色数据
 * @param jsonArray 原array
 * @param classFeature 功能
 * @return 过滤后的,如果当前没有登录信息就不过滤
 */
default JSONArray filter(JSONArray jsonArray, ClassFeature classFeature) {
    // 获取当前用户
    UserModel userModel = BaseServerController.getUserModel();
    if (jsonArray == null || userModel == null) {
        return jsonArray;
    }
    if (userModel.isSystemUser()) {
        // 系统管理全部权限
        return jsonArray;
    }
    RoleService bean = SpringUtil.getBean(RoleService.class);
    String parentId = getParameterValue(classFeature);
    Set<String> dynamicList = bean.getDynamicList(userModel, classFeature, parentId);
    if (dynamicList == null) {
        return null;
    }
    List<Object> collect = jsonArray.stream().filter(o -> {
        JSONObject jsonObject = (JSONObject) o;
        String id = jsonObject.getString("id");
        return dynamicList.contains(id);
    }).collect(Collectors.toList());
    return (JSONArray) JSONArray.toJSON(collect);
}
 
Example 2
Source File: OutGivingProjectEditController.java    From Jpom with MIT License 5 votes vote down vote up
@RequestMapping(value = "editProject", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
@Feature(method = MethodFeature.EDIT)
public String editProject(String id) {
    setAttribute("type", "add");
    OutGivingModel outGivingModel;
    if (StrUtil.isNotEmpty(id)) {
        outGivingModel = outGivingServer.getItem(id);
        if (outGivingModel != null) {
            setAttribute("item", outGivingModel);
            setAttribute("type", "edit");
        }
    }
    // 运行模式
    JSONArray runModes = (JSONArray) JSONArray.toJSON(RunMode.values());
    runModes.remove(RunMode.File.name());
    //
    setAttribute("runModes", runModes);
    //
    JSONArray afterOpt = BaseEnum.toJSONArray(AfterOpt.class);
    setAttribute("afterOpt", afterOpt);
    // 权限
    List<NodeModel> nodeModels = nodeService.list();
    setAttribute("nodeModels", nodeModels);
    //
    String reqId = nodeService.cacheNodeList(nodeModels);
    setAttribute("reqId", reqId);

    // 白名单
    List<String> jsonArray = serverWhitelistServer.getOutGiving();
    setAttribute("whitelistDirectory", jsonArray);
    return "outgiving/editProject";
}
 
Example 3
Source File: EditProjectController.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 修改项目页面
 *
 * @param id 项目Id
 * @return json
 */
@RequestMapping(value = "editProject", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
@Feature(method = MethodFeature.EDIT)
public String editProject(String id) {
    JSONObject projectInfo = projectInfoService.getItem(getNode(), id);

    // 白名单
    List<String> jsonArray = whitelistDirectoryService.getProjectDirectory(getNode());
    setAttribute("whitelistDirectory", jsonArray);

    setAttribute("item", projectInfo);
    // 运行模式
    JSONArray runModes = (JSONArray) JSONArray.toJSON(RunMode.values());
    if (projectInfo != null) {
        try {
            String runMode = projectInfo.getString("runMode");
            RunMode mode = RunMode.valueOf(runMode);
            if (mode != RunMode.File) {
                // java 项目不能转换为file,可能有未结束的进程
                runModes.remove(RunMode.File.name());
            }
        } catch (Exception ignored) {
        }
    }
    setAttribute("runModes", runModes);
    //
    List<String> hashSet = projectInfoService.getAllGroup(getNode());
    if (hashSet.isEmpty()) {
        hashSet.add("默认");
    }
    setAttribute("groups", hashSet);
    //jdk
    JSONArray array = projectInfoService.getJdkList(getNode(), getRequest());
    setAttribute("jdkArray", array);
    return "node/manage/editProject";
}
 
Example 4
Source File: AbstractArray.java    From api with Apache License 2.0 5 votes vote down vote up
/**
* Converts the Object to JSON, typically used for RPC transfers
*/
   @Override
   public Object toJson() {
       List<Object> collect = this.stream().map(e ->
               e.toJson()
       ).collect(Collectors.toList());
       return JSONArray.toJSON(collect);
   }
 
Example 5
Source File: FoodController.java    From java_server with MIT License 5 votes vote down vote up
/**
   * @param dateStart
   * @param dateEnd
   * @param page
   * @param limit
   * @return
   */
  @RequestMapping("getTopFive")
  public @ResponseBody
  Map<String, Object> getTopFive(@RequestParam String dateStart,
                                 @RequestParam Integer campusId, @RequestParam String dateEnd,
                                 Integer page, Integer limit) {
      Map<String, Object> requestMap = new HashMap<String, Object>();
      Map<String, Object> responseMap = new HashMap<String, Object>();

      if (dateStart != null && dateEnd != null) {
          try {
              requestMap.put("dateStart",
                      new SimpleDateFormat("yyyy-MM-dd").parse(dateStart));
              requestMap.put("dateEnd",
                      new SimpleDateFormat("yyyy-MM-dd").parse(dateEnd));
              requestMap.put("limit", limit);
              requestMap.put("offset", (page - 1) * limit);
              requestMap.put("campusId", campusId);
              JSONArray hotFive = (JSONArray) JSONArray.toJSON(foodService
                      .getTopFive(requestMap));
              responseMap.put("hotFive", hotFive);
          } catch (ParseException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }

/*
 * JSONArray hotFive = (JSONArray)
 * JSONArray.toJSON(foodService.getTopFive(requestMap));
 * responseMap.put("hotFive", hotFive);
 */
      return responseMap;
  }
 
Example 6
Source File: BuildService.java    From Jpom with MIT License 4 votes vote down vote up
@Override
public JSONArray listToArray(String dataId) {
    return (JSONArray) JSONArray.toJSON(this.list());
}
 
Example 7
Source File: OutGivingServer.java    From Jpom with MIT License 4 votes vote down vote up
@Override
public JSONArray listToArray(String dataId) {
    return (JSONArray) JSONArray.toJSON(this.list());
}
 
Example 8
Source File: NodeService.java    From Jpom with MIT License 4 votes vote down vote up
@Override
public JSONArray listToArray(String dataId) {
    return (JSONArray) JSONArray.toJSON(this.list());
}
 
Example 9
Source File: SshService.java    From Jpom with MIT License 4 votes vote down vote up
@Override
public JSONArray listToArray(String dataId) {
    return (JSONArray) JSONArray.toJSON(this.list());
}
 
Example 10
Source File: TaskCaseExecuteController.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 获取任务相关数据
 * @param rsp HTTP响应
 */
@RequestMapping(value = "/getMainData.do")
public void getMainData(HttpServletResponse rsp) throws Exception {
	String[] taskdata = new String[2];
	String[] casedata = new String[2];
	String[] logdata = new String[2];
	String[] caseadddata = new String[2];

	Date minDate = taskExecuteService.selectTaskExecuteMinData();
	String dateInterval = DateUtils.getDatePoor(new Date(), minDate);
	taskdata[0] = dateInterval;
	taskdata[1] = String.valueOf(taskExecuteService.selectTaskExecuteCount());

	int casecount = taskCaseExecuteService.selectTaskCaseExecuteCount();
	casedata[0] = String.valueOf(casecount);
	int casesuccount = taskCaseExecuteService.selectTaskCaseExecuteCountForSuccess();
	if (0 == casecount && 0 == casesuccount) {
		casedata[1] = "0";
	} else {
		double percase = (double) casesuccount / casecount;
		BigDecimal bcase = new BigDecimal(percase * 100);
		percase = bcase.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
		casedata[1] = String.valueOf(percase);
	}

	String daysStr=dateInterval.substring(0, dateInterval.indexOf("天"));
	int days=Integer.parseInt(daysStr);
	if (0 == casecount) {
		logdata[0] = "0";
	} else {
		double per = (double) casecount / 45;
		if (days != 0) {
			per = per / days;
		} else {
			per = 0;
		}

		BigDecimal bperrl = new BigDecimal(per);
		per = bperrl.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
		logdata[0] = String.valueOf(per);
	}
	logdata[1] = String.valueOf(taskCaseLogService.selectTaskCaseLogCount());

	int caseaddcount = projectCaseService.selectProjectCaseCount();
	caseadddata[0] = String.valueOf(caseaddcount);
	int thirtyDaysCcount = projectCaseService.selectProjectCaseCountForThirtyDays();
	caseadddata[1] = String.valueOf(thirtyDaysCcount);

	rsp.setContentType("application/json");
	rsp.setCharacterEncoding("utf-8");
	JSONArray taskArray = (JSONArray) JSONArray.toJSON(taskdata);
	JSONArray caseArray = (JSONArray) JSONArray.toJSON(casedata);
	JSONArray logArray = (JSONArray) JSONArray.toJSON(logdata);
	JSONArray caseaddArray = (JSONArray) JSONArray.toJSON(caseadddata);
	JSONObject jsobjcet = new JSONObject();
	jsobjcet.put("taskdata", taskArray);
	jsobjcet.put("casedata", caseArray);
	jsobjcet.put("logdata", logArray);
	jsobjcet.put("caseadddata", caseaddArray);

	rsp.getWriter().write(jsobjcet.toString());
}
 
Example 11
Source File: QaAccidentController.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 图形展示生产事故异步加载数据
 * @param request 请求
 * @return 拉取数据
 */
@ResponseBody
@GetMapping("/getGraphData")
public String getGraphData(HttpServletRequest request)
{
	String projectId = request.getParameter("projectId");
	String queryStartDate = request.getParameter("queryStartDate");
	String queryEndDate = request.getParameter("queryEndDate");
	String statistical = request.getParameter("Statistical");
	String dataLatitude = request.getParameter("dataLatitude");
	
	QaAccident qaAccident = new QaAccident();
	if(StringUtils.isNotEmpty(projectId)){
		qaAccident.setProjectId(Integer.valueOf(projectId));
	}
	Map<String, Object> params = new HashMap<>();
	params.put("beginTime", queryStartDate);
	params.put("endTime", queryEndDate);
	qaAccident.setParams(params);
	
	/*数据统计纬度*/
	if("1".equals(dataLatitude)){
		qaAccident.setImpactTime(0);
	}else if("2".equals(dataLatitude)){
		qaAccident.setDurationTime(0);
	}else{
		qaAccident.setAccidentType("true");
	}		
	
	List<Map<Object, Object>> list;
	
	/*事故类型或是等级纬度*/
	if("0".equals(statistical)){
		list=qaAccidentService.selectGroupByAccidentType(qaAccident);
	}else{
		list=qaAccidentService.selectGroupByAccidentLevel(qaAccident);
	}

	PieCharts[] arraydata = new PieCharts[list.size()];
	String[] legendData=new String[list.size()];
	for(int i=0;i<list.size();i++){
		Map<Object, Object> map=list.get(i);
		PieCharts pieData=new PieCharts();
		pieData.setName(map.get("selectName").toString());
		pieData.setValue(Double.parseDouble(map.get("selectValue").toString()));
		arraydata[i] = pieData;
		legendData[i] = map.get("selectName").toString();
	}
	
	String titleText="事故分析饼图";
	String titleSubText="所有项目";

	JSONArray jsonArrayData = (JSONArray)JSONArray.toJSON(arraydata);
	JSONArray jsonArraylegendData = (JSONArray)JSONArray.toJSON(legendData);
	return "{\"seriesData\":"+jsonArrayData.toString()+",\"legendData\":"+jsonArraylegendData.toString()+",\"titleText\":\""+titleText+"\",\"titleSubText\":\""+titleSubText+"\"}";
}