123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- 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<String[]> list = persistence.getSearchResult(99,sql);
- // log.info("将按钮全部查询出来:"+sql);
- String sql1 = "select Button_ID from Menu_Assign where Menu_ID='"+node+"'";//分配的按钮
- ArrayList<String[]> 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<list.size();j++){
- String[] indexInfo=(String[]) list.get(j);
- code = indexInfo[0] == null ? " " : indexInfo[0].trim();
- String name11 = indexInfo[1] == null ? " " : indexInfo[1].trim();
- // log.debug(code);
- for(int i=0;i<list1.size();i++){
- String[] indexInfo1=(String[]) list1.get(i);
- fd_code = indexInfo1[0] == null ? " " : indexInfo1[0].trim();
- // log.info(code+"================"+fd_code);
-
- if(fd_code.equals(code)){
- isHidden = "1";
- json.append("{FD_CODE:'"+code+"',fd_rightname:'"+name11+"',isCheck:'"+isHidden+"'},");
- break;
- }
-
- }
- if(!fd_code.equals(code)){
- isHidden = "0";
- json.append("{FD_CODE:'"+code+"',fd_rightname:'"+name11+"',isCheck:'"+isHidden+"'},");
- }
- }
- }else{
- for(int i=0;i<list.size();i++){
- String[] indexInfo=(String[]) list.get(i);
- fd_code = indexInfo[0] == null ? " " : indexInfo[0].trim();
- String name = indexInfo[1] == null ? " " : indexInfo[1].trim();
- // log.info(code+"================"+fd_code);
- isHidden = "0";
- json.append("{FD_CODE:'"+fd_code+"',fd_rightname:'"+name+"',isCheck:'"+isHidden+"'},");
- }
- }
- if(json.lastIndexOf(",") > -1){
- json.deleteCharAt(json.lastIndexOf(","));
- }
- json.append("]");
- }else{
- json.append("[");
- for(int i=0;i<list.size();i++){
- String[] indexInfo=(String[]) list.get(i);
- fd_code = indexInfo[0] == null ? " " : indexInfo[0].trim();
- String name = indexInfo[1] == null ? " " : indexInfo[1].trim();
- // log.info(code+"================"+fd_code);
- isHidden = "0";
- json.append("{FD_CODE:'"+fd_code+"',name:'"+name+"',isCheck:'"+isHidden+"'},");
- }
- if(json.lastIndexOf(",") > -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<String,String> map = new HashMap<String, String>();
- 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<s.length;a++){
- if(!s[0].equals("")){
- String[] s1= s[a].split("#");
- for(int b = 0;b<s1.length;b++){
- id = s1[0] == null ? "" : s1[0].trim();
- isleaf = s1[1] == null ? "" : s1[1].trim();
- parentid= s1[2] == null ? "" : s1[2].trim();
- if(isleaf.equals("1")){
- parentid = code+id;
- }else if(isleaf.equals("2")){
- parentid = code+id;
- }
- }
- String fD_OBJECTID = IdentityGenerator.getIdentityGenerator().gerenalIdentity(888);//生成主键
- String sql="insert into Menu_Assign(FD_OBJECTID,Menu_ID,Button_ID) " +
- "values('"+fD_OBJECTID+"','"+code+"','"+parentid+"')";
- insertFlag = jdbc.executeUpdateSQL(sql);
- // ps.setString(1, fD_OBJECTID);
- // ps.setString(2, code);
- // ps.setString(3, parentid);
- // insertFlag = ps.execute();
- }else{
- insertFlag=0;
- }
- }
- if(deleteFlag>-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<s.length;a++){
- // log.debug("sas:"+s[a]);
- String[] s1= s[a].split("#");
- for(int b = 0;b<s1.length;b++){
- id = s1[0] == null ? "" : s1[0].trim();
- // isleaf = s1[1] == null ? "" : s1[1].trim();
- type= s1[1] == null ? "" : s1[1].trim();
- if(type.equals("1")){
- parentid = id;
- type="1";//1:属于菜单
- }else{
- parentid = id;
- type="2";//1:属于按钮
- }
-
- }
- String fD_OBJECTID = IdentityGenerator.getIdentityGenerator().gerenalIdentity(886);//生成主键
- String sql886="insert into SysUser_RoleRightRel(FD_OBJECTID,Role_ID,Role_Type,Right_ID,Right_Type) " +
- "values('"+fD_OBJECTID+"','"+code+"','0','"+parentid+"','"+type+"')";
- insertFlag = jdbc.executeUpdateSQL(sql886);
- // insertFlag = persistence.executeUpdateSQL(886, sql886);
- // ps.setString(1, fD_OBJECTID);
- // ps.setString(2, code);
- // ps.setString(3, parentid);
- // ps.setString(4, type);
- // insertFlag = ps.execute();
-
- }
- log.debug(deleteFlag+"=="+insertFlag);
- if(deleteFlag>-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<String[]> list = new ArrayList<String[]>();
- 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;
- }
- }
|