123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- package com.sinosoft.lz.system.right.service;
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.ProduceMime;
- import net.sf.json.JSONObject;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import com.formaction.Utils;
- import com.formaction.dao.OperateAble;
- import com.formaction.dao.OperateImpl;
- import com.formaction.dao.assistant.AssistantAble;
- import com.formaction.dao.assistant.AssistantImpl;
- import com.formaction.vo.RowSet;
- import com.persistence.service.JDBCHelper;
- import com.persistence.service.exception.PersistenceException;
- import com.persistence.service.exception.TransformTypeException;
- import com.sysmodel.XFormFactory;
- import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
- import com.sinosoft.lz.system.right.RightImp;
- import com.sinosoft.lz.system.right.Rightable;
- import com.sinosoft.lz.system.right.funvo.PowerData;
- import com.sinosoft.lz.system.right.vo.Right;
- @Path("/sysRightService/")
- public class RightImpService implements RightableService{
- private Log log = LogFactory.getLog(RightImpService.class);
- @ProduceMime("application/json")
- @POST
- @Path("/getCanViewModuleJson")
- // http://127.0.0.1:8089/bjglweb/ws/sr/sysRightService/getCanViewModuleJson
- public Right getCanViewModuleJson(String params) {
- Right right = new Right();
- try {
- params = java.net.URLDecoder.decode(params, "UTF-8");
- String userID = Utils.getParameter("uid", params);;
- String nodeID = Utils.getParameter("nodeid", params);;
- Rightable Rightable = new RightImp();
- right = Rightable.getCanViewModuleJson(userID, nodeID);
- } catch (Exception e) {
- e.printStackTrace();
- }
- // log.debug(right.getMydata());
- return right;
- }
- @ProduceMime("application/json")
- @POST
- @Path("/getCanOptionJson")
- // http://127.0.0.1:8089/bjglweb/ws/sr/sysRightService/getCanOptionJson
- public PowerData getCanOptionJson(String params) {
- PowerData pd = new PowerData();
- try {
- Rightable Rightable = new RightImp();
- params = java.net.URLDecoder.decode(params, "UTF-8");
- String userID = Utils.getParameter("uid", params);;
- pd.setFunctionData(Rightable.getCanOptionJson(userID));
- pd.setModuleData(Rightable.getModuleJson(userID));
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return pd;
- }
- /**
- * 获得角色列表服务(展示角色类型+角色名称)用户角色授权调用
- *
- * @param params
- * 表单信息
- * @return
- * @throws TransformTypeException
- * @throws PersistenceException
- */
- @SuppressWarnings("unchecked")
- @POST
- @ProduceMime("application/json")
- @Path("/getRoleList/")
- public String getRoleList(String params) throws PersistenceException, TransformTypeException {
- OperateAble persistence = new OperateImpl();
- AssistantAble assistant = new AssistantImpl();
- try {
- params = java.net.URLDecoder.decode(params, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- log.error("字符转换出现错误:", e);
- }
- log.info(params);
- RowSet rowSet = new RowSet();
- String listId = Utils.getParameter("listId", params);
- FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listId);
- String userId = Utils.getParameter("userId", params);
- String flag = Utils.getParameter("flag", params);
- String condition = "";
- if (flag.equals("not")) {
- condition = " Role_ID not in (select t.Role_ID from SYS_USER_ROLE_REL t where t.User_ID='"
- + userId + "')";
- } else {
- condition = " Role_ID in (select t.Role_ID from SYS_USER_ROLE_REL t where t.User_ID='"
- + userId + "')";
- }
- StringBuffer sql = assistant.getSearchSql(formList, condition);
- log.debug("角色查询----" + sql);
- if (formList.getQueryList().getPageSize() == 0) {
- rowSet = persistence.queryAllDatas(formList, sql);
- } else {
- String firstPageNum = Utils.getParameter("start", params) == null ? "0" : Utils
- .getParameter("start", params);
- String limit = Utils.getParameter("limit", params) == null ? "10" : Utils.getParameter(
- "limit", params);
- rowSet = persistence.queryPagingAllDatas(formList, sql, firstPageNum, limit);
- }
- for (Map<String, String> row : rowSet.getRows()) {// 根据角色类型硬编码返回角色类型
- String roleType = row.get("ROLE_TYPE_881");
- log.debug("角色类型:" + roleType);
- if (roleType.equals("0")) {
- row.put("ROLE_NAME_881", "『菜单模块角色』" + row.get("ROLE_NAME_881"));
- } else if (roleType.equals("1")) {
- row.put("ROLE_NAME_881", "(事件查看角色)" + row.get("ROLE_NAME_881"));
- } else if (roleType.equals("2")) {
- row.put("ROLE_NAME_881", "《路网监控角色》" + row.get("ROLE_NAME_881"));
- } else if (roleType.equals("3")) {
- row.put("ROLE_NAME_881", "【对象操作角色】" + row.get("ROLE_NAME_881"));
- } else if (roleType.equals("4")) {
- row.put("ROLE_NAME_881", "<病害处理角色>" + row.get("ROLE_NAME_881"));
- }
- }
- return JSONObject.fromObject(rowSet).toString();
- }
- /*
- * 查询角色列表
- */
- @SuppressWarnings({ "rawtypes", "unused" })
- @POST
- @ProduceMime("application/json")
- @Path("/getRoleList1/")
- public String getRoleList1(String params) throws PersistenceException, TransformTypeException {
- OperateAble persistence = new OperateImpl();
- AssistantAble assistant = new AssistantImpl();
- ArrayList<String[]> array = new ArrayList<String[]>();
- ArrayList<String[]> list = new ArrayList<String[]>();
- ArrayList<String[]> list1 = new ArrayList<String[]>();
- ArrayList<Map> al = new ArrayList<Map>();
- String flag = null;
- RowSet rowSet = new RowSet();
- JDBCHelper jdbc = new JDBCHelper();
- jdbc.begin();
- try {
- params = java.net.URLDecoder.decode(params, "UTF-8");
- log.info(params);
- flag = Utils.getParameter("flag", params);
- String listId = Utils.getParameter("listId", params);
- // FormListImpl formList =
- // (FormListImpl)XFormFactory.getXFormModel().getFormList(listId);
- String userId = Utils.getParameter("userId", params);// 被选中用户的id
- String userid = Utils.getParameter("userid", params);// 登陆用户的id
- if (userId.equals(userid)) {
- userId = userid;
- }
- String condition = "";
- if (flag.equals("in")) {
- 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='"
- + userId + "')";
- log.debug("condition:" + condition);
- list1 = jdbc.getSearchResult(881, condition);
- for (int i = 0; i < list1.size(); i++) {
- Map<String, String> map = new HashMap<String, String>();
- String[] str = (String[]) list1.get(i);
- String fd_id = str[0];
- String id = str[1];
- String name = str[2];
- String type = str[3];
- map.put("FD_OBJECTID881", fd_id);
- map.put("ROLE_ID_881", id);
- map.put("ROLE_NAME_881", name);
- map.put("ROLE_TYPE_881", type);
- al.add(map);
- }
- rowSet.setRows(al);
- } else {
- // String sql="select distinct Role_ID from SysMenu_ObjRel";
- // log.debug("887:"+sql);
- // array = jdbc.getSearchResult(887, sql);
- // log.debug("array.size():"+array.size());
- // for (int i = 0 ; i< array.size() ; i++){
- // String[] rs = (String[])array.get(i);
- // String code = rs[0] == null ? "" : rs[0];//select
- // fd_objectid,Role_ID,Role_Name,ROLE_TYPE from SYS_ROLE where
- // Role_ID = '"+code+"'
- String sql1 = "select fd_objectid,Role_ID,Role_Name,ROLE_TYPE from SYS_ROLE where "
- + "(role_id in(select DISTINCT ROLE_ID from SYS_USER_ROLE_REL where USER_ID in('"
- + userid
- + "')) "
- + " or parent_id in(select DISTINCT ROLE_ID from SYS_USER_ROLE_REL where USER_ID in('"
- + userid
- + "')))"
- + "and role_id not in (select t.Role_ID from SYS_USER_ROLE_REL t where t.User_ID in('"
- + userId + "'))" + " and role_type='0' ";
- // 左侧角色列表:登陆用户对应角色及其子角色且不包含被选中用户对应的角色
- log.debug("881:" + sql1);
- list = jdbc.getSearchResult(881, sql1);
- for (int j = 0; j < list.size(); j++) {
- Map<String, String> map = new HashMap<String, String>();
- String[] str = (String[]) list.get(j);
- String fd_id = str[0];
- String id = str[1];
- String name = str[2];
- String type = str[3];
- map.put("FD_OBJECTID881", fd_id);
- map.put("ROLE_ID_881", id);
- map.put("ROLE_NAME_881", name);
- map.put("ROLE_TYPE_881", type);
- al.add(map);
- }
- // }
- rowSet.setRows(al);
- }
- } catch (UnsupportedEncodingException e) {
- log.error("字符转换出现错误:", e);
- } finally {
- if (jdbc != null) {
- jdbc.commit();
- jdbc.release();
- }
- }
- return JSONObject.fromObject(rowSet).toString();
- }
- }
|