0ccd92daf1f9a108e364deeee13c387235fb43f8.svn-base 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. package com.sinosoft.lz.system.logon.service;
  2. import java.io.UnsupportedEncodingException;
  3. import java.util.ArrayList;
  4. import java.util.Collection;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.Iterator;
  8. import java.util.List;
  9. import java.util.Map;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.ws.rs.GET;
  12. import javax.ws.rs.POST;
  13. import javax.ws.rs.Path;
  14. import javax.ws.rs.PathParam;
  15. import javax.ws.rs.ProduceMime;
  16. import javax.ws.rs.core.Context;
  17. import org.apache.cxf.transport.http.AbstractHTTPDestination;
  18. import org.apache.log4j.Logger;
  19. import com.formaction.Utils;
  20. import com.persistence.service.JDBCHelper;
  21. import com.persistence.service.PersistenceFactory;
  22. import com.persistence.service.SysPersistence;
  23. import com.persistence.service.exception.PersistenceException;
  24. import com.sinosoft.lz.system.AppContext;
  25. import com.sinosoft.lz.system.auditLog.impl.AuditLogImpl;
  26. import com.sinosoft.lz.system.auditLog.vo.AuditLogVo;
  27. import com.sinosoft.lz.system.department.DepartExc;
  28. import com.sinosoft.lz.system.logon.dao.LoginDao;
  29. import com.sinosoft.lz.system.logon.vo.LoginEnter;
  30. import com.sinosoft.lz.system.logon.vo.LoginInfo;
  31. import com.sinosoft.lz.system.logon.vo.LoginInfos;
  32. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  33. import com.sysmodel.datamodel.xmlmodel.able.MdpConstant;
  34. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  35. import com.toolkit.date.DateHelper;
  36. import flex.messaging.log.Log;
  37. import net.sf.json.JSONArray;
  38. @Path("/LoginService/")
  39. public class LoginService {
  40. private final Logger log = Logger.getLogger(getClass());
  41. @Context
  42. private org.apache.cxf.jaxrs.ext.MessageContext mc;
  43. private String deptId = null;
  44. public static int loginNum=0;
  45. public static Long startTime=0L;
  46. public static Long responseTime=0L;
  47. public String getDeptId() {
  48. return deptId;
  49. }
  50. public void setDeptId(String deptId) {
  51. this.deptId = deptId;
  52. }
  53. @SuppressWarnings("rawtypes")
  54. @ProduceMime("application/json")
  55. @POST
  56. @Path("/getUserInfo")
  57. public String getUserInfo() {
  58. HttpServletRequest rq = (HttpServletRequest) mc
  59. .get(AbstractHTTPDestination.HTTP_REQUEST);
  60. //设置session失效时间两小时
  61. rq.getSession().setMaxInactiveInterval(60*60*2);
  62. String login_name = rq.getSession().getAttribute("User_Name")
  63. .toString();
  64. String sql = "select user_id,real_name from sys_user_info where login_name='"
  65. + login_name + "'";
  66. List list = null;
  67. try {
  68. list = PersistenceFactory.getInstance(ModelFactory.getSysmodel())
  69. .getSearchResultToMap(99, sql);
  70. } catch (PersistenceException e) {
  71. log.error(e.getMessage());
  72. }
  73. log.info("getUserInfo===" + list.size());
  74. String result = "{\"rows\":" + JSONArray.fromObject(list).toString()
  75. + "}";
  76. log.info("getUserInfo===" + result);
  77. return result;
  78. }
  79. //获取用户的公司和部门信息
  80. @SuppressWarnings("rawtypes")
  81. @ProduceMime("application/json")
  82. @POST
  83. @Path("/getUserDeptInfo")
  84. public String getDept() {
  85. HttpServletRequest rq = (HttpServletRequest) mc
  86. .get(AbstractHTTPDestination.HTTP_REQUEST);
  87. String login_name = rq.getSession().getAttribute("User_Name")
  88. .toString();
  89. String sql = "select a.real_name ,a.user_id ,b.parent_id ,b.dept_name dept_name, d.dept_name comp_name from sys_department b,sys_user_info a ,sys_dept_user c ,sys_department d where "
  90. + " a.user_id = c.user_id and b.dept_id = c.dept_id and b.parent_id = d.dept_id and a.login_name='"+login_name+"'";
  91. String sql1 = "select a.real_name ,a.user_id ,b.parent_id ,b.name from sys_department b,sys_user_info a ,sys_dept_user c where "
  92. + "a.user_id = c.user_id and b.dept_id = c.dept_id and a.login_name='"+login_name+"'";
  93. log.info("getUserDeptInfo.sql========"+sql);
  94. log.info("getUserInfo.sql1========"+sql1);
  95. List list = null;
  96. try {
  97. list = PersistenceFactory.getInstance(ModelFactory.getSysmodel())
  98. .getSearchResultToMap(99, sql);
  99. if(list==null||list.size()==0){
  100. list = PersistenceFactory.getInstance(ModelFactory.getSysmodel())
  101. .getSearchResultToMap(99, sql1);
  102. }
  103. } catch (PersistenceException e) {
  104. log.error(e.getMessage());
  105. }
  106. log.info("getUserDeptInfo" + list.size());
  107. String result = "{\"rows\":" + JSONArray.fromObject(list).toString()
  108. + "}";
  109. log.info("getUserDeptInfo==" + result);
  110. return result;
  111. }
  112. /*//获得登录人的部门id
  113. public String getDepartmentId(){
  114. HttpServletRequest rq = (HttpServletRequest) mc
  115. .get(AbstractHTTPDestination.HTTP_REQUEST);
  116. String login_name = rq.getSession().getAttribute("User_Name")
  117. .toString();
  118. String sql = "select a.id from sys_department_0827 a,sys_dept_user b,sys_user_info c where a.id = b.dept_id and b.user_id = c.user_id and c.login_name='"+login_name+"'";
  119. return sql;
  120. }*/
  121. @ProduceMime("application/json")
  122. @POST
  123. @Path("/LoginPw")
  124. public LoginInfo tryLoginPw(String params) {
  125. startTime=new Date().getTime();
  126. LoginInfo loginInfo = new LoginInfo();
  127. String passWord = "";
  128. String userName = "";
  129. log.info(params);
  130. try {
  131. userName = Utils.getParameter("username", params);
  132. passWord = Utils.getParameter("password", params);
  133. HttpServletRequest req = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
  134. Map<String,LoginInfo> userMap = AppContext.getInstance().getLoginUserMap();
  135. // 认证
  136. LoginDao loginDao = new LoginDao();
  137. loginInfo = loginDao.checkLoginPw(userName,passWord);
  138. String userIP = req.getRemoteAddr();
  139. //保存登录日期与时间
  140. if (loginInfo != null && "0".equals(loginInfo.getSt())) {
  141. loginDao.setLoginDate(userName);
  142. }
  143. if (loginInfo != null && "0".equals(loginInfo.getSt())) {
  144. // 多角色 “,”分开
  145. String[] roles = loginDao.getRoleIdsByUserId(loginInfo.getUser_id());
  146. loginInfo.setRoleids(roles[0]);
  147. loginInfo.setRolenames(roles[1]);
  148. // 多部门“,”分开, 存在一个人 属于多个部门的情况
  149. String[] sts = loginDao.getDeptsByUserId(loginInfo.getUser_id());
  150. loginInfo.setDeptids(sts[0]);
  151. loginInfo.setDeptnames(sts[1]);
  152. loginInfo.setParent_ids(sts[2]);
  153. loginInfo.setDept_types(sts[3]);
  154. loginInfo.setCorp_ids(sts[4]);
  155. loginInfo.setCorp_names(sts[5]);
  156. loginInfo.setPcorp_ids(sts[6]);
  157. loginInfo.setPcorp_names(sts[7]);
  158. loginInfo.setSessionId(req.getSession().getId()); //存入会话ID
  159. req.getSession().setAttribute("User_Name", userName);
  160. req.getSession()
  161. .setAttribute("User_ID", loginInfo.getUser_id());
  162. req.getSession().setAttribute("Real_Name",
  163. loginInfo.getReal_name());
  164. req.getSession()
  165. .setAttribute("roleids", loginInfo.getRoleids()); // 多角色
  166. // ID“,”分开
  167. req.getSession().setAttribute("unitCode",
  168. loginInfo.getDeptids());// 多部门ID“,”分开
  169. req.getSession().setAttribute("deptnames",
  170. loginInfo.getDeptnames()); // 多部门NAME“,”分开
  171. req.getSession().setAttribute("loginInfo", loginInfo);
  172. String sessionid = req.getSession().getId();
  173. // if(userMap.containsKey(userName)){
  174. // LoginInfo minfo = userMap.get(userName);
  175. //
  176. // if(!sessionid.equals(minfo.getSessionId())){
  177. // userMap.remove(userName);
  178. // }
  179. // }
  180. userMap.put(userName, loginInfo);
  181. }
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. log.error("登录失败" + e.getMessage());
  185. }
  186. log.info(loginInfo.toString());
  187. return loginInfo;
  188. }
  189. //4A登陆验证
  190. // 返回值为{int,String,String}---(结果标志0-成功,消息,SessionID)
  191. @ProduceMime("application/json")
  192. @POST
  193. @Path("/Login")
  194. public LoginInfo tryLogin(String params) {
  195. LoginInfo loginInfo = new LoginInfo();
  196. // String passWord = "";
  197. String userName = "";
  198. String real_name = "";
  199. log.info("1、应急登录开始:"+params);
  200. try {
  201. // 格式化参数,获取登录的用户名和密码
  202. // params = java.net.URLDecoder.decode(params, "UTF-8");
  203. userName = Utils.getParameter("username", params);
  204. real_name = Utils.getParameter("real_name", params);
  205. // passWord = Utils.getParameter("password", params);
  206. HttpServletRequest req = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
  207. Map<String,LoginInfo> userMap = AppContext.getInstance().getLoginUserMap();
  208. // 认证
  209. LoginDao loginDao = new LoginDao();
  210. log.info("2、应急登录验证:用户名"+userName);
  211. loginInfo = loginDao.checkLogin(userName,real_name);
  212. String userIP = req.getRemoteAddr();
  213. //保存登录日期与时间
  214. if (loginInfo != null && "0".equals(loginInfo.getSt())) {
  215. loginDao.setLoginDate(userName);
  216. }
  217. if (loginInfo != null && "0".equals(loginInfo.getSt())) {
  218. // 多角色 “,”分开
  219. String[] roles = loginDao.getRoleIdsByUserId(loginInfo.getUser_id());
  220. loginInfo.setRoleids(roles[0]);
  221. loginInfo.setRolenames(roles[1]);
  222. // 多部门“,”分开, 存在一个人 属于多个部门的情况
  223. String[] sts = loginDao.getDeptsByUserId(loginInfo.getUser_id());
  224. loginInfo.setDeptids(sts[0]);
  225. loginInfo.setDeptnames(sts[1]);
  226. loginInfo.setParent_ids(sts[2]);
  227. loginInfo.setDept_types(sts[3]);
  228. loginInfo.setCorp_ids(sts[4]);
  229. loginInfo.setCorp_names(sts[5]);
  230. loginInfo.setPcorp_ids(sts[6]);
  231. loginInfo.setPcorp_names(sts[7]);
  232. loginInfo.setSessionId(req.getSession().getId()); //存入会话ID
  233. req.getSession().setAttribute("User_Name", userName);
  234. req.getSession()
  235. .setAttribute("User_ID", loginInfo.getUser_id());
  236. req.getSession().setAttribute("Real_Name",
  237. loginInfo.getReal_name());
  238. req.getSession()
  239. .setAttribute("roleids", loginInfo.getRoleids()); // 多角色
  240. // ID“,”分开
  241. req.getSession().setAttribute("unitCode",
  242. loginInfo.getDeptids());// 多部门ID“,”分开
  243. req.getSession().setAttribute("deptnames",
  244. loginInfo.getDeptnames()); // 多部门NAME“,”分开
  245. req.getSession().setAttribute("loginInfo", loginInfo);
  246. String sessionid = req.getSession().getId();
  247. // if(userMap.containsKey(userName)){
  248. // LoginInfo minfo = userMap.get(userName);
  249. //
  250. // if(!sessionid.equals(minfo.getSessionId())){
  251. // userMap.remove(userName);
  252. // }
  253. // }
  254. userMap.put(userName, loginInfo);
  255. }
  256. } catch (Exception e) {
  257. e.printStackTrace();
  258. log.error("登录失败" + e.getMessage());
  259. }
  260. log.info("登录成功:登录信息="+loginInfo.toString());
  261. //log.info(responseTime-startTime);
  262. return loginInfo;
  263. }
  264. @SuppressWarnings("rawtypes")
  265. @ProduceMime("application/json")
  266. @POST
  267. @Path("/getUserCompId")
  268. public String getUserCompId() {
  269. HttpServletRequest rq = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
  270. String login_name = rq.getSession().getAttribute("User_Name").toString();
  271. String sql = "select c.parent_id from sys_user_info a,sys_dept_user b,sys_department_0827 c where a.login_name='" + login_name + "' and a.user_id=b.user_id and b.dept_id=c.id";
  272. List list = null;
  273. try {
  274. list = PersistenceFactory.getInstance(ModelFactory.getSysmodel()).getSearchResultToMap(
  275. 99, sql);
  276. } catch (PersistenceException e) {
  277. log.error(e.getMessage());
  278. }
  279. log.info("getUserInfo===" + list.size());
  280. String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  281. log.info("getUserInfo===" + result);
  282. return result;
  283. }
  284. /**
  285. * 根据表名和字段,得到字段value
  286. */
  287. public String getBMTableByNameIds(String tablename, String fdCode) {
  288. SysModel sysmodel = ModelFactory.getSysmodel();
  289. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  290. String sql = "select name,fd_objectid from " + tablename
  291. + " where fd_objectid='" + fdCode + "'";
  292. ArrayList<String[]> codes;
  293. String value = "";
  294. try {
  295. codes = persistence.getSearchResult(99, sql);
  296. if (codes.size() > 0) {
  297. for (String[] s : codes) {
  298. if (s[1].equals(fdCode)) {
  299. value = s[0];
  300. }
  301. }
  302. }
  303. } catch (Exception e) {
  304. e.printStackTrace();
  305. log.error("" + e);
  306. }
  307. return value;
  308. }
  309. @SuppressWarnings("unused")
  310. private String getPUnitCode(String departType, String unitCode) {
  311. log.info("部门编码:" + departType + ",单位编码:" + unitCode);
  312. if (("20,10").indexOf(departType) != -1 && !departType.equals("2"))// 市局
  313. // 分局
  314. {
  315. return unitCode;
  316. } else if (("4,5,1,2,3").indexOf(departType) != -1
  317. && unitCode.length() == 7)// 部门
  318. // 属于市局
  319. {
  320. return unitCode.substring(0, 5);
  321. } else if (unitCode.length() > 7) {
  322. return unitCode.substring(0, 7);
  323. } else {
  324. return "error";
  325. }
  326. }
  327. // example
  328. // http://192.168.100.201:8080/bjglweb/ws/ss/SystemService/isLive/123
  329. // 判断用户是否在线
  330. // 返回值为{String}---(结果标志0-成功,SessionID)
  331. @ProduceMime("application/json")
  332. @GET
  333. @Path("/isLive/{userName}/{sessionid}")
  334. public String isLive(@PathParam("userName") String userName,@PathParam("sessionid") String sessionid) {
  335. log.info("判断用户会话存在:" + userName+"---sessionid:"+sessionid);
  336. HttpServletRequest req = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
  337. Map<String,LoginInfo> userMap = AppContext.getInstance().getLoginUserMap();
  338. // if (userMap.containsKey(userName)) {
  339. // LoginInfo linfo = userMap.get(userName);
  340. // if(sessionid.equals(linfo.getSessionId())){
  341. // log.info("存在appcontext中的userinfo userid====="+AppContext.getInstance().getLoginUserMap().get(userName).getUser_id());
  342. //
  343. // return "1";
  344. // // return AppContext.getInstance().getLoginUserMap().get(userName)
  345. // // .getSid();
  346. // }
  347. // }
  348. return "1";
  349. }
  350. //example
  351. //http://192.168.100.75:8080/bjglweb/ws/ss/SystemService/Logout/admin/5f3536ba-681d-4c66-ba3f-ba9b28d20944
  352. /**
  353. * 登出系统
  354. * 返回值为{int,String,String}---(结果标志0-成功,1-失败)
  355. */
  356. @ProduceMime("application/json")
  357. @GET
  358. @Path("/Logout/{userName}/{sessionID}")
  359. public String Logout(@PathParam("userName") String userName,
  360. @PathParam("sessionID") String sessionID) {
  361. HashMap<String, LoginInfo> LoginUserMap = AppContext.getInstance().getLoginUserMap();
  362. HttpServletRequest req = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
  363. if (LoginUserMap.containsKey(userName)) {
  364. LoginInfo loginInfo = LoginUserMap.get(userName);
  365. if (loginInfo.getSessionId().equals(sessionID)) {
  366. LoginUserMap.remove(userName);
  367. loginInfo = null;
  368. // 系统审计日志采集登录管理中登录操作
  369. AuditLogVo auLog=new AuditLogVo();
  370. AuditLogImpl auLogImpl=new AuditLogImpl();
  371. auLog.setSip(req.getRemoteAddr());
  372. auLog.setAppmodule("登录管理");
  373. auLog.setOptype("Logout");
  374. auLog.setMainaccount(userName);
  375. auLog.setOpcontent("登出系统");
  376. auLog.setOpresult("成功");
  377. auLog.setLoglevel("一般");
  378. auLogImpl.insert(auLog);
  379. return "0";
  380. } else {
  381. return "1";
  382. }
  383. } else {
  384. return "1";
  385. }
  386. }
  387. // example
  388. // http://192.168.100.75:8080/bjglweb/ws/ss/SystemService/getLoginfo/123
  389. // 返回值为登录用户的所有信息
  390. // @ProduceMime("application/json")
  391. // @GET
  392. // @Path("/getLoginfo/{userName}")
  393. // public LoginInfo getLoginfo(@PathParam("userName") String userName) {
  394. // if (AppContext.getInstance().getLoginUserMap().containsKey(userName)) {
  395. // LoginInfo loginInfo = (LoginInfo) AppContext.getInstance()
  396. // .getLoginUserMap().get(userName);
  397. // return loginInfo;
  398. // } else {
  399. // return null;
  400. // }
  401. // }
  402. // example
  403. // http://localhost:8081/bjglweb/ws/ss/SystemService/getOnLineUser/c8c2ff6d-44a7-4f80-8812-690db1b94bcc/admin
  404. // 返回值为登录用户的所有信息
  405. // @ProduceMime("application/json")
  406. // @GET
  407. // @Path("/getOnLineUser/{sessionID}/{userName}")
  408. // public LoginInfos getOnLineUser(@PathParam("sessionID") String sessionID,
  409. // @PathParam("userName") String userName) {
  410. //
  411. // LoginInfos loginInfos = new LoginInfos();
  412. // ArrayList<LoginInfo> list = new ArrayList<LoginInfo>();
  413. // HashMap<String, LoginInfo> LoginUserMap = AppContext.getInstance()
  414. // .getLoginUserMap();
  415. // Collection<LoginInfo> collection = LoginUserMap.values();
  416. // Iterator<LoginInfo> it = collection.iterator();
  417. // while (it.hasNext()) {
  418. // LoginInfo loginInfo = new LoginInfo();
  419. // loginInfo = it.next();
  420. // list.add(loginInfo);
  421. // }
  422. // loginInfos.setLoginInfos(list);
  423. // return loginInfos;
  424. // }
  425. // example
  426. // http://192.168.100.75:8080/bjglweb/ws/ss/SystemService/reportOnline/admin
  427. // 返回值为登录用户的所有信息
  428. @SuppressWarnings("unused")
  429. @ProduceMime("application/json")
  430. @GET
  431. @Path("/reportOnline/{userName}")
  432. public String reportOnline(@PathParam("userName") String userName) {
  433. if (AppContext.getInstance().getLoginUserMap().containsKey(userName)) {
  434. String dateTime = DateHelper.getDateTime();
  435. LoginInfo loginInfo = (LoginInfo) AppContext.getInstance()
  436. .getLoginUserMap().get(userName);
  437. // loginInfo.setReportdate(dateTime);
  438. AppContext.getInstance().getLoginUserMap().put(userName, loginInfo);
  439. return "0";
  440. } else {
  441. return "1";
  442. }
  443. }
  444. // 根据当前用户sessionId获得用户信息
  445. public LoginInfo getNowUserInfo(String sessionId) {
  446. HashMap<String, LoginInfo> LoginUserMap = AppContext.getInstance()
  447. .getLoginUserMap();
  448. Collection<LoginInfo> collection = LoginUserMap.values();
  449. Iterator<LoginInfo> it = collection.iterator();
  450. LoginInfo loginInfo = new LoginInfo();
  451. while (it.hasNext()) {
  452. loginInfo = it.next();
  453. // if (sessionId.equals(loginInfo.getSid())) {
  454. // break;
  455. // }
  456. }
  457. return loginInfo;
  458. }
  459. // 根据当前用户UserId获得用户信息
  460. public LoginInfo getNowUserByUid(String uId) {
  461. HashMap<String, LoginInfo> LoginUserMap = AppContext.getInstance()
  462. .getLoginUserMap();
  463. Collection<LoginInfo> collection = LoginUserMap.values();
  464. Iterator<LoginInfo> it = collection.iterator();
  465. LoginInfo loginInfo = new LoginInfo();
  466. while (it.hasNext()) {
  467. loginInfo = it.next();
  468. // if (uId.equals(loginInfo.getUid())) {
  469. // break;
  470. // }
  471. }
  472. return loginInfo;
  473. }
  474. // 取得在线用户的json串
  475. @SuppressWarnings("unused")
  476. @ProduceMime("application/json")
  477. @POST
  478. @Path("/getOnLineUserData/")
  479. public String getOnlineData(String params) throws PersistenceException {
  480. SysModel sysmodel = ModelFactory.getSysmodel();
  481. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  482. try {
  483. params = java.net.URLDecoder.decode(params, "UTF-8");
  484. } catch (UnsupportedEncodingException e) {
  485. e.printStackTrace();
  486. }
  487. LoginInfo loginInfo = null;
  488. String userName = Utils.getParameter("userName", params);
  489. String sessionID = Utils.getParameter("sessionID", params);
  490. LoginInfos loginInfos = new LoginInfos();
  491. // loginInfos = getOnLineUser(sessionID,userName);
  492. String firstPageNum = Utils.getParameter("pager.pageNo", params) == null ? "0"
  493. : Utils.getParameter("pager.pageNo", params);
  494. String limit = Utils.getParameter("pager.pageSize", params) == null ? "10"
  495. : Utils.getParameter("pager.pageSize", params);
  496. StringBuffer json = new StringBuffer();
  497. ArrayList<LoginInfo> list = new ArrayList<LoginInfo>();
  498. list = (ArrayList<LoginInfo>) loginInfos.getLoginInfos();
  499. // String result =
  500. // "{\"pager.pageNo\":"+firstPageNum+",\"pager.totalRows\":"+pageNoResult+",\"rows\":"+rowsResult+"}";
  501. json.append("{\"pager.pageNo\":" + firstPageNum
  502. + ",\"pager.totalRows\":\"\",\"rows\":[");
  503. for (int i = 0; i < list.size(); i++) {
  504. loginInfo = list.get(i);
  505. // String uid=loginInfo.getUid()==null?"":loginInfo.getUid();
  506. // String uname=loginInfo.getUname()==null?"":loginInfo.getUname();
  507. // String
  508. // display_Name=loginInfo.getDisplay_Name()==null?"":loginInfo.getDisplay_Name();
  509. // String msg=loginInfo.getMsg()==null?"":loginInfo.getMsg();
  510. // String sid=loginInfo.getSid()==null?"":loginInfo.getSid();
  511. // String rid=loginInfo.getRid()==null?"":loginInfo.getRid();
  512. // String
  513. // employee_Id=loginInfo.getEmployee_Id()==null?"":loginInfo.getEmployee_Id();
  514. // String uarea=loginInfo.getUarea()==null?"":loginInfo.getUarea();
  515. // String
  516. // uareaName=loginInfo.getUareaName()==null?"":loginInfo.getUareaName();
  517. // String
  518. // logonIp=loginInfo.getLogonIp()==null?"":loginInfo.getLogonIp();
  519. // String
  520. // logondate=loginInfo.getLogondate()==null?"":loginInfo.getLogondate();
  521. // String
  522. // reportdate=loginInfo.getReportdate()==null?"":loginInfo.getReportdate();
  523. // String
  524. // unitCode=loginInfo.getUnitCode()==null?"":loginInfo.getUnitCode();
  525. // String userType =
  526. // loginInfo.getUserType()==null?"":loginInfo.getUserType();
  527. // String userHome =
  528. // loginInfo.getUserHome()==null?"":loginInfo.getUserHome();
  529. // json.append("{\"USER_ID_880\":\""+uid+"\",\"NAME_880\":\""+uname+"\",\"DISPLAY_NAME_880\":\""+display_Name+"\",\"LOGONIP\":\""+logonIp+"\",\"LOGONDATE\":\""+logondate+"\"");
  530. // json.append(",\"UNIT_CODE_880\":\""+unitCode+"\",\"TYPE_880\":\""+userType+"\"");
  531. //
  532. // if(!userType.equals("")){
  533. // String
  534. // fd_codeSql=" select fd_description FROM BM$_UserType where fd_code='"+userType+"' ";
  535. // ArrayList fd_codes;
  536. // fd_codes = persistence.getSearchResult(99,fd_codeSql);
  537. // if(fd_codes.size()<1){
  538. // json.append(",\"TYPE_880_SHOW\":\""+""+"\"");
  539. // }else{
  540. // String[] fd_code = (String[]) fd_codes.get(0);
  541. // json.append(",\"TYPE_880_SHOW\":\""+fd_code[0]+"\"");
  542. // }
  543. // }
  544. // if(!unitCode.equals(""))
  545. // {
  546. // String
  547. // unit_codeSql=" select Dept_Name FROM Sys_Department where Dept_Id='"+unitCode.substring(1)+"' ";
  548. // ArrayList unit_codes;
  549. // unit_codes = persistence.getSearchResult(99,unit_codeSql);
  550. // if(unit_codes.size()<1){
  551. // json.append(",\"UNIT_CODE_880_SHOW\":\""+""+"\"");
  552. // }else{
  553. // String[] unitcode = (String[]) unit_codes.get(0);
  554. // json.append(",\"UNIT_CODE_880_SHOW\":\""+unitcode[0]+"\"");
  555. // }
  556. // }
  557. json.append("},");
  558. }
  559. json.deleteCharAt(json.lastIndexOf(","));
  560. json.append("]}");
  561. // String pageNoResult = origin.getString("total");
  562. // String rowsResult = origin.getString("rows");
  563. //
  564. // String result =
  565. // "{\"pager.pageNo\":"+firstPageNum+",\"pager.totalRows\":"+pageNoResult+",\"rows\":"+rowsResult+"}";
  566. log.debug(json.toString());
  567. System.out.println(json.toString());
  568. return json.toString();
  569. }
  570. // 取得用户登陆情况数据
  571. @SuppressWarnings("unused")
  572. @ProduceMime("application/json")
  573. @POST
  574. @Path("/getCountUserData/")
  575. public String getCountUserData(String params) {
  576. DepartExc departExc = new DepartExc();
  577. // log.info("参数:"+params);
  578. try {
  579. params = java.net.URLDecoder.decode(params, "UTF-8");
  580. } catch (UnsupportedEncodingException e) {
  581. e.printStackTrace();
  582. }
  583. log.info("参数:" + params);
  584. JSONArray json = null;
  585. JDBCHelper jdbc = new JDBCHelper();
  586. jdbc.begin();
  587. String beginTime = Utils.getParameter("startTime", params);
  588. String endTime = Utils.getParameter("endTime", params);
  589. // log.info("开始时间:"+beginTime+"结束时间:"+endTime);
  590. String punitCode = Utils.getParameter("punitCode", params);
  591. StringBuffer sqluser = new StringBuffer();
  592. String logCon = "";
  593. if (!"".equals(beginTime) && !"".equals(endTime)
  594. && !beginTime.equals(endTime)) {
  595. logCon = "and c.Option_Time between '" + beginTime + "' and '"
  596. + endTime + "'";
  597. } else if (!"".equals(beginTime) && "".equals(endTime)) {
  598. logCon = "and c.Option_Time > '" + beginTime + "'";
  599. } else if ("".equals(beginTime) && !"".equals(endTime)) {
  600. logCon = "and c.Option_Time < '" + endTime + "'";
  601. } else if (beginTime.equals(endTime)
  602. && !("".equals(beginTime) || "".equals(endTime))) {
  603. logCon = "and c.Option_Time between '" + beginTime + "' and '"
  604. + endTime + "'";
  605. } else if ("".equals(beginTime) && "".equals(endTime)) {
  606. logCon = "";
  607. }
  608. sqluser.append("SELECT a.Name, a.Display_Name, ");
  609. sqluser.append("(select b.Dept_Name from Sys_Department b where b.Dept_Id = a.Unit_Code and b.is_del = '0') as 所属部门 ,");
  610. sqluser.append(
  611. "(SELECT count(*) from Sys_Log c where c.Action='5' and c.Description like '%登录成功' and c.User_ID = a.name ")
  612. .append(logCon).append(") as enterCount ");
  613. sqluser.append(" FROM SYS_USER_INFO a");
  614. sqluser.append(" where a.Is_Del = '0'");
  615. ArrayList<String[]> userList;
  616. String[][] enterArry = null;
  617. ArrayList<LoginEnter> logEntList = new ArrayList<LoginEnter>();
  618. try {
  619. userList = new ArrayList<String[]>();
  620. LoginEnter le = new LoginEnter();
  621. StringBuffer strsql = new StringBuffer();
  622. strsql.append(sqluser);
  623. strsql.append("and a.SUPERIOR_CODE = '" + punitCode + "' ");
  624. log.info("查询用户成功登陆系统的次数 : " + strsql);
  625. userList = jdbc.getSearchResult(99, strsql.toString());
  626. enterArry = null;
  627. enterArry = new String[userList.size()][3];
  628. for (int i = 0; i < userList.size(); i++) {
  629. String[] temp = (String[]) userList.get(i);
  630. String Name = temp[0] == null ? "" : temp[0];
  631. String Display_Name = temp[1] == null ? "" : temp[1];
  632. String Dept = temp[2] == null ? "" : temp[2];
  633. String entCount = temp[3] == null ? "" : temp[3];
  634. // 获得用户登录系统次数统计信息
  635. // int iEnterCount = this.getWebEnter(Name, logCon,jdbc);
  636. enterArry[i][0] = Display_Name;
  637. enterArry[i][1] = entCount + "";
  638. enterArry[i][2] = Dept + "";
  639. le.setEnterArry(enterArry);
  640. le.setArea(departExc.getBMTableByNameIds("Sys_Department",
  641. punitCode));
  642. }
  643. logEntList.add(le);
  644. } catch (PersistenceException e) {
  645. e.printStackTrace();
  646. log.error("错误:" + e.toString());
  647. jdbc.rollback();
  648. } finally {
  649. jdbc.release();
  650. }
  651. json = JSONArray.fromObject(logEntList);
  652. log.info("json=" + json);
  653. return json.toString();
  654. }
  655. /**
  656. * 获得指定用户成功登陆系统的次数
  657. *
  658. * @param UserID
  659. * 用户登录的账号如:mtgadmin
  660. * @param logCon
  661. * 登录查询条件 要以 AND 开始
  662. *
  663. * @return the bjglweb enter
  664. *
  665. * @throws PersistenceException
  666. * the persistence exception
  667. *
  668. * @author sun
  669. * @version 2009-7-21-15:30:42
  670. *
  671. * Gets the bjglweb enter.
  672. */
  673. // private int getWebEnter(String UserID,String logCon,JDBCHelper jdbc)
  674. // throws PersistenceException {
  675. //
  676. // StringBuffer sb = new StringBuffer();
  677. // sb.append("SELECT count(*) FROM Sys_Log ");
  678. // sb.append(" where Action='5' and Description like '%登录成功' ");
  679. // sb.append(" and User_ID = '" + UserID + "' ");
  680. // if(logCon != null)
  681. // sb.append(logCon);
  682. // return jdbc.getFunctionNumber(99,sb.toString());
  683. // }
  684. // 取得二维常量表中的value
  685. public String getBMTableByNameId(String name, String fdCode) {
  686. SysModel sysmodel = ModelFactory.getSysmodel();
  687. List<String[]> lis = null;
  688. String value = "";
  689. try {
  690. // 二维常量
  691. MdpConstant twoConstan = sysmodel.getMdpConstantByName(name);
  692. lis = twoConstan.getAllNode();
  693. for (String[] s : lis) {
  694. if (s[0].equals(fdCode)) {
  695. value = s[1];
  696. }
  697. }
  698. } catch (Exception e) {
  699. e.printStackTrace();
  700. }
  701. // return JSONObject.fromObject(cvos).toString();
  702. return value;
  703. }
  704. }