建行项目随笔

来源:互联网 发布:现在做淘宝还能赚钱吗 编辑:程序博客网 时间:2024/04/28 11:18
  • 项目框架比较老,里面用法很原始,其中我写了一个html界面通过js那地址栏参数的方法

    //获取地址参数function GetQueryString(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if(r!=null)return  unescape(r[2]); return null;}

  • 解析地址的一些操作

        var curWwwPath = window.document.location.href;// 获取当前网址,如:http://localhost:8083/uimcardprj/share/meun.jspvar pathName = window.document.location.pathname;// 获取主机地址之后的目录,如:uimcardprj/share/meun.jspvar pos = curWwwPath.indexOf(pathName);var localhostPaht = curWwwPath.substring(0, pos);// 获取主机地址,如:http://localhost:8083var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);// 获取带"/"的项目名,如:/uimcardprjvar basePath = localhostPaht + projectName;if (top != self) {    top.window.location.href = basePath + "/sessiontimeout.html";}if (document.URL.indexOf("command") != -1) {    top.window.location.href = basePath + "/sessiontimeout.html";}

    最后这里的bathpath就是项目的地址


  • ftl文件中遍历list及取大小和下标

        <#list menu as m1><#-- 一级菜单开始 后台中map里的menu-->        <div class="navList">    <div class="dt-title"><h3 <#if m1_index == 0>class="navOn"</#if>><b>${m1.title}</b></h3></div>    <div class="dd-title<#if m1_index == 0> dd-titleOn</#if>">    <ul class="list"><#-- 二级菜单开始 -->        <#list m1.child as m2>            <#if m1_index == 0 && m2_index == 0>            <script>         //获得当前人员第一个应该显示资源的路径         $("#startUrl").val("${m2.url}");            </script>            </#if>            <li url="${m2.url}" <#if m2_index == 0>class="navActiveOn"</#if>><img src="../images/newnavigator/icon/_${m1_index}_icon_${m2_index+1}.png" />${m2.title}</li>        </#list><#-- 二级菜单结束 -->    </ul></div></div></#list><#-- 一级菜单结束 -->

  • jqgrid加载窗口

    jQuery("#_traningAClassLessonGrid").jqGrid({    url: jQuery.getBasePath() + '/***/*****?flag=******&***8=****',    datatype: "json",    colNames:['ID', '评估主题', '评估类型','发布状态','开始时间','结束时间','结果明细','删除评估'],    colModel:[        {name:'*',index:'*', width:55, align:'center',key:true,hidden:true},        {name:'*', index:'*', align:'center'},        {name:'*', index:'*', align:'center'},        {name:'*', index:'*', align:'center' ,hidden:false},        {name:'*_*', index:'*_*', align:'center'},        {name:'*_*', index:'*_*', align:'center'},        {name:'*', index:'*', align:'center'},        {name:'*', index:'*', align:'center'}    ],    width:933,    height:250,    rowNum:10,    rowList:[10,20,30],    pager: '#_lessonBar',    sortname: 'id',    viewrecords: true,    sortorder: "desc",    multiselect: false,    jsonReader: {        repeatitems : false    },    rownumbers : true,    caption: "课程评优",    afterInsertRow : function(rowid, data) {        var type = data.TYPE;        var ID="'"+data.ID+"'";        var zt="'"+data.zt+"'";        var code="'"+data.CODE+"'";          if (data.status==1){            $("#_traningAClassLessonGrid").jqGrid('setCell', rowid, 'status', '<span style="cursor:pointer;" onclick="_setEvaluteStatus('+ID+',0,'+zt+')">未发布</span>', {color : 'blue'});        }else if(data.status==0){            $("#_traningAClassLessonGrid").jqGrid('setCell', rowid, 'status', '<span style="cursor:pointer;">已发布</span>', {color : 'red'});        }        $("#_traningAClassLessonGrid").jqGrid('setCell', rowid, 'EVALUTETYPE', '<span>课程评优</span>', {color : 'blue'});        $("#_traningAClassLessonGrid").jqGrid('setCell', rowid, 'DETAILLESSON', '<span style="cursor:pointer;" onclick="_getDETAILLESSON('+ID+');">结果明细</span>', {color : 'blue'});        $("#_traningAClassLessonGrid").jqGrid('setCell', rowid, 'REMOVELESSON', '<span style="cursor:pointer;" onclick="_delTrainingClassLessonAndFaceLesson('+ID+');">删除评估</span>', {color : 'blue'});    }}); 

  • jqgrid查询

    var url = jQuery.getBasePath() + '/command/TrainingClassAction?flag=getEvaluteSuperShow&tc_id=${tc_id}';    jQuery("#_traningAClassLessonGrid").jqGrid('setGridParam',{        url : url+'&begindateQueryFrom='+encodeURIComponent( $('#begindateQueryFrom').val())+'&begindateQueryTo='+encodeURIComponent( $('#begindateQueryTo').val())+'&enddateQueryFrom='+encodeURIComponent( $('#enddateQueryFrom').val())+'&enddateQueryTo='+encodeURIComponent( $('#enddateQueryTo').val())          ,page:1    }).trigger("reloadGrid");

  • 导航菜单的依据权限显示

    • 首先拿到在前台需要的菜单数据
      Map map = nav.getMenuMap(user.getID());//获取菜单map 权限问题 权限分配  
    • 数据库关联查询,角色表 用户表 用户角色关联表 资源表 资源角色关联表

    • 查询该用户的角色对应的所有资源,将这些资源组成map返回

    • 然后就是上面的那种在ftl中遍历list显示菜单了


  • 一个项目中sql有的时候写的好,可以大大减轻代码量

    原来:

    ``` int num=0;num+=updateEvaluteSuper(param);param.put("obj_id", param.get("id"));param.put("N_type", "课程评优");param.put("obj_title", param.get("zt"));num+=saveNoticeSuper(param);List typeList = super.queryForList("trainingclass_sql.xml", "base_getEvaluteSuper", param);List userList=new ArrayList();for(int i=0;i<typeList.size();i++){    Map<String, Object> map = (Map<String, Object>) typeList.get(i);    int type = (Integer) map.get("TYPE");    param.put("EntityId", map.get("ENTITYID"));    if(type==1){        //EntityID为岗位ID(User_Station)        userList=super.queryForList("trainingclass_sql.xml", "base_getUserStation", param);    }else if(type==2) {        //EntityID为部门ID(Tuser_group)        userList=super.queryForList("trainingclass_sql.xml", "base_getTuserGroup", param);    }else if(type==3){        //Type=3,EntityID为职位ID(Tuser(Business))    }    for(int j=0;j<userList.size();j++){        Map<String, Object> userMap=new HashMap<String, Object>();        userMap=(Map<String, Object>) userList.get(j);        param.put("tnotice_id", param.get("id"));        param.put("id", UUIDTool.randomUUID());        param.put("user_id", userMap.get("user_id"));        param.put("r_status", "1");        num+=super.update("trainingclass_sql.xml", "base_saveNoticeUserSuper", param);    }}return num;   ```
    • 但是我发现这么长的业务逻辑我只需要在sql上改改就行了。
      修改的sql:(原来的sql就是一条一条查的简单sql语句)
    SELECTUS_ID AS userIdFROMuser_stationWHEREID IN (    SELECT        ENTITYID    FROM        tc_array_user    WHERE        TC_ID = '93acc5f6-3764-4dce-a299-e93ecb7ff702'    AND type = '1')UNIONSELECT    USER_ID AS userIdFROM    tuser_groupWHERE    GROUP_ID IN (        SELECT            ENTITYID        FROM            tc_array_user        WHERE            TC_ID = '93acc5f6-3764-4dce-a299-e93ecb7ff702'        AND type = '2'    )
  • 总结 :以后一定要加强对sql的优化

7 0
原创粉丝点击