nanfang_branch
kevin 4 years ago
parent c30240a01f
commit e94b5d88fe

@ -270,6 +270,12 @@
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.8.RELEASE</version>
</dependency>
</dependencies>

@ -93,9 +93,25 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>fastjson</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jaxen/jaxen -->
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<!-- WebService服务 -->

@ -1,11 +1,14 @@
package com.manage.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.manage.config.WebServiceCxf;
import com.manage.dao.Power_NoticeMapper;
import com.manage.dao.Power_UserMapper;
import com.manage.encrypt.Base64;
import com.manage.encrypt.MD5;
import com.manage.entity.*;
import com.manage.interfaces.webservice.PowerWebService;
import com.manage.interfaces.webservice.impl.PowerWebServiceImpl;
import com.manage.service.*;
import com.manage.service.cache.Cache;
import com.manage.service.cache.CacheManager;
@ -14,18 +17,24 @@ import com.manage.service.webSocket.WsPool;
import com.manage.util.DateUtils;
import com.manage.util.ExceptionPrintUtil;
import com.manage.util.Msg;
import com.manage.utils.ResultUtils;
import com.manage.utils.XmlUtils;
import com.manage.vo.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.endpoint.Client;
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.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import javax.jws.WebService;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* @ProjectName:
@ -63,6 +72,10 @@ public class FontController {
@Autowired
private Power_DeptService power_deptService;
public static Class getUserClass(Object root) {
return null;
}
/**
* 2.1
* @ProjectName: getRolePowerTreeBySysFlag
@ -363,6 +376,181 @@ public class FontController {
return Msg.success().add("list",list);
}
public static void main(String[] args) throws UnsupportedEncodingException {
String xml="<Request><SourceSystem>*******</SourceSystem><TargetSystem>医院信息平台</TargetSystem><username>sj</username><password>1C821B22D0402F317E40D93213C66843</password></Request>";
XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(xml.getBytes("UTF-8")));
String username = xmlUtils.getElement("username");
String password = xmlUtils.getElement("password");
System.out.println(username);
System.out.println(password);
System.out.println(ResultUtils.success().asXML());
}
/**
* 2.10
* @ProjectName: getToken
* @Description: token
* @Param
* @Return Msg
* @Author:
* @CreateDate: 2019/11/06 10:00
* @UpdateUser:
* @UpdateDate: 2019/11/06 10:00
* @UpdateRemark:
* @Version: 1.0
*/
@RequestMapping(value = "getTokenForHis",method = RequestMethod.POST)
@ResponseBody
public Msg getTokenForHis(String userName,String password) throws Exception{
if(StringUtils.isBlank(userName)){
return Msg.fail("用户名不能为空");
}
if(StringUtils.isBlank(password)){
return Msg.fail("密码不能为空");
}
//1.根据userName,password调用webService,校验第三方系统中是否有此账号
if (!linkHisLogin(userName,password)) {
return Msg.fail("校验第三方系统失败");
}
//2.根据userName查询我们的用户表是否存在
Power_UserVo userVo = new Power_UserVo();
// 判断数据库中是否有此用户,如果没有则插入数据库
List<Power_UserVo> user = userMapper.selectList().stream().filter(u -> userName.equals(u.getUserName())).limit(1).collect(Collectors.toList());
userVo = user.get(0);
if (user.size() == 0) {
//2.1不存在往用户表新增这条用户
userVo.setUserName(userName);
// userVo.setUserPwd(Base64.encode(MD5.KL("1C821B22D0402F317E40D93213C66843")));
userVo.setUserPwd(Base64.encode(MD5.KL(password)));
userVo.setRoleId(1);
userVo.setDeptId("3");
userVo.setEffective(1);
userVo.setCreater("his");
SimpleDateFormat fmt= new SimpleDateFormat();
userVo.setCreateDate(fmt.format(new Date()));
//插入00
userMapper.insert(userVo);
}
String token = setToken(userVo);
return Msg.success().add("token",token);
}
private boolean linkHisLogin(String userName, String password) {
//创建连接工厂
JAXDynamicClientFactory dcf = JAXDynamicClientFactory.newInstance();
//创建客户端
Object[] objects = new Object[0];
Client client = null;
try {
//医院给的webservice地址
String url = "http://192.168.128.170/csp/hsb/DHC.Published.PUB0025.BS.PUB0025.CLS?WSDL=1";
client = dcf.createClient(url);
//动态调用getInfosByUserId方法
//获取请求参数xml字符串
String xmlStr = getXml(userName,password);
objects = client.invoke("HIPManagerInfo", "S0110",xmlStr);
//应答信息
String re = objects[0].toString();
System.out.println(re);
//新用户存到数据库
if (re.contains("成功")) {
return true;
}
return false;
} catch (Exception e) {
e.printStackTrace();
} finally {
if(null != client) {
client.destroy();
}
}
return false;
}
private String getXml(String userName, String password) {
String Request="<Request> <SourceSystem>"+"嘉时软件"+"" +
"</SourceSystem> <TargetSystem>医院信息平台</TargetSystem> " +
" <username>"+userName+"</username> <password>"+password+"" +
"</password> </Request> ";
return Request;
}
/**
* getInfosByUserId
* @param
* @return
*/
@RestController
public class TestController{
@Autowired
private PowerWebServiceImpl powerWebService;
@Autowired
private WebServiceCxf webServiceCxf;
@GetMapping("/call")
public String call(String id) {
PowerWebService queryService = WebServiceCxf.createQueryService(id);
System.out.println(queryService.toString());
// return queryService.getInfosByUserId("token","sj");
String token = CacheManager.getCacheByUserId(id);
return queryService.getInfosByUserId(token, id);
}
}
private String setToken(Power_UserVo userVo){
String date = String.valueOf(DateUtils.getDate());
String token = Base64.encode(MD5.KL(date));
List<Power_Menu> list = null;
List<User_Dept_Menu> menuList = new ArrayList<>();
Set<String> menus = new TreeSet<>();
if (userVo.getRoleId().equals(0) || userVo.getRoleId().equals(-100)) {
list = powerMenuService.queryAllPowerMenu(null,userVo.getRoleId());
} else {
list = powerMenuService.selectUserAndRoleMenuListPower(userVo.getUserId(),null);
}
if(null != list && !list.isEmpty()){
for (Power_Menu powerMenu : list) {
User_Dept_Menu deptMenu = new User_Dept_Menu();
String menuUrl = powerMenu.getMenuUrl();
if (StringUtils.isNotBlank(menuUrl)) {
BeanUtils.copyProperties(powerMenu, deptMenu);
deptMenu.setMethodParent(powerMenu.getParentId());
menuList.add(deptMenu);
}
if (StringUtils.isNotBlank(powerMenu.getMethod())) {
menus.add(powerMenu.getMenuUrl());
}
}
}
userVo.setMenuList(menuList);
userVo.setMenus(menus);
//设置科室
StringBuilder powerDepts = new StringBuilder();
List<Power_Dept> powerDeptList = power_deptService.selectByPrimaryKeys(userVo.getDeptId());
for(int j = 0;j < powerDeptList.size();j++){
if(j<powerDeptList.size()-1){
powerDepts.append(powerDeptList.get(j).getDeptName()).append(",");
}else{
powerDepts.append(powerDeptList.get(j).getDeptName());
}
}
userVo.setRemark(powerDepts.toString());
//移除缓存
CacheManager.removeCacheByObject(userVo);
CacheManager.putCache(date,new Cache(date,userVo,TOKEN_EXPIRE_TIME));
return token;
}
/**
* 2.10
* @ProjectName: getToken
@ -587,4 +775,4 @@ public class FontController {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,211 @@
//package com.docus.bgts.utils;
//
//import com.alibaba.fastjson.JSON;
//import org.apache.http.HttpEntity;
//import org.apache.http.NameValuePair;
//import org.apache.http.client.ClientProtocolException;
//import org.apache.http.client.entity.UrlEncodedFormEntity;
//import org.apache.http.client.methods.*;
//import org.apache.http.client.utils.URIBuilder;
//import org.apache.http.entity.ContentType;
//import org.apache.http.entity.StringEntity;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
//import org.apache.http.message.BasicNameValuePair;
//import org.apache.http.util.EntityUtils;
//
//import java.io.IOException;
//import java.io.UnsupportedEncodingException;
//import java.net.URISyntaxException;
//import java.util.ArrayList;
//import java.util.Map;
//
//public class HttpUtils {
// private static PoolingHttpClientConnectionManager cm;
// private static String EMPTY_STR = "";
// private static String UTF_8 = "UTF-8";
//
// private static void init() {
// if (cm == null) {
// cm = new PoolingHttpClientConnectionManager();
// cm.setMaxTotal(50);// 整个连接池最大连接数
// cm.setDefaultMaxPerRoute(5);// 每路由最大连接数默认值是2
// }
// }
//
// /**
// * 通过连接池获取HttpClient
// *
// * @return
// */
// private static CloseableHttpClient getHttpClient() {
// init();
// return HttpClients.custom().setConnectionManager(cm).build();
// }
// /**
// * @param url
// * @return
// */
// public static String get(String url) {
// HttpGet httpGet = new HttpGet(url);
// return getResult(httpGet);
// }
// /**
// * @param url、params
// * @return
// */
// public static String get(String url, Map<String, String > params) throws URISyntaxException {
// URIBuilder ub = new URIBuilder();
// ub.setPath(url);
//
// ArrayList<NameValuePair> pairs = covertParams2NVPS(params);
// ub.setParameters(pairs);
//
// HttpGet httpGet = new HttpGet(ub.build());
// return getResult(httpGet);
// }
// /**
// * @param url、headers、params
// * @return
// */
// public static String get(String url, Map<String, Object> headers, Map<String, String> params)
// throws URISyntaxException {
// URIBuilder ub = new URIBuilder();
// ub.setPath(url);
//
// if (params != null) {
// ArrayList<NameValuePair> pairs = covertParams2NVPS(params);
// ub.setParameters(pairs);
// }
//
// HttpGet httpGet = new HttpGet(ub.build());
// for (Map.Entry<String, Object> param : headers.entrySet()) {
// httpGet.addHeader(param.getKey(), String.valueOf(param.getValue()));
// }
// return getResult(httpGet);
// }
// /**
// * @param url
// * @return
// */
// public static String post(String url) {
// HttpPost httpPost = new HttpPost(url);
// return getResult(httpPost);
// }
// /**
// * @param url、params
// * @return
// */
// public static String post(String url, Map<String, String> params) throws UnsupportedEncodingException {
// HttpPost httpPost = new HttpPost(url);
// httpPost.setEntity(new UrlEncodedFormEntity(covertParams2NVPS(params), "utf-8"));//设置表单提交编码
//
//// httpPost.setEntity(new StringEntity(JSON.toJSONString(params), ContentType.APPLICATION_FORM_URLENCODED));
// return getResult(httpPost);
// }
//
// public static String post(String url, Object params, Map<String, Object> head) throws UnsupportedEncodingException {
// HttpPost httpPost = new HttpPost(url);
// System.out.println(params);
// httpPost.setEntity(new StringEntity(params.toString()));//设置表单提交编码
// if (params != null) {
// for (Map.Entry<String, Object> param : head.entrySet()) {
// httpPost.addHeader(param.getKey(), String.valueOf(param.getValue()));
// }
// }
//// httpPost.setEntity(new StringEntity(JSON.toJSONString(params), ContentType.APPLICATION_FORM_URLENCODED));
// return getResult(httpPost);
// }
//
// private static ArrayList<NameValuePair> covertParams2NVPS(Map<String, String> params) {
// ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
// for (Map.Entry<String, String> param : params.entrySet()) {
// if (param.getValue() != null) {
// pairs.add(new BasicNameValuePair(param.getKey(), param.getValue()));
// }
// }
//
// return pairs;
// }
// /**
// * @param url、headers、params
// * @return
// */
// public static String post(String url, Map<String, Object> headers, Map<String, Object> params)
// throws UnsupportedEncodingException {
// HttpPost httpPost = new HttpPost(url);
// System.out.println(params);
// if (params != null) {
// for (Map.Entry<String, Object> param : headers.entrySet()) {
// httpPost.addHeader(param.getKey(), String.valueOf(param.getValue()));
// }
// }
//
// httpPost.setEntity(new StringEntity(JSON.toJSONString(params), ContentType.APPLICATION_JSON));
//
// return getResult(httpPost);
// }
//
// /**
// * 处理Http请求
// *
// * @param request
// * @return
// */
// private static String getResult(HttpRequestBase request) {
// // CloseableHttpClient httpClient = HttpClients.createDefault();
// CloseableHttpClient httpClient = getHttpClient();
// try {
// CloseableHttpResponse response = httpClient.execute(request);
// // response.getStatusLine().getStatusCode();
// HttpEntity entity = response.getEntity();
// if (entity != null) {
// // long len = entity.getContentLength();// -1 表示长度未知
// String result = EntityUtils.toString(entity, UTF_8);
// response.close();
// // httpClient.close();
// return result;
// }
// } catch (ClientProtocolException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
//
// }
//
// return EMPTY_STR;
// }
//
// /**
// * 处理Http请求
// *
// * @param requestBuilder
// * @return
// */
// private static String getResult(RequestBuilder requestBuilder) {
// // CloseableHttpClient httpClient = HttpClients.createDefault();
// CloseableHttpClient httpClient = getHttpClient();
// try {
// CloseableHttpResponse response = httpClient.execute(requestBuilder.build());
// // response.getStatusLine().getStatusCode();
// HttpEntity entity = response.getEntity();
// if (entity != null) {
// // long len = entity.getContentLength();// -1 表示长度未知
// String result = EntityUtils.toString(entity, UTF_8);
// response.close();
// // httpClient.close();
// return result;
// }
// } catch (ClientProtocolException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
//
// }
//
// return EMPTY_STR;
// }
//}

@ -0,0 +1,44 @@
package com.docus.bgts.utils;
import java.io.*;
/**
* json
*/
public class JsonUtils {
/**
* json
* @param fileNamejson
* @return
*/
public static String readJsonFile(String fileName) {
String jsonStr = "";
Reader reader=null;
FileReader fileReader=null;
try {
File jsonFile = new File(fileName);
fileReader = new FileReader(jsonFile);
reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
jsonStr = sb.toString();
return jsonStr;
} catch (IOException e) {
e.printStackTrace();
return null;
}finally {
try {
reader.close();
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,73 @@
package com.manage.utils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
/**
*
*/
public class ResultUtils {
/**
* document
* @param response
* @return
*/
public static Element getElement(Document response){
Element element = response.getRootElement();
return element;
}
/**
*
* @return
*/
public static Document success(){
// 1、创建document对象
Document document= DocumentHelper.createDocument();
//2.创建根节点
Element response=document.addElement("Response");
// 3、生成子节点及子节点内容
response.addElement("ResultCode").setText("0");
response.addElement("ResultCount").setText("成功");
return document;
}
/**
*
* @return
*/
public static String fail(){
// 1、创建document对象
Document document= DocumentHelper.createDocument();
//2.创建根节点
Element response=document.addElement("Response");
// 3、生成子节点及子节点内容
response.addElement("ResultCode").setText("1");
response.addElement("ResultCount").setText("失败");
// //赋值
// resCode.setText(String.valueOf(Codes.ERROR.getCode()));
// retCon.setText(Codes.ERROR.getMessage());
return document.asXML();
}
// /**
// * 失败返回
// * @return
// */
// public static String fail(String message){
// // 1、创建document对象
// Document document= DocumentHelper.createDocument();
// //2.创建根节点
// Element response=document.addElement(Codes.RESPONSE.getMessage());
// // 3、生成子节点及子节点内容
// Element RetInfo = response.addElement(Codes.RET_INFO.getMessage());
// //4.生成代码和描述节点
// Element resCode = RetInfo.addElement(Codes.RET_CODE.getMessage());
// Element retCon = RetInfo.addElement(Codes.RET_CON.getMessage());
// //赋值
// resCode.setText(String.valueOf(Codes.ERROR.getCode()));
// retCon.setText(StringUtils.isNotBlank(message)?message: Codes.ERROR.getMessage());
// return document.asXML();
// }
}

@ -0,0 +1,134 @@
package com.manage.utils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.InputStream;
public class XmlUtils {
//定义解析器和文档对象
private SAXReader saxReader;
private Document document;
public XmlUtils(String path) {
//获取解析器
saxReader = new SAXReader();
try {
//获取文档对象
document = saxReader.read(path);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public XmlUtils(InputStream path) {
//获取解析器
saxReader = new SAXReader();
try {
//获取文档对象
document = saxReader.read(path);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
*
* @return
*/
public String getElement(String name) {
//获取根节点
Element root = document.getRootElement();
// Object directory = FileUtils.getJsonByName(Codes.DIRECTORY.getMessage());
// Element current = root;
// if (directory == null) {
// throw new RuntimeException("没有定义目录结构");
// }
// List<String> directoryArr = (List<String>) directory;
// for (String dire : directoryArr) {
// current = current.element(dire);
// }
return root.element(name) == null ? "" : root.element(name).getText();
}
// /**
// * 根据路径动态获取节点
// *
// * @return
// */
// public Element getElement(List<String> directory) {
// //获取根节点
// Element root = document.getRootElement();
//
// Element current = root;
// List<String> directoryArr = directory;
// for (String dire : directoryArr) {
// current = current.element(dire);
// }
// if (current == null) {
// throw new RuntimeException("未找到对应节点");
// }
// return current;
// }
//
// /**
// * 返回存在的根节点
// */
// public List<Element> getJsonByName() {
// //获取目录结构
// String path = FileUtils.currentPath();
// //解析json映射文件
// String json = com.docus.bgts.utils.JsonUtils.readJsonFile(path + Codes.JSON_ADDRESS.getMessage());
// Map jsonMap = JSON.parseObject(json, Map.class);
// //判断是否多条
// List<String> basicArr = (List<String>) jsonMap.get("doubleBasic");
// List<String> directory = (List<String>) jsonMap.get("basicDirectory");
// List<Element> elements = null;
// Element root = this.getElement(directory);
// for (String basic : basicArr) {
// elements = root.elements(basic);
// if (elements != null && elements.size() > 0) {
// break;
// }
// }
// if (elements == null || elements.size() == 0) {
// //只有一条
// List<String> rootDirectory = (List<String>) jsonMap.get("directory");
// root = this.getElement(rootDirectory);
// elements = new ArrayList<>();
// elements.add(root);
// }
// return elements;
// }
//
// /**
// * 根据节点名称获取内容
// *
// * @param name 节点名称
// * @return 节点内容
// */
// public String getElementText(String name) {
// //定位根节点
// Element root = document.getRootElement();
// //根据名称定位节点
// Element msg = root.element(Codes.MSG.getMessage());
// if (msg == null) {
// throw new RuntimeException("没有" + Codes.MSG.getMessage() + "节点");
// }
//// Element patInfo = msg.element(Codes.PAT_INFO.getMessage());
//// if(patInfo==null){
//// throw new RuntimeException("没有"+Codes.PAT_INFO.getMessage()+"节点");
//// }
// Element element = msg.element(name);
// if (element == null) {
// return null;
// }
// //返回节点内容
// return element.getText();
// }
}
Loading…
Cancel
Save