78d8e6d56c28b30a42a773f5ce49c372bd504ad1.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. package com.system.button;
  2. import java.io.UnsupportedEncodingException;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.ws.rs.POST;
  8. import javax.ws.rs.Path;
  9. import javax.ws.rs.ProduceMime;
  10. import org.apache.log4j.Logger;
  11. import com.formaction.Utils;
  12. import com.formaction.vo.Msg;
  13. import com.persistence.service.JDBCHelper;
  14. import com.persistence.service.PersistenceFactory;
  15. import com.persistence.service.SysPersistence;
  16. import com.persistence.service.assitant.generator.CodeGenerator;
  17. import com.persistence.service.assitant.generator.IdentityGenerator;
  18. import com.persistence.service.exception.PersistenceException;
  19. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  20. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  21. @Path("/MenuService")
  22. public class MenuService {
  23. private Logger log = Logger.getLogger(this.getClass());
  24. //编码解析
  25. protected String decode(String params) {
  26. try {
  27. params = java.net.URLDecoder.decode(params, "UTF-8");
  28. } catch (UnsupportedEncodingException e) {
  29. e.printStackTrace();
  30. }
  31. return params;
  32. }
  33. @ProduceMime("application/json")
  34. @POST
  35. @Path("/getButtonList")
  36. public String getButtonList(String params) throws Exception{
  37. SysModel sysmodel = ModelFactory.getSysmodel();
  38. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  39. StringBuffer json=new StringBuffer();
  40. String isHidden = "0";
  41. String code = null;
  42. String fd_code= null;
  43. try{
  44. params = decode(params);
  45. String node = Utils.getParameter("node", params)== null ? "" : Utils.getParameter("node", params);
  46. String sql="select distinct t.fd_code,t.fd_rightname,t.fd_objecttype,t.fd_objectid from bm$_objecttree t";//将按钮全部查询出来
  47. ArrayList<String[]> list = persistence.getSearchResult(99,sql);
  48. // log.info("将按钮全部查询出来:"+sql);
  49. String sql1 = "select Button_ID from Menu_Assign where Menu_ID='"+node+"'";//分配的按钮
  50. ArrayList<String[]> list1 = persistence.getSearchResult(888,sql1);
  51. // log.info("分配的按钮:"+sql1);
  52. // log.info("list1.size():"+list1.size());
  53. if (list.size() >0) {
  54. json.append("[");
  55. if(list1.size()>0){
  56. for(int j=0;j<list.size();j++){
  57. String[] indexInfo=(String[]) list.get(j);
  58. code = indexInfo[0] == null ? " " : indexInfo[0].trim();
  59. String name11 = indexInfo[1] == null ? " " : indexInfo[1].trim();
  60. // log.debug(code);
  61. for(int i=0;i<list1.size();i++){
  62. String[] indexInfo1=(String[]) list1.get(i);
  63. fd_code = indexInfo1[0] == null ? " " : indexInfo1[0].trim();
  64. // log.info(code+"================"+fd_code);
  65. if(fd_code.equals(code)){
  66. isHidden = "1";
  67. json.append("{FD_CODE:'"+code+"',fd_rightname:'"+name11+"',isCheck:'"+isHidden+"'},");
  68. break;
  69. }
  70. }
  71. if(!fd_code.equals(code)){
  72. isHidden = "0";
  73. json.append("{FD_CODE:'"+code+"',fd_rightname:'"+name11+"',isCheck:'"+isHidden+"'},");
  74. }
  75. }
  76. }else{
  77. for(int i=0;i<list.size();i++){
  78. String[] indexInfo=(String[]) list.get(i);
  79. fd_code = indexInfo[0] == null ? " " : indexInfo[0].trim();
  80. String name = indexInfo[1] == null ? " " : indexInfo[1].trim();
  81. // log.info(code+"================"+fd_code);
  82. isHidden = "0";
  83. json.append("{FD_CODE:'"+fd_code+"',fd_rightname:'"+name+"',isCheck:'"+isHidden+"'},");
  84. }
  85. }
  86. if(json.lastIndexOf(",") > -1){
  87. json.deleteCharAt(json.lastIndexOf(","));
  88. }
  89. json.append("]");
  90. }else{
  91. json.append("[");
  92. for(int i=0;i<list.size();i++){
  93. String[] indexInfo=(String[]) list.get(i);
  94. fd_code = indexInfo[0] == null ? " " : indexInfo[0].trim();
  95. String name = indexInfo[1] == null ? " " : indexInfo[1].trim();
  96. // log.info(code+"================"+fd_code);
  97. isHidden = "0";
  98. json.append("{FD_CODE:'"+fd_code+"',name:'"+name+"',isCheck:'"+isHidden+"'},");
  99. }
  100. if(json.lastIndexOf(",") > -1){
  101. json.deleteCharAt(json.lastIndexOf(","));
  102. }
  103. json.append("]");
  104. }
  105. }catch(Exception e){
  106. e.printStackTrace();
  107. }
  108. log.info("json:"+json.toString());
  109. return json.toString();
  110. }
  111. /**
  112. * 菜单对像分配,插入到Menu_Assign表中
  113. * @param params
  114. * @return
  115. * @throws Exception
  116. */
  117. @ProduceMime("application/json")
  118. @POST
  119. @Path("/getMenuList1")
  120. public Msg getMenuList1(String params) throws Exception{
  121. JDBCHelper jdbc = new JDBCHelper();
  122. jdbc.begin();
  123. // ServerConfigure sc=ServerConfigure.getServerConfigerInstance();
  124. // Connection mycon=sc.getDataSource().getConnection();
  125. // mycon.setAutoCommit(false);
  126. // String sql="insert into Menu_Assign(FD_OBJECTID,Menu_ID,Button_ID) " +
  127. // "values(?,?,?)";
  128. // PreparedStatement ps = mycon.prepareStatement(sql);
  129. Map<String,String> map = new HashMap<String, String>();
  130. String id = null;
  131. String isleaf = null;
  132. String parentid = null;
  133. // String sql="";
  134. Msg msg = new Msg();
  135. int flag = 0;
  136. try{
  137. params = decode(params);
  138. String code = Utils.getParameter("roleId", params)== null ? "" : Utils.getParameter("roleId", params);
  139. String str = Utils.getParameter("str", params)== null ? "" : Utils.getParameter("str", params);
  140. String tableName="Menu_Assign";
  141. String name="Menu_ID";
  142. int deleteFlag = deleteRoleMenu(code,tableName,name,jdbc);//插入前先清数据
  143. String[] s = str.split(":");//4
  144. int insertFlag = -1;
  145. for(int a = 0;a<s.length;a++){
  146. if(!s[0].equals("")){
  147. String[] s1= s[a].split("#");
  148. for(int b = 0;b<s1.length;b++){
  149. id = s1[0] == null ? "" : s1[0].trim();
  150. isleaf = s1[1] == null ? "" : s1[1].trim();
  151. parentid= s1[2] == null ? "" : s1[2].trim();
  152. if(isleaf.equals("1")){
  153. parentid = code+id;
  154. }else if(isleaf.equals("2")){
  155. parentid = code+id;
  156. }
  157. }
  158. String fD_OBJECTID = IdentityGenerator.getIdentityGenerator().gerenalIdentity(888);//生成主键
  159. String sql="insert into Menu_Assign(FD_OBJECTID,Menu_ID,Button_ID) " +
  160. "values('"+fD_OBJECTID+"','"+code+"','"+parentid+"')";
  161. insertFlag = jdbc.executeUpdateSQL(sql);
  162. // ps.setString(1, fD_OBJECTID);
  163. // ps.setString(2, code);
  164. // ps.setString(3, parentid);
  165. // insertFlag = ps.execute();
  166. }else{
  167. insertFlag=0;
  168. }
  169. }
  170. if(deleteFlag>-1&&insertFlag>-1){
  171. jdbc.commit();
  172. }else {
  173. jdbc.rollback();
  174. }
  175. }catch(Exception e){
  176. e.printStackTrace();
  177. if(jdbc!=null){
  178. jdbc.rollback();
  179. }
  180. }finally{
  181. if(jdbc!=null){
  182. jdbc.release();
  183. }
  184. }
  185. msg.setObjectID("1");
  186. return msg;
  187. }
  188. /*
  189. * 新增角色的时候先查询角色ID
  190. * */
  191. @ProduceMime("application/json")
  192. @POST
  193. @Path("/selectRoleID")
  194. public Msg selectRoleID(){
  195. Msg msg = new Msg();
  196. CodeGenerator IDMaker = new CodeGenerator();
  197. String roleId = IDMaker.produceIdentity(881);
  198. log.info("roleId:"+roleId);
  199. if(roleId.length()>1){
  200. msg.setInfo(roleId);
  201. }
  202. return msg;
  203. }
  204. /*
  205. * 菜单角色分配
  206. * */
  207. @ProduceMime("application/json")
  208. @POST
  209. @Path("/getRoleMenuList")
  210. public Msg getRoleMenuList(String params) throws Exception{
  211. // ServerConfigure sc=ServerConfigure.getServerConfigerInstance();
  212. // Connection mycon=sc.getDataSource().getConnection();
  213. // mycon.setAutoCommit(false);
  214. // String sql="insert into SysUser_RoleRightRel(FD_OBJECTID,Role_ID,Role_Type,Right_ID,Right_Type) " +
  215. // "values(?,?,'0',?,?)";
  216. // PreparedStatement ps = mycon.prepareStatement(sql);
  217. String id = null;
  218. String isleaf = null;
  219. String parentid = null;
  220. String type = null;
  221. Msg msg = new Msg();
  222. JDBCHelper jdbc = new JDBCHelper();
  223. jdbc.begin();
  224. try{
  225. params = decode(params);
  226. String code = Utils.getParameter("roleId", params)== null ? "" : Utils.getParameter("roleId", params);
  227. // log.info("角色ID=菜单角色分配:"+code);
  228. String str = Utils.getParameter("str", params)== null ? "" : Utils.getParameter("str", params);
  229. // log.info("str:"+str);
  230. String tableName="SysUser_RoleRightRel";
  231. String name="Role_ID";
  232. int deleteFlag = deleteRoleMenu(code,tableName,name,jdbc);//插入前先清数据
  233. // deleteRoleMenu(code,tableName,name,mycon);//插入前先清数据
  234. //100d07#1#100d:001#2#100d07:100d05#1#100d:001#2#100d05:
  235. String[] s = str.split(":");//4
  236. int insertFlag = -1;
  237. for(int a = 0;a<s.length;a++){
  238. // log.debug("sas:"+s[a]);
  239. String[] s1= s[a].split("#");
  240. for(int b = 0;b<s1.length;b++){
  241. id = s1[0] == null ? "" : s1[0].trim();
  242. // isleaf = s1[1] == null ? "" : s1[1].trim();
  243. type= s1[1] == null ? "" : s1[1].trim();
  244. if(type.equals("1")){
  245. parentid = id;
  246. type="1";//1:属于菜单
  247. }else{
  248. parentid = id;
  249. type="2";//1:属于按钮
  250. }
  251. }
  252. String fD_OBJECTID = IdentityGenerator.getIdentityGenerator().gerenalIdentity(886);//生成主键
  253. String sql886="insert into SysUser_RoleRightRel(FD_OBJECTID,Role_ID,Role_Type,Right_ID,Right_Type) " +
  254. "values('"+fD_OBJECTID+"','"+code+"','0','"+parentid+"','"+type+"')";
  255. insertFlag = jdbc.executeUpdateSQL(sql886);
  256. // insertFlag = persistence.executeUpdateSQL(886, sql886);
  257. // ps.setString(1, fD_OBJECTID);
  258. // ps.setString(2, code);
  259. // ps.setString(3, parentid);
  260. // ps.setString(4, type);
  261. // insertFlag = ps.execute();
  262. }
  263. log.debug(deleteFlag+"=="+insertFlag);
  264. if(deleteFlag>-1&&insertFlag>-1){
  265. if(jdbc!=null){
  266. jdbc.commit();
  267. }
  268. }else{
  269. if(jdbc!=null){
  270. jdbc.rollback();
  271. }
  272. }
  273. }catch(Exception e){
  274. e.printStackTrace();
  275. if(jdbc!=null){
  276. jdbc.rollback();
  277. }
  278. }finally{
  279. if(jdbc!=null){
  280. jdbc.release();
  281. }
  282. }
  283. msg.setObjectID("1");
  284. return msg;}
  285. /**
  286. * 插入前先根据role_id删除
  287. * @param params
  288. * @param table
  289. * @param name
  290. * @throws Exception
  291. */
  292. public int deleteRoleMenu(String params,String table,String name,JDBCHelper jdbc) throws Exception{
  293. String sql = "";
  294. int flag =-1;
  295. sql="delete from "+table+" where "+ name+"='"+params+"'";
  296. flag = jdbc.executeUpdateSQL(sql.toString());
  297. return flag;
  298. }
  299. @ProduceMime("application/json")
  300. @POST
  301. @Path("/showUserButtns")
  302. public String showUserButtns(String params) {
  303. try {
  304. params = java.net.URLDecoder.decode(params, "UTF-8");
  305. } catch (UnsupportedEncodingException e1) {
  306. e1.printStackTrace();
  307. }
  308. String objectId = Utils.getParameter("objectId", params)== null ? "" : Utils.getParameter("objectId", params);
  309. String userid = Utils.getParameter("userid", params)== null ? "" : Utils.getParameter("userid", params);
  310. String sql = "select a.right_id from SysUser_RoleRightRel a,SysUser_UserRoleRel b " +
  311. "where a.right_type = '2' and a.Role_ID = b.Role_ID and b.User_ID = '"+userid+"' and a.right_id like '"+objectId+"%'";
  312. // log.info("角色sql:" + sql);
  313. JDBCHelper jdbc = new JDBCHelper();
  314. jdbc.begin();
  315. List<String[]> list = new ArrayList<String[]>();
  316. String result = "";
  317. try {
  318. list = jdbc.getSearchResult(99, sql);
  319. if(list.size()>0){
  320. for(String[] str : list){
  321. String string = str[0]==null?"":str[0];
  322. result = result + string + ",";
  323. }
  324. result = result.substring(0, result.lastIndexOf(','));
  325. //log.info(result);
  326. }
  327. } catch (PersistenceException e) {
  328. e.printStackTrace();
  329. } finally{
  330. jdbc.release();
  331. }
  332. return result;
  333. }
  334. }