public String add_() throws IllegalArgumentException, SecurityException, ClassNotFoundException, IllegalAccessException, NoSuchFieldException, SQLException { super.add(); if (1 == getCfg_res() && !Util.notEmptyString(isPage)) { Property newp = (Property) bean; if (newp.getProperty().indexOf(".") < 0) { String lengthNew = newp.getLength(); String propertyNameNew = newp.getProperty(); String typeNew = newp.getType(); // ①alter table 表名 add 列名 列类型 列参数【加的列在表的最后面】 // 例:alter table test add username char(20) not null default // ''; // alter table test add birth date not null default // '0000-00-00'; // ②alter table 表名 add 列名 列类型 列参数 after 某列【把新列加在某列后面】 // 例:alter table test add gender char(1) not null default '' // after username; // ③alter table 表名 add 列名 列类型 列参数 first【把新列加在最前面】 // 例:alter table test add pid int not null default 0 first; Connection con = null; PreparedStatement ps = null; try { con = LocalConnetionPool.getConnection(); Bean beanBean = baseDao.get(Bean.class, newp.getBean().getId()); String sql = "alter table " + beanBean.getTableName() + " add " + propertyNameNew + " " + typeNew + "(" + lengthNew + ")"; ps = con.prepareStatement(sql); ps.execute(); } catch (SQLException e) { } finally { ps.close(); con.close(); } } } return SUCCESS; }
public String tree() throws SQLException, SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException { treeValue = new ArrayList<AsyncTree>(); if (!Util.notEmptyString(id)) { DetachedCriteria dc = DetachedCriteria.forClass(Bean.class); List<Bean> bl = baseDao.find(dc); List<String> sl = new ArrayList<String>(); for (Bean b : bl) { if (!sl.contains(b.getPkg())) { sl.add(b.getPkg()); } } for (String s : sl) { AsyncTree at = new AsyncTree(); at.setId("pkg:" + s); at.setText(s); at.setState("closed"); treeValue.add(at); } } else if (id.startsWith("pkg:")) { DetachedCriteria dc = DetachedCriteria.forClass(Bean.class); dc.add(Restrictions.eq("pkg", id.replace("pkg:", ""))); List<Bean> bl = baseDao.find(dc); for (Bean b : bl) { AsyncTree at = new AsyncTree(); at.setId("bean:" + String.valueOf(b.getId())); at.setText(b.getBean() + ":" + b.getDescr()); at.setState("closed"); treeValue.add(at); } } else if (id.startsWith("bean:")) { DetachedCriteria dc = DetachedCriteria.forClass(Property.class); String beanId = id.replace("bean:", ""); Bean b = baseDao.get(Bean.class, Integer.valueOf(beanId)); dc.add(Restrictions.eq("bean", b)); List<Property> bl = baseDao.find(dc); for (Property bx : bl) { AsyncTree at = new AsyncTree(); at.setId(String.valueOf(bx.getId())); at.setText(bx.getProperty() + ":" + bx.getDescr()); at.setState("open"); treeValue.add(at); } } return SUCCESS; }
public String c_roleToMemberOrgAtt() throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException { String url = "cfg_c_Role_toMemberOrgAtt.sg"; if ("1".equals(isPage)) { // 返回定制页 bean = baseDao.get(Role.class, String.valueOf(idField.get(bean))); StringBuilder orgTree = new StringBuilder(); Role role = (Role) bean; orgTree.append( "<div style='width:30%;'>" + "组织:" + role.getDescr() + "<a class='easyui-linkbutton' onclick='getChecked()'>保存</a> <a class='easyui-linkbutton' onclick='collapse()'>收起</a> " + "<ul id='roletree' class=\"easyui-tree\" data-options=\"url:'" + url + "?isPage=orgTree&bean.id=" + role.getId() + "',checkbox:true,cascadeCheck:false" + " \"></ul>" + "</div>"); // permissionTree.append("<script>$(function(){$('#roletree').tree({onLoadSuccess:function(node, data){ $('#roletree').tree({onCheck:function(node, checked){alert(node.text+checked);}});}});});function tr(){}</script>"); // permissionTree.append("<script>$(function(){setTimeout('tr()',5000);});function // tr(){$('.tree-checkbox').click(function(){alert(1)});}</script>"); orgTree.append( "<script>function collapse(){$('#roletree').tree('collapseAll');} function getChecked(){var nodes = $('#roletree').tree('getChecked');var s = ''; " + "for(var i=0; i<nodes.length; i++){if (s != '') s += ',';" + "s += nodes[i].id;}" + "$.post('" + url + "?isPage=orgTreeSub',{'id':s,'bean.id':" + role.getId() + "},function(data){alert(data);});}</script>"); setOrgHtml(orgTree.toString()); StringBuilder attSb = new StringBuilder(); attSb.append( "组织属性:<form action='" + url + "?isPage=attSub' method='POST'><input type='submit' value='提交'><p>"); DetachedCriteria dc = DetachedCriteria.forClass(RoleAtt.class); dc.add(Restrictions.eq("role", bean)).add(Restrictions.eq("enable", Constant.ENABLE_NOR)); List<RoleAtt> ras = baseDao.find(dc); List<NameValuePair> nvlist = Util.nvlist(baseDao, "cfg_org_att"); for (NameValuePair nv : nvlist) { String value = nv.getValue(); if (Util.notEmptyString(value)) { String chk = ""; for (RoleAtt ra : ras) { String att = ra.getAtt(); if (att.equals(value)) { chk = "checked"; } } attSb .append("<input type='checkbox' name='atts' value='" + value + "' " + chk + ">") .append(nv.getName()); } } attSb.append("</form>"); setAttHtml(attSb.toString()); return "page"; } else if ("orgTreeSub".equals(isPage)) { bean = baseDao.get(Role.class, String.valueOf(idField.get(bean))); id = "," + id + ","; DetachedCriteria dc = DetachedCriteria.forClass(RoleOrg.class); dc.add(Restrictions.eq("role", bean)).add(Restrictions.eq("enable", Constant.ENABLE_NOR)); List<RoleOrg> rpl = baseDao.find(dc); for (RoleOrg ro : rpl) { String pid = ro.getOrg().getId(); if (!id.contains("," + pid + ",")) { ro.setEnable(Constant.ENABLE_DEL); ro.setUpdateDate(now); ro.setUpdateMember(sessionMember); baseDao.update(ro); } else { id = id.replace("," + pid + ",", ","); } } if (id.length() > 1) { String[] split = id.split(","); for (String s : split) { if (Util.notEmptyString(s)) { RoleOrg rp = new RoleOrg(); Org one = new Org(); one.setId(s); rp.setOrg(one); rp.setRole((Role) bean); rp.setEnable(Constant.ENABLE_NOR); rp.setCreateDate(now); rp.setCreateMember(sessionMember); baseDao.save(rp); } } } setBodyHtml(Constant.UPDATE_SUCCESS); return "orgTreeSub"; } else if ("orgTree".equals(isPage)) { // 返回角色对应的组织树 DetachedCriteria dc = DetachedCriteria.forClass(RoleOrg.class); dc.add(Restrictions.eq("role", bean)).add(Restrictions.eq("enable", "1")); List<RoleOrg> rpl = baseDao.find(dc); List<String> mpl = new ArrayList<String>(); for (RoleOrg rp : rpl) { mpl.add(rp.getOrg().getId()); } treeValue = new ArrayList<AsyncTree>(); List<AsyncTree> findTreeValue = Util.findCheckedTreeValue(mpl, new Org(), null, baseDao); treeValue.addAll(findTreeValue); return "orgTree"; } else if ("member".equals(isPage)) { setCoeo(new EasyOut<BaseTO>()); DetachedCriteria dc = DetachedCriteria.forClass(OrgMember.class); Member member_sear = getMbean().getMember(); if (member_sear != null && Util.notEmptyString(member_sear.getDescr())) { dc.createAlias("member", "ms"); dc.add(Restrictions.ilike("ms.descr", member_sear.getDescr(), MatchMode.ANYWHERE)); } if (Util.notEmptyString(inRoleInput)) {} Org org = getMbean().getOrg(); if (org != null && Util.notEmptyString(org.getId())) dc.add(Restrictions.eq("org", org)); dc.add(Restrictions.eq("enable", "1")); getCoeo().setTotal(baseDao.findCount(dc)); if (Util.emptyString(getSort())) { setSort("id"); setOrder("desc"); } dc = DetachedCriteria.forClass(OrgMember.class); if (Util.notEmptyString(getSort()) && !getSort().contains(".")) { // !sortx.contains(".") // :在包含点号时,无法用其进行排序 if ("desc".equals(getOrder())) { dc.addOrder(Order.desc(getSort())); } else { dc.addOrder(Order.asc(getSort())); } dc.addOrder(Order.asc("id")); } if (member_sear != null && Util.notEmptyString(member_sear.getDescr())) { dc.createAlias("member", "ms"); dc.add(Restrictions.ilike("ms.descr", member_sear.getDescr(), MatchMode.ANYWHERE)); } if (org != null && Util.notEmptyString(org.getId())) dc.add(Restrictions.eq("org", org)); dc.add(Restrictions.eq("enable", "1")); List<BaseTO> cl = baseDao.findWithPage2(dc, (getPage() - 1) * getRows(), getRows()); List<BaseTO> ml = new ArrayList<BaseTO>(); for (BaseTO c : cl) { OrgMember x = (OrgMember) c; Member_ForRole mf = new Member_ForRole(); Member member = x.getMember(); mf.setDescr(member.getDescr()); mf.setId(member.getId()); mf.setInRole(inRole(bean, member)); ml.add(mf); } getCoeo().setRows(ml); return "member"; } else if ("memberSub".equals(isPage)) { if (bean != null && getMbean() != null && getMbean().getMember() != null && Util.notEmptyString(getMbean().getMember().getId())) { Member sm = getMbean().getMember(); DetachedCriteria dc = DetachedCriteria.forClass(RoleMember.class); dc.add(Restrictions.eq("role", bean)) .add(Restrictions.eq("member", sm)) .add(Restrictions.eq("enable", "1")); RoleMember rm = baseDao.findBean(dc); if ("1".equals(inOro)) { if (rm == null) { rm = new RoleMember(); rm.setMember(sm); rm.setRole((Role) bean); rm.setEnable("1"); rm.setCreateDate(now); rm.setCreateMember(sessionMember); baseDao.save(rm); } } else { if (rm != null) { rm.setEnable(Constant.ENABLE_DEL); rm.setUpdateDate(now); rm.setUpdateMember(sessionMember); baseDao.update(rm); } } setBodyHtml("ok"); } return "memberSub"; } return SUCCESS; }
public String c_editUnderRole() throws NoSuchFieldException, IllegalAccessException { if ("1".equals(isPage)) { StringBuilder permissionTree = new StringBuilder(); Role role = baseDao.get(Role.class, String.valueOf(idField.get(bean))); permissionTree.append( "<div style='width:30%;float:left;'>" + "角色:" + role.getDescr() + "<a class='easyui-linkbutton' onclick='getChecked()'>保存功能配置</a> <a class='easyui-linkbutton' onclick='collapse()'>收起</a> " + "<ul id='roletree' class=\"easyui-tree\" data-options=\"url:'cfg_c_Role_editUnder.sg?isPage=tree&bean.id=" + role.getId() + "',checkbox:true,cascadeCheck:false, " + // cascadeCheck:false, "onClick: function(node){ $.post('cfg_c_Role_editUnder.sg?isPage=perf&bean.id=" + role.getId() + "&id='+node.id,function(data){$('#perf').html(data);});}" + // ",onCheck:function(node, checked){alert(node.text+checked);}" // + " \"></ul>" + "</div><div id='perf' style='width:70%;float:right;'></div>"); // permissionTree.append("<script>$(function(){$('#roletree').tree({onLoadSuccess:function(node, data){ $('#roletree').tree({onCheck:function(node, checked){alert(node.text+checked);}});}});});function tr(){}</script>"); // permissionTree.append("<script>$(function(){setTimeout('tr()',5000);});function // tr(){$('.tree-checkbox').click(function(){alert(1)});}</script>"); permissionTree.append( "<script>function collapse(){$('#roletree').tree('collapseAll');} function getChecked(){var nodes = $('#roletree').tree('getChecked');var s = ''; " + "for(var i=0; i<nodes.length; i++){if (s != '') s += ',';" + "s += nodes[i].id;}" + "$.post('cfg_c_Role_editUnder.sg?isPage=permissionSub',{'id':s,'bean.id':" + role.getId() + "},function(data){alert(data);});}</script>"); setBodyHtml(permissionTree.toString()); return "page"; } else if ("tree".equals(isPage)) { DetachedCriteria dc = DetachedCriteria.forClass(RolePermission.class); dc.add(Restrictions.eq("role", bean)); List<RolePermission> rpl = baseDao.find(dc); List<String> mpl = new ArrayList<String>(); for (RolePermission rp : rpl) { mpl.add(rp.getPermission().getId()); } treeValue = new ArrayList<AsyncTree>(); List<AsyncTree> findTreeValue = Util.findCheckedTreeValue(mpl, new Permission(), null, baseDao); treeValue.addAll(findTreeValue); return "tree"; } else if ("perf".equals(isPage)) { Permission p = baseDao.get(Permission.class, Integer.valueOf(id)); DetachedCriteria dc = DetachedCriteria.forClass(Perf.class); dc.add(Restrictions.eq("permission", p)); List<Perf> pl = baseDao.find(dc); Role role = baseDao.get(Role.class, String.valueOf(idField.get(bean))); dc = DetachedCriteria.forClass(RolePerf.class); dc.add(Restrictions.eq("role", role)); List<RolePerf> rpl = baseDao.find(dc); // if pl de p in rpl ,then checked StringBuilder res = new StringBuilder(); res.append("表现:(不选则以ord小的)<p>"); for (Perf perf : pl) { String pod = perf.getId(); res.append( "<input type='checkbox' " + (contain(perf, rpl) ? "checked='checked'" : "") + " name='' value='perf:" + pod + "' /><a target='_blank' href='cfg_detailPerf.sg?bean.id=" + pod + "'>") .append(perf.getDescr() + "(" + perf.getOrd() + ")</a><p>"); } dc = DetachedCriteria.forClass(Filter.class); dc.add(Restrictions.eq("permission", p)); List<Filter> fl = baseDao.find(dc); dc = DetachedCriteria.forClass(RoleFilter.class); dc.add(Restrictions.eq("role", role)); List<RoleFilter> rfl = baseDao.find(dc); // if pl de p in rpl ,then checked res.append("数据过滤:(不选则无过滤)<p>"); for (Filter filter : fl) { String pod = filter.getId(); res.append( "<input type='checkbox' " + (contain(filter, rfl) ? "checked='checked'" : "") + " name='' value='filter:" + pod + "' /><a target='_blank' href='cfg_detailFilter.sg?bean.id=" + pod + "'>") .append(filter.getDescr() + "(" + filter.getOrd() + ")</a><p>"); } res.append( "<script>$(function(){if ($.browser.msie) " + "{ $('input:checkbox').click(function () " + "{ this.blur(); this.focus(); }); } $('input:checkbox').change(function(){" + "$.post('cfg_c_Role_editUnder.sg?isPage=perfSub',{'id':$(this).val(),'check':$(this).attr('checked'),'bean.id':" + role.getId() + "}," + "function(data){alert(data)}); " + "});});</script>"); setBodyHtml(res.toString()); return "perf"; } // 提交Permission修正 else if ("permissionSub".equals(isPage)) { bean = baseDao.get(Role.class, String.valueOf(idField.get(bean))); id = "," + id + ","; DetachedCriteria dc = DetachedCriteria.forClass(RolePermission.class); dc.add(Restrictions.eq("role", bean)); List<RolePermission> rpl = baseDao.find(dc); for (RolePermission rp : rpl) { String pid = rp.getPermission().getId(); if (!id.contains("," + pid + ",")) { baseDao.delete(rp); } else { id = id.replace("," + pid + ",", ","); } } if (id.length() > 1) { String[] split = id.split(","); for (String s : split) { if (Util.notEmptyString(s)) { RolePermission rp = new RolePermission(); Permission one = new Permission(); one.setId(s); rp.setPermission(one); rp.setRole((Role) bean); baseDao.save(rp); } } } setBodyHtml(Constant.UPDATE_SUCCESS); return SUCCESS; } // 提交Perf或者Filter else if ("perfSub".equals(isPage)) { bean = baseDao.get(Role.class, String.valueOf(idField.get(bean))); if (Util.notEmptyString(id)) { if (id.startsWith("perf:")) { String idStr = id.replace("perf:", ""); Perf perf = baseDao.get(Perf.class, Integer.valueOf(idStr)); if (perf != null) { if ("checked".equals(check)) { RolePerf rp = new RolePerf(); rp.setPerf(perf); rp.setRole((Role) bean); baseDao.save(rp); } else { DetachedCriteria dc = DetachedCriteria.forClass(RolePerf.class); dc.add(Restrictions.eq("perf", perf)); dc.add(Restrictions.eq("role", bean)); RolePerf findBean = baseDao.findBean(dc); if (findBean != null) { baseDao.delete(findBean); } } } } else if (id.startsWith("filter:")) { String idStr = id.replace("filter:", ""); Filter perf = baseDao.get(Filter.class, Integer.valueOf(idStr)); if (perf != null) { if ("checked".equals(check)) { RoleFilter rp = new RoleFilter(); rp.setFilter(perf); rp.setRole((Role) bean); baseDao.save(rp); } else { DetachedCriteria dc = DetachedCriteria.forClass(RoleFilter.class); dc.add(Restrictions.eq("filter", perf)); dc.add(Restrictions.eq("role", bean)); RoleFilter findBean = baseDao.findBean(dc); if (findBean != null) { baseDao.delete(findBean); } } } } setBodyHtml(Constant.UPDATE_SUCCESS); return SUCCESS; } } return SUCCESS; }
public String edit() throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException, SQLException { DetachedCriteria dc = DetachedCriteria.forClass(bean.getClass()); dc.add(Restrictions.eq(Constant.ID, idField.get(bean))); Property old = baseDao.findBean(dc); super.edit(); // 相应修改数据库的表中的字段 if (1 == getCfg_res() && !Util.notEmptyString(isPage)) { Property oldp = (Property) old; String lengthOld = oldp.getLength(); String propertyNameOld = oldp.getProperty(); String typeOld = oldp.getType(); Property newp = (Property) bean; String lengthNew = newp.getLength(); String propertyNameNew = newp.getProperty(); String typeNew = newp.getType(); if (lengthOld == null) lengthOld = ""; if (typeOld == null) typeOld = ""; if (propertyNameOld.equals(propertyNameNew)) { if (!lengthOld.equals(lengthNew) || !typeOld.equals(typeNew)) { // alter table 表名 modify 列名 新类型 新参数【修改列类型】 // 例:alter table test modify gender char(4) not null // default ''; Connection con = null; PreparedStatement ps = null; try { con = LocalConnetionPool.getConnection(); Bean beanBean = baseDao.get(Bean.class, oldp.getBean().getId()); if (!Util.notEmptyString(lengthNew)) { lengthNew = "0"; } String sql = "alter table " + beanBean.getTableName() + " modify " + propertyNameOld + " " + typeNew + "(" + lengthNew + ")"; ps = con.prepareStatement(sql); ps.execute(); } finally { ps.close(); con.close(); } } } else { // alter table 表名 change 旧列名 新列名 新类型 新参数【修改列名和列类型】 // 例:alter table test change pid uid int unsigned not null // default 0; Connection con = null; PreparedStatement ps = null; try { con = LocalConnetionPool.getConnection(); Bean beanBean = baseDao.get(Bean.class, oldp.getBean().getId()); String sql = "alter table " + beanBean.getTableName() + " change " + propertyNameOld + " " + propertyNameNew + " " + typeNew + "(" + lengthNew + ")"; ps = con.prepareStatement(sql); ps.execute(); } finally { ps.close(); con.close(); } } } return SUCCESS; }