Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jiwei-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
马天浩
jiwei-api
Commits
ba1dc654
Commit
ba1dc654
authored
Oct 12, 2021
by
matianhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[卫健接口] <feat> 接口接入:门诊信息和住院信息
parent
90f1d102
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
206 additions
and
0 deletions
+206
-0
Constants.java
src/main/java/com/mth/requestsecret/constant/Constants.java
+15
-0
HealthRecordController.java
.../mth/requestsecret/controller/HealthRecordController.java
+51
-0
RestTemplateService.java
...va/com/mth/requestsecret/service/RestTemplateService.java
+110
-0
ZyDetailVO.java
...main/java/com/mth/requestsecret/vo/health/ZyDetailVO.java
+30
-0
No files found.
src/main/java/com/mth/requestsecret/constant/Constants.java
View file @
ba1dc654
...
...
@@ -20,6 +20,14 @@ public class Constants {
* 招必得接口
*/
public
static
final
String
ZBD_REQUEST_SECRET_PREFIX
=
"zbd.request.secret"
;
/**
* 卫健申请码
*/
public
static
final
String
HEALTH_SQM
=
"health.sqm"
;
/**
* 申请码存入redis时间
*/
public
static
final
String
HEALTH_SQM_CURRENT_TIME
=
"health.sqm.current.time"
;
// 数据局接口返回响应码
...
...
@@ -39,4 +47,11 @@ public class Constants {
* redis分布式锁的key
*/
public
static
final
String
SJJ_DISTRIBUTED_LOCK
=
"sjj.distributed.lock"
;
// 错误信息
//-----------------------------------
/**
* 卫健申请码错误
*/
public
static
final
String
ERROR_MSG_HEALTH_SQM
=
"权限码错误"
;
}
src/main/java/com/mth/requestsecret/controller/HealthRecordController.java
0 → 100644
View file @
ba1dc654
package
com
.
mth
.
requestsecret
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mth.requestsecret.service.RestTemplateService
;
import
com.mth.requestsecret.vo.health.ZyDetailVO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* 健康档案接口控制器
*
* @author MaTianHao
* @date 2021/10/11
*/
@RestController
public
class
HealthRecordController
{
@Autowired
private
RestTemplateService
restTemplateService
;
/**
* 住院详情
*/
@PostMapping
(
"zydetail"
)
public
ResponseEntity
<
String
>
zydetail
(
ZyDetailVO
param
)
{
String
apiMethod
=
"zydetail"
;
JSONObject
jsonParam
=
new
JSONObject
();
jsonParam
.
put
(
"startDate"
,
param
.
getStartDate
());
jsonParam
.
put
(
"endDate"
,
param
.
getEndDate
());
jsonParam
.
put
(
"idcard"
,
param
.
getIdcard
());
return
restTemplateService
.
healthRecordSendRequest
(
jsonParam
,
apiMethod
);
}
/**
* 门诊详情
*/
@PostMapping
(
"mzdetail"
)
public
ResponseEntity
<
String
>
mzdetail
(
ZyDetailVO
param
)
{
String
apiMethod
=
"mzdetail"
;
JSONObject
jsonParam
=
new
JSONObject
();
jsonParam
.
put
(
"startDate"
,
param
.
getStartDate
());
jsonParam
.
put
(
"endDate"
,
param
.
getEndDate
());
jsonParam
.
put
(
"idcard"
,
param
.
getIdcard
());
return
restTemplateService
.
healthRecordSendRequest
(
jsonParam
,
apiMethod
);
}
}
src/main/java/com/mth/requestsecret/service/RestTemplateService.java
View file @
ba1dc654
...
...
@@ -3,8 +3,10 @@ package com.mth.requestsecret.service;
import
com.alibaba.fastjson.JSONObject
;
import
com.mth.requestsecret.scheduler.RequestSecretSchedulerTask
;
import
com.mth.requestsecret.util.*
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringEscapeUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.*
;
...
...
@@ -85,6 +87,16 @@ public class RestTemplateService {
@Value
(
"${hongcheng.priviteKey}"
)
private
String
hongchengPriviteKey
;
/**
* 卫健相关
*/
@Value
(
"${health.address}"
)
private
String
healthAddress
;
@Value
(
"${health.ipip}"
)
private
String
healthSqmIp
;
@Value
(
"${health.yhm}"
)
private
String
healthSqmYhm
;
/**
* 瑞成平台接口发送请求
*
...
...
@@ -452,4 +464,102 @@ public class RestTemplateService {
return
responseEntity
;
}
/**
* 卫健 发送请求
*
* @param jsonParam
* @param apiMethod
* @return
*/
public
ResponseEntity
<
String
>
healthRecordSendRequest
(
JSONObject
jsonParam
,
String
apiMethod
)
{
// 请求地址
String
url
=
healthAddress
+
apiMethod
;
// 获取授权码
String
sqm
=
getHealthSqm
(
false
);
jsonParam
.
put
(
"sqm"
,
sqm
);
// 构建请求体
String
paramStr
=
jsonParam
.
toJSONString
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
<>(
paramStr
,
headers
);
log
.
info
(
"卫健api:{}"
,
apiMethod
);
log
.
info
(
"api url:{}"
,
url
);
log
.
info
(
"api params:{}"
,
jsonParam
);
// 发送请求
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
log
.
info
(
"api response:{}"
,
responseEntity
);
// 如果返回权限码错误,则重新请求一次
String
msg
=
JSONObject
.
parseObject
(
responseEntity
.
getBody
()).
getString
(
"msg"
);
if
(
ERROR_MSG_HEALTH_SQM
.
equals
(
msg
))
{
// 重新获取权限码
String
healthSqm
=
getHealthSqm
(
true
);
jsonParam
.
put
(
"sqm"
,
healthSqm
);
String
paramStr1
=
jsonParam
.
toJSONString
();
HttpEntity
<
String
>
httpEntity1
=
new
HttpEntity
<>(
paramStr1
,
headers
);
// 重新发送请求
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity1
,
String
.
class
);
log
.
info
(
"{} 重新请求 api params:{}"
,
apiMethod
,
jsonParam
);
log
.
info
(
"{} 重新请求 api response:{}"
,
apiMethod
,
responseEntity
);
return
responseEntity
;
}
return
responseEntity
;
}
/**
* 获取权限申请码
*
* @param forceRefreshFlag 是否强制刷新申请码,true强制刷新
* @return
*/
@SneakyThrows
private
String
getHealthSqm
(
boolean
forceRefreshFlag
)
{
String
redisSqm
=
redisUtil
.
get
(
HEALTH_SQM
);
String
redisSqmCurrentTime
=
redisUtil
.
get
(
HEALTH_SQM_CURRENT_TIME
);
boolean
refreshTimeFalg
=
StringUtils
.
isNotBlank
(
redisSqmCurrentTime
)
&&
System
.
currentTimeMillis
()
-
Long
.
parseLong
(
redisSqmCurrentTime
)
<
10
*
1000L
;
// 不强制刷新:redis存在直接返回,不存在请求后返回
if
(!
forceRefreshFlag
&&
StringUtils
.
isNotBlank
(
redisSqm
))
{
return
redisSqm
;
}
// 强制刷新:10s内获取过不再请求,否则重新请求
if
(
forceRefreshFlag
&&
refreshTimeFalg
)
{
return
redisSqm
;
}
// 请求地址
String
url
=
healthAddress
+
"organVerify"
;
// 构建请求头
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"ipip"
,
healthSqmIp
);
jsonObject
.
put
(
"yhm"
,
healthSqmYhm
);
String
jsonString
=
jsonObject
.
toJSONString
();
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
<>(
jsonString
,
headers
);
log
.
info
(
"卫健api:获取申请码"
);
log
.
info
(
"api url:{}"
,
url
);
// 发送请求
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
log
.
info
(
"api response:{}"
,
responseEntity
);
// 接口返回,存入redis
String
sqm
=
JSONObject
.
parseObject
(
responseEntity
.
getBody
()).
getString
(
"msg"
);
redisUtil
.
set
(
HEALTH_SQM
,
sqm
);
redisUtil
.
set
(
HEALTH_SQM_CURRENT_TIME
,
String
.
valueOf
(
System
.
currentTimeMillis
()));
// 等待1s,否则使用新的权限码也无法获得数据
Thread
.
sleep
(
1000
);
return
sqm
;
}
}
\ No newline at end of file
src/main/java/com/mth/requestsecret/vo/health/ZyDetailVO.java
0 → 100644
View file @
ba1dc654
package
com
.
mth
.
requestsecret
.
vo
.
health
;
import
lombok.Data
;
/**
* 住院详情、门诊详情vo
* @author MaTianHao
* @date 2021/10/11
*/
@Data
public
class
ZyDetailVO
{
/**
* 开始日期
*/
private
String
startDate
;
/**
* 结束日期
*/
private
String
endDate
;
/**
* 权限申请码
*/
private
String
sqm
;
/**
* 身份证号码,多个以“;”区分
*/
private
String
idcard
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment