根据读取后台配置(前端动态化展示table.)

直接上代码。废话不多说

jsp代码



点击某行记录。执行函数

row数据结构

根据读取后台配置(前端动态化展示table.)_第1张图片

result数据结构

根据读取后台配置(前端动态化展示table.)_第2张图片


function detailTask(){
        var row = $('#dg').datagrid('getSelected');
        if (row){
            $.post('/taskManager/sureDetail.html',{taskId:row.taskId},function(result){
                if (result.success){
                    //查询是否为条件查询字段
                    queryFlagMap(row,result);
                    
                    //查询是否是展示字段。在根据展示字段来展示详情
                    showFlagMap(row,result);
                } else {
                    $.messager.show({
                        title: '错误信息',
                        msg: result.msg
                    });
                }
            },'json');
        }

    }



data数据结构

根据读取后台配置(前端动态化展示table.)_第3张图片

//查询是否为条件查询字段
    function queryFlagMap(row,result){
        $.ajax({
            url:'/taskManager/queryFlagMap.html',
            type:"post",
            data:{'channelId':row.channelId},
            dataType:'json',
            success:function(data){
                var html="";

                 // 拼接查询条件

                for(var i=0;i"+data[i].title+":"+
                    ""
            }    
                $("#toolbar-child").prepend(html);
           }
        });
    }

data数据结构

根据读取后台配置(前端动态化展示table.)_第4张图片

columns数据结构

根据读取后台配置(前端动态化展示table.)_第5张图片

//查询是否是展示字段。在根据展示字段来创建表格
    function showFlagMap(row,result){
        $.ajax({
            url:'/taskManager/showFlagMap.html',
            type:"post",
            data:{'channelId':row.channelId},
            dataType:'json',
            success:function(data){
                var columns=[];
                for(var i=0;i

js

 //查询任务详情 
    function detailList(columns,row,result){
    $('#dlg-detail').dialog('open').dialog('center').dialog('setTitle','详情');
    $('#fm-detail').form('load', result.data);
    $('#dg-child').datagrid({
        rownumbers:true,
        url:'/taskManager/detailList.html?taskId='+row.taskId+'&channelId='+row.channelId,
        striped:true,
        singleSelect:true,
        loadMsg:'数据加载中,请稍后...',
        pagination:true,
        pageNumber:1,
        onLoadSuccess: function (data) {
            vara=data;
        },
        columns: [columns],//数据填充。宣染表格
        collapsible:true
    });
}

js

  //分转元。保留2位小数
    function formatPriceToRMB(_price){
        var result = "0.00";
        if(null != _price || undefined != _price){
            var price = parseInt(_price);
            if(!isNaN(price)) {
              var val = (price/100).toFixed(2);
              result = String(val).replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
            }
        }
        return result;
    }

controller

/**
	 * 查询是否为展示字段
	 * @param channelId
	 * @return
	 */
	@RequestMapping("/showFlagMap")
	@ResponseBody
	public List> showFlagMap(Integer channelId){
		List> resultMap=null;
		try {
			resultMap=taskDataService.showFlagMap(channelId);
			log.info("查询是否为显示字段成功");
		} catch (Exception e) {
			log.error("查询是否为显示字段失败:{}", e);
		}
		return resultMap;
	}

/**
	 * 查询是否为查询字段
	 * @return
	 */
	@RequestMapping("/queryFlagMap")
	@ResponseBody
	public List> queryFlagMap(Integer channelId){
		List> resultMap=null;
		try {
			resultMap=taskDataService.queryFlagMap(channelId);
			log.info("查询是否为条件查询字段成功");
		} catch (Exception e) {
			log.error("查询是否为条件查询字段失败:{}", e);
		}
		return resultMap;
	}
	

/**
	 * 查询任务详情记录
	 * @param request
	 * @return
	 */
	@RequestMapping("/detailList")
	@ResponseBody
	public PageListDto> detailList(HttpServletRequest request) {
		PageListDto> pageList = null;
		try {
			pageList = taskDataService.queryAllDetails(request);
			log.info("分页查询任务详情成功");
		} catch (Exception e) {
			log.error("分页查询任务详情失败:{}", e);
		}
		return pageList;
	}

serviceimpls实现

/**
	 * 是否为条件展示字段
	 */
	@Override
	public List> showFlagMap(Integer channelId) {
		List> resultMap=new ArrayList>();
		
		ChannelEntity entity=channelService.selectById(DatasoureFlagEnum.DATA_R_CASH.getCode(),channelId);
		String schemaInfo=entity.getSchemaInfo();
		SchemaConfig config=JSON.parseObject(schemaInfo,SchemaConfig.class);
		
		//另外增加展示字段
		Map flagName=new HashMap();
		flagName.put("title","比对结果");
		flagName.put("field", "flagName");
		resultMap.add(flagName);
		
		Map deletedName=new HashMap();
		deletedName.put("title","处理状态");
		deletedName.put("field", "deletedName");
		resultMap.add(deletedName);
		
		for(int i=0;i showFlagMap=new HashMap();
				showFlagMap.put("title",config.getFields().get(i).getLabel());
				showFlagMap.put("field", config.getFields().get(i).getColumn());
				resultMap.add(showFlagMap);
			}
		}
		//另外增加展示字段
		Map requestId=new HashMap();
		requestId.put("title","结果ID");
		requestId.put("field", "request_id");
		resultMap.add(requestId);
		return resultMap;
	}

/**
	 * 查询是否为查询字段
	 */
	@Override
	public List> queryFlagMap(Integer channelId) {
		List> resultMap=new ArrayList>();
		
		ChannelEntity entity=channelService.selectById(DatasoureFlagEnum.DATA_R_CASH.getCode(),channelId);
		String schemaInfo=entity.getSchemaInfo();
		SchemaConfig config=JSON.parseObject(schemaInfo,SchemaConfig.class);
		
		for(int i=0;i queryFlagMap=new HashMap();
				queryFlagMap.put("title",config.getFields().get(i).getLabel());
				queryFlagMap.put("field", config.getFields().get(i).getColumn());
				resultMap.add(queryFlagMap);
			}
		}
		return resultMap;
	}

@Override
	public PageListDto> queryAllDetails(HttpServletRequest request) {
				//获取条件查询字段
				Integer taskId=Integer.valueOf( request.getParameter("taskId"));
				Integer channelId=Integer.valueOf(request.getParameter("channelId"));
				Integer rows=Integer.valueOf(request.getParameter("rows"));
				Integer page=Integer.valueOf(request.getParameter("page"));
				String flag=String.valueOf(request.getParameter("flag")).equals("3")?"":request.getParameter("flag");
				String deleted=String.valueOf(request.getParameter("deleted")).equals("2")?"":request.getParameter("deleted");
				
				//获取数据源导入结构
				ChannelEntity entity=channelService.selectById(DatasoureFlagEnum.DATA_R_CASH.getCode(),channelId);
				String schemaInfo=entity.getSchemaInfo();
				SchemaConfig config=JSON.parseObject(schemaInfo,SchemaConfig.class);
				String tableName=config.getTableName(); 
				
				List> list= new ArrayList>(0);
				
				Long total=null;
				try{
					//查询详情记录sql
					StringBuffer selectSql=new StringBuffer("select * from " + tableName
							+ "_data  where task_id=" + taskId);
					//查询记录数sql
					StringBuffer countSql=new StringBuffer("select count(1) as total from " + tableName
							+ "_data  where task_id=  ?") ;
					
					//循环拼接查询条件字段
					for(int i=0;i> result = new PageListDto>();
				result.setRows(list);
				result.setTotal(total);
				return result;
		
	}
	/**
	 * 翻译
	 * @param list
	 */
	private void convert(List> list) {
		int i=0;
		for(i=0;i



最终

根据读取后台配置(前端动态化展示table.)_第6张图片




你可能感兴趣的:(前端)