diff --git a/power-admin/src/main/java/com/manage/controller/methodForEmrMedical.java b/power-admin/src/main/java/com/manage/controller/methodForEmrMedical.java index 9b6e658..3255974 100644 --- a/power-admin/src/main/java/com/manage/controller/methodForEmrMedical.java +++ b/power-admin/src/main/java/com/manage/controller/methodForEmrMedical.java @@ -1,18 +1,21 @@ package com.manage.controller; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.manage.encrypt.Base64; import com.manage.encrypt.MD5; import com.manage.entity.Power_Dept; +import com.manage.entity.Power_Log; import com.manage.entity.Power_Menu; +import com.manage.entity.Power_User; +import com.manage.service.LogService; import com.manage.service.Power_DeptService; import com.manage.service.Power_MenuService; import com.manage.service.Power_UserService; import com.manage.service.cache.Cache; import com.manage.service.cache.CacheManager; -import com.manage.util.DateUtils; -import com.manage.util.Msg; +import com.manage.util.*; import com.manage.vo.Power_UserVo; import com.manage.vo.User_Dept_Menu; import org.apache.commons.lang3.StringUtils; @@ -22,6 +25,8 @@ import org.apache.http.HttpEntity; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; @@ -29,13 +34,15 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; +import java.io.*; +import java.text.SimpleDateFormat; import java.util.*; /** @@ -58,6 +65,9 @@ public class methodForEmrMedical { @Autowired private Power_DeptService power_deptService; + @Autowired + private LogService logService; + @Value("${EMRMEDICALRECORD_IP}") private String ip; @@ -99,11 +109,12 @@ public class methodForEmrMedical { @RequestMapping(value = "getErweima") @ResponseBody - public JSONObject getErweima(String responseType, String clientId, HttpServletRequest request){ + public JSONObject getErweima(String responseType, String clientId, Boolean selfSign, HttpServletRequest request){ // 获得Http客户端 CloseableHttpClient httpClient = HttpClientBuilder.create().build(); // 创建Get请求 - HttpGet httpGet = new HttpGet("https://test.51trust.com/gateway/oauth/authorize?responseType=code&clientId=2017070411003376"); + HttpGet httpGet = new HttpGet("http://10.162.0.60:9999/gateway/oauth/authorize?responseType=" + responseType + "&clientId=" + clientId + "&selfSign=" + selfSign); + //HttpGet httpGet = new HttpGet("http://test.51trust.com/gateway/oauth/authorize?responseType=" + responseType + "&clientId=" + clientId + "&selfSign=" + selfSign); // 请求头 httpGet.setHeader("Content-Type", "application/json;charset=utf8"); // 响应模型 @@ -115,8 +126,6 @@ public class methodForEmrMedical { response = httpClient.execute(httpGet); // 从响应模型中获取响应实体 responseEntity = response.getEntity(); - System.out.println("responseEntity::::"+responseEntity); - System.out.println("响应状态为:" + response.getStatusLine()); if (responseEntity != null) { jsonObject = JSONObject.parseObject(EntityUtils.toString(responseEntity)); String contents = jsonObject.getString("contents"); @@ -149,24 +158,23 @@ public class methodForEmrMedical { @RequestMapping(value = "getUser") @ResponseBody - public JSONObject getUser(String requestId, HttpServletRequest request){ - // 获得Http客户端 + public JSONObject getUser(String requestId, String clientId, HttpServletRequest request){ + // 获得Http客户端"138275ab833e42d9qd6b4weab3y4027c8a3" CloseableHttpClient httpClient = HttpClientBuilder.create().build(); // 创建Get请求 - HttpGet httpGet = new HttpGet("https://test.51trust.com/gateway/oauth/tokeninfo?clientId=2017070411003376&requestId=" + requestId); + //HttpGet httpGet = new HttpGet("https://test.51trust.com/gateway/oauth/tokeninfo?clientId=" + clientId + "&requestId=" + requestId); + HttpGet httpGet = new HttpGet("http://10.162.0.60:9999/gateway/oauth/tokeninfo?clientId="+ clientId +"&requestId=" + requestId); // 请求头 httpGet.setHeader("Content-Type", "application/json;charset=utf8"); // 响应模型 CloseableHttpResponse response = null; - HttpEntity responseEntity=null; + HttpEntity responseEntity = null; JSONObject jsonObject = null; try { // 由客户端执行(发送)Get请求 response = httpClient.execute(httpGet); // 从响应模型中获取响应实体 responseEntity = response.getEntity(); - System.out.println("responseEntity::::"+responseEntity); - System.out.println("响应状态为:" + response.getStatusLine()); if (responseEntity != null) { jsonObject = JSONObject.parseObject(EntityUtils.toString(responseEntity)); String contents = jsonObject.getString("contents"); @@ -197,6 +205,203 @@ public class methodForEmrMedical { //return jsonObject; } + @RequestMapping(value = "smlogin") + @ResponseBody + public HashMap smlogin(String openId, String clientId) throws Exception { + + HashMap map = new HashMap<>(); + try { + System.out.println("--------------------------进入smlogin"); + Map map1 = getUserTwo(openId, clientId); +// Map map1 = (Map) JSON.parse(dataStr); + System.out.println(map1); + String userName = map1.get("employeeNumber").toString(); + + Power_UserVo powerUser = new Power_UserVo(); + powerUser.setUserName(userName); + powerUser.setUserPwd("000000"); + Power_UserVo user = powerUserService.findPowerUserByUserNameAndUserPwd(powerUser); + //添加进操作日志 + Power_Log log = new Power_Log(); + if( user != null){ + //如处于登录状态,先清除缓存 + //CacheManager.removeCacheByObject(user); + //记住 + //MyCookieUtil.remember(request, response); + + //清除用户登录错误次数缓存 + CacheManager.clearOnly(powerUser.getUserName()); + //存session密码置空 + //是否记住密码功能 + //MyCookieUtil.remember(request, response); + //设置token缓存 + String date = String.valueOf(DateUtils.getDate()); + String token = UUID.randomUUID().toString(); + + + + //查询归属医院 + /* long start5 = System.currentTimeMillis(); + Power_User_Dict powerUserDict = powerUserDictMapper.selectDictIdByUserId(user.getUserId()); + long end5 = System.currentTimeMillis(); + System.out.println("查询医院时间="+(end5-start5)/1000.0+"s"); + user.setDictId(powerUserDict.getDictId());*/ + //科室id科室名 + ActionScopeUtils.setSessionAttribute("token",token,Integer.valueOf(String.valueOf(TOKEN_EXPIRE_TIME))/1000); + + //设置用户登录次数缓存 + SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); + CacheManager.addloginUserCount(fmt.format(new Date()),user.getUserName()); + CacheManager.addExcCount("noExc"); + List list = null; + List menuList = new ArrayList<>(); + Set menus = new LinkedHashSet<>(); + if (user.getRoleId().equals(0) || user.getRoleId().equals(-100)) { + list = powerMenuService.queryAllPowerMenu(null,user.getRoleId()); + } else { + list = powerMenuService.selectUserAndRoleMenuListPower(user.getUserId(),null); + } + if(null != list && !list.isEmpty()){ + for (Power_Menu power_menu : list) { + User_Dept_Menu deptMenu = new User_Dept_Menu(); + String menuUrl = power_menu.getMenuUrl(); + if (StringUtils.isNotBlank(menuUrl)) { + BeanUtils.copyProperties(power_menu, deptMenu); + deptMenu.setMethodParent(power_menu.getParentId()); + menuList.add(deptMenu); + } + if (StringUtils.isNotBlank(power_menu.getMethod())) { + menus.add(power_menu.getMenuUrl()); + } + } + } + user.setMenuList(menuList); + user.setMenus(menus); + + //设置科室 + StringBuilder power_depts = new StringBuilder(); + List power_depts1 = power_deptService.selectByPrimaryKeys(user.getDeptId()); + for(int j=0;j
-<%-- 扫码登录--%> + 扫码登录
<%--忘记密码了?--%>
diff --git a/power-admin/src/main/webapp/static/js/login.js b/power-admin/src/main/webapp/static/js/login.js index 2914f7d..26f7c73 100644 --- a/power-admin/src/main/webapp/static/js/login.js +++ b/power-admin/src/main/webapp/static/js/login.js @@ -33,7 +33,12 @@ $(function(){ $.ajax({ type: "post", url : "methodForEmrMedical/getErweima", - data: {responseType:"code", clientId:"2019111514014789"}, + data: { + responseType:"code", + //clientId:"2017070411003376", + clientId:"2019111514014789", + selfSign: "true" + }, success : function(data) { var requestId = ""; $.each(data,function (index, obj){ @@ -49,38 +54,62 @@ $(function(){ zhdl.style.display = "none"; return false; }); - //test(requestId); - getUser(requestId); + polling(requestId); }, }) }); - var i = 0; - function test(requestId) { - while (i == 0) { - getUser(requestId); - } + + function polling(requestId, delay = 1000) { + return new Promise((resolve, reject) =>{ + $.ajax({ + type: "post", + url : "methodForEmrMedical/getUser", + data: { + requestId: requestId, + //clientId:"2017070411003376" + clientId:"2019111514014789" + }, + success: function (data) { + $.each(data,function (index, obj){ + //轮询查询接口 + if (obj === '未授权') { //是否继续轮询 + setTimeout(() => { + resolve(polling(requestId, delay)); + }, delay) + } else { + smlogin(obj); + resolve(obj); + } + return false; + }) + } + }) + }) } - function getUser(requestId) { + function smlogin(user) { $.ajax({ type: "post", - url : "methodForEmrMedical/getUser", - data: {requestId: requestId }, - success : function(data) { - $.each(data,function (index, obj){ - test(requestId); - if (obj != "未授权"){ - alert(obj.userName) - i = 1; - } - return false; - }); + url : "methodForEmrMedical/smlogin", + data: { + openId: user.openId, + //clientId:"2017070411003376" + clientId:"2019111514014789" }, + success: function (data) { + if (data.isSuccess){ + window.location.href = data.url; + }else { + //window.location.href = data.url; + window.location.reload(); + alert(data.msg); + } + + } }) } - }); $('body').keydown(function () {