Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
聂康
local-rnr-enterprise
Commits
c997214d
Commit
c997214d
authored
Jun 17, 2025
by
kang.nie@inzymeits.com
Browse files
初始化代码
parent
741c2feb
Pipeline
#3107
failed with stages
in 0 seconds
Changes
265
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/AuthServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.constants.AuthConstant
;
import
com.cusc.nirvana.user.auth.authentication.plug.util.ThreadLocalUtil
;
import
com.cusc.nirvana.user.auth.client.CaptchaClient
;
import
com.cusc.nirvana.user.auth.client.LoginClient
;
import
com.cusc.nirvana.user.auth.client.RandomIdClient
;
import
com.cusc.nirvana.user.auth.common.constants.CaptchaTypeEnum
;
import
com.cusc.nirvana.user.auth.identification.dto.CaptchaCreateReq
;
import
com.cusc.nirvana.user.auth.identification.dto.CaptchaCreateResp
;
import
com.cusc.nirvana.user.auth.identification.dto.CaptchaVerificationReq
;
import
com.cusc.nirvana.user.auth.identification.dto.MobileLoginReq
;
import
com.cusc.nirvana.user.auth.identification.dto.Oauth2Token
;
import
com.cusc.nirvana.user.auth.identification.dto.RandomIdReq
;
import
com.cusc.nirvana.user.auth.identification.dto.RandomIdResp
;
import
com.cusc.nirvana.user.auth.identification.dto.SmsSendConfig
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.config.EnterpriseConfig
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.EnterpriseLoginSourceEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.ResponseCode
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.CaptchaResponseDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.LoginRequestDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.LoginResponseDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.LoginSmsRequestDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.LoginUserNameReqDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IAuthService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IUserService
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
/**
* @author stayAnd
* @date 2022/4/12
*/
@Service
@Slf4j
public
class
AuthServiceImpl
implements
IAuthService
{
@Resource
private
CaptchaClient
captchaClient
;
@Resource
private
LoginClient
loginClient
;
@Resource
private
IUserService
userService
;
@Resource
private
RandomIdClient
randomIdClient
;
@Resource
private
EnterpriseConfig
enterpriseConfig
;
@Override
public
CaptchaResponseDTO
getGraphic
(
String
platformSource
)
{
CaptchaCreateReq
req
=
new
CaptchaCreateReq
();
req
.
setApplicationId
(
EnterpriseLoginSourceEnum
.
WEB
.
getAppId
());
req
.
setCaptchaHeight
(
40
);
req
.
setCaptchaWidth
(
90
);
req
.
setCaptchaType
(
CaptchaTypeEnum
.
TYPE_DEFAULT
);
req
.
setCaptchaLength
(
4
);
Response
<
CaptchaCreateResp
>
response
=
captchaClient
.
simpleGraphic
(
req
);
if
(
null
==
response
||
!
response
.
isSuccess
()
||
null
==
response
.
getData
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
CaptchaCreateResp
data
=
response
.
getData
();
return
new
CaptchaResponseDTO
().
setCaptchaImg
(
data
.
getCaptchaImg
()).
setRequestId
(
data
.
getRequestId
());
}
@Override
public
void
getSms
(
LoginSmsRequestDTO
dto
)
{
dto
.
setTenantNo
(
enterpriseConfig
.
getTenantNo
());
MobileLoginReq
mobileLoginReq
=
new
MobileLoginReq
();
BeanUtils
.
copyProperties
(
dto
,
mobileLoginReq
);
mobileLoginReq
.
setApplicationId
(
EnterpriseLoginSourceEnum
.
WEB
.
getAppId
());
mobileLoginReq
.
setCaptchaExpire
(
1800
);
mobileLoginReq
.
setCheckCaptchaImg
(
true
);
SmsSendConfig
config
=
new
SmsSendConfig
();
config
.
setStrategyCode
(
"verification_code_sync_strategy"
);
config
.
setSmsTemplateCode
(
"verification_code_template_code"
);
mobileLoginReq
.
setSmsSendConfig
(
config
);
log
.
info
(
"getSms request = {}"
,
JSONObject
.
toJSONString
(
mobileLoginReq
));
Response
response
=
loginClient
.
sendSmsCaptcha
(
mobileLoginReq
);
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
}
@Override
public
LoginResponseDTO
login
(
LoginRequestDTO
loginRequestDTO
)
{
loginRequestDTO
.
setTenantNo
(
enterpriseConfig
.
getTenantNo
());
MobileLoginReq
req
=
new
MobileLoginReq
();
req
.
setApplicationId
(
EnterpriseLoginSourceEnum
.
WEB
.
getAppId
());
req
.
setTenantNo
(
enterpriseConfig
.
getTenantNo
());
req
.
setPhone
(
loginRequestDTO
.
getPhone
());
req
.
setCaptcha
(
loginRequestDTO
.
getSms
());
log
.
info
(
"login req = {}"
,
JSONObject
.
toJSONString
(
req
));
Response
<
Oauth2Token
>
response
=
loginClient
.
mobileLogin
(
req
);
if
(
null
==
response
)
{
throw
new
CuscUserException
(
""
,
"登录系统异常"
);
}
if
(!
response
.
isSuccess
()){
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
if
(
null
==
response
.
getData
()){
throw
new
CuscUserException
(
""
,
"登录失败"
);
}
Oauth2Token
data
=
response
.
getData
();
String
organId
=
userService
.
getOrganId
(
data
.
getInfo
().
getUserId
(),
enterpriseConfig
.
getTenantNo
());
ThreadLocalUtil
.
set
(
AuthConstant
.
USER_ID_NAME
,
data
.
getInfo
().
getUserId
());
ThreadLocalUtil
.
set
(
AuthConstant
.
TENANT_NO_NAME
,
loginRequestDTO
.
getTenantNo
());
ThreadLocalUtil
.
set
(
AuthConstant
.
ORGAN_ID_NAME
,
organId
);
return
new
LoginResponseDTO
().
setAccessToken
(
data
.
getAccess_token
())
.
setRefreshToken
(
data
.
getRefresh_token
())
.
setExpiresIn
(
data
.
getExpires_in
())
.
setLoginName
(
data
.
getInfo
().
getLoginName
())
.
setNickName
(
data
.
getInfo
().
getNickName
())
.
setUserId
(
data
.
getInfo
().
getUserId
())
.
setOrganId
(
organId
)
.
setOrganName
(
userService
.
getOrganName
(
organId
,
enterpriseConfig
.
getTenantNo
()));
}
/**
* 获取随机请求id-登录密码加密
*
* @return
*/
@Override
public
Response
<
RandomIdResp
>
getLoginSecretKey
(
String
platformSource
)
{
RandomIdReq
randomIdReq
=
new
RandomIdReq
();
randomIdReq
.
setApplicationId
(
EnterpriseLoginSourceEnum
.
WEB
.
getAppId
());
return
randomIdClient
.
getRequestIdByLogin
(
randomIdReq
);
}
/**
* 登录-用户名+密码登录
*
* @param bean
* @return
*/
@Override
public
LoginResponseDTO
userNameLogin
(
LoginUserNameReqDTO
bean
)
{
bean
.
setTenantNo
(
enterpriseConfig
.
getTenantNo
());
if
(
CuscStringUtils
.
isNotEmpty
(
bean
.
getCaptchaCode
())
&&
CuscStringUtils
.
isNotEmpty
(
bean
.
getCaptchaId
())){
//验证图形验证码
CaptchaVerificationReq
verificationReq
=
new
CaptchaVerificationReq
();
verificationReq
.
setTenantNo
(
enterpriseConfig
.
getTenantNo
());
verificationReq
.
setApplicationId
(
EnterpriseLoginSourceEnum
.
WEB
.
getAppId
());
verificationReq
.
setCaptchaValue
(
bean
.
getCaptchaCode
());
verificationReq
.
setRequestId
(
bean
.
getCaptchaId
());
Response
<
Boolean
>
captchaResp
=
captchaClient
.
verificationCaptcha
(
verificationReq
);
if
(!
captchaResp
.
isSuccess
()
||
!
captchaResp
.
getData
()){
throw
new
CuscUserException
(
ResponseCode
.
CAPTCHA_IMAGE_CODE_ERROR
.
getCode
(),
ResponseCode
.
CAPTCHA_IMAGE_CODE_ERROR
.
getMsg
());
}
}
bean
.
setApplicationId
(
EnterpriseLoginSourceEnum
.
WEB
.
getAppId
());
log
.
info
(
"login userName req = {}"
,
JSONObject
.
toJSONString
(
bean
));
Response
<
Oauth2Token
>
response
=
loginClient
.
userNameLogin
(
bean
);
if
(
null
==
response
)
{
throw
new
CuscUserException
(
ResponseCode
.
USER_NAME_PASSWORD_ERROR
.
getCode
(),
ResponseCode
.
USER_NAME_PASSWORD_ERROR
.
getMsg
());
}
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
Oauth2Token
data
=
response
.
getData
();
String
organId
=
userService
.
getOrganId
(
data
.
getInfo
().
getUserId
(),
enterpriseConfig
.
getTenantNo
());
ThreadLocalUtil
.
set
(
AuthConstant
.
USER_ID_NAME
,
data
.
getInfo
().
getUserId
());
ThreadLocalUtil
.
set
(
AuthConstant
.
TENANT_NO_NAME
,
bean
.
getTenantNo
());
ThreadLocalUtil
.
set
(
AuthConstant
.
ORGAN_ID_NAME
,
organId
);
return
new
LoginResponseDTO
().
setAccessToken
(
data
.
getAccess_token
())
.
setRefreshToken
(
data
.
getRefresh_token
())
.
setExpiresIn
(
data
.
getExpires_in
())
.
setLoginName
(
data
.
getInfo
().
getLoginName
())
.
setNickName
(
data
.
getInfo
().
getNickName
())
.
setUserId
(
data
.
getInfo
().
getUserId
())
.
setOrganId
(
organId
)
.
setOrganName
(
userService
.
getOrganName
(
organId
,
enterpriseConfig
.
getTenantNo
()));
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/BaseConfigServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.enterprise.common.CompanyTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.common.IndustryTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.DicDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IBaseConfigService
;
import
com.cusc.nirvana.user.rnr.fp.constants.LivenessActionSeqEnum
;
import
com.cusc.nirvana.user.rnr.fp.constants.LivenessTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum
;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
@Service
public
class
BaseConfigServiceImpl
implements
IBaseConfigService
{
private
static
final
Set
<
String
>
PERSON_CERTTYPE_CODE_SET
=
new
HashSet
<
String
>();
private
static
final
Set
<
String
>
COMPANY_CERTTYPE_CODE_SET
=
new
HashSet
<>();
static
{
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
IDCARD
.
getCode
());
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
HKIDCARD
.
getCode
());
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
PASSPORT
.
getCode
());
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
PLA
.
getCode
());
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
POLICEPAPER
.
getCode
());
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
TAIBAOZHENG
.
getCode
());
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
HKRESIDENCECARD
.
getCode
());
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
TWRESIDENCECARD
.
getCode
());
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
RESIDENCE
.
getCode
());
PERSON_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
OTHER
.
getCode
());
COMPANY_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
UNITCREDITCODE
.
getCode
());
COMPANY_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
BUSINESS_LICENSE_NO
.
getCode
());
COMPANY_CERTTYPE_CODE_SET
.
add
(
CertTypeEnum
.
SOCIAL_ORG_LEGAL_PERSON_CERT
.
getCode
());
}
@Override
public
Response
getDicData
(
String
tenantNo
)
{
Map
<
String
,
Object
>
dicMap
=
new
HashMap
<>();
dicMap
.
put
(
"certType"
,
wrapPersonCertTypeDicList
());
dicMap
.
put
(
"companyCertType"
,
wrapCompanyCertTypeDicList
());
dicMap
.
put
(
"companyType"
,
wrapCompanyTypeDicList
());
dicMap
.
put
(
"industryType"
,
wrapIndustryTypeDicList
());
dicMap
.
put
(
"livenessType"
,
wrapLivenessTypeDicList
());
dicMap
.
put
(
"livenessActionSeq"
,
wrapLivenessActionSeqDicList
());
return
Response
.
createSuccess
(
dicMap
);
}
private
Object
wrapLivenessActionSeqDicList
()
{
List
<
DicDTO
>
list
=
new
ArrayList
<>();
for
(
LivenessActionSeqEnum
item
:
LivenessActionSeqEnum
.
values
())
{
DicDTO
dicItem
=
new
DicDTO
();
dicItem
.
setLabel
(
item
.
getName
());
dicItem
.
setValue
(
item
.
getCode
());
list
.
add
(
dicItem
);
}
return
list
;
}
private
Object
wrapLivenessTypeDicList
()
{
List
<
DicDTO
>
list
=
new
ArrayList
<>();
for
(
LivenessTypeEnum
item
:
LivenessTypeEnum
.
values
())
{
DicDTO
dicItem
=
new
DicDTO
();
dicItem
.
setLabel
(
item
.
getName
());
dicItem
.
setValue
(
item
.
getCode
());
list
.
add
(
dicItem
);
}
return
list
;
}
private
List
<
DicDTO
>
wrapIndustryTypeDicList
()
{
List
<
DicDTO
>
list
=
new
ArrayList
<>();
for
(
IndustryTypeEnum
item
:
IndustryTypeEnum
.
values
())
{
DicDTO
dicItem
=
new
DicDTO
();
dicItem
.
setLabel
(
item
.
getValue
());
dicItem
.
setValue
(
item
.
getCode
()
+
""
);
list
.
add
(
dicItem
);
}
return
list
;
}
private
List
<
DicDTO
>
wrapCompanyCertTypeDicList
()
{
List
<
DicDTO
>
list
=
new
ArrayList
<>();
for
(
CertTypeEnum
item
:
CertTypeEnum
.
values
())
{
DicDTO
dicItem
=
new
DicDTO
();
if
(
COMPANY_CERTTYPE_CODE_SET
.
contains
(
item
.
getCode
()))
{
dicItem
.
setLabel
(
item
.
getName
());
dicItem
.
setValue
(
item
.
getCode
());
list
.
add
(
dicItem
);
}
}
return
list
;
}
private
List
<
DicDTO
>
wrapCompanyTypeDicList
()
{
List
<
DicDTO
>
list
=
new
ArrayList
<>();
for
(
CompanyTypeEnum
item
:
CompanyTypeEnum
.
values
())
{
DicDTO
dicItem
=
new
DicDTO
();
dicItem
.
setLabel
(
item
.
getValue
());
dicItem
.
setValue
(
item
.
getCode
()
+
""
);
list
.
add
(
dicItem
);
}
return
list
;
}
private
List
<
DicDTO
>
wrapPersonCertTypeDicList
()
{
List
<
DicDTO
>
list
=
new
ArrayList
<>();
for
(
CertTypeEnum
item
:
CertTypeEnum
.
values
())
{
DicDTO
dicItem
=
new
DicDTO
();
if
(
PERSON_CERTTYPE_CODE_SET
.
contains
(
item
.
getCode
()))
{
dicItem
.
setLabel
(
item
.
getName
());
dicItem
.
setValue
(
item
.
getCode
());
list
.
add
(
dicItem
);
}
}
return
list
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/CarInfoImportServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.ImportSimDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ICarInfoImportService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ICarInfoUploadService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
/**
* @className: CarInfoImportServiceImpl
* @description: 车辆信息导入实现层
* @author: jk
* @date: 2022/6/28 19:08
* @version: 1.0
**/
@Service
@Slf4j
public
class
CarInfoImportServiceImpl
implements
ICarInfoImportService
{
@Resource
private
ICarInfoUploadService
iCarInfoUploadService
;
@Override
public
Response
<?>
importSim
(
ImportSimDTO
importSimDTO
)
{
return
iCarInfoUploadService
.
excelProcess
(
importSimDTO
);
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/CardUnBindServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.CustomerTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.convert.PersonalRnrRequestConvert
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.*
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ICardUnBindService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IPersonalRnrService
;
import
com.cusc.nirvana.user.rnr.enterprise.util.DesensitizationUtil
;
import
com.cusc.nirvana.user.rnr.fp.client.CardUnBindClient
;
import
com.cusc.nirvana.user.rnr.fp.client.FpRnrUnbindClient
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.constants.BizTypeEnum
;
import
com.cusc.nirvana.user.rnr.fp.dto.*
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCardInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.*
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* 解绑实现类
*
* @author yubo
* @since 2022-04-25 09:32
*/
@Service
@Slf4j
public
class
CardUnBindServiceImpl
implements
ICardUnBindService
{
@Autowired
IPersonalRnrService
personalRnrService
;
@Autowired
FpRnrUnbindClient
rnrUnbindClient
;
@Resource
private
CardUnBindClient
cardUnBindClient
;
@Resource
private
MgRnrCardInfoClient
mgRnrCardInfoClient
;
/**
* 二手车现车主解绑-自然人
*/
@Override
public
Response
secondHandPersonalUnbind
(
SecondHandUnbindRequestDTO
bean
)
{
//调用新车主实名认证接口
PersonalRnrRequestDTO
personalRnrRequestDTO
=
PersonalRnrRequestConvert
.
INSTANCE
.
secondHandUnbindDTOToPersonalRnrDTO
(
bean
);
personalRnrRequestDTO
.
setCustomerType
(
CustomerTypeEnum
.
USED_CAR_OWNER
.
getCode
());
personalRnrRequestDTO
.
setRnrBizzTypeEnum
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
Response
<
RnrRelationDTO
>
rnrRelationDTOResponse
=
personalRnrService
.
checkAndConvertToRelation
(
personalRnrRequestDTO
,
true
);
if
(!
rnrRelationDTOResponse
.
isSuccess
())
{
return
Response
.
createError
(
rnrRelationDTOResponse
.
getMsg
(),
rnrRelationDTOResponse
.
getCode
());
}
//调用fp接口
RnrRelationDTO
rnrRelationDTO
=
rnrRelationDTOResponse
.
getData
();
//修改order信息
changeOrder
(
rnrRelationDTO
.
getOrder
());
Response
rnrResponse
=
rnrUnbindClient
.
secondHandUnbind
(
rnrRelationDTO
.
getOrder
().
getSerialNumber
(),
bean
.
getRequestId
(),
rnrRelationDTO
);
if
(
rnrResponse
.
isSuccess
())
{
return
Response
.
createSuccess
(
new
PersonalRnrDTO
((
Integer
)
rnrResponse
.
getData
()));
}
return
rnrResponse
;
}
/**
* 校验工单状态
* @param bean
* @return
*/
@Override
public
Response
checkOrderStatus
(
RnrOrderDTO
bean
){
//短信校验
Response
response
=
cardUnBindClient
.
checkMessageOutTime
(
bean
);
if
(!
response
.
isSuccess
()){
return
response
;
}
Response
<
RnrOrderDTO
>
orderStatus
=
cardUnBindClient
.
getOrderStatus
(
bean
);
if
(!
orderStatus
.
isSuccess
()){
return
Response
.
createError
(
"获取工单信息失败"
,
orderStatus
.
getData
());
}
return
orderStatus
;
}
/**
* 车主 解绑
*
* @param bean
* @return
*/
@Override
public
Response
originalOwner
(
VehicleCardRnrDTO
bean
)
{
return
this
.
sendMessage
(
bean
);
}
private
RnrOrderDTO
createOrder
(
MgRnrInfoDTO
rnrInfo
)
{
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setOrderType
(
RnrOrderType
.
UNBIND
.
getCode
());
rnrOrderDTO
.
setRnrId
(
rnrInfo
.
getUuid
());
rnrOrderDTO
.
setAuditType
(
RnrOrderAuditTypeEnum
.
AUTO
.
getCode
());
rnrOrderDTO
.
setAutoRnr
(
true
);
rnrOrderDTO
.
setIsBatchOrder
(
1
);
rnrOrderDTO
.
setSerialNumber
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setOrderSource
(
RnrOrderSourceEnum
.
PORTAL
.
getCode
());
rnrOrderDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setTenantNo
(
rnrInfo
.
getTenantNo
());
rnrOrderDTO
.
setOrgId
(
rnrInfo
.
getOrgId
());
rnrOrderDTO
.
setOrderStatus
(
RnrOrderStatusEnum
.
TO_EXAMINE
.
getCode
());
rnrOrderDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
return
rnrOrderDTO
;
}
private
MgRnrInfoDTO
getRnrInfo
(
VehicleCardRnrDTO
bean
)
{
log
.
info
(
"获取实名人员信息入参: {}"
,
JSON
.
toJSONString
(
bean
));
//获取人员信息
FpVehicleCardRnrDTO
fpVehicleCardRnrDTO
=
new
FpVehicleCardRnrDTO
();
fpVehicleCardRnrDTO
.
setRnrId
(
bean
.
getRnrId
());
log
.
info
(
"获取实名人员信息转换参数: {}"
,
JSON
.
toJSONString
(
fpVehicleCardRnrDTO
));
Response
<
MgRnrInfoDTO
>
rnrInfo
=
cardUnBindClient
.
getRnrInfo
(
fpVehicleCardRnrDTO
);
if
(!
rnrInfo
.
isSuccess
())
{
return
null
;
}
return
rnrInfo
.
getData
();
}
/**
* 发送短信
*
* @param bean
* @return
*/
@Override
public
Response
sendMessage
(
VehicleCardRnrDTO
bean
)
{
//校验
FpVehicleCardRnrDTO
fpVehicleCardRnrDTO
=
new
FpVehicleCardRnrDTO
();
fpVehicleCardRnrDTO
.
setVin
(
bean
.
getVin
());
Response
<
List
<
MgRnrCardInfoDTO
>>
cardList
=
cardUnBindClient
.
getCardList
(
fpVehicleCardRnrDTO
);
if
(!
cardList
.
isSuccess
()
||
cardList
.
getData
()
==
null
)
{
//卡未实名或没有绑定在车上
return
Response
.
createError
(
cardList
.
getMsg
(),
cardList
.
getCode
());
}
List
<
MgRnrCardInfoDTO
>
rnrCardList
=
cardList
.
getData
();
List
<
String
>
iccidList
=
bean
.
getIccidList
();
//需要解绑的卡
List
<
MgRnrCardInfoDTO
>
toUnbindCardList
=
rnrCardList
.
stream
().
filter
(
t
->
iccidList
.
contains
(
t
.
getIccid
())).
collect
(
Collectors
.
toList
());
if
(
toUnbindCardList
.
size
()
!=
iccidList
.
size
()){
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"输入的卡存在未实名的卡信息"
);
}
MgRnrInfoDTO
rnrInfo
=
getRnrInfo
(
bean
);
if
(
rnrInfo
==
null
)
{
return
Response
.
createError
(
"获取实名人员信息失败"
);
}
log
.
info
(
"自然人解绑短信发送入参: {}"
,
JSON
.
toJSONString
(
bean
));
MgRnrInfoDTO
rnrInfoData
=
getRnrInfo
(
bean
);
if
(
rnrInfoData
==
null
)
{
return
Response
.
createError
(
"实名信息为空"
);
}
RnrOrderDTO
order
=
this
.
createOrder
(
rnrInfoData
);
//插入工单信息
Response
<
RnrOrderDTO
>
orderResponse
=
cardUnBindClient
.
insertOrder
(
order
);
if
(!
orderResponse
.
isSuccess
()
||
orderResponse
.
getData
()
==
null
){
return
Response
.
createError
(
orderResponse
.
getMsg
(),
orderResponse
.
getData
());
}
//插入卡信息
List
<
MgRnrCardInfoDTO
>
cardInfoDTOList
=
createCardInfoDTOS
(
toUnbindCardList
,
rnrInfo
,
bean
.
getVin
(),
order
.
getUuid
());
Response
<
Boolean
>
cardResponse
=
mgRnrCardInfoClient
.
insertBatch
(
cardInfoDTOList
);
if
(!
cardResponse
.
isSuccess
()
||
cardResponse
.
getData
()
==
null
){
return
Response
.
createError
(
orderResponse
.
getMsg
(),
orderResponse
.
getData
());
}
//配置短信参数
List
<
String
>
paramsList
=
new
ArrayList
<>();
paramsList
.
add
(
rnrInfoData
.
getFullName
()
+
"女士/先生"
);
paramsList
.
add
(
bean
.
getVin
());
//拼接iccid参数列表
String
iccIdList
=
""
;
for
(
String
iccid
:
bean
.
getIccidList
())
{
iccIdList
+=
iccid
+
","
;
}
String
subIccIdList
=
iccIdList
.
substring
(
0
,
iccIdList
.
length
()
-
1
);
paramsList
.
add
(
subIccIdList
);
SmsRequestDTO
smsRequestDTO
=
new
SmsRequestDTO
();
smsRequestDTO
.
setBizType
(
BizTypeEnum
.
UNBOUND
.
getCode
());
smsRequestDTO
.
setParams
(
paramsList
);
smsRequestDTO
.
setPhone
(
rnrInfoData
.
getPhone
());
FpSendMessageDTO
fpSendMessageDTO
=
new
FpSendMessageDTO
();
fpSendMessageDTO
.
setRnrid
(
bean
.
getRnrId
());
fpSendMessageDTO
.
setUser
(
rnrInfoData
.
getCreator
());
fpSendMessageDTO
.
setIccidLists
(
subIccIdList
);
fpSendMessageDTO
.
setSmsRequestDTO
(
smsRequestDTO
);
fpSendMessageDTO
.
setOrderId
(
order
.
getUuid
());
//发送短信
Response
<
FpRnrSmsInfoDTO
>
smsResponse
=
cardUnBindClient
.
sendSms
(
fpSendMessageDTO
);
if
(!
smsResponse
.
isSuccess
()
&&
smsResponse
.
getData
()
==
null
){
return
Response
.
createError
(
"短信发送失败"
);
}
else
{
return
Response
.
createSuccess
(
"短信发送成功"
,
orderResponse
.
getData
());
}
}
/**
* 根据vin 获取以绑定的iccids集合,以及车主信息
*/
@Override
public
Response
getIccidsByVin
(
VehicleCardRnrDTO
bean
){
UserInfoAndCardListDTO
userInfoAndCardListDTO
=
new
UserInfoAndCardListDTO
();
FpVehicleCardRnrDTO
fpVehicleCardRnrDTO
=
new
FpVehicleCardRnrDTO
();
fpVehicleCardRnrDTO
.
setVin
(
bean
.
getVin
());
Response
<
List
<
MgRnrCardInfoDTO
>>
cardList
=
cardUnBindClient
.
getCardList
(
fpVehicleCardRnrDTO
);
if
(!
cardList
.
isSuccess
()
||
cardList
.
getData
()
==
null
||
cardList
.
getData
().
size
()<
1
){
return
Response
.
createError
(
"卡未绑定"
);
}
//List<MgRnrCardInfoDTO> collect = cardList.getData().stream().filter(t -> t.getRnrBizzType()==RnrBizzTypeEnum.Bind.getCode()).collect(Collectors.toList());
List
<
MgRnrCardInfoDTO
>
collect
=
cardList
.
getData
();
List
<
String
>
iccids
=
new
ArrayList
<>();
for
(
MgRnrCardInfoDTO
cardInfoDTO:
collect
){
iccids
.
add
(
cardInfoDTO
.
getIccid
());
}
VehicleCardRnrDTO
cardRnrDTO
=
new
VehicleCardRnrDTO
();
cardRnrDTO
.
setVin
(
bean
.
getVin
());
cardRnrDTO
.
setRnrId
(
collect
.
get
(
0
).
getRnrId
());
cardRnrDTO
.
setIccidList
(
iccids
);
userInfoAndCardListDTO
.
setVehicleCardRnrDTO
(
cardRnrDTO
);
bean
.
setRnrId
(
collect
.
get
(
0
).
getRnrId
());
MgRnrInfoDTO
rnrInfo
=
getRnrInfo
(
bean
);
if
(
rnrInfo
==
null
){
return
Response
.
createError
(
"获取车主信息失败"
);
}
String
phone
=
DesensitizationUtil
.
desensitizePhone
(
rnrInfo
.
getPhone
());
rnrInfo
.
setPhone
(
phone
);
userInfoAndCardListDTO
.
setMgRnrInfoDTO
(
rnrInfo
);
return
Response
.
createSuccess
(
"获取信息成功"
,
userInfoAndCardListDTO
);
}
//-----------------------私有方法区
//修改order信息
private
void
changeOrder
(
RnrOrderDTO
order
)
{
order
.
setAuditType
(
RnrOrderAuditTypeEnum
.
MANUAL
.
getCode
());
order
.
setAutoRnr
(
false
);
order
.
setOrderType
(
RnrOrderType
.
SEC_UNBIND
.
getCode
());
order
.
setSendWorkOrder
(
true
);
}
private
List
<
MgRnrCardInfoDTO
>
createCardInfoDTOS
(
List
<
MgRnrCardInfoDTO
>
toUnBindCardList
,
MgRnrInfoDTO
rnrInfoDTO
,
String
vin
,
String
orderId
)
{
List
<
MgRnrCardInfoDTO
>
cardInfoDTOList
=
new
ArrayList
<>();
for
(
MgRnrCardInfoDTO
unBindCard
:
toUnBindCardList
)
{
MgRnrCardInfoDTO
mgRnrCardInfoDTO
=
new
MgRnrCardInfoDTO
();
mgRnrCardInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrCardInfoDTO
.
setIccid
(
unBindCard
.
getIccid
());
mgRnrCardInfoDTO
.
setOldCardId
(
unBindCard
.
getUuid
());
mgRnrCardInfoDTO
.
setTenantNo
(
rnrInfoDTO
.
getTenantNo
());
mgRnrCardInfoDTO
.
setIotId
(
vin
);
mgRnrCardInfoDTO
.
setRnrId
(
rnrInfoDTO
.
getUuid
());
mgRnrCardInfoDTO
.
setOrderId
(
orderId
);
mgRnrCardInfoDTO
.
setRnrStatus
(
RnrStatus
.
INIT
.
getCode
());
mgRnrCardInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
cardInfoDTOList
.
add
(
mgRnrCardInfoDTO
);
}
return
cardInfoDTOList
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/ChangeTboxServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.ChangeTboxDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.IccidChangeDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IChangeTboxService
;
import
com.cusc.nirvana.user.rnr.fp.client.CardUnBindClient
;
import
com.cusc.nirvana.user.rnr.fp.client.ChangeTboxClient
;
import
com.cusc.nirvana.user.rnr.fp.client.VinCardClient
;
import
com.cusc.nirvana.user.rnr.fp.constants.BizTypeEnum
;
import
com.cusc.nirvana.user.rnr.fp.dto.FpRnrSmsInfoDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.FpSendMessageDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.FpVehicleCardRnrDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.SmsRequestDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.UnbindReceiceSMSDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VerifyVinCardResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardDTO
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCardInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.*
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* @author changh
* @date 2022/4/24
*/
@Service
@Slf4j
public
class
ChangeTboxServiceImpl
implements
IChangeTboxService
{
@Resource
private
CardUnBindClient
cardUnBindClient
;
@Resource
private
ChangeTboxClient
changeTboxClient
;
@Resource
private
VinCardClient
vinCardClient
;
@Resource
private
MgRnrCardInfoClient
mgRnrCardInfoClient
;
@Override
public
Response
submit
(
ChangeTboxDTO
bean
)
{
log
.
info
(
"换卡入参:{}"
,
JSON
.
toJSONString
(
bean
));
List
<
String
>
oldIccids
=
new
ArrayList
<>();
List
<
String
>
newIccids
=
new
ArrayList
<>();
for
(
IccidChangeDTO
changeDTO:
bean
.
getIccidList
()){
oldIccids
.
add
(
changeDTO
.
getOldIccid
());
newIccids
.
add
(
changeDTO
.
getNewIccid
());
}
//校验旧的iccid和vin
/*FpVehicleCardRnrDTO fpVehicleCardRnrDTO = new FpVehicleCardRnrDTO();
fpVehicleCardRnrDTO.setVin(bean.getVin());
Response<List<MgRnrCardInfoDTO>> cardList = cardUnBindClient.getCardList(fpVehicleCardRnrDTO);
if(!cardList.isSuccess() || cardList.getData() == null){
return Response.createError("vin无法获取iccid列表");
}
List<MgRnrCardInfoDTO> cardDatas = cardList.getData();
List<MgRnrCardInfoDTO> rnrCardInfoDTOS = cardDatas.stream().filter(t -> oldIccids.contains(t.getIccid())).collect(Collectors.toList());
if(rnrCardInfoDTOS.size() != oldIccids.size()){
return Response.createError("iccids与vin不匹配:{}",JSON.toJSONString(rnrCardInfoDTOS));
}*/
List
<
VinCardDTO
>
vinCardDTOList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
bean
.
getIccidList
().
size
();
i
++){
VinCardDTO
vinCardDTO
=
new
VinCardDTO
();
vinCardDTO
.
setVin
(
bean
.
getVin
());
vinCardDTO
.
setIccid
(
bean
.
getIccidList
().
get
(
i
).
getOldIccid
());
vinCardDTOList
.
add
(
vinCardDTO
);
}
log
.
info
(
"校验车卡关系入参:{}"
,
JSON
.
toJSONString
(
vinCardDTOList
));
Response
<
VerifyVinCardResponseDTO
>
verifyVinCard
=
vinCardClient
.
verifyVinCard
(
vinCardDTOList
);
log
.
info
(
"校验车卡关系:{}"
,
JSON
.
toJSONString
(
verifyVinCard
));
if
(!
verifyVinCard
.
isSuccess
()){
return
verifyVinCard
;
}
//校验新的iccid
Response
<
Boolean
>
checkStatus
=
changeTboxClient
.
checkStatus
(
newIccids
);
log
.
info
(
"校验新车卡出参:{}"
,
JSON
.
toJSONString
(
checkStatus
));
if
(!
checkStatus
.
isSuccess
()
||
!
checkStatus
.
getData
()){
return
Response
.
createError
(
"换卡iccid状态为已实名"
);
}
//发送短信
return
this
.
sendSMS
(
bean
);
/*RnrRelationDTO rnrRelationDTO = turnParams(oldIccids,newIccids,bean.getVin(),cardDatas.get(0).getRnrId(),cardDatas.get(0).getTenantNo());
log.info("换卡转换参数:{}", JSON.toJSONString(rnrRelationDTO));
return changeTboxClient.changeTbox(rnrRelationDTO);*/
}
private
MgRnrInfoDTO
getRnrInfo
(
ChangeTboxDTO
bean
){
//获取人员信息
FpVehicleCardRnrDTO
fpVehicleCardRnrDTO
=
new
FpVehicleCardRnrDTO
();
fpVehicleCardRnrDTO
.
setVin
(
bean
.
getVin
());
Response
<
List
<
MgRnrCardInfoDTO
>>
cardList
=
cardUnBindClient
.
getCardList
(
fpVehicleCardRnrDTO
);
if
(!
cardList
.
isSuccess
()){
return
null
;
}
FpVehicleCardRnrDTO
vehicleCardRnrDTO
=
new
FpVehicleCardRnrDTO
();
vehicleCardRnrDTO
.
setRnrId
(
cardList
.
getData
().
get
(
0
).
getRnrId
());
Response
<
MgRnrInfoDTO
>
rnrInfo
=
cardUnBindClient
.
getRnrInfo
(
vehicleCardRnrDTO
);
if
(!
rnrInfo
.
isSuccess
()){
return
null
;
}
return
rnrInfo
.
getData
();
}
/*private RnrRelationDTO turnParams(List<String> oldIccids, List<String> newIccids, String vin,String rnrid, String tenNo){
RnrRelationDTO rnrRelationDTO = new RnrRelationDTO();
RnrOrderDTO order = createOrder(rnrid, tenNo);
List<MgRnrCardInfoDTO> cardInfoDTOS = new ArrayList<>();
List<MgRnrCardInfoDTO> oldCardInfoDTOS = createCardInfoDTOS(oldIccids, tenNo, vin, rnrid,order.getUuid());
List<MgRnrCardInfoDTO> newCardInfoDTOS = createCardInfoDTOS(newIccids, tenNo, vin, rnrid,order.getUuid());
cardInfoDTOS.addAll(oldCardInfoDTOS);
cardInfoDTOS.addAll(newCardInfoDTOS);
rnrRelationDTO.setOrder(order);
rnrRelationDTO.setCardList(cardInfoDTOS);
return rnrRelationDTO;
}*/
private
RnrOrderDTO
createOrder
(
MgRnrInfoDTO
rnrInfo
){
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
ChangeBinding
.
getCode
());
rnrOrderDTO
.
setOrderType
(
RnrOrderType
.
TBOX_CHANGE
.
getCode
());
rnrOrderDTO
.
setRnrId
(
rnrInfo
.
getUuid
());
rnrOrderDTO
.
setAuditType
(
RnrOrderAuditTypeEnum
.
AUTO
.
getCode
());
rnrOrderDTO
.
setAutoRnr
(
true
);
rnrOrderDTO
.
setIsBatchOrder
(
1
);
rnrOrderDTO
.
setSerialNumber
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setOrderSource
(
RnrOrderSourceEnum
.
PORTAL
.
getCode
());
rnrOrderDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setTenantNo
(
rnrInfo
.
getTenantNo
());
rnrOrderDTO
.
setOrgId
(
rnrInfo
.
getOrgId
());
rnrOrderDTO
.
setOrderStatus
(
RnrOrderStatusEnum
.
TO_EXAMINE
.
getCode
());
return
rnrOrderDTO
;
}
private
List
<
MgRnrCardInfoDTO
>
createCardInfoDTOS
(
ChangeTboxDTO
changeTboxDTO
,
String
tenNo
,
String
rnrid
,
String
orderId
,
Long
routingKey
){
//旧卡
List
<
String
>
oldIccidList
=
changeTboxDTO
.
getIccidList
().
stream
().
map
(
IccidChangeDTO:
:
getOldIccid
).
collect
(
Collectors
.
toList
());
//查询旧卡已经实名的业务
MgRnrCardInfoDTO
query
=
new
MgRnrCardInfoDTO
();
query
.
setIccidList
(
oldIccidList
);
query
.
setRnrId
(
rnrid
);
query
.
setRnrStatus
(
RnrStatus
.
RNR
.
getCode
());
Map
<
String
,
String
>
oldIccidMap
=
mgRnrCardInfoClient
.
queryByList
(
query
).
getData
().
stream
().
collect
(
Collectors
.
toMap
(
MgRnrCardInfoDTO:
:
getIccid
,
MgRnrCardInfoDTO:
:
getUuid
,
(
o1
,
o2
)
->
o1
));
List
<
MgRnrCardInfoDTO
>
cardInfoDTOList
=
new
ArrayList
<>();
for
(
IccidChangeDTO
dto
:
changeTboxDTO
.
getIccidList
()){
MgRnrCardInfoDTO
mgRnrCardInfoDTO
=
new
MgRnrCardInfoDTO
();
mgRnrCardInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrCardInfoDTO
.
setIccid
(
dto
.
getNewIccid
());
mgRnrCardInfoDTO
.
setOldCardId
(
oldIccidMap
.
getOrDefault
(
dto
.
getOldIccid
(),
""
));
mgRnrCardInfoDTO
.
setTenantNo
(
tenNo
);
mgRnrCardInfoDTO
.
setIotId
(
changeTboxDTO
.
getVin
());
mgRnrCardInfoDTO
.
setRnrId
(
rnrid
);
mgRnrCardInfoDTO
.
setOrderId
(
orderId
);
mgRnrCardInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setRnrStatus
(
RnrStatus
.
INIT
.
getCode
());
mgRnrCardInfoDTO
.
setNoticeStatus
(
NoticeStatusEnum
.
NONEED
.
getCode
());
mgRnrCardInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
ChangeBinding
.
getCode
());
mgRnrCardInfoDTO
.
setRoutingKey
(
routingKey
);
cardInfoDTOList
.
add
(
mgRnrCardInfoDTO
);
}
return
cardInfoDTOList
;
}
@Override
public
Response
queryResult
(
ChangeTboxDTO
bean
)
{
//1.通过submit方法响应的新的rnrId查询业务结果
return
Response
.
createSuccess
(
true
);
}
/**
* 发送短信
*/
@Override
public
Response
sendSMS
(
ChangeTboxDTO
bean
)
{
log
.
info
(
"换卡发送短信入参:{}"
,
JSON
.
toJSONString
(
bean
));
MgRnrInfoDTO
rnrInfoData
=
getRnrInfo
(
bean
);
if
(
rnrInfoData
==
null
){
return
Response
.
createError
(
"无法获取到手机号信息"
);
}
List
<
String
>
paramsList
=
getMessageContext
(
bean
);
SmsRequestDTO
smsRequestDTO
=
new
SmsRequestDTO
();
smsRequestDTO
.
setBizType
(
BizTypeEnum
.
CHANGETBOX
.
getCode
());
smsRequestDTO
.
setParams
(
paramsList
);
smsRequestDTO
.
setPhone
(
rnrInfoData
.
getPhone
());
FpSendMessageDTO
fpSendMessageDTO
=
new
FpSendMessageDTO
();
fpSendMessageDTO
.
setRnrid
(
rnrInfoData
.
getUuid
());
fpSendMessageDTO
.
setUser
(
rnrInfoData
.
getCreator
());
fpSendMessageDTO
.
setIccidLists
(
paramsList
.
get
(
2
));
fpSendMessageDTO
.
setSmsRequestDTO
(
smsRequestDTO
);
RnrOrderDTO
order
=
createOrder
(
rnrInfoData
);
order
.
setRoutingKey
(
rnrInfoData
.
getRoutingKey
());
fpSendMessageDTO
.
setOrderId
(
order
.
getUuid
());
//构建卡信息
List
<
MgRnrCardInfoDTO
>
cardInfoDTOList
=
createCardInfoDTOS
(
bean
,
rnrInfoData
.
getTenantNo
(),
rnrInfoData
.
getUuid
(),
order
.
getUuid
(),
rnrInfoData
.
getRoutingKey
());
//发送短信
Response
<
FpRnrSmsInfoDTO
>
smsResponse
=
cardUnBindClient
.
sendSms
(
fpSendMessageDTO
);
if
(!
smsResponse
.
isSuccess
()){
return
Response
.
createError
(
"短信发送失败"
);
}
else
{
Response
<
RnrOrderDTO
>
orderResponse
=
cardUnBindClient
.
insertOrder
(
order
);
Response
<
Boolean
>
cardResponse
=
mgRnrCardInfoClient
.
insertBatch
(
cardInfoDTOList
);
if
(
orderResponse
.
isSuccess
()
&&
cardResponse
.
isSuccess
()){
return
Response
.
createSuccess
(
"短信发送成功"
,
order
);
}
else
{
return
Response
.
createError
(
"创建工单/卡信息失败"
);
}
}
}
private
List
<
String
>
getMessageContext
(
ChangeTboxDTO
bean
){
MgRnrInfoDTO
rnrInfoData
=
getRnrInfo
(
bean
);
//配置短信参数
List
<
String
>
paramsList
=
new
ArrayList
<>();
/*if (rnrInfoData.getGender() == 0) {
paramsList.add(rnrInfoData.getFullName() + "女士");
} else {
paramsList.add(rnrInfoData.getFullName() + "先生");
}*/
paramsList
.
add
(
rnrInfoData
.
getFullName
()
+
"女士/先生"
);
paramsList
.
add
(
bean
.
getVin
());
//paramsList.add(bean.getVin());
String
iccIdList
=
""
;
for
(
IccidChangeDTO
changeDTO:
bean
.
getIccidList
()){
iccIdList
+=
changeDTO
.
getOldIccid
()
+
"换为"
+
changeDTO
.
getNewIccid
()
+
","
;
}
String
substring
=
iccIdList
.
substring
(
0
,
iccIdList
.
length
()-
1
);
paramsList
.
add
(
substring
);
return
paramsList
;
}
//短信回调接口
@Override
public
Response
receiveMessage
(
UnbindReceiceSMSDTO
bean
)
{
log
.
info
(
"换卡短信回调入参:{}"
,
JSON
.
toJSONString
(
bean
));
return
cardUnBindClient
.
receiveMessage
(
bean
);
}
@Override
public
Response
checkSMSStatus
(
FpRnrSmsInfoDTO
bean
)
{
log
.
info
(
"换卡校验短信状态入参:{}"
,
JSON
.
toJSONString
(
bean
));
Response
<
FpRnrSmsInfoDTO
>
messageStatus
=
cardUnBindClient
.
getMessageStatus
(
bean
);
if
(!
messageStatus
.
isSuccess
()
||
messageStatus
.
getData
()
==
null
){
return
Response
.
createError
(
"获取短信失败"
);
}
long
currentTimeMillis
=
System
.
currentTimeMillis
();
//校验时间2分钟内
Date
createTime
=
messageStatus
.
getData
().
getCreateTime
();
long
startTime
=
createTime
.
getTime
();
if
(
currentTimeMillis
-
120
*
1000
>
startTime
){
return
Response
.
createError
(
"短信获取超时"
);
}
//校验内容
if
(!
messageStatus
.
getData
().
getReceiveContent
().
toLowerCase
().
equals
(
"y"
)){
return
Response
.
createError
(
"短信回复为N"
);
}
return
Response
.
createSuccess
(
"短信校验通过"
);
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/DistributorServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cache.CacheFactory
;
import
com.cache.local.guava.page.Page
;
import
com.cusc.nirvana.common.result.PageResult
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.eiam.client.OrganizationClient
;
import
com.cusc.nirvana.user.eiam.client.UserClient
;
import
com.cusc.nirvana.user.eiam.client.UserRoleClient
;
import
com.cusc.nirvana.user.eiam.dto.OrganizationDTO
;
import
com.cusc.nirvana.user.eiam.dto.UserDTO
;
import
com.cusc.nirvana.user.eiam.dto.UserRoleDTO
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.common.RedisConstants
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.OrdinaryAdminEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.ResponseCode
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.DistributorAddDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.DistributorChangeAdminDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.DistributorDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.DistributorPageQueryDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IDistributorService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IUserService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.Calendar
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @author stayAnd
* @date 2022/4/14
*/
@Service
@Slf4j
public
class
DistributorServiceImpl
implements
IDistributorService
{
@Resource
private
IUserService
userService
;
@Resource
private
OrganizationClient
organizationClient
;
@Resource
private
UserClient
userClient
;
@Resource
private
CacheFactory
cacheFactory
;
@Resource
private
UserRoleClient
userRoleClient
;
/**
* 默认经销商管理员角色code
*/
@Value
(
"${distributor.user.role.id:201}"
)
private
String
distributorRoleCode
;
@Value
(
"${user.eiam.applicationId:4}"
)
private
String
applicationId
;
@Override
public
void
add
(
DistributorAddDTO
dto
)
{
UserDTO
queryUserDTO
=
userService
.
queryUserInInfoByPhone
(
dto
.
getPhone
());
if
(
null
!=
queryUserDTO
)
{
throw
new
CuscUserException
(
ResponseCode
.
USER_PHONE_EXISTS
.
getCode
(),
ResponseCode
.
USER_PHONE_EXISTS
.
getMsg
());
}
//获取当前的用户
String
userId
=
UserSubjectUtil
.
getUserId
();
String
organId
=
userService
.
getOrganId
(
userId
,
UserSubjectUtil
.
getTenantNo
());
if
(
StringUtils
.
isBlank
(
organId
))
{
throw
new
CuscUserException
(
ResponseCode
.
USER_ORGAN_NOT_FOUND
.
getCode
(),
ResponseCode
.
USER_ORGAN_NOT_FOUND
.
getMsg
());
}
UserDTO
userDto
=
dto
.
toUserDto
();
userDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
userDto
.
setApplicationId
(
applicationId
);
userDto
.
setOrdinaryAdmin
(
OrdinaryAdminEnum
.
DISTRIBUTOR
.
getCode
());
UserDTO
addUserDto
=
userService
.
addUser
(
userDto
);
//添加经销商(组织)
OrganizationDTO
organDto
=
dto
.
toOrganDTO
();
//设置经销商的上级节点为当前车企
organDto
.
setParentId
(
organId
);
organDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
organDto
.
setOrganCode
(
generateOrganCode
());
Response
<
OrganizationDTO
>
organizationResponse
=
organizationClient
.
add
(
organDto
);
OrganizationDTO
organizationDTO
=
organizationResponse
.
getData
();
//新增经销商管理员及其关系
userService
.
addUserRelationRole
(
addUserDto
.
getUuid
(),
organizationDTO
.
getUuid
(),
distributorRoleCode
);
}
@Override
public
PageResult
<
DistributorDTO
>
page
(
DistributorPageQueryDTO
dto
)
{
//获取当前的用户
String
userId
=
UserSubjectUtil
.
getUserId
();
//当前用户的组织id
String
organId
=
userService
.
getOrganId
(
userId
,
UserSubjectUtil
.
getTenantNo
());
OrganizationDTO
queryDto
=
dto
.
toPageQueryDto
();
queryDto
.
setParentId
(
organId
);
Response
<
PageResult
<
OrganizationDTO
>>
organResponse
=
organizationClient
.
queryByPage
(
queryDto
);
PageResult
<
OrganizationDTO
>
page
=
organResponse
.
getData
();
List
<
DistributorDTO
>
dtoList
=
page
.
getList
().
stream
().
map
(
organizationDTO
->
{
DistributorDTO
distributorDTO
=
new
DistributorDTO
();
distributorDTO
.
setId
(
organizationDTO
.
getUuid
());
distributorDTO
.
setDistributorNo
(
organizationDTO
.
getOrganCode
());
distributorDTO
.
setDistributorName
(
organizationDTO
.
getOrganName
());
distributorDTO
.
setDistributorAdminUserName
(
organizationDTO
.
getAdminName
());
distributorDTO
.
setDistributorAdminUserAccount
(
organizationDTO
.
getAdminAccount
());
distributorDTO
.
setDistributorAdminUserId
(
organizationDTO
.
getAdminUserId
());
distributorDTO
.
setPhone
(
organizationDTO
.
getAdminPhone
());
distributorDTO
.
setStatus
(
organizationDTO
.
getStatus
());
distributorDTO
.
setRemark
(
organizationDTO
.
getComment
());
distributorDTO
.
setCreateTime
(
organizationDTO
.
getCreateTime
());
return
distributorDTO
;
}).
collect
(
Collectors
.
toList
());
return
new
PageResult
<>(
dtoList
,
page
.
getTotalCount
(),
page
.
getPageSize
(),
page
.
getCurrPage
());
}
@Override
public
Map
<
String
,
Object
>
pageToMap
(
DistributorPageQueryDTO
dto
)
{
Map
<
String
,
Object
>
returnMap
=
new
HashMap
<>();
//获取当前的用户
String
userId
=
UserSubjectUtil
.
getUserId
();
//当前用户的组织id
String
organId
=
userService
.
getOrganId
(
userId
,
UserSubjectUtil
.
getTenantNo
());
if
(
StringUtils
.
isEmpty
(
organId
)){
returnMap
.
put
(
"errorMsg"
,
"该用户没有组织id"
);
returnMap
.
put
(
"errorCode"
,
10001
);
return
returnMap
;
}
OrganizationDTO
queryDto
=
dto
.
toPageQueryDto
();
queryDto
.
setParentId
(
organId
);
Response
<
PageResult
<
OrganizationDTO
>>
organResponse
=
organizationClient
.
queryByPage
(
queryDto
);
PageResult
<
OrganizationDTO
>
page
=
organResponse
.
getData
();
List
<
DistributorDTO
>
dtoList
=
page
.
getList
().
stream
().
map
(
organizationDTO
->
{
DistributorDTO
distributorDTO
=
new
DistributorDTO
();
distributorDTO
.
setId
(
organizationDTO
.
getUuid
());
distributorDTO
.
setDistributorNo
(
organizationDTO
.
getOrganCode
());
distributorDTO
.
setDistributorName
(
organizationDTO
.
getOrganName
());
distributorDTO
.
setDistributorAdminUserName
(
organizationDTO
.
getAdminName
());
distributorDTO
.
setDistributorAdminUserAccount
(
organizationDTO
.
getAdminAccount
());
distributorDTO
.
setDistributorAdminUserId
(
organizationDTO
.
getAdminUserId
());
distributorDTO
.
setPhone
(
organizationDTO
.
getAdminPhone
());
distributorDTO
.
setStatus
(
organizationDTO
.
getStatus
());
distributorDTO
.
setRemark
(
organizationDTO
.
getComment
());
distributorDTO
.
setCreateTime
(
organizationDTO
.
getCreateTime
());
return
distributorDTO
;
}).
collect
(
Collectors
.
toList
());
PageResult
<
DistributorDTO
>
returnList
=
new
PageResult
<>(
dtoList
,
page
.
getTotalCount
(),
page
.
getPageSize
(),
page
.
getCurrPage
());
if
(
returnList
.
getList
().
size
()<=
0
){
returnMap
.
put
(
"errorMsg"
,
"该用户未查询相关经销商"
);
returnMap
.
put
(
"errorCode"
,
10001
);
return
returnMap
;
}
else
{
returnMap
.
put
(
"errorCode"
,
10000
);
returnMap
.
put
(
"returnList"
,
returnList
);
return
returnMap
;
}
}
@Override
public
void
update
(
DistributorDTO
distributorDTO
)
{
OrganizationDTO
updateDto
=
new
OrganizationDTO
();
updateDto
.
setUuid
(
distributorDTO
.
getId
());
updateDto
.
setOrganName
(
distributorDTO
.
getDistributorName
());
updateDto
.
setComment
(
distributorDTO
.
getRemark
());
updateDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
organizationClient
.
update
(
updateDto
);
}
@Override
public
void
changeAdmin
(
DistributorChangeAdminDTO
dto
)
{
if
(
dto
.
getNewAdminUserId
()
==
null
)
{
UserDTO
userDTO
=
userService
.
queryUserInInfoByPhone
(
dto
.
getCreateAdminPhone
());
if
(
null
!=
userDTO
)
{
throw
new
CuscUserException
(
ResponseCode
.
USER_PHONE_EXISTS
.
getCode
(),
ResponseCode
.
USER_PHONE_EXISTS
.
getMsg
());
}
}
if
(
null
==
dto
.
getNewAdminUserId
())
{
//创建用户
UserDTO
userAdminDto
=
new
UserDTO
();
userAdminDto
.
setOrdinaryAdmin
(
1
);
userAdminDto
.
setUserName
(
dto
.
getCreateAdminAccount
());
userAdminDto
.
setFullName
(
dto
.
getCreateAdminUserName
());
userAdminDto
.
setPhone
(
dto
.
getCreateAdminPhone
());
userAdminDto
.
setPassword
(
dto
.
getCreateAdminPassword
());
userAdminDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
userAdminDto
.
setApplicationId
(
applicationId
);
UserDTO
userDTO
=
userService
.
addUser
(
userAdminDto
);
userService
.
addUserRelationRole
(
userDTO
.
getUuid
(),
dto
.
getId
(),
distributorRoleCode
);
}
else
{
//选中的员工 赋值新的角色管理员
UserDTO
newAdminDto
=
new
UserDTO
();
newAdminDto
.
setUuid
(
dto
.
getNewAdminUserId
());
newAdminDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
newAdminDto
.
setApplicationId
(
applicationId
);
newAdminDto
.
setOrdinaryAdmin
(
1
);
userClient
.
update
(
newAdminDto
);
UserRoleDTO
newUserRoleAdminDto
=
new
UserRoleDTO
();
newUserRoleAdminDto
.
setUserId
(
dto
.
getNewAdminUserId
());
newUserRoleAdminDto
.
setRoleId
(
userService
.
getRoleId
(
distributorRoleCode
));
userRoleClient
.
updateByUserId
(
newUserRoleAdminDto
);
}
//取消当前经销商管理员
UserDTO
cancelAdminDto
=
new
UserDTO
();
cancelAdminDto
.
setUuid
(
dto
.
getCurrentAdminUserId
());
cancelAdminDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
cancelAdminDto
.
setApplicationId
(
applicationId
);
cancelAdminDto
.
setOrdinaryAdmin
(
0
);
userClient
.
update
(
cancelAdminDto
);
UserRoleDTO
cancelRoleAdminDto
=
new
UserRoleDTO
();
cancelRoleAdminDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
cancelRoleAdminDto
.
setApplicationId
(
applicationId
);
cancelRoleAdminDto
.
setUserId
(
dto
.
getCurrentAdminUserId
());
userRoleClient
.
delBatchUser
(
cancelRoleAdminDto
);
}
public
String
generateOrganCode
()
{
try
{
Calendar
calendar
=
Calendar
.
getInstance
();
int
year
=
calendar
.
get
(
Calendar
.
YEAR
);
Long
aLong
=
cacheFactory
.
getStringService
().
setValueIncr
(
RedisConstants
.
ORG_ORGAN_CODE_PREFIX
+
year
,
1
);
return
String
.
valueOf
(
year
*
10000
+
aLong
);
}
catch
(
Exception
e
)
{
log
.
error
(
"generateOrganCode has error"
,
e
);
}
return
""
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/EnterpriseRnrServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.eiam.client.OrganizationClient
;
import
com.cusc.nirvana.user.eiam.dto.OrganizationDTO
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.*
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IEnterpriseRnrService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IPersonalRnrService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IUserService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IVehicleCardService
;
import
com.cusc.nirvana.user.rnr.enterprise.util.FileUtil
;
import
com.cusc.nirvana.user.rnr.fp.client.EnterpriseRnrClient
;
import
com.cusc.nirvana.user.rnr.fp.client.FpRnrClient
;
import
com.cusc.nirvana.user.rnr.fp.client.NewVinCardClient
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.constants.BizTypeEnum
;
import
com.cusc.nirvana.user.rnr.fp.dto.*
;
import
com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrBizzTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrFileType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderAuditTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderSourceEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderStatusEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderType
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCompanyInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrFileDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrLiaisonInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrTagDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
com.cusc.nirvana.user.util.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
@Service
@Slf4j
public
class
EnterpriseRnrServiceImpl
implements
IEnterpriseRnrService
{
@Autowired
IVehicleCardService
vehicleCardService
;
@Autowired
SmsServiceImpl
smsService
;
@Autowired
IPersonalRnrService
personalRnrService
;
@Resource
private
EnterpriseRnrClient
enterpriseClient
;
@Resource
private
OrganizationClient
organizationClient
;
@Resource
private
IUserService
userService
;
@Resource
private
NewVinCardClient
checkClient
;
@Autowired
FpRnrClient
fpRnrClient
;
private
static
final
String
SUCCESS_CODE
=
"0"
;
@Value
(
"${rnr.frontEnterpriseH5CallBackUrl}"
)
private
String
frontEnterpriseH5CallBackUrl
;
@Value
(
"${rnr.frontEnterprisePadCallBackUrl}"
)
private
String
frontEnterprisePadCallBackUrl
;
/**
* 校验车卡关系
*
* @param dto dto bean
* @return
*/
@Override
public
Response
<
EMVinCardResponseDTO
>
verifyVinCards
(
EnterpriseRnrVinCardInfoDTO
dto
)
{
if
(
StringUtils
.
isBlank
(
dto
.
getFileId
()))
{
return
Response
.
createError
(
"文件ID不能为空"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
Response
<
EMVinCardResponseDTO
>
emVinCardResponseDTOResponse
=
vehicleCardService
.
verifyAndUploadVinCard
(
dto
.
getFileId
());
if
(
emVinCardResponseDTOResponse
.
isSuccess
()
&&
emVinCardResponseDTOResponse
.
getData
().
getTotalCount
()
>
5000
)
{
return
Response
.
createError
(
"文件条数应小于5000条"
);
}
return
emVinCardResponseDTOResponse
;
}
@Override
public
Response
<
CompanyRnrResponseDTO
>
submitRnr
(
EnterpriseRnrCertificationInfoDTO
dto
)
{
log
.
info
(
"入参信息:{}"
,
JSON
.
toJSONString
(
dto
));
//验证车卡关系
Response
<
List
<
VinCardDTO
>>
listResponse
=
vehicleCardService
.
checkIccidList
(
dto
.
getFileId
());
log
.
info
(
"验证车卡关系"
,
dto
);
if
(!
listResponse
.
isSuccess
())
{
return
Response
.
createSuccess
(
false
);
}
//验证责任人证件有效期
String
currentDate
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
format
(
new
Date
(
System
.
currentTimeMillis
()));
String
corporationCertExpirationDate
=
dto
.
getCorporationCertExpirationDate
();
if
(
currentDate
.
compareTo
(
corporationCertExpirationDate
)
>
0
)
{
return
Response
.
createError
(
"证件已过期"
);
}
//验证短信
/*SmsRequestDTO smsRequestDTO = new SmsRequestDTO();
smsRequestDTO.setPhone(dto.getCorporationPhone());
smsRequestDTO.setTenantNo(UserSubjectUtil.getTenantNo());
smsRequestDTO.setBizType(BizTypeEnum.RNR.getCode());
smsRequestDTO.setCaptcha(dto.getVerificationCode());
Response smsResponse = smsService.checkSmsCaptcha(smsRequestDTO);
if (!smsResponse.isSuccess()) {
return Response.createError(smsResponse.getMsg(), smsResponse.getCode());
}*/
//调用fp接口 提交企业实名
RnrRelationDTO
rnrRelationDTO
=
turnParams
(
dto
,
listResponse
.
getData
());
if
(
CollectionUtils
.
isEmpty
(
rnrRelationDTO
.
getCardList
()))
{
return
Response
.
createError
(
"ICCID不能为空"
);
}
log
.
info
(
"dto111111111111:{}"
,
JSON
.
toJSONString
(
dto
));
log
.
info
(
"RnrRelationDTO11:{}"
,
JSON
.
toJSONString
(
rnrRelationDTO
));
rnrRelationDTO
.
setRequestId
(
dto
.
getRequestId
());
rnrRelationDTO
.
setSerialNumber
(
rnrRelationDTO
.
getOrder
().
getSerialNumber
());
Response
<
Boolean
>
enterpriseResponse
=
enterpriseClient
.
enterpriseRnr
(
rnrRelationDTO
,
dto
.
getRequestId
());
log
.
info
(
"提交企业实名:{}"
,
JSON
.
toJSONString
(
enterpriseResponse
));
if
(!
enterpriseResponse
.
isSuccess
())
{
return
Response
.
createError
(
enterpriseResponse
.
getMsg
(),
enterpriseResponse
.
getCode
());
}
else
{
Response
submitResponse
=
Response
.
createSuccess
();
CompanyRnrResponseDTO
companyRnrResponseDTO
=
new
CompanyRnrResponseDTO
();
companyRnrResponseDTO
.
setVerifyStatus
(
1
);
submitResponse
.
setData
(
companyRnrResponseDTO
);
return
submitResponse
;
}
}
@Override
public
Map
<
String
,
Object
>
queryEnterpriseRnrPerson
(
EnterpriseCorporationChangeDTO
dto
)
{
Map
<
String
,
Object
>
returnMap
=
new
HashMap
<>();
EnterpriseRnrPersonNameReqDTO
query
=
new
EnterpriseRnrPersonNameReqDTO
();
query
.
setCompanyName
(
dto
.
getCompanyName
());
query
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
String
organId
=
userService
.
getOrganId
(
UserSubjectUtil
.
getUserId
(),
UserSubjectUtil
.
getTenantNo
());
if
(
StringUtils
.
isEmpty
(
organId
))
{
returnMap
.
put
(
"errorMsg"
,
"该用户没有组织id"
);
returnMap
.
put
(
"errorCode"
,
10001
);
return
returnMap
;
}
OrganizationDTO
orgQuery
=
new
OrganizationDTO
();
orgQuery
.
setUuid
(
organId
);
orgQuery
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
OrganizationDTO
data
=
organizationClient
.
getByUuid
(
orgQuery
).
getData
();
//查询的人的组织 是否是车企
if
(
null
==
data
.
getBizType
())
{
returnMap
.
put
(
"errorMsg"
,
"该用户不是车企"
);
returnMap
.
put
(
"errorCode"
,
10001
);
return
returnMap
;
}
query
.
setVehicleCompany
(
data
.
getBizType
()
==
1
);
Response
<
List
<
EnterpriseRnrPersonNameResponseDTO
>>
listResponse
=
enterpriseClient
.
queryEnterpriseRnrPersonName
(
query
);
if
(!
listResponse
.
getSuccess
())
{
throw
new
CuscUserException
(
listResponse
.
getCode
(),
listResponse
.
getMsg
());
}
// return listResponse.getData().stream().map(responseDTO->{
// EnterpriseRnrPersonDTO rnrPersonDTO = new EnterpriseRnrPersonDTO();
// rnrPersonDTO.setCompanyName(responseDTO.getCompanyName());
// rnrPersonDTO.setCorporationName(responseDTO.getFullName());
// return rnrPersonDTO;
// }).collect(Collectors.toList());
List
<
EnterpriseRnrPersonDTO
>
returnList
=
listResponse
.
getData
().
stream
().
map
(
responseDTO
->
{
EnterpriseRnrPersonDTO
rnrPersonDTO
=
new
EnterpriseRnrPersonDTO
();
rnrPersonDTO
.
setCompanyName
(
responseDTO
.
getCompanyName
());
rnrPersonDTO
.
setCorporationName
(
responseDTO
.
getFullName
());
return
rnrPersonDTO
;
}).
collect
(
Collectors
.
toList
());
if
(
returnList
.
size
()
<=
0
)
{
returnMap
.
put
(
"errorMsg"
,
"该用户未查询相关公司"
);
returnMap
.
put
(
"errorCode"
,
10001
);
return
returnMap
;
}
else
{
returnMap
.
put
(
"errorCode"
,
10000
);
returnMap
.
put
(
"returnList"
,
returnList
);
return
returnMap
;
}
}
@Override
public
void
submitChange
(
EnterpriseCorporationChangeDTO
bean
)
{
EnterpriseChangeRnrPersonDTO
dto
=
new
EnterpriseChangeRnrPersonDTO
();
BeanUtils
.
copyProperties
(
bean
,
dto
);
dto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
dto
.
setCreator
(
UserSubjectUtil
.
getUserId
());
Response
response
=
enterpriseClient
.
changeEnterpriseRnrPerson
(
CuscStringUtils
.
generateUuid
(),
bean
.
getRequestId
(),
dto
);
if
(!
response
.
getSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
}
//转换成RelationDto
private
RnrRelationDTO
turnParams
(
EnterpriseRnrCertificationInfoDTO
dto
,
List
<
VinCardDTO
>
vinCardDTOList
)
{
RnrRelationDTO
rnrRelationDTO
=
new
RnrRelationDTO
();
String
rnrID
=
CuscStringUtils
.
generateUuid
();
String
tenantNo
=
UserSubjectUtil
.
getTenantNo
();
//查询当前用户的组织id
String
orgId
=
userService
.
getOrganId
(
UserSubjectUtil
.
getUserId
(),
tenantNo
);
//租户
rnrRelationDTO
.
setTenantNo
(
tenantNo
);
rnrRelationDTO
.
setIsTrust
(
0
);
// rnrRelationDTO.setIsSecondHandCar(dto.getCustomerType() == 1 ? 1 : 0);
//公司信息
MgRnrCompanyInfoDTO
mgRnrCompanyInfoDTO
=
createCompanyInfoDTO
(
dto
,
rnrID
,
tenantNo
);
//人的信息
MgRnrInfoDTO
mgRnrInfoDTO
=
createRnrInfo
(
dto
,
rnrID
,
tenantNo
,
mgRnrCompanyInfoDTO
.
getUuid
());
mgRnrInfoDTO
.
setOrgId
(
orgId
);
mgRnrInfoDTO
.
setIsTrust
(
0
);
int
orderType
=
0
;
if
(
mgRnrCompanyInfoDTO
.
getIsVehicleCompany
()
==
0
)
{
orderType
=
RnrOrderType
.
COMPANY_NEW_VEHICLE
.
getCode
();
}
else
{
orderType
=
RnrOrderType
.
CARMAKER_NEW_VEHICLE
.
getCode
();
}
//订单信息
RnrOrderDTO
rnrOrderDTO
=
createOrder
(
dto
,
mgRnrInfoDTO
,
mgRnrInfoDTO
.
getUuid
(),
tenantNo
,
orderType
);
rnrOrderDTO
.
setOrgId
(
orgId
);
//卡信息
List
<
MgRnrCardInfoDTO
>
cardInfoDTOS
=
createCardInfoDTOs
(
dto
,
rnrRelationDTO
,
tenantNo
,
rnrID
,
rnrOrderDTO
.
getUuid
(),
vinCardDTOList
);
//文件列表
List
<
MgRnrFileDTO
>
fileDTOS
=
getMgRnrFileDTOs
(
dto
,
new
RnrRelationDTO
(),
mgRnrInfoDTO
.
getUuid
(),
tenantNo
,
mgRnrCompanyInfoDTO
.
getUuid
());
//taglist
List
<
MgRnrTagDTO
>
tagDTOS
=
new
ArrayList
<>();
//实名联系人信息
List
<
MgRnrLiaisonInfoDTO
>
liaisonInfoDTOS
=
new
ArrayList
<>();
rnrRelationDTO
.
setRnrLiaisonList
(
liaisonInfoDTOS
);
rnrRelationDTO
.
setCompanyInfo
(
mgRnrCompanyInfoDTO
);
rnrRelationDTO
.
setInfo
(
mgRnrInfoDTO
);
rnrRelationDTO
.
setCardList
(
cardInfoDTOS
);
rnrRelationDTO
.
setOrder
(
rnrOrderDTO
);
rnrRelationDTO
.
setRnrFileList
(
fileDTOS
);
rnrRelationDTO
.
setRnrTagList
(
tagDTOS
);
return
rnrRelationDTO
;
}
//创建工单
private
RnrOrderDTO
createOrder
(
EnterpriseRnrCertificationInfoDTO
dto
,
MgRnrInfoDTO
rnrInfoDTO
,
String
uuid
,
String
tenNo
,
int
orderType
)
{
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setOrderType
(
orderType
);
rnrOrderDTO
.
setRnrId
(
uuid
);
rnrOrderDTO
.
setAuditType
(
RnrOrderAuditTypeEnum
.
MANUAL
.
getCode
());
rnrOrderDTO
.
setAutoRnr
(
false
);
rnrOrderDTO
.
setIsBatchOrder
(
1
);
rnrOrderDTO
.
setSerialNumber
(
rnrInfoDTO
.
getSerial_number
());
rnrOrderDTO
.
setOrderSource
(
RnrOrderSourceEnum
.
PORTAL
.
getCode
());
rnrOrderDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setTenantNo
(
tenNo
);
rnrOrderDTO
.
setOrderStatus
(
RnrOrderStatusEnum
.
TO_EXAMINE
.
getCode
());
rnrOrderDTO
.
setSendWorkOrder
(
true
);
rnrOrderDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
return
rnrOrderDTO
;
}
//卡信息
private
List
<
MgRnrCardInfoDTO
>
createCardInfoDTOs
(
EnterpriseRnrCertificationInfoDTO
dto
,
RnrRelationDTO
relationDTO
,
String
tenantNo
,
String
rnrId
,
String
uuid
,
List
<
VinCardDTO
>
vinCardDTOS
)
{
List
<
MgRnrCardInfoDTO
>
cardInfoDTOS
=
new
ArrayList
<>();
for
(
VinCardDTO
cardDTO
:
vinCardDTOS
)
{
MgRnrCardInfoDTO
mgRnrCardInfoDTO
=
new
MgRnrCardInfoDTO
();
mgRnrCardInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrCardInfoDTO
.
setIccid
(
cardDTO
.
getIccid
());
mgRnrCardInfoDTO
.
setTenantNo
(
tenantNo
);
mgRnrCardInfoDTO
.
setIotId
(
cardDTO
.
getVin
());
mgRnrCardInfoDTO
.
setRnrId
(
rnrId
);
mgRnrCardInfoDTO
.
setOrderId
(
uuid
);
mgRnrCardInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
cardInfoDTOS
.
add
(
mgRnrCardInfoDTO
);
}
return
cardInfoDTOS
;
}
//公司信息
private
MgRnrCompanyInfoDTO
createCompanyInfoDTO
(
EnterpriseRnrCertificationInfoDTO
dto
,
String
rnrId
,
String
tenNo
)
{
MgRnrCompanyInfoDTO
mgRnrCompanyInfoDTO
=
new
MgRnrCompanyInfoDTO
();
mgRnrCompanyInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrCompanyInfoDTO
.
setRnrId
(
rnrId
);
mgRnrCompanyInfoDTO
.
setCompanyCertAddress
(
dto
.
getCompanyCertAddress
());
mgRnrCompanyInfoDTO
.
setCompanyCertNumber
(
dto
.
getCompanyCertNumber
());
mgRnrCompanyInfoDTO
.
setCompanyCertType
(
dto
.
getCompanyCertType
());
mgRnrCompanyInfoDTO
.
setCompanyContactAddress
(
dto
.
getCompanyContactAddress
());
mgRnrCompanyInfoDTO
.
setCompanyName
(
dto
.
getCompanyName
());
mgRnrCompanyInfoDTO
.
setCompanyType
(
dto
.
getCompanyType
());
mgRnrCompanyInfoDTO
.
setIndustryType
(
dto
.
getIndustryType
());
mgRnrCompanyInfoDTO
.
setTenantNo
(
tenNo
);
mgRnrCompanyInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrCompanyInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrCompanyInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
//是否是车企,数据库默认值是0
if
(
dto
.
getIsVehicleCompany
()
==
null
)
{
dto
.
setIsVehicleCompany
(
0
);
}
mgRnrCompanyInfoDTO
.
setIsVehicleCompany
(
dto
.
getIsVehicleCompany
());
return
mgRnrCompanyInfoDTO
;
}
//人信息
private
MgRnrInfoDTO
createRnrInfo
(
EnterpriseRnrCertificationInfoDTO
dto
,
String
rnrId
,
String
tenantNo
,
String
uuid
)
{
MgRnrInfoDTO
mgRnrInfoDTO
=
new
MgRnrInfoDTO
();
mgRnrInfoDTO
.
setUuid
(
rnrId
);
mgRnrInfoDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
mgRnrInfoDTO
.
setSerial_number
(
CuscStringUtils
.
generateUuid
());
mgRnrInfoDTO
.
setIsCompany
(
1
);
mgRnrInfoDTO
.
setCertAddress
(
dto
.
getCorporationCertAddress
());
mgRnrInfoDTO
.
setCertType
(
dto
.
getCorporationCertType
());
mgRnrInfoDTO
.
setCertNumber
(
dto
.
getCorporationCertNumber
());
mgRnrInfoDTO
.
setContactAddress
(
dto
.
getCorporationContactAddress
());
mgRnrInfoDTO
.
setFullName
(
dto
.
getCorporationName
());
mgRnrInfoDTO
.
setGender
(
Integer
.
valueOf
(
dto
.
getCorporationGender
()));
mgRnrInfoDTO
.
setPhone
(
dto
.
getCorporationPhone
());
mgRnrInfoDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
mgRnrInfoDTO
.
setEffectiveDate
(
DateUtils
.
parseDate
(
dto
.
getCorporationCertEffectiveDate
(),
"yyyy-MM-dd"
));
mgRnrInfoDTO
.
setExpiredDate
(
dto
.
getCorporationCertExpirationDate
());
//mgRnrInfoDTO.setUuid(CuscStringUtils.generateUuid());
mgRnrInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrInfoDTO
.
setIsCompany
(
1
);
mgRnrInfoDTO
.
setRnrCompanyId
(
uuid
);
mgRnrInfoDTO
.
setRnrStatus
(
0
);
mgRnrInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
return
mgRnrInfoDTO
;
}
private
List
<
MgRnrFileDTO
>
getMgRnrFileDTOs
(
EnterpriseRnrCertificationInfoDTO
requestDTO
,
RnrRelationDTO
rnrRelationDTO
,
String
uuid
,
String
tenNo
,
String
companyId
)
{
List
<
MgRnrFileDTO
>
mgRnrFileDTOS
=
new
ArrayList
<>();
//企业实名认证授权书
List
<
String
>
authorizationLetterPic
=
requestDTO
.
getAuthorizationLetterPic
();
for
(
int
i
=
0
;
i
<
authorizationLetterPic
.
size
();
i
++)
{
mgRnrFileDTOS
.
add
(
newFileDTO
(
rnrRelationDTO
,
authorizationLetterPic
.
get
(
i
),
RnrFileType
.
ENTERPRISE_AUTH_FILE
.
getCode
(),
"0"
,
uuid
,
tenNo
,
companyId
));
}
//企业证件照
List
<
String
>
licenseImages
=
requestDTO
.
getLicenseImages
();
for
(
int
i
=
0
;
i
<
licenseImages
.
size
();
i
++)
{
mgRnrFileDTOS
.
add
(
newFileDTO
(
rnrRelationDTO
,
licenseImages
.
get
(
i
),
RnrFileType
.
ENTERPRISE_PIC
.
getCode
(),
"0"
,
uuid
,
tenNo
,
companyId
));
}
//企业照片
//String enterprisePic = requestDTO.getLicenseImages();
//mgRnrFileDTOS.add(newFileDTO(rnrRelationDTO,enterprisePic,RnrFileType.ENTERPRISE_PIC.getCode(),"0",uuid,tenNo));
//责任人证件照
List
<
String
>
corporationPhotoPic
=
requestDTO
.
getCorporationPhotoPic
();
for
(
int
i
=
0
;
i
<
corporationPhotoPic
.
size
();
i
++)
{
int
index
=
0
;
if
(
i
!=
0
)
{
index
=
1
;
}
//@皮豆 com.cusc.nirvana.user.rnr.enterprise.service.impl.EnterpriseRnrServiceImpl#getFileType
//这个方法直接用 com.cusc.nirvana.user.rnr.enterprise.util.FileUtil#getFileType这个方法替换就好了
mgRnrFileDTOS
.
add
(
newFileDTO
(
rnrRelationDTO
,
corporationPhotoPic
.
get
(
i
),
FileUtil
.
getFileType
(
requestDTO
.
getCorporationCertType
(),
index
),
"0"
,
uuid
,
tenNo
,
companyId
));
}
//String corporationCertFrontPic = corporationPhotoPic.get(0);
//mgRnrFileDTOS.add(newFileDTO(rnrRelationDTO,corporationCertFrontPic,getFileType(requestDTO.getCorporationCertType(),1),"0",uuid,tenNo));
//String corporationCertBackPic = corporationPhotoPic.get(1);
//mgRnrFileDTOS.add(newFileDTO(rnrRelationDTO,corporationCertBackPic,getFileType(requestDTO.getCorporationCertType(),0),"0",uuid,tenNo));
//活体视频
if
(
StringUtils
.
isNotBlank
(
requestDTO
.
getLiveVerificationVideo
()))
{
mgRnrFileDTOS
.
add
(
newFileDTO
(
rnrRelationDTO
,
requestDTO
.
getLiveVerificationVideo
(),
RnrFileType
.
LIVENESS_VIDEO
.
getCode
(),
"0"
,
uuid
,
tenNo
,
companyId
));
}
//责任告知书
if
(!
CollectionUtils
.
isEmpty
(
requestDTO
.
getDutyPic
()))
{
for
(
String
duty
:
requestDTO
.
getDutyPic
())
{
mgRnrFileDTOS
.
add
(
newFileDTO
(
rnrRelationDTO
,
duty
,
RnrFileType
.
DUTY_FILE
.
getCode
(),
"0"
,
uuid
,
tenNo
,
companyId
));
}
}
//入网合同
if
(!
CollectionUtils
.
isEmpty
(
requestDTO
.
getContractPic
()))
{
for
(
String
contact
:
requestDTO
.
getContractPic
())
{
mgRnrFileDTOS
.
add
(
newFileDTO
(
rnrRelationDTO
,
contact
,
RnrFileType
.
VEHUCLE_BIND
.
getCode
(),
"0"
,
uuid
,
tenNo
,
companyId
));
}
}
return
mgRnrFileDTOS
;
}
private
MgRnrFileDTO
newFileDTO
(
RnrRelationDTO
rnrRelationDTO
,
String
pic
,
Integer
fileType
,
String
liasionId
,
String
uuid
,
String
tenNo
,
String
companyId
)
{
MgRnrFileDTO
mgRnrFileDTO
=
new
MgRnrFileDTO
();
mgRnrFileDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrFileDTO
.
setRnrId
(
uuid
);
mgRnrFileDTO
.
setFileType
(
fileType
);
mgRnrFileDTO
.
setFileSystemId
(
pic
);
mgRnrFileDTO
.
setTenantNo
(
tenNo
);
mgRnrFileDTO
.
setLiaisonId
(
liasionId
);
mgRnrFileDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrFileDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrFileDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
mgRnrFileDTO
.
setTenantNo
(
tenNo
);
mgRnrFileDTO
.
setRnrCompanyId
(
companyId
);
return
mgRnrFileDTO
;
}
/**
* 获取文件类型
*
* @param certType 证书类型
* @param index 索引
*/
private
Integer
getFileType
(
String
certType
,
int
index
)
{
CertTypeEnum
certTypeEnum
=
Arrays
.
stream
(
CertTypeEnum
.
values
())
.
filter
(
c
->
StringUtils
.
equalsIgnoreCase
(
c
.
getCode
(),
certType
))
.
findFirst
().
get
();
switch
(
certTypeEnum
)
{
case
IDCARD:
if
(
index
==
0
)
return
RnrFileType
.
IDENTITY_CARD_BACK
.
getCode
();
if
(
index
==
1
)
return
RnrFileType
.
IDENTITY_CARD_FRONT
.
getCode
();
return
null
;
case
PLA:
if
(
index
==
0
)
return
RnrFileType
.
OFFICIAL_CARD_FRONT
.
getCode
();
if
(
index
==
1
)
return
RnrFileType
.
OFFICIAL_CARD_BACK
.
getCode
();
case
HKIDCARD:
if
(
index
==
0
)
return
RnrFileType
.
HK_MACAO_PASSPORT_FRONT
.
getCode
();
if
(
index
==
1
)
return
RnrFileType
.
HK_MACAO_PASSPORT_BACK
.
getCode
();
case
TAIBAOZHENG:
if
(
index
==
0
)
return
RnrFileType
.
TAIWAN_CARD_FRONT
.
getCode
();
if
(
index
==
1
)
return
RnrFileType
.
TAIWAN_CARD_BACK
.
getCode
();
case
PASSPORT:
if
(
index
==
0
)
return
RnrFileType
.
FOREIGN_NATIONAL_PASSPORT_FRONT
.
getCode
();
if
(
index
==
1
)
return
RnrFileType
.
FOREIGN_NATIONAL_PASSPORT_BACK
.
getCode
();
case
POLICEPAPER:
if
(
index
==
0
)
return
RnrFileType
.
POLICE_CARD_FRONT
.
getCode
();
if
(
index
==
1
)
return
RnrFileType
.
POLICE_CARD_BACK
.
getCode
();
case
HKRESIDENCECARD:
if
(
index
==
0
)
return
RnrFileType
.
HK_MACAO_RESIDENCE_PERMIT_FRONT
.
getCode
();
if
(
index
==
1
)
return
RnrFileType
.
HK_MACAO_RESIDENCE_PERMIT_BACK
.
getCode
();
case
TWRESIDENCECARD:
if
(
index
==
0
)
return
RnrFileType
.
TAIWAN_RESIDENCE_PERMIT_FRONT
.
getCode
();
if
(
index
==
1
)
return
RnrFileType
.
TAIWAN_RESIDENCE_PERMIT_BACK
.
getCode
();
case
RESIDENCE:
if
(
index
==
0
)
return
RnrFileType
.
RESIDENCE_BOOKLET_FRONT
.
getCode
();
if
(
index
==
1
)
return
RnrFileType
.
RESIDENCE_BOOKLET_BACK
.
getCode
();
default
:
return
null
;
}
}
@Override
public
EnterpriseRnrH5RespDTO
submitRnrH5
(
EnterpriseRnrH5RequestDTO
dto
)
{
if
(
dto
.
getVinList
().
stream
().
distinct
().
count
()
!=
dto
.
getVinList
().
size
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"请不要输入重复的vin"
);
}
//检查短信验证码
SmsRequestDTO
smsRequestDTO
=
new
SmsRequestDTO
();
smsRequestDTO
.
setPhone
(
dto
.
getCorporationPhone
());
smsRequestDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
smsRequestDTO
.
setBizType
(
BizTypeEnum
.
RNR
.
getCode
());
smsRequestDTO
.
setCaptcha
(
dto
.
getVerificationCode
());
Response
smsResponse
=
smsService
.
checkSmsCaptcha
(
smsRequestDTO
);
if
(!
smsResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
smsResponse
.
getCode
(),
smsResponse
.
getMsg
());
}
EnterpriseRnrCertificationInfoDTO
certificationInfoDTO
=
new
EnterpriseRnrCertificationInfoDTO
();
BeanUtils
.
copyProperties
(
dto
,
certificationInfoDTO
);
//构建relationDto
String
rnrId
=
CuscStringUtils
.
generateUuid
();
String
tenantNo
=
UserSubjectUtil
.
getTenantNo
();
String
orgId
=
userService
.
getOrganId
(
UserSubjectUtil
.
getUserId
(),
tenantNo
);
//公司信息
MgRnrCompanyInfoDTO
mgRnrCompanyInfoDTO
=
createCompanyInfoDTO
(
certificationInfoDTO
,
rnrId
,
tenantNo
);
//rnrInfo
MgRnrInfoDTO
rnrInfo
=
createRnrInfo
(
certificationInfoDTO
,
rnrId
,
tenantNo
,
mgRnrCompanyInfoDTO
.
getUuid
());
rnrInfo
.
setIsTrust
(
0
);
rnrInfo
.
setOrgId
(
orgId
);
//rnrOrder
RnrOrderDTO
rnrOrderDTO
=
createOrder
(
certificationInfoDTO
,
rnrInfo
,
rnrInfo
.
getUuid
(),
tenantNo
,
RnrOrderType
.
COMPANY_NEW_VEHICLE
.
getCode
());
rnrOrderDTO
.
setOrgId
(
orgId
);
//文件列表
List
<
MgRnrFileDTO
>
fileDTOList
=
getMgRnrFileDTOs
(
certificationInfoDTO
,
null
,
rnrId
,
tenantNo
,
mgRnrCompanyInfoDTO
.
getUuid
());
//卡列表
List
<
String
>
vinList
=
dto
.
getVinList
();
List
<
MgRnrCardInfoDTO
>
cardInfoDTOList
=
createCardInfoDtoByVinList
(
vinList
,
tenantNo
,
rnrId
,
rnrOrderDTO
.
getUuid
());
RnrRelationDTO
rnrRelationDTO
=
new
RnrRelationDTO
();
rnrRelationDTO
.
setCompanyInfo
(
mgRnrCompanyInfoDTO
);
rnrRelationDTO
.
setInfo
(
rnrInfo
);
rnrRelationDTO
.
setCardList
(
cardInfoDTOList
);
rnrRelationDTO
.
setOrder
(
rnrOrderDTO
);
rnrRelationDTO
.
setRnrFileList
(
fileDTOList
);
rnrRelationDTO
.
getOrder
().
setOrderSource
(
RnrOrderSourceEnum
.
H5
.
getCode
());
Response
response
=
enterpriseClient
.
submitH5
(
rnrRelationDTO
);
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
EnterpriseRnrH5RespDTO
rnrH5RespDTO
=
new
EnterpriseRnrH5RespDTO
();
LiveLoginReqDTO
loginUrlDto
=
new
LiveLoginReqDTO
();
loginUrlDto
.
setOrderNo
(
rnrOrderDTO
.
getUuid
());
if
(
"PAD"
.
equals
(
dto
.
getSource
()))
{
loginUrlDto
.
setCallBackUrl
(
frontEnterprisePadCallBackUrl
);
}
else
{
loginUrlDto
.
setCallBackUrl
(
frontEnterpriseH5CallBackUrl
);
}
//调用云端接口
Response
<
LiveLoginRespDTO
>
h5LiveLoginUrl
=
fpRnrClient
.
h5LiveLoginUrl
(
loginUrlDto
);
if
(
h5LiveLoginUrl
.
isSuccess
())
{
rnrH5RespDTO
.
setH5LivenessUrl
(
h5LiveLoginUrl
.
getData
().
getH5LiveLoginUrl
());
}
rnrH5RespDTO
.
setRnrId
(
rnrId
);
rnrH5RespDTO
.
setOrderId
(
rnrOrderDTO
.
getUuid
());
return
rnrH5RespDTO
;
}
@Override
public
EnterpriseRnrH5CallBackRespDTO
afreshLivenessUrl
(
LivenessCallbackReqDTO
bean
)
{
EnterpriseRnrH5CallBackRespDTO
respDTO
=
new
EnterpriseRnrH5CallBackRespDTO
();
boolean
success
=
bean
.
getCode
().
equals
(
SUCCESS_CODE
);
if
(
success
)
{
//todo 调用云端接口
LiveLoginReqDTO
liveLoginReqDTO
=
new
LiveLoginReqDTO
();
liveLoginReqDTO
.
setOrderNo
(
bean
.
getOrderNo
());
Response
<
LivenessResultDTO
>
livenessResult
=
fpRnrClient
.
h5LivenessResult
(
liveLoginReqDTO
);
if
(
null
==
livenessResult
||
!
livenessResult
.
isSuccess
()
||
null
==
livenessResult
.
getData
())
{
//没有查询到 活体视屏 和 照片 再次拉起腾讯活体H5
LiveLoginReqDTO
loginUrlDto
=
new
LiveLoginReqDTO
();
loginUrlDto
.
setOrderNo
(
bean
.
getOrderNo
());
loginUrlDto
.
setCallBackUrl
(
frontEnterpriseH5CallBackUrl
);
// 调用云端接口
Response
<
LiveLoginRespDTO
>
h5LiveLoginUrl
=
fpRnrClient
.
h5LiveLoginUrl
(
loginUrlDto
);
respDTO
.
setStatus
(
2
);
if
(
h5LiveLoginUrl
.
isSuccess
())
{
respDTO
.
setH5LivenessUrl
(
h5LiveLoginUrl
.
getData
().
getH5LiveLoginUrl
());
}
}
else
{
LivenessResultDTO
livenessResultData
=
livenessResult
.
getData
();
EnterpriseH5CallBackRequestDTO
callBackDto
=
new
EnterpriseH5CallBackRequestDTO
();
callBackDto
.
setOrderNo
(
bean
.
getOrderNo
());
String
[]
livenessPhotos
=
new
String
[
2
];
livenessPhotos
[
0
]
=
livenessResultData
.
getPhotoId
();
livenessPhotos
[
1
]
=
livenessResultData
.
getPhotoId
();
callBackDto
.
setLivenessPicFileId
(
livenessPhotos
);
callBackDto
.
setVideFileId
(
livenessResultData
.
getVideoFileId
());
Response
<
Integer
>
response
=
enterpriseClient
.
enterpriseRnrH5CallBack
(
callBackDto
);
if
(!
response
.
isSuccess
()
||
null
==
response
.
getData
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
Integer
data
=
response
.
getData
();
respDTO
.
setStatus
(
data
);
}
}
else
{
LiveLoginReqDTO
loginUrlDto
=
new
LiveLoginReqDTO
();
loginUrlDto
.
setOrderNo
(
bean
.
getOrderNo
());
loginUrlDto
.
setCallBackUrl
(
frontEnterpriseH5CallBackUrl
);
//调用云端接口
Response
<
LiveLoginRespDTO
>
h5LiveLoginUrl
=
fpRnrClient
.
h5LiveLoginUrl
(
loginUrlDto
);
if
(
h5LiveLoginUrl
.
isSuccess
())
{
respDTO
.
setH5LivenessUrl
(
h5LiveLoginUrl
.
getData
().
getH5LiveLoginUrl
());
}
respDTO
.
setStatus
(
2
);
//需要修改数据状态
//RnrOrderDTO orderDTO = new RnrOrderDTO();
//orderDTO.setUuid(bean.getOrderNo());
//fpRnrClient.updateRnrInValid(orderDTO);
}
return
respDTO
;
}
private
List
<
MgRnrCardInfoDTO
>
createCardInfoDtoByVinList
(
List
<
String
>
vinList
,
String
tenantNo
,
String
rnrId
,
String
orderId
)
{
List
<
MgRnrCardInfoDTO
>
cardInfoDTOList
=
Collections
.
synchronizedList
(
new
ArrayList
<>());
String
creator
=
UserSubjectUtil
.
getUserId
();
String
operator
=
UserSubjectUtil
.
getUserId
();
vinList
.
parallelStream
().
forEach
(
vin
->
{
VinCardQueryDTO
dto
=
new
VinCardQueryDTO
();
dto
.
setVin
(
vin
);
Response
<
VinCardResultDTO
>
vinCardResultResponse
=
checkClient
.
queryUnBindCardByVin
(
dto
);
log
.
info
(
"createCardInfoDtoByVinList vin = {},reponse = {}"
,
vin
,
JSONObject
.
toJSONString
(
vinCardResultResponse
));
if
(
null
==
vinCardResultResponse
||
!
vinCardResultResponse
.
isSuccess
()
||
null
==
vinCardResultResponse
.
getData
()
||
CollectionUtils
.
isEmpty
(
vinCardResultResponse
.
getData
().
getIccidList
()))
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"未查询到卡信息"
);
}
List
<
String
>
iccidList
=
vinCardResultResponse
.
getData
().
getIccidList
();
for
(
String
iccid
:
iccidList
)
{
MgRnrCardInfoDTO
mgRnrCardInfoDTO
=
new
MgRnrCardInfoDTO
();
mgRnrCardInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrCardInfoDTO
.
setIccid
(
iccid
);
mgRnrCardInfoDTO
.
setTenantNo
(
tenantNo
);
mgRnrCardInfoDTO
.
setIotId
(
vin
);
mgRnrCardInfoDTO
.
setRnrId
(
rnrId
);
mgRnrCardInfoDTO
.
setOrderId
(
orderId
);
mgRnrCardInfoDTO
.
setCreator
(
creator
);
mgRnrCardInfoDTO
.
setOperator
(
operator
);
mgRnrCardInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
cardInfoDTOList
.
add
(
mgRnrCardInfoDTO
);
}
});
return
cardInfoDTOList
;
}
@Override
public
EnterpriseRnrH5RespDTO
submitRnrWithFile
(
EnterpriseRnrH5FileRequestDTO
dto
)
{
//检查短信验证码
SmsRequestDTO
smsRequestDTO
=
new
SmsRequestDTO
();
smsRequestDTO
.
setPhone
(
dto
.
getCorporationPhone
());
smsRequestDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
smsRequestDTO
.
setBizType
(
BizTypeEnum
.
RNR
.
getCode
());
smsRequestDTO
.
setCaptcha
(
dto
.
getVerificationCode
());
Response
smsResponse
=
smsService
.
checkSmsCaptcha
(
smsRequestDTO
);
if
(!
smsResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
smsResponse
.
getCode
(),
smsResponse
.
getMsg
());
}
//验证车卡关系
Response
<
List
<
VinCardDTO
>>
listResponse
=
vehicleCardService
.
checkIccidList
(
dto
.
getFileId
());
log
.
info
(
"验证车卡关系"
,
dto
);
if
(!
listResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
listResponse
.
getCode
(),
listResponse
.
getMsg
());
}
EnterpriseRnrCertificationInfoDTO
requestDto
=
new
EnterpriseRnrCertificationInfoDTO
();
BeanUtils
.
copyProperties
(
dto
,
requestDto
);
RnrRelationDTO
rnrRelationDTO
=
turnParams
(
requestDto
,
listResponse
.
getData
());
rnrRelationDTO
.
getOrder
().
setOrderSource
(
RnrOrderSourceEnum
.
H5
.
getCode
());
Response
response
=
enterpriseClient
.
submitH5
(
rnrRelationDTO
);
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
EnterpriseRnrH5RespDTO
rnrH5RespDTO
=
new
EnterpriseRnrH5RespDTO
();
LiveLoginReqDTO
loginUrlDto
=
new
LiveLoginReqDTO
();
loginUrlDto
.
setOrderNo
(
rnrRelationDTO
.
getOrder
().
getUuid
());
if
(
"PAD"
.
equals
(
dto
.
getSource
()))
{
loginUrlDto
.
setCallBackUrl
(
frontEnterprisePadCallBackUrl
);
}
else
{
loginUrlDto
.
setCallBackUrl
(
frontEnterpriseH5CallBackUrl
);
}
//调用云端接口
Response
<
LiveLoginRespDTO
>
h5LiveLoginUrl
=
fpRnrClient
.
h5LiveLoginUrl
(
loginUrlDto
);
if
(
h5LiveLoginUrl
.
isSuccess
())
{
rnrH5RespDTO
.
setH5LivenessUrl
(
h5LiveLoginUrl
.
getData
().
getH5LiveLoginUrl
());
}
rnrH5RespDTO
.
setRnrId
(
rnrRelationDTO
.
getInfo
().
getUuid
());
rnrH5RespDTO
.
setOrderId
(
rnrRelationDTO
.
getOrder
().
getUuid
());
return
rnrH5RespDTO
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/EnterpriseUnBindServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.RnrStatusEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.EnterpriseUnBindDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.VinCheckDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.VinCheckResponseDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.EnterpriseUnBindService
;
import
com.cusc.nirvana.user.rnr.fp.client.EnterpriseRnrClient
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCardInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.RnrOrderClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrBizzTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderStatusEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrStatus
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.function.Function
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
/**
* @className: EnterpriseUnBindServiceImpl
* @description: 企业解绑
* @author: jk
* @date: 2022/6/16 18:23
* @version: 1.0
**/
@Service
@Slf4j
public
class
EnterpriseUnBindServiceImpl
implements
EnterpriseUnBindService
{
@Resource
private
MgRnrCardInfoClient
mgRnrCardInfoClient
;
@Resource
private
MgRnrInfoClient
mgRnrInfoClient
;
@Resource
private
RnrOrderClient
rnrOrderClient
;
@Resource
private
EnterpriseRnrClient
enterpriseRnrClient
;
/**
* @author: jk
* @description: 参数解绑校验
* @date: 2022/6/16 18:26
*/
@Override
public
VinCheckResponseDTO
enterpriseUnBindCheck
(
EnterpriseUnBindDTO
dto
)
{
VinCheckResponseDTO
vinCheckResponseDTO
=
new
VinCheckResponseDTO
();
if
(!
CollectionUtils
.
isEmpty
(
dto
.
getVinList
())
&&
dto
.
getVinList
().
stream
().
distinct
().
count
()
!=
dto
.
getVinList
().
size
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"请不要输入同样的Vin"
);
}
MgRnrCardInfoDTO
mgRnrCardInfoDTO
=
new
MgRnrCardInfoDTO
();
mgRnrCardInfoDTO
.
setVinList
(
dto
.
getVinList
());
//根据vin查询VIN是否存在且实名
Response
<
List
<
MgRnrCardInfoDTO
>>
responseList
=
mgRnrCardInfoClient
.
queryBindListByVinsAndIccids
(
mgRnrCardInfoDTO
);
if
(!
responseList
.
isSuccess
())
{
throw
new
CuscUserException
(
responseList
.
getCode
(),
responseList
.
getMsg
());
}
if
(
CollectionUtils
.
isEmpty
(
responseList
.
getData
())){
throw
new
CuscUserException
(
""
,
"未查到实名数据!"
);
}
List
<
MgRnrCardInfoDTO
>
mgRnrCardInfoDTOList
=
responseList
.
getData
();
boolean
hasInitCard
=
mgRnrCardInfoDTOList
.
stream
().
anyMatch
(
card
->
RnrStatus
.
INIT
.
getCode
()
==
card
.
getRnrStatus
());
if
(
hasInitCard
)
{
throw
new
CuscUserException
(
""
,
"存在未完成的工单信息"
);
}
//转为map
Map
<
String
,
MgRnrCardInfoDTO
>
mgRnrCardInfoMap
=
mgRnrCardInfoDTOList
.
stream
().
collect
(
Collectors
.
toMap
(
MgRnrCardInfoDTO:
:
getIotId
,
Function
.
identity
(),
(
key1
,
key2
)
->
key2
));
List
<
String
>
vinList
=
dto
.
getVinList
();
//过滤出参数是否都存在
List
<
VinCheckDTO
>
vinCheckDTOMap
=
vinList
.
stream
().
map
(
a
->
{
VinCheckDTO
vinCheckDetailDTOs
=
new
VinCheckDTO
();
if
(
null
==
mgRnrCardInfoMap
.
get
(
a
))
{
vinCheckDetailDTOs
.
setVin
(
a
);
vinCheckDetailDTOs
.
setCheckResult
(
false
);
vinCheckDetailDTOs
.
setErrorMsg
(
"VIN不存在实名卡"
);
}
return
vinCheckDetailDTOs
;
}).
filter
(
b
->
null
!=
b
&&
!
StringUtils
.
isEmpty
(
b
.
getVin
())).
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
vinCheckDTOMap
))
{
vinCheckResponseDTO
.
setList
(
vinCheckDTOMap
);
return
vinCheckResponseDTO
;
}
// List<MgRnrCardInfoDTO> distinctList = mgRnrCardInfoDTOList.stream().filter(distinctByKey(p->p.getRnrId())).collect(Collectors.toList());
// //获取持卡人集合去重
List
<
String
>
rnrList
=
mgRnrCardInfoDTOList
.
stream
().
distinct
().
map
(
MgRnrCardInfoDTO:
:
getRnrId
).
collect
(
Collectors
.
toList
());
MgRnrInfoDTO
mgRnrInfoDTO
=
new
MgRnrInfoDTO
();
mgRnrInfoDTO
.
setUuidList
(
rnrList
);
//查询info信息
Response
<
List
<
MgRnrInfoDTO
>>
mgRnrInfoList
=
mgRnrInfoClient
.
queryByList
(
mgRnrInfoDTO
);
if
(!
mgRnrInfoList
.
isSuccess
())
{
throw
new
CuscUserException
(
mgRnrInfoList
.
getCode
(),
mgRnrInfoList
.
getMsg
());
}
List
<
MgRnrInfoDTO
>
mgRnrInfoDTOList
=
mgRnrInfoList
.
getData
();
//根据姓名+身份证号码分组
Map
<
String
,
List
<
MgRnrInfoDTO
>>
rnrInfoMap
=
mgRnrInfoDTOList
.
stream
().
collect
(
Collectors
.
groupingBy
(
this
::
getGroupKey
));
//如果map大于1,说明VIN属于不同联系人
if
(
null
!=
rnrInfoMap
&&
rnrInfoMap
.
size
()
>
1
)
{
List
<
VinCheckDTO
>
vinCheckDTOS
=
vinList
.
stream
().
map
(
a
->
{
VinCheckDTO
vinCheckDetailDTO
=
new
VinCheckDTO
();
vinCheckDetailDTO
.
setVin
(
a
);
vinCheckDetailDTO
.
setCheckResult
(
false
);
vinCheckDetailDTO
.
setErrorMsg
(
"VIN下卡不是同一个人的"
);
return
vinCheckDetailDTO
;
}).
filter
(
a
->!
StringUtils
.
isEmpty
(
a
.
getVin
())).
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
vinCheckDTOS
))
{
vinCheckResponseDTO
.
setList
(
vinCheckDTOS
);
return
vinCheckResponseDTO
;
}
}
//表示校验通过了
List
<
VinCheckDTO
>
vinCheckDTOS
=
vinList
.
stream
().
map
(
a
->
{
VinCheckDTO
vinCheckDetailDTO
=
new
VinCheckDTO
();
vinCheckDetailDTO
.
setVin
(
a
);
vinCheckDetailDTO
.
setCheckResult
(
true
);
return
vinCheckDetailDTO
;
}).
filter
(
a
->!
StringUtils
.
isEmpty
(
a
.
getVin
())).
collect
(
Collectors
.
toList
());
vinCheckResponseDTO
.
setList
(
vinCheckDTOS
);
vinCheckResponseDTO
.
setPhone
(
mgRnrInfoList
.
getData
().
get
(
0
).
getPhone
());
vinCheckResponseDTO
.
setUserName
(
mgRnrInfoList
.
getData
().
get
(
0
).
getFullName
());
return
vinCheckResponseDTO
;
}
/**
* @author: jk
* @description: 提交解绑信息
* @date: 2022/6/17 10:44
* @version: 1.0
*/
@Override
public
Response
submitUnBind
(
EnterpriseUnBindDTO
dto
)
{
VinCheckResponseDTO
response
=
this
.
enterpriseUnBindCheck
(
dto
);
List
<
VinCheckDTO
>
list
=
response
.
getList
();
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
for
(
VinCheckDTO
VinCheckDTO
:
list
)
{
if
(!
VinCheckDTO
.
getCheckResult
())
{
throw
new
CuscUserException
(
""
,
VinCheckDTO
.
getErrorMsg
());
}
}
}
// if(!response.isSuccess()){
// throw new CuscUserException(response.getCode(),response.getMsg());
// }
Response
<
RnrRelationDTO
>
rnrRelationDTOResponse
=
convertToRelationDTO
(
dto
);
if
(!
rnrRelationDTOResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
rnrRelationDTOResponse
.
getCode
(),
rnrRelationDTOResponse
.
getMsg
());
}
Response
enterpriseFpResponse
=
enterpriseRnrClient
.
enterpriseUnBind
(
rnrRelationDTOResponse
.
getData
());
if
(!
enterpriseFpResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
enterpriseFpResponse
.
getCode
(),
enterpriseFpResponse
.
getMsg
());
}
dto
.
setOrderId
(
rnrRelationDTOResponse
.
getData
().
getOrder
().
getUuid
());
return
Response
.
createSuccess
(
""
,
dto
);
}
//组装信息
private
Response
<
RnrRelationDTO
>
convertToRelationDTO
(
EnterpriseUnBindDTO
dto
)
{
String
rnrID
=
CuscStringUtils
.
generateUuid
();
String
orderID
=
CuscStringUtils
.
generateUuid
();
String
carID
=
CuscStringUtils
.
generateUuid
();
RnrRelationDTO
rnrRelationDTO
=
new
RnrRelationDTO
();
//查询卡信息
MgRnrCardInfoDTO
mgRnrCardInfo
=
new
MgRnrCardInfoDTO
();
mgRnrCardInfo
.
setVinList
(
dto
.
getVinList
());
Response
<
List
<
MgRnrCardInfoDTO
>>
mgRnrCardInfoList
=
mgRnrCardInfoClient
.
queryBindListByVinsAndIccids
(
mgRnrCardInfo
);
if
(!
mgRnrCardInfoList
.
isSuccess
())
{
throw
new
CuscUserException
(
mgRnrCardInfoList
.
getCode
(),
mgRnrCardInfoList
.
getMsg
());
}
if
(
CollectionUtils
.
isEmpty
(
mgRnrCardInfoList
.
getData
())){
throw
new
CuscUserException
(
com
.
cusc
.
nirvana
.
user
.
rnr
.
enterprise
.
constants
.
ResponseCode
.
RNR_CAR_INFO_IS_NULL
.
getCode
(),
com
.
cusc
.
nirvana
.
user
.
rnr
.
enterprise
.
constants
.
ResponseCode
.
RNR_CAR_INFO_IS_NULL
.
getMsg
());
}
List
<
MgRnrCardInfoDTO
>
mgRnrCardInfoDTOList
=
mgRnrCardInfoList
.
getData
();
//获取rnrID集合
List
<
String
>
rnrIdList
=
mgRnrCardInfoDTOList
.
stream
().
map
(
MgRnrCardInfoDTO:
:
getRnrId
).
collect
(
Collectors
.
toList
());
//获取orderId 集合
List
<
String
>
orderIdList
=
mgRnrCardInfoDTOList
.
stream
().
map
(
MgRnrCardInfoDTO:
:
getOrderId
).
collect
(
Collectors
.
toList
());
//info信息
MgRnrInfoDTO
mgRnrInfoDTO
=
getMgRnrInfoDTO
(
rnrID
,
rnrIdList
);
rnrRelationDTO
.
setInfo
(
mgRnrInfoDTO
);
//工单信息
RnrOrderDTO
rnrOrderDTO
=
getMgRnrOrderDTO
(
orderID
,
rnrID
,
orderIdList
);
rnrRelationDTO
.
setOrder
(
rnrOrderDTO
);
//carInfo
List
<
MgRnrCardInfoDTO
>
mgRnrCardInfoArray
=
getMgRnrCardDTOs
(
mgRnrCardInfoDTOList
,
rnrRelationDTO
);
rnrRelationDTO
.
setCardList
(
mgRnrCardInfoArray
);
rnrRelationDTO
.
setCarNumber
(
dto
.
getVinList
().
size
());
return
Response
.
createSuccess
(
rnrRelationDTO
);
}
/**
* 获取实名主体信息
*
* @param rnrIdList 请求消息
*/
private
MgRnrInfoDTO
getMgRnrInfoDTO
(
String
rnrID
,
List
<
String
>
rnrIdList
)
{
MgRnrInfoDTO
mgRnrInfoDTO
=
new
MgRnrInfoDTO
();
mgRnrInfoDTO
.
setUuidList
(
rnrIdList
);
mgRnrInfoDTO
.
setRnrStatus
(
RnrStatusEnum
.
REAL_NAME
.
getCode
());
//查询info
Response
<
List
<
MgRnrInfoDTO
>>
mgRnrInfoList
=
mgRnrInfoClient
.
queryByList
(
mgRnrInfoDTO
);
if
(!
mgRnrInfoList
.
isSuccess
())
{
throw
new
CuscUserException
(
mgRnrInfoList
.
getCode
(),
mgRnrInfoList
.
getMsg
());
}
if
(
CollectionUtils
.
isEmpty
(
mgRnrInfoList
.
getData
())){
throw
new
CuscUserException
(
com
.
cusc
.
nirvana
.
user
.
rnr
.
enterprise
.
constants
.
ResponseCode
.
RNR_INFO_IS_NULL
.
getCode
(),
com
.
cusc
.
nirvana
.
user
.
rnr
.
enterprise
.
constants
.
ResponseCode
.
RNR_INFO_IS_NULL
.
getMsg
());
}
//获取info信息
MgRnrInfoDTO
MgRnrInfoDTOList
=
mgRnrInfoList
.
getData
().
get
(
0
);
MgRnrInfoDTOList
.
setUuid
(
rnrID
);
MgRnrInfoDTOList
.
setRnrStatus
(
RnrStatusEnum
.
NO_REAL_NAME
.
getCode
());
MgRnrInfoDTOList
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
MgRnrInfoDTOList
.
setCreator
(
UserSubjectUtil
.
getUserId
());
MgRnrInfoDTOList
.
setOperator
(
UserSubjectUtil
.
getUserId
());
MgRnrInfoDTOList
.
setCreateTime
(
null
);
MgRnrInfoDTOList
.
setUpdateTime
(
null
);
return
MgRnrInfoDTOList
;
}
/**
* 创建工单信息
*
* @param orderID
* @param orderIdList
*/
private
RnrOrderDTO
getMgRnrOrderDTO
(
String
orderID
,
String
rnrId
,
List
<
String
>
orderIdList
)
{
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setUuid
(
orderIdList
.
get
(
0
));
Response
<
RnrOrderDTO
>
rnrOrderResponse
=
rnrOrderClient
.
getByUuid
(
rnrOrderDTO
);
if
(!
rnrOrderResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
rnrOrderResponse
.
getCode
(),
rnrOrderResponse
.
getMsg
());
}
if
(
null
==
rnrOrderResponse
.
getData
()){
throw
new
CuscUserException
(
com
.
cusc
.
nirvana
.
user
.
rnr
.
enterprise
.
constants
.
ResponseCode
.
RNR_ORDER_IS_NULL
.
getCode
(),
com
.
cusc
.
nirvana
.
user
.
rnr
.
enterprise
.
constants
.
ResponseCode
.
RNR_ORDER_IS_NULL
.
getMsg
());
}
RnrOrderDTO
rnrOrderResponseData
=
rnrOrderResponse
.
getData
();
rnrOrderResponseData
.
setUuid
(
orderID
);
rnrOrderResponseData
.
setOrderStatus
(
RnrOrderStatusEnum
.
TO_EXAMINE
.
getCode
());
//新增类型,企业解绑
rnrOrderResponseData
.
setOrderType
(
RnrOrderType
.
ENTERPRISEUNBIND
.
getCode
());
rnrOrderResponseData
.
setCreator
(
UserSubjectUtil
.
getUserId
());
rnrOrderResponseData
.
setOperator
(
UserSubjectUtil
.
getUserId
());
rnrOrderResponseData
.
setRnrId
(
rnrId
);
rnrOrderResponseData
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
rnrOrderResponseData
.
setCreateTime
(
null
);
rnrOrderResponseData
.
setUpdateTime
(
null
);
return
rnrOrderResponseData
;
}
/**
* 获取实名卡信息
*
* @param mgRnrCardInfoDTOList 请求消息
*/
private
List
<
MgRnrCardInfoDTO
>
getMgRnrCardDTOs
(
List
<
MgRnrCardInfoDTO
>
mgRnrCardInfoDTOList
,
RnrRelationDTO
rnrRelationDTO
)
{
String
carID
=
CuscStringUtils
.
generateUuid
();
for
(
MgRnrCardInfoDTO
mgRnrCardInfoDTO
:
mgRnrCardInfoDTOList
)
{
String
oldCarId
=
mgRnrCardInfoDTO
.
getUuid
();
mgRnrCardInfoDTO
.
setUuid
(
carID
);
mgRnrCardInfoDTO
.
setRnrStatus
(
Integer
.
valueOf
(
RnrStatusEnum
.
NO_REAL_NAME
.
getCode
()));
mgRnrCardInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
mgRnrCardInfoDTO
.
setOldCardId
(
oldCarId
);
mgRnrCardInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setRnrId
(
rnrRelationDTO
.
getInfo
().
getUuid
());
mgRnrCardInfoDTO
.
setOrderId
(
rnrRelationDTO
.
getOrder
().
getUuid
());
mgRnrCardInfoDTO
.
setCreateTime
(
null
);
mgRnrCardInfoDTO
.
setUpdateTime
(
null
);
mgRnrCardInfoDTO
.
setOrderId
(
UserSubjectUtil
.
getUserId
());
}
return
mgRnrCardInfoDTOList
;
}
//私有方法
private
String
getGroupKey
(
MgRnrInfoDTO
vo
)
{
return
vo
.
getFullName
()
+
vo
.
getCertNumber
();
}
public
static
<
T
>
Predicate
<
T
>
distinctByKey
(
Function
<?
super
T
,
Object
>
keyExtractor
)
{
Map
<
Object
,
Boolean
>
seen
=
new
ConcurrentHashMap
<>();
System
.
out
.
println
(
"这个函数将应用到每个item"
);
return
t
->
seen
.
putIfAbsent
(
keyExtractor
.
apply
(
t
),
Boolean
.
TRUE
)
==
null
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/FileServiceImpl.java
0 → 100644
View file @
c997214d
/*
package com.cusc.nirvana.user.rnr.enterprise.service.impl;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil;
import com.cusc.nirvana.user.exception.CuscUserException;
import com.cusc.nirvana.user.rnr.enterprise.constants.FIleSystemType;
import com.cusc.nirvana.user.rnr.enterprise.dto.ExcelSheetDTO;
import com.cusc.nirvana.user.rnr.enterprise.dto.FileDownloadDTO;
import com.cusc.nirvana.user.rnr.enterprise.dto.FileUploadDTO;
import com.cusc.nirvana.user.rnr.enterprise.dto.OssDownloadRs;
import com.cusc.nirvana.user.rnr.enterprise.service.IFileService;
import com.cusc.nirvana.user.rnr.enterprise.util.FileUtil;
import com.cusc.nirvana.user.rnr.fp.common.ResponseCode;
import com.cusc.nirvana.user.rnr.fp.dto.FileRecordDTO;
import com.cusc.nirvana.user.rnr.fp.dto.VinCardDTO;
import com.cusc.nirvana.user.util.CuscStringUtils;
import com.cusc.nirvana.web.exception.AppGlobalException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RequestCallback;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
*/
/**
* 文件上传服务类
*
* @author huzl
* @date 2022/04/18
*//*
@Slf4j
@Service
public class FileServiceImpl implements IFileService {
@Value("${rnr.fileSystem:}")
private String fileServiceSrv;
@Resource
private RestTemplate nonLoadBalancedFile;
@Autowired
private OssConfig ossConfig;
@Value("${rnr.fileSelect}")
private String fileSelect;
@Override
public Response<FileRecordDTO> upload(FileUploadDTO fileUploadDTO) {
*/
/* String url = fileServiceSrv + "/file/upload/" + fileUploadDTO.getType();
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
if (StringUtils.isNotBlank(fileUploadDTO.getRootPath())) {
headers.set("rootPath", fileUploadDTO.getRootPath());
} else {
headers.set("rootPath", "rnr/");
}
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
if (StringUtils.isNotBlank(fileUploadDTO.getPath())) {
parameters.add("path", fileUploadDTO.getPath());
}
if (StringUtils.isNotBlank(fileUploadDTO.getUuid())) {
parameters.add("uuid", fileUploadDTO.getUuid());
}
ByteArrayResource resource = null;
try {
resource = new ByteArrayResource(fileUploadDTO.getFile().getBytes()) {
@Override
public String getFilename() {
return fileUploadDTO.getFile().getOriginalFilename();
}
};
} catch (IOException e) {
throw new AppGlobalException("读取文件流错误", e);
}
parameters.add("file", resource);
*//*
//final HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(parameters, headers);
//final ResponseEntity<String> entity = nonLoadBalancedFile.exchange(url, HttpMethod.POST, httpEntity, String
// .class);
log.info("FileUpload,parameter:{}", fileUploadDTO);
String saveFileName = "";
FileRecordDTO fileRecordDTO = new FileRecordDTO();
try {
saveFileName = CuscStringUtils.generateUuid()
+ fileUploadDTO.getFile().getOriginalFilename()
.substring(fileUploadDTO.getFile().getOriginalFilename().lastIndexOf("."));
String accessUrl = OSSUtil.upload(ossConfig.getBucketName(),
new ByteArrayInputStream(fileUploadDTO.getFile().getBytes()),
ossConfig.getPrefix() + saveFileName);
fileRecordDTO.setAccessUrl(accessUrl);
fileRecordDTO.setUuid(saveFileName);
fileRecordDTO.setFileName(saveFileName);
} catch (Exception e) {
throw new AppGlobalException("上传文件异常 MinIOUtils.uploadFile", e);
}
Response<FileRecordDTO> response = Response.createSuccess(fileRecordDTO);
return response;
}
*/
/**
* 下载文件
*
* @param downloadDTO
* @return
*//*
@Override
public InputStream download(FileDownloadDTO downloadDTO) {
if (FIleSystemType.MINIO.getCode().equals(fileSelect)) {
byte[] result = downloadToByteArray(downloadDTO);
return new ByteArrayInputStream(result);
} else if (FIleSystemType.OSS.getCode().equals(fileSelect)) {
byte[] result = downloadToByteArrayForOss(downloadDTO);
return new ByteArrayInputStream(result);
} else {
throw new CuscUserException(fileSelect, "未知文件系统");
}
}
*/
/**
* 下载文件(oss)
*
* @param downloadDTO
* @return
*//*
@Override
public byte[] downloadToByteArrayForOss(FileDownloadDTO downloadDTO) {
log.info("downloadToByteArrayForOss下载文件-开始");
byte[] result = new byte[0];
try {
OssDownloadRs ossDownloadRs =
OSSUtil.downloadFile(ossConfig.getBucketName(), ossConfig.getPrefix() + downloadDTO.getUuid());
InputStream fileStream = ossDownloadRs.getInputStream();
result = IOUtils.toByteArray(fileStream);
downloadDTO.setFileName(downloadDTO.getUuid());
} catch (Exception e) {
log.error("---downloadToByteArrayForOss--failure-", e);
}
log.info("downloadToByteArrayForOss下载文件-结束");
return result;
}
*/
/**
* 下载文件(minio)
*
* @param downloadDTO
* @return
*//*
@Override
public byte[] downloadToByteArray(FileDownloadDTO downloadDTO) {
//String url = fileServiceSrv + "/file/download/" + downloadDTO.getUuid();
//log.debug("url: " + url);
log.info("downloadToByteArray下载文件-开始");
byte[] result = new byte[0];
try {
//InputStream fileStream = MinIOUtils.getObject(minIOConfig.getBucketName(), downloadDTO.getUuid());
InputStream fileStream = null;
result = IOUtils.toByteArray(fileStream);
downloadDTO.setFileName(downloadDTO.getUuid());
} catch (Exception e) {
log.error("---downloadToByteArray--failure-", e);
}
//final ResponseEntity<byte[]> response = nonLoadBalancedFile.getForEntity(url, byte[].class);
//ContentDisposition contentDisposition = response.getHeaders().getContentDisposition();
log.info("downloadToByteArray下载文件-结束");
*/
/* try {
if (contentDisposition != null && CuscStringUtils.isNotEmpty(contentDisposition.getFilename())) {
downloadDTO.setFileName(URLDecoder.decode(contentDisposition.getFilename(), "utf-8"));
}
} catch (UnsupportedEncodingException e) {
log.warn("fileName decode error", e);
}
byte[] result = response.getBody();*//*
return result;
}
@Override
public List<VinCardDTO> downloadAndToVinCardList(String fileId) throws IOException {
FileDownloadDTO fileDownloadDTO = new FileDownloadDTO(fileId, "");
InputStream download = download(fileDownloadDTO);
return FileUtil.convertExcelToVinCardList(download, fileDownloadDTO.getFileName());
}
@Override
public Response<FileRecordDTO> createAndUploadExcel(String filedId, String fileName, ExcelSheetDTO excelSheetDTO) {
FileUploadDTO fileUploadDTO = new FileUploadDTO();
MultipartFile multipartFile;
try {
multipartFile = FileUtil.bytesToMultipartFile(FileUtil.createExcelBytes(excelSheetDTO, fileName), fileName);
} catch (Exception e) {
log.error("生成校验文件失败", e);
return Response.createError("生成校验文件失败", ResponseCode.INVALID_DATA.getCode());
}
fileUploadDTO.setType("private");
// if (StringUtils.isNotBlank(filedId)) {
// fileUploadDTO.setUuid(filedId);
// }
// fileUploadDTO.setType("public");
if (StringUtils.isBlank(fileUploadDTO.getUserId())) {
fileUploadDTO.setUserId(UserSubjectUtil.getUserId());
}
fileUploadDTO.setFile(multipartFile);
return upload(fileUploadDTO);
}
@Override
public File downloadToLocal(FileDownloadDTO downloadDTO) throws Exception {
String url = fileServiceSrv + "/file/download/" + downloadDTO.getUuid();
String localFileName = "";
if (StringUtils.isNotEmpty(downloadDTO.getFileName())) {
localFileName = downloadDTO.getFileName();
}
String targetPath = generateTmpPath(localFileName);
//定义请求头的接收类型
AtomicBoolean isError = new AtomicBoolean(false);
MultiValueMap<String, String> headers = new HttpHeaders();
headers.add("Accept", MediaType.toString(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.ALL)));
final HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(null, headers);
RequestCallback requestCallback = nonLoadBalancedFile.httpEntityCallback(httpEntity);
//对响应进行流式处理而不是将其全部加载到内存中
nonLoadBalancedFile.execute(url, HttpMethod.GET, requestCallback, clientHttpResponse -> {
HttpStatus statusCode = clientHttpResponse.getStatusCode();
if (statusCode != HttpStatus.OK) {
isError.set(true);
} else {
Files.copy(clientHttpResponse.getBody(), Paths.get(targetPath));
}
return null;
});
if (isError.get()) {
throw new Exception("文件下载失败");
}
return new File(targetPath);
}
private String generateTmpPath(String fileName) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Date date = new Date();
String path = format.format(date);
StringBuilder targetPath = new StringBuilder();
int index = fileName.lastIndexOf(".");
String name = index == -1 ? fileName : fileName.substring(0, index);
String ext = index == -1 ? "" : fileName.substring(index);
String tmpPath = FileUtils.getTempDirectoryPath();
targetPath.append(tmpPath).append((tmpPath.endsWith(File.separator) ? "" : File.separator)).append(path)
.append(File.separator);
File filePath = new File(targetPath.toString());
if (!filePath.exists()) {
filePath.mkdirs();
}
targetPath.append(name).append("_").append(System.currentTimeMillis()).append(ext);
return targetPath.toString();
}
}
*/
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/ICarInfoUploadServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.ExcelReader
;
import
com.alibaba.excel.exception.ExcelAnalysisException
;
import
com.alibaba.excel.read.metadata.ReadSheet
;
import
com.cusc.nirvana.common.result.PageResult
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.FuelTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.PlaceOfOriginOfVehicleEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.VehicleChannelTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.VehicleTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.FileDownloadDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.ImportSimDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.excel.CarInfoListener
;
import
com.cusc.nirvana.user.rnr.enterprise.excel.CarInfoRow
;
import
com.cusc.nirvana.user.rnr.enterprise.excel.CarInfoRowCountListener
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ICarInfoUploadService
;
import
com.cusc.nirvana.user.rnr.fp.client.FileSystemClient
;
import
com.cusc.nirvana.user.rnr.fp.client.FpCarInfoClient
;
import
com.cusc.nirvana.user.rnr.fp.dto.FileRecordDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.FpCarInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.client.SimFileHistoryClient
;
import
com.cusc.nirvana.user.rnr.mg.dto.SimFileHistoryDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.disk.DiskFileItem
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.commons.CommonsMultipartFile
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
java.io.*
;
import
java.nio.file.Files
;
import
java.text.SimpleDateFormat
;
import
java.util.Base64
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
/**
* @className: ICarInfoUploadServiceImpl
* @description: TODO
* @author: fxh
* @date: 2022/6/28 19:18
* @version: 1.0
**/
@Slf4j
@Service
@RefreshScope
public
class
ICarInfoUploadServiceImpl
implements
ICarInfoUploadService
{
private
final
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ICarInfoUploadServiceImpl
.
class
);
/**核心线程数*/
private
final
static
int
CORE_POOL_SIZE
=
Runtime
.
getRuntime
().
availableProcessors
()
*
2
;
private
final
static
int
MAX_POOL_SIZE
=
CORE_POOL_SIZE
*
2
;
private
final
static
long
KEEP_ALIVE_TIME
=
60L
;
@Value
(
"${import.simrel.upload.maxFilesInQueue:100}"
)
private
int
maxQueuedImportFiles
;
@Value
(
"${import.simrel.upload.tmp-dir:}"
)
private
String
tmpDir
;
@Value
(
"${import.simrel.upload.error-excel-path:sim-export:}"
)
private
String
errorExcelPath
;
@Value
(
"${import.simrel.upload.max-record-count:1000000}"
)
private
Integer
maxRecordCount
;
@Autowired
private
SimFileHistoryClient
simFileHistoryClient
;
@Autowired
private
FpCarInfoClient
fpCarInfoClient
;
/**导入文件线程池*/
private
ThreadPoolExecutor
executor
;
@Resource
private
FileSystemClient
fileSystemClient
;
@Value
(
"${rnr.carInfo:}"
)
private
String
carInfo
;
@PostConstruct
public
void
init
()
{
executor
=
new
ThreadPoolExecutor
(
CORE_POOL_SIZE
,
MAX_POOL_SIZE
,
KEEP_ALIVE_TIME
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<>(
maxQueuedImportFiles
));
}
@Override
public
Response
excelProcess
(
ImportSimDTO
importSimDTO
)
{
if
(
executor
.
getQueue
().
size
()
>=
maxQueuedImportFiles
)
{
return
Response
.
createError
(
"处理文件失败,当前排队上传任务太多,请稍后重试..."
);
}
FileDownloadDTO
fileDownloadDTO
=
new
FileDownloadDTO
();
fileDownloadDTO
.
setUuid
(
importSimDTO
.
getFileUuid
());
fileDownloadDTO
.
setFileName
(
importSimDTO
.
getFileName
());
try
{
String
base64
=
fileSystemClient
.
getBase64
(
fileDownloadDTO
).
getData
().
getBase64
();
byte
[]
result
=
Base64
.
getDecoder
().
decode
(
base64
);
if
(
result
==
null
||
result
.
length
==
0
)
{
return
Response
.
createError
(
"没有找到车辆信息Excel文件"
);
}
SimFileHistoryDTO
tmpHistoryDto
=
new
SimFileHistoryDTO
();
if
(
importSimDTO
.
getFileType
()
==
2
)
{
tmpHistoryDto
.
setTotalCount
(
0
);
//获取总行数
getExcelTotalCount
(
result
,
tmpHistoryDto
);
}
if
(
tmpHistoryDto
.
getTotalCount
()
>
maxRecordCount
)
{
return
Response
.
createError
(
"上传记录数不能大于["
+
maxRecordCount
+
"]"
);
}
SimFileHistoryDTO
simFileHistoryDTO
=
insertImportFile
(
importSimDTO
);
simFileHistoryDTO
.
setTotalCount
(
tmpHistoryDto
.
getTotalCount
());
simFileHistoryDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
String
creator
=
UserSubjectUtil
.
getUserId
();
String
tenantNo
=
UserSubjectUtil
.
getTenantNo
();
executor
.
submit
(
new
Runnable
()
{
@Override
public
void
run
()
{
asyncProcessExcel
(
result
,
simFileHistoryDTO
,
importSimDTO
,
creator
,
tenantNo
);
}
});
return
Response
.
createSuccess
(
"文件正在处理中..."
);
}
catch
(
Exception
ex
)
{
log
.
error
(
"导入车卡关系失败,原因:"
+
ex
.
getMessage
());
return
Response
.
createError
(
"导入车卡关系失败,原因:"
+
ex
.
getMessage
());
}
}
@Override
public
PageResult
<
FpCarInfoDTO
>
queryCarInfo
(
FpCarInfoDTO
fpCarInfoDTO
)
{
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
if
(
StringUtils
.
isNotEmpty
(
fpCarInfoDTO
.
getStartTime
())){
fpCarInfoDTO
.
setStartTime
(
simpleDateFormat
.
format
(
new
Date
(
Long
.
valueOf
(
fpCarInfoDTO
.
getStartTime
()))));
}
if
(
StringUtils
.
isNotEmpty
(
fpCarInfoDTO
.
getEndTime
()))
{
fpCarInfoDTO
.
setEndTime
(
simpleDateFormat
.
format
(
new
Date
(
Long
.
valueOf
(
fpCarInfoDTO
.
getEndTime
()))));
}
fpCarInfoDTO
.
setTenantno
(
StringUtils
.
isEmpty
(
fpCarInfoDTO
.
getTenantno
())?
UserSubjectUtil
.
getTenantNo
():
fpCarInfoDTO
.
getTenantno
());
fpCarInfoDTO
.
setOrgid
(
StringUtils
.
isEmpty
(
fpCarInfoDTO
.
getOrgid
())?
UserSubjectUtil
.
getOrganId
():
fpCarInfoDTO
.
getOrgid
());
Response
<
PageResult
<
FpCarInfoDTO
>>
response
=
fpCarInfoClient
.
queryByPage
(
fpCarInfoDTO
);
if
(!
response
.
isSuccess
()){
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
PageResult
<
FpCarInfoDTO
>
fpCarInfoDTOList
=
response
.
getData
();
List
<
FpCarInfoDTO
>
page
=
fpCarInfoDTOList
.
getList
().
stream
().
map
(
fpCarInfo
->{
fpCarInfo
.
setFuelType
(
FuelTypeEnum
.
getEnumByCode
(
fpCarInfo
.
getFuelType
()).
getName
());
fpCarInfo
.
setVehicleChannelType
(
VehicleChannelTypeEnum
.
getEnumByCode
(
fpCarInfo
.
getVehicleChannelType
()).
getName
());
fpCarInfo
.
setVehicleType
(
VehicleTypeEnum
.
getEnumByCode
(
fpCarInfo
.
getVehicleType
()).
getName
());
fpCarInfo
.
setPlaceOfOriginOfVehicle
(
PlaceOfOriginOfVehicleEnum
.
getEnumByCode
(
fpCarInfo
.
getPlaceOfOriginOfVehicle
()).
getName
());
return
fpCarInfo
;
}).
collect
(
Collectors
.
toList
());
return
new
PageResult
<
FpCarInfoDTO
>(
page
,
fpCarInfoDTOList
.
getTotalCount
(),
fpCarInfoDTOList
.
getPageSize
(),
fpCarInfoDTOList
.
getCurrPage
());
}
/**
* 获取excel的总行数
* @param fileBytes
* @param simFileHistoryDTO
*/
private
void
getExcelTotalCount
(
byte
[]
fileBytes
,
SimFileHistoryDTO
simFileHistoryDTO
)
throws
ExcelAnalysisException
{
try
{
ByteArrayInputStream
is
=
new
ByteArrayInputStream
(
fileBytes
);
ExcelReader
excelReader
=
EasyExcel
.
read
(
is
,
CarInfoRow
.
class
,
new
CarInfoRowCountListener
(
simFileHistoryDTO
)).
build
();
if
(
excelReader
!=
null
)
{
ReadSheet
readSheet
=
EasyExcel
.
readSheet
(
0
).
build
();
excelReader
.
read
(
readSheet
);
excelReader
.
finish
();
}
}
catch
(
Exception
ex
)
{
throw
new
ExcelAnalysisException
(
"读取车辆信息Excel文件失败"
);
}
}
/**
* 异步处理导入文件
* @param simFileHistoryDTO
*/
private
boolean
asyncProcessExcel
(
byte
[]
fileBytes
,
SimFileHistoryDTO
simFileHistoryDTO
,
ImportSimDTO
importSimDTO
,
String
creator
,
String
tenantNo
)
{
// 从文件服务下载需导入的文件
ByteArrayInputStream
is
=
new
ByteArrayInputStream
(
fileBytes
);
ExcelReader
excelReader
=
null
;
String
errorExcelFile
=
tmpDir
+
"/"
+
CuscStringUtils
.
generateUuid
()
+
".xlsx"
;
// 读取sim卡Excel文件
try
{
if
(
simFileHistoryDTO
.
getFileType
()
==
2
)
{
// 读取车卡关系Excel文件
excelReader
=
EasyExcel
.
read
(
is
,
CarInfoRow
.
class
,
new
CarInfoListener
(
fpCarInfoClient
,
simFileHistoryDTO
,
errorExcelFile
,
importSimDTO
,
creator
,
tenantNo
)).
build
();
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"导入车辆信息错误,原因:"
,
e
);
return
false
;
}
finally
{
if
(
is
!=
null
){
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
log
.
warn
(
"关闭流失败"
,
e
);
}
}
try
{
if
(
excelReader
!=
null
)
{
ReadSheet
readSheet
=
EasyExcel
.
readSheet
(
0
).
build
();
excelReader
.
read
(
readSheet
);
excelReader
.
finish
();
}
File
excelFile
=
new
File
(
errorExcelFile
);
if
(
excelFile
.
exists
())
{
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
dto
.
FileUploadDTO
fileUploadDTO
=
new
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
dto
.
FileUploadDTO
();
fileUploadDTO
.
setPath
(
errorExcelPath
);
fileUploadDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
MultipartFile
multipartFile
=
getMultipartFile
(
excelFile
,
simFileHistoryDTO
);
if
(
multipartFile
!=
null
)
{
fileUploadDTO
.
setFile
(
multipartFile
);
Response
<
FileRecordDTO
>
response
=
fileSystemClient
.
uploadFile
(
fileUploadDTO
);
if
(
response
.
getSuccess
())
{
simFileHistoryDTO
.
setErrorFileAddr
(
response
.
getData
().
getUuid
());
}
}
}
}
finally
{
simFileHistoryDTO
.
setStatus
(
1
);
simFileHistoryClient
.
update
(
simFileHistoryDTO
);
}
}
return
true
;
}
private
MultipartFile
getMultipartFile
(
File
file
,
SimFileHistoryDTO
simFileHistoryDTO
)
{
try
{
FileItem
fileItem
=
new
DiskFileItem
(
"excelFile"
,
Files
.
probeContentType
(
file
.
toPath
()),
false
,
simFileHistoryDTO
.
getFileName
(),
(
int
)
file
.
length
(),
file
.
getParentFile
());
byte
[]
buffer
=
new
byte
[
4096
];
int
n
;
try
(
InputStream
inputStream
=
new
FileInputStream
(
file
);
OutputStream
os
=
fileItem
.
getOutputStream
();)
{
while
((
n
=
inputStream
.
read
(
buffer
,
0
,
4096
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
n
);
}
MultipartFile
multipartFile
=
new
CommonsMultipartFile
(
fileItem
);
return
multipartFile
;
}
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"上传车辆信息错误文件至文件服务器失败,原因:"
,
e
);
}
return
null
;
}
/**
* 新增导入文件信息
* @param importSimDTO
* @return
*/
private
SimFileHistoryDTO
insertImportFile
(
ImportSimDTO
importSimDTO
)
{
SimFileHistoryDTO
simFileHistoryDTO
=
new
SimFileHistoryDTO
();
simFileHistoryDTO
.
setOrgUuid
(
importSimDTO
.
getOrgUuid
());
simFileHistoryDTO
.
setFileName
(
importSimDTO
.
getFileName
());
simFileHistoryDTO
.
setVerification
(
0
);
simFileHistoryDTO
.
setErrorInfo
(
""
);
simFileHistoryDTO
.
setBatchNo
(
""
);
simFileHistoryDTO
.
setTotalCount
(
0
);
simFileHistoryDTO
.
setErrorCount
(
0
);
simFileHistoryDTO
.
setStatus
(
0
);
simFileHistoryDTO
.
setFileType
(
importSimDTO
.
getFileType
());
simFileHistoryDTO
.
setFileAddr
(
importSimDTO
.
getFileUuid
());
simFileHistoryDTO
.
setImportType
(
0
);
simFileHistoryDTO
.
setIsDelete
(
0
);
simFileHistoryDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
Response
<
SimFileHistoryDTO
>
response
=
simFileHistoryClient
.
add
(
simFileHistoryDTO
);
return
response
.
getData
();
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/LogServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cusc.nirvana.common.result.PageResult
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.eiam.client.UserClient
;
import
com.cusc.nirvana.user.eiam.dto.UserDTO
;
import
com.cusc.nirvana.user.eiam.dto.UserSimpleDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.common.SysModuleEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.LogCategoryDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.LogInfoRequestDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.LogInfoResponseDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ILogService
;
import
com.cusc.nirvana.user.rnr.enterprise.util.DesensitizationUtil
;
import
com.cusc.nirvana.user.rnr.fp.client.FpUserOperationLogClient
;
import
com.cusc.nirvana.user.rnr.fp.dto.FpUserOperationLogDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* @author stayAnd
* @date 2022/7/4
*/
@Service
public
class
LogServiceImpl
implements
ILogService
{
@Resource
private
FpUserOperationLogClient
logClient
;
@Resource
private
UserClient
userClient
;
@Override
public
LogCategoryDTO
category
()
{
LogCategoryDTO
logCategoryDTO
=
new
LogCategoryDTO
();
Map
<
String
,
List
<
SysModuleEnum
>>
sysLogMap
=
Arrays
.
stream
(
SysModuleEnum
.
values
()).
collect
(
Collectors
.
groupingBy
(
SysModuleEnum:
:
getSysModule
));
List
<
LogCategoryDTO
.
LogCategoryDetailDTO
>
detailDTOList
=
new
ArrayList
<>();
sysLogMap
.
forEach
((
key
,
vlaue
)->{
LogCategoryDTO
.
LogCategoryDetailDTO
detailDTO
=
new
LogCategoryDTO
.
LogCategoryDetailDTO
();
List
<
String
>
optList
=
vlaue
.
stream
().
map
(
SysModuleEnum:
:
getSysAction
).
collect
(
Collectors
.
toList
());
detailDTO
.
setLogCategory
(
key
);
detailDTO
.
setLogOptList
(
optList
);
detailDTOList
.
add
(
detailDTO
);
});
logCategoryDTO
.
setLogDetailList
(
detailDTOList
);
return
logCategoryDTO
;
}
@Override
public
PageResult
<
LogInfoResponseDTO
>
list
(
LogInfoRequestDTO
requestDTO
)
{
PageResult
<
LogInfoResponseDTO
>
result
=
new
PageResult
<>();
FpUserOperationLogDTO
queryDto
=
new
FpUserOperationLogDTO
();
String
accountUserId
=
null
;
if
(
CuscStringUtils
.
isNotEmpty
(
requestDTO
.
getAccount
()))
{
UserDTO
query
=
new
UserDTO
();
query
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
query
.
setApplicationId
(
UserSubjectUtil
.
getAppId
());
query
.
setUserName
(
requestDTO
.
getAccount
());
UserDTO
userDTO
=
userClient
.
getByUserName
(
query
).
getData
();
if
(
null
==
userDTO
)
{
result
.
setList
(
Collections
.
emptyList
());
result
.
setTotalCount
(
0
);
return
result
;
}
accountUserId
=
userDTO
.
getUuid
();
queryDto
.
setCreator
(
accountUserId
);
}
String
phoneUserId
=
null
;
if
(
CuscStringUtils
.
isNotEmpty
(
requestDTO
.
getPhone
()))
{
UserDTO
query
=
new
UserDTO
();
query
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
query
.
setApplicationId
(
UserSubjectUtil
.
getAppId
());
query
.
setPhone
(
requestDTO
.
getPhone
());
UserDTO
userDTO
=
userClient
.
getByPhone
(
query
).
getData
();
if
(
null
==
userDTO
)
{
result
.
setList
(
Collections
.
emptyList
());
result
.
setTotalCount
(
0
);
return
result
;
}
phoneUserId
=
userDTO
.
getUuid
();
queryDto
.
setCreator
(
phoneUserId
);
}
if
(
CuscStringUtils
.
isNotEmpty
(
accountUserId
)
&&
CuscStringUtils
.
isNotEmpty
(
phoneUserId
)
&&
!
accountUserId
.
equals
(
phoneUserId
))
{
result
.
setList
(
Collections
.
emptyList
());
result
.
setTotalCount
(
0
);
return
result
;
}
if
(
CuscStringUtils
.
isEmpty
(
requestDTO
.
getOrgId
()))
{
queryDto
.
setOrgId
(
UserSubjectUtil
.
getOrganId
());
}
else
{
queryDto
.
setOrgId
(
requestDTO
.
getOrgId
());
}
if
(
CuscStringUtils
.
isNotEmpty
(
requestDTO
.
getLogCategory
())){
queryDto
.
setOptModule
(
requestDTO
.
getLogCategory
());
}
if
(
CuscStringUtils
.
isNotEmpty
(
requestDTO
.
getLogOpt
()))
{
queryDto
.
setOptAction
(
requestDTO
.
getLogOpt
());
}
if
(
null
!=
requestDTO
.
getCreateTimeStart
())
{
queryDto
.
setCreateTimeQueryStart
(
requestDTO
.
getCreateTimeStart
());
}
if
(
null
!=
requestDTO
.
getCreateTimeEnd
())
{
queryDto
.
setCreateTimeQueryStartEnd
(
requestDTO
.
getCreateTimeEnd
());
}
queryDto
.
setCurrPage
(
requestDTO
.
getCurrPage
());
queryDto
.
setPageSize
(
requestDTO
.
getPageSize
());
PageResult
<
FpUserOperationLogDTO
>
response
=
logClient
.
queryByPage
(
queryDto
).
getData
();
List
<
FpUserOperationLogDTO
>
dataList
=
response
.
getList
();
if
(
CollectionUtils
.
isEmpty
(
dataList
))
{
result
.
setList
(
Collections
.
emptyList
());
result
.
setTotalCount
(
0
);
return
result
;
}
result
.
setTotalCount
(
response
.
getTotalCount
());
List
<
String
>
userIdList
=
dataList
.
stream
().
map
(
FpUserOperationLogDTO:
:
getCreator
).
collect
(
Collectors
.
toList
());
UserDTO
uuidQuery
=
new
UserDTO
();
uuidQuery
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
uuidQuery
.
setApplicationId
(
UserSubjectUtil
.
getAppId
());
uuidQuery
.
setUuidList
(
userIdList
);
List
<
UserSimpleDTO
>
userList
=
userClient
.
getByUuids
(
uuidQuery
).
getData
();
Map
<
String
,
UserSimpleDTO
>
userMap
=
userList
.
stream
().
collect
(
Collectors
.
toMap
(
UserSimpleDTO:
:
getUuid
,
Function
.
identity
(),
(
o1
,
o2
)
->
o2
));
List
<
LogInfoResponseDTO
>
dtoList
=
dataList
.
stream
().
map
(
log
->
{
LogInfoResponseDTO
logInfoResponseDTO
=
new
LogInfoResponseDTO
();
logInfoResponseDTO
.
setLogCategory
(
log
.
getOptModule
());
logInfoResponseDTO
.
setLogOpt
(
log
.
getOptAction
());
logInfoResponseDTO
.
setLogContent
(
log
.
getOptContent
());
logInfoResponseDTO
.
setIp
(
log
.
getRequestIp
());
logInfoResponseDTO
.
setCreateTime
(
log
.
getCreateTime
());
UserSimpleDTO
userSimpleDTO
=
userMap
.
get
(
log
.
getCreator
());
logInfoResponseDTO
.
setAccount
(
null
!=
userSimpleDTO
?
userSimpleDTO
.
getUserName
()
:
""
);
logInfoResponseDTO
.
setPhone
(
null
!=
userSimpleDTO
?
DesensitizationUtil
.
desensitizePhone
(
userSimpleDTO
.
getPhone
())
:
""
);
return
logInfoResponseDTO
;
}).
collect
(
Collectors
.
toList
());
result
.
setList
(
dtoList
);
return
result
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/ManufacturerRnrServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.convert.ManufacturerRnrConvert
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.CompanyRnrResponseDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.EnterpriseRnrFollowUpDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.VehicleEnterpriseRnrEchoDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IManufacturerRnrService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IUserService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IVehicleCardService
;
import
com.cusc.nirvana.user.rnr.fp.client.EnterpriseRnrClient
;
import
com.cusc.nirvana.user.rnr.fp.client.FileSystemClient
;
import
com.cusc.nirvana.user.rnr.fp.dto.FileDownloadDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.ImageBase64DTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardDTO
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCompanyInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrFileClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgVehicleCompanyClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrBizzTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrFileType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderAuditTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderSourceEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderStatusEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderType
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCompanyInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrFileDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgVehicleCompanyDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
@Service
@Slf4j
public
class
ManufacturerRnrServiceImpl
implements
IManufacturerRnrService
{
@Autowired
MgVehicleCompanyClient
vehicleCompanyClient
;
@Resource
private
FileSystemClient
fileSystemClient
;
@Autowired
IVehicleCardService
vehicleCardService
;
@Autowired
private
MgRnrCompanyInfoClient
companyInfoClient
;
@Autowired
private
MgRnrFileClient
rnrFileClient
;
@Autowired
private
MgRnrInfoClient
rnrInfoClient
;
@Resource
private
EnterpriseRnrClient
enterpriseClient
;
@Resource
private
IUserService
userService
;
/**
* 查询车企详情
*
* @return 实例对象
*/
@Override
public
VehicleEnterpriseRnrEchoDTO
findDetail
(
String
tenantNo
,
String
orgId
)
{
//获取当前的用户车企信息
MgVehicleCompanyDTO
paramDTO
=
new
MgVehicleCompanyDTO
();
paramDTO
.
setTenantNo
(
tenantNo
);
paramDTO
.
setOrgId
(
orgId
);
Response
<
MgVehicleCompanyDTO
>
response
=
vehicleCompanyClient
.
getVehicleCompany
(
paramDTO
);
log
.
info
(
"查询企业信息返参:{}"
,
JSON
.
toJSONString
(
response
));
if
(
response
==
null
||
!
response
.
getSuccess
()
||
response
.
getData
()
==
null
)
{
return
null
;
}
MgVehicleCompanyDTO
vehicleCompanyDTO
=
response
.
getData
();
//人的信息
MgRnrInfoDTO
rnrInfo
=
new
MgRnrInfoDTO
();
rnrInfo
.
setUuid
(
vehicleCompanyDTO
.
getFirstRnrId
());
rnrInfo
.
setTenantNo
(
tenantNo
);
Response
<
MgRnrInfoDTO
>
rnrInfoResp
=
rnrInfoClient
.
getByUuid
(
rnrInfo
);
if
(
rnrInfoResp
==
null
||
!
rnrInfoResp
.
isSuccess
()
||
rnrInfoResp
.
getData
()
==
null
)
{
throw
new
CuscUserException
(
""
,
"实名责任人信息不能为空"
);
}
rnrInfo
=
rnrInfoResp
.
getData
();
//设置责任人信息
vehicleCompanyDTO
.
setCorporationName
(
rnrInfo
.
getFullName
());
vehicleCompanyDTO
.
setCorporationPhone
(
rnrInfo
.
getPhone
());
VehicleEnterpriseRnrEchoDTO
resultDTO
=
ManufacturerRnrConvert
.
INSTANCE
.
vehicleCompanyToEchoDTO
(
vehicleCompanyDTO
);
resultDTO
.
setVehicleEnterpriseId
(
vehicleCompanyDTO
.
getUuid
());
//企业实名认证授权书
resultDTO
.
setAuthorizationLetterPic
(
getFileBase64ByRnrIdType
(
vehicleCompanyDTO
.
getFirstRnrId
(),
tenantNo
,
RnrFileType
.
ENTERPRISE_AUTH_FILE
));
//入网合同
resultDTO
.
setContractPic
(
getFileBase64ByRnrIdType
(
vehicleCompanyDTO
.
getFirstRnrId
(),
tenantNo
,
RnrFileType
.
VEHUCLE_BIND
));
//责任告知书
resultDTO
.
setDutyPic
(
getFileBase64ByRnrIdType
(
vehicleCompanyDTO
.
getFirstRnrId
(),
tenantNo
,
RnrFileType
.
DUTY_FILE
));
return
resultDTO
;
}
private
List
<
String
>
getFileBase64ByRnrIdType
(
String
rnrId
,
String
tenantNo
,
RnrFileType
rnrFileType
)
{
MgRnrFileDTO
file
=
new
MgRnrFileDTO
();
file
.
setRnrId
(
rnrId
);
file
.
setTenantNo
(
tenantNo
);
file
.
setFileType
(
rnrFileType
.
getCode
());
Response
<
List
<
MgRnrFileDTO
>>
fileListResp
=
rnrFileClient
.
queryByList
(
file
);
log
.
info
(
"查询文件 rnrId = {},tenantNo = {}, fileType ={}, response = {}"
,
rnrId
,
tenantNo
,
rnrFileType
.
getComment
(),
JSONObject
.
toJSONString
(
fileListResp
));
if
(
fileListResp
==
null
||
!
fileListResp
.
isSuccess
())
{
return
Collections
.
emptyList
();
}
List
<
String
>
base64List
=
new
ArrayList
<>();
for
(
MgRnrFileDTO
fileTmp
:
fileListResp
.
getData
()){
FileDownloadDTO
fileDownloadDTO
=
new
FileDownloadDTO
();
fileDownloadDTO
.
setUuid
(
fileTmp
.
getFileSystemId
());
Response
<
ImageBase64DTO
>
fileRecordResponse
=
fileSystemClient
.
getBase64
(
fileDownloadDTO
);
if
(
fileRecordResponse
!=
null
&&
fileRecordResponse
.
isSuccess
())
{
//需要将文件信息转为base64
base64List
.
add
(
fileRecordResponse
.
getData
().
getBase64
());
}
}
return
base64List
;
}
@Override
public
Response
<
CompanyRnrResponseDTO
>
submitRnrFollowUp
(
EnterpriseRnrFollowUpDTO
bean
)
{
log
.
info
(
"submitRnrFollowUp 入参信息:{}"
,
JSON
.
toJSONString
(
bean
));
//通过车企信息id查询车企信息
MgVehicleCompanyDTO
fvc
=
new
MgVehicleCompanyDTO
();
fvc
.
setUuid
(
bean
.
getVehicleEnterpriseId
());
Response
<
MgVehicleCompanyDTO
>
fvcResp
=
vehicleCompanyClient
.
getByUuid
(
fvc
);
if
(
fvcResp
!=
null
&&
fvcResp
.
isSuccess
())
{
fvc
=
fvcResp
.
getData
();
}
//验证车卡关系
Response
<
List
<
VinCardDTO
>>
listResponse
=
vehicleCardService
.
checkIccidList
(
bean
.
getFileId
());
log
.
info
(
"验证车卡关系"
,
bean
);
if
(!
listResponse
.
isSuccess
())
{
return
Response
.
createSuccess
(
false
);
}
//调用fp接口 提交车企实名
RnrRelationDTO
rnrRelationDTO
=
turnParams
(
fvc
,
listResponse
.
getData
());
if
(
CollectionUtils
.
isEmpty
(
rnrRelationDTO
.
getCardList
()))
{
return
Response
.
createError
(
"ICCID不能为空"
);
}
rnrRelationDTO
.
setSerialNumber
(
rnrRelationDTO
.
getOrder
().
getSerialNumber
());
Response
<
Boolean
>
enterpriseResponse
=
enterpriseClient
.
enterpriseRnrFollowUp
(
rnrRelationDTO
);
log
.
info
(
"提交车企实名后续 :{}"
,
JSON
.
toJSONString
(
enterpriseResponse
));
if
(!
enterpriseResponse
.
isSuccess
())
{
return
Response
.
createError
(
enterpriseResponse
.
getMsg
(),
enterpriseResponse
.
getCode
());
}
else
{
Response
submitResponse
=
Response
.
createSuccess
();
CompanyRnrResponseDTO
companyRnrResponseDTO
=
new
CompanyRnrResponseDTO
();
companyRnrResponseDTO
.
setVerifyStatus
(
0
);
submitResponse
.
setData
(
companyRnrResponseDTO
);
return
submitResponse
;
}
}
//转换成RelationDto
private
RnrRelationDTO
turnParams
(
MgVehicleCompanyDTO
vcDto
,
List
<
VinCardDTO
>
vinCardDTOList
)
{
RnrRelationDTO
rnrRelationDTO
=
new
RnrRelationDTO
();
String
rnrId
=
CuscStringUtils
.
generateUuid
();
String
tenantNo
=
UserSubjectUtil
.
getTenantNo
();
//租户
rnrRelationDTO
.
setTenantNo
(
tenantNo
);
rnrRelationDTO
.
setIsTrust
(
0
);
//查询当前用户的组织id
String
orgId
=
userService
.
getOrganId
(
UserSubjectUtil
.
getUserId
(),
tenantNo
);
//人的信息
MgRnrInfoDTO
rnrInfo
=
new
MgRnrInfoDTO
();
rnrInfo
.
setUuid
(
vcDto
.
getFirstRnrId
());
rnrInfo
.
setTenantNo
(
tenantNo
);
Response
<
MgRnrInfoDTO
>
rnrInfoResp
=
rnrInfoClient
.
getByUuid
(
rnrInfo
);
if
(
rnrInfoResp
==
null
||
!
rnrInfoResp
.
isSuccess
()
||
rnrInfoResp
.
getData
()
==
null
)
{
throw
new
CuscUserException
(
""
,
"实名责任人信息不能为空"
);
}
rnrInfo
=
rnrInfoResp
.
getData
();
rnrInfo
.
setUuid
(
rnrId
);
rnrInfo
.
setCreator
(
UserSubjectUtil
.
getUserId
());
rnrInfo
.
setCreateTime
(
null
);
rnrInfo
.
setOperator
(
null
);
rnrInfo
.
setUpdateTime
(
null
);
rnrInfo
.
setId
(
null
);
rnrInfo
.
setSerial_number
(
rnrId
);
rnrInfo
.
setOrgId
(
orgId
);
//公司信息 ,通过rnrId查询公司信息
MgRnrCompanyInfoDTO
companyInfo
=
new
MgRnrCompanyInfoDTO
();
companyInfo
.
setRnrId
(
vcDto
.
getFirstRnrId
());
companyInfo
.
setTenantNo
(
tenantNo
);
Response
<
MgRnrCompanyInfoDTO
>
companyInfoResp
=
companyInfoClient
.
getByRnrid
(
companyInfo
);
if
(
companyInfoResp
==
null
||
!
companyInfoResp
.
isSuccess
()
||
companyInfoResp
.
getData
()
==
null
)
{
throw
new
CuscUserException
(
""
,
"实名车企信息不能为空"
);
}
companyInfo
=
companyInfoResp
.
getData
();
companyInfo
.
setUuid
(
CuscStringUtils
.
generateUuid
());
companyInfo
.
setRnrId
(
rnrId
);
companyInfo
.
setCreator
(
UserSubjectUtil
.
getUserId
());
companyInfo
.
setCreateTime
(
null
);
companyInfo
.
setOperator
(
null
);
companyInfo
.
setUpdateTime
(
null
);
companyInfo
.
setId
(
null
);
companyInfo
.
setSerial_number
(
rnrId
);
int
orderType
=
RnrOrderType
.
CARMAKER_NEW_VEHICLE
.
getCode
();
//订单信息
RnrOrderDTO
rnrOrderDTO
=
createOrder
(
rnrId
,
tenantNo
,
orderType
);
rnrOrderDTO
.
setOrgId
(
orgId
);
//卡信息
List
<
MgRnrCardInfoDTO
>
cardInfoDTOS
=
createCardInfoDTOs
(
tenantNo
,
rnrId
,
rnrOrderDTO
.
getUuid
(),
vinCardDTOList
);
//文件列表
//公司信息 ,通过rnrId查询公司信息
MgRnrFileDTO
fileInfo
=
new
MgRnrFileDTO
();
fileInfo
.
setRnrId
(
vcDto
.
getFirstRnrId
());
fileInfo
.
setTenantNo
(
tenantNo
);
Response
<
List
<
MgRnrFileDTO
>>
fileInfoResp
=
rnrFileClient
.
queryByList
(
fileInfo
);
if
(
fileInfoResp
==
null
||
!
fileInfoResp
.
isSuccess
()
||
CollectionUtils
.
isEmpty
(
fileInfoResp
.
getData
()))
{
throw
new
CuscUserException
(
""
,
"实名图片信息不能为空"
);
}
List
<
MgRnrFileDTO
>
fileInfoList
=
fileInfoResp
.
getData
();
for
(
MgRnrFileDTO
file
:
fileInfoList
){
file
.
setRnrId
(
rnrId
);
file
.
setRnrCompanyId
(
companyInfo
.
getUuid
());
file
.
setCreator
(
UserSubjectUtil
.
getUserId
());
file
.
setCreateTime
(
null
);
file
.
setOperator
(
null
);
file
.
setUpdateTime
(
null
);
file
.
setId
(
null
);
file
.
setSerial_number
(
rnrId
);
}
//实名联系人信息
rnrRelationDTO
.
setRnrLiaisonList
(
new
ArrayList
<>());
rnrRelationDTO
.
setCompanyInfo
(
companyInfo
);
rnrRelationDTO
.
setInfo
(
rnrInfo
);
rnrRelationDTO
.
setCardList
(
cardInfoDTOS
);
rnrRelationDTO
.
setOrder
(
rnrOrderDTO
);
rnrRelationDTO
.
setRnrFileList
(
fileInfoList
);
rnrRelationDTO
.
setRnrTagList
(
new
ArrayList
<>());
return
rnrRelationDTO
;
}
//创建工单
private
RnrOrderDTO
createOrder
(
String
uuid
,
String
tenNo
,
int
orderType
)
{
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setOrderType
(
orderType
);
rnrOrderDTO
.
setRnrId
(
uuid
);
rnrOrderDTO
.
setAuditType
(
RnrOrderAuditTypeEnum
.
AUTO
.
getCode
());
rnrOrderDTO
.
setAutoRnr
(
true
);
rnrOrderDTO
.
setIsBatchOrder
(
1
);
rnrOrderDTO
.
setSerialNumber
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setOrderSource
(
RnrOrderSourceEnum
.
PORTAL
.
getCode
());
rnrOrderDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setTenantNo
(
tenNo
);
rnrOrderDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
rnrOrderDTO
.
setOrderStatus
(
RnrOrderStatusEnum
.
PASS
.
getCode
());
rnrOrderDTO
.
setSendWorkOrder
(
false
);
return
rnrOrderDTO
;
}
//卡信息
private
List
<
MgRnrCardInfoDTO
>
createCardInfoDTOs
(
String
tenantNo
,
String
rnrId
,
String
uuid
,
List
<
VinCardDTO
>
vinCardDTOS
)
{
List
<
MgRnrCardInfoDTO
>
cardInfoDTOS
=
new
ArrayList
<>();
for
(
VinCardDTO
cardDTO
:
vinCardDTOS
)
{
MgRnrCardInfoDTO
mgRnrCardInfoDTO
=
new
MgRnrCardInfoDTO
();
mgRnrCardInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrCardInfoDTO
.
setIccid
(
cardDTO
.
getIccid
());
mgRnrCardInfoDTO
.
setTenantNo
(
tenantNo
);
mgRnrCardInfoDTO
.
setIotId
(
cardDTO
.
getVin
());
mgRnrCardInfoDTO
.
setRnrId
(
rnrId
);
mgRnrCardInfoDTO
.
setOrderId
(
uuid
);
mgRnrCardInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
cardInfoDTOS
.
add
(
mgRnrCardInfoDTO
);
}
return
cardInfoDTOS
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/NewVinCardServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.service.INewVinCardService
;
import
com.cusc.nirvana.user.rnr.fp.client.NewVinCardClient
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.dto.*
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
/**
* @author stayAnd
* @date 2022/5/18
*/
@Service
public
class
NewVinCardServiceImpl
implements
INewVinCardService
{
@Resource
private
NewVinCardClient
newVinCardClient
;
@Override
public
Response
<
VinCardResultDTO
>
queryUnBindCardByVin
(
VinCardQueryDTO
queryDTO
)
{
return
newVinCardClient
.
queryUnBindCardByVin
(
queryDTO
);
}
@Override
public
VinCardResultDTO
queryBindCardByVin
(
VinCardQueryDTO
queryDTO
)
{
return
newVinCardClient
.
queryBindCardByVin
(
queryDTO
).
getData
();
}
@Override
public
VinCardCheckResultDTO
checkVinCard
(
VinCardCheckDTO
vinCardCheckDTO
)
{
//paramCheck(vinCardCheckDTO);
if
(!
CollectionUtils
.
isEmpty
(
vinCardCheckDTO
.
getIccidList
())
&&
vinCardCheckDTO
.
getIccidList
().
stream
().
distinct
().
count
()
!=
vinCardCheckDTO
.
getIccidList
().
size
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"请不要输入同样的iccid"
);
}
Response
<
VinCardCheckResultDTO
>
checkResponse
=
newVinCardClient
.
checkVinCard
(
vinCardCheckDTO
);
if
(!
checkResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
checkResponse
.
getCode
(),
checkResponse
.
getMsg
());
}
return
checkResponse
.
getData
();
}
@Override
public
VinCheckResultDTO
checkVin
(
VinCheckRequestDTO
requestDTO
)
{
if
(
requestDTO
.
getVinList
().
stream
().
distinct
().
count
()
!=
requestDTO
.
getVinList
().
size
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"请不要输入同样的iccid"
);
}
Response
<
VinCheckResultDTO
>
response
=
newVinCardClient
.
checkVin
(
requestDTO
);
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
return
response
.
getData
();
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/OrderMgrServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.eiam.client.OrganizationClient
;
import
com.cusc.nirvana.user.eiam.dto.OrganizationDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.common.BizConstants
;
import
com.cusc.nirvana.user.rnr.enterprise.common.CompanyTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.common.IndustryTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.AuthInfo
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.AuthItemInfo
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.CardInfo
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.EnterpriseInfo
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.FileInfo
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.NatualPersonInfo
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.OrderDetailsResponse
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.OrderInfo
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IOrderMgrService
;
import
com.cusc.nirvana.user.rnr.enterprise.util.DateExtentUtils
;
import
com.cusc.nirvana.user.rnr.fp.client.FileSystemClient
;
import
com.cusc.nirvana.user.rnr.fp.dto.FileDownloadDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.FileRecordDTO
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrAuthenticationResultClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCardInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCompanyInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrFileClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrLiaisonInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.RnrOrderClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.AuthWayTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.GenderEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrFileType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrLiaisonType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderType
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrAuthenticationResultDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCompanyInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrFileDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrLiaisonInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO
;
import
com.cusc.nirvana.user.util.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
@Service
@Slf4j
public
class
OrderMgrServiceImpl
implements
IOrderMgrService
{
public
static
final
String
DEFALUT_VALUE_LIAISONID
=
"0"
;
public
static
final
String
AUTH_RESULT_SUCCESS
=
"1"
;
@Resource
private
RnrOrderClient
rnrOrderClient
;
@Resource
private
MgRnrInfoClient
mgRnrInfoClient
;
@Resource
private
MgRnrCompanyInfoClient
mgRnrCompanyInfoClient
;
@Resource
private
MgRnrFileClient
mgRnrFileClient
;
@Resource
private
MgRnrCardInfoClient
mgRnrCardInfoClient
;
@Resource
private
MgRnrLiaisonInfoClient
mgRnrLiaisonInfoClient
;
@Resource
private
MgRnrAuthenticationResultClient
mgRnrAuthenticationResultClient
;
@Resource
@Qualifier
(
"nonLoadBalancedFile"
)
private
RestTemplate
restTemplateNoLB
;
@Resource
private
FileSystemClient
fileSystemClient
;
/**
* 自然人关联文件类型集合
*/
private
static
Set
<
Integer
>
NPFileTypeSet
=
new
HashSet
<>();
/**
* 企业关联文件类型
*/
private
static
Set
<
Integer
>
EntFileTypeSet
=
new
HashSet
<>();
/**
* 认证信息关联文件类型
*/
private
static
Set
<
Integer
>
authFileTypeSet
=
new
HashSet
<>();
static
{
NPFileTypeSet
.
add
(
RnrFileType
.
IDENTITY_CARD_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
IDENTITY_CARD_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
POLICE_CARD_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
POLICE_CARD_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
HK_MACAO_PASSPORT_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
HK_MACAO_PASSPORT_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
TAIWAN_CARD_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
TAIWAN_CARD_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
FOREIGN_NATIONAL_PASSPORT_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
FOREIGN_NATIONAL_PASSPORT_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
HK_MACAO_RESIDENCE_PERMIT_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
HK_MACAO_RESIDENCE_PERMIT_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
TAIWAN_RESIDENCE_PERMIT_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
TAIWAN_RESIDENCE_PERMIT_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
RESIDENCE_BOOKLET_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
RESIDENCE_BOOKLET_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
OFFICIAL_CARD_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
OFFICIAL_CARD_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
OTHER
.
getCode
());
EntFileTypeSet
.
add
(
RnrFileType
.
ENTERPRISE_PIC
.
getCode
());
EntFileTypeSet
.
add
(
RnrFileType
.
ENTERPRISE_AUTH_FILE
.
getCode
());
authFileTypeSet
.
add
(
RnrFileType
.
LIVENESS_SCREEN_FIRST
.
getCode
());
authFileTypeSet
.
add
(
RnrFileType
.
LIVENESS_SCREEN_TWO
.
getCode
());
authFileTypeSet
.
add
(
RnrFileType
.
LIVENESS_VIDEO
.
getCode
());
}
@Override
public
OrderDetailsResponse
queryOrderDetail
(
String
rnrOrderUuid
)
{
OrderDetailsResponse
rsp
=
new
OrderDetailsResponse
();
RnrOrderDTO
rnrOrderDto
=
new
RnrOrderDTO
();
rnrOrderDto
.
setUuid
(
rnrOrderUuid
);
Response
<
RnrOrderDTO
>
rnrOrderRsp
=
rnrOrderClient
.
getByUuid
(
rnrOrderDto
);
if
(
rnrOrderRsp
!=
null
&&
rnrOrderRsp
.
isSuccess
()
&&
rnrOrderRsp
.
getData
()
!=
null
)
{
RnrOrderDTO
rnrOrder
=
wrapOrderInfo
(
rsp
,
rnrOrderRsp
);
//包装工单信息
String
rnrId
=
rnrOrder
.
getRnrId
();
String
tenantNo
=
rnrOrder
.
getTenantNo
();
MgRnrInfoDTO
mgRnrInfoQueryBean
=
new
MgRnrInfoDTO
();
mgRnrInfoQueryBean
.
setUuid
(
rnrId
);
mgRnrInfoQueryBean
.
setTenantNo
(
tenantNo
);
Response
<
MgRnrInfoDTO
>
mgRnrInfoRsp
=
mgRnrInfoClient
.
getByUuid
(
mgRnrInfoQueryBean
);
if
(
mgRnrInfoRsp
!=
null
&&
mgRnrInfoRsp
.
isSuccess
()
&&
mgRnrInfoRsp
.
getData
()
!=
null
)
{
MgRnrInfoDTO
mgRnrInfo
=
mgRnrInfoRsp
.
getData
();
if
(
mgRnrInfo
.
getIsCompany
()
==
0
)
{
//个人实名
deal4NaturalPerson
(
rsp
,
rnrId
,
mgRnrInfo
);
rsp
.
getOrderInfo
().
setIsCompany
(
false
);
}
else
if
(
mgRnrInfo
.
getIsCompany
()
==
1
)
{
//企业实名
dear4Company
(
rsp
,
mgRnrInfo
);
rsp
.
getOrderInfo
().
setIsCompany
(
true
);
}
//车卡关系
wrapCardInfo
(
rsp
,
rnrId
,
tenantNo
);
//处理认证信息
// wrapAuthInfo(rsp, rnrId, tenantNo);
wrapAuthInfoNew
(
rsp
,
rnrId
,
tenantNo
);
//处理文件
wrapFileInfo
(
rsp
,
rnrId
,
tenantNo
);
//////////
//企业变更责任人
if
(
RnrOrderType
.
COMPANY_CORPORATION_CHANGE
.
getCode
()
==
rnrOrder
.
getOrderType
())
{
rsp
.
setOldCompanyInfo
(
rsp
.
getEnterpriseInfo
());
rsp
.
setEnterpriseInfo
(
null
);
wrapNewOwnerInfo
(
rsp
,
mgRnrInfo
);
}
}
}
return
rsp
;
}
@Resource
private
OrganizationClient
organizationClient
;
private
RnrOrderDTO
wrapOrderInfo
(
OrderDetailsResponse
rsp
,
Response
<
RnrOrderDTO
>
rnrOrderRsp
)
{
RnrOrderDTO
rnrOrder
=
rnrOrderRsp
.
getData
();
Integer
orderType
=
rnrOrder
.
getOrderType
();
OrderInfo
orderInfo
=
new
OrderInfo
();
orderInfo
.
setRnrCreateDate
(
DateUtils
.
formatDatetime
(
rnrOrder
.
getCreateTime
()));
orderInfo
.
setBizTypeName
(
RnrOrderType
.
getDescription
(
orderType
).
getComment
());
if
(
StringUtils
.
isNotBlank
(
rnrOrder
.
getOrgId
()))
{
OrganizationDTO
queryOrg
=
new
OrganizationDTO
();
queryOrg
.
setUuid
(
rnrOrder
.
getOrgId
());
Response
<
OrganizationDTO
>
orgRsp
=
organizationClient
.
getByUuid
(
queryOrg
);
if
(
orgRsp
!=
null
&&
orgRsp
.
isSuccess
()
&&
orgRsp
.
getData
()
!=
null
)
{
OrganizationDTO
orgDetail
=
orgRsp
.
getData
();
if
(
orgDetail
.
getBizType
()
==
BizConstants
.
ORG_BIZ_TYPE_VEHICLE_COMPANY
)
{
orderInfo
.
setVehicleCompanyName
(
orgDetail
.
getOrganName
());
}
else
if
(
orgDetail
.
getBizType
()
==
BizConstants
.
ORG_BIZ_TYPE_DISTRIBUTOR
)
{
orderInfo
.
setDistributorName
(
orgDetail
.
getOrganName
());
}
}
}
rsp
.
setOrderInfo
(
orderInfo
);
return
rnrOrder
;
}
private
void
deal4NaturalPerson
(
OrderDetailsResponse
rsp
,
String
rnrId
,
MgRnrInfoDTO
mgRnrInfo
)
{
try
{
//车主、责任人信息
wrapOwnerInfo
(
rsp
,
mgRnrInfo
);
//委托实名
if
(
mgRnrInfo
.
getIsTrust
()
==
1
)
{
wrapAgentInfo
(
rsp
,
rnrId
,
mgRnrInfo
.
getTenantNo
());
}
}
catch
(
Exception
e
)
{
log
.
error
(
"deal4NaturalPerson error"
,
e
);
}
}
private
void
wrapOwnerInfo
(
OrderDetailsResponse
rsp
,
MgRnrInfoDTO
mgRnrInfo
)
{
NatualPersonInfo
ownerInfo
=
wrapNatualPersonInfoByInfoDto
(
mgRnrInfo
);
rsp
.
setOwnerInfo
(
ownerInfo
);
//自然人-车主、企业实名-责任人
}
private
void
dear4Company
(
OrderDetailsResponse
rsp
,
MgRnrInfoDTO
mgRnrInfo
)
{
String
companyUuid
=
mgRnrInfo
.
getRnrCompanyId
();
MgRnrCompanyInfoDTO
queryBean4CompanyUuid
=
new
MgRnrCompanyInfoDTO
();
queryBean4CompanyUuid
.
setUuid
(
companyUuid
);
queryBean4CompanyUuid
.
setTenantNo
(
mgRnrInfo
.
getTenantNo
());
Response
<
MgRnrCompanyInfoDTO
>
rnrCompanyRsp
=
mgRnrCompanyInfoClient
.
getByUuid
(
queryBean4CompanyUuid
);
if
(
rnrCompanyRsp
!=
null
&&
rnrCompanyRsp
.
isSuccess
()
&&
rnrCompanyRsp
.
getData
()
!=
null
)
{
MgRnrCompanyInfoDTO
mgRnrCompanyInfo
=
rnrCompanyRsp
.
getData
();
EnterpriseInfo
entInfo
=
new
EnterpriseInfo
();
entInfo
.
setCompanyName
(
mgRnrCompanyInfo
.
getCompanyName
());
entInfo
.
setIndustryType
(
IndustryTypeEnum
.
getEnumByCode
(
mgRnrCompanyInfo
.
getIndustryType
()).
getValue
());
entInfo
.
setCompanyType
(
CompanyTypeEnum
.
getEnumByCode
(
mgRnrCompanyInfo
.
getCompanyType
()).
getValue
());
entInfo
.
setCompanyContactAddress
(
mgRnrCompanyInfo
.
getCompanyContactAddress
());
entInfo
.
setCompanyCertNumber
(
mgRnrCompanyInfo
.
getCompanyCertNumber
());
entInfo
.
setCompanyCertAddress
(
mgRnrCompanyInfo
.
getCompanyCertAddress
());
entInfo
.
setCompanyCertType
(
CertTypeEnum
.
getEnumByCode
(
mgRnrCompanyInfo
.
getCompanyCertType
()).
getName
());
rsp
.
setEnterpriseInfo
(
entInfo
);
}
wrapOwnerInfo
(
rsp
,
mgRnrInfo
);
}
//企业责任人变更后的信息
private
void
wrapNewOwnerInfo
(
OrderDetailsResponse
rsp
,
MgRnrInfoDTO
mgRnrInfo
)
{
NatualPersonInfo
ownerInfo
=
wrapNatualPersonInfoByInfoDto
(
mgRnrInfo
);
ownerInfo
.
setFileMap
(
rsp
.
getOwnerInfo
().
getFileMap
());
rsp
.
setOwnerInfo
(
null
);
rsp
.
setNewOwnerInfo
(
ownerInfo
);
//自然人-车主、企业实名-责任人
}
private
NatualPersonInfo
wrapNatualPersonInfoByInfoDto
(
MgRnrInfoDTO
mgRnrInfo
)
{
NatualPersonInfo
ownerInfo
=
new
NatualPersonInfo
();
if
(
mgRnrInfo
.
getExpiredDate
()
!=
null
)
{
ownerInfo
.
setExpiredDate
(
mgRnrInfo
.
getExpiredDate
());
}
if
(
mgRnrInfo
.
getEffectiveDate
()
!=
null
)
{
ownerInfo
.
setEffectiveDate
(
DateUtils
.
formatDate
(
DateExtentUtils
.
dateToLocalDate
(
mgRnrInfo
.
getEffectiveDate
()),
"yyyy-MM-dd"
));
}
ownerInfo
.
setPhone
(
mgRnrInfo
.
getPhone
());
ownerInfo
.
setGender
(
GenderEnum
.
findByCode
(
mgRnrInfo
.
getGender
()).
getName
());
ownerInfo
.
setContactAddress
(
mgRnrInfo
.
getContactAddress
());
ownerInfo
.
setCertType
(
CertTypeEnum
.
getEnumByCode
(
mgRnrInfo
.
getCertType
()).
getName
());
ownerInfo
.
setCertNumber
(
mgRnrInfo
.
getCertNumber
());
ownerInfo
.
setFullName
(
mgRnrInfo
.
getFullName
());
ownerInfo
.
setIsCompany
(
mgRnrInfo
.
getIsCompany
()
==
1
);
ownerInfo
.
setCertAddress
(
mgRnrInfo
.
getCertAddress
());
ownerInfo
.
setUuid
(
mgRnrInfo
.
getUuid
());
return
ownerInfo
;
}
private
void
wrapCardInfo
(
OrderDetailsResponse
rsp
,
String
rnrId
,
String
tenantNo
)
{
try
{
MgRnrCardInfoDTO
cardInfoQBean
=
new
MgRnrCardInfoDTO
();
cardInfoQBean
.
setRnrId
(
rnrId
);
cardInfoQBean
.
setTenantNo
(
tenantNo
);
Response
<
List
<
MgRnrCardInfoDTO
>>
cardInfoListRsp
=
mgRnrCardInfoClient
.
queryByList
(
cardInfoQBean
);
if
(
cardInfoListRsp
!=
null
&&
cardInfoListRsp
.
isSuccess
()
&&
cardInfoListRsp
.
getData
()
!=
null
)
{
List
<
MgRnrCardInfoDTO
>
rnrCardInfoList
=
cardInfoListRsp
.
getData
();
if
(
rnrCardInfoList
.
size
()
>
0
)
{
List
<
CardInfo
>
cardInfoList
=
new
ArrayList
<>();
for
(
MgRnrCardInfoDTO
rnrCardInfo
:
rnrCardInfoList
)
{
CardInfo
cardInfo
=
new
CardInfo
();
cardInfo
.
setIccid
(
rnrCardInfo
.
getIccid
());
cardInfo
.
setVin
(
rnrCardInfo
.
getIotId
());
cardInfo
.
setCheckInfo
(
"待确认信息"
);
cardInfoList
.
add
(
cardInfo
);
}
rsp
.
setCardInfoList
(
cardInfoList
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"wrapCardInfo error"
,
e
);
}
}
private
void
wrapAgentInfo
(
OrderDetailsResponse
rsp
,
String
rnrId
,
String
tenantNo
)
{
try
{
NatualPersonInfo
agentInfo
=
new
NatualPersonInfo
();
MgRnrLiaisonInfoDTO
queryBean
=
new
MgRnrLiaisonInfoDTO
();
queryBean
.
setRnrId
(
rnrId
);
queryBean
.
setTenantNo
(
tenantNo
);
queryBean
.
setLiaisonType
(
RnrLiaisonType
.
CONSIGNEE
.
getCode
());
Response
<
List
<
MgRnrLiaisonInfoDTO
>>
mgRnrLiaisonInfoRsp
=
mgRnrLiaisonInfoClient
.
queryByList
(
queryBean
);
if
(
mgRnrLiaisonInfoRsp
!=
null
&&
mgRnrLiaisonInfoRsp
.
isSuccess
()
&&
mgRnrLiaisonInfoRsp
.
getData
()
!=
null
)
{
List
<
MgRnrLiaisonInfoDTO
>
mgRnrLiaisonInfoList
=
mgRnrLiaisonInfoRsp
.
getData
();
//代理人只且只有一个
if
(
mgRnrLiaisonInfoList
.
size
()
>
0
)
{
MgRnrLiaisonInfoDTO
mgRnrLiaisonInfo
=
mgRnrLiaisonInfoList
.
get
(
0
);
agentInfo
.
setFullName
(
mgRnrLiaisonInfo
.
getLiaisonName
());
agentInfo
.
setCertType
(
CertTypeEnum
.
getEnumByCode
(
mgRnrLiaisonInfo
.
getLiaisonCertType
()).
getName
());
agentInfo
.
setCertNumber
(
mgRnrLiaisonInfo
.
getLiaisonCertNumber
());
agentInfo
.
setCertAddress
(
mgRnrLiaisonInfo
.
getLiaisonCertAddress
());
agentInfo
.
setPhone
(
mgRnrLiaisonInfo
.
getLiaisonPhone
());
agentInfo
.
setContactAddress
(
mgRnrLiaisonInfo
.
getLiaisonContactAddress
());
agentInfo
.
setUuid
(
mgRnrLiaisonInfo
.
getUuid
());
agentInfo
.
setGender
(
"TODO"
);
agentInfo
.
setExpiredDate
(
"TODO"
);
//FIXME
rsp
.
setAgentInfo
(
agentInfo
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"wrapAgentInfo error"
,
e
);
}
}
private
void
wrapFileInfo
(
OrderDetailsResponse
rsp
,
String
rnrId
,
String
tenantNo
)
{
try
{
MgRnrFileDTO
queryBean
=
new
MgRnrFileDTO
();
queryBean
.
setRnrId
(
rnrId
);
queryBean
.
setTenantNo
(
tenantNo
);
Response
<
List
<
MgRnrFileDTO
>>
fileInfoListRsp
=
mgRnrFileClient
.
queryByList
(
queryBean
);
if
(
fileInfoListRsp
!=
null
&&
fileInfoListRsp
.
isSuccess
()
&&
fileInfoListRsp
.
getData
()
!=
null
)
{
List
<
MgRnrFileDTO
>
fileInfoList
=
fileInfoListRsp
.
getData
();
for
(
MgRnrFileDTO
fileInfo
:
fileInfoList
)
{
String
fileType
=
RnrFileType
.
getDescription
(
fileInfo
.
getFileType
()).
name
();
if
(
NPFileTypeSet
.
contains
(
fileInfo
.
getFileType
()))
{
if
(
StringUtils
.
isNotBlank
(
fileInfo
.
getLiaisonId
())
&&
!
DEFALUT_VALUE_LIAISONID
.
equals
(
fileInfo
.
getLiaisonId
())
&&
rsp
.
getAgentInfo
()
!=
null
)
{
Map
<
String
,
List
<
FileInfo
>>
fileMap
=
rsp
.
getAgentInfo
().
getFileMap
();
fileMap
.
put
(
fileType
,
getFileInfoList
(
fileMap
.
get
(
fileType
),
fileInfo
));
}
else
if
(
rsp
.
getOwnerInfo
()
!=
null
)
{
Map
<
String
,
List
<
FileInfo
>>
fileMap
=
rsp
.
getOwnerInfo
().
getFileMap
();
fileMap
.
put
(
fileType
,
getFileInfoList
(
fileMap
.
get
(
fileType
),
fileInfo
));
}
}
else
if
(
EntFileTypeSet
.
contains
(
fileInfo
.
getFileType
())
&&
rsp
.
getEnterpriseInfo
()
!=
null
)
{
//企业信息模块中展示文件
EnterpriseInfo
enterpriseInfo
=
rsp
.
getEnterpriseInfo
();
Map
<
String
,
List
<
FileInfo
>>
fileMap
=
enterpriseInfo
.
getFileMap
();
fileMap
.
put
(
fileType
,
getFileInfoList
(
fileMap
.
get
(
fileType
),
fileInfo
));
continue
;
}
else
if
(
authFileTypeSet
.
contains
(
fileInfo
.
getFileType
())
&&
rsp
.
getAuthInfo
()
!=
null
)
{
Map
<
String
,
List
<
FileInfo
>>
fileMap
=
rsp
.
getAuthInfo
().
getFileMap
();
fileMap
.
put
(
fileType
,
getFileInfoList
(
fileMap
.
get
(
fileType
),
fileInfo
));
continue
;
}
else
{
Map
<
String
,
List
<
FileInfo
>>
fileMap
=
rsp
.
getFileMap
();
fileMap
.
put
(
fileType
,
getFileInfoList
(
fileMap
.
get
(
fileType
),
fileInfo
));
continue
;
}
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"wrapFileInfo error"
,
e
);
}
}
private
void
wrapAuthInfoNew
(
OrderDetailsResponse
rsp
,
String
rnrId
,
String
tenantNo
)
{
MgRnrAuthenticationResultDTO
baseAuthQBean
=
new
MgRnrAuthenticationResultDTO
();
baseAuthQBean
.
setRnrId
(
rnrId
);
baseAuthQBean
.
setTenantNo
(
tenantNo
);
try
{
Response
<
List
<
MgRnrAuthenticationResultDTO
>>
authResultRsp
=
mgRnrAuthenticationResultClient
.
queryByList
(
baseAuthQBean
);
if
(
authResultRsp
!=
null
&&
authResultRsp
.
isSuccess
()
&&
authResultRsp
.
getData
()
!=
null
)
{
List
<
MgRnrAuthenticationResultDTO
>
authResultList
=
authResultRsp
.
getData
();
if
(
authResultList
.
size
()
>
0
)
{
AuthInfo
authInfo
=
new
AuthInfo
();
List
<
AuthItemInfo
>
authItemInfoList
=
new
ArrayList
<>();
for
(
MgRnrAuthenticationResultDTO
authResultItem
:
authResultList
)
{
AuthItemInfo
authItem
=
new
AuthItemInfo
();
authItem
.
setMessage
(
authResultItem
.
getAuthResultMsg
());
authItem
.
setSuccess
(
AUTH_RESULT_SUCCESS
.
equals
(
authResultItem
.
getAuthResult
()));
authItem
.
setTpActionCode
(
authResultItem
.
getAuthWayType
());
AuthWayTypeEnum
authWayEnum
=
AuthWayTypeEnum
.
getEnumByCode
(
authResultItem
.
getAuthWayType
());
authItem
.
setTpActionName
(
authWayEnum
==
null
?
""
:
authWayEnum
.
getName
());
authItemInfoList
.
add
(
authItem
);
}
authInfo
.
setAuthItemInfoList
(
authItemInfoList
);
rsp
.
setAuthInfo
(
authInfo
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"wrapAuthInfo error"
,
e
);
}
}
private
List
<
FileInfo
>
getFileInfoList
(
List
<
FileInfo
>
fileInfos
,
MgRnrFileDTO
fileInfo
)
{
List
<
FileInfo
>
fileList
=
null
;
if
(
fileInfos
==
null
)
{
fileList
=
new
ArrayList
<>();
fileList
.
add
(
wrapFileInfo
(
fileInfo
));
}
else
{
fileInfos
.
add
(
wrapFileInfo
(
fileInfo
));
fileList
=
fileInfos
;
}
return
fileList
;
}
public
String
getFileUrl
(
String
fileUuid
)
{
try
{
//String url = fileServerUrl + "/file/url/" + fileUuid;
//RnrResponse<String> fileUrlRsp = RnrBaseRestTemplateUtils.getForResponse(this.restTemplateNoLB, url, String.class);
//return fileUrlRsp != null && fileUrlRsp.isSuccess() && fileUrlRsp.getData() != null ? fileUrlRsp.getData() : null;
FileDownloadDTO
dto
=
new
FileDownloadDTO
();
dto
.
setUuid
(
fileUuid
);
Response
<
FileRecordDTO
>
response
=
fileSystemClient
.
getUrl
(
dto
);
return
response
.
getData
().
getAccessUrl
();
}
catch
(
Exception
e
)
{
log
.
error
(
"getFileUrl error"
,
e
);
return
null
;
}
}
private
FileInfo
wrapFileInfo
(
MgRnrFileDTO
rnrFileInfo
)
{
FileInfo
fileInfo
=
new
FileInfo
();
fileInfo
.
setFileBase64
(
rnrFileInfo
.
getFileBase64
());
fileInfo
.
setFileName
(
rnrFileInfo
.
getFileName
());
fileInfo
.
setFileTypeComment
(
RnrFileType
.
getDescription
(
rnrFileInfo
.
getFileType
()).
name
());
String
fileUuid
=
rnrFileInfo
.
getFileSystemId
();
String
fileUrl
=
getFileUrl
(
fileUuid
);
fileInfo
.
setFileUrl
(
fileUrl
);
return
fileInfo
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/OrganServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cache.CacheFactory
;
import
com.cusc.nirvana.common.result.PageResult
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.eiam.client.OrganizationClient
;
import
com.cusc.nirvana.user.eiam.client.UserClient
;
import
com.cusc.nirvana.user.eiam.client.UserOrganClient
;
import
com.cusc.nirvana.user.eiam.client.UserRoleClient
;
import
com.cusc.nirvana.user.eiam.dto.*
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.common.RedisConstants
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.*
;
import
com.cusc.nirvana.user.rnr.enterprise.convert.OrganConvert
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.*
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IOrganService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IUserService
;
import
com.cusc.nirvana.user.rnr.fp.constants.BizTypeEnum
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.Resource
;
import
java.util.Calendar
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* Description: 车企组织管理service
* <br />
* CreateDate 2022-05-20 13:37:40
*
* @author yuyi
**/
@Service
@Slf4j
public
class
OrganServiceImpl
implements
IOrganService
{
@Resource
private
IUserService
userService
;
@Resource
private
OrganizationClient
organizationClient
;
@Resource
private
UserClient
userClient
;
@Resource
private
CacheFactory
cacheFactory
;
@Resource
private
UserRoleClient
userRoleClient
;
@Value
(
"${user.eiam.applicationId:4}"
)
private
String
applicationId
;
@Resource
private
UserOrganClient
userOrganClient
;
@Override
public
void
add
(
OrganDTO
bean
)
{
//查询用户是否存在
UserDTO
queryUserDTO
=
userService
.
queryUserInInfoByPhone
(
bean
.
getOrganAdminPhone
());
if
(
null
!=
queryUserDTO
)
{
throw
new
CuscUserException
(
ResponseCode
.
USER_PHONE_EXISTS
.
getCode
(),
ResponseCode
.
USER_PHONE_EXISTS
.
getMsg
());
}
//如果父类id为空表示创建在当前登录人下
String
organId
=
""
;
if
(!
StringUtils
.
isEmpty
(
bean
.
getParentId
())){
organId
=
bean
.
getParentId
();
}
else
{
organId
=
userService
.
getOrganId
(
UserSubjectUtil
.
getUserId
(),
UserSubjectUtil
.
getTenantNo
());
}
//获取当前登录人的上级id
OrganizationDTO
organs
=
new
OrganizationDTO
();
organs
.
setUuid
(
organId
);
Response
<
OrganizationDTO
>
organizationResponse
=
organizationClient
.
getByUuid
(
organs
);
if
(!
organizationResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
organizationResponse
.
getCode
(),
organizationResponse
.
getMsg
());
}
// OrganizationDTO organization = new OrganizationDTO();
// organization.setUuid(StringUtils.isEmpty(bean.getParentId())?organizationResponse.getData().getParentId():bean.getParentId());
// organization.setTenantNo(UserSubjectUtil.getTenantNo());
//
// Response<OrganizationDTO> organizationDTOResponse = organizationClient.getByUuid(organization);
// if (!organizationDTOResponse.isSuccess()) {
// throw new CuscUserException(organizationDTOResponse.getCode(),organizationDTOResponse.getMsg());
// }
//如果是经销商,不允许选择别的子组织
if
(
OrganBizzTypeEnum
.
DISTRIBUTOR
.
getCode
()==
organizationResponse
.
getData
().
getBizType
()
&&
OrganBizzTypeEnum
.
DISTRIBUTOR
.
getCode
()
!=
bean
.
getBizType
()){
throw
new
CuscUserException
(
ResponseCode
.
BIZTYPE_ERROR
.
getCode
(),
ResponseCode
.
BIZTYPE_ERROR
.
getMsg
());
}
// //获取当前的用户的组织
// UserOrganDTO userOrganDTO = new UserOrganDTO();
// userOrganDTO.setUserId(UserSubjectUtil.getUserId());
// userOrganDTO.setTenantNo(UserSubjectUtil.getTenantNo());
//
// Response<List<OrganizationDTO>> organResp = organizationClient.getOrganListByUserId(userOrganDTO);
//
// if (!organResp.isSuccess()) {
// throw new CuscUserException(organResp.getCode(),organResp.getMsg());
// }
//
// if(CollectionUtils.isEmpty(organResp.getData())){
// throw new CuscUserException(ResponseCode.USER_ORGAN_NOT_FOUND.getCode(),
// ResponseCode.USER_ORGAN_NOT_FOUND.getMsg());
// }
//
// OrganizationDTO organ = organResp.getData().get(0);
UserDTO
userDto
=
bean
.
toUserDTO
();
userDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
userDto
.
setApplicationId
(
applicationId
);
//如果是车厂管理员为0,如果经销商为1,如果是子组织为2
userDto
.
setOrdinaryAdmin
(
bean
.
getBizType
().
equals
(
OrganBizzTypeEnum
.
CAR_FACTORY
.
getCode
())?
OrdinaryAdminEnum
.
CAR_FACTORY
.
getCode
():
bean
.
getBizType
().
equals
(
OrganBizzTypeEnum
.
DISTRIBUTOR
.
getCode
())
?
OrdinaryAdminEnum
.
DISTRIBUTOR
.
getCode
():
OrdinaryAdminEnum
.
ORGAN
.
getCode
());
UserDTO
addUserDto
=
userService
.
addUser
(
userDto
);
//添加车企组织
OrganizationDTO
organDto
=
bean
.
toOrganDTO
();
organDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
organDto
.
setOrganCode
(
generateOrganCode
());
//如果没有传值上级id,获取当前用户登录的组织uuid
// if(StringUtils.isEmpty(bean.getParentId())){
// organDto.setParentId(organ.getUuid());
// }
organDto
.
setParentId
(
organizationResponse
.
getData
().
getUuid
());
Response
<
OrganizationDTO
>
organizationResponses
=
organizationClient
.
add
(
organDto
);
OrganizationDTO
organizationDTO
=
organizationResponses
.
getData
();
//新增车企组织管理员及其关系
userService
.
addUserRelationRole
(
addUserDto
.
getUuid
(),
organizationDTO
.
getUuid
(),
OrganBizzTypeEnum
.
CAR_FACTORY
.
getCode
()
==
bean
.
getBizType
()
||
OrganBizzTypeEnum
.
SON_ORGAN
.
getCode
()
==
bean
.
getBizType
()?
RoleTyeEnum
.
SON_FACTORY
.
getCode
():
RoleTyeEnum
.
DISTRIBUTOR
.
getCode
());
}
@Override
public
PageResult
<
OrganDTO
>
page
(
OrganPageDTO
bean
)
{
//获取当前的用户
String
userId
=
UserSubjectUtil
.
getUserId
();
//获取当前的用户的组织
UserOrganDTO
userOrganDTO
=
new
UserOrganDTO
();
userOrganDTO
.
setUserId
(
UserSubjectUtil
.
getUserId
());
userOrganDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
<
List
<
OrganizationDTO
>>
organResp
=
organizationClient
.
getOrganListByUserId
(
userOrganDTO
);
if
(!
organResp
.
isSuccess
())
{
throw
new
CuscUserException
(
organResp
.
getCode
(),
organResp
.
getMsg
());
}
if
(
CollectionUtils
.
isEmpty
(
organResp
.
getData
())){
throw
new
CuscUserException
(
ResponseCode
.
USER_ORGAN_NOT_FOUND
.
getCode
(),
ResponseCode
.
USER_ORGAN_NOT_FOUND
.
getMsg
());
}
OrganizationDTO
organ
=
organResp
.
getData
().
get
(
0
);
//查询当前用户,下一级数据。不查所有
OrganizationDTO
queryDto
=
bean
.
toOrganPageDTO
();
// queryDto.setQueryCode(organ.getQueryCode());
if
(
StringUtils
.
isEmpty
(
bean
.
getParentId
()))
{
queryDto
.
setParentId
(
organ
.
getUuid
());
}
queryDto
.
setOrganType
(
null
);
queryDto
.
setType
(
"1"
);
Response
<
PageResult
<
OrganizationDTO
>>
organResponse
=
organizationClient
.
queryByPage
(
queryDto
);
if
(!
organResponse
.
isSuccess
()){
throw
new
CuscUserException
(
organResponse
.
getCode
(),
organResponse
.
getMsg
());
}
PageResult
<
OrganizationDTO
>
page
=
organResponse
.
getData
();
//查询父类名称
List
<
String
>
parentList
=
page
.
getList
().
stream
().
map
(
OrganizationDTO:
:
getParentId
).
collect
(
Collectors
.
toList
());
OrganizationDTO
organizationDTOs
=
new
OrganizationDTO
();
organizationDTOs
.
setUuidList
(
parentList
);
Response
<
List
<
OrganizationDTO
>>
response
=
organizationClient
.
queryByList
(
organizationDTOs
);
if
(!
response
.
isSuccess
()){
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
List
<
OrganizationDTO
>
organizationDTOList
=
response
.
getData
();
Map
<
String
,
String
>
map
=
organizationDTOList
.
stream
().
collect
(
Collectors
.
toMap
(
OrganizationDTO:
:
getUuid
,
OrganizationDTO:
:
getOrganName
,(
k
,
v
)->
v
));
List
<
OrganDTO
>
dtoList
=
page
.
getList
().
stream
().
map
(
organizationDTO
->
{
OrganDTO
organDTO
=
OrganConvert
.
INSTANCE
.
eiamOrganToLocalOrgan
(
organizationDTO
);
organDTO
.
setOrganAdminName
(
organizationDTO
.
getAdminName
());
organDTO
.
setOrganAdminAccount
(
organizationDTO
.
getAdminAccount
());
organDTO
.
setUserId
(
organizationDTO
.
getAdminUserId
());
organDTO
.
setOrganAdminPhone
(
organizationDTO
.
getAdminPhone
());
organDTO
.
setCreateTime
(
organizationDTO
.
getCreateTime
());
organDTO
.
setParentOrganName
(
map
.
get
(
organizationDTO
.
getParentId
()));
organDTO
.
setAdminUserId
(
organizationDTO
.
getAdminUserId
());
return
organDTO
;
}).
collect
(
Collectors
.
toList
());
return
new
PageResult
<
OrganDTO
>(
dtoList
,
page
.
getTotalCount
(),
page
.
getPageSize
(),
page
.
getCurrPage
());
}
@Override
public
void
update
(
UpdateOrganDTO
bean
)
{
OrganizationDTO
updateDto
=
new
OrganizationDTO
();
updateDto
.
setUuid
(
bean
.
getUuid
());
updateDto
.
setOrganName
(
bean
.
getOrganName
());
updateDto
.
setComment
(
bean
.
getComment
());
updateDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
updateDto
.
setOperator
(
UserSubjectUtil
.
getUserId
());
updateDto
.
setBizType
(
bean
.
getBizType
());
updateDto
.
setStatus
(
bean
.
getStatus
());
organizationClient
.
update
(
updateDto
);
}
/**
* @author: jk
* @description: 变更管理员
* @date: 2022/5/27 9:13
* @version: 1.0
* @Param:
* @Return:
*/
@Override
public
void
changeAdmin
(
OrganChangeAdminDto
dto
)
{
//如果新管理id为空表示是用新账户替换
if
(
null
==
dto
.
getNewAdminUserId
()){
//查询新账号是否存在
UserDTO
userDTO
=
userService
.
queryUserInInfoByPhone
(
dto
.
getCreateAdminPhone
());
if
(
null
!=
userDTO
)
{
throw
new
CuscUserException
(
ResponseCode
.
USER_PHONE_EXISTS
.
getCode
(),
ResponseCode
.
USER_PHONE_EXISTS
.
getMsg
());
}
}
dto
.
setOrdinaryAdmin
(
OrganBizzTypeEnum
.
CAR_FACTORY
.
getCode
()==
dto
.
getBizType
()?
OrdinaryAdminEnum
.
CAR_FACTORY
.
getCode
():
OrganBizzTypeEnum
.
DISTRIBUTOR
.
getCode
()==
dto
.
getBizType
()?
OrdinaryAdminEnum
.
DISTRIBUTOR
.
getCode
():
OrdinaryAdminEnum
.
ORGAN
.
getCode
());
if
(
null
==
dto
.
getNewAdminUserId
())
{
this
.
checkNewAdminIsNull
(
dto
);
//创建用户
UserDTO
userAdminDto
=
new
UserDTO
();
userAdminDto
.
setOrdinaryAdmin
(
dto
.
getOrdinaryAdmin
());
userAdminDto
.
setUserName
(
dto
.
getCreateAdminAccount
());
userAdminDto
.
setFullName
(
dto
.
getCreateAdminUserName
());
userAdminDto
.
setPhone
(
dto
.
getCreateAdminPhone
());
userAdminDto
.
setPassword
(
dto
.
getCreateAdminPassword
());
userAdminDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
userAdminDto
.
setApplicationId
(
applicationId
);
//新增用户 eiam_user
UserDTO
userDTO
=
userService
.
addUser
(
userAdminDto
);
//新增用户组织eiam_user_organ 和 用户和角色关系 eiam_user_role
userService
.
addUserRelationRole
(
userDTO
.
getUuid
(),
dto
.
getUuid
(),
OrdinaryAdminEnum
.
CAR_FACTORY
.
getCode
()
==
dto
.
getOrdinaryAdmin
()
||
OrdinaryAdminEnum
.
ORGAN
.
getCode
()
==
dto
.
getOrdinaryAdmin
()?
RoleTyeEnum
.
SON_FACTORY
.
getCode
():
RoleTyeEnum
.
DISTRIBUTOR
.
getCode
());
}
else
{
if
(
StringUtils
.
isEmpty
(
dto
.
getNewAdminUserId
())){
throw
new
CuscUserException
(
CheckChangeAdminEnum
.
NEW_ADMIN_USER_ID
.
getCode
(),
CheckChangeAdminEnum
.
NEW_ADMIN_USER_ID
.
getMsg
());
}
//选中的员工 赋值新的角色管理员
UserDTO
newAdminDto
=
new
UserDTO
();
newAdminDto
.
setUuid
(
dto
.
getNewAdminUserId
());
newAdminDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
newAdminDto
.
setApplicationId
(
applicationId
);
newAdminDto
.
setOrdinaryAdmin
(
dto
.
getOrdinaryAdmin
());
newAdminDto
.
setIsTenantAdmin
(
1
);
//更新用户表数据 eiam_user
Response
updateResponse
=
userClient
.
update
(
newAdminDto
);
if
(!
updateResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
updateResponse
.
getCode
(),
updateResponse
.
getMsg
());
}
UserRoleDTO
newUserRoleAdminDto
=
new
UserRoleDTO
();
newUserRoleAdminDto
.
setUserId
(
dto
.
getNewAdminUserId
());
newUserRoleAdminDto
.
setRoleId
(
userService
.
getRoleId
(
OrdinaryAdminEnum
.
CAR_FACTORY
.
getCode
()
==
dto
.
getOrdinaryAdmin
()
||
OrdinaryAdminEnum
.
ORGAN
.
getCode
()
==
dto
.
getOrdinaryAdmin
()?
RoleTyeEnum
.
SON_FACTORY
.
getCode
():
RoleTyeEnum
.
DISTRIBUTOR
.
getCode
()));
//更新用户和角色关系 eiam_user_role
userRoleClient
.
updateByUserId
(
newUserRoleAdminDto
);
}
UserOrganDTO
userOrganDTO
=
new
UserOrganDTO
();
userOrganDTO
.
setOrganId
(
dto
.
getUuid
());
Response
<
List
<
UserOrganDTO
>>
queryByList
=
userOrganClient
.
queryByList
(
userOrganDTO
);
if
(!
queryByList
.
isSuccess
()){
throw
new
CuscUserException
(
queryByList
.
getCode
(),
queryByList
.
getMsg
());
}
List
<
UserOrganDTO
>
organizationDTOList
=
queryByList
.
getData
();
List
<
String
>
uuidList
=
organizationDTOList
.
stream
().
map
(
UserOrganDTO:
:
getUserId
).
collect
(
Collectors
.
toList
());
UserDTO
userDTO
=
new
UserDTO
();
userDTO
.
setUuidList
(
uuidList
);
userDTO
.
setApplicationId
(
applicationId
);
userDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
<
List
<
UserSimpleDTO
>>
userSimpleList
=
userClient
.
query
(
userDTO
);
if
(!
userSimpleList
.
isSuccess
()){
throw
new
CuscUserException
(
userSimpleList
.
getCode
(),
userSimpleList
.
getMsg
());
}
List
<
UserSimpleDTO
>
userSimpleDTOList
=
userSimpleList
.
getData
();
//查询之前的管理员
List
<
UserSimpleDTO
>
oldAdminUserList
=
userSimpleDTOList
.
stream
().
filter
(
a
->
a
.
getOrdinaryAdmin
()
>
0
&&
!
a
.
getUuid
().
equals
(
dto
.
getNewAdminUserId
())
).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
oldAdminUserList
))
{
log
.
info
(
"未查询到其他管理员"
);
return
;
}
//取消当前账号管理员身份
UserDTO
cancelAdminDto
=
new
UserDTO
();
cancelAdminDto
.
setUuid
(
oldAdminUserList
.
get
(
0
).
getUuid
());
cancelAdminDto
.
setTenantNo
(
oldAdminUserList
.
get
(
0
).
getTenantNo
());
cancelAdminDto
.
setApplicationId
(
applicationId
);
cancelAdminDto
.
setOrdinaryAdmin
(
0
);
cancelAdminDto
.
setIsTenantAdmin
(
0
);
userClient
.
update
(
cancelAdminDto
);
UserRoleDTO
cancelRoleAdminDto
=
new
UserRoleDTO
();
cancelRoleAdminDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
cancelRoleAdminDto
.
setApplicationId
(
applicationId
);
cancelRoleAdminDto
.
setUserId
(
oldAdminUserList
.
get
(
0
).
getUuid
());
//角色降级 车厂、车企子组织降级为102 , 经销商降级为202
// cancelRoleAdminDto.setRoleId(userService.getRoleId(OrdinaryAdminEnum.CAR_FACTORY.getCode() == dto.getOrdinaryAdmin() || OrdinaryAdminEnum.ORGAN.getCode() == dto.getOrdinaryAdmin()? RoleTyeEnum.UPDATE_CAR_FACTORY.getCode():RoleTyeEnum.UPDATE_DISTRIBUTOR.getCode()));
userRoleClient
.
delBatchUser
(
cancelRoleAdminDto
);
//新增用户角色关系
UserRoleDTO
userRoleDto
=
new
UserRoleDTO
();
userRoleDto
.
setUserId
(
oldAdminUserList
.
get
(
0
).
getUuid
());
userRoleDto
.
setRoleId
(
userService
.
getRoleId
(
OrdinaryAdminEnum
.
CAR_FACTORY
.
getCode
()
==
dto
.
getOrdinaryAdmin
()
||
OrdinaryAdminEnum
.
ORGAN
.
getCode
()
==
dto
.
getOrdinaryAdmin
()?
RoleTyeEnum
.
UPDATE_CAR_FACTORY
.
getCode
():
RoleTyeEnum
.
UPDATE_DISTRIBUTOR
.
getCode
()));
userRoleDto
.
setApplicationId
(
applicationId
);
userRoleDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
userRoleClient
.
add
(
userRoleDto
);
// userRoleClient.updateByUserId(cancelRoleAdminDto);
}
public
static
Response
checkNewAdminIsNull
(
OrganChangeAdminDto
dto
){
if
(
StringUtils
.
isEmpty
(
dto
.
getCreateAdminAccount
())){
throw
new
CuscUserException
(
CheckChangeAdminEnum
.
CREATE_ADMIN_ACCOUNT
.
getCode
(),
CheckChangeAdminEnum
.
CREATE_ADMIN_ACCOUNT
.
getMsg
());
}
if
(
StringUtils
.
isEmpty
(
dto
.
getCreateAdminUserName
())){
throw
new
CuscUserException
(
CheckChangeAdminEnum
.
CREATE_ADMIN_NAME
.
getCode
(),
CheckChangeAdminEnum
.
CREATE_ADMIN_NAME
.
getMsg
());
}
if
(
StringUtils
.
isEmpty
(
dto
.
getCreateAdminPassword
())){
throw
new
CuscUserException
(
CheckChangeAdminEnum
.
CREATE_ADMIN_PASSWORD
.
getCode
(),
CheckChangeAdminEnum
.
CREATE_ADMIN_PASSWORD
.
getMsg
());
}
if
(
StringUtils
.
isEmpty
(
dto
.
getCreateAdminPhone
())){
throw
new
CuscUserException
(
CheckChangeAdminEnum
.
CREATE_ADMIN_PHONE
.
getCode
(),
CheckChangeAdminEnum
.
CREATE_ADMIN_PHONE
.
getMsg
());
}
return
null
;
}
@Override
public
List
<
UserAccountDTO
>
queryUserAccount
(
OrganUserAccountDTO
dto
)
{
UserOrganDTO
userOrganDTO
=
new
UserOrganDTO
();
userOrganDTO
.
setOrganId
(
dto
.
getOrganId
());
Response
<
List
<
UserOrganDTO
>>
userOrganDTOResponse
=
userOrganClient
.
queryByList
(
userOrganDTO
);
if
(!
userOrganDTOResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYS_BUSY
.
getCode
(),
ResponseCode
.
SYS_BUSY
.
getMsg
());
}
List
<
UserOrganDTO
>
userOrganDTOList
=
userOrganDTOResponse
.
getData
();
List
<
String
>
userIdList
=
userOrganDTOList
.
stream
().
map
(
UserOrganDTO:
:
getUserId
).
collect
(
Collectors
.
toList
());
UserDTO
userDTO
=
new
UserDTO
();
userDTO
.
setUuidList
(
userIdList
);
userDTO
.
setApplicationId
(
applicationId
);
userDTO
.
setTenantNo
(
dto
.
getTenantNo
());
Response
<
List
<
UserSimpleDTO
>>
userSimpleList
=
userClient
.
getByUuids
(
userDTO
);
if
(!
userSimpleList
.
isSuccess
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYS_BUSY
.
getCode
(),
ResponseCode
.
SYS_BUSY
.
getMsg
());
}
List
<
UserAccountDTO
>
list
=
null
;
list
=
userSimpleList
.
getData
().
stream
().
map
(
a
->{
UserAccountDTO
userAccountDTO
=
new
UserAccountDTO
();
userAccountDTO
.
setUuid
(
a
.
getUuid
());
userAccountDTO
.
setFullName
(
a
.
getFullName
());
userAccountDTO
.
setUserName
(
a
.
getUserName
());
userAccountDTO
.
setTenantNo
(
a
.
getTenantNo
());
return
userAccountDTO
;
}
).
collect
(
Collectors
.
toList
());
return
list
;
}
@Override
public
List
<
OrganDTO
>
queryCurrentSubOrgList
()
{
String
organId
=
UserSubjectUtil
.
getOrganId
();
OrganizationDTO
dto
=
new
OrganizationDTO
();
dto
.
setUuid
(
organId
);
dto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
OrganizationDTO
data
=
organizationClient
.
getByUuid
(
dto
).
getData
();
if
(
null
==
data
)
{
return
Collections
.
emptyList
();
}
OrganizationDTO
query
=
new
OrganizationDTO
();
query
.
setQueryCode
(
data
.
getQueryCode
());
List
<
OrganizationDTO
>
organizationList
=
organizationClient
.
queryByList
(
query
).
getData
();
if
(
CollectionUtils
.
isEmpty
(
organizationList
)){
return
Collections
.
emptyList
();
}
return
organizationList
.
stream
().
map
(
o
->{
OrganDTO
organDTO
=
new
OrganDTO
();
BeanUtils
.
copyProperties
(
o
,
organDTO
);
return
organDTO
;
}).
collect
(
Collectors
.
toList
());
}
public
String
generateOrganCode
()
{
try
{
Calendar
calendar
=
Calendar
.
getInstance
();
int
year
=
calendar
.
get
(
Calendar
.
YEAR
);
Long
aLong
=
cacheFactory
.
getStringService
().
setValueIncr
(
RedisConstants
.
ORG_ORGAN_CODE_PREFIX
+
year
,
1
);
return
String
.
valueOf
(
year
*
10000
+
aLong
);
}
catch
(
Exception
e
)
{
log
.
error
(
"generateOrganCode has error"
,
e
);
}
return
""
;
}
//------------------私有方法区域
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/PersonalRnrServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.CustomerTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.convert.PersonalRnrRequestConvert
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.ConsignerInfoDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.LivenessCallbackReqDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.PersonalRnrDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.PersonalRnrH5CallBackRespDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.PersonalRnrH5ReqDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.PersonalRnrH5RespDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.PersonalRnrRequestDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.PersonalRnrResponseDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.VinDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IPersonalRnrService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IUserService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IVehicleCardService
;
import
com.cusc.nirvana.user.rnr.enterprise.util.FileUtil
;
import
com.cusc.nirvana.user.rnr.enterprise.util.SpringValidationUtil
;
import
com.cusc.nirvana.user.rnr.enterprise.util.ValidationUtil
;
import
com.cusc.nirvana.user.rnr.fp.client.CardUnBindClient
;
import
com.cusc.nirvana.user.rnr.fp.client.FpRnrClient
;
import
com.cusc.nirvana.user.rnr.fp.client.VinCardClient
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.constants.BizTypeEnum
;
import
com.cusc.nirvana.user.rnr.fp.dto.*
;
import
com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.GenderEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrBizzTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrFileType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrLiaisonType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderAuditTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderSourceEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderStatusEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrStatus
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrFileDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrLiaisonInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
com.cusc.nirvana.user.util.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
javax.annotation.Resource
;
import
javax.validation.ConstraintViolation
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* 个人实名信息
*
* @author **
*/
@Service
@Slf4j
public
class
PersonalRnrServiceImpl
implements
IPersonalRnrService
{
@Autowired
IVehicleCardService
vehicleCardService
;
@Autowired
SmsServiceImpl
smsService
;
@Autowired
FpRnrClient
fpRnrClient
;
@Autowired
VinCardClient
vinCardClient
;
@Autowired
CardUnBindClient
cardUnBindClient
;
@Value
(
"${rnr.h5.url:wwww}"
)
private
String
rnrH5Url
;
@Resource
private
IUserService
userService
;
@Value
(
"${rnr.frontPersonH5CallBackUrl}"
)
private
String
frontPersonH5CallBackUrl
;
@Value
(
"${rnr.frontPersonPadCallBackUrl}"
)
private
String
frontPersonPadCallBackUrl
;
@Override
public
Response
<
PersonalRnrResponseDTO
>
verifyVinCards
(
VinCardInfoDTO
vinCardListDTO
)
{
//调用公共验证接口
Response
<
VerifyVinCardResponseDTO
>
response
=
vehicleCardService
.
verifyVinCard
(
vinCardListDTO
);
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
//拼接消息体
PersonalRnrResponseDTO
personalRnrResponseDTO
=
new
PersonalRnrResponseDTO
();
if
(
CollectionUtils
.
isEmpty
(
response
.
getData
().
getIccidVerifyResults
()))
{
return
Response
.
createError
(
"ICCID和VIN不能为空"
);
}
List
<
String
>
msg
=
response
.
getData
().
getIccidVerifyResults
().
stream
()
.
filter
(
ret
->
!
ret
.
isExist
())
.
map
(
ret
->
ret
.
getMsg
())
.
collect
(
Collectors
.
toList
());
personalRnrResponseDTO
.
setResponseMsg
(
msg
);
if
(
msg
.
isEmpty
())
{
return
Response
.
createSuccess
(
personalRnrResponseDTO
);
}
else
{
return
Response
.
createError
(
ResponseCode
.
INVALID_DATA
.
getMsg
(),
personalRnrResponseDTO
);
}
}
@Override
public
Response
getIccidListByVin
(
VinDTO
vinDTO
)
{
IccidListDTO
iccidListDTO
=
new
IccidListDTO
();
Response
<
VinCardInfoDTO
>
response
=
vinCardClient
.
queryVinCard
(
vinDTO
.
getVin
());
if
(!
response
.
isSuccess
())
{
return
response
;
}
if
(
response
.
getData
()
==
null
||
CollectionUtils
.
isEmpty
(
response
.
getData
().
getIccidList
()))
{
iccidListDTO
.
setIccidList
(
Collections
.
emptyList
());
}
else
{
iccidListDTO
.
setIccidList
(
response
.
getData
().
getIccidList
());
}
return
Response
.
createSuccess
(
iccidListDTO
);
}
@Override
public
Response
<
PersonalRnrDTO
>
submitRnr
(
@RequestBody
PersonalRnrRequestDTO
requestDTO
)
{
requestDTO
.
setRnrBizzTypeEnum
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
if
(
requestDTO
.
getIccidList
().
stream
().
distinct
().
count
()
!=
requestDTO
.
getIccidList
().
size
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"请不要输入同样的iccid"
);
}
Response
<
RnrRelationDTO
>
rnrRelationDTOResponse
=
checkAndConvertToRelation
(
requestDTO
,
false
);
if
(!
rnrRelationDTOResponse
.
isSuccess
())
{
return
Response
.
createError
(
rnrRelationDTOResponse
.
getMsg
(),
rnrRelationDTOResponse
.
getCode
());
}
RnrRelationDTO
rnrRelationDTO
=
rnrRelationDTOResponse
.
getData
();
Response
rnrResponse
;
if
(
requestDTO
.
getCustomerType
()
==
CustomerTypeEnum
.
USED_CAR_OWNER
.
getCode
())
{
rnrResponse
=
fpRnrClient
.
personSecondHandRnr
(
rnrRelationDTO
.
getOrder
().
getSerialNumber
(),
requestDTO
.
getRequestId
(),
rnrRelationDTO
);
}
else
{
//新车车主实名,如果vin已经有实名的卡,走一车多卡绑定模式
/*Response<List<MgRnrCardInfoDTO>> cardListResponse = cardUnBindClient.getCardList(new FpVehicleCardRnrDTO().setVin(requestDTO.getVin()));
if (!cardListResponse.isSuccess()) {
return Response.createError(cardListResponse.getMsg(), cardListResponse.getCode());
}
if(!CollectionUtils.isEmpty(cardListResponse.getData())){
return Response.createError("VIN【" + requestDTO.getVin() + "】存在已实名的卡,请走一车多卡进行绑定",ResponseCode.INVALID_DATA.getCode());
}*/
rnrResponse
=
fpRnrClient
.
personRnr
(
rnrRelationDTO
.
getOrder
().
getSerialNumber
(),
requestDTO
.
getRequestId
(),
rnrRelationDTO
);
}
if
(
rnrResponse
.
isSuccess
())
{
return
Response
.
createSuccess
(
new
PersonalRnrDTO
((
Integer
)
rnrResponse
.
getData
()));
}
return
rnrResponse
;
}
/**
* 检查参数并转换
*
* @param requestDTO
* @return
*/
@Override
public
Response
<
RnrRelationDTO
>
checkAndConvertToRelation
(
PersonalRnrRequestDTO
requestDTO
,
boolean
unbind
)
{
log
.
info
(
"Param checkAndConvertToRelation:{}"
,
JSON
.
toJSONString
(
requestDTO
));
//手机验证码验证
Response
response
;
//手机验证码验证去掉
/* SmsRequestDTO smsRequestDTO = new SmsRequestDTO();
if (requestDTO.getIsConsigner()) {
smsRequestDTO.setPhone(requestDTO.getConsignerInfo().getPhone());
smsRequestDTO.setCaptcha(requestDTO.getConsignerInfo().getVerificationCode());
} else {
smsRequestDTO.setPhone(requestDTO.getPhone());
smsRequestDTO.setCaptcha(requestDTO.getVerificationCode());
}
smsRequestDTO.setBizType(BizTypeEnum.RNR.getCode());
smsRequestDTO.setTenantNo(UserSubjectUtil.getTenantNo());
response = smsService.checkSmsCaptcha(smsRequestDTO);
if (!response.isSuccess()) {
return Response.createError(response.getMsg(), response.getCode());
}*/
//参数必填校验
response
=
validRnrInfo
(
requestDTO
,
unbind
);
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
// //车卡信息验证
VinCardInfoDTO
vinCardListDTO
=
new
VinCardInfoDTO
();
vinCardListDTO
.
setVin
(
requestDTO
.
getVin
());
vinCardListDTO
.
setIccidList
(
requestDTO
.
getIccidList
());
response
=
verifyVinCards
(
vinCardListDTO
);
if
(!
response
.
isSuccess
())
{
if
(
StringUtils
.
equals
(
response
.
getMsg
(),
ResponseCode
.
INVALID_DATA
.
getMsg
()))
{
//返回第一个错误
return
Response
.
createError
(((
PersonalRnrResponseDTO
)
response
.
getData
()).
getResponseMsg
().
get
(
0
),
response
.
getCode
());
}
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
return
Response
.
createSuccess
(
convertToRelationDTO
(
requestDTO
));
}
/**
* 获取活体认证code接口
*
* @return
*/
@Override
public
Response
<
LivenessCodeResponseDTO
>
getLivenessCode
()
{
LivenessCodeRequestDTO
livenessCodeRequestDTO
=
new
LivenessCodeRequestDTO
();
livenessCodeRequestDTO
.
setSerialNumber
(
CuscStringUtils
.
generateUuid
());
String
tenantNo
=
UserSubjectUtil
.
getTenantNo
();
livenessCodeRequestDTO
.
setTenantNo
(
tenantNo
);
return
fpRnrClient
.
getLivenessCode
(
livenessCodeRequestDTO
);
}
@Override
public
PersonalRnrH5RespDTO
submitRnrH5
(
PersonalRnrH5ReqDTO
bean
)
{
bean
.
checkParam
();
if
(
bean
.
getIccidList
().
stream
().
distinct
().
count
()
!=
bean
.
getIccidList
().
size
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"请不要输入同样的iccid"
);
}
SmsRequestDTO
smsRequestDTO
=
new
SmsRequestDTO
();
if
(
bean
.
getIsConsigner
())
{
smsRequestDTO
.
setPhone
(
bean
.
getConsignerInfo
().
getPhone
());
smsRequestDTO
.
setCaptcha
(
bean
.
getConsignerInfo
().
getVerificationCode
());
}
else
{
smsRequestDTO
.
setPhone
(
bean
.
getPhone
());
smsRequestDTO
.
setCaptcha
(
bean
.
getVerificationCode
());
}
smsRequestDTO
.
setBizType
(
BizTypeEnum
.
RNR
.
getCode
());
smsRequestDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
smsResponse
=
smsService
.
checkSmsCaptcha
(
smsRequestDTO
);
if
(!
smsResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
smsResponse
.
getCode
(),
smsResponse
.
getMsg
());
}
PersonalRnrRequestDTO
personalRnrRequestDTO
=
PersonalRnrRequestConvert
.
INSTANCE
.
h5PersonRnrRequestToPersonRequstDTO
(
bean
);
personalRnrRequestDTO
.
setRnrBizzTypeEnum
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
Response
<
RnrRelationDTO
>
rnrRelationDTOResponse
=
checkAndConvertToRelation
(
personalRnrRequestDTO
,
false
);
if
(!
rnrRelationDTOResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
rnrRelationDTOResponse
.
getCode
(),
rnrRelationDTOResponse
.
getMsg
());
}
RnrRelationDTO
data
=
rnrRelationDTOResponse
.
getData
();
data
.
getOrder
().
setOrderSource
(
RnrOrderSourceEnum
.
H5
.
getCode
());
log
.
info
(
"PersonalRnrServiceImpl h5提交参数 data = {}"
,
JSONObject
.
toJSONString
(
data
));
//先不存工单系统
Response
response
=
fpRnrClient
.
personRnrH5
(
data
.
getOrder
().
getSerialNumber
(),
data
);
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
PersonalRnrH5RespDTO
h5RespDTO
=
new
PersonalRnrH5RespDTO
();
h5RespDTO
.
setOrderId
(
data
.
getOrder
().
getUuid
());
LiveLoginReqDTO
loginUrlDto
=
new
LiveLoginReqDTO
();
loginUrlDto
.
setOrderNo
(
data
.
getOrder
().
getUuid
());
if
(
"PAD"
.
equals
(
bean
.
getSource
()))
{
loginUrlDto
.
setCallBackUrl
(
frontPersonPadCallBackUrl
);
}
else
{
loginUrlDto
.
setCallBackUrl
(
frontPersonH5CallBackUrl
);
}
//todo 调用云端接口
Response
<
LiveLoginRespDTO
>
h5LiveLoginUrl
=
fpRnrClient
.
h5LiveLoginUrl
(
loginUrlDto
);
if
(
h5LiveLoginUrl
.
isSuccess
())
{
h5RespDTO
.
setH5LivenessUrl
(
h5LiveLoginUrl
.
getData
().
getH5LiveLoginUrl
());
}
h5RespDTO
.
setRnrId
(
data
.
getInfo
().
getUuid
());
return
h5RespDTO
;
}
@Override
public
PersonalRnrH5CallBackRespDTO
afreshLivenessUrl
(
LivenessCallbackReqDTO
bean
)
{
boolean
success
=
bean
.
getCode
().
equals
(
"0"
);
PersonalRnrH5CallBackRespDTO
reponse
=
new
PersonalRnrH5CallBackRespDTO
();
if
(
success
)
{
//活体成功
PersonH5CallBackRequestDTO
callBackDto
=
new
PersonH5CallBackRequestDTO
();
callBackDto
.
setOrderNo
(
bean
.
getOrderNo
());
callBackDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
//调用云端接口
LiveLoginReqDTO
liveLoginReqDTO
=
new
LiveLoginReqDTO
();
liveLoginReqDTO
.
setOrderNo
(
bean
.
getOrderNo
());
Response
<
LivenessResultDTO
>
livenessResult
=
fpRnrClient
.
h5LivenessResult
(
liveLoginReqDTO
);
if
(
null
==
livenessResult
||
!
livenessResult
.
isSuccess
()
||
null
==
livenessResult
.
getData
())
{
//没有查询到 活体视屏 和 照片 再次拉起腾讯活体H5
reponse
.
setStatus
(
2
);
LiveLoginReqDTO
loginUrlDto
=
new
LiveLoginReqDTO
();
loginUrlDto
.
setOrderNo
(
bean
.
getOrderNo
());
if
(
"PAD"
.
equals
(
bean
.
getSource
()))
{
loginUrlDto
.
setCallBackUrl
(
frontPersonPadCallBackUrl
);
}
else
{
loginUrlDto
.
setCallBackUrl
(
frontPersonH5CallBackUrl
);
}
//todo 调用云端接口
Response
<
LiveLoginRespDTO
>
h5LiveLoginUrl
=
fpRnrClient
.
h5LiveLoginUrl
(
loginUrlDto
);
if
(
h5LiveLoginUrl
.
isSuccess
())
{
reponse
.
setH5LivenessUrl
(
h5LiveLoginUrl
.
getData
().
getH5LiveLoginUrl
());
}
return
reponse
;
}
LivenessResultDTO
livenessResultData
=
livenessResult
.
getData
();
String
[]
livenessPhotos
=
new
String
[
2
];
livenessPhotos
[
0
]
=
livenessResultData
.
getPhotoId
();
livenessPhotos
[
1
]
=
livenessResultData
.
getPhotoId
();
callBackDto
.
setLivenessPicFileId
(
livenessPhotos
);
callBackDto
.
setVideFileId
(
livenessResultData
.
getVideoFileId
());
Response
<
Integer
>
response
=
fpRnrClient
.
personH5CallBack
(
callBackDto
);
if
(!
response
.
isSuccess
()
||
null
==
response
.
getData
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
Integer
data
=
response
.
getData
();
reponse
.
setStatus
(
data
);
}
else
{
//活体失败
reponse
.
setStatus
(
2
);
LiveLoginReqDTO
loginUrlDto
=
new
LiveLoginReqDTO
();
loginUrlDto
.
setOrderNo
(
bean
.
getOrderNo
());
if
(
"PAD"
.
equals
(
bean
.
getSource
()))
{
loginUrlDto
.
setCallBackUrl
(
frontPersonPadCallBackUrl
);
}
else
{
loginUrlDto
.
setCallBackUrl
(
frontPersonH5CallBackUrl
);
}
Response
<
LiveLoginRespDTO
>
h5LiveLoginUrl
=
fpRnrClient
.
h5LiveLoginUrl
(
loginUrlDto
);
if
(
h5LiveLoginUrl
.
isSuccess
())
{
reponse
.
setH5LivenessUrl
(
h5LiveLoginUrl
.
getData
().
getH5LiveLoginUrl
());
}
//需要修改数据状态
//RnrOrderDTO orderDTO = new RnrOrderDTO();
//orderDTO.setUuid(bean.getOrderNo());
//fpRnrClient.updateRnrInValid(orderDTO);
}
return
reponse
;
}
//-------------私有方法区----------------------
/**
* 转成实名信息
*
* @param requestDTO 请求消息
*/
private
RnrRelationDTO
convertToRelationDTO
(
PersonalRnrRequestDTO
requestDTO
)
{
String
rnrID
=
CuscStringUtils
.
generateUuid
();
RnrRelationDTO
rnrRelationDTO
=
new
RnrRelationDTO
();
String
tenantNo
=
UserSubjectUtil
.
getTenantNo
();
//租户
rnrRelationDTO
.
setTenantNo
(
tenantNo
);
rnrRelationDTO
.
setIsTrust
(
requestDTO
.
getIsConsigner
()
?
1
:
0
);
rnrRelationDTO
.
setIsSecondHandCar
(
requestDTO
.
getCustomerType
()
==
1
?
1
:
0
);
//查询当前用户的组织id
String
orgId
=
userService
.
getOrganId
(
UserSubjectUtil
.
getUserId
(),
tenantNo
);
//实名实体信息
MgRnrInfoDTO
rnrInfoDTO
=
getMgRnrInfoDTO
(
requestDTO
,
rnrID
);
rnrInfoDTO
.
setOrgId
(
orgId
);
rnrRelationDTO
.
setInfo
(
rnrInfoDTO
);
//实名工单信息
RnrOrderDTO
orderDTO
=
getMgRnrOrderDTO
(
requestDTO
,
rnrRelationDTO
);
orderDTO
.
setOrgId
(
orgId
);
orderDTO
.
setTenantNo
(
tenantNo
);
rnrRelationDTO
.
setOrder
(
orderDTO
);
//实名卡信息
rnrRelationDTO
.
setCardList
(
getMgRnrCardDTOs
(
requestDTO
,
rnrRelationDTO
));
//联系人信息
if
(
requestDTO
.
getIsConsigner
())
{
rnrRelationDTO
.
setRnrLiaisonList
(
getMgRnrLiaisonDTOs
(
requestDTO
,
rnrRelationDTO
));
}
//实名文件信息
rnrRelationDTO
.
setRnrFileList
(
getMgRnrFileDTOs
(
requestDTO
,
rnrRelationDTO
));
return
rnrRelationDTO
;
}
/**
* 创建工单信息
*
* @param requestDTO 请求消息
* @param rnrRelationDTO 实名消息
*/
private
RnrOrderDTO
getMgRnrOrderDTO
(
PersonalRnrRequestDTO
requestDTO
,
RnrRelationDTO
rnrRelationDTO
)
{
//二手车、或者证书类型不是身份证都是手工
boolean
sendWorkOrder
=
isSendWorkOrder
(
requestDTO
);
boolean
isSecondHandCar
=
rnrRelationDTO
.
getIsSecondHandCar
()
==
1
;
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setOrderType
(
isSecondHandCar
?
RnrOrderType
.
SEC_VEHICLE
.
getCode
()
:
RnrOrderType
.
NEW_VEHICLE
.
getCode
());
rnrOrderDTO
.
setRnrId
(
rnrRelationDTO
.
getInfo
().
getUuid
());
rnrOrderDTO
.
setAuditType
(
sendWorkOrder
?
RnrOrderAuditTypeEnum
.
MANUAL
.
getCode
()
:
RnrOrderAuditTypeEnum
.
AUTO
.
getCode
());
rnrOrderDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
rnrOrderDTO
.
setAutoRnr
(!
sendWorkOrder
);
rnrOrderDTO
.
setIsBatchOrder
(
0
);
rnrOrderDTO
.
setSerialNumber
(
rnrRelationDTO
.
getInfo
().
getSerial_number
());
rnrOrderDTO
.
setOrderSource
(
RnrOrderSourceEnum
.
PORTAL
.
getCode
());
rnrOrderDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setSendWorkOrder
(
sendWorkOrder
);
rnrOrderDTO
.
setOrderStatus
(
sendWorkOrder
?
RnrOrderStatusEnum
.
ASSIGNMENT
.
getCode
()
:
RnrOrderStatusEnum
.
PASS
.
getCode
());
rnrOrderDTO
.
setRnrBizzType
(
requestDTO
.
getRnrBizzTypeEnum
());
return
rnrOrderDTO
;
}
/**
* 判断是否是是否需要发送工单
*
* @param requestDTO
* @return
*/
private
boolean
isSendWorkOrder
(
PersonalRnrRequestDTO
requestDTO
)
{
//二手车实名,委托人模式,新车车主非身份证模式都需要发送工单
return
requestDTO
.
getCustomerType
()
==
CustomerTypeEnum
.
USED_CAR_OWNER
.
getCode
()
||
requestDTO
.
getIsConsigner
()
||
!
StringUtils
.
equalsIgnoreCase
(
requestDTO
.
getCertType
(),
CertTypeEnum
.
IDCARD
.
getCode
());
}
/**
* 获取联系人信息
*
* @param requestDTO 请求消息
*/
private
List
<
MgRnrLiaisonInfoDTO
>
getMgRnrLiaisonDTOs
(
PersonalRnrRequestDTO
requestDTO
,
RnrRelationDTO
rnrRelationDTO
)
{
List
<
MgRnrLiaisonInfoDTO
>
liaisonInfoDTOS
=
new
ArrayList
<>();
ConsignerInfoDTO
consignerInfo
=
requestDTO
.
getConsignerInfo
();
MgRnrLiaisonInfoDTO
mgRnrLiaisonInfoDTO
=
new
MgRnrLiaisonInfoDTO
();
mgRnrLiaisonInfoDTO
.
setLiaisonName
(
consignerInfo
.
getFullName
());
mgRnrLiaisonInfoDTO
.
setLiaisonPhone
(
consignerInfo
.
getPhone
());
mgRnrLiaisonInfoDTO
.
setLiaisonCertAddress
(
consignerInfo
.
getCertAddress
());
mgRnrLiaisonInfoDTO
.
setLiaisonCertNumber
(
consignerInfo
.
getCertNumber
());
mgRnrLiaisonInfoDTO
.
setLiaisonCertType
(
consignerInfo
.
getCertType
());
mgRnrLiaisonInfoDTO
.
setLiaisonContactAddress
(
consignerInfo
.
getContactAddress
());
mgRnrLiaisonInfoDTO
.
setLiaisonType
(
RnrLiaisonType
.
CONSIGNEE
.
getCode
());
mgRnrLiaisonInfoDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
mgRnrLiaisonInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrLiaisonInfoDTO
.
setRnrId
(
rnrRelationDTO
.
getInfo
().
getUuid
());
mgRnrLiaisonInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrLiaisonInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrLiaisonInfoDTO
.
setRnrBizzType
(
requestDTO
.
getRnrBizzTypeEnum
());
mgRnrLiaisonInfoDTO
.
setLiaisonExpiredDate
(
requestDTO
.
getCertExpirationDate
());
mgRnrLiaisonInfoDTO
.
setLiaisonGender
(
consignerInfo
.
getGender
());
mgRnrLiaisonInfoDTO
.
setLiaisonExpiredDate
(
consignerInfo
.
getCertExpirationDate
());
liaisonInfoDTOS
.
add
(
mgRnrLiaisonInfoDTO
);
return
liaisonInfoDTOS
;
}
/**
* 获取实名文件信息
*
* @param requestDTO 请求消息
*/
private
List
<
MgRnrFileDTO
>
getMgRnrFileDTOs
(
PersonalRnrRequestDTO
requestDTO
,
RnrRelationDTO
rnrRelationDTO
)
{
List
<
MgRnrFileDTO
>
mgRnrFileDTOS
=
new
ArrayList
<>();
String
rnrId
=
rnrRelationDTO
.
getInfo
().
getUuid
();
int
rnrBizzTypeEnum
=
requestDTO
.
getRnrBizzTypeEnum
();
//证件照片
List
<
String
>
certPic
=
requestDTO
.
getCertPic
();
for
(
int
i
=
0
;
i
<
certPic
.
size
();
i
++)
{
String
pic
=
certPic
.
get
(
i
);
Integer
fileType
=
FileUtil
.
getFileType
(
requestDTO
.
getCertType
(),
i
);
if
(
fileType
!=
null
)
{
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
pic
,
fileType
,
rnrBizzTypeEnum
));
}
}
if
(
requestDTO
.
getIsConsigner
())
{
String
consignerId
=
rnrRelationDTO
.
getRnrLiaisonList
().
get
(
0
).
getUuid
();
//委托人照片
List
<
String
>
consignerPic
=
requestDTO
.
getConsignerInfo
().
getCertPic
();
for
(
int
i
=
0
;
i
<
consignerPic
.
size
();
i
++)
{
String
pic
=
consignerPic
.
get
(
i
);
Integer
fileType
=
FileUtil
.
getFileType
(
requestDTO
.
getConsignerInfo
().
getCertType
(),
i
);
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
pic
,
fileType
,
consignerId
,
rnrBizzTypeEnum
));
}
//委托书
for
(
String
attorney
:
requestDTO
.
getConsignerInfo
().
getAttorneyLetterPic
())
{
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
attorney
,
RnrFileType
.
LETTER_ATTORNEY
.
getCode
(),
consignerId
,
rnrBizzTypeEnum
));
}
//活体视频
if
(
StringUtils
.
isNotBlank
(
requestDTO
.
getLiveVerificationVideo
()))
{
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
requestDTO
.
getLiveVerificationVideo
(),
RnrFileType
.
LIVENESS_VIDEO
.
getCode
(),
consignerId
,
rnrBizzTypeEnum
));
}
}
else
{
//活体视频
if
(
StringUtils
.
isNotBlank
(
requestDTO
.
getLiveVerificationVideo
()))
{
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
requestDTO
.
getLiveVerificationVideo
(),
RnrFileType
.
LIVENESS_VIDEO
.
getCode
(),
rnrBizzTypeEnum
));
}
}
//二手车,购车合同,购车发票,过户合同
if
(
requestDTO
.
getCustomerType
()
==
CustomerTypeEnum
.
USED_CAR_OWNER
.
getCode
())
{
if
(!
CollectionUtils
.
isEmpty
(
requestDTO
.
getPurchaseInvoicePic
()))
{
for
(
String
invoice
:
requestDTO
.
getPurchaseInvoicePic
())
{
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
invoice
,
RnrFileType
.
CAR_PURCHASE_INVOICE
.
getCode
(),
rnrBizzTypeEnum
));
}
}
for
(
String
contract
:
requestDTO
.
getPurchaseContractPic
())
{
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
contract
,
RnrFileType
.
CAR_PURCHASE_CONTRACT
.
getCode
(),
rnrBizzTypeEnum
));
}
for
(
String
transfer
:
requestDTO
.
getTransferCertificatePic
())
{
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
transfer
,
RnrFileType
.
CAR_TRANSFER_CERTIFICATE
.
getCode
(),
rnrBizzTypeEnum
));
}
}
//入网合同
if
(!
CollectionUtils
.
isEmpty
(
requestDTO
.
getContractPic
()))
{
for
(
String
contractPic
:
requestDTO
.
getContractPic
())
{
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
contractPic
,
RnrFileType
.
VEHUCLE_BIND
.
getCode
(),
rnrBizzTypeEnum
));
}
}
//责任告知书
if
(!
CollectionUtils
.
isEmpty
(
requestDTO
.
getDutyPic
()))
{
for
(
String
duty:
requestDTO
.
getDutyPic
())
{
mgRnrFileDTOS
.
add
(
FileUtil
.
newFileDTO
(
rnrId
,
duty
,
RnrFileType
.
DUTY_FILE
.
getCode
(),
rnrBizzTypeEnum
));
}
}
return
mgRnrFileDTOS
;
}
/**
* 获取实名卡信息
*
* @param requestDTO 请求消息
*/
private
List
<
MgRnrCardInfoDTO
>
getMgRnrCardDTOs
(
PersonalRnrRequestDTO
requestDTO
,
RnrRelationDTO
rnrRelationDTO
)
{
List
<
String
>
iccidList
=
requestDTO
.
getIccidList
();
List
<
MgRnrCardInfoDTO
>
mgRnrCardInfoDTOS
=
new
ArrayList
<>();
MgRnrCardInfoDTO
mgRnrCardInfoDTO
;
for
(
String
iccid
:
iccidList
)
{
mgRnrCardInfoDTO
=
new
MgRnrCardInfoDTO
();
mgRnrCardInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrCardInfoDTO
.
setIccid
(
iccid
);
mgRnrCardInfoDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
mgRnrCardInfoDTO
.
setIotId
(
requestDTO
.
getVin
());
mgRnrCardInfoDTO
.
setRnrId
(
rnrRelationDTO
.
getInfo
().
getUuid
());
mgRnrCardInfoDTO
.
setOrderId
(
rnrRelationDTO
.
getOrder
().
getUuid
());
mgRnrCardInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrCardInfoDTO
.
setRnrBizzType
(
requestDTO
.
getRnrBizzTypeEnum
());
mgRnrCardInfoDTOS
.
add
(
mgRnrCardInfoDTO
);
}
return
mgRnrCardInfoDTOS
;
}
/**
* 获取实名主体信息
*
* @param requestDTO 请求消息
*/
private
MgRnrInfoDTO
getMgRnrInfoDTO
(
PersonalRnrRequestDTO
requestDTO
,
String
rnrID
)
{
MgRnrInfoDTO
mgRnrInfoDTO
=
PersonalRnrRequestConvert
.
INSTANCE
.
requestDTOToMgRnrDTO
(
requestDTO
);
mgRnrInfoDTO
.
setIsCompany
(
0
);
mgRnrInfoDTO
.
setIsTrust
(
requestDTO
.
getIsConsigner
()
?
1
:
0
);
mgRnrInfoDTO
.
setIsSecondHandCar
(
Objects
.
equals
(
requestDTO
.
getCustomerType
(),
CustomerTypeEnum
.
NEW_CAR_OWNER
.
getCode
())
?
0
:
1
);
mgRnrInfoDTO
.
setUuid
(
rnrID
);
mgRnrInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrInfoDTO
.
setSerial_number
(
CuscStringUtils
.
generateUuid
());
mgRnrInfoDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
mgRnrInfoDTO
.
setRnrStatus
(
RnrStatus
.
INIT
.
getCode
());
mgRnrInfoDTO
.
setRnrBizzType
(
requestDTO
.
getRnrBizzTypeEnum
());
mgRnrInfoDTO
.
setEffectiveDate
(
DateUtils
.
parseDate
(
requestDTO
.
getCertEffectiveDate
(),
"yyyy-MM-dd"
));
mgRnrInfoDTO
.
setExpiredDate
(
requestDTO
.
getCertExpirationDate
());
return
mgRnrInfoDTO
;
}
/**
* 进行参数验证
*
* @param requestDTO 请求消息
*/
private
Response
validRnrInfo
(
PersonalRnrRequestDTO
requestDTO
,
boolean
unbind
)
{
// if (StringUtils.isBlank(requestDTO.getPurchaseContract())) {
// return Response.createError("购车合同不能为空", ResponseCode.INVALID_DATA.getCode());
// }
// if (StringUtils.isBlank(requestDTO.getPurchaseInvoice())) {
// return Response.createError("购车证明不能为空", ResponseCode.INVALID_DATA.getCode());
// }
//检查手机
Response
response
=
ValidationUtil
.
checkPhone
(
requestDTO
.
getPhone
());
if
(!
response
.
isSuccess
())
{
return
response
;
}
//性别校验
response
=
validGender
(
requestDTO
.
getGender
());
if
(!
response
.
isSuccess
())
{
return
response
;
}
//校验证件号码
response
=
ValidationUtil
.
checkIdentifyNumber
(
requestDTO
.
getCertType
(),
requestDTO
.
getCertNumber
());
if
(!
response
.
isSuccess
())
{
return
response
;
}
//证件照数量验证
response
=
ValidationUtil
.
checkIdentifyPics
(
requestDTO
.
getCertType
(),
requestDTO
.
getCertPic
().
size
());
if
(!
response
.
isSuccess
())
{
return
response
;
}
//二手车车主,需要有过户证明
if
(
requestDTO
.
getCustomerType
()
==
CustomerTypeEnum
.
USED_CAR_OWNER
.
getCode
())
{
if
(
CollectionUtils
.
isEmpty
(
requestDTO
.
getTransferCertificatePic
()))
{
return
Response
.
createError
(
"过户证明不能为空"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
if
(
CollectionUtils
.
isEmpty
(
requestDTO
.
getPurchaseContractPic
()))
{
return
Response
.
createError
(
"购车合同不能为空"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
if
(!
unbind
&&
CollectionUtils
.
isEmpty
(
requestDTO
.
getPurchaseInvoicePic
()))
{
return
Response
.
createError
(
"购车发票不能为空"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
}
if
(
requestDTO
.
getIsConsigner
())
{
//验证委托人关系
ConsignerInfoDTO
consignerInfo
=
requestDTO
.
getConsignerInfo
();
Set
<
ConstraintViolation
<
ConsignerInfoDTO
>>
violations
=
SpringValidationUtil
.
groupVerificationParameters
(
consignerInfo
);
if
(!
violations
.
isEmpty
())
{
return
Response
.
createError
(
violations
.
stream
().
findFirst
().
get
().
getMessage
());
}
//性别校验
response
=
validGender
(
consignerInfo
.
getGender
());
if
(!
response
.
isSuccess
())
{
return
response
;
}
//校验证件号码
response
=
ValidationUtil
.
checkIdentifyNumber
(
consignerInfo
.
getCertType
(),
consignerInfo
.
getCertNumber
());
if
(!
response
.
isSuccess
())
{
return
response
;
}
//证件照数量验证
response
=
ValidationUtil
.
checkIdentifyPics
(
consignerInfo
.
getCertType
(),
consignerInfo
.
getCertPic
().
size
());
if
(!
response
.
isSuccess
())
{
return
response
;
}
//检查手机
response
=
ValidationUtil
.
checkPhone
(
consignerInfo
.
getPhone
());
if
(!
response
.
isSuccess
())
{
return
response
;
}
}
else
{
//没有委托人,车主验证码必填
if
(
StringUtils
.
isBlank
(
requestDTO
.
getVerificationCode
()))
{
return
Response
.
createError
(
"手机验证码不能为空"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
}
return
Response
.
createSuccess
();
}
/**
* 校验性别
*
*/
private
Response
validGender
(
Integer
gender
)
{
if
(
gender
==
null
||
(
gender
!=
GenderEnum
.
FEMALE
.
getCode
()
&&
gender
!=
GenderEnum
.
MALE
.
getCode
()))
{
return
Response
.
createError
(
"性别格式错误"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
return
Response
.
createSuccess
();
}
@Override
public
Response
<
RnrResponseDTO
>
h5ValidationOCR
(
H5ValidationOCRReqDTO
bean
)
{
bean
.
setIsIdentityCard
(
true
);
bean
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
bean
.
setBizUuid
(
RnrBizzTypeEnum
.
Bind
.
getCode
().
toString
());
bean
.
setSerialNumber
(
CuscStringUtils
.
generateUuid
());
log
.
info
(
"h5ValidationOCR request :"
+
JSONObject
.
toJSONString
(
bean
));
Response
<
RnrResponseDTO
>
response
=
fpRnrClient
.
h5ValidationOCR
(
bean
);
log
.
info
(
"h5ValidationOCR response :"
+
JSONObject
.
toJSONString
(
response
));
return
response
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/ProtocolManageServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.eiam.client.OrganizationClient
;
import
com.cusc.nirvana.user.eiam.client.UserClient
;
import
com.cusc.nirvana.user.eiam.client.UserOrganClient
;
import
com.cusc.nirvana.user.eiam.dto.OrganizationDTO
;
import
com.cusc.nirvana.user.eiam.dto.UserOrganDTO
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.config.EnterpriseConfig
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.FileMouldEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.ResponseCode
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.*
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IProtocolManageService
;
import
com.cusc.nirvana.user.rnr.fp.client.FileSystemClient
;
import
com.cusc.nirvana.user.rnr.fp.client.FpRnrProtocolManageClient
;
import
com.cusc.nirvana.user.rnr.fp.client.OrganClient
;
import
com.cusc.nirvana.user.rnr.fp.dto.FileRecordDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.FpRnrProtocolManageDTO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.formula.functions.T
;
import
org.checkerframework.checker.units.qual.K
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.Resource
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.*
;
import
java.util.concurrent.Future
;
import
java.util.stream.Collectors
;
/**
* @className: ProtocolManageServiceImpl
* @description: 协议管理
* @author: jk
* @date: 2022/6/1 13:55
* @version: 1.0
**/
@Service
@Slf4j
@RefreshScope
public
class
ProtocolManageServiceImpl
implements
IProtocolManageService
{
@Resource
private
FpRnrProtocolManageClient
fpRnrProtocolManageClient
;
@Resource
private
UserClient
userClient
;
@Value
(
"${user.eiam.applicationId:4}"
)
private
String
applicationId
;
@Value
(
"${rnr.fileMouldUrl}"
)
private
String
fileMouldUrl
;
@Resource
private
UserOrganClient
userOrganClient
;
@Resource
private
FileSystemClient
fileSystemClient
;
@Resource
private
OrganClient
organClient
;
@Resource
private
EnterpriseConfig
enterpriseConfig
;
@Resource
private
OrganizationClient
organizationClient
;
@Override
public
void
add
(
ProtocolManageDTO
dto
)
{
//根据当前登录人获取组织id
UserOrganDTO
userOrganDTO
=
this
.
queryUserOrgan
();
if
(
StringUtils
.
isEmpty
(
UserSubjectUtil
.
getUserId
())){
throw
new
CuscUserException
(
ResponseCode
.
DATA_NULL
.
getCode
(),
ResponseCode
.
DATA_NULL
.
getMsg
());
}
//通过组织id出协议文件
FpRnrProtocolManageDTO
fpRnrProtocolManageDTO
=
new
FpRnrProtocolManageDTO
();
fpRnrProtocolManageDTO
.
setOrgId
(
dto
.
getOrgId
());
Response
<
List
<
FpRnrProtocolManageDTO
>>
responseList
=
fpRnrProtocolManageClient
.
queryByList
(
fpRnrProtocolManageDTO
);
if
(!
responseList
.
isSuccess
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYS_BUSY
.
getCode
(),
ResponseCode
.
SYS_BUSY
.
getMsg
());
}
if
(!
CollectionUtils
.
isEmpty
(
responseList
.
getData
())){
throw
new
CuscUserException
(
ResponseCode
.
ProtocolManage_NOT_NULL
.
getCode
(),
ResponseCode
.
ProtocolManage_NOT_NULL
.
getMsg
());
}
FpRnrProtocolManageDTO
fpRnrProtocolManage
=
new
FpRnrProtocolManageDTO
();
BeanUtils
.
copyProperties
(
dto
,
fpRnrProtocolManage
);
fpRnrProtocolManage
.
setCreator
(
UserSubjectUtil
.
getUserId
());
fpRnrProtocolManage
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
fpRnrProtocolManage
.
setOrgId
(
dto
.
getOrgId
());
log
.
warn
(
"fpRnrProtocolManage入参{}"
,
JSONObject
.
toJSONString
(
fpRnrProtocolManage
));
fpRnrProtocolManageClient
.
add
(
fpRnrProtocolManage
);
}
@Override
public
void
update
(
ProtocolManageUpdateDTO
dto
)
{
if
(
StringUtils
.
isEmpty
(
dto
.
getUuid
())){
throw
new
CuscUserException
(
ResponseCode
.
UUID_NULL
.
getCode
(),
ResponseCode
.
UUID_NULL
.
getMsg
());
}
//获取当前登录人数据
UserOrganDTO
userOrganDTO
=
this
.
queryUserOrgan
();
FpRnrProtocolManageDTO
fpRnrProtocolManageDTO
=
new
FpRnrProtocolManageDTO
();
BeanUtils
.
copyProperties
(
dto
,
fpRnrProtocolManageDTO
);
fpRnrProtocolManageDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
fpRnrProtocolManageDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
fpRnrProtocolManageDTO
.
setOrgId
(
dto
.
getOrgId
());
fpRnrProtocolManageClient
.
update
(
fpRnrProtocolManageDTO
);
}
@Override
public
Response
<
List
<
ProtocolManageDTO
>>
query
(
ProtocolManageUpdateDTO
dto
)
{
UserOrganDTO
userOrganDTO
=
this
.
queryUserOrgan
();
//没有登录直接展示最上级LOGO
OrganizationDTO
organizationDTO
=
new
OrganizationDTO
();
organizationDTO
.
setUuid
(
dto
.
getOrgId
());
organizationDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
<
OrganizationDTO
>
organizationDTOResponse
=
organClient
.
getCarSubOrganByOrganId
(
organizationDTO
);
if
(!
organizationDTOResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
organizationDTOResponse
.
getCode
(),
organizationDTOResponse
.
getMsg
());
}
//通过组织id出协议文件
FpRnrProtocolManageDTO
fpRnrProtocolManageDTO
=
new
FpRnrProtocolManageDTO
();
fpRnrProtocolManageDTO
.
setOrgId
(
organizationDTOResponse
.
getData
().
getUuid
());
fpRnrProtocolManageDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
<
List
<
FpRnrProtocolManageDTO
>>
responseList
=
fpRnrProtocolManageClient
.
queryByList
(
fpRnrProtocolManageDTO
);
if
(!
responseList
.
isSuccess
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYS_BUSY
.
getCode
(),
ResponseCode
.
SYS_BUSY
.
getMsg
());
}
List
<
FpRnrProtocolManageDTO
>
rnrProtocolManageDTOList
=
responseList
.
getData
();
if
(
CollectionUtils
.
isEmpty
(
rnrProtocolManageDTOList
))
{
return
Response
.
createSuccess
(
rnrProtocolManageDTOList
);
}
FpRnrProtocolManageDTO
fpRnrProtocolManage
=
rnrProtocolManageDTOList
.
get
(
0
);
ProtocolManageDTO
protocolManageDTO
=
new
ProtocolManageDTO
();
String
orgId
=
fpRnrProtocolManage
.
getOrgId
();
ProtocolManageOneDTO
protocolManageOneDTO
=
new
ProtocolManageOneDTO
();
BeanUtils
.
copyProperties
(
fpRnrProtocolManage
,
protocolManageOneDTO
);
//将对象属性转为map
Map
<
String
,
String
>
map
=
convertToMap
(
protocolManageOneDTO
);
Map
<
String
,
Object
>
mapReturn
=
new
HashMap
<>();
//并行调用查询文件路径
map
.
entrySet
().
stream
().
map
(
entry
->
{
if
(!
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
FileDownloadDTO
fileRecordDTO
=
new
FileDownloadDTO
();
fileRecordDTO
.
setUuid
(
entry
.
getValue
());
Response
<
FileRecordDTO
>
fileRecordDTOResponse
=
fileSystemClient
.
getUrl
(
fileRecordDTO
);
if
(!
fileRecordDTOResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYS_BUSY
.
getCode
(),
ResponseCode
.
SYS_BUSY
.
getMsg
());
}
ProtocolManageUrlDTO
protocolManageUrlDTO
=
new
ProtocolManageUrlDTO
();
protocolManageUrlDTO
.
setFileUrl
(
fileRecordDTOResponse
.
getData
().
getAccessUrl
());
//protocolManageUrlDTO.setFileName(fileRecordDTOResponse.getData().getFileName());
protocolManageUrlDTO
.
setUuid
(
fileRecordDTOResponse
.
getData
().
getUuid
());
mapReturn
.
put
(
entry
.
getKey
(),
protocolManageUrlDTO
);
}
else
{
mapReturn
.
put
(
entry
.
getKey
(),
""
);
}
return
mapReturn
;
//将路径塞进map对应的key中
// entry.setValue(fileRecordDTOResponse.getData().getPath());
}).
collect
(
Collectors
.
toList
());
mapReturn
.
put
(
"id"
,
fpRnrProtocolManage
.
getId
());
mapReturn
.
put
(
"uuid"
,
fpRnrProtocolManage
.
getUuid
());
mapReturn
.
put
(
"orgId"
,
fpRnrProtocolManage
.
getOrgId
());
//通过反射将map key对应value塞进对应bean属性中
// Object obj= toBean(map1,ProtocolManageDTO.class);
// protocolManageDTO = (ProtocolManageDTO)obj;
// protocolManageDTO.setOrgId(orgId);
return
Response
.
createSuccess
(
mapReturn
);
}
/**
* @author: jk
* @description: 查询文件模板
* @date: 2022/6/2 14:36
* @version: 1.0
* @Param:
* @Return:
*/
@Override
public
Response
<
Map
>
queryFileMould
()
{
String
[]
fileMouldList
=
fileMouldUrl
.
split
(
","
);
Map
<
String
,
String
>
map
=
new
HashMap
<>();
FileMouldEnum
[]
fileMouldEnums
=
FileMouldEnum
.
getFileMouldMap
();
for
(
FileMouldEnum
fileMouldEnum:
fileMouldEnums
){
FileDownloadDTO
fileRecordDTO
=
new
FileDownloadDTO
();
fileRecordDTO
.
setUuid
(
fileMouldList
[
fileMouldEnum
.
getCode
()]);
Response
<
FileRecordDTO
>
fileRecordDTOResponse
=
fileSystemClient
.
getUrl
(
fileRecordDTO
);
if
(!
fileRecordDTOResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYS_BUSY
.
getCode
(),
ResponseCode
.
SYS_BUSY
.
getMsg
());
}
map
.
put
(
fileMouldEnum
.
getMsg
(),
fileRecordDTOResponse
.
getData
().
getAccessUrl
());
}
return
Response
.
createSuccess
(
map
);
}
@Override
public
Response
<
List
<
ProtocolManageDTO
>>
noLogin
()
{
UserOrganDTO
userOrganDTO
=
this
.
queryUserOrgan
();
//没有登录直接展示最上级LOGO
//通过组织id出协议文件
OrganizationDTO
organizationDTO
=
new
OrganizationDTO
();
organizationDTO
.
setTenantNo
(
enterpriseConfig
.
getTenantNo
());
organizationDTO
.
setParentId
(
"0"
);
organizationDTO
.
setBizType
(
1
);
Response
<
List
<
OrganizationDTO
>>
re
=
organizationClient
.
queryByList
(
organizationDTO
);
if
(!
re
.
isSuccess
()){
throw
new
CuscUserException
(
""
,
"获取组织信息失败"
);
}
FpRnrProtocolManageDTO
fpRnrProtocolManageDTO
=
new
FpRnrProtocolManageDTO
();
fpRnrProtocolManageDTO
.
setTenantNo
(
enterpriseConfig
.
getTenantNo
());
fpRnrProtocolManageDTO
.
setType
(
"1"
);
Response
<
List
<
FpRnrProtocolManageDTO
>>
responseList
=
fpRnrProtocolManageClient
.
queryByList
(
fpRnrProtocolManageDTO
);
if
(!
responseList
.
isSuccess
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYS_BUSY
.
getCode
(),
ResponseCode
.
SYS_BUSY
.
getMsg
());
}
List
<
FpRnrProtocolManageDTO
>
rnrProtocolManageDTOList
=
responseList
.
getData
();
if
(
CollectionUtils
.
isEmpty
(
rnrProtocolManageDTOList
))
{
return
Response
.
createSuccess
(
rnrProtocolManageDTOList
);
}
FpRnrProtocolManageDTO
fpRnrProtocolManage
=
rnrProtocolManageDTOList
.
get
(
0
);
ProtocolManageDTO
protocolManageDTO
=
new
ProtocolManageDTO
();
String
orgId
=
fpRnrProtocolManage
.
getOrgId
();
ProtocolManageOneDTO
protocolManageOneDTO
=
new
ProtocolManageOneDTO
();
BeanUtils
.
copyProperties
(
fpRnrProtocolManage
,
protocolManageOneDTO
);
//将对象属性转为map
Map
<
String
,
String
>
map
=
convertToMap
(
protocolManageOneDTO
);
Map
<
String
,
Object
>
loginOutReturn
=
new
HashMap
<>();
//并行调用查询文件路径
map
.
entrySet
().
stream
().
map
(
entry
->
{
if
(!
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
FileDownloadDTO
fileRecordDTO
=
new
FileDownloadDTO
();
fileRecordDTO
.
setUuid
(
entry
.
getValue
());
Response
<
FileRecordDTO
>
fileRecordDTOResponse
=
fileSystemClient
.
getUrl
(
fileRecordDTO
);
if
(!
fileRecordDTOResponse
.
isSuccess
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYS_BUSY
.
getCode
(),
ResponseCode
.
SYS_BUSY
.
getMsg
());
}
ProtocolManageUrlDTO
protocolManageUrlDTO
=
new
ProtocolManageUrlDTO
();
protocolManageUrlDTO
.
setFileUrl
(
fileRecordDTOResponse
.
getData
().
getAccessUrl
());
//protocolManageUrlDTO.setFileName(fileRecordDTOResponse.getData().getFileName());
protocolManageUrlDTO
.
setUuid
(
fileRecordDTOResponse
.
getData
().
getUuid
());
if
(
StringUtils
.
isEmpty
(
UserSubjectUtil
.
getUserId
())
&&
(
"logoPc"
.
equals
(
entry
.
getKey
())
||
"logoH5"
.
equals
(
entry
.
getKey
())))
{
loginOutReturn
.
put
(
entry
.
getKey
(),
protocolManageUrlDTO
);
}
}
else
{
loginOutReturn
.
put
(
entry
.
getKey
(),
""
);
}
return
loginOutReturn
;
}).
collect
(
Collectors
.
toList
());
loginOutReturn
.
put
(
"id"
,
fpRnrProtocolManage
.
getId
());
loginOutReturn
.
put
(
"uuid"
,
fpRnrProtocolManage
.
getUuid
());
loginOutReturn
.
put
(
"orgId"
,
fpRnrProtocolManage
.
getOrgId
());
loginOutReturn
.
put
(
"organName"
,
re
.
getData
().
get
(
0
).
getOrganName
());
return
Response
.
createSuccess
(
loginOutReturn
);
}
//通过反射 将key映射到对象的bean中
public
static
T
toBean
(
Map
beanPropMap
,
Class
type
)
{
try
{
T
beanInstance
=
(
T
)
type
.
getConstructor
().
newInstance
();
for
(
Object
k
:
beanPropMap
.
keySet
())
{
String
key
=
(
String
)
k
;
Object
value
=
beanPropMap
.
get
(
k
);
if
(
value
!=
null
)
{
try
{
Field
field
=
type
.
getDeclaredField
(
key
);
field
.
setAccessible
(
true
);
field
.
set
(
beanInstance
,
value
);
field
.
setAccessible
(
false
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
return
beanInstance
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
void
main
(
String
[]
args
)
{
FpRnrProtocolManageDTO
fpRnrProtocolManageDTO
=
new
FpRnrProtocolManageDTO
();
fpRnrProtocolManageDTO
.
setOrgId
(
"11"
);
fpRnrProtocolManageDTO
.
setTenantNo
(
"222"
);
fpRnrProtocolManageDTO
.
setCompanyAgreementHorizontal
(
"1"
);
fpRnrProtocolManageDTO
.
setCompanyAgreementVertical
(
"2"
);
fpRnrProtocolManageDTO
.
setCompanyAgreementWord
(
"3"
);
fpRnrProtocolManageDTO
.
setOtherHorizontal
(
"4"
);
ProtocolManageOneDTO
protocolManageOneDTO
=
new
ProtocolManageOneDTO
();
BeanUtils
.
copyProperties
(
fpRnrProtocolManageDTO
,
protocolManageOneDTO
);
Map
<
String
,
String
>
map
=
convertToMap
(
protocolManageOneDTO
);
Map
<
String
,
ProtocolManageUrlDTO
>
map1
=
new
HashMap
<>();
List
<
Map
>
list
=
new
ArrayList
<>();
map
.
entrySet
().
stream
().
map
(
entry
->{
if
(!
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
FileRecordDTO
fileRecordDTO
=
new
FileRecordDTO
();
fileRecordDTO
.
setUuid
(
entry
.
getValue
());
ProtocolManageUrlDTO
protocolManageUrlDTO
=
new
ProtocolManageUrlDTO
();
protocolManageUrlDTO
.
setFileUrl
(
"fileRecordDTOResponse.getData().getPath()"
);
protocolManageUrlDTO
.
setFileName
(
"fileRecordDTOResponse.getData().getFileName()"
);
map1
.
put
(
entry
.
getKey
(),
protocolManageUrlDTO
);
System
.
out
.
println
(
entry
.
getValue
());
System
.
out
.
println
(
entry
.
getKey
());
System
.
out
.
println
(
JSONObject
.
toJSONString
(
fileRecordDTO
));
}
return
map1
;
}).
collect
(
Collectors
.
toList
());
list
.
add
(
map1
);
Object
fpRnrProtocolManageDTO1
=
toBean
(
map
,
QueryProtocolManageDTO
.
class
);
fpRnrProtocolManageDTO
=
(
FpRnrProtocolManageDTO
)
fpRnrProtocolManageDTO1
;
// mapToObject(map,fpRnrProtocolManageDTO);
System
.
out
.
println
(
JSONObject
.
toJSONString
(
map
));
}
//将java对象转为map为了方便调用文件查询接口
public
static
Map
<
String
,
String
>
convertToMap
(
Object
obj
)
{
try
{
if
(
obj
instanceof
Map
)
{
return
(
Map
)
obj
;
}
Map
<
String
,
String
>
returnMap
=
org
.
apache
.
commons
.
beanutils
.
BeanUtils
.
describe
(
obj
);
returnMap
.
remove
(
"class"
);
return
returnMap
;
}
catch
(
IllegalAccessException
e1
)
{
e1
.
getMessage
();
}
catch
(
InvocationTargetException
e2
)
{
e2
.
getMessage
();
}
catch
(
NoSuchMethodException
e3
)
{
e3
.
getMessage
();
}
return
new
HashMap
();
}
public
UserOrganDTO
queryUserOrgan
(){
//根据当前登录人获取组织id
UserOrganDTO
userOrganDTO
=
new
UserOrganDTO
();
userOrganDTO
.
setUserId
(
UserSubjectUtil
.
getUserId
());
Response
<
List
<
UserOrganDTO
>>
response
=
userOrganClient
.
queryByList
(
userOrganDTO
);
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
ResponseCode
.
SYS_BUSY
.
getCode
(),
ResponseCode
.
SYS_BUSY
.
getMsg
());
}
List
<
UserOrganDTO
>
userOrganDTOList
=
response
.
getData
();
if
(
CollectionUtils
.
isEmpty
(
userOrganDTOList
)){
throw
new
CuscUserException
(
ResponseCode
.
USER_ORGAN_NOT_FOUND
.
getCode
(),
ResponseCode
.
USER_ORGAN_NOT_FOUND
.
getMsg
());
}
return
userOrganDTOList
.
get
(
0
);
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/RoleServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.eiam.client.OrganizationClient
;
import
com.cusc.nirvana.user.eiam.dto.OrganizationDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.common.RoleEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.RoleDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IRoleService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
* @author stayAnd
* @date 2022/4/15
*/
@Service
public
class
RoleServiceImpl
implements
IRoleService
{
@Resource
private
OrganizationClient
organizationClient
;
@Override
public
List
<
RoleDTO
>
getRoListByOrganId
(
String
organId
)
{
OrganizationDTO
dto
=
new
OrganizationDTO
();
dto
.
setUuid
(
organId
);
dto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
<
OrganizationDTO
>
reposne
=
organizationClient
.
getByUuid
(
dto
);
if
(
reposne
==
null
||
!
reposne
.
isSuccess
()
||
null
==
reposne
.
getData
())
{
return
Collections
.
emptyList
();
}
OrganizationDTO
data
=
reposne
.
getData
();
List
<
RoleDTO
>
roleDTOList
=
new
ArrayList
<>();
if
(
data
.
getBizType
()
==
1
)
{
roleDTOList
.
add
(
new
RoleDTO
().
setRoleCode
(
RoleEnum
.
CAR_ENTERPRISES_OP
.
getCode
()).
setRoleName
(
RoleEnum
.
CAR_ENTERPRISES_OP
.
getName
()));
}
else
if
(
data
.
getBizType
()
==
2
){
roleDTOList
.
add
(
new
RoleDTO
().
setRoleCode
(
RoleEnum
.
DISTRIBUTOR_ENTERPRISES_OP
.
getCode
()).
setRoleName
(
RoleEnum
.
DISTRIBUTOR_ENTERPRISES_OP
.
getName
()));
}
else
if
(
data
.
getBizType
()
==
3
){
roleDTOList
.
add
(
new
RoleDTO
().
setRoleCode
(
RoleEnum
.
CAR_ENTERPRISES_OP
.
getCode
()).
setRoleName
(
RoleEnum
.
CAR_ENTERPRISES_OP
.
getName
()));
}
return
roleDTOList
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/SearchCardAuthServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.cusc.nirvana.common.result.PageResult
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.eiam.client.OrganizationClient
;
import
com.cusc.nirvana.user.eiam.client.RoleClient
;
import
com.cusc.nirvana.user.eiam.dto.OrganizationDTO
;
import
com.cusc.nirvana.user.eiam.dto.UserOrganDTO
;
import
com.cusc.nirvana.user.eiam.dto.UserRoleDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.SearchCardAuthDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ISearchCardAuthService
;
import
com.cusc.nirvana.user.rnr.enterprise.util.DesensitizationUtil
;
import
com.cusc.nirvana.user.rnr.fp.client.FpSearchCardAuthClient
;
import
com.cusc.nirvana.user.rnr.fp.client.OrganClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgCheckProgressClient
;
import
com.cusc.nirvana.user.rnr.mg.dto.*
;
import
com.cusc.nirvana.user.util.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 查询车辆认证进度
* @modify 单车进度查询封装返回结果 2022-05-18
*/
@Service
@Slf4j
public
class
SearchCardAuthServiceImpl
implements
ISearchCardAuthService
{
@Resource
private
FpSearchCardAuthClient
fpSearchCardAuthClient
;
@Resource
private
MgCheckProgressClient
mgCheckProgressClient
;
@Resource
private
OrganClient
organClient
;
@Resource
private
OrganizationClient
organizationClient
;
@Resource
private
RoleClient
roleClient
;
/**
* 单车进度
* @modify 查脱敏配置进行数据脱敏
* @param bean
* @return
*/
@Override
public
Response
<
List
<
MgSearchCardAuthDTO
>>
searchAuth1
(
SearchCardAuthDTO
bean
)
{
MgRnrCardInfoDTO
cardInfoDTO
=
new
MgRnrCardInfoDTO
();
cardInfoDTO
.
setIotId
(
bean
.
getVin
());
Response
<
List
<
MgSearchCardAuthDTO
>>
response
=
fpSearchCardAuthClient
.
getMgSearchCardAuthDTO
(
cardInfoDTO
);
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
List
<
MgSearchCardAuthDTO
>
cardAuthDTOList
=
response
.
getData
();
//查询脱敏配置 false 脱敏, true 不脱敏
Boolean
hideSensitive
=
getHideSensitiveByUserId
();
List
<
MgCheckProgressDTO
>
collect
=
cardAuthDTOList
.
stream
().
map
(
cardAuthDTO
->
{
MgCheckProgressDTO
checkProgressDTO
=
new
MgCheckProgressDTO
();
if
(
hideSensitive
){
checkProgressDTO
.
setIotId
(
cardAuthDTO
.
getCardInfoDTO
().
getIotId
());
checkProgressDTO
.
setFullName
(
cardAuthDTO
.
getRnrInfoDTO
().
getFullName
());
checkProgressDTO
.
setPhone
(
cardAuthDTO
.
getRnrInfoDTO
().
getPhone
());
}
else
{
checkProgressDTO
.
setIotId
(
DesensitizationUtil
.
desensitizeVin
(
cardAuthDTO
.
getCardInfoDTO
().
getIotId
()));
checkProgressDTO
.
setFullName
(
DesensitizationUtil
.
desensitizeName
(
cardAuthDTO
.
getRnrInfoDTO
().
getFullName
()));
checkProgressDTO
.
setPhone
(
DesensitizationUtil
.
desensitizePhone
(
cardAuthDTO
.
getRnrInfoDTO
().
getPhone
()));
}
checkProgressDTO
.
setIccid
(
cardAuthDTO
.
getCardInfoDTO
().
getIccid
());
checkProgressDTO
.
setOrderType
(
String
.
valueOf
(
cardAuthDTO
.
getRnrOrderDTO
().
getOrderType
()));
checkProgressDTO
.
setOrderStatus
(
String
.
valueOf
(
cardAuthDTO
.
getRnrOrderDTO
().
getOrderStatus
()));
checkProgressDTO
.
setStartCheckDate
(
DateUtils
.
formatDatetime
(
cardAuthDTO
.
getRnrOrderDTO
().
getCreateTime
()));
checkProgressDTO
.
setCompanyName
(
cardAuthDTO
.
getCompanyInfoDTO
()!=
null
?
cardAuthDTO
.
getCompanyInfoDTO
().
getCompanyName
():
""
);
checkProgressDTO
.
setOrgName
(
cardAuthDTO
.
getOrgName
());
return
checkProgressDTO
;
}).
collect
(
Collectors
.
toList
());
return
Response
.
createSuccess
(
"查询成功!"
,
collect
);
}
/**
* 审核列表
* @param bean
* @return
*/
@Override
public
Response
searchAuth2
(
SearchCardAuthDTO
bean
)
{
MgCheckProgressDTO
checkProgressDTO
=
new
MgCheckProgressDTO
();
//查询dto转换
checkProgressDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
checkProgressDTO
.
setIotId
(
bean
.
getVin
());
checkProgressDTO
.
setIccid
(
bean
.
getIccid
());
checkProgressDTO
.
setFullName
(
bean
.
getUser
());
checkProgressDTO
.
setPhone
(
bean
.
getUserPhone
());
checkProgressDTO
.
setCompanyName
(
bean
.
getCompanyName
());
checkProgressDTO
.
setIsVehicleCompany
(
bean
.
getIsVehicleCompany
());
checkProgressDTO
.
setStartCheckBegin
(
bean
.
getStartSendCheck
());
checkProgressDTO
.
setStartCheckEnd
(
bean
.
getEndSendCheck
());
checkProgressDTO
.
setEndCheckBegin
(
bean
.
getStartCheck
());
checkProgressDTO
.
setEndCheckEnd
(
bean
.
getEndCheck
());
checkProgressDTO
.
setOrderType
(
bean
.
getOrderType
());
checkProgressDTO
.
setOrderStatus
(
bean
.
getCheckStatus
());
checkProgressDTO
.
setPageSize
(
bean
.
getPageSize
());
checkProgressDTO
.
setCurrPage
(
bean
.
getCurrPage
());
List
<
String
>
userOrgIdList
=
this
.
getUserOrgIdList
();
checkProgressDTO
.
setOrgIdList
(
userOrgIdList
);
Response
<
PageResult
<
MgCheckProgressDTO
>>
response
=
fpSearchCardAuthClient
.
getCheckProgressList
(
checkProgressDTO
);
//查询脱敏配置 false 脱敏, true 不脱敏
Boolean
hideSensitive
=
getHideSensitiveByUserId
();
List
<
MgCheckProgressDTO
>
list
=
response
.
getData
().
getList
();
if
(!
hideSensitive
){
for
(
MgCheckProgressDTO
mgCheckProgressDTO
:
list
){
mgCheckProgressDTO
.
setIotId
(
DesensitizationUtil
.
desensitizeVin
(
mgCheckProgressDTO
.
getIotId
()));
mgCheckProgressDTO
.
setFullName
(
DesensitizationUtil
.
desensitizeName
(
mgCheckProgressDTO
.
getFullName
()));
mgCheckProgressDTO
.
setPhone
(
DesensitizationUtil
.
desensitizePhone
(
mgCheckProgressDTO
.
getPhone
()));
}
}
return
response
;
}
/**
* 审核看板统计
* @return
* @modify 2022-05-31 根据登录用户的所属车企的所有下属组织做筛选 注意带上租户编号
*/
@Override
public
Response
queryCheckStatistics
()
{
//查询到当前用户的车企组织
UserOrganDTO
param
=
new
UserOrganDTO
();
param
.
setUserId
(
UserSubjectUtil
.
getUserId
());
param
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
<
OrganizationDTO
>
organizationDTOResponse
=
organClient
.
getCarSubOrganByUserId
(
param
);
//再用上面查到的组织查询所有下级 queryByList接口可以查询到所有下级组织,参数传queryCode
OrganizationDTO
organizationDTO
=
new
OrganizationDTO
();
organizationDTO
.
setQueryCode
(
organizationDTOResponse
.
getData
().
getQueryCode
());
Response
<
List
<
OrganizationDTO
>>
listResponse
=
organizationClient
.
queryByList
(
organizationDTO
);
List
<
OrganizationDTO
>
orgList
=
listResponse
.
getData
();
List
<
String
>
orgIdList
=
orgList
.
stream
().
map
(
OrganizationDTO:
:
getUuid
).
collect
(
Collectors
.
toList
());
MgCheckStatisticsQueryDTO
queryDTO
=
new
MgCheckStatisticsQueryDTO
();
queryDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
queryDTO
.
setUserOrgId
(
organizationDTOResponse
.
getData
().
getUuid
());
queryDTO
.
setOrgIdList
(
orgIdList
);
Response
<
MgCheckStatisticsDTO
>
response
=
mgCheckProgressClient
.
queryCheckStatistics
(
queryDTO
);
return
response
;
}
private
List
<
String
>
getUserOrgIdList
(){
//查询到当前用户的车企组织
UserOrganDTO
param
=
new
UserOrganDTO
();
param
.
setUserId
(
UserSubjectUtil
.
getUserId
());
param
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
<
OrganizationDTO
>
organizationDTOResponse
=
organClient
.
getCarSubOrganByUserId
(
param
);
//再用上面查到的组织查询所有下级 queryByList接口可以查询到所有下级组织,参数传queryCode
OrganizationDTO
organizationDTO
=
new
OrganizationDTO
();
organizationDTO
.
setQueryCode
(
organizationDTOResponse
.
getData
().
getQueryCode
());
Response
<
List
<
OrganizationDTO
>>
listResponse
=
organizationClient
.
queryByList
(
organizationDTO
);
List
<
OrganizationDTO
>
orgList
=
listResponse
.
getData
();
List
<
String
>
orgIdList
=
orgList
.
stream
().
map
(
OrganizationDTO:
:
getUuid
).
collect
(
Collectors
.
toList
());
return
orgIdList
;
}
private
Boolean
getHideSensitiveByUserId
(){
UserRoleDTO
userRoleDTO
=
new
UserRoleDTO
();
userRoleDTO
.
setUserId
(
UserSubjectUtil
.
getUserId
());
userRoleDTO
.
setApplicationId
(
UserSubjectUtil
.
getAppId
());
userRoleDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
<
Boolean
>
booleanResponse
=
roleClient
.
queryHideSensitiveByUserId
(
userRoleDTO
);
Boolean
data
=
booleanResponse
.
getData
();
return
data
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/SimVehicleRelImportImportServiceImpl.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.ExcelReader
;
import
com.alibaba.excel.exception.ExcelAnalysisException
;
import
com.alibaba.excel.read.metadata.ReadSheet
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.eiam.dto.OrganizationDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.common.FileTypeEnum
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.FIleSystemType
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.FileDownloadDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.FileUploadDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.ImportSimDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.excel.*
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ISimVehicleRelImportService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ISimVehicleService
;
import
com.cusc.nirvana.user.rnr.fp.client.FileSystemClient
;
import
com.cusc.nirvana.user.rnr.fp.client.SimVehicleRelClient
;
import
com.cusc.nirvana.user.rnr.fp.dto.FileRecordDTO
;
import
com.cusc.nirvana.user.rnr.mg.client.OrgSimRelClient
;
import
com.cusc.nirvana.user.rnr.mg.client.SimFileHistoryClient
;
import
com.cusc.nirvana.user.rnr.mg.dto.SimFileHistoryDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.disk.DiskFileItem
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.commons.CommonsMultipartFile
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.nio.file.Files
;
import
java.util.Base64
;
import
java.util.List
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
/**
* @author stayand
*/
@Service
@Slf4j
public
class
SimVehicleRelImportImportServiceImpl
implements
ISimVehicleRelImportService
{
private
final
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SimVehicleRelImportImportServiceImpl
.
class
);
/**核心线程数*/
private
final
static
int
CORE_POOL_SIZE
=
Runtime
.
getRuntime
().
availableProcessors
()
*
2
;
private
final
static
int
MAX_POOL_SIZE
=
CORE_POOL_SIZE
*
2
;
private
final
static
long
KEEP_ALIVE_TIME
=
60L
;
@Value
(
"${import.simrel.upload.maxFilesInQueue:100}"
)
private
int
maxQueuedImportFiles
;
@Value
(
"${import.simrel.upload.tmp-dir:}"
)
private
String
tmpDir
;
@Value
(
"${import.simrel.upload.error-excel-path:sim-export:}"
)
private
String
errorExcelPath
;
@Value
(
"${import.simrel.upload.max-record-count:5000}"
)
private
Integer
maxRecordCount
;
@Autowired
private
SimFileHistoryClient
simFileHistoryClient
;
@Autowired
private
SimVehicleRelClient
simVehicleClient
;
@Autowired
private
ISimVehicleService
simVehicleService
;
@Autowired
private
OrgSimRelClient
orgSimRelClient
;
/**导入文件线程池*/
private
ThreadPoolExecutor
executor
;
@PostConstruct
public
void
init
()
{
executor
=
new
ThreadPoolExecutor
(
CORE_POOL_SIZE
,
MAX_POOL_SIZE
,
KEEP_ALIVE_TIME
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<>(
maxQueuedImportFiles
));
}
@Resource
private
FileSystemClient
fileSystemClient
;
@Override
public
Response
excelProcess
(
ImportSimDTO
importSimDTO
)
{
if
(
executor
.
getQueue
().
size
()
>=
maxQueuedImportFiles
)
{
return
Response
.
createError
(
"处理文件失败,当前排队上传任务太多,请稍后重试..."
);
}
FileDownloadDTO
fileDownloadDTO
=
new
FileDownloadDTO
();
fileDownloadDTO
.
setUuid
(
importSimDTO
.
getFileUuid
());
fileDownloadDTO
.
setFileName
(
importSimDTO
.
getFileName
());
try
{
String
base64
=
fileSystemClient
.
getBase64
(
fileDownloadDTO
).
getData
().
getBase64
();
byte
[]
result
=
Base64
.
getDecoder
().
decode
(
base64
);
if
(
result
==
null
||
result
.
length
==
0
)
{
return
Response
.
createError
(
"没有找到车卡关系Excel文件"
);
}
SimFileHistoryDTO
tmpHistoryDto
=
new
SimFileHistoryDTO
();
if
(
importSimDTO
.
getFileType
()
==
1
)
{
tmpHistoryDto
.
setTotalCount
(
0
);
//获取总行数
getExcelTotalCount
(
result
,
tmpHistoryDto
);
}
//如果是启用停用
if
(
importSimDTO
.
getFileType
()==
FileTypeEnum
.
CARCLOSE
.
getCode
()||
importSimDTO
.
getFileType
()==
FileTypeEnum
.
CARSTARTUP
.
getCode
()){
tmpHistoryDto
.
setTotalCount
(
0
);
getExcelTotalCountStatus
(
result
,
tmpHistoryDto
);
}
if
(
tmpHistoryDto
.
getTotalCount
()
>
maxRecordCount
)
{
return
Response
.
createError
(
"上传记录数不能大于["
+
maxRecordCount
+
"]"
);
}
SimFileHistoryDTO
simFileHistoryDTO
=
insertImportFile
(
importSimDTO
);
simFileHistoryDTO
.
setTotalCount
(
tmpHistoryDto
.
getTotalCount
());
simFileHistoryDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
executor
.
submit
(
new
Runnable
()
{
@Override
public
void
run
()
{
asyncProcessExcel
(
result
,
simFileHistoryDTO
,
importSimDTO
.
getTagUuid
());
}
});
return
Response
.
createSuccess
(
"文件正在处理中..."
);
}
catch
(
Exception
ex
)
{
log
.
error
(
"导入车卡关系失败,原因:"
+
ex
.
getMessage
());
return
Response
.
createError
(
"导入车卡关系失败,原因:"
+
ex
.
getMessage
());
}
}
/**
* 获取excel的总行数
* @param fileBytes
* @param simFileHistoryDTO
*/
private
void
getExcelTotalCount
(
byte
[]
fileBytes
,
SimFileHistoryDTO
simFileHistoryDTO
)
throws
ExcelAnalysisException
{
try
{
ByteArrayInputStream
is
=
new
ByteArrayInputStream
(
fileBytes
);
ExcelReader
excelReader
=
EasyExcel
.
read
(
is
,
VehicleSimRelRow
.
class
,
new
VehicleSimRowCountListener
(
simFileHistoryDTO
)).
build
();
if
(
excelReader
!=
null
)
{
ReadSheet
readSheet
=
EasyExcel
.
readSheet
(
0
).
build
();
excelReader
.
read
(
readSheet
);
excelReader
.
finish
();
}
}
catch
(
Exception
ex
)
{
throw
new
ExcelAnalysisException
(
"读取车卡关系Excel文件失败"
);
}
}
/**
* 获取excel的总行数
* @param fileBytes
* @param simFileHistoryDTO
*/
private
void
getExcelTotalCountStatus
(
byte
[]
fileBytes
,
SimFileHistoryDTO
simFileHistoryDTO
)
throws
ExcelAnalysisException
{
try
{
ByteArrayInputStream
is
=
new
ByteArrayInputStream
(
fileBytes
);
ExcelReader
excelReader
=
EasyExcel
.
read
(
is
,
VehicleStatusRelRow
.
class
,
new
VehicleStatusRowCountListener
(
simFileHistoryDTO
)).
build
();
if
(
excelReader
!=
null
)
{
ReadSheet
readSheet
=
EasyExcel
.
readSheet
(
0
).
build
();
excelReader
.
read
(
readSheet
);
excelReader
.
finish
();
}
}
catch
(
Exception
ex
)
{
throw
new
ExcelAnalysisException
(
"读取车卡关系Excel文件失败"
);
}
}
/**
* 异步处理导入文件
* @param simFileHistoryDTO
*/
private
boolean
asyncProcessExcel
(
byte
[]
fileBytes
,
SimFileHistoryDTO
simFileHistoryDTO
,
String
tagUuid
)
{
// 从文件服务下载需导入的文件
ByteArrayInputStream
is
=
new
ByteArrayInputStream
(
fileBytes
);
ExcelReader
excelReader
=
null
;
String
errorExcelFile
=
tmpDir
+
"/"
+
CuscStringUtils
.
generateUuid
()
+
".xlsx"
;
// 读取sim卡Excel文件
try
{
if
(
simFileHistoryDTO
.
getFileType
()
==
1
)
{
// 读取车卡关系Excel文件
excelReader
=
EasyExcel
.
read
(
is
,
VehicleSimRelRow
.
class
,
new
VehicleSimListener
(
simVehicleClient
,
simFileHistoryDTO
,
errorExcelFile
,
tagUuid
)).
build
();
}
if
(
simFileHistoryDTO
.
getFileType
()
==
FileTypeEnum
.
CARSTARTUP
.
getCode
()||
simFileHistoryDTO
.
getFileType
()
==
FileTypeEnum
.
CARCLOSE
.
getCode
())
{
// 读取车卡关系Excel文件
excelReader
=
EasyExcel
.
read
(
is
,
VehicleStatusRelRow
.
class
,
new
VehicleStatusListener
(
simVehicleClient
,
simFileHistoryDTO
,
errorExcelFile
,
tagUuid
,
orgSimRelClient
)).
build
();
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"导入组织和SIM卡关系错误,原因:"
,
e
);
return
false
;
}
finally
{
if
(
is
!=
null
){
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
log
.
warn
(
"关闭流失败"
,
e
);
}
}
try
{
if
(
excelReader
!=
null
)
{
ReadSheet
readSheet
=
EasyExcel
.
readSheet
(
0
).
build
();
excelReader
.
read
(
readSheet
);
excelReader
.
finish
();
}
File
excelFile
=
new
File
(
errorExcelFile
);
if
(
excelFile
.
exists
())
{
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
dto
.
FileUploadDTO
fileUploadDTO
=
new
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
dto
.
FileUploadDTO
();
fileUploadDTO
.
setPath
(
errorExcelPath
);
fileUploadDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
MultipartFile
multipartFile
=
getMultipartFile
(
excelFile
,
simFileHistoryDTO
);
if
(
multipartFile
!=
null
)
{
fileUploadDTO
.
setFile
(
multipartFile
);
Response
<
FileRecordDTO
>
response
=
fileSystemClient
.
uploadFile
(
fileUploadDTO
);
if
(
response
.
getSuccess
())
{
simFileHistoryDTO
.
setErrorFileAddr
(
response
.
getData
().
getUuid
());
}
}
}
}
finally
{
simFileHistoryDTO
.
setStatus
(
1
);
simFileHistoryClient
.
update
(
simFileHistoryDTO
);
}
}
return
true
;
}
private
MultipartFile
getMultipartFile
(
File
file
,
SimFileHistoryDTO
simFileHistoryDTO
)
{
try
{
FileItem
fileItem
=
new
DiskFileItem
(
"excelFile"
,
Files
.
probeContentType
(
file
.
toPath
()),
false
,
simFileHistoryDTO
.
getFileName
(),
(
int
)
file
.
length
(),
file
.
getParentFile
());
byte
[]
buffer
=
new
byte
[
4096
];
int
n
;
try
(
InputStream
inputStream
=
new
FileInputStream
(
file
);
OutputStream
os
=
fileItem
.
getOutputStream
();)
{
while
((
n
=
inputStream
.
read
(
buffer
,
0
,
4096
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
n
);
}
MultipartFile
multipartFile
=
new
CommonsMultipartFile
(
fileItem
);
return
multipartFile
;
}
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"上传SIM卡错误文件至文件服务器失败,原因:"
,
e
);
}
return
null
;
}
/**
* 新增导入文件信息
* @param importSimDTO
* @return
*/
private
SimFileHistoryDTO
insertImportFile
(
ImportSimDTO
importSimDTO
)
{
SimFileHistoryDTO
simFileHistoryDTO
=
new
SimFileHistoryDTO
();
simFileHistoryDTO
.
setOrgUuid
(
importSimDTO
.
getOrgUuid
());
simFileHistoryDTO
.
setFileName
(
importSimDTO
.
getFileName
());
simFileHistoryDTO
.
setVerification
(
0
);
simFileHistoryDTO
.
setErrorInfo
(
""
);
simFileHistoryDTO
.
setBatchNo
(
""
);
simFileHistoryDTO
.
setTotalCount
(
0
);
simFileHistoryDTO
.
setErrorCount
(
0
);
simFileHistoryDTO
.
setStatus
(
0
);
simFileHistoryDTO
.
setFileType
(
importSimDTO
.
getFileType
());
simFileHistoryDTO
.
setFileAddr
(
importSimDTO
.
getFileUuid
());
simFileHistoryDTO
.
setImportType
(
0
);
simFileHistoryDTO
.
setIsDelete
(
0
);
simFileHistoryDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
Response
<
SimFileHistoryDTO
>
response
=
simFileHistoryClient
.
add
(
simFileHistoryDTO
);
return
response
.
getData
();
}
}
Prev
1
…
8
9
10
11
12
13
14
Next
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