package com.system.button; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.ProduceMime; import org.apache.log4j.Logger; import com.formaction.Utils; import com.formaction.vo.Msg; 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.assitant.generator.IdentityGenerator; import com.persistence.service.exception.PersistenceException; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; @Path("/MenuService") public class MenuService { 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; } @ProduceMime("application/json") @POST @Path("/getButtonList") public String getButtonList(String params) throws Exception{ SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json=new StringBuffer(); String isHidden = "0"; String code = null; String fd_code= null; try{ params = decode(params); String node = Utils.getParameter("node", params)== null ? "" : Utils.getParameter("node", params); String sql="select distinct t.fd_code,t.fd_rightname,t.fd_objecttype,t.fd_objectid from bm$_objecttree t";//将按钮全部查询出来 ArrayList list = persistence.getSearchResult(99,sql); // log.info("将按钮全部查询出来:"+sql); String sql1 = "select Button_ID from Menu_Assign where Menu_ID='"+node+"'";//分配的按钮 ArrayList list1 = persistence.getSearchResult(888,sql1); // log.info("分配的按钮:"+sql1); // log.info("list1.size():"+list1.size()); if (list.size() >0) { json.append("["); if(list1.size()>0){ for(int j=0;j -1){ json.deleteCharAt(json.lastIndexOf(",")); } json.append("]"); }else{ json.append("["); for(int i=0;i -1){ json.deleteCharAt(json.lastIndexOf(",")); } json.append("]"); } }catch(Exception e){ e.printStackTrace(); } log.info("json:"+json.toString()); return json.toString(); } /** * 菜单对像分配,插入到Menu_Assign表中 * @param params * @return * @throws Exception */ @ProduceMime("application/json") @POST @Path("/getMenuList1") public Msg getMenuList1(String params) throws Exception{ JDBCHelper jdbc = new JDBCHelper(); jdbc.begin(); // ServerConfigure sc=ServerConfigure.getServerConfigerInstance(); // Connection mycon=sc.getDataSource().getConnection(); // mycon.setAutoCommit(false); // String sql="insert into Menu_Assign(FD_OBJECTID,Menu_ID,Button_ID) " + // "values(?,?,?)"; // PreparedStatement ps = mycon.prepareStatement(sql); Map map = new HashMap(); String id = null; String isleaf = null; String parentid = null; // String sql=""; Msg msg = new Msg(); int flag = 0; try{ params = decode(params); String code = Utils.getParameter("roleId", params)== null ? "" : Utils.getParameter("roleId", params); String str = Utils.getParameter("str", params)== null ? "" : Utils.getParameter("str", params); String tableName="Menu_Assign"; String name="Menu_ID"; int deleteFlag = deleteRoleMenu(code,tableName,name,jdbc);//插入前先清数据 String[] s = str.split(":");//4 int insertFlag = -1; for(int a = 0;a-1&&insertFlag>-1){ jdbc.commit(); }else { jdbc.rollback(); } }catch(Exception e){ e.printStackTrace(); if(jdbc!=null){ jdbc.rollback(); } }finally{ if(jdbc!=null){ jdbc.release(); } } msg.setObjectID("1"); return msg; } /* * 新增角色的时候先查询角色ID * */ @ProduceMime("application/json") @POST @Path("/selectRoleID") public Msg selectRoleID(){ Msg msg = new Msg(); CodeGenerator IDMaker = new CodeGenerator(); String roleId = IDMaker.produceIdentity(881); log.info("roleId:"+roleId); if(roleId.length()>1){ msg.setInfo(roleId); } return msg; } /* * 菜单角色分配 * */ @ProduceMime("application/json") @POST @Path("/getRoleMenuList") public Msg getRoleMenuList(String params) throws Exception{ // ServerConfigure sc=ServerConfigure.getServerConfigerInstance(); // Connection mycon=sc.getDataSource().getConnection(); // mycon.setAutoCommit(false); // String sql="insert into SysUser_RoleRightRel(FD_OBJECTID,Role_ID,Role_Type,Right_ID,Right_Type) " + // "values(?,?,'0',?,?)"; // PreparedStatement ps = mycon.prepareStatement(sql); String id = null; String isleaf = null; String parentid = null; String type = null; Msg msg = new Msg(); JDBCHelper jdbc = new JDBCHelper(); jdbc.begin(); try{ params = decode(params); String code = Utils.getParameter("roleId", params)== null ? "" : Utils.getParameter("roleId", params); // log.info("角色ID=菜单角色分配:"+code); String str = Utils.getParameter("str", params)== null ? "" : Utils.getParameter("str", params); // log.info("str:"+str); String tableName="SysUser_RoleRightRel"; String name="Role_ID"; int deleteFlag = deleteRoleMenu(code,tableName,name,jdbc);//插入前先清数据 // deleteRoleMenu(code,tableName,name,mycon);//插入前先清数据 //100d07#1#100d:001#2#100d07:100d05#1#100d:001#2#100d05: String[] s = str.split(":");//4 int insertFlag = -1; for(int a = 0;a-1&&insertFlag>-1){ if(jdbc!=null){ jdbc.commit(); } }else{ if(jdbc!=null){ jdbc.rollback(); } } }catch(Exception e){ e.printStackTrace(); if(jdbc!=null){ jdbc.rollback(); } }finally{ if(jdbc!=null){ jdbc.release(); } } msg.setObjectID("1"); return msg;} /** * 插入前先根据role_id删除 * @param params * @param table * @param name * @throws Exception */ public int deleteRoleMenu(String params,String table,String name,JDBCHelper jdbc) throws Exception{ String sql = ""; int flag =-1; sql="delete from "+table+" where "+ name+"='"+params+"'"; flag = jdbc.executeUpdateSQL(sql.toString()); return flag; } @ProduceMime("application/json") @POST @Path("/showUserButtns") public String showUserButtns(String params) { try { params = java.net.URLDecoder.decode(params, "UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } String objectId = Utils.getParameter("objectId", params)== null ? "" : Utils.getParameter("objectId", params); String userid = Utils.getParameter("userid", params)== null ? "" : Utils.getParameter("userid", params); String sql = "select a.right_id from SysUser_RoleRightRel a,SysUser_UserRoleRel b " + "where a.right_type = '2' and a.Role_ID = b.Role_ID and b.User_ID = '"+userid+"' and a.right_id like '"+objectId+"%'"; // log.info("角色sql:" + sql); JDBCHelper jdbc = new JDBCHelper(); jdbc.begin(); List list = new ArrayList(); String result = ""; try { list = jdbc.getSearchResult(99, sql); if(list.size()>0){ for(String[] str : list){ String string = str[0]==null?"":str[0]; result = result + string + ","; } result = result.substring(0, result.lastIndexOf(',')); //log.info(result); } } catch (PersistenceException e) { e.printStackTrace(); } finally{ jdbc.release(); } return result; } }