123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777 |
- package com.sinosoft.lz.system.right.role.service;
- import java.io.UnsupportedEncodingException;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Date;
- import java.util.Iterator;
- import java.util.List;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.PathParam;
- import javax.ws.rs.ProduceMime;
- import org.apache.log4j.Logger;
- import com.formaction.Utils;
- import com.formaction.vo.Msg;
- import com.persistence.DbConnection;
- import com.persistence.service.JDBCHelper;
- import com.persistence.service.PersistenceFactory;
- import com.persistence.service.SysPersistence;
- import com.persistence.service.assitant.generator.CodeGenerator;
- import com.persistence.service.exception.PersistenceException;
- import com.sinosoft.lz.system.function.busi.FunctionBean;
- import com.sinosoft.lz.system.function.vo.FunctionButtonVO;
- import com.sinosoft.lz.system.function.vo.FunctionVO;
- import com.sinosoft.lz.system.right.role.busi.RoleBean;
- import com.sinosoft.lz.system.right.role.busi.SysRoleRightRelBean;
- import com.sinosoft.lz.system.right.role.dao.RoleDAO;
- import com.sinosoft.lz.system.right.role.vo.RoleVO;
- import com.sinosoft.lz.system.right.role.vo.SysRoleRightRelVO;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.MdpModule;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- import com.sysmodel.datamodel.xmlmodel.impl.MdpModuleImpl;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- @Path("/RoleService/")
- public class RoleService{
- private Logger log = Logger.getLogger(this.getClass());
- // 编码解析
- protected String decode(String params) {
- try {
- params = java.net.URLDecoder.decode(params, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return params;
- }
- /**
- * 所有按钮列表服务
- *
- * @param params
- * @return
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- @ProduceMime("application/json")
- @POST
- @Path("/getRoleList")
- public String getRoleList() throws Exception {
- StringBuffer sb = new StringBuffer();
- String sql = "select * from SYS_Role where role_type='0'";
- RoleBean roleBean = new RoleBean();
- Collection<RoleVO> coll = roleBean.getSysRole(sql);
- sb.append("[");
- Iterator<RoleVO> it = coll.iterator();
- while (it.hasNext()) {
- RoleVO vo = it.next();
- sb.append("{\"FD_OBJECTID\":\"" + vo.getFdObjectid() + "\",\"ROLE_TYPE\":\""
- + vo.getIsDel() + "\",\"ROLE_ID\":\"" + vo.getRoleId() + "\"");
- sb.append(",\"ROLE_NAME\":\"" + vo.getRoleName() + "\"},");
- }
- if (sb.lastIndexOf(",") > -1) {
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- sb.append("]");
- log.info("json:" + sb);
- return sb.toString();
- }
-
- /**
- * 获取角色名称和id,用于下拉框
- * 格式如:{"list":[{"value":"1","key":"人身事故"},{"value":"2","key":"电网事故"},{"value":"3","key":"设备事故"},{"value":"4","key":"防风防汛"}]}
- * @param params
- * @return
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- @ProduceMime("application/json")
- @POST
- @Path("/getRoleKVs")
- public String getRoleKVs() throws Exception {
- StringBuffer sb = new StringBuffer();
- String sql = "select role_id,role_name from SYS_Role ";
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- stat = conn.createStatement();
- rs = stat.executeQuery(sql);
- sb.append("{\"list\":[");
- while (rs.next()) {
- String roleId = (String) rs.getString("role_id") == null ? "": rs.getString("role_id");
- String roleName = (String) rs.getString("role_name") == null ? "" : rs.getString("role_name");
- sb.append("{\"value\":\"" + roleId + "\",\"key\":\"" + roleName + "\"},");
- }
- if (sb.lastIndexOf(",") > -1) {
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- sb.append("]}");
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("取得RoleKVs集合" + sql, e);
- } finally {
- db.close(rs);
- db.close(stat);
- db.close(conn);
- }
- log.info("json:" + sb);
- return sb.toString();
- }
- /**
- * 获取所有功能点
- *
- * @return
- * @throws Exception
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getRoleButtonList/{roleId}")
- public String getFunctionList(@PathParam("roleId") String roleId) throws Exception {
- StringBuffer sb = new StringBuffer();
- sb.append("[");
- sb.append(getTreeJson(roleId));
- if (sb.lastIndexOf(",") > -1) {
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- sb.append("]");
- log.info("json:" + sb);
- return sb.toString();
- }
- private StringBuffer getTreeJson(String roleId) throws ClassNotFoundException {
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- StringBuffer sb = new StringBuffer();
- SysModel sysmodel = ModelFactory.getSysmodel();
- ArrayList<MdpModuleImpl> mdplist = sysmodel.getMdpModules();
- String sql = "select module_id from SYS_function group by module_id";
- FunctionBean functionBean = new FunctionBean();
- try {
- conn = db.getConnection();
- stat = conn.createStatement();
- rs = stat.executeQuery(sql);
- while (rs.next()) {
- String[] moduleCode = rs.getString(1).split("_");
- MdpModule mdp = sysmodel.getMdpModuleByCode(moduleCode[1]);
- for (MdpModuleImpl mdps : mdplist) {
- if (moduleCode[1].equals(mdps.getCode()) && mdps.getPcode().equals("")) {
- sb.append("{\"module_id\":\"" + mdp.getName() + "\",\"id\":\""
- + mdp.getCode() + "\",\"state\":\"closed\"},");
- } else {
- if (moduleCode[1].equals(mdps.getCode())) {
- sb.append("{\"module_id\":\"" + mdp.getName() + "\",\"id\":\""
- + mdp.getCode() + "\",\"state\":\"closed\"");
- // sb.append("\"caozuo\":\"<input name='"+mdp.getName()+"' value='"+mdp.getName()+"' onclick=checkAllBox(this,'"+mdp.getCode()+"') type='checkbox'/>全选\"");
- ArrayList<FunctionVO> functionVO = (ArrayList<FunctionVO>) functionBean
- .getSysFunction("select * from SYS_function where module_id='"
- + rs.getString(1) + "'");
- sb.append(",\"children\":[");
- for (FunctionVO fvo : functionVO) {
- String[] fmoduleCode = fvo.getModuleId().split("_");
- MdpModule fmdp = sysmodel.getMdpModuleByCode(fmoduleCode[1]);
- sb.append("{\"fd_objectid\":\"" + fvo.getFdObjectid()
- + "\",\"id\":\"" + fvo.getId() + "\",\"name\":\""
- + fvo.getName() + "\",\"module_id\":\"" + fmdp.getName()
- + "\"");
- // sb.append(",\"caozuo\":\"<input value='"+fvo.getId()+"' onclick=checkAllBox(this,'selected') type='checkbox'/>全选\"");
- ArrayList<FunctionButtonVO> fbvList = (ArrayList<FunctionButtonVO>) functionBean
- .getSysFunctionButton("select * from SYS_FUNCTION_BUTTON where fun_id='"
- + fvo.getFdObjectid() + "'");
- sb.append(",\"button\":\"");
- for (FunctionButtonVO fbv : fbvList) {
- // sb.append("<input type='checkbox' id='selected' value='"+fbv.getFdObjectid()+"' name='selected' "+this.getChecked(fbv.getFdObjectid(),
- // roleId)+" onClick=checkData(this,'selected');>");
- sb.append("<input type='checkbox' id='selected' value='"
- + fbv.getFdObjectid() + "' name='selected' "
- + this.getChecked(fbv.getFdObjectid(), roleId) + ">");
- sb.append(fbv.getName() + " </input>");
- }
- sb.append("" + "\",\"state\":\"open\"");
- sb.append("},");
- }
- if (sb.lastIndexOf(",") > -1) {
- sb.deleteCharAt(sb.lastIndexOf(","));
- }
- sb.append("]");
- sb.append("},");
- }
- }
- }
- }
- } catch (SQLException e) {
- log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 取得SysFunctionVO集合" + sql, e);
- } finally {
- db.close(rs);
- db.close(stat);
- db.close(conn);
- }
- return sb;
- }
- @SuppressWarnings("rawtypes")
- private boolean isValueInVector(String value, ArrayList rsVec) {
- String[] temp = null;
- if (rsVec != null) {
- for (int i = 0; i < rsVec.size(); i++) {
- temp = (String[]) rsVec.get(i);
- temp[0] = temp[0] == null ? "" : temp[0];
- if (value.equals(temp[0]))
- return true;
- }
- }
- return false;
- }
- @SuppressWarnings("rawtypes")
- public String getChecked(String value, String roleId) {
- String sql = "select Right_ID FROM SYS_ROLE_RIGHT_REL WHERE Role_ID='" + roleId + "'";
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- ArrayList rsVec;
- try {
- rsVec = persistence.getSearchResult(886, sql);
- if (isValueInVector(value, rsVec)) {
- return "checked";
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return "";
- }
- /**
- * 按钮的新增 选择按钮的入库,修改 所选择的按钮的展示
- *
- * @throws ClassNotFoundException
- */
- @POST
- @Path("/saveRole")
- public String saveRole(String params) throws ClassNotFoundException {
- String msg = "";
- params = decode(params);
- log.info(params);
- RoleBean roleBean = new RoleBean();
- String name = Utils.getParameter("role_name", params) == null ? "" : Utils.getParameter(
- "role_name", params);
- String role_type = Utils.getParameter("role_type", params) == null ? "" : Utils
- .getParameter("role_type", params);
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
- "deptId", params);
- String roleId = CodeGenerator.produceIdentity(881);
- RoleVO vo = new RoleVO();
- vo.setRoleId(roleId);
- vo.setRoleName(name);
- // vo.setRoleDescription(name);
- // vo.setRoleState(1);
- // vo.setRoleType(role_type);
- // vo.setCreateUnit(deptId);
- boolean flag = roleBean.addSysRole(vo);
- if (!flag) {
- msg = "{\"success\":" + new Boolean(true).toString() + "}";
- } else {
- msg = "{\"success\":" + new Boolean(false).toString() + "}";
- }
- log.info(msg);
- return msg;
- }
- /**
- * 按钮的修改 选择按钮的入库,修改 所选择的按钮的展示
- *
- * @throws ClassNotFoundException
- */
- @POST
- @Path("/updateRole")
- public String updateRole(String params) throws ClassNotFoundException {
- String msg = "";
- log.info(params);
- params = decode(params);
- String fd_objectid = Utils.getParameter("fd_objectid", params) == null ? "" : Utils
- .getParameter("fd_objectid", params);
- String name = Utils.getParameter("role_name", params) == null ? "" : Utils.getParameter(
- "role_name", params);
- RoleBean roleBean = new RoleBean();
- RoleVO vo = roleBean.getRoleVO(fd_objectid);
- vo.setRoleName(name);
- // vo.setRoleDescription(name);
- boolean flag = roleBean.modifySysRole(vo);
- log.info(flag);
- if (flag) {
- msg = "{\"success\":" + new Boolean(true).toString() + "}";
- } else {
- msg = "{\"success\":" + new Boolean(false).toString() + "}";
- }
- return msg;
- }
- /**
- * 按钮的删除 选择按钮的入库,修改 所选择的按钮的展示
- *
- * @throws ClassNotFoundException
- */
- @POST
- @Path("/deleteRole")
- public String deleteRole(String params) throws ClassNotFoundException {
- String msg = "";
- params = decode(params);
- RoleBean roleBean = new RoleBean();
- String roleId = Utils.getParameter("roleId", params) == null ? "" : Utils.getParameter(
- "roleId", params);
- boolean flag = roleBean.delSysRole(roleId);
- log.info(flag);
- if (flag) {
- msg = "{\"success\":" + new Boolean(true).toString() + "}";
- } else {
- msg = "{\"success\":" + new Boolean(false).toString() + "}";
- }
- return msg;
- }
- @POST
- @Path("/saveRoleButton")
- public String saveRoleButton(String params) throws ClassNotFoundException {
- params = decode(params);
- log.info(params);
- String msg = "";
- String roleId = Utils.getParameter("roleId", params) == null ? "" : Utils.getParameter(
- "roleId", params);
- String roleType = Utils.getParameter("roleType", params) == null ? "" : Utils.getParameter(
- "roleType", params);
- String buttonStr = Utils.getParameter("selected", params) == null ? "" : Utils
- .getParameter("selected", params);
- SysRoleRightRelBean roleBean = new SysRoleRightRelBean();
- SysRoleRightRelVO relvo = roleBean.getSysRoleRightRelVO(roleId);
- if (relvo != null) {
- roleBean.delSysRoleRightRel(roleId);
- }
- SysRoleRightRelVO vo = null;
- ArrayList<SysRoleRightRelVO> voList = new ArrayList<SysRoleRightRelVO>();
- String[] str = buttonStr.split(",");
- for (int i = 0; i < str.length; i++) {
- vo = new SysRoleRightRelVO();
- vo.setRoleId(roleId);
- vo.setRoleType(roleType);
- vo.setRightId(str[i]);
- voList.add(vo);
- }
- int[] num = roleBean.addSysRoleRightRel(voList);
- if (num.length > 0) {
- msg = "{\"success\":" + new Boolean(true).toString() + "}";
- } else {
- msg = "{\"success\":" + new Boolean(false).toString() + "}";
- }
- log.info(msg);
- return msg;
- }
- /**
- * 功能:根据角色类型查询所有角色
- *
- * @param params
- * @return
- * @throws Exception
- */
- @SuppressWarnings("rawtypes")
- @ProduceMime("application/json")
- @POST
- @Path("/getRoleInfo")
- public String getRoleInfo(String params) {
- // 角色类型
- String result = null;
- RoleDAO dao = new RoleDAO();
- List list = dao.loadRoleInfoByCondition();
- result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
- log.info(result);
- return result;
- }
-
-
- /**
- * 功能:获取角色菜单多选下拉框
- *
- * @param params
- * @return
- * @throws Exception
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getMenuTreeRole")
- public String getMenuTreeRole(String params){
- log.info(params);
- // String[] condition = node.split("node=");
- String node = Utils.getParameter("id", params)== null ? "0" : Utils.getParameter("id", params);
- String role_id = Utils.getParameter("role_id", params)== null ? "1" : Utils.getParameter("role_id", params);
- JDBCHelper jdbc = new JDBCHelper();
- jdbc.begin();
- ArrayList<String[]> list = new ArrayList<String[]>();
-
- StringBuffer buf=new StringBuffer();
- buf.append("select distinct m4.menu_id,m4.parent_menu_id,m4.menu_name,m4.fd_objectid,m3.is_parent from \n");
- buf.append("( select m1.menu_id menu_id,m1.parent_menu_id,m1.menu_name,m2.fd_objectid \n");
- buf.append("from SYS_MENU m1 left join SYS_ROLE_RIGHT_REL m2 on m1.menu_id=m2.menu_id and m2.is_del = '0' and m2.role_id='"+role_id+"' \n");
- buf.append(") m4 left join ( select parent_menu_id is_parent from sys_menu where is_del='0' group by parent_menu_id ) m3 on m4.menu_id=m3.is_parent \n");
- log.info(buf.toString());
- try {
- list = jdbc.getSearchResult(99, buf.toString());
- }catch(Exception e){
- e.printStackTrace();
- jdbc.rollback();
- }finally{
- if(jdbc!=null){
- jdbc.release();
- }
- }
- StringBuffer json = new StringBuffer();
- json.append("{treeNodes:[");
- String[] temp = null;
- String code = "";
- String parentcode = "";
- String fd_RightName = "";
- String flag = "true";
- String checked = "";
- String isparent="";
- if(list.size()>0){
- for (int i = 0 ; i< list.size() ; i++){
- temp = list.get(i);
- code = temp[0];
- parentcode = temp[1];
- fd_RightName = temp[2];
- checked=temp[3];
- isparent=temp[4];
- if(isparent!=null){
- flag="true";
- }else{
- flag="false";
- }
- json.append("{");
- json.append("id:'"+code+"',parentId:'"+parentcode+"',");
- json.append("isParent:'"+flag+"',");
- json.append("name:'"+fd_RightName+"',");
- json.append("icon:'/nwyj/images/system/button/toc_closed.gif'");
-
- if(checked!=null){
- json.append(",checked:'true'");
- }
- json.append("},");
- }
- }
- if(json.lastIndexOf(",") > -1){
- json.deleteCharAt(json.lastIndexOf(","));
- }
- json.append("]}");
-
-
-
- //log.info(JSONObject.fromObject(json.toString()).toString());
- System.out.println(JSONObject.fromObject(json.toString()).toString());
- return JSONObject.fromObject(json.toString()).toString();
-
- }
- /**
- * 功能:系统搜索模块单选下拉框
- *
- * @param params
- * @return
- * @throws Exception
- */
- @ProduceMime("application/json")
- @POST
- @Path("/getSearchTree")
- public String getSearchTree(){
- JDBCHelper jdbc = new JDBCHelper();
- jdbc.begin();
- ArrayList<String[]> list = new ArrayList<String[]>();
-
- StringBuffer buf=new StringBuffer();
- buf.append(" select * from ( ( select menu_id,menu_name ,parent_menu_id from sys_menu where length(menu_id)=5 ) t1 left join \n");
- buf.append(" (select parent_menu_id is_parent from sys_menu group by parent_menu_id ) t2 on t1.menu_id=t2.is_parent ) \n");
- log.info(buf.toString());
- try {
- list = jdbc.getSearchResult(99, buf.toString());
- }catch(Exception e){
- e.printStackTrace();
- jdbc.rollback();
- }finally{
- if(jdbc!=null){
- jdbc.release();
- }
- }
- StringBuffer json = new StringBuffer();
- json.append("{treeNodes:[");
- String[] temp = null;
- String menu_id = "";
- String menu_name = "";
- String parent_menu_id;
- String isparent="";
- String flag="false";
- if(list.size()>0){
- for (int i = 0 ; i< list.size() ; i++){
- temp = list.get(i);
- menu_id = temp[0];
- menu_name = temp[1];
- parent_menu_id=temp[2];
- isparent = temp[3];
- if(isparent!=null){
- flag="true";
- }else{
- flag="false";
- }
- json.append("{");
- json.append("id:'"+menu_id+"',parentId:'"+parent_menu_id+"',");
- json.append("isParent:'"+flag+"',");
- json.append("name:'"+menu_name+"',");
- json.append("icon:'/nwyj/images/system/button/toc_closed.gif'");
- json.append("},");
- }
- }
- if(json.lastIndexOf(",") > -1){
- json.deleteCharAt(json.lastIndexOf(","));
- }
- json.append("]}");
-
-
-
- log.info(JSONObject.fromObject(json.toString()).toString());
- return JSONObject.fromObject(json.toString()).toString();
- }
-
- /**
- * 保存菜单与角色的关系
- * @param params
- * @return
- */
- @ProduceMime("application/json")
- @POST
- @Path("/saveMenuRoleRel")
- public Msg saveMenuRoleRel(String params){
- //按钮id
- String buttonIds=Utils.getParameter("buttonIds", params)== null ? "" : Utils.getParameter("buttonIds", params);
- log.info(buttonIds);
- //角色id
- String roleId=Utils.getParameter("roleId", params)== null ? "" : Utils.getParameter("roleId", params);
- //删除该角色已有的按钮分配信息
- String sql = "delete from SYS_ROLE_RIGHT_REL where ROLE_ID='"+roleId+"'";
- //返回信息
- Msg msg=new Msg();
- JDBCHelper jdbc=new JDBCHelper();
- jdbc.begin();
- msg.setSucsess("true");
- ArrayList<String> list=new ArrayList<String>();
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
- try {
- jdbc.executeUpdateSQL(sql);//执行删除sql
- //拆分按钮id
- String[] s = buttonIds.split("#");
- for(String str:s){
- //插入语句
- sql="insert into SYS_ROLE_RIGHT_REL values('"+roleId+"','"+roleId+"','"+str+"','0','"+df.format(new Date())+"')";
- //将插入语句放入list,批量保存
- list.add(sql);
- }
- //执行批量保存方法
- jdbc.executeUpdateSQL(list);
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- //事务回滚
- jdbc.rollback();
- //输出错误信息
- log.error(e.getMessage(),e);
- //返回错误信息
- msg.setSucsess("error");
- }
- jdbc.commit();
- return msg;
- }
-
-
- @ProduceMime("application/json")
- @POST
- @Path("/getOrgTree")
- public String getOrgTree(String params){
- log.info(params);
- String node = Utils.getParameter("id", params)== null ? "1" : Utils.getParameter("id", params);
- JDBCHelper jdbc = new JDBCHelper();
- jdbc.begin();
- ArrayList<String[]> list = new ArrayList<String[]>();
- String sql = "select dept_id ,parent_id , dept_name from sys_department where parent_id = '"+node+"'";
- log.info(sql);
- try {
- list = jdbc.getSearchResult(99, sql);
- }catch(Exception e){
- e.printStackTrace();
- jdbc.rollback();
- }finally{
- if(jdbc!=null){
- jdbc.release();
- }
- }
- StringBuffer json = new StringBuffer();
- json.append("{treeNodes:[");
- String[] temp = null;
- String code = "";
- String parentcode = "";
- String fd_RightName = "";
- String flag = "true";
- if(list.size()>0){
- for (int i = 0 ; i< list.size() ; i++){
- temp = list.get(i);
- code = temp[0];
- parentcode = temp[1];
- fd_RightName = temp[2];
- if(!isOrgLeaf(code)){
- flag="false";
- }else{
- flag="true";
- }
- json.append("{");
- json.append("id:'"+code+"',parentId:'"+parentcode+"',");
- json.append("isParent:'"+flag+"',");
- json.append("name:'"+fd_RightName+"',");
- json.append("icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
- json.append("},");
- }
- }
- if(json.lastIndexOf(",") > -1){
- json.deleteCharAt(json.lastIndexOf(","));
- }
- json.append("]}");
-
-
-
- log.info(JSONObject.fromObject(json.toString()).toString());
- return JSONObject.fromObject(json.toString()).toString();
-
- }
- //判定是否有子节点
- public boolean isOrgLeaf (String node){
- boolean flag = false;
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- ArrayList<String[]> childList = new ArrayList<String[]>();
- String sql = "select dept_id from sys_department where parent_id = '" + node + "'";
-
- // log.debug("判断是否有子节点:"+sql);
- try{
- childList = persistence.getSearchResult(99,sql);
- }catch(PersistenceException e){
- e.printStackTrace();
- }
- if(childList.size() > 0){
- flag = true;
- }
- return flag;
- }
-
- //删除角色,包括角色表、角色按钮关联表、角色菜单关联表
- @ProduceMime("application/json")
- @POST
- @Path("/deleteRoleID")
- public String deleteRoleID(String params){
- String flag="false";
- try {
- params=new String(params.getBytes("ISO8859-1"),"UTF-8");
- } catch (UnsupportedEncodingException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- String[] strs=params.split(",");
- DbConnection dbConn = new DbConnection();
- Connection conn = null;
- PreparedStatement pstm1 = null;
- PreparedStatement pstm2 = null;
- PreparedStatement pstm3 = null;
- String SQL1="delete from sys_role where fd_objectid = ?";
- String SQL2="delete from SYS_ROLE_BUTTON_REL where ROLE_ID = ?";
- String SQL3="delete from SYS_ROLE_RIGHT_REL where ROLE_ID= ?";
- try{
- conn=dbConn.getConnection();
- conn.setAutoCommit(false);
- pstm1=conn.prepareStatement(SQL1);
- pstm2=conn.prepareStatement(SQL2);
- pstm3=conn.prepareStatement(SQL3);
- for(int i=0;i<strs.length;i++){
-
- pstm1.setString(1, strs[i]);
- pstm2.setString(1, strs[i]);
- pstm3.setString(1, strs[i]);
- pstm1.executeUpdate();
- pstm2.executeUpdate();
- pstm3.executeUpdate();
- }
- conn.commit();
- conn.setAutoCommit(true);
- //System.out.println(123123123);
- flag="true";
- }catch(Exception e){
- try {
- conn.rollback();
- conn.setAutoCommit(true);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- e.printStackTrace();
-
- }finally{
- try {
- if(pstm1!=null)
- pstm1.close();
- if(pstm2!=null)
- pstm2.close();
- if(pstm3!=null)
- pstm3.close();
- if(conn!=null)
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
-
- return flag;
- }
-
- }
|