Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
P
pica-cloud-account
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
Close sidebar
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
com.pica.cloud.account
pica-cloud-account
提交
363ddd82
提交
363ddd82
编写于
5月 15, 2020
作者:
Peijun.zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
format code service
上级
9af2b222
流水线
#25406
已失败 于阶段
in 0 second
变更
4
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
344 行增加
和
232 行删除
+344
-232
PatHealthPackController.java
...nt/account/server/controller/PatHealthPackController.java
+10
-232
AccountExceptionEnum.java
...ud/account/account/server/enums/AccountExceptionEnum.java
+5
-0
PatHealthPackService.java
.../account/account/server/service/PatHealthPackService.java
+37
-0
PatHealthPackServiceIml.java
.../account/server/service/impl/PatHealthPackServiceIml.java
+292
-0
未找到文件。
server/src/main/java/com/pica/cloud/account/account/server/controller/PatHealthPackController.java
浏览文件 @
363ddd82
// Copyright 2016-2101 Pica.
// Copyright 2016-2101 Pica.
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
controller
;
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
controller
;
import
com.pica.cloud.account.account.common.req.AcctPatFamilyDto
;
import
com.pica.cloud.account.account.common.req.AcctPatFamilyReq
;
import
com.pica.cloud.account.account.common.req.AcctPatFamilyReq
;
import
com.pica.cloud.account.account.common.req.AcctPatInfoReq
;
import
com.pica.cloud.account.account.common.req.AcctPatInfoReq
;
import
com.pica.cloud.account.account.common.resp.PatBindResp
;
import
com.pica.cloud.account.account.common.resp.PatBindResp
;
import
com.pica.cloud.account.account.common.resp.PatFamilyResp
;
import
com.pica.cloud.account.account.common.resp.PatFamilyResp
;
import
com.pica.cloud.account.account.server.entity.AcctPatFamily
;
import
com.pica.cloud.account.account.server.service.PatHealthPackService
;
import
com.pica.cloud.account.account.server.entity.AcctPatInfo
;
import
com.pica.cloud.account.account.server.entity.AcctPatUnion
;
import
com.pica.cloud.account.account.server.mapper.AcctPatFamilyMapper
;
import
com.pica.cloud.account.account.server.mapper.AcctPatInfoMapper
;
import
com.pica.cloud.account.account.server.mapper.AcctPatUnionMapper
;
import
com.pica.cloud.foundation.encryption.common.constants.EncryptConstants
;
import
com.pica.cloud.foundation.encryption.util.EncryptUtils
;
import
com.pica.cloud.foundation.entity.PicaResponse
;
import
com.pica.cloud.foundation.entity.PicaResponse
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
static
java
.
util
.
stream
.
Collectors
.
toList
;
/**
/**
* @Description TODO
* @Description TODO
...
@@ -43,262 +28,55 @@ import static java.util.stream.Collectors.toList;
...
@@ -43,262 +28,55 @@ import static java.util.stream.Collectors.toList;
public
class
PatHealthPackController
{
public
class
PatHealthPackController
{
@Autowired
@Autowired
private
AcctPatInfoMapper
patInfoMapper
;
private
PatHealthPackService
packService
;
@Autowired
private
AcctPatUnionMapper
patUnionMapper
;
@Autowired
private
AcctPatFamilyMapper
patFamilyMapper
;
@ApiOperation
(
"获取主账户ID-根据unionId"
)
@ApiOperation
(
"获取主账户ID-根据unionId"
)
@GetMapping
(
value
=
"/acctId/unionId/{unionId}"
)
@GetMapping
(
value
=
"/acctId/unionId/{unionId}"
)
public
PicaResponse
<
Integer
>
getAcctIdByUnionId
(
@PathVariable
(
"unionId"
)
String
unionId
)
throws
Exception
{
public
PicaResponse
<
Integer
>
getAcctIdByUnionId
(
@PathVariable
(
"unionId"
)
String
unionId
)
throws
Exception
{
AcctPatUnion
patUnion
=
patUnionMapper
.
selectByUnionId
(
unionId
);
return
PicaResponse
.
toResponse
(
packService
.
getAcctIdByUnionId
(
unionId
));
return
PicaResponse
.
toResponse
(
patUnion
==
null
?
0
:
patUnion
.
getAcctId
());
}
}
@ApiOperation
(
"获取主账户ID-作为监护人自身patientId"
)
@ApiOperation
(
"获取主账户ID-作为监护人自身patientId"
)
@GetMapping
(
value
=
"/acctId/patId/{patientId}"
)
@GetMapping
(
value
=
"/acctId/patId/{patientId}"
)
public
PicaResponse
<
Integer
>
getAcctIdByPatId
(
@PathVariable
(
"patientId"
)
Integer
patientId
)
throws
Exception
{
public
PicaResponse
<
Integer
>
getAcctIdByPatId
(
@PathVariable
(
"patientId"
)
Integer
patientId
)
throws
Exception
{
List
<
AcctPatFamily
>
patFamilyList
=
patFamilyMapper
.
getByPatIdSelf
(
patientId
);
return
PicaResponse
.
toResponse
(
packService
.
getAcctIdByPatId
(
patientId
));
if
(
CollectionUtils
.
isEmpty
(
patFamilyList
))
{
//该居民id无 家庭成员记录,返回0
return
PicaResponse
.
toResponse
(
0
);
}
if
(
patFamilyList
.
size
()
>
1
)
{
//db中数据有异常,log todo 抛异常
return
PicaResponse
.
toResponse
(
patFamilyList
.
get
(
0
).
getAcctId
());
}
return
PicaResponse
.
toResponse
(
patFamilyList
.
get
(
0
).
getAcctId
());
}
}
@ApiOperation
(
"上级的监护人 + 下级所有成员 patientId list"
)
@ApiOperation
(
"上级的监护人 + 下级所有成员 patientId list"
)
@GetMapping
(
value
=
"/directPatIds/{patientId}"
)
@GetMapping
(
value
=
"/directPatIds/{patientId}"
)
public
PicaResponse
<
List
<
Integer
>>
getDirectPatIdsByPatId
(
@PathVariable
(
"patientId"
)
Integer
patientId
)
throws
Exception
{
public
PicaResponse
<
List
<
Integer
>>
getDirectPatIdsByPatId
(
@PathVariable
(
"patientId"
)
Integer
patientId
)
throws
Exception
{
return
PicaResponse
.
toResponse
(
packService
.
getDirectPatIdsByPatId
(
patientId
));
List
<
Integer
>
patIds
=
new
ArrayList
<>();
List
<
AcctPatFamily
>
memberList
=
patFamilyMapper
.
getByPatIdNotSelf
(
patientId
);
if
(
CollectionUtils
.
isEmpty
(
memberList
))
{
//该居民id无 家庭成员记录,返回null
return
PicaResponse
.
toResponse
(
patIds
);
}
if
(
memberList
.
size
()
>
1
)
{
//db中数据有异常,log todo 抛异常
return
PicaResponse
.
toResponse
(
memberList
.
get
(
0
).
getAcctId
());
}
//加入病人id所在家庭组的监护人- 上级
AcctPatFamily
parentMember
=
patFamilyMapper
.
getSelfByAcctId
(
memberList
.
get
(
0
).
getAcctId
());
patIds
.
add
(
parentMember
.
getPatientId
());
//下级所有成员 包括自身
List
<
AcctPatFamily
>
patFamilyList
=
patFamilyMapper
.
getListByAcctId
(
memberList
.
get
(
0
).
getAcctId
());
patIds
.
addAll
(
patFamilyList
.
stream
().
map
(
obj
->
obj
.
getPatientId
()).
collect
(
toList
()));
return
PicaResponse
.
toResponse
(
patIds
);
}
}
@ApiOperation
(
"根据accid获取家庭关系idList"
)
@ApiOperation
(
"根据accid获取家庭关系idList"
)
@GetMapping
(
value
=
"/familyPats/{acctId}"
)
@GetMapping
(
value
=
"/familyPats/{acctId}"
)
public
PicaResponse
<
PatFamilyResp
>
getFamilyPatsByAcctId
(
@PathVariable
(
"acctId"
)
Integer
acctId
)
throws
Exception
{
public
PicaResponse
<
PatFamilyResp
>
getFamilyPatsByAcctId
(
@PathVariable
(
"acctId"
)
Integer
acctId
)
throws
Exception
{
PatFamilyResp
resp
=
new
PatFamilyResp
();
return
PicaResponse
.
toResponse
(
packService
.
getFamilyPatsByAcctId
(
acctId
));
List
<
AcctPatFamily
>
patFamilyList
=
patFamilyMapper
.
getListByAcctId
(
acctId
);
resp
.
setMemberPatIds
(
patFamilyList
.
stream
().
map
(
obj
->
obj
.
getPatientId
()).
collect
(
toList
()));
List
<
AcctPatFamilyDto
>
dtos
=
new
ArrayList
<>();
for
(
AcctPatFamily
family
:
patFamilyList
){
AcctPatFamilyDto
dto
=
new
AcctPatFamilyDto
();
dto
.
setPatientId
(
family
.
getPatientId
());
dto
.
setRelation
(
family
.
getRelation
());
dtos
.
add
(
dto
);
}
resp
.
setFailMemberList
(
dtos
);
return
PicaResponse
.
toResponse
(
resp
);
}
}
@ApiOperation
(
"保存主账户"
)
@ApiOperation
(
"保存主账户"
)
@PostMapping
(
value
=
"/acct"
)
@PostMapping
(
value
=
"/acct"
)
@Transactional
public
PicaResponse
<
Integer
>
saveAcct
(
@RequestBody
AcctPatInfoReq
patInfoReq
)
throws
Exception
{
public
PicaResponse
<
Integer
>
saveAcct
(
@RequestBody
AcctPatInfoReq
patInfoReq
)
throws
Exception
{
return
PicaResponse
.
toResponse
(
packService
.
saveAcct
(
patInfoReq
));
if
(
Objects
.
isNull
(
patInfoReq
.
getPatientId
())
||
patInfoReq
.
getPatientId
()
==
0
||
Objects
.
isNull
(
patInfoReq
.
getName
())
||
Objects
.
isNull
(
patInfoReq
.
getMobile
())
){
//log // TODO: 2020/5/14
return
null
;
}
String
mobileEncrypt
=
EncryptUtils
.
encryptContent
(
patInfoReq
.
getMobile
(),
EncryptConstants
.
ENCRYPT_TYPE_MOBILE
);
//check 手机号是否已是主账户
// AcctPatInfo query = new AcctPatInfo();
// query.setMobilePhone(mobileEncrypt);
// List<AcctPatInfo> acctList = patInfoMapper.selectByCondition(query);
List
<
AcctPatFamily
>
patFamilyList
=
patFamilyMapper
.
getByPatIdSelf
(
patInfoReq
.
getPatientId
());
if
(
CollectionUtils
.
isNotEmpty
(
patFamilyList
))
{
// 重复时返回已有账户
return
PicaResponse
.
toResponse
(
patFamilyList
.
get
(
0
));
}
//手机号无重复时创建
AcctPatInfo
patInfo
=
new
AcctPatInfo
();
patInfo
.
setName
(
patInfoReq
.
getName
());
patInfo
.
setMobilePhone
(
mobileEncrypt
);
patInfo
.
setRegisterProduct
(
1
);
patInfo
.
setRegisterSource
(
1
);
//todo
patInfo
.
setRegTime
(
new
Date
());
patInfo
.
setDeleteFlag
(
1
);
patInfo
.
setCreatedId
(
0
);
//todo 本人
patInfo
.
setModifiedId
(
0
);
patInfo
.
setCreatedTime
(
new
Date
());
patInfo
.
setModifiedTime
(
new
Date
());
patInfoMapper
.
insert
(
patInfo
);
AcctPatFamily
patFamily
=
new
AcctPatFamily
();
patFamily
.
setAcctId
(
patInfo
.
getId
());
patFamily
.
setPatientId
(
patInfoReq
.
getPatientId
());
patFamily
.
setRelation
(
1
);
patFamily
.
setDeleteFlag
(
1
);
patFamily
.
setCreatedId
(
0
);
//todo 本人
patFamily
.
setModifiedId
(
0
);
patFamily
.
setCreatedTime
(
new
Date
());
patFamily
.
setModifiedTime
(
new
Date
());
patFamilyMapper
.
insert
(
patFamily
);
return
PicaResponse
.
toResponse
(
patInfo
.
getId
());
}
}
@ApiOperation
(
"建立微信与账号关联关系"
)
@ApiOperation
(
"建立微信与账号关联关系"
)
@PostMapping
(
value
=
"/acct/bindUnion"
)
@PostMapping
(
value
=
"/acct/bindUnion"
)
public
PicaResponse
<
PatBindResp
>
bindUnion
(
@RequestBody
AcctPatInfoReq
patInfoReq
)
throws
Exception
{
public
PicaResponse
<
PatBindResp
>
bindUnion
(
@RequestBody
AcctPatInfoReq
patInfoReq
)
throws
Exception
{
PatBindResp
resp
=
new
PatBindResp
();
return
PicaResponse
.
toResponse
(
packService
.
bindUnion
(
patInfoReq
));
//unionid是否已被其他账号绑定
AcctPatUnion
patUnion
=
patUnionMapper
.
selectByUnionId
(
patInfoReq
.
getUnionId
());
if
(
Objects
.
nonNull
(
patUnion
))
{
//被绑定
//且非传入acct_d
if
(!
patUnion
.
getAcctId
().
equals
(
patInfoReq
.
getAcctId
()))
{
resp
.
setBindStatus
(
false
);
resp
.
setMsg
(
"该unionid已被其他手机号绑定"
);
}
else
{
//unionId,已被传入acctId绑定,返回 true
resp
.
setBindStatus
(
true
);
}
}
else
{
//acctId是否已绑定其他unionId
patUnion
=
patUnionMapper
.
selectByAcctId
(
patInfoReq
.
getAcctId
());
if
(
Objects
.
nonNull
(
patUnion
))
{
//acctId已有unionId,且不是传入的unionId
if
(!
patUnion
.
getUnionId
().
equals
(
patInfoReq
.
getUnionId
()))
{
resp
.
setBindStatus
(
false
);
resp
.
setMsg
(
"该手机号已绑定其他微信号,请尝试使用其他手机号"
);
}
}
else
{
//未绑定 新增绑定记录
AcctPatUnion
entity
=
new
AcctPatUnion
();
entity
.
setAcctId
(
patInfoReq
.
getAcctId
());
entity
.
setUnionId
(
patInfoReq
.
getUnionId
());
entity
.
setUnionType
(
1
);
entity
.
setDeleteFlag
(
1
);
entity
.
setCreatedId
(
0
);
//todo 本人
entity
.
setModifiedId
(
0
);
entity
.
setCreatedTime
(
new
Date
());
entity
.
setModifiedTime
(
new
Date
());
patUnionMapper
.
insert
(
entity
);
resp
.
setBindStatus
(
true
);
}
}
return
PicaResponse
.
toResponse
(
resp
);
}
}
@ApiOperation
(
"建立家庭服务关系"
)
@ApiOperation
(
"建立家庭服务关系"
)
@PostMapping
(
value
=
"/family/member"
)
@PostMapping
(
value
=
"/family/member"
)
public
PicaResponse
<
PatFamilyResp
>
saveMember
(
@RequestBody
AcctPatFamilyReq
familyReqReq
)
throws
Exception
{
public
PicaResponse
<
PatFamilyResp
>
saveMember
(
@RequestBody
AcctPatFamilyReq
familyReqReq
)
throws
Exception
{
return
PicaResponse
.
toResponse
(
packService
.
saveMember
(
familyReqReq
));
PatFamilyResp
resp
=
new
PatFamilyResp
();
boolean
successFlag
=
true
;
//check member valid
List
<
AcctPatFamilyDto
>
memberList
=
familyReqReq
.
getMemberList
();
for
(
AcctPatFamilyDto
member
:
memberList
){
//null check todo
}
List
<
AcctPatFamilyDto
>
failList
=
new
ArrayList
<>();
List
<
Integer
>
patIds
=
memberList
.
stream
().
map
(
obj
->
obj
.
getPatientId
()).
collect
(
toList
());
List
<
AcctPatFamilyDto
>
relatedPats
=
new
ArrayList
<>();
List
<
AcctPatFamily
>
familyList
=
patFamilyMapper
.
getListByPatIds
(
patIds
);
for
(
AcctPatFamily
member
:
familyList
){
if
(!
familyReqReq
.
getAcctId
().
equals
(
member
.
getAcctId
())){
AcctPatFamilyDto
failOne
=
new
AcctPatFamilyDto
();
failOne
.
setPatientId
(
member
.
getPatientId
());
failOne
.
setRelation
(
member
.
getRelation
());
failList
.
add
(
failOne
);
successFlag
=
false
;
}
else
{
//居民已被传入acctId关联为家庭成员,不需要再保存
AcctPatFamilyDto
failOneRelated
=
new
AcctPatFamilyDto
();
failOneRelated
.
setRelation
(
member
.
getRelation
());
failOneRelated
.
setPatientId
(
member
.
getPatientId
());
relatedPats
.
add
(
failOneRelated
);
}
}
//已关联自身居民list
if
(
relatedPats
.
size
()
>
0
){
successFlag
=
false
;
failList
.
addAll
(
relatedPats
);
}
//通过后 再建立家庭关系
if
(
successFlag
){
for
(
AcctPatFamilyDto
member
:
memberList
){
AcctPatFamily
entity
=
new
AcctPatFamily
();
entity
.
setAcctId
(
familyReqReq
.
getAcctId
());
entity
.
setPatientId
(
member
.
getPatientId
());
entity
.
setRelation
(
member
.
getRelation
());
entity
.
setDeleteFlag
(
1
);
entity
.
setCreatedId
(
familyReqReq
.
getAcctId
());
entity
.
setModifiedId
(
familyReqReq
.
getAcctId
());
entity
.
setCreatedTime
(
new
Date
());
entity
.
setModifiedTime
(
new
Date
());
patFamilyMapper
.
insert
(
entity
);
}
}
resp
.
setSuccessFlag
(
successFlag
);
resp
.
setFailMemberList
(
failList
);
return
PicaResponse
.
toResponse
(
resp
);
}
}
@ApiOperation
(
"根据patientId获取监护人-本人监护人(自身patId),本人成员(监护人patId)"
)
@ApiOperation
(
"根据patientId获取监护人-本人监护人(自身patId),本人成员(监护人patId)"
)
@GetMapping
(
value
=
"/familyAcct/patId/{patId}"
)
@GetMapping
(
value
=
"/familyAcct/patId/{patId}"
)
public
PicaResponse
<
Integer
>
getFamilyAcctPatId
(
@PathVariable
(
"patId"
)
Integer
patId
)
throws
Exception
{
public
PicaResponse
<
Integer
>
getFamilyAcctPatId
(
@PathVariable
(
"patId"
)
Integer
patId
)
throws
Exception
{
Integer
rtnPatId
=
0
;
return
PicaResponse
.
toResponse
(
packService
.
getFamilyAcctPatId
(
patId
));
List
<
AcctPatFamily
>
acctMembers
=
patFamilyMapper
.
getByPatIdSelf
(
patId
);
if
(
CollectionUtils
.
isNotEmpty
(
acctMembers
)){
//本人为监护人 返回自身patId
rtnPatId
=
acctMembers
.
get
(
0
).
getPatientId
();
}
else
{
//查询是否存在 作为成员的记录
List
<
AcctPatFamily
>
members
=
patFamilyMapper
.
getByPatIdNotSelf
(
patId
);
if
(
CollectionUtils
.
isNotEmpty
(
members
)){
//本人为成员时记录存在
AcctPatFamily
acctPat
=
patFamilyMapper
.
getSelfByAcctId
(
members
.
get
(
0
).
getAcctId
());
rtnPatId
=
acctPat
.
getPatientId
();
}
else
{
//传入patId不存在家庭记录
}
}
return
PicaResponse
.
toResponse
(
rtnPatId
);
}
}
...
...
server/src/main/java/com/pica/cloud/account/account/server/enums/AccountExceptionEnum.java
浏览文件 @
363ddd82
...
@@ -57,6 +57,11 @@ public enum AccountExceptionEnum {
...
@@ -57,6 +57,11 @@ public enum AccountExceptionEnum {
PICA_PWD_MISMATCH_5_H5
(
"216549"
,
"该账号密码错误次数已达上限请24小时后再试,或请使用其他登录方式"
),
PICA_PWD_MISMATCH_5_H5
(
"216549"
,
"该账号密码错误次数已达上限请24小时后再试,或请使用其他登录方式"
),
PAT_ACCT_HAS_EXIST
(
"216550"
,
"账号已存在"
),
PAT_ACCT_HAS_EXIST
(
"216550"
,
"账号已存在"
),
PAT_ACCT_HAS_MORE
(
"216551"
,
"主账号存在多条"
),
PAT_MEMBER_HAS_MORE
(
"216552"
,
"成员在多个家庭组存在"
),
PAT_SAVE_PARAM_ERROR
(
"216553"
,
"保存主账户参数错误"
),
PAT_UNIONID_BINDED_ERROR
(
"216554"
,
"该unionid已被其他手机号绑定"
),
PAT_MOBILE_BINDED_WECHAT_ERROR
(
"216555"
,
"该手机已绑定其他微信"
),
xxx_xxx
(
""
,
""
);
xxx_xxx
(
""
,
""
);
...
...
server/src/main/java/com/pica/cloud/account/account/server/service/PatHealthPackService.java
0 → 100644
浏览文件 @
363ddd82
// Copyright 2016-2101 Pica.
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
service
;
import
com.pica.cloud.account.account.common.req.AcctPatFamilyReq
;
import
com.pica.cloud.account.account.common.req.AcctPatInfoReq
;
import
com.pica.cloud.account.account.common.resp.PatBindResp
;
import
com.pica.cloud.account.account.common.resp.PatFamilyResp
;
import
java.util.List
;
/**
* @ClassName PatHealthPackService
* @Description TODO
* @Author peijun.zhao
* @Date 2020/5/14 18:30
* @ModifyDate 2020/5/14 18:30
* @Version 1.0
*/
public
interface
PatHealthPackService
{
Integer
getAcctIdByUnionId
(
String
unionId
);
Integer
getAcctIdByPatId
(
Integer
patientId
);
List
<
Integer
>
getDirectPatIdsByPatId
(
Integer
patientId
);
PatFamilyResp
getFamilyPatsByAcctId
(
Integer
acctId
);
Integer
saveAcct
(
AcctPatInfoReq
patInfoReq
);
PatBindResp
bindUnion
(
AcctPatInfoReq
patInfoReq
);
PatFamilyResp
saveMember
(
AcctPatFamilyReq
familyReqReq
);
Integer
getFamilyAcctPatId
(
Integer
patId
);
}
server/src/main/java/com/pica/cloud/account/account/server/service/impl/PatHealthPackServiceIml.java
0 → 100644
浏览文件 @
363ddd82
// Copyright 2016-2101 Pica.
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
service
.
impl
;
import
com.pica.cloud.account.account.common.req.AcctPatFamilyDto
;
import
com.pica.cloud.account.account.common.req.AcctPatFamilyReq
;
import
com.pica.cloud.account.account.common.req.AcctPatInfoReq
;
import
com.pica.cloud.account.account.common.resp.PatBindResp
;
import
com.pica.cloud.account.account.common.resp.PatFamilyResp
;
import
com.pica.cloud.account.account.server.entity.AcctPatFamily
;
import
com.pica.cloud.account.account.server.entity.AcctPatInfo
;
import
com.pica.cloud.account.account.server.entity.AcctPatUnion
;
import
com.pica.cloud.account.account.server.enums.AccountExceptionEnum
;
import
com.pica.cloud.account.account.server.mapper.AcctPatFamilyMapper
;
import
com.pica.cloud.account.account.server.mapper.AcctPatInfoMapper
;
import
com.pica.cloud.account.account.server.mapper.AcctPatUnionMapper
;
import
com.pica.cloud.account.account.server.service.PatHealthPackService
;
import
com.pica.cloud.foundation.encryption.common.constants.EncryptConstants
;
import
com.pica.cloud.foundation.encryption.util.EncryptUtils
;
import
com.pica.cloud.foundation.entity.PicaException
;
import
com.pica.cloud.foundation.entity.PicaResponse
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Objects
;
import
static
java
.
util
.
stream
.
Collectors
.
toList
;
/**
* @ClassName PatHealthPackServiceIml
* @Description TODO
* @Author peijun.zhao
* @Date 2020/5/14 18:30
* @ModifyDate 2020/5/14 18:30
* @Version 1.0
*/
@Service
public
class
PatHealthPackServiceIml
implements
PatHealthPackService
{
@Autowired
private
AcctPatInfoMapper
patInfoMapper
;
@Autowired
private
AcctPatUnionMapper
patUnionMapper
;
@Autowired
private
AcctPatFamilyMapper
patFamilyMapper
;
@Override
public
Integer
getAcctIdByUnionId
(
String
unionId
)
{
AcctPatUnion
patUnion
=
patUnionMapper
.
selectByUnionId
(
unionId
);
return
patUnion
==
null
?
0
:
patUnion
.
getAcctId
();
}
/**
* @Description 获取居民id是本人的家庭组记录-
* 作为家庭主账户、本人居民id,单条ok 多条异常数据
* @Author peijun.zhao
* @Date 2020/5/14 18:48
* @ModifyDate 2020/5/14 18:48
* @Params [patientId]
* @Return java.lang.Integer
*/
@Override
public
Integer
getAcctIdByPatId
(
Integer
patientId
)
{
List
<
AcctPatFamily
>
patFamilyList
=
patFamilyMapper
.
getByPatIdSelf
(
patientId
);
if
(
CollectionUtils
.
isEmpty
(
patFamilyList
))
{
//该居民id无 家庭成员记录,返回0
return
0
;
}
if
(
patFamilyList
.
size
()
>
1
)
{
//db中数据有异常,log 异常
throw
new
PicaException
(
AccountExceptionEnum
.
PAT_ACCT_HAS_MORE
.
getCode
(),
AccountExceptionEnum
.
PAT_ACCT_HAS_MORE
.
getMessage
());
}
return
patFamilyList
.
get
(
0
).
getAcctId
();
}
@Override
public
List
<
Integer
>
getDirectPatIdsByPatId
(
Integer
patientId
)
{
List
<
Integer
>
patIds
=
new
ArrayList
<>();
List
<
AcctPatFamily
>
memberList
=
patFamilyMapper
.
getByPatIdNotSelf
(
patientId
);
if
(
CollectionUtils
.
isEmpty
(
memberList
))
{
//该居民id无 家庭成员记录,返回null
return
patIds
;
}
if
(
memberList
.
size
()
>
1
)
{
//db中数据有异常,log 抛异常
throw
new
PicaException
(
AccountExceptionEnum
.
PAT_MEMBER_HAS_MORE
.
getCode
(),
AccountExceptionEnum
.
PAT_MEMBER_HAS_MORE
.
getMessage
());
}
//add 病人id所在家庭组的监护人- 上级
AcctPatFamily
parentMember
=
patFamilyMapper
.
getSelfByAcctId
(
memberList
.
get
(
0
).
getAcctId
());
patIds
.
add
(
parentMember
.
getPatientId
());
//下级所有成员 包括自身
List
<
AcctPatFamily
>
patFamilyList
=
patFamilyMapper
.
getListByAcctId
(
memberList
.
get
(
0
).
getAcctId
());
patIds
.
addAll
(
patFamilyList
.
stream
().
map
(
obj
->
obj
.
getPatientId
()).
collect
(
toList
()));
return
patIds
;
}
@Override
public
PatFamilyResp
getFamilyPatsByAcctId
(
Integer
acctId
)
{
PatFamilyResp
resp
=
new
PatFamilyResp
();
List
<
AcctPatFamily
>
patFamilyList
=
patFamilyMapper
.
getListByAcctId
(
acctId
);
resp
.
setMemberPatIds
(
patFamilyList
.
stream
().
map
(
obj
->
obj
.
getPatientId
()).
collect
(
toList
()));
List
<
AcctPatFamilyDto
>
dtos
=
new
ArrayList
<>();
for
(
AcctPatFamily
family
:
patFamilyList
){
AcctPatFamilyDto
dto
=
new
AcctPatFamilyDto
();
dto
.
setPatientId
(
family
.
getPatientId
());
dto
.
setRelation
(
family
.
getRelation
());
dtos
.
add
(
dto
);
}
resp
.
setFailMemberList
(
dtos
);
return
resp
;
}
@Transactional
@Override
public
Integer
saveAcct
(
AcctPatInfoReq
patInfoReq
)
{
if
(
Objects
.
isNull
(
patInfoReq
.
getPatientId
())
||
patInfoReq
.
getPatientId
()
==
0
||
Objects
.
isNull
(
patInfoReq
.
getName
())
||
Objects
.
isNull
(
patInfoReq
.
getMobile
())
){
throw
new
PicaException
(
AccountExceptionEnum
.
PAT_SAVE_PARAM_ERROR
.
getCode
(),
AccountExceptionEnum
.
PAT_SAVE_PARAM_ERROR
.
getMessage
());
}
String
mobileEncrypt
=
EncryptUtils
.
encryptContent
(
patInfoReq
.
getMobile
(),
EncryptConstants
.
ENCRYPT_TYPE_MOBILE
);
//check 手机号是否已是主账户
List
<
AcctPatFamily
>
patFamilyList
=
patFamilyMapper
.
getByPatIdSelf
(
patInfoReq
.
getPatientId
());
if
(
CollectionUtils
.
isNotEmpty
(
patFamilyList
))
{
// 重复时返回已有账户
return
patFamilyList
.
get
(
0
).
getAcctId
();
}
//手机号无重复时创建
AcctPatInfo
patInfo
=
new
AcctPatInfo
();
patInfo
.
setName
(
patInfoReq
.
getName
());
patInfo
.
setMobilePhone
(
mobileEncrypt
);
patInfo
.
setRegisterProduct
(
1
);
patInfo
.
setRegisterSource
(
1
);
patInfo
.
setRegTime
(
new
Date
());
patInfo
.
setDeleteFlag
(
1
);
patInfo
.
setCreatedId
(
0
);
patInfo
.
setModifiedId
(
0
);
patInfo
.
setCreatedTime
(
new
Date
());
patInfo
.
setModifiedTime
(
new
Date
());
patInfoMapper
.
insert
(
patInfo
);
AcctPatFamily
patFamily
=
new
AcctPatFamily
();
patFamily
.
setAcctId
(
patInfo
.
getId
());
patFamily
.
setPatientId
(
patInfoReq
.
getPatientId
());
patFamily
.
setRelation
(
1
);
patFamily
.
setDeleteFlag
(
1
);
patFamily
.
setCreatedId
(
0
);
patFamily
.
setModifiedId
(
0
);
patFamily
.
setCreatedTime
(
new
Date
());
patFamily
.
setModifiedTime
(
new
Date
());
patFamilyMapper
.
insert
(
patFamily
);
return
patInfo
.
getId
();
}
@Transactional
@Override
public
PatBindResp
bindUnion
(
AcctPatInfoReq
patInfoReq
)
{
PatBindResp
resp
=
new
PatBindResp
();
//unionid是否已被其他账号绑定
AcctPatUnion
patUnion
=
patUnionMapper
.
selectByUnionId
(
patInfoReq
.
getUnionId
());
if
(
Objects
.
nonNull
(
patUnion
))
{
//被绑定
//且非传入acct_d
if
(!
patUnion
.
getAcctId
().
equals
(
patInfoReq
.
getAcctId
()))
{
resp
.
setBindStatus
(
false
);
resp
.
setMsg
(
AccountExceptionEnum
.
PAT_UNIONID_BINDED_ERROR
.
getMessage
());
}
else
{
//unionId,已被传入acctId绑定,返回 true
resp
.
setBindStatus
(
true
);
}
}
else
{
//acctId是否已绑定其他unionId
patUnion
=
patUnionMapper
.
selectByAcctId
(
patInfoReq
.
getAcctId
());
if
(
Objects
.
nonNull
(
patUnion
))
{
//acctId已有unionId,且不是传入的unionId
if
(!
patUnion
.
getUnionId
().
equals
(
patInfoReq
.
getUnionId
()))
{
resp
.
setBindStatus
(
false
);
resp
.
setMsg
(
AccountExceptionEnum
.
PAT_MOBILE_BINDED_WECHAT_ERROR
.
getMessage
());
}
}
else
{
//未绑定 新增绑定记录
AcctPatUnion
entity
=
new
AcctPatUnion
();
entity
.
setAcctId
(
patInfoReq
.
getAcctId
());
entity
.
setUnionId
(
patInfoReq
.
getUnionId
());
entity
.
setUnionType
(
1
);
entity
.
setDeleteFlag
(
1
);
entity
.
setCreatedId
(
patInfoReq
.
getAcctId
());
entity
.
setModifiedId
(
patInfoReq
.
getAcctId
());
entity
.
setCreatedTime
(
new
Date
());
entity
.
setModifiedTime
(
new
Date
());
patUnionMapper
.
insert
(
entity
);
resp
.
setBindStatus
(
true
);
}
}
return
resp
;
}
@Transactional
@Override
public
PatFamilyResp
saveMember
(
AcctPatFamilyReq
familyReqReq
)
{
PatFamilyResp
resp
=
new
PatFamilyResp
();
boolean
successFlag
=
true
;
//check member valid
List
<
AcctPatFamilyDto
>
memberList
=
familyReqReq
.
getMemberList
();
List
<
AcctPatFamilyDto
>
failList
=
new
ArrayList
<>();
List
<
Integer
>
patIds
=
memberList
.
stream
().
map
(
obj
->
obj
.
getPatientId
()).
collect
(
toList
());
List
<
AcctPatFamilyDto
>
relatedPats
=
new
ArrayList
<>();
List
<
AcctPatFamily
>
familyList
=
patFamilyMapper
.
getListByPatIds
(
patIds
);
for
(
AcctPatFamily
member
:
familyList
){
if
(!
familyReqReq
.
getAcctId
().
equals
(
member
.
getAcctId
())){
//居民已被其他账户绑定为家庭成员
AcctPatFamilyDto
failOne
=
new
AcctPatFamilyDto
();
failOne
.
setPatientId
(
member
.
getPatientId
());
failOne
.
setRelation
(
member
.
getRelation
());
failList
.
add
(
failOne
);
successFlag
=
false
;
}
else
{
//居民已被传入acctId关联为家庭成员,不需要再保存
AcctPatFamilyDto
failOneRelated
=
new
AcctPatFamilyDto
();
failOneRelated
.
setRelation
(
member
.
getRelation
());
failOneRelated
.
setPatientId
(
member
.
getPatientId
());
relatedPats
.
add
(
failOneRelated
);
successFlag
=
false
;
}
}
//已关联自身居民list
if
(
relatedPats
.
size
()
>
0
){
successFlag
=
false
;
failList
.
addAll
(
relatedPats
);
}
//通过后 再建立家庭关系
if
(
successFlag
){
for
(
AcctPatFamilyDto
member
:
memberList
){
AcctPatFamily
entity
=
new
AcctPatFamily
();
entity
.
setAcctId
(
familyReqReq
.
getAcctId
());
entity
.
setPatientId
(
member
.
getPatientId
());
entity
.
setRelation
(
member
.
getRelation
());
entity
.
setDeleteFlag
(
1
);
entity
.
setCreatedId
(
familyReqReq
.
getAcctId
());
entity
.
setModifiedId
(
familyReqReq
.
getAcctId
());
entity
.
setCreatedTime
(
new
Date
());
entity
.
setModifiedTime
(
new
Date
());
patFamilyMapper
.
insert
(
entity
);
}
}
resp
.
setSuccessFlag
(
successFlag
);
resp
.
setFailMemberList
(
failList
);
return
resp
;
}
@Override
public
Integer
getFamilyAcctPatId
(
Integer
patId
)
{
Integer
rtnPatId
=
0
;
List
<
AcctPatFamily
>
acctMembers
=
patFamilyMapper
.
getByPatIdSelf
(
patId
);
if
(
CollectionUtils
.
isNotEmpty
(
acctMembers
)){
//本人为监护人 返回自身patId
rtnPatId
=
acctMembers
.
get
(
0
).
getPatientId
();
}
else
{
//查询是否存在 作为成员的记录
List
<
AcctPatFamily
>
members
=
patFamilyMapper
.
getByPatIdNotSelf
(
patId
);
if
(
CollectionUtils
.
isNotEmpty
(
members
)){
//本人为成员时记录存在
AcctPatFamily
acctPat
=
patFamilyMapper
.
getSelfByAcctId
(
members
.
get
(
0
).
getAcctId
());
rtnPatId
=
acctPat
.
getPatientId
();
}
else
{
//传入patId不存在家庭记录
}
}
return
rtnPatId
;
}
}
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录