e34b684cb76fe0a21429c8fbe91dec2041f12d55.svn-base 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. package com.sinosoft.lz.system.right.service;
  2. import java.io.UnsupportedEncodingException;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import javax.ws.rs.POST;
  7. import javax.ws.rs.Path;
  8. import javax.ws.rs.ProduceMime;
  9. import net.sf.json.JSONObject;
  10. import org.apache.commons.logging.Log;
  11. import org.apache.commons.logging.LogFactory;
  12. import com.formaction.Utils;
  13. import com.formaction.dao.OperateAble;
  14. import com.formaction.dao.OperateImpl;
  15. import com.formaction.dao.assistant.AssistantAble;
  16. import com.formaction.dao.assistant.AssistantImpl;
  17. import com.formaction.vo.RowSet;
  18. import com.persistence.service.JDBCHelper;
  19. import com.persistence.service.exception.PersistenceException;
  20. import com.persistence.service.exception.TransformTypeException;
  21. import com.sysmodel.XFormFactory;
  22. import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
  23. import com.sinosoft.lz.system.right.RightImp;
  24. import com.sinosoft.lz.system.right.Rightable;
  25. import com.sinosoft.lz.system.right.funvo.PowerData;
  26. import com.sinosoft.lz.system.right.vo.Right;
  27. @Path("/sysRightService/")
  28. public class RightImpService implements RightableService{
  29. private Log log = LogFactory.getLog(RightImpService.class);
  30. @ProduceMime("application/json")
  31. @POST
  32. @Path("/getCanViewModuleJson")
  33. // http://127.0.0.1:8089/bjglweb/ws/sr/sysRightService/getCanViewModuleJson
  34. public Right getCanViewModuleJson(String params) {
  35. Right right = new Right();
  36. try {
  37. params = java.net.URLDecoder.decode(params, "UTF-8");
  38. String userID = Utils.getParameter("uid", params);;
  39. String nodeID = Utils.getParameter("nodeid", params);;
  40. Rightable Rightable = new RightImp();
  41. right = Rightable.getCanViewModuleJson(userID, nodeID);
  42. } catch (Exception e) {
  43. e.printStackTrace();
  44. }
  45. // log.debug(right.getMydata());
  46. return right;
  47. }
  48. @ProduceMime("application/json")
  49. @POST
  50. @Path("/getCanOptionJson")
  51. // http://127.0.0.1:8089/bjglweb/ws/sr/sysRightService/getCanOptionJson
  52. public PowerData getCanOptionJson(String params) {
  53. PowerData pd = new PowerData();
  54. try {
  55. Rightable Rightable = new RightImp();
  56. params = java.net.URLDecoder.decode(params, "UTF-8");
  57. String userID = Utils.getParameter("uid", params);;
  58. pd.setFunctionData(Rightable.getCanOptionJson(userID));
  59. pd.setModuleData(Rightable.getModuleJson(userID));
  60. } catch (Exception e) {
  61. // TODO Auto-generated catch block
  62. e.printStackTrace();
  63. }
  64. return pd;
  65. }
  66. /**
  67. * 获得角色列表服务(展示角色类型+角色名称)用户角色授权调用
  68. *
  69. * @param params
  70. * 表单信息
  71. * @return
  72. * @throws TransformTypeException
  73. * @throws PersistenceException
  74. */
  75. @SuppressWarnings("unchecked")
  76. @POST
  77. @ProduceMime("application/json")
  78. @Path("/getRoleList/")
  79. public String getRoleList(String params) throws PersistenceException, TransformTypeException {
  80. OperateAble persistence = new OperateImpl();
  81. AssistantAble assistant = new AssistantImpl();
  82. try {
  83. params = java.net.URLDecoder.decode(params, "UTF-8");
  84. } catch (UnsupportedEncodingException e) {
  85. log.error("字符转换出现错误:", e);
  86. }
  87. log.info(params);
  88. RowSet rowSet = new RowSet();
  89. String listId = Utils.getParameter("listId", params);
  90. FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listId);
  91. String userId = Utils.getParameter("userId", params);
  92. String flag = Utils.getParameter("flag", params);
  93. String condition = "";
  94. if (flag.equals("not")) {
  95. condition = " Role_ID not in (select t.Role_ID from SYS_USER_ROLE_REL t where t.User_ID='"
  96. + userId + "')";
  97. } else {
  98. condition = " Role_ID in (select t.Role_ID from SYS_USER_ROLE_REL t where t.User_ID='"
  99. + userId + "')";
  100. }
  101. StringBuffer sql = assistant.getSearchSql(formList, condition);
  102. log.debug("角色查询----" + sql);
  103. if (formList.getQueryList().getPageSize() == 0) {
  104. rowSet = persistence.queryAllDatas(formList, sql);
  105. } else {
  106. String firstPageNum = Utils.getParameter("start", params) == null ? "0" : Utils
  107. .getParameter("start", params);
  108. String limit = Utils.getParameter("limit", params) == null ? "10" : Utils.getParameter(
  109. "limit", params);
  110. rowSet = persistence.queryPagingAllDatas(formList, sql, firstPageNum, limit);
  111. }
  112. for (Map<String, String> row : rowSet.getRows()) {// 根据角色类型硬编码返回角色类型
  113. String roleType = row.get("ROLE_TYPE_881");
  114. log.debug("角色类型:" + roleType);
  115. if (roleType.equals("0")) {
  116. row.put("ROLE_NAME_881", "『菜单模块角色』" + row.get("ROLE_NAME_881"));
  117. } else if (roleType.equals("1")) {
  118. row.put("ROLE_NAME_881", "(事件查看角色)" + row.get("ROLE_NAME_881"));
  119. } else if (roleType.equals("2")) {
  120. row.put("ROLE_NAME_881", "《路网监控角色》" + row.get("ROLE_NAME_881"));
  121. } else if (roleType.equals("3")) {
  122. row.put("ROLE_NAME_881", "【对象操作角色】" + row.get("ROLE_NAME_881"));
  123. } else if (roleType.equals("4")) {
  124. row.put("ROLE_NAME_881", "<病害处理角色>" + row.get("ROLE_NAME_881"));
  125. }
  126. }
  127. return JSONObject.fromObject(rowSet).toString();
  128. }
  129. /*
  130. * 查询角色列表
  131. */
  132. @SuppressWarnings({ "rawtypes", "unused" })
  133. @POST
  134. @ProduceMime("application/json")
  135. @Path("/getRoleList1/")
  136. public String getRoleList1(String params) throws PersistenceException, TransformTypeException {
  137. OperateAble persistence = new OperateImpl();
  138. AssistantAble assistant = new AssistantImpl();
  139. ArrayList<String[]> array = new ArrayList<String[]>();
  140. ArrayList<String[]> list = new ArrayList<String[]>();
  141. ArrayList<String[]> list1 = new ArrayList<String[]>();
  142. ArrayList<Map> al = new ArrayList<Map>();
  143. String flag = null;
  144. RowSet rowSet = new RowSet();
  145. JDBCHelper jdbc = new JDBCHelper();
  146. jdbc.begin();
  147. try {
  148. params = java.net.URLDecoder.decode(params, "UTF-8");
  149. log.info(params);
  150. flag = Utils.getParameter("flag", params);
  151. String listId = Utils.getParameter("listId", params);
  152. // FormListImpl formList =
  153. // (FormListImpl)XFormFactory.getXFormModel().getFormList(listId);
  154. String userId = Utils.getParameter("userId", params);// 被选中用户的id
  155. String userid = Utils.getParameter("userid", params);// 登陆用户的id
  156. if (userId.equals(userid)) {
  157. userId = userid;
  158. }
  159. String condition = "";
  160. if (flag.equals("in")) {
  161. condition = " select fd_objectid,Role_ID,Role_Name,ROLE_TYPE from SYS_ROLE where Role_ID in (select t.Role_ID from SYS_USER_ROLE_REL t where t.User_ID='"
  162. + userId + "')";
  163. log.debug("condition:" + condition);
  164. list1 = jdbc.getSearchResult(881, condition);
  165. for (int i = 0; i < list1.size(); i++) {
  166. Map<String, String> map = new HashMap<String, String>();
  167. String[] str = (String[]) list1.get(i);
  168. String fd_id = str[0];
  169. String id = str[1];
  170. String name = str[2];
  171. String type = str[3];
  172. map.put("FD_OBJECTID881", fd_id);
  173. map.put("ROLE_ID_881", id);
  174. map.put("ROLE_NAME_881", name);
  175. map.put("ROLE_TYPE_881", type);
  176. al.add(map);
  177. }
  178. rowSet.setRows(al);
  179. } else {
  180. // String sql="select distinct Role_ID from SysMenu_ObjRel";
  181. // log.debug("887:"+sql);
  182. // array = jdbc.getSearchResult(887, sql);
  183. // log.debug("array.size():"+array.size());
  184. // for (int i = 0 ; i< array.size() ; i++){
  185. // String[] rs = (String[])array.get(i);
  186. // String code = rs[0] == null ? "" : rs[0];//select
  187. // fd_objectid,Role_ID,Role_Name,ROLE_TYPE from SYS_ROLE where
  188. // Role_ID = '"+code+"'
  189. String sql1 = "select fd_objectid,Role_ID,Role_Name,ROLE_TYPE from SYS_ROLE where "
  190. + "(role_id in(select DISTINCT ROLE_ID from SYS_USER_ROLE_REL where USER_ID in('"
  191. + userid
  192. + "')) "
  193. + " or parent_id in(select DISTINCT ROLE_ID from SYS_USER_ROLE_REL where USER_ID in('"
  194. + userid
  195. + "')))"
  196. + "and role_id not in (select t.Role_ID from SYS_USER_ROLE_REL t where t.User_ID in('"
  197. + userId + "'))" + " and role_type='0' ";
  198. // 左侧角色列表:登陆用户对应角色及其子角色且不包含被选中用户对应的角色
  199. log.debug("881:" + sql1);
  200. list = jdbc.getSearchResult(881, sql1);
  201. for (int j = 0; j < list.size(); j++) {
  202. Map<String, String> map = new HashMap<String, String>();
  203. String[] str = (String[]) list.get(j);
  204. String fd_id = str[0];
  205. String id = str[1];
  206. String name = str[2];
  207. String type = str[3];
  208. map.put("FD_OBJECTID881", fd_id);
  209. map.put("ROLE_ID_881", id);
  210. map.put("ROLE_NAME_881", name);
  211. map.put("ROLE_TYPE_881", type);
  212. al.add(map);
  213. }
  214. // }
  215. rowSet.setRows(al);
  216. }
  217. } catch (UnsupportedEncodingException e) {
  218. log.error("字符转换出现错误:", e);
  219. } finally {
  220. if (jdbc != null) {
  221. jdbc.commit();
  222. jdbc.release();
  223. }
  224. }
  225. return JSONObject.fromObject(rowSet).toString();
  226. }
  227. }