列表指标校验

2013/06/21 2610点热度 0人点赞 0条评论

昨天写的java json字符串转map集合递归嵌套这篇博文,只是某个功能中的一小部门.

这个功能就根据json串配置的校验指标,去校验对应的列表数据中的必填项是否完整,不完整就在当前页面提示用户,去完善数据.当某条记录不完善的时候,会将不完善的那条数据的背景色置为红色,如图:

校验分为两类,一类是dom加载完以后校验当前页出现的id,一类是全局的校验.

 

后台处理代码

//将前台的json串转成map集合
            JSONObject jsonObject = JSONObject.fromObject(jsonStr);    
            Map<String, Object> map = JSONObject.fromObject(jsonObject);
            for(Entry<String, Object> entry:map.entrySet()){
                  Object strval = entry.getValue();  
                  JSONObject jsonObject1= JSONObject.fromObject(strval);    
                   Map<String, Object> map1 = JSONObject.fromObject(jsonObject1);
                   map.put(entry.getKey(), map1);
            }
            //获取有职称人员的map
            returnids= process_ValidateListService.checkPageData(map,lsh,selectStr,idsStr);
public String checkPageData(Map<String, Object> map, String lsh,
            String selectStr,String idsStr) throws ServiceException {
        String returnIds="";
        try {
            for(Entry<String, Object> entry:map.entrySet()){
                //获取所有的指标map={'TABLES':'PROCESS_RYJBXX r,PRCOESS_RYKZXXB k','TABLESLINK':'r.ID=k.RYID','PROCESS_RYJBXX':'r.ZWXM,r.ZGXL,r.ZJLX,r.ZJHM','PRCOESS_RYKZXXB':'k.ZW,k.ZC,k.CSZY'}
                Map<String, Object> zbmap=(Map<String, Object>) entry.getValue();
                returnIds=process_qyyzcryDao.checkPageData(zbmap,lsh,selectStr,idsStr);
                if(returnIds.isEmpty()){
                    returnIds="no";
                }
            }
        } catch (DAOException e) {
            this.log.info("列表数据校验失败,请联系管理员!",e);
            returnIds="fail";
            throw new ServiceException(e);
        }finally{
            return returnIds;
        }
    }
/**
 * 校验当前页面数据的完整性
 * @author ducc
 * @param zbmap
 * @param lsh
 * @param selectStr
 * @return
 */
public String checkPageData(Map<String, Object> zbmap, String lsh,
        String selectStr,String idsStr)throws DAOException {
    String returnIds="";
    Session session=this.getSession();
    try {
        //获取所有的指标map={'TABLES':'PROCESS_RYJBXX r,PRCOESS_RYKZXXB k,PROCESS_QYRYGXB g','TABLESLINK':'r.ID=k.RYID and g.RYID=r.RYID and g.rylx=\'QYRYFXB009\'','PROCESS_RYJBXX':'r.ZWXM,r.ZGXL,r.ZJLX,r.ZJHM','PRCOESS_RYKZXXB':'k.ZW,k.ZC,k.CSZY'}
        String tables=(String) zbmap.get("TABLES");
        String[] tablearr=null;//获取要查询表的数组
        if(tables.indexOf(",")>-1){//如果包含,
            tablearr=tables.split(",");
        }else{
            if(!"".equals(tables)){
                tablearr=new String[0];
                tablearr[0]=tables;
            }
             
        }
        String tableslink="no";//获取表的关联关系
        Object objtableslink=zbmap.get("TABLESLINK");
        if(objtableslink!=null){
            tableslink=objtableslink.toString();
        }
         
        if("no".equalsIgnoreCase(tableslink)){//没有关联关系
             
        }else{
            Map<String,Object> map=new HashMap<String, Object>();
            for(String str:tablearr){//遍历所有的表
                map.put(str.split(" ")[0], str.split(" ")[1]);
            }
            String sqlWhere="";
            String alias="";
            for(Entry<String, Object> entry:map.entrySet()){
                String str=entry.getKey();
                alias=(String) entry.getValue();
                if(null!=zbmap.get(str)){
                    String strWhere=(String) zbmap.get(str);
                    String[] strWhereArr=strWhere.split(",");
                    for(String strw:strWhereArr){
                        sqlWhere=sqlWhere+" "+strw+" is null or";
                    }
                }
            }
            if(!"".equals(sqlWhere)){
                sqlWhere=" and (" +sqlWhere.substring(0,sqlWhere.lastIndexOf("or"))+" )";
            }
            String sql="select "+selectStr+"  from "+tables+" where "+alias+".liushuihao=? "+sqlWhere+" and "+tableslink+" and "+selectStr+" in("+idsStr+")";
            sql=sql.replaceAll("\"", "'");
            List<Map<String, Object>> list= session.createSQLQuery(sql).setString(0, lsh).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
            String selectid=selectStr.substring(selectStr.indexOf(".")+1);
            for(Map<String,Object> idmap:list){
                if("".equals(returnIds)){
                    returnIds= BigDecimal2Long(idmap.get(selectid.toUpperCase()))+"";
                }else{
                    returnIds=returnIds+","+BigDecimal2Long(idmap.get(selectid.toUpperCase()));
                }
            }
        }
    } catch (Exception e) {
        returnIds="fail";
        this.logger.info("",e);
        throw new DAOException(e);
    }finally{
        return returnIds;
    }
}

 

yxkong

这个人很懒,什么都没留下

文章评论