123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774 |
- package com.sinosoft.lz.system.logon.service;
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import javax.ws.rs.GET;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.PathParam;
- import javax.ws.rs.ProduceMime;
- import javax.ws.rs.core.Context;
- import org.apache.cxf.transport.http.AbstractHTTPDestination;
- import org.apache.log4j.Logger;
- import com.formaction.Utils;
- import com.persistence.service.JDBCHelper;
- import com.persistence.service.PersistenceFactory;
- import com.persistence.service.SysPersistence;
- import com.persistence.service.exception.PersistenceException;
- import com.sinosoft.lz.system.AppContext;
- import com.sinosoft.lz.system.auditLog.impl.AuditLogImpl;
- import com.sinosoft.lz.system.auditLog.vo.AuditLogVo;
- import com.sinosoft.lz.system.department.DepartExc;
- import com.sinosoft.lz.system.logon.dao.LoginDao;
- import com.sinosoft.lz.system.logon.vo.LoginEnter;
- import com.sinosoft.lz.system.logon.vo.LoginInfo;
- import com.sinosoft.lz.system.logon.vo.LoginInfos;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.MdpConstant;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- import com.toolkit.date.DateHelper;
- import flex.messaging.log.Log;
- import net.sf.json.JSONArray;
- @Path("/LoginService/")
- public class LoginService {
- private final Logger log = Logger.getLogger(getClass());
- @Context
- private org.apache.cxf.jaxrs.ext.MessageContext mc;
- private String deptId = null;
- public static int loginNum=0;
- public static Long startTime=0L;
- public static Long responseTime=0L;
- public String getDeptId() {
- return deptId;
- }
- public void setDeptId(String deptId) {
- this.deptId = deptId;
- }
- @SuppressWarnings("rawtypes")
- @ProduceMime("application/json")
- @POST
- @Path("/getUserInfo")
- public String getUserInfo() {
- HttpServletRequest rq = (HttpServletRequest) mc
- .get(AbstractHTTPDestination.HTTP_REQUEST);
- //设置session失效时间两小时
- rq.getSession().setMaxInactiveInterval(60*60*2);
- String login_name = rq.getSession().getAttribute("User_Name")
- .toString();
- String sql = "select user_id,real_name from sys_user_info where login_name='"
- + login_name + "'";
- List list = null;
- try {
- list = PersistenceFactory.getInstance(ModelFactory.getSysmodel())
- .getSearchResultToMap(99, sql);
- } catch (PersistenceException e) {
- log.error(e.getMessage());
- }
- log.info("getUserInfo===" + list.size());
- String result = "{\"rows\":" + JSONArray.fromObject(list).toString()
- + "}";
- log.info("getUserInfo===" + result);
- return result;
- }
- //获取用户的公司和部门信息
- @SuppressWarnings("rawtypes")
- @ProduceMime("application/json")
- @POST
- @Path("/getUserDeptInfo")
- public String getDept() {
- HttpServletRequest rq = (HttpServletRequest) mc
- .get(AbstractHTTPDestination.HTTP_REQUEST);
- String login_name = rq.getSession().getAttribute("User_Name")
- .toString();
- 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 "
- + " 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+"'";
-
- 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 "
- + "a.user_id = c.user_id and b.dept_id = c.dept_id and a.login_name='"+login_name+"'";
- log.info("getUserDeptInfo.sql========"+sql);
- log.info("getUserInfo.sql1========"+sql1);
- List list = null;
- try {
- list = PersistenceFactory.getInstance(ModelFactory.getSysmodel())
- .getSearchResultToMap(99, sql);
- if(list==null||list.size()==0){
- list = PersistenceFactory.getInstance(ModelFactory.getSysmodel())
- .getSearchResultToMap(99, sql1);
- }
- } catch (PersistenceException e) {
- log.error(e.getMessage());
- }
- log.info("getUserDeptInfo" + list.size());
- String result = "{\"rows\":" + JSONArray.fromObject(list).toString()
- + "}";
- log.info("getUserDeptInfo==" + result);
- return result;
- }
- /*//获得登录人的部门id
- public String getDepartmentId(){
- HttpServletRequest rq = (HttpServletRequest) mc
- .get(AbstractHTTPDestination.HTTP_REQUEST);
- String login_name = rq.getSession().getAttribute("User_Name")
- .toString();
- 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+"'";
- return sql;
- }*/
-
-
- @ProduceMime("application/json")
- @POST
- @Path("/LoginPw")
- public LoginInfo tryLoginPw(String params) {
- startTime=new Date().getTime();
- LoginInfo loginInfo = new LoginInfo();
- String passWord = "";
- String userName = "";
- log.info(params);
- try {
- userName = Utils.getParameter("username", params);
- passWord = Utils.getParameter("password", params);
- HttpServletRequest req = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
- Map<String,LoginInfo> userMap = AppContext.getInstance().getLoginUserMap();
-
- // 认证
- LoginDao loginDao = new LoginDao();
- loginInfo = loginDao.checkLoginPw(userName,passWord);
-
-
- String userIP = req.getRemoteAddr();
- //保存登录日期与时间
- if (loginInfo != null && "0".equals(loginInfo.getSt())) {
- loginDao.setLoginDate(userName);
- }
-
- if (loginInfo != null && "0".equals(loginInfo.getSt())) {
-
-
- // 多角色 “,”分开
- String[] roles = loginDao.getRoleIdsByUserId(loginInfo.getUser_id());
- loginInfo.setRoleids(roles[0]);
- loginInfo.setRolenames(roles[1]);
- // 多部门“,”分开, 存在一个人 属于多个部门的情况
- String[] sts = loginDao.getDeptsByUserId(loginInfo.getUser_id());
- loginInfo.setDeptids(sts[0]);
- loginInfo.setDeptnames(sts[1]);
- loginInfo.setParent_ids(sts[2]);
- loginInfo.setDept_types(sts[3]);
- loginInfo.setCorp_ids(sts[4]);
- loginInfo.setCorp_names(sts[5]);
- loginInfo.setPcorp_ids(sts[6]);
- loginInfo.setPcorp_names(sts[7]);
-
- loginInfo.setSessionId(req.getSession().getId()); //存入会话ID
-
- req.getSession().setAttribute("User_Name", userName);
- req.getSession()
- .setAttribute("User_ID", loginInfo.getUser_id());
- req.getSession().setAttribute("Real_Name",
- loginInfo.getReal_name());
- req.getSession()
- .setAttribute("roleids", loginInfo.getRoleids()); // 多角色
- // ID“,”分开
- req.getSession().setAttribute("unitCode",
- loginInfo.getDeptids());// 多部门ID“,”分开
- req.getSession().setAttribute("deptnames",
- loginInfo.getDeptnames()); // 多部门NAME“,”分开
- req.getSession().setAttribute("loginInfo", loginInfo);
-
-
- String sessionid = req.getSession().getId();
- // if(userMap.containsKey(userName)){
- // LoginInfo minfo = userMap.get(userName);
- //
- // if(!sessionid.equals(minfo.getSessionId())){
- // userMap.remove(userName);
- // }
- // }
- userMap.put(userName, loginInfo);
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("登录失败" + e.getMessage());
- }
- log.info(loginInfo.toString());
- return loginInfo;
- }
-
- //4A登陆验证
- // 返回值为{int,String,String}---(结果标志0-成功,消息,SessionID)
- @ProduceMime("application/json")
- @POST
- @Path("/Login")
- public LoginInfo tryLogin(String params) {
- LoginInfo loginInfo = new LoginInfo();
- // String passWord = "";
- String userName = "";
- String real_name = "";
- log.info("1、应急登录开始:"+params);
- try {
- // 格式化参数,获取登录的用户名和密码
- // params = java.net.URLDecoder.decode(params, "UTF-8");
- userName = Utils.getParameter("username", params);
- real_name = Utils.getParameter("real_name", params);
- // passWord = Utils.getParameter("password", params);
- HttpServletRequest req = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
- Map<String,LoginInfo> userMap = AppContext.getInstance().getLoginUserMap();
-
- // 认证
- LoginDao loginDao = new LoginDao();
- log.info("2、应急登录验证:用户名"+userName);
- loginInfo = loginDao.checkLogin(userName,real_name);
-
-
- String userIP = req.getRemoteAddr();
- //保存登录日期与时间
- if (loginInfo != null && "0".equals(loginInfo.getSt())) {
- loginDao.setLoginDate(userName);
- }
-
- if (loginInfo != null && "0".equals(loginInfo.getSt())) {
-
-
- // 多角色 “,”分开
- String[] roles = loginDao.getRoleIdsByUserId(loginInfo.getUser_id());
- loginInfo.setRoleids(roles[0]);
- loginInfo.setRolenames(roles[1]);
- // 多部门“,”分开, 存在一个人 属于多个部门的情况
- String[] sts = loginDao.getDeptsByUserId(loginInfo.getUser_id());
- loginInfo.setDeptids(sts[0]);
- loginInfo.setDeptnames(sts[1]);
- loginInfo.setParent_ids(sts[2]);
- loginInfo.setDept_types(sts[3]);
- loginInfo.setCorp_ids(sts[4]);
- loginInfo.setCorp_names(sts[5]);
- loginInfo.setPcorp_ids(sts[6]);
- loginInfo.setPcorp_names(sts[7]);
-
- loginInfo.setSessionId(req.getSession().getId()); //存入会话ID
-
- req.getSession().setAttribute("User_Name", userName);
- req.getSession()
- .setAttribute("User_ID", loginInfo.getUser_id());
- req.getSession().setAttribute("Real_Name",
- loginInfo.getReal_name());
- req.getSession()
- .setAttribute("roleids", loginInfo.getRoleids()); // 多角色
- // ID“,”分开
- req.getSession().setAttribute("unitCode",
- loginInfo.getDeptids());// 多部门ID“,”分开
- req.getSession().setAttribute("deptnames",
- loginInfo.getDeptnames()); // 多部门NAME“,”分开
- req.getSession().setAttribute("loginInfo", loginInfo);
-
-
- String sessionid = req.getSession().getId();
- // if(userMap.containsKey(userName)){
- // LoginInfo minfo = userMap.get(userName);
- //
- // if(!sessionid.equals(minfo.getSessionId())){
- // userMap.remove(userName);
- // }
- // }
- userMap.put(userName, loginInfo);
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("登录失败" + e.getMessage());
- }
- log.info("登录成功:登录信息="+loginInfo.toString());
-
- //log.info(responseTime-startTime);
- return loginInfo;
- }
-
-
-
-
-
- @SuppressWarnings("rawtypes")
- @ProduceMime("application/json")
- @POST
- @Path("/getUserCompId")
- public String getUserCompId() {
- HttpServletRequest rq = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
- String login_name = rq.getSession().getAttribute("User_Name").toString();
- 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";
- List list = null;
- try {
- list = PersistenceFactory.getInstance(ModelFactory.getSysmodel()).getSearchResultToMap(
- 99, sql);
- } catch (PersistenceException e) {
- log.error(e.getMessage());
- }
- log.info("getUserInfo===" + list.size());
- String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
- log.info("getUserInfo===" + result);
- return result;
- }
-
- /**
- * 根据表名和字段,得到字段value
- */
- public String getBMTableByNameIds(String tablename, String fdCode) {
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql = "select name,fd_objectid from " + tablename
- + " where fd_objectid='" + fdCode + "'";
- ArrayList<String[]> codes;
- String value = "";
- try {
- codes = persistence.getSearchResult(99, sql);
- if (codes.size() > 0) {
- for (String[] s : codes) {
- if (s[1].equals(fdCode)) {
- value = s[0];
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("" + e);
- }
- return value;
- }
- @SuppressWarnings("unused")
- private String getPUnitCode(String departType, String unitCode) {
- log.info("部门编码:" + departType + ",单位编码:" + unitCode);
- if (("20,10").indexOf(departType) != -1 && !departType.equals("2"))// 市局
- // 分局
- {
- return unitCode;
- } else if (("4,5,1,2,3").indexOf(departType) != -1
- && unitCode.length() == 7)// 部门
- // 属于市局
- {
- return unitCode.substring(0, 5);
- } else if (unitCode.length() > 7) {
- return unitCode.substring(0, 7);
- } else {
- return "error";
- }
- }
- // example
- // http://192.168.100.201:8080/bjglweb/ws/ss/SystemService/isLive/123
- // 判断用户是否在线
- // 返回值为{String}---(结果标志0-成功,SessionID)
- @ProduceMime("application/json")
- @GET
- @Path("/isLive/{userName}/{sessionid}")
- public String isLive(@PathParam("userName") String userName,@PathParam("sessionid") String sessionid) {
- log.info("判断用户会话存在:" + userName+"---sessionid:"+sessionid);
- HttpServletRequest req = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
- Map<String,LoginInfo> userMap = AppContext.getInstance().getLoginUserMap();
- // if (userMap.containsKey(userName)) {
- // LoginInfo linfo = userMap.get(userName);
- // if(sessionid.equals(linfo.getSessionId())){
- // log.info("存在appcontext中的userinfo userid====="+AppContext.getInstance().getLoginUserMap().get(userName).getUser_id());
- //
- // return "1";
- // // return AppContext.getInstance().getLoginUserMap().get(userName)
- // // .getSid();
- // }
- // }
- return "1";
- }
- //example
- //http://192.168.100.75:8080/bjglweb/ws/ss/SystemService/Logout/admin/5f3536ba-681d-4c66-ba3f-ba9b28d20944
- /**
- * 登出系统
- * 返回值为{int,String,String}---(结果标志0-成功,1-失败)
- */
- @ProduceMime("application/json")
- @GET
- @Path("/Logout/{userName}/{sessionID}")
- public String Logout(@PathParam("userName") String userName,
- @PathParam("sessionID") String sessionID) {
-
- HashMap<String, LoginInfo> LoginUserMap = AppContext.getInstance().getLoginUserMap();
- HttpServletRequest req = (HttpServletRequest) mc.get(AbstractHTTPDestination.HTTP_REQUEST);
- if (LoginUserMap.containsKey(userName)) {
- LoginInfo loginInfo = LoginUserMap.get(userName);
- if (loginInfo.getSessionId().equals(sessionID)) {
- LoginUserMap.remove(userName);
- loginInfo = null;
- // 系统审计日志采集登录管理中登录操作
- AuditLogVo auLog=new AuditLogVo();
- AuditLogImpl auLogImpl=new AuditLogImpl();
- auLog.setSip(req.getRemoteAddr());
- auLog.setAppmodule("登录管理");
- auLog.setOptype("Logout");
- auLog.setMainaccount(userName);
- auLog.setOpcontent("登出系统");
- auLog.setOpresult("成功");
- auLog.setLoglevel("一般");
- auLogImpl.insert(auLog);
-
- return "0";
- } else {
- return "1";
- }
- } else {
- return "1";
- }
- }
- // example
- // http://192.168.100.75:8080/bjglweb/ws/ss/SystemService/getLoginfo/123
- // 返回值为登录用户的所有信息
- // @ProduceMime("application/json")
- // @GET
- // @Path("/getLoginfo/{userName}")
- // public LoginInfo getLoginfo(@PathParam("userName") String userName) {
- // if (AppContext.getInstance().getLoginUserMap().containsKey(userName)) {
- // LoginInfo loginInfo = (LoginInfo) AppContext.getInstance()
- // .getLoginUserMap().get(userName);
- // return loginInfo;
- // } else {
- // return null;
- // }
- // }
- // example
- // http://localhost:8081/bjglweb/ws/ss/SystemService/getOnLineUser/c8c2ff6d-44a7-4f80-8812-690db1b94bcc/admin
- // 返回值为登录用户的所有信息
- // @ProduceMime("application/json")
- // @GET
- // @Path("/getOnLineUser/{sessionID}/{userName}")
- // public LoginInfos getOnLineUser(@PathParam("sessionID") String sessionID,
- // @PathParam("userName") String userName) {
- //
- // LoginInfos loginInfos = new LoginInfos();
- // ArrayList<LoginInfo> list = new ArrayList<LoginInfo>();
- // HashMap<String, LoginInfo> LoginUserMap = AppContext.getInstance()
- // .getLoginUserMap();
- // Collection<LoginInfo> collection = LoginUserMap.values();
- // Iterator<LoginInfo> it = collection.iterator();
- // while (it.hasNext()) {
- // LoginInfo loginInfo = new LoginInfo();
- // loginInfo = it.next();
- // list.add(loginInfo);
- // }
- // loginInfos.setLoginInfos(list);
- // return loginInfos;
- // }
- // example
- // http://192.168.100.75:8080/bjglweb/ws/ss/SystemService/reportOnline/admin
- // 返回值为登录用户的所有信息
- @SuppressWarnings("unused")
- @ProduceMime("application/json")
- @GET
- @Path("/reportOnline/{userName}")
- public String reportOnline(@PathParam("userName") String userName) {
- if (AppContext.getInstance().getLoginUserMap().containsKey(userName)) {
- String dateTime = DateHelper.getDateTime();
- LoginInfo loginInfo = (LoginInfo) AppContext.getInstance()
- .getLoginUserMap().get(userName);
- // loginInfo.setReportdate(dateTime);
- AppContext.getInstance().getLoginUserMap().put(userName, loginInfo);
- return "0";
- } else {
- return "1";
- }
- }
- // 根据当前用户sessionId获得用户信息
- public LoginInfo getNowUserInfo(String sessionId) {
- HashMap<String, LoginInfo> LoginUserMap = AppContext.getInstance()
- .getLoginUserMap();
- Collection<LoginInfo> collection = LoginUserMap.values();
- Iterator<LoginInfo> it = collection.iterator();
- LoginInfo loginInfo = new LoginInfo();
- while (it.hasNext()) {
- loginInfo = it.next();
- // if (sessionId.equals(loginInfo.getSid())) {
- // break;
- // }
- }
- return loginInfo;
- }
- // 根据当前用户UserId获得用户信息
- public LoginInfo getNowUserByUid(String uId) {
- HashMap<String, LoginInfo> LoginUserMap = AppContext.getInstance()
- .getLoginUserMap();
- Collection<LoginInfo> collection = LoginUserMap.values();
- Iterator<LoginInfo> it = collection.iterator();
- LoginInfo loginInfo = new LoginInfo();
- while (it.hasNext()) {
- loginInfo = it.next();
- // if (uId.equals(loginInfo.getUid())) {
- // break;
- // }
- }
- return loginInfo;
- }
- // 取得在线用户的json串
- @SuppressWarnings("unused")
- @ProduceMime("application/json")
- @POST
- @Path("/getOnLineUserData/")
- public String getOnlineData(String params) throws PersistenceException {
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- try {
- params = java.net.URLDecoder.decode(params, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- LoginInfo loginInfo = null;
- String userName = Utils.getParameter("userName", params);
- String sessionID = Utils.getParameter("sessionID", params);
- LoginInfos loginInfos = new LoginInfos();
- // loginInfos = getOnLineUser(sessionID,userName);
- String firstPageNum = Utils.getParameter("pager.pageNo", params) == null ? "0"
- : Utils.getParameter("pager.pageNo", params);
- String limit = Utils.getParameter("pager.pageSize", params) == null ? "10"
- : Utils.getParameter("pager.pageSize", params);
- StringBuffer json = new StringBuffer();
- ArrayList<LoginInfo> list = new ArrayList<LoginInfo>();
- list = (ArrayList<LoginInfo>) loginInfos.getLoginInfos();
- // String result =
- // "{\"pager.pageNo\":"+firstPageNum+",\"pager.totalRows\":"+pageNoResult+",\"rows\":"+rowsResult+"}";
- json.append("{\"pager.pageNo\":" + firstPageNum
- + ",\"pager.totalRows\":\"\",\"rows\":[");
- for (int i = 0; i < list.size(); i++) {
- loginInfo = list.get(i);
- // String uid=loginInfo.getUid()==null?"":loginInfo.getUid();
- // String uname=loginInfo.getUname()==null?"":loginInfo.getUname();
- // String
- // display_Name=loginInfo.getDisplay_Name()==null?"":loginInfo.getDisplay_Name();
- // String msg=loginInfo.getMsg()==null?"":loginInfo.getMsg();
- // String sid=loginInfo.getSid()==null?"":loginInfo.getSid();
- // String rid=loginInfo.getRid()==null?"":loginInfo.getRid();
- // String
- // employee_Id=loginInfo.getEmployee_Id()==null?"":loginInfo.getEmployee_Id();
- // String uarea=loginInfo.getUarea()==null?"":loginInfo.getUarea();
- // String
- // uareaName=loginInfo.getUareaName()==null?"":loginInfo.getUareaName();
- // String
- // logonIp=loginInfo.getLogonIp()==null?"":loginInfo.getLogonIp();
- // String
- // logondate=loginInfo.getLogondate()==null?"":loginInfo.getLogondate();
- // String
- // reportdate=loginInfo.getReportdate()==null?"":loginInfo.getReportdate();
- // String
- // unitCode=loginInfo.getUnitCode()==null?"":loginInfo.getUnitCode();
- // String userType =
- // loginInfo.getUserType()==null?"":loginInfo.getUserType();
- // String userHome =
- // loginInfo.getUserHome()==null?"":loginInfo.getUserHome();
- // json.append("{\"USER_ID_880\":\""+uid+"\",\"NAME_880\":\""+uname+"\",\"DISPLAY_NAME_880\":\""+display_Name+"\",\"LOGONIP\":\""+logonIp+"\",\"LOGONDATE\":\""+logondate+"\"");
- // json.append(",\"UNIT_CODE_880\":\""+unitCode+"\",\"TYPE_880\":\""+userType+"\"");
- //
- // if(!userType.equals("")){
- // String
- // fd_codeSql=" select fd_description FROM BM$_UserType where fd_code='"+userType+"' ";
- // ArrayList fd_codes;
- // fd_codes = persistence.getSearchResult(99,fd_codeSql);
- // if(fd_codes.size()<1){
- // json.append(",\"TYPE_880_SHOW\":\""+""+"\"");
- // }else{
- // String[] fd_code = (String[]) fd_codes.get(0);
- // json.append(",\"TYPE_880_SHOW\":\""+fd_code[0]+"\"");
- // }
- // }
- // if(!unitCode.equals(""))
- // {
- // String
- // unit_codeSql=" select Dept_Name FROM Sys_Department where Dept_Id='"+unitCode.substring(1)+"' ";
- // ArrayList unit_codes;
- // unit_codes = persistence.getSearchResult(99,unit_codeSql);
- // if(unit_codes.size()<1){
- // json.append(",\"UNIT_CODE_880_SHOW\":\""+""+"\"");
- // }else{
- // String[] unitcode = (String[]) unit_codes.get(0);
- // json.append(",\"UNIT_CODE_880_SHOW\":\""+unitcode[0]+"\"");
- // }
- // }
- json.append("},");
- }
- json.deleteCharAt(json.lastIndexOf(","));
- json.append("]}");
- // String pageNoResult = origin.getString("total");
- // String rowsResult = origin.getString("rows");
- //
- // String result =
- // "{\"pager.pageNo\":"+firstPageNum+",\"pager.totalRows\":"+pageNoResult+",\"rows\":"+rowsResult+"}";
- log.debug(json.toString());
- System.out.println(json.toString());
- return json.toString();
- }
- // 取得用户登陆情况数据
- @SuppressWarnings("unused")
- @ProduceMime("application/json")
- @POST
- @Path("/getCountUserData/")
- public String getCountUserData(String params) {
- DepartExc departExc = new DepartExc();
- // log.info("参数:"+params);
- try {
- params = java.net.URLDecoder.decode(params, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- log.info("参数:" + params);
- JSONArray json = null;
- JDBCHelper jdbc = new JDBCHelper();
- jdbc.begin();
- String beginTime = Utils.getParameter("startTime", params);
- String endTime = Utils.getParameter("endTime", params);
- // log.info("开始时间:"+beginTime+"结束时间:"+endTime);
- String punitCode = Utils.getParameter("punitCode", params);
- StringBuffer sqluser = new StringBuffer();
- String logCon = "";
- if (!"".equals(beginTime) && !"".equals(endTime)
- && !beginTime.equals(endTime)) {
- logCon = "and c.Option_Time between '" + beginTime + "' and '"
- + endTime + "'";
- } else if (!"".equals(beginTime) && "".equals(endTime)) {
- logCon = "and c.Option_Time > '" + beginTime + "'";
- } else if ("".equals(beginTime) && !"".equals(endTime)) {
- logCon = "and c.Option_Time < '" + endTime + "'";
- } else if (beginTime.equals(endTime)
- && !("".equals(beginTime) || "".equals(endTime))) {
- logCon = "and c.Option_Time between '" + beginTime + "' and '"
- + endTime + "'";
- } else if ("".equals(beginTime) && "".equals(endTime)) {
- logCon = "";
- }
- sqluser.append("SELECT a.Name, a.Display_Name, ");
- sqluser.append("(select b.Dept_Name from Sys_Department b where b.Dept_Id = a.Unit_Code and b.is_del = '0') as 所属部门 ,");
- sqluser.append(
- "(SELECT count(*) from Sys_Log c where c.Action='5' and c.Description like '%登录成功' and c.User_ID = a.name ")
- .append(logCon).append(") as enterCount ");
- sqluser.append(" FROM SYS_USER_INFO a");
- sqluser.append(" where a.Is_Del = '0'");
- ArrayList<String[]> userList;
- String[][] enterArry = null;
- ArrayList<LoginEnter> logEntList = new ArrayList<LoginEnter>();
- try {
- userList = new ArrayList<String[]>();
- LoginEnter le = new LoginEnter();
- StringBuffer strsql = new StringBuffer();
- strsql.append(sqluser);
- strsql.append("and a.SUPERIOR_CODE = '" + punitCode + "' ");
- log.info("查询用户成功登陆系统的次数 : " + strsql);
- userList = jdbc.getSearchResult(99, strsql.toString());
- enterArry = null;
- enterArry = new String[userList.size()][3];
- for (int i = 0; i < userList.size(); i++) {
- String[] temp = (String[]) userList.get(i);
- String Name = temp[0] == null ? "" : temp[0];
- String Display_Name = temp[1] == null ? "" : temp[1];
- String Dept = temp[2] == null ? "" : temp[2];
- String entCount = temp[3] == null ? "" : temp[3];
- // 获得用户登录系统次数统计信息
- // int iEnterCount = this.getWebEnter(Name, logCon,jdbc);
- enterArry[i][0] = Display_Name;
- enterArry[i][1] = entCount + "";
- enterArry[i][2] = Dept + "";
- le.setEnterArry(enterArry);
- le.setArea(departExc.getBMTableByNameIds("Sys_Department",
- punitCode));
- }
- logEntList.add(le);
- } catch (PersistenceException e) {
- e.printStackTrace();
- log.error("错误:" + e.toString());
- jdbc.rollback();
- } finally {
- jdbc.release();
- }
- json = JSONArray.fromObject(logEntList);
- log.info("json=" + json);
- return json.toString();
- }
- /**
- * 获得指定用户成功登陆系统的次数
- *
- * @param UserID
- * 用户登录的账号如:mtgadmin
- * @param logCon
- * 登录查询条件 要以 AND 开始
- *
- * @return the bjglweb enter
- *
- * @throws PersistenceException
- * the persistence exception
- *
- * @author sun
- * @version 2009-7-21-15:30:42
- *
- * Gets the bjglweb enter.
- */
- // private int getWebEnter(String UserID,String logCon,JDBCHelper jdbc)
- // throws PersistenceException {
- //
- // StringBuffer sb = new StringBuffer();
- // sb.append("SELECT count(*) FROM Sys_Log ");
- // sb.append(" where Action='5' and Description like '%登录成功' ");
- // sb.append(" and User_ID = '" + UserID + "' ");
- // if(logCon != null)
- // sb.append(logCon);
- // return jdbc.getFunctionNumber(99,sb.toString());
- // }
- // 取得二维常量表中的value
- public String getBMTableByNameId(String name, String fdCode) {
- SysModel sysmodel = ModelFactory.getSysmodel();
- List<String[]> lis = null;
- String value = "";
- try {
- // 二维常量
- MdpConstant twoConstan = sysmodel.getMdpConstantByName(name);
- lis = twoConstan.getAllNode();
- for (String[] s : lis) {
- if (s[0].equals(fdCode)) {
- value = s[1];
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- // return JSONObject.fromObject(cvos).toString();
- return value;
- }
- }
|