|
@ -0,0 +1,162 @@
|
|
|
package com.yihu.jw.security.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
|
|
|
import com.yihu.jw.entity.ca.OauthCaConfigDO;
|
|
|
import com.yihu.jw.security.dao.OauthCaConfigDao;
|
|
|
import com.yihu.jw.security.dao.doctor.BaseDoctorDao;
|
|
|
import com.yihu.jw.security.dao.doctor.BaseDoctorHospitalDao;
|
|
|
import com.yihu.jw.util.http.HttpClientUtil;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 心脏中心医院
|
|
|
* Created by wangzhinan on 2020/10/20.
|
|
|
*
|
|
|
* @author yeshijie.
|
|
|
*/
|
|
|
@Service
|
|
|
public class XzzxService {
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(XzzxService.class);
|
|
|
@Autowired
|
|
|
private HttpClientUtil httpClientUtil;
|
|
|
@Autowired
|
|
|
private OauthCaConfigDao oauthCaConfigDao;
|
|
|
@Autowired
|
|
|
private BaseDoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private BaseDoctorHospitalDao doctorHospitalDao;
|
|
|
|
|
|
/**
|
|
|
* OAuth登陆-认证请求接口
|
|
|
* @param sys
|
|
|
* @return
|
|
|
*/
|
|
|
public String getQRCode(String sys) {
|
|
|
try {
|
|
|
logger.info("生成二维码 getQRCode :"+sys);
|
|
|
OauthCaConfigDO oauthCaConfigDO = oauthCaConfigDao.findOne("oauth_ca_config");
|
|
|
String url = "";
|
|
|
if (oauthCaConfigDO!=null){
|
|
|
url=oauthCaConfigDO.getUrl()+"/gateway/oauth/authorize?responseType=code&clientId="+sys;
|
|
|
}
|
|
|
String response = httpClientUtil.get(url,"utf-8");
|
|
|
JSONObject rs = new JSONObject();
|
|
|
JSONObject data = new JSONObject();
|
|
|
String res = "";
|
|
|
if (StringUtils.isNotBlank(response)){
|
|
|
JSONObject object = JSONObject.parseObject(response);
|
|
|
String status = object.getString("status");
|
|
|
if (status.equalsIgnoreCase("0")){
|
|
|
JSONObject jsonObject = object.getJSONObject("data");
|
|
|
String imgBase64 = jsonObject.getString("imgBase64");
|
|
|
data.put("resultCode",0);
|
|
|
data.put("resultMsg","Success");
|
|
|
data.put("qrCodeImg",imgBase64);
|
|
|
data.put("qrCode",jsonObject.getString("requestId"));
|
|
|
rs.put("code",1000);
|
|
|
rs.put("msg","成功");
|
|
|
rs.put("data",data);
|
|
|
}else {
|
|
|
rs.put("code",-1);
|
|
|
rs.put("msg",object.getString("message"));
|
|
|
}
|
|
|
}
|
|
|
return rs.toJSONString();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* OAuth登陆-获取用户信息
|
|
|
* @param clientId
|
|
|
* @param requestId
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getTokeninfo(String clientId,String requestId){
|
|
|
try {
|
|
|
OauthCaConfigDO oauthCaConfigDO = oauthCaConfigDao.findOne("oauth_ca_config");
|
|
|
String url = "";
|
|
|
if (oauthCaConfigDO!=null){
|
|
|
url=oauthCaConfigDO.getUrl()+"/gateway/oauth/tokeninfo?clientId="+clientId+"&requestId="+requestId+"";
|
|
|
}
|
|
|
String response = httpClientUtil.get(url,"utf-8");
|
|
|
logger.info("验证二维码 getQueryQRCode :"+response);
|
|
|
return JSONObject.parseObject(response);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
public String synDoctorToCa(String clientId,String requestId,String doctorId){
|
|
|
try {
|
|
|
OauthCaConfigDO oauthCaConfigDO = oauthCaConfigDao.findOne("oauth_ca_config");
|
|
|
String url = "";
|
|
|
if (oauthCaConfigDO!=null){
|
|
|
url=oauthCaConfigDO.getUrl()+"/gateway/doctor/synDoctor";
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(doctorId)){
|
|
|
BaseDoctorDO doctorDO = doctorDao.findById(doctorId);
|
|
|
List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(doctorId);
|
|
|
JSONObject body = new JSONObject();
|
|
|
JSONObject head = new JSONObject();
|
|
|
head.put("clientId","2017070411003376");
|
|
|
head.put("clientSecret","2017070411003360");
|
|
|
body.put("head",head);
|
|
|
JSONObject by= new JSONObject();
|
|
|
by.put("uid",doctorDO.getIdcard());
|
|
|
by.put("uidCardType","SF");
|
|
|
by.put("doctorName",doctorDO.getName());
|
|
|
by.put("phone",doctorDO.getMobile());
|
|
|
if (doctorHospitalDOS!=null&&doctorHospitalDOS.size()!=0){
|
|
|
by.put("department",doctorHospitalDOS.get(0).getOrgName());
|
|
|
by.put("department",doctorHospitalDOS.get(0).getDeptName());
|
|
|
}
|
|
|
body.put("body",by);
|
|
|
String response = httpClientUtil.sendPost(url,body.toJSONString());
|
|
|
logger.info("同步医生信息"+response);
|
|
|
return response;
|
|
|
}else {
|
|
|
List<BaseDoctorDO> doctorDOList = doctorDao.findByDel();
|
|
|
for (BaseDoctorDO doctorDO:doctorDOList){
|
|
|
List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(doctorDO.getId());
|
|
|
JSONObject body = new JSONObject();
|
|
|
JSONObject head = new JSONObject();
|
|
|
head.put("clientId","2017070411003376");
|
|
|
head.put("clientSecret","2017070411003360");
|
|
|
body.put("head",head);
|
|
|
JSONObject by= new JSONObject();
|
|
|
by.put("uid",doctorDO.getIdcard());
|
|
|
by.put("uidCardType","SF");
|
|
|
by.put("doctorName",doctorDO.getName());
|
|
|
by.put("phone",doctorDO.getMobile());
|
|
|
if (doctorHospitalDOS!=null&&doctorHospitalDOS.size()!=0){
|
|
|
by.put("orgName",doctorHospitalDOS.get(0).getOrgName());
|
|
|
by.put("department",doctorHospitalDOS.get(0).getDeptName());
|
|
|
}
|
|
|
body.put("body",by);
|
|
|
String response = httpClientUtil.sendPost(url,body.toJSONString());
|
|
|
logger.info("同步医生信息"+response);
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|