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/SimVehicleRelServiceImpl.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.eiam.client.OrganizationClient
;
import
com.cusc.nirvana.user.eiam.dto.OrganizationDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.DeleteByUuidDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.ImportSimDTO
;
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.SimVehicleRelClient
;
import
com.cusc.nirvana.user.rnr.fp.dto.*
;
import
com.cusc.nirvana.user.rnr.mg.client.OrgBusinessTagClient
;
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.OrgBusinessTagDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.OrgBusinessTagQueryDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.OrgSimRelDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.OrgSimRelQueryDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.SimFileHistoryDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.SimFileHistoryQueryDTO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
SimVehicleRelServiceImpl
implements
ISimVehicleService
{
@Autowired
private
SimFileHistoryClient
simFileHistoryClient
;
@Autowired
private
ISimVehicleRelImportService
simVehicleRelService
;
@Autowired
private
OrgSimRelClient
simRelClient
;
@Autowired
private
SimVehicleRelClient
simVehicleRelClient
;
@Autowired
private
OrgBusinessTagClient
businessTagClient
;
@Autowired
private
OrganizationClient
organizationClient
;
@Override
public
Response
<
List
<
OrganizationDTO
>>
queryOrgByList
(
OrganizationDTO
organizationDTO
)
{
return
organizationClient
.
queryByList
(
organizationDTO
);
}
@Override
public
Response
<?>
importSim
(
ImportSimDTO
importSimDTO
)
{
return
simVehicleRelService
.
excelProcess
(
importSimDTO
);
}
@Override
public
Response
<
SimVehicleDTO
>
unbind
(
BindRequestDTO
requestDTO
)
{
return
simVehicleRelClient
.
unbind
(
requestDTO
);
}
@Override
public
Response
<
IccidDetailDTO
>
getSimByUuid
(
String
uuid
)
{
Response
<
OrgSimRelDTO
>
orgSimResponse
=
simRelClient
.
getByUuid
(
uuid
);
IccidDetailDTO
iccidDetailDTO
=
null
;
if
(
orgSimResponse
.
isSuccess
()
&&
orgSimResponse
.
getData
()
!=
null
)
{
OrgSimRelDTO
orgSimRelDTO
=
orgSimResponse
.
getData
();
List
<
String
>
iccids
=
new
ArrayList
<>();
iccids
.
add
(
orgSimRelDTO
.
getIccid
());
IccidListDTO
listDTO
=
new
IccidListDTO
();
listDTO
.
setIccidList
(
iccids
);
Response
<
List
<
IccidDetailDTO
>>
simVehicleResponse
=
simVehicleRelClient
.
queryByIccids
(
listDTO
);
if
(
simVehicleResponse
.
isSuccess
()
&&
!
CollectionUtils
.
isEmpty
(
simVehicleResponse
.
getData
()))
{
iccidDetailDTO
=
simVehicleResponse
.
getData
().
get
(
0
);
iccidDetailDTO
.
setCreateTime
(
orgSimRelDTO
.
getCreateTime
());
iccidDetailDTO
.
setCreator
(
orgSimRelDTO
.
getCreator
());
}
}
return
Response
.
createSuccess
(
iccidDetailDTO
);
}
@Override
public
Response
<
PageResult
<
IccidDetailDTO
>>
querySimByPage
(
OrgSimRelQueryDTO
queryDTO
)
{
Response
<
PageResult
<
OrgSimRelDTO
>>
response
=
simRelClient
.
queryByPage
(
queryDTO
);
Map
<
String
,
OrgSimRelDTO
>
map
=
new
LinkedHashMap
<>();
List
<
IccidDetailDTO
>
iccidDetailDTOS
=
new
ArrayList
<>();
List
<
String
>
iccids
=
new
ArrayList
<>();
if
(
response
.
isSuccess
()
&&
response
.
getData
()
!=
null
)
{
response
.
getData
().
getList
().
forEach
(
orgSimRelDTO
->
{
map
.
put
(
orgSimRelDTO
.
getIccid
(),
orgSimRelDTO
);
iccids
.
add
(
orgSimRelDTO
.
getIccid
());
});
}
if
(!
CollectionUtils
.
isEmpty
(
iccids
))
{
IccidListDTO
listDTO
=
new
IccidListDTO
();
listDTO
.
setIccidList
(
iccids
);
Response
<
List
<
IccidDetailDTO
>>
detailResponse
=
simVehicleRelClient
.
queryByIccids
(
listDTO
);
detailResponse
.
getData
().
forEach
(
iccidDetailDTO
->
{
OrgSimRelDTO
orgSimRelDTO
=
map
.
get
(
iccidDetailDTO
.
getIccid
());
iccidDetailDTO
.
setCreateTime
(
orgSimRelDTO
.
getCreateTime
());
iccidDetailDTO
.
setCreator
(
orgSimRelDTO
.
getCreator
());
iccidDetailDTOS
.
add
(
iccidDetailDTO
);
});
}
PageResult
<
VinIccidDTO
>
pageResult
=
new
PageResult
(
iccidDetailDTOS
,
response
.
getData
().
getTotalCount
(),
response
.
getData
().
getPageSize
(),
response
.
getData
().
getCurrPage
());
return
Response
.
createSuccess
(
pageResult
);
}
@Override
public
Response
<
List
<
VinIccidDTO
>>
querySimVehicleByVin
(
String
orgUuid
,
String
vin
)
{
Response
<
List
<
VinIccidDTO
>>
response
=
simVehicleRelClient
.
getIccidByVin
(
vin
);
if
(
response
.
isSuccess
()
&&
!
CollectionUtils
.
isEmpty
(
response
.
getData
()))
{
Iterator
<
VinIccidDTO
>
iter
=
response
.
getData
().
iterator
();
while
(
iter
.
hasNext
())
{
VinIccidDTO
vinIccidDTO
=
iter
.
next
();
Response
<
OrgSimRelDTO
>
simResponse
=
simRelClient
.
getByIccid
(
vinIccidDTO
.
getIccid
());
if
(
simResponse
.
isSuccess
()
&&
simResponse
.
getData
()
!=
null
&&
!
simResponse
.
getData
().
getOrgUuid
().
equals
(
orgUuid
))
{
iter
.
remove
();
}
}
}
return
response
;
}
@Override
public
Response
<
PageResult
<
SimVehicleResultDTO
>>
querySimVehiclePage
(
SimVehicleQueryDTO
queryDTO
)
{
return
simVehicleRelClient
.
querySimVehiclePage
(
queryDTO
);
}
@Override
public
Response
deleteImportHisotry
(
DeleteByUuidDTO
uuidDTO
)
{
SimFileHistoryDTO
simFileHistoryDTO
=
new
SimFileHistoryDTO
();
simFileHistoryDTO
.
setUuid
(
uuidDTO
.
getUuid
());
return
simFileHistoryClient
.
delete
(
simFileHistoryDTO
);
}
@Override
public
Response
<
SimFileHistoryDTO
>
getImportHistory
(
String
uuid
)
{
return
simFileHistoryClient
.
getByUuid
(
uuid
);
}
@Override
public
Response
<
PageResult
<
SimFileHistoryDTO
>>
queryImportHistory
(
SimFileHistoryQueryDTO
queryDTO
)
{
return
simFileHistoryClient
.
queryByPage
(
queryDTO
);
}
@Override
public
Response
<
OrgBusinessTagDTO
>
getTagByUuid
(
String
uuid
)
{
return
businessTagClient
.
getByUuid
(
uuid
);
}
@Override
public
Response
<
List
<
OrgBusinessTagDTO
>>
queryTags
(
OrgBusinessTagQueryDTO
queryDto
)
{
return
businessTagClient
.
query
(
queryDto
);
}
private
Response
<
List
<
IccidDetailDTO
>>
getIccidDetail
(
List
<
String
>
iccids
)
{
IccidListDTO
listDTO
=
new
IccidListDTO
();
listDTO
.
setIccidList
(
iccids
);
Response
<
List
<
IccidDetailDTO
>>
detailResponse
=
simVehicleRelClient
.
queryByIccids
(
listDTO
);
return
detailResponse
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/SmsServiceImpl.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.service.ISmsService
;
import
com.cusc.nirvana.user.rnr.enterprise.util.ValidationUtil
;
import
com.cusc.nirvana.user.rnr.fp.client.SmsClient
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.dto.SmsRequestDTO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
* Description: 短信service
* <br />
* CreateDate 2022-04-16 15:11:41
*
* @author yuyi
**/
@Service
@Slf4j
public
class
SmsServiceImpl
implements
ISmsService
{
@Autowired
SmsClient
smsClient
;
@Override
public
Response
sendSmsRnr
(
SmsRequestDTO
bean
)
{
if
(
StringUtils
.
isBlank
(
bean
.
getBizType
()))
{
return
Response
.
createError
(
"业务类型不能为空"
,
ResponseCode
.
INVALID_DATA
);
}
if
(
StringUtils
.
isBlank
(
bean
.
getPhone
()))
{
return
Response
.
createError
(
"手机号不能为空"
,
ResponseCode
.
INVALID_DATA
);
}
//检查手机
Response
checkPhone
=
ValidationUtil
.
checkPhone
(
bean
.
getPhone
());
if
(!
checkPhone
.
isSuccess
())
{
throw
new
CuscUserException
(
checkPhone
.
getCode
(),
checkPhone
.
getMsg
());
}
bean
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
return
smsClient
.
sendSmsCaptcha
(
bean
);
}
@Override
public
Response
checkSmsCaptcha
(
SmsRequestDTO
bean
)
{
if
(
StringUtils
.
isBlank
(
bean
.
getBizType
()))
{
return
Response
.
createError
(
"业务类型不能为空"
,
ResponseCode
.
INVALID_DATA
);
}
if
(
StringUtils
.
isBlank
(
bean
.
getPhone
()))
{
return
Response
.
createError
(
"手机号不能为空"
,
ResponseCode
.
INVALID_DATA
);
}
if
(
StringUtils
.
isBlank
(
bean
.
getCaptcha
()))
{
return
Response
.
createError
(
"验证码不能为空"
,
ResponseCode
.
INVALID_DATA
);
}
bean
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
return
smsClient
.
checkSmsCaptcha
(
bean
);
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/SurplusCardBindServiceImpl.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.rnr.enterprise.dto.VehicleCardRnrDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ISmsService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.ISurplusCardBindService
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IVehicleCardService
;
import
com.cusc.nirvana.user.rnr.fp.client.CardUnBindClient
;
import
com.cusc.nirvana.user.rnr.fp.client.FpSurplusCardBindClient
;
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.dto.*
;
import
com.cusc.nirvana.user.rnr.mg.constants.*
;
import
com.cusc.nirvana.user.rnr.mg.dto.*
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* @author yubo
* @since 2022-05-03 09:16
*/
@Service
@Slf4j
public
class
SurplusCardBindServiceImpl
implements
ISurplusCardBindService
{
@Autowired
VinCardClient
vinCardClient
;
@Autowired
CardUnBindClient
cardUnBindClient
;
@Autowired
ISmsService
smsService
;
@Autowired
FpSurplusCardBindClient
fpSurplusCardBindClient
;
@Autowired
IVehicleCardService
vehicleCardService
;
/**
* Description: 提交绑定剩余卡
* 1.发送短信
* 2.等待短信回复
* 3.将实名id与iccid绑定
**/
@Override
public
Response
bindSurplusCard
(
VehicleCardRnrDTO
bean
)
{
//校验车卡关系
Response
response
=
validCard
(
bean
);
if
(!
response
.
isSuccess
())
{
return
response
;
}
//获取实名信息
Response
<
MgRnrInfoDTO
>
rnrInfo
=
cardUnBindClient
.
getRnrInfo
(
new
FpVehicleCardRnrDTO
().
setRnrId
(
bean
.
getRnrId
()));
if
(!
rnrInfo
.
isSuccess
())
{
return
Response
.
createError
(
rnrInfo
.
getMsg
(),
rnrInfo
.
getCode
());
}
MgRnrInfoDTO
rnrInfoDTO
=
rnrInfo
.
getData
();
if
(
rnrInfoDTO
==
null
)
{
return
Response
.
createError
(
"未获取到对应的实名信息"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
RnrRelationDTO
rnrRelationDTO
=
toRelationDto
(
bean
,
rnrInfoDTO
);
Response
<
String
>
integerResponse
=
fpSurplusCardBindClient
.
surplusCardBind
(
rnrRelationDTO
);
if
(!
integerResponse
.
isSuccess
())
{
return
Response
.
createError
(
integerResponse
.
getMsg
(),
integerResponse
.
getCode
());
}
return
Response
.
createSuccess
(
new
MgBizNoticeDTO
(
rnrRelationDTO
.
getOrder
().
getUuid
()));
}
/**
* Description: 查询绑定结果
**/
@Override
public
Response
<
SurplusQueryResponseDTO
>
queryResult
(
SurplusQueryRequestDTO
bean
)
{
return
fpSurplusCardBindClient
.
queryResult
(
bean
);
}
//----------------------------私有方法区------------
//校验车卡关系
private
Response
validCard
(
VehicleCardRnrDTO
bean
)
{
//车卡关系校验
List
<
VinCardDTO
>
vinCardDTOS
=
bean
.
getIccidList
().
stream
().
map
(
iccid
->
new
VinCardDTO
(
bean
.
getVin
(),
iccid
)).
collect
(
Collectors
.
toList
());
Response
<
VerifyVinCardResponseDTO
>
response
=
vehicleCardService
.
verifyVinCardBatch
(
vinCardDTOS
);
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
if
(
response
.
getData
()
==
null
||
CollectionUtils
.
isEmpty
(
response
.
getData
().
getIccidVerifyResults
()))
{
return
Response
.
createError
(
"ICCID不能为空"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
//车卡是否已绑定
Optional
<
VinCardVerityResult
>
first
=
response
.
getData
().
getIccidVerifyResults
().
stream
().
filter
(
r
->
!
r
.
isExist
()).
findFirst
();
if
(
first
.
isPresent
())
{
return
Response
.
createError
(
first
.
get
().
getMsg
(),
ResponseCode
.
INVALID_DATA
.
getCode
());
}
//根据vin查询所有已经实名的iccid
Response
<
List
<
MgRnrCardInfoDTO
>>
cardListResponse
=
cardUnBindClient
.
getCardList
(
new
FpVehicleCardRnrDTO
().
setVin
(
bean
.
getVin
()));
if
(!
cardListResponse
.
isSuccess
())
{
return
Response
.
createError
(
cardListResponse
.
getMsg
(),
cardListResponse
.
getCode
());
}
if
(
CollectionUtils
.
isEmpty
(
cardListResponse
.
getData
()))
{
return
Response
.
createError
(
"VIN【"
+
bean
.
getVin
()
+
"】没有已实名的卡"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
Set
<
String
>
rnrCards
=
cardListResponse
.
getData
().
stream
()
.
filter
(
card
->
card
.
getRnrStatus
()
==
RnrStatus
.
RNR
.
getCode
())
.
map
(
c
->
c
.
getIccid
()).
collect
(
Collectors
.
toSet
());
//卡是否已经实名了
Optional
<
String
>
find
=
bean
.
getIccidList
().
stream
().
filter
(
iccid
->
rnrCards
.
contains
(
iccid
)).
findFirst
();
if
(
find
.
isPresent
())
{
return
Response
.
createError
(
"卡【"
+
find
.
get
()
+
"】已实名"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
//实名业务id是否正确
String
rnrId
=
cardListResponse
.
getData
().
get
(
0
).
getRnrId
();
if
(!
StringUtils
.
equals
(
rnrId
,
bean
.
getRnrId
()))
{
return
Response
.
createError
(
"实名业务和VIN不匹配"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
return
Response
.
createSuccess
();
}
/**
* 转成relation dto
*
* @param bean
* @param rnrInfoDTO
* @return
*/
private
RnrRelationDTO
toRelationDto
(
VehicleCardRnrDTO
bean
,
MgRnrInfoDTO
rnrInfoDTO
)
{
RnrRelationDTO
relationDTO
=
new
RnrRelationDTO
();
relationDTO
.
setInfo
(
rnrInfoDTO
);
relationDTO
.
setOrder
(
createOrder
(
rnrInfoDTO
));
relationDTO
.
setIsTrust
(
0
);
relationDTO
.
setIsSecondHandCar
(
0
);
relationDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
relationDTO
.
setCardList
(
createCardList
(
relationDTO
.
getOrder
().
getUuid
(),
bean
,
rnrInfoDTO
));
return
relationDTO
;
}
/**
* 获取卡信息
*
* @param bean
* @param info
* @return
*/
private
List
<
MgRnrCardInfoDTO
>
createCardList
(
String
orderId
,
VehicleCardRnrDTO
bean
,
MgRnrInfoDTO
info
)
{
return
bean
.
getIccidList
().
stream
()
.
map
(
iccid
->
{
MgRnrCardInfoDTO
cardInfoDTO
=
new
MgRnrCardInfoDTO
();
cardInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
cardInfoDTO
.
setIotId
(
bean
.
getVin
());
cardInfoDTO
.
setIccid
(
iccid
);
cardInfoDTO
.
setRnrId
(
info
.
getUuid
());
cardInfoDTO
.
setOrderId
(
orderId
);
cardInfoDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
cardInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
cardInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
cardInfoDTO
.
setSerial_number
(
info
.
getSerial_number
());
cardInfoDTO
.
setNoticeStatus
(
NoticeStatusEnum
.
NONEED
.
getCode
());
cardInfoDTO
.
setRnrStatus
(
RnrStatus
.
INIT
.
getCode
());
cardInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
return
cardInfoDTO
;
}).
collect
(
Collectors
.
toList
());
}
/**
* 插入订单信息
*
* @param rnrInfoDTO
* @return
*/
private
RnrOrderDTO
createOrder
(
MgRnrInfoDTO
rnrInfoDTO
)
{
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setOrderType
(
RnrOrderType
.
ONE_CAR_MORE_CARD_BIND
.
getCode
());
rnrOrderDTO
.
setRnrId
(
rnrInfoDTO
.
getUuid
());
rnrOrderDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
rnrOrderDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
rnrOrderDTO
.
setOrderSource
(
RnrOrderSourceEnum
.
PORTAL
.
getCode
());
rnrOrderDTO
.
setSerialNumber
(
rnrInfoDTO
.
getSerial_number
());
rnrOrderDTO
.
setOrderStatus
(
RnrOrderStatusEnum
.
TO_EXAMINE
.
getCode
());
rnrOrderDTO
.
setAutoRnr
(
true
);
rnrOrderDTO
.
setAuditType
(
RnrOrderAuditTypeEnum
.
AUTO
.
getCode
());
rnrOrderDTO
.
setSendWorkOrder
(
false
);
rnrOrderDTO
.
setIsBatchOrder
(
0
);
rnrOrderDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
rnrOrderDTO
.
setOrgId
(
rnrInfoDTO
.
getOrgId
());
return
rnrOrderDTO
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/T1InstructionServiceImpl.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.dto.T1CommonResponseDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.T1CompletionReqDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.T1InstructionService
;
import
com.cusc.nirvana.user.rnr.fp.client.IFpT1UploadStatusClient
;
import
com.cusc.nirvana.user.rnr.fp.client.T1DataUploadClient
;
import
com.cusc.nirvana.user.rnr.fp.dto.FpT1UploadStatusDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.InstructionDTO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.util.List
;
/**
* @className: T1InstructionServiceImpl
* @description: 指令下发
* @author: jk
* @date: 2022/7/26 16:57
* @version: 1.0
**/
@Slf4j
@Service
public
class
T1InstructionServiceImpl
implements
T1InstructionService
{
@Autowired
private
T1DataUploadClient
t1DataUploadClient
;
@Autowired
private
IFpT1UploadStatusClient
iFpT1UploadStatusClient
;
@Override
public
Response
<
InstructionDTO
>
instructionsIssue
(
InstructionDTO
instructionDTO
)
{
return
t1DataUploadClient
.
instructions
(
instructionDTO
);
}
@Override
public
T1CommonResponseDTO
callbackResult
(
T1CompletionReqDTO
t1CompletionReqDTO
)
{
FpT1UploadStatusDTO
fpT1UploadStatusDTO
=
new
FpT1UploadStatusDTO
();
fpT1UploadStatusDTO
.
setIccid
(
t1CompletionReqDTO
.
getICCID
());
Response
<
List
<
FpT1UploadStatusDTO
>>
response
=
iFpT1UploadStatusClient
.
queryByList
(
fpT1UploadStatusDTO
);
if
(!
response
.
isSuccess
()||
CollectionUtils
.
isEmpty
(
response
.
getData
())){
return
T1CommonResponseDTO
.
createError
(
t1CompletionReqDTO
.
getRequestID
(),
"没有查询到相关卡信息"
);
}
FpT1UploadStatusDTO
fpT1UploadStatus
=
response
.
getData
().
get
(
0
);
fpT1UploadStatus
.
setReportCompletion
(
t1CompletionReqDTO
.
getIsAuth
()?
1
:
2
);
fpT1UploadStatus
.
setReportCompletionResp
(
t1CompletionReqDTO
.
getMessage
());
Response
<
FpT1UploadStatusDTO
>
fpT1UploadStatusDTOResponse
=
iFpT1UploadStatusClient
.
update
(
fpT1UploadStatus
);
if
(!
fpT1UploadStatusDTOResponse
.
isSuccess
()){
return
T1CommonResponseDTO
.
createError
(
t1CompletionReqDTO
.
getRequestID
(),
"更新数据失败"
);
}
return
T1CommonResponseDTO
.
createSuccess
(
t1CompletionReqDTO
.
getRequestID
());
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/UserServiceImpl.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.*
;
import
com.cusc.nirvana.user.eiam.dto.*
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
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.List
;
/**
* @author stayAnd
* @date 2022/4/14
* 用户相关
*/
@Service
@Slf4j
public
class
UserServiceImpl
implements
IUserService
{
@Resource
private
UserOrganClient
userOrganClient
;
@Resource
private
UserClient
userClient
;
@Resource
private
UserRoleClient
userRoleClient
;
@Value
(
"${user.eiam.applicationId:4}"
)
private
String
applicationId
;
@Resource
private
RoleClient
roleClient
;
@Resource
private
OrganizationClient
organizationClient
;
@Override
public
String
getOrganId
(
String
userId
,
String
tenantNo
)
{
UserOrganDTO
dto
=
new
UserOrganDTO
();
dto
.
setUserId
(
userId
);
dto
.
setTenantNo
(
tenantNo
);
log
.
info
(
"getOrganId param = {}"
,
JSONObject
.
toJSONString
(
dto
));
Response
<
List
<
UserOrganDTO
>>
listResponse
=
userOrganClient
.
queryByList
(
dto
);
return
listResponse
.
getData
().
stream
().
filter
(
userOrganDTO
->
userId
.
equals
(
userOrganDTO
.
getUserId
()))
.
findFirst
().
map
(
UserOrganDTO:
:
getOrganId
).
orElse
(
null
);
}
@Override
public
void
addUserRelationRole
(
String
userId
,
String
organId
,
String
roleCode
)
{
//新增经销商和管理员关系
UserOrganDTO
userOrganDto
=
new
UserOrganDTO
();
userOrganDto
.
setUserId
(
userId
);
userOrganDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
userOrganDto
.
setOrganId
(
organId
);
userOrganClient
.
add
(
userOrganDto
);
//新增用户角色关系
UserRoleDTO
userRoleDto
=
new
UserRoleDTO
();
userRoleDto
.
setUserId
(
userId
);
userRoleDto
.
setRoleId
(
getRoleId
(
roleCode
));
userRoleDto
.
setApplicationId
(
applicationId
);
userRoleDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
userRoleClient
.
add
(
userRoleDto
);
}
@Override
public
String
getRoleId
(
String
roleCode
)
{
RoleDTO
dto
=
new
RoleDTO
();
dto
.
setApplicationId
(
applicationId
);
dto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
dto
.
setRoleCode
(
roleCode
);
Response
<
RoleDTO
>
roleDTOResponse
=
roleClient
.
get
(
dto
);
if
(
roleDTOResponse
!=
null
&&
roleDTOResponse
.
isSuccess
()
&&
null
!=
roleDTOResponse
.
getData
())
{
return
roleDTOResponse
.
getData
().
getUuid
();
}
return
""
;
}
@Override
public
String
getOrganName
(
String
organId
,
String
tenantNo
)
{
OrganizationDTO
query
=
new
OrganizationDTO
();
query
.
setTenantNo
(
tenantNo
);
query
.
setUuid
(
organId
);
Response
<
OrganizationDTO
>
response
=
organizationClient
.
getByUuid
(
query
);
if
(
response
!=
null
&&
response
.
isSuccess
()
&&
response
.
getData
()
!=
null
)
{
return
response
.
getData
().
getOrganName
();
}
return
null
;
}
@Override
public
UserDTO
queryUserInInfoByPhone
(
String
phone
)
{
UserDTO
queryDto
=
new
UserDTO
();
queryDto
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
queryDto
.
setApplicationId
(
applicationId
);
queryDto
.
setPhone
(
phone
);
Response
<
UserDTO
>
response
=
userClient
.
getByPhone
(
queryDto
);
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
log
.
info
(
"queryUserInInfoByPhone request = {} | response = {}"
,
JSONObject
.
toJSONString
(
queryDto
),
JSONObject
.
toJSONString
(
response
));
return
response
.
getData
();
}
@Override
public
UserDTO
addUser
(
UserDTO
userDTO
)
{
Response
userResponse
=
userClient
.
add
(
userDTO
);
if
(
null
==
userResponse
)
{
throw
new
CuscUserException
(
""
,
"新增用户失败"
);
}
if
(!
userResponse
.
isSuccess
()
||
userResponse
.
getData
()
==
null
)
{
throw
new
CuscUserException
(
userResponse
.
getCode
(),
userResponse
.
getMsg
());
}
return
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
userResponse
.
getData
()),
UserDTO
.
class
);
}
@Override
public
void
updateUserRole
(
String
roleCode
,
String
userId
)
{
String
roleId
=
this
.
getRoleId
(
roleCode
);
if
(
StringUtils
.
isNotBlank
(
roleId
))
{
UserRoleDTO
updateDto
=
new
UserRoleDTO
();
updateDto
.
setUserId
(
userId
);
updateDto
.
setRoleId
(
roleId
);
userRoleClient
.
updateByUserId
(
updateDto
);
}
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/VehicleCardServiceImpl.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.EMVinCardResponseDTO
;
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.UnBindIccidDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.VehicleCardRnrDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.VinDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IVehicleCardService
;
import
com.cusc.nirvana.user.rnr.enterprise.util.DesensitizationUtil
;
import
com.cusc.nirvana.user.rnr.enterprise.util.FileUtil
;
import
com.cusc.nirvana.user.rnr.fp.client.CardUnBindClient
;
import
com.cusc.nirvana.user.rnr.fp.client.FileSystemClient
;
import
com.cusc.nirvana.user.rnr.fp.client.NewVinCardClient
;
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.dto.*
;
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
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
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.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
javax.validation.Valid
;
import
java.io.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* @author yubo
* @since 2022-04-18 09:26
*/
@Service
@Slf4j
public
class
VehicleCardServiceImpl
implements
IVehicleCardService
{
@Resource
private
FileSystemClient
fileSystemClient
;
@Autowired
VinCardClient
vinCardClient
;
@Autowired
NewVinCardClient
newVinCardClient
;
@Autowired
CardUnBindClient
cardUnBindClient
;
@Value
(
"${fileTemplate.manufacturer.fileSize: 500}"
)
private
String
fileSize
;
/**
* 车卡关系和卡校验
*
* @param vinCardDTO
* @return
*/
@Override
public
Response
<
VerifyVinCardResponseDTO
>
verifyVinCard
(
@Valid
VinCardInfoDTO
vinCardDTO
)
{
//调用批量验证接口
List
<
VinCardDTO
>
vinCardDTOS
=
vinCardDTO
.
getIccidList
().
stream
().
map
(
iccid
->
new
VinCardDTO
(
vinCardDTO
.
getVin
(),
iccid
)).
collect
(
Collectors
.
toList
());
return
verifyVinCardBatch
(
vinCardDTOS
);
}
/**
* 批量车卡关系和卡校验
*
* @param verifyDTOs
* @return
*/
@Override
public
Response
<
VerifyVinCardResponseDTO
>
verifyVinCardBatch
(
List
<
VinCardDTO
>
verifyDTOs
)
{
//进行vin和iccid的验证
Response
<
VerifyVinCardResponseDTO
>
response
=
vinCardClient
.
verifyVinCard
(
verifyDTOs
);
if
(!
response
.
isSuccess
())
{
return
response
;
}
return
Response
.
createSuccess
(
response
.
getData
());
}
@Override
public
Response
<
IccidListDTO
>
getIccidListByVin
(
String
vin
)
{
Response
<
VinCardInfoDTO
>
iccidListByVin
=
vinCardClient
.
queryVinCard
(
vin
);
if
(!
iccidListByVin
.
getSuccess
())
{
return
Response
.
createSuccess
(
false
);
}
return
Response
.
createSuccess
(
iccidListByVin
.
getData
());
}
//解析excel
@Override
public
Response
<
List
<
VinCardDTO
>>
checkIccidList
(
String
fileId
){
//校验文件大小,调文件系统接口 /query/minfo/{uuid} 单位kb
FileRecordDTO
data
=
new
FileRecordDTO
();
data
.
setUuid
(
fileId
);
Response
<
FileRecordDTO
>
fileRecordResponse
=
fileSystemClient
.
getFileSize
(
data
);
log
.
info
(
"获取文件信息"
,
fileRecordResponse
.
getData
());
if
(
fileRecordResponse
.
isSuccess
()){
data
=
fileRecordResponse
.
getData
();
}
// 校验文件大小
if
(
Double
.
parseDouble
(
fileSize
)
<
data
.
getFileSize
()){
return
Response
.
createError
(
"文件大小限制为500k"
);
}
log
.
info
(
"下载文件"
);
Response
<
List
<
VinCardDTO
>>
listResponse
=
parseExcel
(
fileId
);
if
(!
listResponse
.
isSuccess
()
||
listResponse
.
getData
()
==
null
||
listResponse
.
getData
().
size
()<
1
){
return
Response
.
createError
(
"获取校验通过的iccids失败"
);
}
List
<
VinCardDTO
>
cardDTOLists
=
listResponse
.
getData
();
log
.
info
(
"vin和iccid的验证 : "
+
cardDTOLists
.
toString
());
Response
<
VerifyVinCardResponseDTO
>
verifyVinCardResponseDTOResponse
=
verifyVinCardBatch
(
cardDTOLists
);
if
(!
verifyVinCardResponseDTOResponse
.
isSuccess
())
{
return
Response
.
createError
(
verifyVinCardResponseDTOResponse
.
getMsg
(),
verifyVinCardResponseDTOResponse
.
getCode
());
}
int
size
=
verifyVinCardResponseDTOResponse
.
getData
().
getIccidVerifyResults
().
stream
().
filter
(
s
->
s
.
equals
(
false
)).
collect
(
Collectors
.
toList
()).
size
();
if
(
size
>
0
){
return
Response
.
createError
(
"车卡关系校验失败"
,
cardDTOLists
);
}
else
{
return
Response
.
createSuccess
(
"车卡关系校验成功"
,
cardDTOLists
);
}
}
@Override
public
Response
<
UnBindIccidDTO
>
getUnBindIccidList
(
VinDTO
vinDTO
)
{
//根据vin查询所有iccid
Response
<
VinCardInfoDTO
>
response
=
vinCardClient
.
queryVinCard
(
vinDTO
.
getVin
());
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
if
(
response
.
getData
()
==
null
||
CollectionUtils
.
isEmpty
(
response
.
getData
().
getIccidList
()))
{
return
Response
.
createError
(
"VIN【"
+
vinDTO
.
getVin
()
+
"】没有已绑定的卡"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
//根据vin查询所有已经实名的iccid
Response
<
List
<
MgRnrCardInfoDTO
>>
cardListResponse
=
cardUnBindClient
.
getCardList
(
new
FpVehicleCardRnrDTO
().
setVin
(
vinDTO
.
getVin
()));
if
(!
cardListResponse
.
isSuccess
())
{
return
Response
.
createError
(
cardListResponse
.
getMsg
(),
cardListResponse
.
getCode
());
}
UnBindIccidDTO
unBindIccidDTO
=
new
UnBindIccidDTO
();
String
rnrId
;
//过滤掉已经实名的iccid
List
<
String
>
iccidList
=
response
.
getData
().
getIccidList
();
if
(!
CollectionUtils
.
isEmpty
(
cardListResponse
.
getData
()))
{
Set
<
String
>
bindIccids
=
cardListResponse
.
getData
().
stream
()
.
filter
(
card
->
card
.
getRnrStatus
()
==
RnrStatus
.
RNR
.
getCode
())
.
map
(
card
->
card
.
getIccid
()).
collect
(
Collectors
.
toSet
());
iccidList
=
iccidList
.
stream
().
filter
(
id
->
!
bindIccids
.
contains
(
id
)).
distinct
().
collect
(
Collectors
.
toList
());
rnrId
=
cardListResponse
.
getData
().
get
(
0
).
getRnrId
();
}
else
{
return
Response
.
createError
(
"VIN【"
+
vinDTO
.
getVin
()
+
"】没有已实名的卡"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
if
(
CollectionUtils
.
isEmpty
(
iccidList
))
{
return
Response
.
createError
(
"VIN【"
+
vinDTO
.
getVin
()
+
"】没有未实名的卡"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
//获取实名信息
Response
<
MgRnrInfoDTO
>
rnrInfo
=
cardUnBindClient
.
getRnrInfo
(
new
FpVehicleCardRnrDTO
().
setRnrId
(
rnrId
));
if
(!
rnrInfo
.
isSuccess
())
{
return
Response
.
createError
(
rnrInfo
.
getMsg
(),
rnrInfo
.
getCode
());
}
MgRnrInfoDTO
rnrInfoDTO
=
rnrInfo
.
getData
();
if
(
rnrInfoDTO
==
null
)
{
return
Response
.
createError
(
"未获取到对应的实名信息"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
unBindIccidDTO
.
setIccidList
(
iccidList
);
unBindIccidDTO
.
setVin
(
vinDTO
.
getVin
());
unBindIccidDTO
.
setGender
(
rnrInfoDTO
.
getGender
());
unBindIccidDTO
.
setRnrId
(
rnrInfoDTO
.
getUuid
());
unBindIccidDTO
.
setName
(
DesensitizationUtil
.
desensitizeName
(
rnrInfoDTO
.
getFullName
()));
unBindIccidDTO
.
setPhone
(
DesensitizationUtil
.
desensitizePhone
(
rnrInfoDTO
.
getPhone
()));
return
Response
.
createSuccess
(
unBindIccidDTO
);
}
@Override
public
Response
<
VehicleCardRnrDTO
>
getBindIccidList
(
VinDTO
vinDTO
)
{
//根据vin查询所有已经实名的iccid
Response
<
List
<
MgRnrCardInfoDTO
>>
cardListResponse
=
cardUnBindClient
.
getCardList
(
new
FpVehicleCardRnrDTO
().
setVin
(
vinDTO
.
getVin
()));
if
(!
cardListResponse
.
isSuccess
())
{
return
Response
.
createError
(
cardListResponse
.
getMsg
(),
cardListResponse
.
getCode
());
}
VehicleCardRnrDTO
vehicleCardRnrDTO
=
new
VehicleCardRnrDTO
();
if
(!
CollectionUtils
.
isEmpty
(
cardListResponse
.
getData
())){
List
<
String
>
iccids
=
cardListResponse
.
getData
().
stream
()
.
filter
(
card
->
card
.
getRnrStatus
()
==
RnrStatus
.
RNR
.
getCode
())
.
map
(
c
->
c
.
getIccid
()).
collect
(
Collectors
.
toList
());
vehicleCardRnrDTO
.
setVin
(
vinDTO
.
getVin
());
vehicleCardRnrDTO
.
setIccidList
(
iccids
);
vehicleCardRnrDTO
.
setRnrId
(
cardListResponse
.
getData
().
get
(
0
).
getRnrId
());
}
return
Response
.
createSuccess
(
vehicleCardRnrDTO
);
}
/**
* 新车实名查询iccid,如果已经有实名信息,提醒走一车多卡
* @param vin
* @return
*/
@Override
public
Response
<
IccidListDTO
>
getNewCarUnBindIccidList
(
String
vin
)
{
//根据vin查询所有iccid
VinCardQueryDTO
queryDTO
=
new
VinCardQueryDTO
();
queryDTO
.
setVin
(
vin
);
Response
<
VinCardResultDTO
>
response
=
newVinCardClient
.
queryUnBindCardByVin
(
queryDTO
);
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
if
(
response
.
getData
()
==
null
||
CollectionUtils
.
isEmpty
(
response
.
getData
().
getIccidList
()))
{
return
Response
.
createError
(
"VIN【"
+
vin
+
"】没有已绑定的卡"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
//根据vin查询所有已经实名的iccid
Response
<
List
<
MgRnrCardInfoDTO
>>
cardListResponse
=
cardUnBindClient
.
getCardList
(
new
FpVehicleCardRnrDTO
().
setVin
(
vin
));
if
(!
cardListResponse
.
isSuccess
())
{
return
Response
.
createError
(
cardListResponse
.
getMsg
(),
cardListResponse
.
getCode
());
}
if
(!
CollectionUtils
.
isEmpty
(
cardListResponse
.
getData
())){
return
Response
.
createError
(
"VIN【"
+
vin
+
"】存在已实名的卡,请通过一车多卡进行绑定"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
return
Response
.
createSuccess
(
response
.
getData
());
}
/**
* 解析excel 获取校验成功的列表
* @param fileId
* @return
*/
@Override
public
Response
<
List
<
VinCardDTO
>>
parseExcel
(
String
fileId
){
List
<
VinCardDTO
>
cardDTOLists
=
new
ArrayList
<>();
List
<
VinCardVerityResult
>
cardDTOList
=
new
ArrayList
<>();
FileDownloadDTO
fileDownloadDTO
=
new
FileDownloadDTO
(
fileId
,
""
);
//InputStream download = fileService.download(fileDownloadDTO);
try
{
String
base64
=
fileSystemClient
.
getBase64
(
fileDownloadDTO
).
getData
().
getBase64
();
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
Base64
.
getDecoder
().
decode
(
base64
));
cardDTOList
=
FileUtil
.
convertExcelToVinCardLists
(
inputStream
,
fileId
);
}
catch
(
Exception
e
)
{
log
.
error
(
"读取车卡列表失败"
,
e
);
//return Response.createError("读取车卡列表失败", ResponseCode.INVALID_DATA.getCode());
}
if
(
cardDTOList
.
size
()>
5000
){
Response
.
createError
(
"文件条数应小于5000"
);
}
List
<
VinCardVerityResult
>
vinCardVerityResultList
=
cardDTOList
.
stream
().
filter
(
s
->
s
.
isExist
()).
collect
(
Collectors
.
toList
());
for
(
VinCardVerityResult
result:
vinCardVerityResultList
){
cardDTOLists
.
add
(
new
VinCardDTO
(
result
.
getVin
(),
result
.
getIccid
()));
}
return
Response
.
createSuccess
(
"获取校验正确iccid列表"
,
cardDTOLists
);
}
/**
* 根据文件id下载并读取excel,进行vin和iccid校验,并上传处理失败的记录到文件系统
*
* @param fileId
* @return
*/
@Override
public
Response
<
EMVinCardResponseDTO
>
verifyAndUploadVinCard
(
String
fileId
)
{
//校验文件大小,调文件系统接口
FileRecordDTO
data
=
new
FileRecordDTO
();
data
.
setUuid
(
fileId
);
Response
<
FileRecordDTO
>
fileRecordResponse
=
fileSystemClient
.
getFileSize
(
data
);
log
.
info
(
"获取文件信息{}"
,
fileRecordResponse
.
getData
());
if
(
fileRecordResponse
.
isSuccess
())
{
data
=
fileRecordResponse
.
getData
();
}
// 校验文件大小
if
(
Double
.
parseDouble
(
fileSize
)
<
data
.
getFileSize
())
{
return
Response
.
createError
(
"文件大小限制为500k"
);
}
List
<
VinCardDTO
>
cardDTOList
=
null
;
try
{
//cardDTOList = fileService.downloadAndToVinCardList(fileId);
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
dto
.
FileDownloadDTO
fileDownloadDTO
=
new
FileDownloadDTO
();
fileDownloadDTO
.
setUuid
(
fileId
);
String
base64
=
fileSystemClient
.
getBase64
(
fileDownloadDTO
).
getData
().
getBase64
();
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
Base64
.
getDecoder
().
decode
(
base64
));
cardDTOList
=
FileUtil
.
convertExcelToVinCardList
(
inputStream
,
fileId
);
}
catch
(
Exception
e
)
{
log
.
error
(
"读取车卡列表失败"
,
e
);
return
Response
.
createError
(
"读取车卡列表失败"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
Response
<
VerifyVinCardResponseDTO
>
response
=
verifyVinCardBatch
(
cardDTOList
);
log
.
info
(
"verifyAndUploadVinCard response"
,
response
.
toString
());
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
//校验结果处理,计算失败次数
List
<
VinCardVerityResult
>
iccidVerifyResults
=
response
.
getData
().
getIccidVerifyResults
();
//判断是否又重复的iccid
List
<
String
>
repeatIccIdList
=
iccidVerifyResults
.
stream
().
filter
(
VinCardVerityResult:
:
isExist
)
.
collect
(
Collectors
.
groupingBy
(
VinCardVerityResult:
:
getIccid
))
.
entrySet
().
stream
().
filter
(
entry
->
entry
.
getValue
().
size
()
>
1
).
map
(
Map
.
Entry
::
getKey
).
collect
(
Collectors
.
toList
());
//设置iccid重复提示
iccidVerifyResults
.
stream
().
filter
(
v
->
repeatIccIdList
.
contains
(
v
.
getIccid
())).
forEach
(
v
->
{
v
.
setExist
(
false
);
v
.
setMsg
(
"iccid重复"
);
});
int
failCount
=
(
int
)
iccidVerifyResults
.
stream
().
filter
(
re
->
!
re
.
isExist
()).
count
();
log
.
info
(
"failCount{}"
,
failCount
);
String
fileName
=
""
;
//如果失败记录,生成excel并上传
ExcelSheetDTO
excelSheetDTO
=
FileUtil
.
convertVerityResultToExcelDTO
(
iccidVerifyResults
);
//Response<FileRecordDTO> recordDTOResponse = fileService.createAndUploadExcel(fileId, "车卡信息校验结果.xlsx", excelSheetDTO);
MultipartFile
multipartFile
;
try
{
multipartFile
=
FileUtil
.
bytesToMultipartFile
(
FileUtil
.
createExcelBytes
(
excelSheetDTO
,
"车卡解绑信息校验结果.xlsx"
),
"车卡解绑信息校验结果.xlsx"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"生成校验文件失败"
,
e
);
return
Response
.
createError
(
"生成校验文件失败"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
FileUploadDTO
dto
=
new
FileUploadDTO
();
dto
.
setFile
(
multipartFile
);
Response
<
FileRecordDTO
>
recordResponse
=
fileSystemClient
.
uploadFile
(
dto
);
if
(!
recordResponse
.
isSuccess
())
{
return
Response
.
createError
(
recordResponse
.
getMsg
(),
recordResponse
.
getCode
());
}
String
fileleKey
=
recordResponse
.
getData
().
getUuid
();
return
Response
.
createSuccess
(
new
EMVinCardResponseDTO
(
iccidVerifyResults
.
size
(),
failCount
,
fileleKey
,
fileName
));
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/VehicleRnrUnboundServiceImpl.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.rnr.enterprise.dto.EMVinCardResponseDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.ExcelSheetDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.VehicleRnrVinCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.enterprise.service.IVehicleRnrUnboundService
;
import
com.cusc.nirvana.user.rnr.enterprise.util.FileUtil
;
import
com.cusc.nirvana.user.rnr.fp.client.FileSystemClient
;
import
com.cusc.nirvana.user.rnr.fp.client.VehicleUnboundClient
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.dto.*
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCompanyInfoClient
;
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.*
;
import
com.cusc.nirvana.user.rnr.mg.dto.*
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.io.ByteArrayInputStream
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 车企实名解绑实现类
*
* @author yubo
* @since 2022-04-24 09:41
*/
@Service
@Slf4j
public
class
VehicleRnrUnboundServiceImpl
implements
IVehicleRnrUnboundService
{
@Resource
private
FileSystemClient
fileSystemClient
;
@Autowired
VehicleUnboundClient
vehicleUnboundClient
;
@Autowired
MgVehicleCompanyClient
vehicleCompanyClient
;
@Autowired
private
MgRnrCompanyInfoClient
companyInfoClient
;
@Autowired
private
MgRnrInfoClient
rnrInfoClient
;
/**
* 车企实名解绑校验车卡信息
*
* @param vehicleRnrVinCardInfoDTO
*/
@Override
public
Response
<
EMVinCardResponseDTO
>
verifyUnboundVinCards
(
VehicleRnrVinCardInfoDTO
vehicleRnrVinCardInfoDTO
)
{
//获取校验结果
Response
<
VerifyVinCardResponseDTO
>
response
=
getVerifyResults
(
vehicleRnrVinCardInfoDTO
);
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
//校验结果处理,计算失败次数
List
<
VinCardVerityResult
>
iccidVerifyResults
=
response
.
getData
().
getIccidVerifyResults
();
int
failCount
=
getFailedCount
(
iccidVerifyResults
);
//如果失败记录,生成excel并上传
ExcelSheetDTO
excelSheetDTO
=
FileUtil
.
convertVerityResultToExcelDTO
(
iccidVerifyResults
);
MultipartFile
multipartFile
;
try
{
multipartFile
=
FileUtil
.
bytesToMultipartFile
(
FileUtil
.
createExcelBytes
(
excelSheetDTO
,
"车卡解绑信息校验结果.xlsx"
),
"车卡解绑信息校验结果.xlsx"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"生成校验文件失败"
,
e
);
return
Response
.
createError
(
"生成校验文件失败"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
FileUploadDTO
dto
=
new
FileUploadDTO
();
dto
.
setFile
(
multipartFile
);
Response
<
FileRecordDTO
>
recordResponse
=
fileSystemClient
.
uploadFile
(
dto
);
if
(!
recordResponse
.
isSuccess
())
{
return
Response
.
createError
(
recordResponse
.
getMsg
(),
recordResponse
.
getCode
());
}
String
fileId
=
recordResponse
.
getData
().
getUuid
();
return
Response
.
createSuccess
(
new
EMVinCardResponseDTO
(
iccidVerifyResults
.
size
(),
failCount
,
fileId
));
}
/**
* 车企解绑
*
* @param vehicleRnrVinCardInfoDTO
* @return
*/
@Override
public
Response
unboundSubmit
(
VehicleRnrVinCardInfoDTO
vehicleRnrVinCardInfoDTO
)
{
//获取校验结果
Response
<
VehicleUnboundVerifyRequestDTO
>
verifyCard
=
getVerifyCard
(
vehicleRnrVinCardInfoDTO
);
if
(!
verifyCard
.
isSuccess
())
{
return
Response
.
createSuccess
(
verifyCard
.
getMsg
(),
verifyCard
.
getCode
());
}
//获取车企实名业务ID
MgVehicleCompanyDTO
fpVehicleCompanyDTO
=
new
MgVehicleCompanyDTO
();
fpVehicleCompanyDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
Response
<
MgVehicleCompanyDTO
>
byTenantNo
=
vehicleCompanyClient
.
getVehicleCompany
(
fpVehicleCompanyDTO
);
if
(!
byTenantNo
.
isSuccess
()
||
byTenantNo
.
getData
()
==
null
)
{
return
Response
.
createError
(
"没有对应的车企信息"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
fpVehicleCompanyDTO
=
byTenantNo
.
getData
();
//获取车企信息
MgRnrCompanyInfoDTO
companyInfoDTO
=
new
MgRnrCompanyInfoDTO
();
companyInfoDTO
.
setRnrId
(
fpVehicleCompanyDTO
.
getFirstRnrId
());
Response
<
MgRnrCompanyInfoDTO
>
byRnrid
=
companyInfoClient
.
getByRnrid
(
companyInfoDTO
);
if
(!
byRnrid
.
isSuccess
())
{
return
Response
.
createError
(
byRnrid
.
getMsg
(),
ResponseCode
.
INVALID_DATA
.
getCode
());
}
if
(
byRnrid
.
getData
()
==
null
)
{
return
Response
.
createError
(
"没有对应的车企实名信息"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
companyInfoDTO
=
byRnrid
.
getData
();
//获取实名信息
MgRnrInfoDTO
mgRnrInfoDTO
=
new
MgRnrInfoDTO
();
mgRnrInfoDTO
.
setUuid
(
fpVehicleCompanyDTO
.
getFirstRnrId
());
Response
<
MgRnrInfoDTO
>
byUuid
=
rnrInfoClient
.
getByUuid
(
mgRnrInfoDTO
);
if
(!
byUuid
.
isSuccess
()
||
byUuid
.
getData
()
==
null
)
{
return
Response
.
createError
(
"企业实名信息获取失败"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
mgRnrInfoDTO
=
byUuid
.
getData
();
//数据转换
VehicleUnbindDTO
vehicleUnbindDTO
=
new
VehicleUnbindDTO
();
vehicleUnbindDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
vehicleUnbindDTO
.
setIsTrust
(
0
);
vehicleUnbindDTO
.
setIsSecondHandCar
(
0
);
vehicleUnbindDTO
.
setInfo
(
getVehicleRnrInfo
(
mgRnrInfoDTO
));
vehicleUnbindDTO
.
setCompanyInfo
(
createCompanyInfoDTO
(
companyInfoDTO
,
vehicleUnbindDTO
.
getInfo
().
getUuid
()));
mgRnrInfoDTO
.
setRnrCompanyId
(
companyInfoDTO
.
getUuid
());
vehicleUnbindDTO
.
setOrder
(
getVehicleOrderInfo
(
vehicleUnbindDTO
.
getInfo
(),
companyInfoDTO
));
vehicleUnbindDTO
.
setCardList
(
getVehicleCardInfo
(
vehicleUnbindDTO
.
getInfo
()
,
vehicleUnbindDTO
.
getOrder
().
getUuid
(),
verifyCard
.
getData
().
getCardDTOS
()));
// vehicleUnbindDTO.setRnrFileList(getVehicleFiles(vehicleUnbindDTO.getInfo(), byTenantNo.getData()));
return
vehicleUnboundClient
.
batchUnbound
(
vehicleUnbindDTO
);
}
//------------- 私有方法区 -------------
/**
* 公司信息
* @param mgRnrCompanyInfoDTO
* @param rnrId
* @return
*/
private
MgRnrCompanyInfoDTO
createCompanyInfoDTO
(
MgRnrCompanyInfoDTO
mgRnrCompanyInfoDTO
,
String
rnrId
)
{
mgRnrCompanyInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrCompanyInfoDTO
.
setRnrId
(
rnrId
);
mgRnrCompanyInfoDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
mgRnrCompanyInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrCompanyInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrCompanyInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
//是否是车企
mgRnrCompanyInfoDTO
.
setIndustryType
(
"1"
);
return
mgRnrCompanyInfoDTO
;
}
//获取文件信息
// private List<MgRnrFileDTO> getVehicleFiles(MgRnrInfoDTO info, MgVehicleCompanyDTO data) {
// List<MgRnrFileDTO> mgRnrFileDTOS = new ArrayList<>();
//
// String rnrId = info.getUuid();
// //mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, data.getCorporationCertFront(), RnrFileType.IDENTITY_CARD_BACK.getCode()));
// //mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, data.getCorporationCertBack(), RnrFileType.IDENTITY_CARD_FRONT.getCode()));
// //mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, data.getCompanyCertAuth(), RnrFileType.ENTERPRISE_AUTH_FILE.getCode()));
// //mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, data.getLivenessVideoId(), RnrFileType.LIVENESS_VIDEO.getCode()));
//
// return mgRnrFileDTOS;
// }
/**
* 获取车卡信息
* @param info
* @param orderId
* @param vinCardList
* @return
*/
private
List
<
MgRnrCardInfoDTO
>
getVehicleCardInfo
(
MgRnrInfoDTO
info
,
String
orderId
,
List
<
VinCardDTO
>
vinCardList
)
{
return
vinCardList
.
stream
().
map
(
vc
->
{
MgRnrCardInfoDTO
cardInfoDTO
=
new
MgRnrCardInfoDTO
();
cardInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
cardInfoDTO
.
setIotId
(
vc
.
getVin
());
cardInfoDTO
.
setIccid
(
vc
.
getIccid
());
cardInfoDTO
.
setRnrId
(
info
.
getUuid
());
cardInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
cardInfoDTO
.
setSerial_number
(
info
.
getSerial_number
());
cardInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
cardInfoDTO
.
setOrderId
(
orderId
);
cardInfoDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
cardInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
return
cardInfoDTO
;
}).
collect
(
Collectors
.
toList
());
}
/**
* 获取车企责订单信息
* @param mgRnrInfoDTO
* @param companyDTO
* @return
*/
private
RnrOrderDTO
getVehicleOrderInfo
(
MgRnrInfoDTO
mgRnrInfoDTO
,
MgRnrCompanyInfoDTO
companyDTO
)
{
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setOrderType
(
RnrOrderType
.
COMPANY_CORPORATION_UNBIND
.
getCode
());
rnrOrderDTO
.
setRnrId
(
mgRnrInfoDTO
.
getUuid
());
rnrOrderDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
rnrOrderDTO
.
setTenantNo
(
mgRnrInfoDTO
.
getTenantNo
());
rnrOrderDTO
.
setOperator
(
mgRnrInfoDTO
.
getUserId
());
rnrOrderDTO
.
setCreator
(
mgRnrInfoDTO
.
getUserId
());
rnrOrderDTO
.
setOrderSource
(
RnrOrderSourceEnum
.
PORTAL
.
getCode
());
rnrOrderDTO
.
setSerialNumber
(
mgRnrInfoDTO
.
getSerial_number
());
rnrOrderDTO
.
setIsBatchOrder
(
0
);
rnrOrderDTO
.
setOrderStatus
(
RnrOrderStatusEnum
.
TO_EXAMINE
.
getCode
());
rnrOrderDTO
.
setAutoRnr
(
true
);
rnrOrderDTO
.
setAuditType
(
RnrOrderAuditTypeEnum
.
AUTO
.
getCode
());
rnrOrderDTO
.
setSendWorkOrder
(
false
);
rnrOrderDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
rnrOrderDTO
.
setOrgId
(
mgRnrInfoDTO
.
getOrgId
());
return
rnrOrderDTO
;
}
/**
* 获取车企责任人信息
* @param mgRnrInfoDTO
* @return
*/
private
MgRnrInfoDTO
getVehicleRnrInfo
(
MgRnrInfoDTO
mgRnrInfoDTO
)
{
mgRnrInfoDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
mgRnrInfoDTO
.
setSerial_number
(
CuscStringUtils
.
generateUuid
());
mgRnrInfoDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrInfoDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrInfoDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrInfoDTO
.
setUserId
(
UserSubjectUtil
.
getUserId
());
mgRnrInfoDTO
.
setIsCompany
(
1
);
mgRnrInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Unbound
.
getCode
());
return
mgRnrInfoDTO
;
}
/**
* 获取错误数量
*
* @param iccidVerifyResults
* @return
*/
private
int
getFailedCount
(
List
<
VinCardVerityResult
>
iccidVerifyResults
)
{
return
(
int
)
iccidVerifyResults
.
stream
().
filter
(
re
->
!
re
.
isExist
()).
count
();
}
/**
* 获取解绑结果
*
* @param vehicleRnrVinCardInfoDTO
* @return
*/
private
Response
<
VerifyVinCardResponseDTO
>
getVerifyResults
(
VehicleRnrVinCardInfoDTO
vehicleRnrVinCardInfoDTO
)
{
Response
<
VehicleUnboundVerifyRequestDTO
>
verifyCard
=
getVerifyCard
(
vehicleRnrVinCardInfoDTO
);
if
(!
verifyCard
.
isSuccess
())
{
return
Response
.
createSuccess
(
verifyCard
.
getMsg
(),
verifyCard
.
getCode
());
}
// return mockResut(verifyCard.getData());
return
vehicleUnboundClient
.
verifyUnboundVinCardBatch
(
verifyCard
.
getData
());
}
// private Response<VerifyVinCardResponseDTO> mockResut(VehicleUnboundVerifyRequestDTO data) {
// List<VinCardVerityResult> collect = data.getCardDTOS().stream().map(card -> {
// VinCardVerityResult result = new VinCardVerityResult();
// result.setVin(card.getVin());
// result.setIccid(card.getIccid());
// boolean b = new Random().nextBoolean();
// result.setExist(b);
// result.setMsg(b ? "" : "Error....");
// return result;
// }).collect(Collectors.toList());
// VerifyVinCardResponseDTO verifyVinCardResponseDTO = new VerifyVinCardResponseDTO();
// verifyVinCardResponseDTO.setIccidVerifyResults(collect);
// return Response.createSuccess(verifyVinCardResponseDTO);
// }
/**
* 获取检验结果
*
* @return
*/
private
Response
<
VehicleUnboundVerifyRequestDTO
>
getVerifyCard
(
VehicleRnrVinCardInfoDTO
vehicleRnrVinCardInfoDTO
)
{
if
(
StringUtils
.
isBlank
(
vehicleRnrVinCardInfoDTO
.
getFileId
()))
{
return
Response
.
createError
(
"文件ID不能为空"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
List
<
VinCardDTO
>
cardList
=
null
;
try
{
//cardDTOList = fileService.downloadAndToVinCardList(vehicleRnrVinCardInfoDTO.getFileId());
FileDownloadDTO
dto
=
new
com
.
cusc
.
nirvana
.
user
.
rnr
.
enterprise
.
dto
.
FileDownloadDTO
();
dto
.
setUuid
(
vehicleRnrVinCardInfoDTO
.
getFileId
());
String
base64
=
fileSystemClient
.
getBase64
(
dto
).
getData
().
getBase64
();
byte
[]
decode
=
Base64
.
getDecoder
().
decode
(
base64
);
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
decode
);
cardList
=
FileUtil
.
convertExcelToVinCardList
(
inputStream
,
vehicleRnrVinCardInfoDTO
.
getFileId
());
}
catch
(
Exception
e
)
{
log
.
error
(
"读取车卡列表失败"
,
e
);
return
Response
.
createError
(
"读取车卡列表失败"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
if
(
CollectionUtils
.
isEmpty
(
cardList
))
{
return
Response
.
createError
(
"未读取到车卡信息"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
VehicleUnboundVerifyRequestDTO
verifyRequestDTO
=
new
VehicleUnboundVerifyRequestDTO
();
verifyRequestDTO
.
setCardDTOS
(
cardList
);
verifyRequestDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
verifyRequestDTO
.
setUserId
(
UserSubjectUtil
.
getUserId
());
return
Response
.
createSuccess
(
verifyRequestDTO
);
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/service/impl/Watermark.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.service.impl
;
public
class
Watermark
{
}
\ No newline at end of file
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/DateExtentUtils.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.util
;
import
java.time.*
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Date
;
/**
* @program: workspace-rnr-new
* @description:
* @author: lig131
* @create: 2022-04-27 09:44
**/
public
class
DateExtentUtils
{
/**
* 日期转为LocalDateTime
*
* @param date 日期
* @return LocalDateTime
*/
public
static
LocalDateTime
dateToLocalDateTime
(
final
Date
date
)
{
if
(
null
==
date
)
{
return
null
;
}
final
Instant
instant
=
date
.
toInstant
();
final
ZoneId
zoneId
=
ZoneId
.
systemDefault
();
final
LocalDateTime
localDateTime
=
instant
.
atZone
(
zoneId
).
toLocalDateTime
();
return
localDateTime
;
}
/**
* 日期转为LocalDate
*
* @param date 日期
* @return LocalDateTime
*/
public
static
LocalDate
dateToLocalDate
(
final
Date
date
)
{
if
(
null
==
date
)
{
return
null
;
}
final
Instant
instant
=
date
.
toInstant
();
final
ZoneId
zoneId
=
ZoneId
.
systemDefault
();
final
LocalDate
localDate
=
instant
.
atZone
(
zoneId
).
toLocalDate
();
return
localDate
;
}
/**
* LocalDateTime转为日期
*
* @param localDateTime LocalDateTime
* @return 日期
*/
public
static
Date
localDateTimeToDate
(
final
LocalDateTime
localDateTime
)
{
if
(
null
==
localDateTime
)
{
return
null
;
}
final
ZoneId
zoneId
=
ZoneId
.
systemDefault
();
final
ZonedDateTime
zdt
=
localDateTime
.
atZone
(
zoneId
);
final
Date
date
=
Date
.
from
(
zdt
.
toInstant
());
return
date
;
}
/**
* LocalDate转为日期
*
* @param localDate
* @return
*/
public
static
Date
localDateToDate
(
final
LocalDate
localDate
)
{
if
(
null
==
localDate
)
{
return
null
;
}
final
ZoneId
zoneId
=
ZoneId
.
systemDefault
();
final
ZonedDateTime
zdt
=
localDate
.
atStartOfDay
().
atZone
(
zoneId
);
final
Date
date
=
Date
.
from
(
zdt
.
toInstant
());
return
date
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/DesensitizationUtil.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.util
;
import
org.apache.commons.lang3.StringUtils
;
/**
* 脱敏工具类
*
* @author yubo
* @since 2022-05-03 10:26
*/
public
class
DesensitizationUtil
{
/**
* 不脱敏
*/
public
static
final
int
DESENSITIZATION_NONE
=
0
;
/**
* 对手机号脱敏
*/
public
static
final
int
DESENSITIZATION_PHONE
=
1
;
/**
* 对姓名脱敏
*/
public
static
final
int
DESENSITIZATION_NAME
=
2
;
/**
* 对姓名脱敏
*/
public
static
final
int
DESENSITIZATION_VIN
=
3
;
/**
* 手机号脱敏
*
* @param phone
* @return
*/
public
static
String
desensitizePhone
(
String
phone
)
{
if
(
StringUtils
.
isNotBlank
(
phone
))
{
return
phone
.
replaceAll
(
"(\\w{3})\\w{4}(\\w{4})"
,
"$1****$2"
);
}
return
phone
;
}
/**
* 姓名脱敏
*
* @param name
* @return
*/
public
static
String
desensitizeName
(
String
name
)
{
if
(
StringUtils
.
isNotBlank
(
name
))
{
String
left
=
StringUtils
.
left
(
name
,
1
);
return
StringUtils
.
rightPad
(
left
,
name
.
length
(),
"*"
);
}
return
name
;
}
public
static
String
desensitizeByRule
(
int
rule
,
String
content
){
if
(
rule
==
DESENSITIZATION_PHONE
){
return
desensitizePhone
(
content
);
}
if
(
rule
==
DESENSITIZATION_NAME
)
{
return
desensitizeName
(
content
);
}
if
(
rule
==
DESENSITIZATION_VIN
)
{
return
desensitizeVin
(
content
);
}
return
content
;
}
public
static
String
desensitizeVin
(
String
vin
){
//vin 17 位
if
(
StringUtils
.
isNotBlank
(
vin
))
{
//vin.replace(3,13)
String
substring
=
vin
.
substring
(
4
,
13
);
return
vin
.
replace
(
substring
,
"**********"
);
}
return
vin
;
}
public
static
String
desensitizeIccid
(
String
iccid
){
//iccid 20 位
if
(
StringUtils
.
isNotBlank
(
iccid
))
{
String
substring
=
iccid
.
substring
(
5
,
15
);
return
iccid
.
replace
(
substring
,
"**********"
);
}
return
iccid
;
}
public
static
String
desensitizeCertNumber
(
String
certNumber
)
{
if
(
StringUtils
.
isNotBlank
(
certNumber
))
{
if
(
certNumber
.
length
()
>=
10
)
{
//展示前4后4
String
substring
=
certNumber
.
substring
(
4
,
certNumber
.
length
()-
4
);
return
certNumber
.
replace
(
substring
,
"**********"
);
}
else
if
(
certNumber
.
length
()
>=
3
){
//展示前1后1
String
substring
=
certNumber
.
substring
(
1
,
certNumber
.
length
()-
1
);
return
certNumber
.
replace
(
substring
,
"**********"
);
}
else
{
return
certNumber
;
}
}
return
certNumber
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/FileUtil.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.util
;
import
com.alibaba.fastjson.JSON
;
import
com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.enterprise.dto.ExcelSheetDTO
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.dto.VerifyExcelStatusEnum
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardVerityResult
;
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.dto.MgRnrFileDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.disk.DiskFileItemFactory
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.commons.CommonsMultipartFile
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
/**
* 文件处理类
*
* @author yubo
* @since 2022-04-19 10:12
*/
public
class
FileUtil
{
/**
* 车企和企业的excel转成车卡list
*
* @param inputStream
* @return
*/
public
static
List
<
VinCardDTO
>
convertExcelToVinCardList
(
InputStream
inputStream
,
String
fileName
)
throws
IOException
{
return
convertExcelToVinCardList
(
inputStream
,
isExcelXSSFFormat
(
fileName
),
1
);
}
public
static
List
<
VinCardVerityResult
>
convertExcelToVinCardLists
(
InputStream
inputStream
,
String
fileName
)
throws
IOException
{
return
convertExcelToVinCardLists
(
inputStream
,
isExcelXSSFFormat
(
fileName
),
1
);
}
//创建文件信息
public
static
MgRnrFileDTO
newFileDTO
(
String
rnrId
,
String
pic
,
Integer
fileType
,
int
rnrBizzType
)
{
return
newFileDTO
(
rnrId
,
pic
,
fileType
,
"0"
,
rnrBizzType
);
}
//创建文件信息
public
static
MgRnrFileDTO
newFileDTO
(
String
rnrId
,
String
pic
,
Integer
fileType
,
String
liasionId
,
int
rnrBizzType
)
{
MgRnrFileDTO
mgRnrFileDTO
=
new
MgRnrFileDTO
();
mgRnrFileDTO
.
setUuid
(
CuscStringUtils
.
generateUuid
());
mgRnrFileDTO
.
setRnrId
(
rnrId
);
mgRnrFileDTO
.
setFileType
(
fileType
);
mgRnrFileDTO
.
setFileSystemId
(
pic
);
mgRnrFileDTO
.
setTenantNo
(
UserSubjectUtil
.
getTenantNo
());
mgRnrFileDTO
.
setLiaisonId
(
liasionId
);
mgRnrFileDTO
.
setCreator
(
UserSubjectUtil
.
getUserId
());
mgRnrFileDTO
.
setOperator
(
UserSubjectUtil
.
getUserId
());
mgRnrFileDTO
.
setRnrBizzType
(
rnrBizzType
);
return
mgRnrFileDTO
;
}
/**
* 车企和企业的excel转成车卡list
*
* @param usingXSSF 是否使用xssf
* @param skipLines 跳过的行数,用于跳过列名行
* @return
*/
public
static
List
<
VinCardDTO
>
convertExcelToVinCardList
(
InputStream
inputStream
,
boolean
usingXSSF
,
int
skipLines
)
throws
IOException
{
try
(
Workbook
wb
=
usingXSSF
?
new
XSSFWorkbook
(
inputStream
)
:
new
HSSFWorkbook
(
inputStream
))
{
Sheet
sheet
=
wb
.
getSheetAt
(
0
);
Iterator
<
Row
>
iterator
=
sheet
.
iterator
();
List
<
VinCardDTO
>
vinCardDTOS
=
new
ArrayList
<>();
int
index
=
0
;
while
(
iterator
.
hasNext
())
{
Row
next
=
iterator
.
next
();
if
(
index
<
skipLines
)
{
index
++;
continue
;
}
//如果读取到的第一列的数据为空,则跳过
String
cellValue
=
getCellValue
(
next
.
getCell
(
0
));
if
(
StringUtils
.
isBlank
(
cellValue
)){
continue
;
}
vinCardDTOS
.
add
(
new
VinCardDTO
(
cellValue
,
getCellValue
(
next
.
getCell
(
1
))));
}
return
vinCardDTOS
;
}
}
/**
* 获取文件类型
*
* @param certType 证书类型
* @param index 索引
*/
public
static
Integer
getFileType
(
String
certType
,
int
index
)
{
CertTypeEnum
typeEnum
=
CertTypeEnum
.
getEnumByCode
(
certType
);
if
(
index
<
0
||
typeEnum
==
null
||
typeEnum
.
getFileTypes
()
==
null
||
typeEnum
.
getFileTypes
().
length
<
0
)
{
throw
new
CuscUserException
(
ResponseCode
.
INVALID_DATA
.
getCode
(),
"证件类型【"
+
certType
+
"】错误"
);
}
//不能超过固定的文件数量
if
(
typeEnum
.
isFixedSize
()
&&
index
>=
typeEnum
.
getFileTypes
().
length
)
{
throw
new
CuscUserException
(
ResponseCode
.
INVALID_DATA
.
getCode
(),
"证件【"
+
typeEnum
.
getName
()
+
"】上传文件数超过指定数量【"
+
typeEnum
.
getFileTypes
().
length
+
"】"
);
}
if
(
index
>=
typeEnum
.
getFileTypes
().
length
)
{
index
=
typeEnum
.
getFileTypes
().
length
-
1
;
}
return
typeEnum
.
getFileTypes
()[
index
].
getCode
();
}
public
static
List
<
VinCardVerityResult
>
convertExcelToVinCardLists
(
InputStream
inputStream
,
boolean
usingXSSF
,
int
skipLines
)
throws
IOException
{
try
(
Workbook
wb
=
usingXSSF
?
new
XSSFWorkbook
(
inputStream
)
:
new
HSSFWorkbook
(
inputStream
))
{
Sheet
sheet
=
wb
.
getSheetAt
(
0
);
Iterator
<
Row
>
iterator
=
sheet
.
iterator
();
List
<
VinCardVerityResult
>
vinCardDTOS
=
new
ArrayList
<>();
int
index
=
0
;
while
(
iterator
.
hasNext
())
{
Row
next
=
iterator
.
next
();
if
(
index
<
skipLines
)
{
index
++;
continue
;
}
//如果读取到的第一列的数据为空,表示已经读到最后,跳出
String
cellValue
=
getCellValue
(
next
.
getCell
(
0
));
if
(
StringUtils
.
isBlank
(
cellValue
)){
continue
;
}
vinCardDTOS
.
add
(
new
VinCardVerityResult
(
cellValue
,
getCellValue
(
next
.
getCell
(
1
)),
StringUtils
.
equals
(
getCellValue
(
next
.
getCell
(
2
)),
VerifyExcelStatusEnum
.
SUCCESS
.
getCode
())
,
getCellValue
(
next
.
getCell
(
3
))));
}
return
vinCardDTOS
;
}
}
/**
* 获取单元格值
*
* @param cell
* @return
*/
private
static
String
getCellValue
(
Cell
cell
)
{
if
(
cell
==
null
)
{
return
""
;
}
CellType
cellType
=
cell
.
getCellType
();
switch
(
cellType
)
{
case
STRING:
return
cell
.
getStringCellValue
();
case
NUMERIC:
return
String
.
valueOf
((
int
)
cell
.
getNumericCellValue
());
case
BOOLEAN:
return
String
.
valueOf
(
cell
.
getBooleanCellValue
());
default
:
return
""
;
}
}
/**
* 校验结果转成excel数据
*/
public
static
ExcelSheetDTO
convertVerityResultToExcelDTO
(
List
<
VinCardVerityResult
>
verityResults
)
{
ExcelSheetDTO
excelSheetDTO
=
new
ExcelSheetDTO
();
excelSheetDTO
.
setSheetName
(
"验证结果列表"
);
excelSheetDTO
.
setSchema
(
new
String
[]{
"VIN"
,
"ICCID"
,
"状态"
,
"错误信息"
});
if
(!
verityResults
.
isEmpty
())
{
for
(
VinCardVerityResult
verityResult
:
verityResults
)
{
excelSheetDTO
.
getData
().
add
(
new
String
[]{
verityResult
.
getVin
(),
verityResult
.
getIccid
()
,
verityResult
.
isExist
()
?
VerifyExcelStatusEnum
.
SUCCESS
.
getCode
()
:
VerifyExcelStatusEnum
.
FAILED
.
getCode
()
,
verityResult
.
getMsg
()});
}
}
return
excelSheetDTO
;
}
/**
* 通过文件名判断excel格式
*
* @param fileName
* @return
*/
public
static
boolean
isExcelXSSFFormat
(
String
fileName
)
{
return
StringUtils
.
isNotBlank
(
fileName
)
&&
fileName
.
toLowerCase
().
endsWith
(
".xlsx"
);
}
public
static
MultipartFile
bytesToMultipartFile
(
byte
[]
bytes
,
String
fileName
)
{
FileItem
fileItem
=
new
DiskFileItemFactory
().
createItem
(
"file"
,
MediaType
.
MULTIPART_FORM_DATA_VALUE
,
true
,
fileName
);
try
(
InputStream
input
=
new
ByteArrayInputStream
(
bytes
);
OutputStream
os
=
fileItem
.
getOutputStream
())
{
IOUtils
.
copy
(
input
,
os
);
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
"Invalid file: "
+
e
,
e
);
}
return
new
CommonsMultipartFile
(
fileItem
);
}
public
static
byte
[]
createExcelBytes
(
ExcelSheetDTO
excelSheetDTO
,
String
fileName
)
throws
IOException
{
return
createExcelBytes
(
excelSheetDTO
,
isExcelXSSFFormat
(
fileName
));
}
private
static
byte
[]
createExcelBytes
(
ExcelSheetDTO
excelSheetDTO
,
boolean
excelXSSFFormat
)
throws
IOException
{
Workbook
workbook
=
excelXSSFFormat
?
new
XSSFWorkbook
()
:
new
HSSFWorkbook
();
Sheet
sheet
=
workbook
.
createSheet
(
excelSheetDTO
.
getSheetName
());
//写入列名行
int
rowIndex
=
0
,
colIndex
=
0
;
Row
row
=
sheet
.
createRow
(
rowIndex
++);
for
(
String
name
:
excelSheetDTO
.
getSchema
())
{
row
.
createCell
(
colIndex
++).
setCellValue
(
name
);
}
//写入信息
for
(
String
[]
colData
:
excelSheetDTO
.
getData
())
{
colIndex
=
0
;
row
=
sheet
.
createRow
(
rowIndex
++);
for
(
String
cellValue
:
colData
)
{
row
.
createCell
(
colIndex
++).
setCellValue
(
cellValue
);
}
}
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
(
1024
);
workbook
.
write
(
byteArrayOutputStream
);
return
byteArrayOutputStream
.
toByteArray
();
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/IccidUtil.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.util
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 针对iccid的工具类
*/
public
class
IccidUtil
{
private
static
Map
<
String
,
String
>
iccidTOTelcomMap
=
new
HashMap
<>();
static
{
iccidTOTelcomMap
.
put
(
"898600"
,
"中国移动"
);
iccidTOTelcomMap
.
put
(
"898602"
,
"中国移动"
);
iccidTOTelcomMap
.
put
(
"898604"
,
"中国移动"
);
iccidTOTelcomMap
.
put
(
"898607"
,
"中国移动"
);
iccidTOTelcomMap
.
put
(
"898608"
,
"中国移动"
);
iccidTOTelcomMap
.
put
(
"898601"
,
"中国联通"
);
iccidTOTelcomMap
.
put
(
"898606"
,
"中国联通"
);
iccidTOTelcomMap
.
put
(
"898609"
,
"中国联通"
);
iccidTOTelcomMap
.
put
(
"898603"
,
"中国电信"
);
iccidTOTelcomMap
.
put
(
"898611"
,
"中国电信"
);
}
/**
* 获取iccid所属运营商
* @param iccid
* @return
*/
public
static
String
getTelcom
(
String
iccid
)
{
String
key
=
iccid
.
substring
(
0
,
6
);
String
telcomName
=
iccidTOTelcomMap
.
getOrDefault
(
key
,
"未知"
);
return
telcomName
;
}
public
static
boolean
check
(
String
iccid
)
{
String
key
=
iccid
.
substring
(
0
,
6
);
String
telcomName
=
iccidTOTelcomMap
.
getOrDefault
(
key
,
null
);
return
StringUtils
.
isNotBlank
(
telcomName
);
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/IpAddrUtil.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.util
;
import
javax.servlet.http.HttpServletRequest
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
/**
* @className: IpAddrUtil
* @description: 获取访问的ip
* @author: jk
* @date: 2022/7/27 14:07
* @version: 1.0
**/
public
class
IpAddrUtil
{
public
static
String
getIpAddr
(
HttpServletRequest
request
)
{
String
ipAddress
=
request
.
getHeader
(
"x-forwarded-for"
);
if
(
ipAddress
==
null
||
ipAddress
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ipAddress
))
{
ipAddress
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
ipAddress
==
null
||
ipAddress
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ipAddress
))
{
ipAddress
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
ipAddress
==
null
||
ipAddress
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ipAddress
))
{
ipAddress
=
request
.
getRemoteAddr
();
String
localIp
=
"127.0.0.1"
;
String
localIpv6
=
"0:0:0:0:0:0:0:1"
;
if
(
ipAddress
.
equals
(
localIp
)
||
ipAddress
.
equals
(
localIpv6
))
{
// 根据网卡取本机配置的IP
InetAddress
inet
=
null
;
try
{
inet
=
InetAddress
.
getLocalHost
();
ipAddress
=
inet
.
getHostAddress
();
}
catch
(
UnknownHostException
e
)
{
e
.
printStackTrace
();
}
}
}
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
String
ipSeparate
=
","
;
int
ipLength
=
15
;
if
(
ipAddress
!=
null
&&
ipAddress
.
length
()
>
ipLength
)
{
if
(
ipAddress
.
indexOf
(
ipSeparate
)
>
0
)
{
ipAddress
=
ipAddress
.
substring
(
0
,
ipAddress
.
indexOf
(
ipSeparate
));
}
}
return
ipAddress
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/MinIOUtils.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.util
;
import
io.minio.*
;
import
io.minio.http.Method
;
import
io.minio.messages.Bucket
;
import
io.minio.messages.DeleteObject
;
import
io.minio.messages.Item
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Optional
;
/**
* @Author: wangft
* @CreateTime: 2022/6/2 0002 15:09
* @Description: MinIO工具类
*/
@Slf4j
public
class
MinIOUtils
{
private
static
MinioClient
minioClient
;
private
static
String
endpoint
;
private
static
String
bucketName
;
private
static
String
accessKey
;
private
static
String
secretKey
;
private
static
Integer
imgSize
;
private
static
Integer
fileSize
;
private
static
final
String
SEPARATOR
=
"/"
;
public
MinIOUtils
()
{
}
public
MinIOUtils
(
String
endpoint
,
String
bucketName
,
String
accessKey
,
String
secretKey
,
Integer
imgSize
,
Integer
fileSize
)
{
MinIOUtils
.
endpoint
=
endpoint
;
MinIOUtils
.
bucketName
=
bucketName
;
MinIOUtils
.
accessKey
=
accessKey
;
MinIOUtils
.
secretKey
=
secretKey
;
MinIOUtils
.
imgSize
=
imgSize
;
MinIOUtils
.
fileSize
=
fileSize
;
createMinioClient
();
}
/**
* 创建基于Java端的MinioClient
*/
public
void
createMinioClient
()
{
try
{
if
(
null
==
minioClient
)
{
log
.
info
(
"开始创建 MinioClient..."
);
minioClient
=
MinioClient
.
builder
()
.
endpoint
(
endpoint
)
.
credentials
(
accessKey
,
secretKey
)
.
build
();
createBucket
(
bucketName
);
log
.
info
(
"创建完毕 MinioClient..."
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"MinIO服务器异常:{}"
,
e
);
}
}
/**
* 获取上传文件前缀路径
*
* @return
*/
public
static
String
getBasisUrl
()
{
return
endpoint
+
SEPARATOR
+
bucketName
+
SEPARATOR
;
}
/****************************** Operate Bucket Start ******************************/
/**
* 启动SpringBoot容器的时候初始化Bucket
* 如果没有Bucket则创建
*
* @throws Exception
*/
private
static
void
createBucket
(
String
bucketName
)
throws
Exception
{
if
(!
bucketExists
(
bucketName
))
{
minioClient
.
makeBucket
(
MakeBucketArgs
.
builder
().
bucket
(
bucketName
).
build
());
}
}
/**
* 判断Bucket是否存在,true:存在,false:不存在
*
* @return
* @throws Exception
*/
public
static
boolean
bucketExists
(
String
bucketName
)
throws
Exception
{
return
minioClient
.
bucketExists
(
BucketExistsArgs
.
builder
().
bucket
(
bucketName
).
build
());
}
/**
* 获得Bucket的策略
*
* @param bucketName
* @return
* @throws Exception
*/
public
static
String
getBucketPolicy
(
String
bucketName
)
throws
Exception
{
String
bucketPolicy
=
minioClient
.
getBucketPolicy
(
GetBucketPolicyArgs
.
builder
()
.
bucket
(
bucketName
)
.
build
()
);
return
bucketPolicy
;
}
/**
* 获得所有Bucket列表
*
* @return
* @throws Exception
*/
public
static
List
<
Bucket
>
getAllBuckets
()
throws
Exception
{
return
minioClient
.
listBuckets
();
}
/**
* 根据bucketName获取其相关信息
*
* @param bucketName
* @return
* @throws Exception
*/
public
static
Optional
<
Bucket
>
getBucket
(
String
bucketName
)
throws
Exception
{
return
getAllBuckets
().
stream
().
filter
(
b
->
b
.
name
().
equals
(
bucketName
)).
findFirst
();
}
/**
* 根据bucketName删除Bucket,true:删除成功; false:删除失败,文件或已不存在
*
* @param bucketName
* @throws Exception
*/
public
static
void
removeBucket
(
String
bucketName
)
throws
Exception
{
minioClient
.
removeBucket
(
RemoveBucketArgs
.
builder
().
bucket
(
bucketName
).
build
());
}
/****************************** Operate Bucket End ******************************/
/****************************** Operate Files Start ******************************/
/**
* 判断文件是否存在
*
* @param bucketName 存储桶
* @param objectName 文件名
* @return
*/
public
static
boolean
isObjectExist
(
String
bucketName
,
String
objectName
)
{
boolean
exist
=
true
;
try
{
minioClient
.
statObject
(
StatObjectArgs
.
builder
().
bucket
(
bucketName
).
object
(
objectName
).
build
());
}
catch
(
Exception
e
)
{
exist
=
false
;
}
return
exist
;
}
/**
* 判断文件夹是否存在
*
* @param bucketName 存储桶
* @param objectName 文件夹名称
* @return
*/
public
static
boolean
isFolderExist
(
String
bucketName
,
String
objectName
)
{
boolean
exist
=
false
;
try
{
Iterable
<
Result
<
Item
>>
results
=
minioClient
.
listObjects
(
ListObjectsArgs
.
builder
().
bucket
(
bucketName
).
prefix
(
objectName
).
recursive
(
false
).
build
());
for
(
Result
<
Item
>
result
:
results
)
{
Item
item
=
result
.
get
();
if
(
item
.
isDir
()
&&
objectName
.
equals
(
item
.
objectName
()))
{
exist
=
true
;
}
}
}
catch
(
Exception
e
)
{
exist
=
false
;
}
return
exist
;
}
/**
* 根据文件前缀查询文件
*
* @param bucketName 存储桶
* @param prefix 前缀
* @param recursive 是否使用递归查询
* @return MinioItem 列表
* @throws Exception
*/
public
static
List
<
Item
>
getAllObjectsByPrefix
(
String
bucketName
,
String
prefix
,
boolean
recursive
)
throws
Exception
{
List
<
Item
>
list
=
new
ArrayList
<>();
Iterable
<
Result
<
Item
>>
objectsIterator
=
minioClient
.
listObjects
(
ListObjectsArgs
.
builder
().
bucket
(
bucketName
).
prefix
(
prefix
).
recursive
(
recursive
).
build
());
if
(
objectsIterator
!=
null
)
{
for
(
Result
<
Item
>
o
:
objectsIterator
)
{
Item
item
=
o
.
get
();
list
.
add
(
item
);
}
}
return
list
;
}
/**
* 获取文件流
*
* @param bucketName 存储桶
* @param objectName 文件名
* @return 二进制流
*/
public
static
InputStream
getObject
(
String
bucketName
,
String
objectName
)
throws
Exception
{
return
minioClient
.
getObject
(
GetObjectArgs
.
builder
().
bucket
(
bucketName
).
object
(
objectName
).
build
());
}
/**
* 断点下载
*
* @param bucketName 存储桶
* @param objectName 文件名称
* @param offset 起始字节的位置
* @param length 要读取的长度
* @return 二进制流
*/
public
InputStream
getObject
(
String
bucketName
,
String
objectName
,
long
offset
,
long
length
)
throws
Exception
{
return
minioClient
.
getObject
(
GetObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
objectName
)
.
offset
(
offset
)
.
length
(
length
)
.
build
());
}
/**
* 获取路径下文件列表
*
* @param bucketName 存储桶
* @param prefix 文件名称
* @param recursive 是否递归查找,false:模拟文件夹结构查找
* @return 二进制流
*/
public
static
Iterable
<
Result
<
Item
>>
listObjects
(
String
bucketName
,
String
prefix
,
boolean
recursive
)
{
return
minioClient
.
listObjects
(
ListObjectsArgs
.
builder
()
.
bucket
(
bucketName
)
.
prefix
(
prefix
)
.
recursive
(
recursive
)
.
build
());
}
/**
* 使用MultipartFile进行文件上传
*
* @param bucketName 存储桶
* @param file 文件名
* @param objectName 对象名
* @param contentType 类型
* @return
* @throws Exception
*/
public
static
ObjectWriteResponse
uploadFile
(
String
bucketName
,
MultipartFile
file
,
String
objectName
,
String
contentType
)
throws
Exception
{
InputStream
inputStream
=
file
.
getInputStream
();
return
minioClient
.
putObject
(
PutObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
objectName
)
.
contentType
(
contentType
)
.
stream
(
inputStream
,
inputStream
.
available
(),
-
1
)
.
build
());
}
/**
* 上传本地文件
*
* @param bucketName 存储桶
* @param objectName 对象名称
* @param fileName 本地文件路径
*/
public
static
ObjectWriteResponse
uploadFile
(
String
bucketName
,
String
objectName
,
String
fileName
)
throws
Exception
{
return
minioClient
.
uploadObject
(
UploadObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
objectName
)
.
filename
(
fileName
)
.
build
());
}
/**
* 通过流上传文件
*
* @param bucketName 存储桶
* @param objectName 文件对象
* @param inputStream 文件流
*/
public
static
ObjectWriteResponse
uploadFile
(
String
bucketName
,
String
objectName
,
InputStream
inputStream
)
throws
Exception
{
return
minioClient
.
putObject
(
PutObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
objectName
)
.
stream
(
inputStream
,
inputStream
.
available
(),
-
1
)
.
build
());
}
/**
* 创建文件夹或目录
*
* @param bucketName 存储桶
* @param objectName 目录路径
*/
public
static
ObjectWriteResponse
createDir
(
String
bucketName
,
String
objectName
)
throws
Exception
{
return
minioClient
.
putObject
(
PutObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
objectName
)
.
stream
(
new
ByteArrayInputStream
(
new
byte
[]{}),
0
,
-
1
)
.
build
());
}
/**
* 获取文件信息, 如果抛出异常则说明文件不存在
*
* @param bucketName 存储桶
* @param objectName 文件名称
*/
public
static
String
getFileStatusInfo
(
String
bucketName
,
String
objectName
)
throws
Exception
{
return
minioClient
.
statObject
(
StatObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
objectName
)
.
build
()).
toString
();
}
/**
* 拷贝文件
*
* @param bucketName 存储桶
* @param objectName 文件名
* @param srcBucketName 目标存储桶
* @param srcObjectName 目标文件名
*/
public
static
ObjectWriteResponse
copyFile
(
String
bucketName
,
String
objectName
,
String
srcBucketName
,
String
srcObjectName
)
throws
Exception
{
return
minioClient
.
copyObject
(
CopyObjectArgs
.
builder
()
.
source
(
CopySource
.
builder
().
bucket
(
bucketName
).
object
(
objectName
).
build
())
.
bucket
(
srcBucketName
)
.
object
(
srcObjectName
)
.
build
());
}
/**
* 删除文件
*
* @param bucketName 存储桶
* @param objectName 文件名称
*/
public
static
void
removeFile
(
String
bucketName
,
String
objectName
)
throws
Exception
{
minioClient
.
removeObject
(
RemoveObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
objectName
)
.
build
());
}
/**
* 批量删除文件
*
* @param bucketName 存储桶
* @param keys 需要删除的文件列表
* @return
*/
public
static
void
removeFiles
(
String
bucketName
,
List
<
String
>
keys
)
{
List
<
DeleteObject
>
objects
=
new
LinkedList
<>();
keys
.
forEach
(
s
->
{
objects
.
add
(
new
DeleteObject
(
s
));
try
{
removeFile
(
bucketName
,
s
);
}
catch
(
Exception
e
)
{
log
.
error
(
"批量删除失败!error:{}"
,
e
);
}
});
}
/**
* 获取文件外链
*
* @param bucketName 存储桶
* @param objectName 文件名
* @param expires 过期时间 <=7 秒 (外链有效时间(单位:秒))
* @return url
* @throws Exception
*/
public
static
String
getPresignedObjectUrl
(
String
bucketName
,
String
objectName
,
Integer
expires
)
throws
Exception
{
GetPresignedObjectUrlArgs
args
=
GetPresignedObjectUrlArgs
.
builder
().
expiry
(
expires
).
bucket
(
bucketName
).
object
(
objectName
).
build
();
return
minioClient
.
getPresignedObjectUrl
(
args
);
}
/**
* 获得文件外链
*
* @param bucketName
* @param objectName
* @return url
* @throws Exception
*/
public
static
String
getPresignedObjectUrl
(
String
bucketName
,
String
objectName
)
throws
Exception
{
GetPresignedObjectUrlArgs
args
=
GetPresignedObjectUrlArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
objectName
)
.
method
(
Method
.
GET
).
build
();
return
minioClient
.
getPresignedObjectUrl
(
args
);
}
/**
* 将URLDecoder编码转成UTF8
*
* @param str
* @return
* @throws UnsupportedEncodingException
*/
public
static
String
getUtf8ByURLDecoder
(
String
str
)
throws
UnsupportedEncodingException
{
String
url
=
str
.
replaceAll
(
"%(?![0-9a-fA-F]{2})"
,
"%25"
);
return
URLDecoder
.
decode
(
url
,
"UTF-8"
);
}
/**
* 获取文件大小
* @param bucketName
* @param objectName
* @return
* @throws Exception
*/
public
static
StatObjectResponse
getObjectInfo
(
String
bucketName
,
String
objectName
)
throws
Exception
{
return
minioClient
.
statObject
(
StatObjectArgs
.
builder
()
.
bucket
(
bucketName
)
.
object
(
objectName
)
.
build
());
}
/****************************** Operate Files End ******************************/
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/OSSUtil.java
0 → 100644
View file @
c997214d
/*
package com.cusc.nirvana.user.rnr.enterprise.util;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.*;
import com.cusc.nirvana.user.exception.CuscUserException;
import com.cusc.nirvana.user.rnr.enterprise.dto.OssDownloadRs;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.net.URL;
import java.util.Date;
import java.util.List;
@Data
public class OSSUtil {
private static String endpoint;
private static String accessKeyId;
private static String accessKeySecret;
private static String bucketName;
private static String prefix;
private static OSS ossClient;
public OSSUtil(String endpoint, String bucketName, String accessKey, String secretKey, String prefix) {
OSSUtil.endpoint = endpoint;
OSSUtil.bucketName = bucketName;
OSSUtil.accessKeyId = accessKey;
OSSUtil.accessKeySecret = secretKey;
OSSUtil.prefix = prefix;
getOSSClient();
}
*/
/**
* 获取oss客户端实例
* @return
*//*
public static OSS getOSSClient(){
// if(null == ossClient){
// // 创建OSSClient实例。
// ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
// }
// return ossClient;
return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
}
*/
/**
* 本地文件上传
*
* @param sourceFilePathName 本地文件路径
* @param aimFilePathName 在阿里OSS中保存的可以包含路径的文件名
* @return 返回上传后文件的访问路径
* @throws FileNotFoundException
*//*
public static String upload(String bucketName, String sourceFilePathName, String aimFilePathName) throws FileNotFoundException {
FileInputStream is = new FileInputStream(sourceFilePathName);
if (aimFilePathName.startsWith("/")) {
aimFilePathName = aimFilePathName.substring(1);
}
// 如果需要上传时设置存储类型与访问权限,请参考以下示例代码。
// ObjectMetadata metadata = new ObjectMetadata();
// int indexOfLastDot = aimFilePathName.lastIndexOf(".");
// String suffix = aimFilePathName.substring(indexOfLastDot);
// metadata.setContentType(getContentType(suffix));
//避免文件覆盖
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, aimFilePathName, is);
//避免访问时将图片下载下来
//putObjectRequest.setMetadata(metadata);
OSS ossClient = getOSSClient();
ossClient.putObject(putObjectRequest);
// 设置URL过期时间为100年
Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000 * 24 * 365 * 100);
URL url = ossClient.generatePresignedUrl(bucketName, aimFilePathName, expiration);
ossClient.shutdown();
return url.toString();
}
*/
/**
* 流上传文件
*
* @param is 文件流
* @param aimFilePathName 在阿里OSS中保存的可以包含路径的文件名
* @return 返回上传后文件的访问路径
* @throws FileNotFoundException
*//*
public static String upload(String bucketName, InputStream is, String aimFilePathName) throws FileNotFoundException {
if (aimFilePathName.startsWith("/")) {
aimFilePathName = aimFilePathName.substring(1);
}
//避免文件覆盖
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, aimFilePathName, is);
//避免访问时将图片下载下来
//putObjectRequest.setMetadata(metadata);
OSS ossClient = getOSSClient();
ossClient.putObject(putObjectRequest);
// 设置URL过期时间为100年
Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000 * 24 * 365 * 100);
URL url = ossClient.generatePresignedUrl(bucketName, aimFilePathName, expiration);
ossClient.shutdown();
return url.toString();
}
*/
/**
* 获取文件大小
*
* @param aimFilePathName 在阿里OSS中保存的可以包含路径的文件名
* @return 返回上传后文件的访问路径
* @throws FileNotFoundException
*//*
public static Double getFileSize(String bucketName, String aimFilePathName) throws FileNotFoundException {
OSS ossClient = getOSSClient();
boolean existFlag = ossClient.doesObjectExist(bucketName, aimFilePathName);
if(!existFlag){
throw new CuscUserException("500","文件不存在");
}
Double fileSize = 0D;
ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucketName, aimFilePathName);
fileSize = Double.valueOf(objectMetadata.getContentLength());
ossClient.shutdown();
return fileSize;
}
*/
/**
* multipartFile实现上传
*
* @param multipartFile
* @return
*//*
public static String upload(String bucketName, MultipartFile multipartFile) throws IOException {
// 获取上传的文件的输入流
InputStream inputStream = multipartFile.getInputStream();
// 获取文件名称
String fileName = multipartFile.getOriginalFilename();
// 拼接fileName
fileName = prefix + fileName;
// 如果需要上传时设置存储类型与访问权限
//ObjectMetadata metadata = new ObjectMetadata();
//metadata.setContentType(getContentType(fileName.substring(fileName.lastIndexOf("."))));
// 上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, inputStream);
//putObjectRequest.setMetadata(metadata);
OSS ossClient = getOSSClient();
ossClient.putObject(putObjectRequest);
//文件访问路径
Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000 * 24 * 365 * 100);
URL url = ossClient.generatePresignedUrl(bucketName, fileName, expiration);
// 关闭ossClient
ossClient.shutdown();
// 把上传到oss的路径返回
return url.toString();
}
*/
/**
* 判断文件是否存在,文件名需要完整路径,
* 如rnr_test/1.jpg
*
* @param objectName
* @return
*//*
public static boolean isFileExist(String bucketName, String objectName) {
OSS ossClient = getOSSClient();
boolean res = ossClient.doesObjectExist(bucketName, objectName);
return res;
}
*/
/**
* 根据文件名获取文件路径
*
* @param bucketName 要下载的文件名
* @param fileName 文件完整名称
* *//*
public static String getFileUrl(String bucketName, String fileName) {
OSS ossClient = getOSSClient();
//文件访问路径
Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000 * 24 * 365 * 100);
URL url = ossClient.generatePresignedUrl(bucketName, fileName, expiration);
// 关闭ossClient
ossClient.shutdown();
return url.toString();
}
*/
/**
* 通过文件名下载文件到本地
*
* @param objectName 要下载的文件名
* @param localFileName 本地要创建的文件名
*//*
public static void downloadFile(String bucketName, String objectName, String localFileName) {
OSS ossClient = getOSSClient();
// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
ossClient.getObject(new GetObjectRequest(bucketName, objectName), new File(localFileName));
// 关闭OSSClient。
ossClient.shutdown();
}
*/
/**
* 通过文件名获取下载流
*
* @param objectName 要下载的文件名
*//*
public static OssDownloadRs downloadFile(String bucketName, String objectName) {
OSS ossClient = getOSSClient();
// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
OSSObject object = ossClient.getObject(new GetObjectRequest(bucketName, objectName));
InputStream inputStream = object.getObjectContent();
OssDownloadRs ossDownloadRs = new OssDownloadRs();
ossDownloadRs.setOss(ossClient);
ossDownloadRs.setInputStream(inputStream);
// 关闭OSSClient。
// ossClient.shutdown();
return ossDownloadRs;
}
*/
/**
* 删除文件
*
* @param objectName
*//*
public static void deleteFile(String bucketName, String objectName) {
OSS ossClient = getOSSClient();
ossClient.deleteObject(bucketName, objectName);
ossClient.shutdown();
}
*/
/**
* 批量删除文件或目录
*
* @param keys
*//*
public static void deleteFiles(String bucketName, List<String> keys) {
OSS ossClient = getOSSClient();
// 删除文件。
DeleteObjectsResult deleteObjectsResult = ossClient.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(keys));
List<String> deletedObjects = deleteObjectsResult.getDeletedObjects();
ossClient.shutdown();
}
*/
/**
* 创建文件夹
*
* @param folder
* @return
*//*
public static String createFolder(String bucketName, String folder) {
// 文件夹名
String fileName = folder;
OSS ossClient = getOSSClient();
// 判断文件夹是否存在,不存在则创建
if (!ossClient.doesObjectExist(bucketName, fileName)) {
// 创建文件夹
ossClient.putObject(bucketName, fileName, new ByteArrayInputStream(new byte[0]));
// 得到文件夹名
OSSObject object = ossClient.getObject(bucketName, fileName);
return object.getKey();
}
ossClient.shutdown();
return fileName;
}
*/
/**
* @return String
* @MethodName: contentType
* @Description: 获取文件类型
*//*
private static String contentType(String fileType) {
fileType = fileType.toLowerCase();
String contentType = "";
if (fileType.equals("bmp")) {
contentType = "image/bmp";
} else if (fileType.equals("gif")) {
contentType = "image/gif";
} else if (fileType.equals("png") || fileType.equals("jpeg") || fileType.equals("jpg")) {
contentType = "image/jpeg";
} else if (fileType.equals("html")) {
contentType = "text/html";
} else if (fileType.equals("txt")) {
contentType = "text/plain";
} else if (fileType.equals("vsd")) {
contentType = "application/vnd.visio";
} else if (fileType.equals("ppt") || fileType.equals("pptx")) {
contentType = "application/vnd.ms-powerpoint";
} else if (fileType.equals("doc") || fileType.equals("docx")) {
contentType = "application/msword";
} else if (fileType.equals("xml")) {
contentType = "text/xml";
} else if (fileType.equals("mp4")) {
contentType = "video/mp4";
} else {
contentType = "application/octet-stream";
}
return contentType;
}
}*/
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/ResponseUtil.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.util
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.eiam.common.IamListRespone
;
import
java.util.List
;
/**
* Description: 响应值工具类
* <br />
* CreateDate 2021-11-09 17:42
*
* @author yuyi
**/
public
class
ResponseUtil
{
/**
* Description: 对响应值list类型转换
* <br />
* CreateDate 2021-11-09 17:45:25
*
* @author yuyi
**/
public
static
<
T
>
Response
<
IamListRespone
<
T
>>
changeResponseList
(
Response
<
List
<
T
>>
listResponse
)
{
Response
<
IamListRespone
<
T
>>
ret
=
Response
.
createSuccess
();
if
(
listResponse
!=
null
)
{
IamListRespone
listRes
=
new
IamListRespone
();
listRes
.
setList
(
listResponse
.
getData
());
ret
=
new
Response
<
IamListRespone
<
T
>>(
listResponse
.
getMsg
(),
listResponse
.
getCode
(),
listRes
,
listResponse
.
getSuccess
(),
""
);
}
return
ret
;
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/SpringValidationUtil.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.util
;
import
javax.validation.ConstraintViolation
;
import
javax.validation.Validation
;
import
javax.validation.ValidatorFactory
;
import
java.util.Set
;
/**
* @author yubo
* @since 2022-04-18 19:17
*/
public
class
SpringValidationUtil
{
/**
* 分组验证参数
* @param <T>
* @param validateData 参数
* @param validateGroup 分组
* @return
*/
public
static
<
T
>
Set
<
ConstraintViolation
<
T
>>
groupVerificationParameters
(
T
validateData
,
Class
<?>...
validateGroup
)
{
ValidatorFactory
validatorFactory
=
Validation
.
buildDefaultValidatorFactory
();
return
validatorFactory
.
getValidator
().
validate
(
validateData
,
validateGroup
);
}
}
src/main/java/com/cusc/nirvana/user/rnr/enterprise/util/ValidationUtil.java
0 → 100644
View file @
c997214d
package
com.cusc.nirvana.user.rnr.enterprise.util
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.enterprise.constants.IdentifyConstants
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.Arrays
;
import
java.util.Optional
;
/**
* 校验工具类
*
* @author yubo
* @since 2022-04-19 13:49
*/
public
class
ValidationUtil
{
/**
* 检查手机格式
* @param phone
* @return
*/
public
static
Response
checkPhone
(
String
phone
){
if
(!
phone
.
matches
(
IdentifyConstants
.
PHONE_REGEX
)){
return
Response
.
createError
(
"手机格式错误"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
return
Response
.
createSuccess
();
}
/**
* 使用正则表达式检查证件合法性
*
* @param certType
* @param identityNumber
*/
public
static
Response
checkIdentifyNumber
(
String
certType
,
String
identityNumber
)
{
Optional
<
CertTypeEnum
>
first
=
Arrays
.
stream
(
CertTypeEnum
.
values
())
.
filter
(
c
->
StringUtils
.
equalsIgnoreCase
(
c
.
getCode
(),
certType
))
.
findFirst
();
if
(!
first
.
isPresent
())
{
return
Response
.
createError
(
"证件类型错误"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
CertTypeEnum
certTypeEnum
=
first
.
get
();
//如果是身份证,判断号码是否合法
if
(
certTypeEnum
==
CertTypeEnum
.
IDCARD
&&
!
identityNumber
.
matches
(
IdentifyConstants
.
ID_CARD_REGEX
))
{
return
Response
.
createError
(
"身份证号码格式错误"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
else
if
(
certTypeEnum
==
CertTypeEnum
.
HKIDCARD
&&
!
identityNumber
.
matches
(
IdentifyConstants
.
HK_MACAU_REGEX
))
{
return
Response
.
createError
(
"港澳通行证号码格式错误"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
else
if
(
certTypeEnum
==
CertTypeEnum
.
TAIBAOZHENG
&&
!
identityNumber
.
matches
(
IdentifyConstants
.
HK_TAIWAN_CITIZEN_REGEX
))
{
return
Response
.
createError
(
"台湾居民来往大陆通行证号码格式错误"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
return
Response
.
createSuccess
();
}
//验证证件照片数量
//身份证、港澳通行证、台湾通行证 需要正反面两张照片
public
static
Response
checkIdentifyPics
(
String
certType
,
int
size
)
{
// if (StringUtils.equalsIgnoreCase(CertTypeEnum.IDCARD.getCode(), certType)
// || StringUtils.equalsIgnoreCase(CertTypeEnum.HKIDCARD.getCode(), certType)
// || StringUtils.equalsIgnoreCase(CertTypeEnum.TAIBAOZHENG.getCode(), certType)) {
if
(
size
<
2
)
{
return
Response
.
createError
(
"证件正反面照片不能为空"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
// }
// if (size < 1) {
// return Response.createError("证件照不能为空", ResponseCode.INVALID_DATA.getCode());
// }
return
Response
.
createSuccess
();
}
}
src/main/resources/bootstrap-prod.yml
0 → 100644
View file @
c997214d
spring
:
cloud
:
nacos
:
config
:
server-addr
:
10.179.71.33:8848,10.179.71.81:8848,10.179.71.221:8848
username
:
nacos
password
:
nacos
namespace
:
92bf8770-8770-4326-a20e-2ed8b17a559e
group
:
DEFAULT_GROUP
file-extension
:
yml
discovery
:
server-addr
:
10.179.71.33:8848,10.179.71.81:8848,10.179.71.221:8848
namespace
:
92bf8770-8770-4326-a20e-2ed8b17a559e
username
:
nacos
password
:
nacos
group
:
DEFAULT_GROUP
src/main/resources/bootstrap.yml
0 → 100644
View file @
c997214d
spring
:
application
:
name
:
local-rnr-enterprise
Prev
1
…
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