Commit 88ce9651 authored by kang.nie@inzymeits.com's avatar kang.nie@inzymeits.com
Browse files

初始化代码

parent 00477413
Pipeline #3106 failed with stages
in 0 seconds
package com.cusc.nirvana.user.rnr.customer.service;
import com.cusc.nirvana.user.eiam.dto.UserDTO;
/**
* @author: jk
* @date: 2022/6/8 9:28
* @version: 1.0
*/
public interface IUserService {
/**
* 获取用户的组织id
* @param userId 用户id
* @return
*/
String getOrganId(String userId,String tenantNo);
/**
* 添加用户
* @param userId 用户id
* @param organId 组织id
* @param roleCode 角色code
*/
void addUserRelationRole(String userId, String organId, String roleCode);
/**
* 获取角色id
* @param roleCode
* @return
*/
String getRoleId(String roleCode);
/**
* 获取组织名称
* @param organId
* @return
*/
String getOrganName(String organId,String tenantNo);
/**
* 根据号码查询用户
* @param phone
* @return
*/
UserDTO queryUserInInfoByPhone(String phone);
/**
* 添加用户
* @param userDTO
* @return
*/
UserDTO addUser(UserDTO userDTO);
/**
* 修改用户角色
* @param roleId
* @param userId
*/
void updateUserRole(String roleId, String userId);
}
package com.cusc.nirvana.user.rnr.customer.service;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.customer.dto.EMVinCardResponseDTO;
import com.cusc.nirvana.user.rnr.customer.dto.UnBindIccidDTO;
import com.cusc.nirvana.user.rnr.customer.dto.VehicleCardRnrDTO;
import com.cusc.nirvana.user.rnr.customer.dto.VinDTO;
import com.cusc.nirvana.user.rnr.fp.dto.IccidListDTO;
import com.cusc.nirvana.user.rnr.fp.dto.VerifyVinCardResponseDTO;
import com.cusc.nirvana.user.rnr.fp.dto.VinCardDTO;
import com.cusc.nirvana.user.rnr.fp.dto.VinCardInfoDTO;
import java.util.List;
/**
* 车卡服务接口
*
* @author yubo
* @since 2022-04-18 09:15
*/
public interface IVehicleCardService {
/**
* 车卡关系和卡校验
*
* @param vinCardListDTO
* @return
*/
Response<VerifyVinCardResponseDTO> verifyVinCard(VinCardInfoDTO vinCardListDTO);
/**
* 批量车卡关系和卡校验
*
* @param verifyDTOs
* @return
*/
Response<VerifyVinCardResponseDTO> verifyVinCardBatch(List<VinCardDTO> verifyDTOs);
/**
* 通过vin查询未实名的iccid
* @param vinDTO
* @return
*/
Response<UnBindIccidDTO> getUnBindIccidList(VinDTO vinDTO);
/**
* 通过vin查询实名的iccid
* @param vinDTO
* @return
*/
Response<VehicleCardRnrDTO> getBindIccidList(VinDTO vinDTO);
/**
新车实名查询iccid,如果已经有实名信息,提醒走一车多卡
* @param vin
* @return
*/
Response<IccidListDTO> getNewCarUnBindIccidList(String vin);
}
package com.cusc.nirvana.user.rnr.customer.service;
import com.cusc.nirvana.common.result.Response;
/**
* @className: ValidationService
* @author: jk
* @date: 2022/7/22 9:49
* @version: 1.0
**/
public interface ValidationService {
Response checkEffectiveTime();
}
package com.cusc.nirvana.user.rnr.customer.service.impl;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.customer.constants.CompanyTypeEnum;
import com.cusc.nirvana.user.rnr.customer.constants.IndustryTypeEnum;
import com.cusc.nirvana.user.rnr.customer.dto.DicDTO;
import com.cusc.nirvana.user.rnr.customer.service.IBaseConfigService;
import com.cusc.nirvana.user.rnr.fp.constants.LivenessActionSeqEnum;
import com.cusc.nirvana.user.rnr.fp.constants.LivenessTypeEnum;
import com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class BaseConfigServiceImpl implements IBaseConfigService {
private static final Set<String> PERSON_CERTTYPE_CODE_SET = new HashSet<String>();
private static final Set<String> COMPANY_CERTTYPE_CODE_SET = new HashSet<>();
static {
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.IDCARD.getCode());
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.HKIDCARD.getCode());
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.PASSPORT.getCode());
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.PLA.getCode());
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.POLICEPAPER.getCode());
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.TAIBAOZHENG.getCode());
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.HKRESIDENCECARD.getCode());
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.TWRESIDENCECARD.getCode());
//PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.SOCIAL_ORG_LEGAL_PERSON_CERT.getCode());
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.RESIDENCE.getCode());
PERSON_CERTTYPE_CODE_SET.add(CertTypeEnum.OTHER.getCode());
COMPANY_CERTTYPE_CODE_SET.add(CertTypeEnum.UNITCREDITCODE.getCode());
COMPANY_CERTTYPE_CODE_SET.add(CertTypeEnum.BUSINESS_LICENSE_NO.getCode());
}
@Override
public Response getDicData(String tenantNo) {
Map<String, Object> dicMap = new HashMap<>();
dicMap.put("certType", wrapPersonCertTypeDicList());
dicMap.put("companyCertType", wrapCompanyCertTypeDicList());
dicMap.put("companyType", wrapCompanyTypeDicList());
dicMap.put("industryType", wrapIndustryTypeDicList());
dicMap.put("livenessType", wrapLivenessTypeDicList());
dicMap.put("livenessActionSeq", wrapLivenessActionSeqDicList());
return Response.createSuccess(dicMap);
}
private Object wrapLivenessActionSeqDicList() {
List<DicDTO> list = new ArrayList<>();
for (LivenessActionSeqEnum item : LivenessActionSeqEnum.values()) {
DicDTO dicItem = new DicDTO();
dicItem.setLabel(item.getName());
dicItem.setValue(item.getCode());
list.add(dicItem);
}
return list;
}
private Object wrapLivenessTypeDicList() {
List<DicDTO> list = new ArrayList<>();
for (LivenessTypeEnum item : LivenessTypeEnum.values()) {
DicDTO dicItem = new DicDTO();
dicItem.setLabel(item.getName());
dicItem.setValue(item.getCode());
list.add(dicItem);
}
return list;
}
private List<DicDTO> wrapIndustryTypeDicList() {
List<DicDTO> list = new ArrayList<>();
for (IndustryTypeEnum item : IndustryTypeEnum.values()) {
DicDTO dicItem = new DicDTO();
dicItem.setLabel(item.getValue());
dicItem.setValue(item.getCode() + "");
list.add(dicItem);
}
return list;
}
private List<DicDTO> wrapCompanyCertTypeDicList() {
List<DicDTO> list = new ArrayList<>();
for (CertTypeEnum item : CertTypeEnum.values()) {
DicDTO dicItem = new DicDTO();
if (COMPANY_CERTTYPE_CODE_SET.contains(item.getCode())) {
dicItem.setLabel(item.getName());
dicItem.setValue(item.getCode());
list.add(dicItem);
}
}
return list;
}
private List<DicDTO> wrapCompanyTypeDicList() {
List<DicDTO> list = new ArrayList<>();
for (CompanyTypeEnum item : CompanyTypeEnum.values()) {
DicDTO dicItem = new DicDTO();
dicItem.setLabel(item.getValue());
dicItem.setValue(item.getCode() + "");
list.add(dicItem);
}
return list;
}
private List<DicDTO> wrapPersonCertTypeDicList() {
List<DicDTO> list = new ArrayList<>();
for (CertTypeEnum item : CertTypeEnum.values()) {
DicDTO dicItem = new DicDTO();
if (PERSON_CERTTYPE_CODE_SET.contains(item.getCode())) {
dicItem.setLabel(item.getName());
dicItem.setValue(item.getCode());
list.add(dicItem);
}
}
return list;
}
}
package com.cusc.nirvana.user.rnr.customer.service.impl;
import com.alibaba.fastjson.JSON;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.customer.dto.FileDownloadDTO;
import com.cusc.nirvana.user.rnr.customer.service.IFileService;
import com.cusc.nirvana.user.rnr.fp.client.FileSystemClient;
import com.cusc.nirvana.user.rnr.fp.dto.FileRecordDTO;
import com.cusc.nirvana.user.rnr.fp.dto.FileUploadDTO;
import com.cusc.nirvana.user.rnr.fp.dto.ImageBase64DTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Decoder;
import javax.annotation.Resource;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* 文件上传服务类
*
* @author huzl
* @date 2022/04/18
*/
@Slf4j
@Service
public class FileServiceImpl implements IFileService {
//文件后缀常量
private static final List<String> FILE_SUFFIX_LIST =
Arrays.asList("jpg","jpeg", "png", "gif", "bmp", "pdf", "mp4", "avi", "wav",
"rm","xls","xlsx","doc","docx");
// @Value("${rnr.fileSystem}")
// private String fileServiceSrv;
// @Value("${rnr.fileSelect}")
// private String fileSelect;
@Resource
private FileSystemClient fileSystemClient;
//@Resource
//private RestTemplate nonLoadBalancedFile;
@Override
public Response<FileRecordDTO> upload(FileUploadDTO fileUploadDTO) {
// String url = fileServiceSrv + "/file/upload/" + fileUploadDTO.getType();
//
// final HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.MULTIPART_FORM_DATA);
// if (StringUtils.isNotBlank(fileUploadDTO.getRootPath())) {
// headers.set("rootPath", fileUploadDTO.getRootPath());
// } else {
// headers.set("rootPath", "rnr/");
// }
//
// MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
// if (StringUtils.isNotBlank(fileUploadDTO.getPath())) {
// parameters.add("path", fileUploadDTO.getPath());
// }
// if (StringUtils.isNotBlank(fileUploadDTO.getUuid())) {
// parameters.add("uuid", fileUploadDTO.getUuid());
// }
//
// ByteArrayResource resource = null;
// try {
// resource = new ByteArrayResource(fileUploadDTO.getFile().getBytes()) {
// @Override
// public String getFilename() {
// return fileUploadDTO.getFile().getOriginalFilename();
// }
// };
// } catch (IOException e) {
// throw new AppGlobalException("读取文件流错误", e);
// }
//
// parameters.add("file", resource);
//
// final HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(parameters, headers);
// final ResponseEntity<String> entity = nonLoadBalancedFile.exchange(url, HttpMethod.POST, httpEntity, String
// .class);
// log.info("FileUpload, url:{},parameter:{},header:{},response:{}", url, fileUploadDTO, headers,
// entity.toString());
// Response<FileRecordDTO> response = JSONObject.parseObject(entity.getBody(),
// new TypeReference<Response<FileRecordDTO>>(new Type[] {FileRecordDTO.class}) {
// }.getType());
return fileSystemClient.uploadImage(fileUploadDTO);
}
/**
* 文件上传-重新写
*
* @param fileUploadDTO
* @return
*/
@Override
public Response<FileRecordDTO> uploadTwo(FileUploadDTO fileUploadDTO) {
Response<FileRecordDTO> response = null;
try {
String originalFilename = fileUploadDTO.getFile().getOriginalFilename();
//检查文件后缀
Response fileSuffixResp = chechFileSuffix(originalFilename);
if(!fileSuffixResp.isSuccess()){
return fileSuffixResp;
}
//保存文件防止文件名重复。
// String saveFileName = CuscStringUtils.generateUuid()
// + originalFilename.substring(originalFilename.lastIndexOf("."));
//
// String path = "";
// Object objectWriteResponse = null;
response = fileSystemClient.uploadFile(fileUploadDTO);
log.info("FileUpload response:{}", JSON.toJSON(response));
// FileRecordDTO fileRecord =response.getData();
// FileRecordDTO fileRecordDTO = new FileRecordDTO();
// fileRecordDTO.setFileName(fileRecord.getFileName());
// fileRecordDTO.setPath(fileRecord.getPath());
// fileRecordDTO.setUuid(fileRecord.getUuid());
// fileRecordDTO.setAccessUrl(fileRecord.getAccessUrl());
// response = Response.createSuccess(fileRecordDTO);
} catch (Exception e) {
log.error("----upload-Exception---", e);
}
return response;
}
/**
* 下载文件
*
* @param downloadDTO
* @return
*/
@Override
public InputStream download(FileDownloadDTO downloadDTO) {
byte[] result = downloadToByteArray(downloadDTO);
return new ByteArrayInputStream(result);
}
/**
* 下载文件
*
* @param downloadDTO
* @return
*/
@Override
public byte[] downloadToByteArray(FileDownloadDTO downloadDTO) {
// String url = fileServiceSrv + "/file/download/" + downloadDTO.getUuid();
// log.debug("url: " + url);
//
// log.info("下载文件-开始");
// final ResponseEntity<byte[]> response = nonLoadBalancedFile.getForEntity(url, byte[].class);
// ContentDisposition contentDisposition = response.getHeaders().getContentDisposition();
// log.info("下载文件-结束");
// try {
// if (contentDisposition != null && CuscStringUtils.isNotEmpty(contentDisposition.getFilename())) {
// downloadDTO.setFileName(URLDecoder.decode(contentDisposition.getFilename(), "utf-8"));
// }
// } catch (UnsupportedEncodingException e) {
// log.warn("fileName decode error", e);
// }
// byte[] result = response.getBody();
com.cusc.nirvana.user.rnr.fp.dto.FileDownloadDTO fileDownloadDTO =
new com.cusc.nirvana.user.rnr.fp.dto.FileDownloadDTO();
BeanUtils.copyProperties(downloadDTO, fileDownloadDTO);
Response<ImageBase64DTO> response = fileSystemClient.getBase64(fileDownloadDTO);
ImageBase64DTO imageBase64DTO = response.getData();
byte[] result = null;
try {
result = new BASE64Decoder().decodeBuffer(imageBase64DTO.getBase64());
} catch (IOException e) {
log.warn("fileName decode error", e);
}
return result;
}
// @Override
// public File downloadToLocal(FileDownloadDTO downloadDTO) throws Exception {
// String url = fileServiceSrv + "/file/download/" + downloadDTO.getUuid();
// String localFileName = "";
// if (StringUtils.isNotEmpty(downloadDTO.getFileName())) {
// localFileName = downloadDTO.getFileName();
// }
// String targetPath = generateTmpPath(localFileName);
// //定义请求头的接收类型
// AtomicBoolean isError = new AtomicBoolean(false);
// MultiValueMap<String, String> headers = new HttpHeaders();
// headers.add("Accept", MediaType.toString(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.ALL)));
// final HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(null, headers);
// RequestCallback requestCallback = nonLoadBalancedFile.httpEntityCallback(httpEntity);
// //对响应进行流式处理而不是将其全部加载到内存中
// nonLoadBalancedFile.execute(url, HttpMethod.GET, requestCallback, clientHttpResponse -> {
// HttpStatus statusCode = clientHttpResponse.getStatusCode();
// if (statusCode != HttpStatus.OK) {
// isError.set(true);
// } else {
// Files.copy(clientHttpResponse.getBody(), Paths.get(targetPath));
// }
// return null;
// });
// if (isError.get()) {
// throw new Exception("文件下载失败");
// }
// return new File(targetPath);
// }
private String generateTmpPath(String fileName) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Date date = new Date();
String path = format.format(date);
StringBuilder targetPath = new StringBuilder();
int index = fileName.lastIndexOf(".");
String name = index == -1 ? fileName : fileName.substring(0, index);
String ext = index == -1 ? "" : fileName.substring(index);
String tmpPath = FileUtils.getTempDirectoryPath();
targetPath.append(tmpPath).append((tmpPath.endsWith(File.separator) ? "" : File.separator)).append(path)
.append(File.separator);
File filePath = new File(targetPath.toString());
if (!filePath.exists()) {
filePath.mkdirs();
}
targetPath.append(name).append("_").append(System.currentTimeMillis()).append(ext);
return targetPath.toString();
}
/**
* Description: 文件后缀检查
* <br />
* CreateDate 2022-07-09 23:56:03
*
* @author yuyi
**/
private Response chechFileSuffix(String fileName) {
int startIndex = fileName.lastIndexOf(".");
if (startIndex <= 0) {
return Response.createError("请上传规定的文件格式");
}
String suffixName = fileName.substring(startIndex+1).toLowerCase();
if (FILE_SUFFIX_LIST.contains(suffixName)) {
return Response.createSuccess();
}
return Response.createError("请上传规定的文件格式");
}
}
package com.cusc.nirvana.user.rnr.customer.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.ciam.client.CiamUserClient;
import com.cusc.nirvana.user.ciam.dto.CiamUserDTO;
import com.cusc.nirvana.user.eiam.client.OrganizationClient;
import com.cusc.nirvana.user.eiam.dto.OrganizationDTO;
import com.cusc.nirvana.user.exception.CuscUserException;
import com.cusc.nirvana.user.rnr.customer.dto.*;
import com.cusc.nirvana.user.rnr.customer.service.IEnterpriseH5Service;
import com.cusc.nirvana.user.rnr.customer.service.IUserService;
import com.cusc.nirvana.user.rnr.fp.client.EnterpriseRnrClient;
import com.cusc.nirvana.user.rnr.fp.client.FpRnrClient;
import com.cusc.nirvana.user.rnr.fp.client.NewVinCardClient;
import com.cusc.nirvana.user.rnr.fp.client.SimVehicleRelClient;
import com.cusc.nirvana.user.rnr.fp.common.ResponseCode;
import com.cusc.nirvana.user.rnr.fp.constants.BizTypeEnum;
import com.cusc.nirvana.user.rnr.fp.dto.*;
import com.cusc.nirvana.user.rnr.mg.constants.*;
import com.cusc.nirvana.user.rnr.mg.dto.*;
import com.cusc.nirvana.user.util.CuscStringUtils;
import com.cusc.nirvana.user.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* @className: IEnterpriseH5Impl
* @description: 车主企业实名
* @author: jk
* @date: 2022/6/8 9:18
* @version: 1.0
**/
@Service
@Slf4j
public class IEnterpriseH5Impl implements IEnterpriseH5Service {
@Autowired
SmsServiceImpl smsService;
@Resource
private IUserService userService;
@Resource
private EnterpriseRnrClient enterpriseClient;
@Resource
private NewVinCardClient checkClient;
private static final String SUCCESS_CODE = "0";
@Autowired
FpRnrClient fpRnrClient;
@Value("${enterpriseH5Result:}")
private String enterpriseH5Result;
@Resource
private SimVehicleRelClient simVehicleRelClient;
@Resource
private OrganizationClient organizationClient;
@Resource
private CiamUserClient ciamUserClient;
@Override
public EnterpriseH5RespDTO submitRnrH5(EnterpriseH5RequestDTO dto) {
if (dto.getVinList().stream().distinct().count() != dto.getVinList().size()) {
throw new CuscUserException(ResponseCode.SYSTEM_ERROR.getCode(),"请不要输入重复的vin");
}
for(int i = 0 ;i<dto.getVinList().size();i++){
Response<List<VinIccidDTO>> iccids = simVehicleRelClient.getIccidByVin(dto.getVinList().get(i));
if (!iccids.isSuccess()) {
throw new CuscUserException(iccids.getCode(), iccids.getMsg());
}
for(VinIccidDTO iccidDetailDTO : iccids.getData()) {
//如果为false不允许补录
if (!iccidDetailDTO.getRealBySelf()) {
throw new CuscUserException(com.cusc.nirvana.user.rnr.customer.constants.ResponseCode.REAL_BY_SELF_FALSE.getCode(), com.cusc.nirvana.user.rnr.customer.constants.ResponseCode.REAL_BY_SELF_FALSE.getMsg());
}
}
}
//检查短信验证码
//todo验证码校验被我屏蔽了
// SmsRequestDTO smsRequestDTO = new SmsRequestDTO();
// smsRequestDTO.setPhone(dto.getCorporationPhone());
// smsRequestDTO.setTenantNo(UserSubjectUtil.getTenantNo());
// smsRequestDTO.setBizType(BizTypeEnum.RNR.getCode());
// smsRequestDTO.setCaptcha(dto.getVerificationCode());
// Response smsResponse = smsService.checkSmsCaptcha(smsRequestDTO);
// if (!smsResponse.isSuccess()) {
// throw new CuscUserException(smsResponse.getCode(), smsResponse.getMsg());
// }
EnterpriseRnrCertificationInfoDTO certificationInfoDTO = new EnterpriseRnrCertificationInfoDTO();
BeanUtils.copyProperties(dto, certificationInfoDTO);
//构建relationDto
String rnrId = CuscStringUtils.generateUuid();
String tenantNo = UserSubjectUtil.getTenantNo();
// String orgId = userService.getOrganId(UserSubjectUtil.getUserId(), tenantNo);
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setParentId("0");
organizationDTO.setTenantNo(tenantNo);
Response<List<OrganizationDTO>> orgResponse= organizationClient.queryByList(organizationDTO);
if(!orgResponse.isSuccess()){
throw new CuscUserException(orgResponse.getCode(), orgResponse.getMsg());
}
OrganizationDTO organizationDTO1= orgResponse.getData().get(0);
String orgId = StringUtils.isNotEmpty(dto.getOrgId())?dto.getOrgId():organizationDTO1.getUuid();
//公司信息
MgRnrCompanyInfoDTO mgRnrCompanyInfoDTO = createCompanyInfoDTO(certificationInfoDTO, rnrId, tenantNo);
//rnrInfo
MgRnrInfoDTO rnrInfo = createRnrInfo(certificationInfoDTO, rnrId, tenantNo, mgRnrCompanyInfoDTO.getUuid());
rnrInfo.setIsTrust(0);
rnrInfo.setOrgId(orgId);
//rnrOrder
RnrOrderDTO rnrOrderDTO = createOrder(certificationInfoDTO, rnrInfo, rnrInfo.getUuid(), tenantNo, RnrOrderType.COMPANY_NEW_VEHICLE.getCode());
rnrOrderDTO.setOrgId(orgId);
//文件列表
List<MgRnrFileDTO> fileDTOList = getMgRnrFileDTOs(certificationInfoDTO, null, rnrId, tenantNo,mgRnrCompanyInfoDTO.getUuid());
//卡列表
List<String> vinList = dto.getVinList();
List<MgRnrCardInfoDTO> cardInfoDTOList = createCardInfoDtoByVinList(vinList, tenantNo, rnrId, rnrOrderDTO.getUuid());
RnrRelationDTO rnrRelationDTO = new RnrRelationDTO();
rnrRelationDTO.setCompanyInfo(mgRnrCompanyInfoDTO);
rnrRelationDTO.setInfo(rnrInfo);
rnrRelationDTO.setCardList(cardInfoDTOList);
rnrRelationDTO.setOrder(rnrOrderDTO);
rnrRelationDTO.setRnrFileList(fileDTOList);
Response response = enterpriseClient.submitH5(rnrRelationDTO);
if (!response.isSuccess()) {
throw new CuscUserException(response.getCode(), response.getMsg());
}
EnterpriseH5RespDTO rnrH5RespDTO = new EnterpriseH5RespDTO();
LiveLoginReqDTO loginUrlDto = new LiveLoginReqDTO();
loginUrlDto.setOrderNo(rnrOrderDTO.getUuid());
loginUrlDto.setCallBackUrl(enterpriseH5Result);
// 调用云端接口
Response<LiveLoginRespDTO> h5LiveLoginUrl = fpRnrClient.h5LiveLoginUrl(loginUrlDto);
if (h5LiveLoginUrl.isSuccess()) {
rnrH5RespDTO.setH5LivenessUrl(h5LiveLoginUrl.getData().getH5LiveLoginUrl());
}
rnrH5RespDTO.setRnrId(rnrId);
rnrH5RespDTO.setOrderId(rnrOrderDTO.getUuid());
return rnrH5RespDTO;
}
//公司信息
private MgRnrCompanyInfoDTO createCompanyInfoDTO(EnterpriseRnrCertificationInfoDTO dto, String rnrId, String tenNo) {
MgRnrCompanyInfoDTO mgRnrCompanyInfoDTO = new MgRnrCompanyInfoDTO();
mgRnrCompanyInfoDTO.setUuid(CuscStringUtils.generateUuid());
mgRnrCompanyInfoDTO.setRnrId(rnrId);
mgRnrCompanyInfoDTO.setCompanyCertAddress(dto.getCompanyCertAddress());
mgRnrCompanyInfoDTO.setCompanyCertNumber(dto.getCompanyCertNumber());
mgRnrCompanyInfoDTO.setCompanyCertType(dto.getCompanyCertType());
mgRnrCompanyInfoDTO.setCompanyContactAddress(dto.getCompanyContactAddress());
mgRnrCompanyInfoDTO.setCompanyName(dto.getCompanyName());
mgRnrCompanyInfoDTO.setCompanyType(dto.getCompanyType());
mgRnrCompanyInfoDTO.setIndustryType(dto.getIndustryType());
mgRnrCompanyInfoDTO.setTenantNo(tenNo);
mgRnrCompanyInfoDTO.setCreator(UserSubjectUtil.getUserId());
mgRnrCompanyInfoDTO.setOperator(UserSubjectUtil.getUserId());
mgRnrCompanyInfoDTO.setRnrBizzType(RnrBizzTypeEnum.Bind.getCode());
//是否是车企,数据库默认值是0
if (dto.getIsVehicleCompany() == null) {
dto.setIsVehicleCompany(0);
}
mgRnrCompanyInfoDTO.setIsVehicleCompany(dto.getIsVehicleCompany());
return mgRnrCompanyInfoDTO;
}
//人信息
private MgRnrInfoDTO createRnrInfo(EnterpriseRnrCertificationInfoDTO dto, String rnrId, String tenantNo, String uuid) {
CiamUserDTO ciamUserDTO = new CiamUserDTO();
ciamUserDTO.setUuid(UserSubjectUtil.getUserId());
Response<CiamUserDTO> response = ciamUserClient.queryUserByUuid(ciamUserDTO);
if(!response.isSuccess()){
throw new CuscUserException(response.getCode(),response.getMsg());
}
MgRnrInfoDTO mgRnrInfoDTO = new MgRnrInfoDTO();
mgRnrInfoDTO.setUuid(rnrId);
mgRnrInfoDTO.setTenantNo(UserSubjectUtil.getTenantNo());
mgRnrInfoDTO.setSerial_number(CuscStringUtils.generateUuid());
mgRnrInfoDTO.setIsCompany(1);
mgRnrInfoDTO.setCertAddress(dto.getCorporationCertAddress());
mgRnrInfoDTO.setCertType(dto.getCorporationCertType());
mgRnrInfoDTO.setCertNumber(dto.getCorporationCertNumber());
mgRnrInfoDTO.setContactAddress(dto.getCorporationContactAddress());
mgRnrInfoDTO.setFullName(dto.getCorporationName());
mgRnrInfoDTO.setGender(Integer.valueOf(dto.getCorporationGender()));
mgRnrInfoDTO.setPhone(response.getData().getPhoneNum());
mgRnrInfoDTO.setTenantNo(UserSubjectUtil.getTenantNo());
mgRnrInfoDTO.setEffectiveDate(DateUtils.parseDate(dto.getCorporationCertEffectiveDate(),"yyyy-MM-dd"));
mgRnrInfoDTO.setExpiredDate(dto.getCorporationCertExpirationDate());
//mgRnrInfoDTO.setUuid(CuscStringUtils.generateUuid());
mgRnrInfoDTO.setCreator(UserSubjectUtil.getUserId());
mgRnrInfoDTO.setOperator(UserSubjectUtil.getUserId());
mgRnrInfoDTO.setIsCompany(1);
mgRnrInfoDTO.setRnrCompanyId(uuid);
mgRnrInfoDTO.setRnrStatus(0);
mgRnrInfoDTO.setUserId(UserSubjectUtil.getUserId());
mgRnrInfoDTO.setRnrBizzType(RnrBizzTypeEnum.Bind.getCode());
return mgRnrInfoDTO;
}
//创建工单
private RnrOrderDTO createOrder(EnterpriseRnrCertificationInfoDTO dto, MgRnrInfoDTO rnrInfoDTO, String uuid, String tenNo, int orderType) {
RnrOrderDTO rnrOrderDTO = new RnrOrderDTO();
rnrOrderDTO.setUuid(CuscStringUtils.generateUuid());
rnrOrderDTO.setOrderType(orderType);
rnrOrderDTO.setRnrId(uuid);
rnrOrderDTO.setAuditType(RnrOrderAuditTypeEnum.MANUAL.getCode());
rnrOrderDTO.setAutoRnr(false);
rnrOrderDTO.setIsBatchOrder(1);
rnrOrderDTO.setSerialNumber(rnrInfoDTO.getSerial_number());
rnrOrderDTO.setOrderSource(RnrOrderSourceEnum.H5_CUSTOMER.getCode());
rnrOrderDTO.setCreator(UserSubjectUtil.getUserId());
rnrOrderDTO.setOperator(UserSubjectUtil.getUserId());
rnrOrderDTO.setTenantNo(tenNo);
rnrOrderDTO.setOrderStatus(RnrOrderStatusEnum.TO_EXAMINE.getCode());
rnrOrderDTO.setSendWorkOrder(true);
rnrOrderDTO.setRnrBizzType(RnrBizzTypeEnum.Bind.getCode());
return rnrOrderDTO;
}
//卡信息
private List<MgRnrCardInfoDTO> createCardInfoDTOs(EnterpriseRnrCertificationInfoDTO dto, RnrRelationDTO relationDTO, String tenantNo, String rnrId, String uuid, List<VinCardDTO> vinCardDTOS) {
List<MgRnrCardInfoDTO> cardInfoDTOS = new ArrayList<>();
for (VinCardDTO cardDTO : vinCardDTOS) {
MgRnrCardInfoDTO mgRnrCardInfoDTO = new MgRnrCardInfoDTO();
mgRnrCardInfoDTO.setUuid(CuscStringUtils.generateUuid());
mgRnrCardInfoDTO.setIccid(cardDTO.getIccid());
mgRnrCardInfoDTO.setTenantNo(tenantNo);
mgRnrCardInfoDTO.setIotId(cardDTO.getVin());
mgRnrCardInfoDTO.setRnrId(rnrId);
mgRnrCardInfoDTO.setOrderId(uuid);
mgRnrCardInfoDTO.setCreator(UserSubjectUtil.getUserId());
mgRnrCardInfoDTO.setOperator(UserSubjectUtil.getUserId());
mgRnrCardInfoDTO.setRnrBizzType(RnrBizzTypeEnum.Bind.getCode());
cardInfoDTOS.add(mgRnrCardInfoDTO);
}
return cardInfoDTOS;
}
private List<MgRnrFileDTO> getMgRnrFileDTOs(EnterpriseRnrCertificationInfoDTO requestDTO, RnrRelationDTO rnrRelationDTO, String uuid, String tenNo,String companyId) {
List<MgRnrFileDTO> mgRnrFileDTOS = new ArrayList<>();
//企业实名认证授权书
List<String> authorizationLetterPic = requestDTO.getAuthorizationLetterPic();
for (int i = 0; i < authorizationLetterPic.size(); i++) {
mgRnrFileDTOS.add(newFileDTO(rnrRelationDTO, authorizationLetterPic.get(i), RnrFileType.ENTERPRISE_AUTH_FILE.getCode(), "0", uuid, tenNo, companyId));
}
//企业证件照
List<String> licenseImages = requestDTO.getLicenseImages();
for (int i = 0; i < licenseImages.size(); i++) {
mgRnrFileDTOS.add(newFileDTO(rnrRelationDTO, licenseImages.get(i), RnrFileType.ENTERPRISE_PIC.getCode(), "0", uuid, tenNo, companyId));
}
//责任人证件照
List<String> corporationPhotoPic = requestDTO.getCorporationPhotoPic();
for (int i = 0; i < corporationPhotoPic.size(); i++) {
int index = 0;
if (i != 0) {
index = 1;
}
mgRnrFileDTOS.add(newFileDTO(rnrRelationDTO, corporationPhotoPic.get(i), getFileType(requestDTO.getCorporationCertType(), index), "0", uuid, tenNo, companyId));
}
//活体视频
if (StringUtils.isNotBlank(requestDTO.getLiveVerificationVideo())) {
mgRnrFileDTOS.add(newFileDTO(rnrRelationDTO, requestDTO.getLiveVerificationVideo(), RnrFileType.LIVENESS_VIDEO.getCode(), "0", uuid, tenNo, companyId));
}
//责任告知书
if (!CollectionUtils.isEmpty(requestDTO.getDutyPic())) {
for (String duty:requestDTO.getDutyPic()) {
mgRnrFileDTOS.add(newFileDTO(rnrRelationDTO,duty,RnrFileType.DUTY_FILE.getCode(),"0",uuid,tenNo,companyId));
}
}
//入网合同
if (!CollectionUtils.isEmpty(requestDTO.getContractPic())) {
for (String contact:requestDTO.getContractPic()) {
mgRnrFileDTOS.add(newFileDTO(rnrRelationDTO,contact,RnrFileType.VEHUCLE_BIND.getCode(),"0",uuid,tenNo,companyId));
}
}
return mgRnrFileDTOS;
}
private MgRnrFileDTO newFileDTO(RnrRelationDTO rnrRelationDTO, String pic, Integer fileType, String liasionId, String uuid, String tenNo,String companyId) {
MgRnrFileDTO mgRnrFileDTO = new MgRnrFileDTO();
mgRnrFileDTO.setUuid(CuscStringUtils.generateUuid());
mgRnrFileDTO.setRnrId(uuid);
mgRnrFileDTO.setFileType(fileType);
mgRnrFileDTO.setFileSystemId(pic);
mgRnrFileDTO.setTenantNo(tenNo);
mgRnrFileDTO.setLiaisonId(liasionId);
mgRnrFileDTO.setCreator(UserSubjectUtil.getUserId());
mgRnrFileDTO.setOperator(UserSubjectUtil.getUserId());
mgRnrFileDTO.setRnrBizzType(RnrBizzTypeEnum.Bind.getCode());
mgRnrFileDTO.setTenantNo(tenNo);
mgRnrFileDTO.setRnrCompanyId(companyId);
return mgRnrFileDTO;
}
/**
* 获取文件类型
*
* @param certType 证书类型
* @param index 索引
*/
private Integer getFileType(String certType, int index) {
CertTypeEnum certTypeEnum = Arrays.stream(CertTypeEnum.values())
.filter(c -> StringUtils.equalsIgnoreCase(c.getCode(), certType))
.findFirst().get();
switch (certTypeEnum) {
case IDCARD:
if (index == 0) return RnrFileType.IDENTITY_CARD_BACK.getCode();
if (index == 1) return RnrFileType.IDENTITY_CARD_FRONT.getCode();
return null;
case PLA:
if (index == 0) return RnrFileType.OFFICIAL_CARD_FRONT.getCode();
if (index == 1) return RnrFileType.OFFICIAL_CARD_BACK.getCode();
case HKIDCARD:
if (index == 0) return RnrFileType.HK_MACAO_PASSPORT_FRONT.getCode();
if (index == 1) return RnrFileType.HK_MACAO_PASSPORT_BACK.getCode();
case TAIBAOZHENG:
if (index == 0) return RnrFileType.TAIWAN_CARD_FRONT.getCode();
if (index == 1) return RnrFileType.TAIWAN_CARD_BACK.getCode();
case PASSPORT:
if (index == 0) return RnrFileType.FOREIGN_NATIONAL_PASSPORT_FRONT.getCode();
if (index == 1) return RnrFileType.FOREIGN_NATIONAL_PASSPORT_BACK.getCode();
case POLICEPAPER:
if (index == 0) return RnrFileType.POLICE_CARD_FRONT.getCode();
if (index == 1) return RnrFileType.POLICE_CARD_BACK.getCode();
case HKRESIDENCECARD:
if (index == 0) return RnrFileType.HK_MACAO_RESIDENCE_PERMIT_FRONT.getCode();
if (index == 1) return RnrFileType.HK_MACAO_RESIDENCE_PERMIT_BACK.getCode();
case TWRESIDENCECARD:
if (index == 0) return RnrFileType.TAIWAN_RESIDENCE_PERMIT_FRONT.getCode();
if (index == 1) return RnrFileType.TAIWAN_RESIDENCE_PERMIT_BACK.getCode();
case RESIDENCE:
if (index == 0) return RnrFileType.RESIDENCE_BOOKLET_FRONT.getCode();
if (index == 1) return RnrFileType.RESIDENCE_BOOKLET_BACK.getCode();
case OTHER:
if (index == 0) return RnrFileType.OTHER.getCode();
if (index == 1) return RnrFileType.OTHER.getCode();
default:
return null;
}
}
private List<MgRnrCardInfoDTO> createCardInfoDtoByVinList(List<String> vinList, String tenantNo, String rnrId, String orderId) {
List<MgRnrCardInfoDTO> cardInfoDTOList = Collections.synchronizedList(new ArrayList<>());
String creator = UserSubjectUtil.getUserId();
String operator = UserSubjectUtil.getUserId();
vinList.stream().forEach(vin -> {
VinCardQueryDTO dto = new VinCardQueryDTO();
dto.setVin(vin);
Response<VinCardResultDTO> vinCardResultResponse = checkClient.queryUnBindCardByVin(dto);
log.info("createCardInfoDtoByVinList vin = {},reponse = {}", vin, JSONObject.toJSONString(vinCardResultResponse));
if (null == vinCardResultResponse || !vinCardResultResponse.isSuccess()
|| null == vinCardResultResponse.getData()
|| CollectionUtils.isEmpty(vinCardResultResponse.getData().getIccidList())) {
throw new CuscUserException(ResponseCode.SYSTEM_ERROR.getCode(), "未查询到卡信息");
}
List<String> iccidList = vinCardResultResponse.getData().getIccidList();
for (String iccid : iccidList) {
MgRnrCardInfoDTO mgRnrCardInfoDTO = new MgRnrCardInfoDTO();
mgRnrCardInfoDTO.setUuid(CuscStringUtils.generateUuid());
mgRnrCardInfoDTO.setIccid(iccid);
mgRnrCardInfoDTO.setTenantNo(tenantNo);
mgRnrCardInfoDTO.setIotId(vin);
mgRnrCardInfoDTO.setRnrId(rnrId);
mgRnrCardInfoDTO.setOrderId(orderId);
mgRnrCardInfoDTO.setCreator(creator);
mgRnrCardInfoDTO.setOperator(operator);
mgRnrCardInfoDTO.setRnrBizzType(RnrBizzTypeEnum.Bind.getCode());
cardInfoDTOList.add(mgRnrCardInfoDTO);
}
});
return cardInfoDTOList;
}
@Override
public EnterpriseH5CallBackRespDTO afreshLivenessUrl(LivenessCallbackReqDTO bean) {
EnterpriseH5CallBackRespDTO respDTO = new EnterpriseH5CallBackRespDTO();
boolean success = bean.getCode().equals(SUCCESS_CODE);
if (success) {
// 调用云端接口
//todo 接口调用可能有问题 应该为get请求
LiveLoginReqDTO liveLoginReqDTO = new LiveLoginReqDTO();
liveLoginReqDTO.setOrderNo(bean.getOrderNo());
Response<LivenessResultDTO> livenessResult = fpRnrClient.h5LivenessResult(liveLoginReqDTO);
if (null == livenessResult || !livenessResult.isSuccess() || null == livenessResult.getData()) {
//没有查询到 活体视屏 和 照片 再次拉起腾讯活体H5
LiveLoginReqDTO loginUrlDto = new LiveLoginReqDTO();
loginUrlDto.setOrderNo(bean.getOrderNo());
loginUrlDto.setCallBackUrl(enterpriseH5Result);
// 调用云端接口
Response<LiveLoginRespDTO> h5LiveLoginUrl = fpRnrClient.h5LiveLoginUrl(loginUrlDto);
respDTO.setStatus(2);
if (h5LiveLoginUrl.isSuccess()) {
respDTO.setH5LivenessUrl(h5LiveLoginUrl.getData().getH5LiveLoginUrl());
}
} else {
LivenessResultDTO livenessResultData = livenessResult.getData();
EnterpriseH5CallBackRequestDTO callBackDto = new EnterpriseH5CallBackRequestDTO();
callBackDto.setOrderNo(bean.getOrderNo());
String[] livenessPhotos = new String[2];
livenessPhotos[0] = livenessResultData.getPhotoId();
livenessPhotos[1] = livenessResultData.getPhotoId();
callBackDto.setLivenessPicFileId(livenessPhotos);
callBackDto.setVideFileId(livenessResultData.getVideoFileId());
Response<Integer> response = enterpriseClient.enterpriseRnrH5CallBack(callBackDto);
if (!response.isSuccess() || null == response.getData()) {
throw new CuscUserException(response.getCode(), response.getMsg());
}
Integer data = response.getData();
respDTO.setStatus(data);
}
} else {
LiveLoginReqDTO loginUrlDto = new LiveLoginReqDTO();
loginUrlDto.setOrderNo(bean.getOrderNo());
loginUrlDto.setCallBackUrl(enterpriseH5Result);
// 调用云端接口
Response<LiveLoginRespDTO> h5LiveLoginUrl = fpRnrClient.h5LiveLoginUrl(loginUrlDto);
if (h5LiveLoginUrl.isSuccess()) {
respDTO.setH5LivenessUrl(h5LiveLoginUrl.getData().getH5LiveLoginUrl());
}
respDTO.setStatus(2);
}
return respDTO;
}
}
package com.cusc.nirvana.user.rnr.customer.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil;
import com.cusc.nirvana.user.ciam.client.CiamUserClient;
import com.cusc.nirvana.user.ciam.constants.CiamClientConstant;
import com.cusc.nirvana.user.ciam.dto.CiamUserDTO;
import com.cusc.nirvana.user.eiam.client.OrganizationClient;
import com.cusc.nirvana.user.eiam.dto.OrganizationDTO;
import com.cusc.nirvana.user.exception.CuscUserException;
import com.cusc.nirvana.user.rnr.customer.constants.CustomerTypeEnum;
import com.cusc.nirvana.user.rnr.customer.constants.RnrStatusEnum;
import com.cusc.nirvana.user.rnr.customer.converter.PersonalRequestConvert;
import com.cusc.nirvana.user.rnr.customer.dto.ConsignerInfoDTO;
import com.cusc.nirvana.user.rnr.customer.dto.LivenessCallbackReqDTO;
import com.cusc.nirvana.user.rnr.customer.dto.PersonalH5CallBackRespDTO;
import com.cusc.nirvana.user.rnr.customer.dto.PersonalH5ReqDTO;
import com.cusc.nirvana.user.rnr.customer.dto.PersonalH5RespDTO;
import com.cusc.nirvana.user.rnr.customer.dto.PersonalRequestDTO;
import com.cusc.nirvana.user.rnr.customer.dto.PersonalResponseDTO;
import com.cusc.nirvana.user.rnr.customer.service.IPersonalH5Service;
import com.cusc.nirvana.user.rnr.customer.service.IUserService;
import com.cusc.nirvana.user.rnr.customer.service.IVehicleCardService;
import com.cusc.nirvana.user.rnr.customer.util.FileUtil;
import com.cusc.nirvana.user.rnr.customer.util.SpringValidationUtil;
import com.cusc.nirvana.user.rnr.customer.util.ValidationUtil;
import com.cusc.nirvana.user.rnr.fp.client.FpRnrClient;
import com.cusc.nirvana.user.rnr.fp.client.SimVehicleRelClient;
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.IccidDetailDTO;
import com.cusc.nirvana.user.rnr.fp.dto.IccidListDTO;
import com.cusc.nirvana.user.rnr.fp.dto.LiveLoginReqDTO;
import com.cusc.nirvana.user.rnr.fp.dto.LiveLoginRespDTO;
import com.cusc.nirvana.user.rnr.fp.dto.LivenessResultDTO;
import com.cusc.nirvana.user.rnr.fp.dto.PersonH5CallBackRequestDTO;
import com.cusc.nirvana.user.rnr.fp.dto.VerifyVinCardResponseDTO;
import com.cusc.nirvana.user.rnr.fp.dto.VinCardInfoDTO;
import com.cusc.nirvana.user.rnr.mg.client.MgRnrInfoClient;
import com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum;
import com.cusc.nirvana.user.rnr.mg.constants.GenderEnum;
import com.cusc.nirvana.user.rnr.mg.constants.RnrBizzTypeEnum;
import com.cusc.nirvana.user.rnr.mg.constants.RnrFileType;
import com.cusc.nirvana.user.rnr.mg.constants.RnrLiaisonType;
import com.cusc.nirvana.user.rnr.mg.constants.RnrOrderAuditTypeEnum;
import com.cusc.nirvana.user.rnr.mg.constants.RnrOrderSourceEnum;
import com.cusc.nirvana.user.rnr.mg.constants.RnrOrderStatusEnum;
import com.cusc.nirvana.user.rnr.mg.constants.RnrOrderType;
import com.cusc.nirvana.user.rnr.mg.constants.RnrStatus;
import com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO;
import com.cusc.nirvana.user.rnr.mg.dto.MgRnrFileDTO;
import com.cusc.nirvana.user.rnr.mg.dto.MgRnrInfoDTO;
import com.cusc.nirvana.user.rnr.mg.dto.MgRnrLiaisonInfoDTO;
import com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO;
import com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO;
import com.cusc.nirvana.user.util.CuscStringUtils;
import com.cusc.nirvana.user.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import javax.validation.ConstraintViolation;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @className: IPersonalH5Impl
* @description: 车主H5
* @author: jk
* @date: 2022/6/7 11:08
* @version: 1.0
**/
@Service
@Slf4j
public class IPersonalH5Impl implements IPersonalH5Service {
@Resource
private IUserService userService;
@Autowired
SmsServiceImpl smsService;
@Autowired
FpRnrClient fpRnrClient;
@Autowired
VinCardClient vinCardClient;
@Autowired
IVehicleCardService vehicleCardService;
@Autowired
private SimVehicleRelClient simVehicleRelClient;
@Autowired
private MgRnrInfoClient mgRnrInfoClient;
@Value("${personalH5Result:}")
private String personalH5Result;
@Resource
private OrganizationClient organizationClient;
@Resource
private CiamUserClient ciamUserClient;
@Override
public PersonalH5RespDTO submitRnrH5(PersonalH5ReqDTO bean) {
bean.checkParam();
//只允许本人补录
bean.setIsConsigner(false);
//查询是否允许补录
IccidListDTO mgRnrCardInfoDTO = new IccidListDTO();
mgRnrCardInfoDTO.setIccidList(bean.getIccidList());
Response<List<IccidDetailDTO>> iccids = simVehicleRelClient.queryByIccids(mgRnrCardInfoDTO);
if (!iccids.isSuccess()) {
throw new CuscUserException(iccids.getCode(), iccids.getMsg());
}
for(IccidDetailDTO iccidDetailDTO :iccids.getData()) {
//如果为false不允许补录
if (!iccidDetailDTO.getRealBySelf()) {
throw new CuscUserException(com.cusc.nirvana.user.rnr.customer.constants.ResponseCode.REAL_BY_SELF_FALSE.getCode(), com.cusc.nirvana.user.rnr.customer.constants.ResponseCode.REAL_BY_SELF_FALSE.getMsg());
}
}
PersonalRequestDTO personalRnrRequestDTO = PersonalRequestConvert.INSTANCE.h5PersonRnrRequestToPersonRequstDTO(bean);
personalRnrRequestDTO.setRnrBizzTypeEnum(RnrBizzTypeEnum.Bind.getCode());
Response<RnrRelationDTO> rnrRelationDTOResponse = checkAndConvertToRelation(personalRnrRequestDTO, false);
if (!rnrRelationDTOResponse.isSuccess()) {
throw new CuscUserException(rnrRelationDTOResponse.getCode(), rnrRelationDTOResponse.getMsg());
}
RnrRelationDTO data = rnrRelationDTOResponse.getData();
data.getOrder().setOrderSource(RnrOrderSourceEnum.H5_CUSTOMER.getCode());
log.info("PersonalRnrServiceImpl h5提交参数 data = {}", JSONObject.toJSONString(data));
Response response = fpRnrClient.personRnrH5(data.getOrder().getSerialNumber(), data);
if (!response.isSuccess()) {
throw new CuscUserException(response.getCode(), response.getMsg());
}
//组装数据入库mg_rnr_info
// try {
// Response response1 = mgRnrInfoClient.add(buildMgRnrInfoDTO(bean));
// if(!response1.isSuccess()){
// throw new CuscUserException(response1.getCode(), response1.getMsg());
// }
// } catch (ParseException e) {
// throw new CuscUserException(ResponseCode.INVALID_DATA.getCode(),ResponseCode.INVALID_DATA.getMsg());
// }
PersonalH5RespDTO h5RespDTO = new PersonalH5RespDTO();
h5RespDTO.setOrderId(data.getOrder().getUuid());
LiveLoginReqDTO loginUrlDto = new LiveLoginReqDTO();
loginUrlDto.setOrderNo(data.getOrder().getUuid());
loginUrlDto.setCallBackUrl(personalH5Result);
// 调用云端接口
Response<LiveLoginRespDTO> h5LiveLoginUrl = fpRnrClient.h5LiveLoginUrl(loginUrlDto);
if (h5LiveLoginUrl.isSuccess()) {
h5RespDTO.setH5LivenessUrl(h5LiveLoginUrl.getData().getH5LiveLoginUrl());
}
h5RespDTO.setRnrId(data.getInfo().getUuid());
return h5RespDTO;
}
//组装mg_rnr_info入参
private MgRnrInfoDTO buildMgRnrInfoDTO(PersonalH5ReqDTO dto) throws ParseException {
MgRnrInfoDTO mgRnrInfoDTO = new MgRnrInfoDTO();
mgRnrInfoDTO.setUuid(CuscStringUtils.generateUuid());
mgRnrInfoDTO.setRnrBizzType(RnrBizzTypeEnum.INFO_CHANGE.getCode());
mgRnrInfoDTO.setFullName(dto.getFullName());
mgRnrInfoDTO.setCertType(dto.getCertType());
mgRnrInfoDTO.setCertNumber(dto.getCertNumber());
mgRnrInfoDTO.setCertAddress(dto.getCertAddress());
//拆分时间
// String certExpirationDate = dto.getCertExpirationDate();
mgRnrInfoDTO.setEffectiveDate(new SimpleDateFormat("yyyy-MM-dd").parse(dto.getCertExpirationDate()));
// mgRnrInfoDTO.setExpiredDate(new SimpleDateFormat("yyyy-MM-dd").parse(certExpirationDate.split("-")[1]));
mgRnrInfoDTO.setContactAddress(dto.getContactAddress());
mgRnrInfoDTO.setPhone(dto.getPhone());
mgRnrInfoDTO.setGender(Integer.valueOf(dto.getGender()));
// 是否为企业 0 不是 1 是
mgRnrInfoDTO.setIsCompany(0);
mgRnrInfoDTO.setIsTrust(0);
mgRnrInfoDTO.setIsSecondHandCar(dto.getCustomerType());
mgRnrInfoDTO.setRnrStatus(RnrStatusEnum.INIT.getCode());
mgRnrInfoDTO.setUserId(UserSubjectUtil.getUserId());
mgRnrInfoDTO.setTenantNo(UserSubjectUtil.getTenantNo());
mgRnrInfoDTO.setCreator(UserSubjectUtil.getUserId());
return mgRnrInfoDTO;
}
/**
* 检查参数并转换
*
* @param requestDTO
* @return
*/
public Response<RnrRelationDTO> checkAndConvertToRelation(PersonalRequestDTO requestDTO, boolean unbind) {
log.info("Param checkAndConvertToRelation:{}", JSON.toJSONString(requestDTO));
//手机验证码验证
Response response;
// SmsRequestDTO smsRequestDTO = new SmsRequestDTO();
// if (requestDTO.getIsConsigner()) {
// smsRequestDTO.setPhone(requestDTO.getConsignerInfo().getPhone());
// smsRequestDTO.setCaptcha(requestDTO.getConsignerInfo().getVerificationCode());
// } else {
// smsRequestDTO.setPhone(requestDTO.getPhone());
// smsRequestDTO.setCaptcha(requestDTO.getVerificationCode());
// }
// smsRequestDTO.setBizType(BizTypeEnum.RNR.getCode());
// smsRequestDTO.setTenantNo(UserSubjectUtil.getTenantNo());
// response = smsService.checkSmsCaptcha(smsRequestDTO);
// if (!response.isSuccess()) {
// return Response.createError(response.getMsg(), response.getCode());
// }
//参数必填校验
response = validRnrInfo(requestDTO, unbind);
if (!response.isSuccess()) {
return Response.createError(response.getMsg(), response.getCode());
}
// //车卡信息验证
VinCardInfoDTO vinCardListDTO = new VinCardInfoDTO();
vinCardListDTO.setVin(requestDTO.getVin());
vinCardListDTO.setIccidList(requestDTO.getIccidList());
response = verifyVinCards(vinCardListDTO);
if (!response.isSuccess()) {
if (StringUtils.equals(response.getMsg(), ResponseCode.INVALID_DATA.getMsg())) {
//返回第一个错误
return Response.createError(((PersonalResponseDTO) response.getData()).getResponseMsg().get(0), response.getCode());
}
return Response.createError(response.getMsg(), response.getCode());
}
return Response.createSuccess(convertToRelationDTO(requestDTO));
}
/**
* 进行参数验证
*
* @param requestDTO 请求消息
*/
private Response validRnrInfo(PersonalRequestDTO requestDTO, boolean unbind) {
// if (StringUtils.isBlank(requestDTO.getPurchaseContract())) {
// return Response.createError("购车合同不能为空", ResponseCode.INVALID_DATA.getCode());
// }
// if (StringUtils.isBlank(requestDTO.getPurchaseInvoice())) {
// return Response.createError("购车证明不能为空", ResponseCode.INVALID_DATA.getCode());
// }
// //检查手机
// Response response = ValidationUtil.checkPhone(requestDTO.getPhone());
// if (!response.isSuccess()) {
// return response;
// }
//性别校验
Response response = validGender(requestDTO.getGender());
if (!response.isSuccess()) {
return response;
}
//校验证件号码
response = ValidationUtil.checkIdentifyNumber(requestDTO.getCertType(), requestDTO.getCertNumber());
if (!response.isSuccess()) {
return response;
}
//证件照数量验证
response = ValidationUtil.checkIdentifyPics(requestDTO.getCertType(), requestDTO.getCertPic().size());
if (!response.isSuccess()) {
return response;
}
//二手车车主,需要有过户证明
if (requestDTO.getCustomerType() == CustomerTypeEnum.USED_CAR_OWNER.getCode()) {
if (CollectionUtils.isEmpty(requestDTO.getTransferCertificatePic())) {
return Response.createError("过户证明不能为空", ResponseCode.INVALID_DATA.getCode());
}
if (CollectionUtils.isEmpty(requestDTO.getPurchaseContractPic())) {
return Response.createError("购车合同不能为空", ResponseCode.INVALID_DATA.getCode());
}
if (!unbind && CollectionUtils.isEmpty(requestDTO.getPurchaseInvoicePic())) {
return Response.createError("购车发票不能为空", ResponseCode.INVALID_DATA.getCode());
}
}
if (requestDTO.getIsConsigner()) {
//验证委托人关系
ConsignerInfoDTO consignerInfo = requestDTO.getConsignerInfo();
Set<ConstraintViolation<ConsignerInfoDTO>> violations = SpringValidationUtil.groupVerificationParameters(consignerInfo);
if (!violations.isEmpty()) {
return Response.createError(violations.stream().findFirst().get().getMessage());
}
//性别校验
response = validGender(consignerInfo.getGender());
if (!response.isSuccess()) {
return response;
}
//校验证件号码
response = ValidationUtil.checkIdentifyNumber(consignerInfo.getCertType(), consignerInfo.getCertNumber());
if (!response.isSuccess()) {
return response;
}
//证件照数量验证
response = ValidationUtil.checkIdentifyPics(consignerInfo.getCertType(), consignerInfo.getCertPic().size());
if (!response.isSuccess()) {
return response;
}
//检查手机
response = ValidationUtil.checkPhone(consignerInfo.getPhone());
if (!response.isSuccess()) {
return response;
}
} else {
// //没有委托人,车主验证码必填
// if (StringUtils.isBlank(requestDTO.getVerificationCode())) {
// return Response.createError("手机验证码不能为空", ResponseCode.INVALID_DATA.getCode());
// }
}
return Response.createSuccess();
}
@Override
public PersonalH5CallBackRespDTO afreshLivenessUrl(LivenessCallbackReqDTO bean) {
boolean success = bean.getCode().equals("0");
PersonalH5CallBackRespDTO reponse = new PersonalH5CallBackRespDTO();
if (success) {
//活体成功
PersonH5CallBackRequestDTO callBackDto = new PersonH5CallBackRequestDTO();
callBackDto.setOrderNo(bean.getOrderNo());
callBackDto.setTenantNo(UserSubjectUtil.getTenantNo());
callBackDto.setCiamUserId(UserSubjectUtil.getUserId());
// 调用云端接口
// todo 接口可能有问题
LiveLoginReqDTO liveLoginReqDTO = new LiveLoginReqDTO();
liveLoginReqDTO.setOrderNo(bean.getOrderNo());
Response<LivenessResultDTO> livenessResult = fpRnrClient.h5LivenessResult(liveLoginReqDTO);
if (null == livenessResult || !livenessResult.isSuccess() || null == livenessResult.getData()) {
//没有查询到 活体视屏 和 照片 再次拉起腾讯活体H5
reponse.setStatus(2);
LiveLoginReqDTO loginUrlDto = new LiveLoginReqDTO();
loginUrlDto.setOrderNo(bean.getOrderNo());
loginUrlDto.setCallBackUrl(personalH5Result);
// 调用云端接口
Response<LiveLoginRespDTO> h5LiveLoginUrl = fpRnrClient.h5LiveLoginUrl(loginUrlDto);
if (h5LiveLoginUrl.isSuccess()) {
reponse.setH5LivenessUrl(h5LiveLoginUrl.getData().getH5LiveLoginUrl());
}
return reponse;
}
LivenessResultDTO livenessResultData = livenessResult.getData();
String[] livenessPhotos = new String[2];
livenessPhotos[0] = livenessResultData.getPhotoId();
livenessPhotos[1] = livenessResultData.getPhotoId();
callBackDto.setLivenessPicFileId(livenessPhotos);
callBackDto.setVideFileId(livenessResultData.getVideoFileId());
Response<Integer> response = fpRnrClient.personH5CallBack(callBackDto);
if (!response.isSuccess() || null == response.getData()) {
throw new CuscUserException(response.getCode(), response.getMsg());
}
Integer data = response.getData();
reponse.setStatus(data);
} else {
//活体失败
reponse.setStatus(2);
LiveLoginReqDTO loginUrlDto = new LiveLoginReqDTO();
loginUrlDto.setOrderNo(bean.getOrderNo());
loginUrlDto.setCallBackUrl(personalH5Result);
//调用云端接口
Response<LiveLoginRespDTO> h5LiveLoginUrl = fpRnrClient.h5LiveLoginUrl(loginUrlDto);
if (h5LiveLoginUrl.isSuccess()) {
reponse.setH5LivenessUrl(h5LiveLoginUrl.getData().getH5LiveLoginUrl());
}
//需要修改数据状态
//RnrOrderDTO orderDTO = new RnrOrderDTO();
//orderDTO.setUuid(bean.getOrderNo());
//fpRnrClient.updateRnrInValid(orderDTO);
}
return reponse;
}
/**
* 校验性别
*
*/
private Response validGender(Integer gender) {
if (gender == null || (gender != GenderEnum.FEMALE.getCode()
&& gender != GenderEnum.MALE.getCode())) {
return Response.createError("性别格式错误", ResponseCode.INVALID_DATA.getCode());
}
return Response.createSuccess();
}
public Response<PersonalResponseDTO> verifyVinCards(VinCardInfoDTO vinCardListDTO) {
//调用公共验证接口
Response<VerifyVinCardResponseDTO> response = vehicleCardService.verifyVinCard(vinCardListDTO);
if (!response.isSuccess()) {
return Response.createError(response.getMsg(), response.getCode());
}
//拼接消息体
PersonalResponseDTO personalRnrResponseDTO = new PersonalResponseDTO();
if (CollectionUtils.isEmpty(response.getData().getIccidVerifyResults())) {
return Response.createError("ICCID和VIN不能为空");
}
List<String> msg = response.getData().getIccidVerifyResults().stream()
.filter(ret -> !ret.isExist())
.map(ret -> ret.getMsg())
.collect(Collectors.toList());
personalRnrResponseDTO.setResponseMsg(msg);
if (msg.isEmpty()) {
return Response.createSuccess(personalRnrResponseDTO);
} else {
return Response.createError(ResponseCode.INVALID_DATA.getMsg(), personalRnrResponseDTO);
}
}
/**
* 转成实名信息
*
* @param requestDTO 请求消息
*/
private RnrRelationDTO convertToRelationDTO(PersonalRequestDTO requestDTO) {
String rnrID = CuscStringUtils.generateUuid();
RnrRelationDTO rnrRelationDTO = new RnrRelationDTO();
String tenantNo = UserSubjectUtil.getTenantNo();
//租户
rnrRelationDTO.setTenantNo(tenantNo);
rnrRelationDTO.setIsTrust(requestDTO.getIsConsigner() ? 1 : 0);
rnrRelationDTO.setIsSecondHandCar(requestDTO.getCustomerType() == 1 ? 1 : 0);
//查询当前用户的组织id
// String orgId = userService.getOrganId(UserSubjectUtil.getUserId(), tenantNo);
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setParentId("0");
organizationDTO.setTenantNo(tenantNo);
Response<List<OrganizationDTO>> orgResponse= organizationClient.queryByList(organizationDTO);
if(!orgResponse.isSuccess()){
throw new CuscUserException(orgResponse.getCode(), orgResponse.getMsg());
}
OrganizationDTO organizationDTO1= orgResponse.getData().get(0);
String orgId = StringUtils.isNotEmpty(requestDTO.getOrgId())?requestDTO.getOrgId():organizationDTO1.getUuid();
//实名实体信息
MgRnrInfoDTO rnrInfoDTO = getMgRnrInfoDTO(requestDTO, rnrID);
rnrInfoDTO.setOrgId(orgId);
rnrRelationDTO.setInfo(rnrInfoDTO);
//实名工单信息
RnrOrderDTO orderDTO = getMgRnrOrderDTO(requestDTO, rnrRelationDTO);
orderDTO.setOrgId(orgId);
orderDTO.setTenantNo(tenantNo);
rnrRelationDTO.setOrder(orderDTO);
//实名卡信息
rnrRelationDTO.setCardList(getMgRnrCardDTOs(requestDTO, rnrRelationDTO));
//联系人信息
if (requestDTO.getIsConsigner()) {
rnrRelationDTO.setRnrLiaisonList(getMgRnrLiaisonDTOs(requestDTO, rnrRelationDTO));
}
//实名文件信息
rnrRelationDTO.setRnrFileList(getMgRnrFileDTOs(requestDTO, rnrRelationDTO));
return rnrRelationDTO;
}
/**
* 获取实名主体信息
*
* @param requestDTO 请求消息
*/
private MgRnrInfoDTO getMgRnrInfoDTO(PersonalRequestDTO requestDTO, String rnrID) {
CiamUserDTO ciamUserDTO = new CiamUserDTO();
ciamUserDTO.setUuid(UserSubjectUtil.getUserId());
log.info("queryUserByUuid入参{}",JSON.toJSON(ciamUserDTO));
Response<CiamUserDTO> response = ciamUserClient.queryUserByUuid(ciamUserDTO);
if(!response.isSuccess()){
throw new CuscUserException(response.getCode(),response.getMsg());
}
MgRnrInfoDTO mgRnrInfoDTO = PersonalRequestConvert.INSTANCE.requestDTOToMgRnrDTO(requestDTO);
mgRnrInfoDTO.setIsCompany(0);
mgRnrInfoDTO.setIsTrust(requestDTO.getIsConsigner() ? 1 : 0);
mgRnrInfoDTO.setIsSecondHandCar(Objects.equals(requestDTO.getCustomerType(), CustomerTypeEnum.NEW_CAR_OWNER.getCode()) ? 0 : 1);
mgRnrInfoDTO.setUuid(rnrID);
mgRnrInfoDTO.setCreator(UserSubjectUtil.getUserId());
mgRnrInfoDTO.setOperator(UserSubjectUtil.getUserId());
mgRnrInfoDTO.setSerial_number(CuscStringUtils.generateUuid());
mgRnrInfoDTO.setTenantNo(UserSubjectUtil.getTenantNo());
mgRnrInfoDTO.setRnrStatus(RnrStatus.INIT.getCode());
mgRnrInfoDTO.setRnrBizzType(requestDTO.getRnrBizzTypeEnum());
mgRnrInfoDTO.setExpiredDate(requestDTO.getCertExpirationDate());
mgRnrInfoDTO.setEffectiveDate(DateUtils.parseDate(requestDTO.getCertEffectiveDate(),"yyyy-MM-dd"));
mgRnrInfoDTO.setUserId(UserSubjectUtil.getUserId());
mgRnrInfoDTO.setPhone(response.getData().getPhoneNum());
return mgRnrInfoDTO;
}
/**
* 创建工单信息
*
* @param requestDTO 请求消息
* @param rnrRelationDTO 实名消息
*/
private RnrOrderDTO getMgRnrOrderDTO(PersonalRequestDTO requestDTO, RnrRelationDTO rnrRelationDTO) {
//二手车、或者证书类型不是身份证都是手工
boolean sendWorkOrder = isSendWorkOrder(requestDTO);
boolean isSecondHandCar = rnrRelationDTO.getIsSecondHandCar() == 1;
RnrOrderDTO rnrOrderDTO = new RnrOrderDTO();
rnrOrderDTO.setUuid(CuscStringUtils.generateUuid());
rnrOrderDTO.setOrderType(isSecondHandCar ? RnrOrderType.SEC_VEHICLE.getCode() : RnrOrderType.NEW_VEHICLE.getCode());
rnrOrderDTO.setRnrId(rnrRelationDTO.getInfo().getUuid());
rnrOrderDTO.setAuditType(sendWorkOrder ? RnrOrderAuditTypeEnum.MANUAL.getCode() : RnrOrderAuditTypeEnum.AUTO.getCode());
rnrOrderDTO.setTenantNo(UserSubjectUtil.getTenantNo());
rnrOrderDTO.setAutoRnr(!sendWorkOrder);
rnrOrderDTO.setIsBatchOrder(0);
rnrOrderDTO.setSerialNumber(rnrRelationDTO.getInfo().getSerial_number());
rnrOrderDTO.setOrderSource(RnrOrderSourceEnum.H5_CUSTOMER.getCode());
rnrOrderDTO.setCreator(UserSubjectUtil.getUserId());
rnrOrderDTO.setOperator(UserSubjectUtil.getUserId());
rnrOrderDTO.setSendWorkOrder(sendWorkOrder);
rnrOrderDTO.setOrderStatus(sendWorkOrder ? RnrOrderStatusEnum.ASSIGNMENT.getCode() : RnrOrderStatusEnum.PASS.getCode());
rnrOrderDTO.setRnrBizzType(requestDTO.getRnrBizzTypeEnum());
return rnrOrderDTO;
}
/**
* 判断是否是是否需要发送工单
*
* @param requestDTO
* @return
*/
private boolean isSendWorkOrder(PersonalRequestDTO requestDTO) {
//二手车实名,委托人模式,新车车主非身份证模式都需要发送工单
return requestDTO.getCustomerType() == CustomerTypeEnum.USED_CAR_OWNER.getCode()
|| requestDTO.getIsConsigner()
|| !StringUtils.equalsIgnoreCase(requestDTO.getCertType(), CertTypeEnum.IDCARD.getCode());
}
/**
* 获取实名卡信息
*
* @param requestDTO 请求消息
*/
private List<MgRnrCardInfoDTO> getMgRnrCardDTOs(PersonalRequestDTO requestDTO, RnrRelationDTO rnrRelationDTO) {
List<String> iccidList = requestDTO.getIccidList();
List<MgRnrCardInfoDTO> mgRnrCardInfoDTOS = new ArrayList<>();
MgRnrCardInfoDTO mgRnrCardInfoDTO;
for (String iccid : iccidList) {
mgRnrCardInfoDTO = new MgRnrCardInfoDTO();
mgRnrCardInfoDTO.setUuid(CuscStringUtils.generateUuid());
mgRnrCardInfoDTO.setIccid(iccid);
mgRnrCardInfoDTO.setTenantNo(UserSubjectUtil.getTenantNo());
mgRnrCardInfoDTO.setIotId(requestDTO.getVin());
mgRnrCardInfoDTO.setRnrId(rnrRelationDTO.getInfo().getUuid());
mgRnrCardInfoDTO.setOrderId(rnrRelationDTO.getOrder().getUuid());
mgRnrCardInfoDTO.setCreator(UserSubjectUtil.getUserId());
mgRnrCardInfoDTO.setOperator(UserSubjectUtil.getUserId());
mgRnrCardInfoDTO.setRnrBizzType(requestDTO.getRnrBizzTypeEnum());
mgRnrCardInfoDTOS.add(mgRnrCardInfoDTO);
}
return mgRnrCardInfoDTOS;
}
/**
* 获取联系人信息
*
* @param requestDTO 请求消息
*/
private List<MgRnrLiaisonInfoDTO> getMgRnrLiaisonDTOs(PersonalRequestDTO requestDTO, RnrRelationDTO rnrRelationDTO) {
List<MgRnrLiaisonInfoDTO> liaisonInfoDTOS = new ArrayList<>();
ConsignerInfoDTO consignerInfo = requestDTO.getConsignerInfo();
MgRnrLiaisonInfoDTO mgRnrLiaisonInfoDTO = new MgRnrLiaisonInfoDTO();
mgRnrLiaisonInfoDTO.setLiaisonName(consignerInfo.getFullName());
mgRnrLiaisonInfoDTO.setLiaisonPhone(consignerInfo.getPhone());
mgRnrLiaisonInfoDTO.setLiaisonCertAddress(consignerInfo.getCertAddress());
mgRnrLiaisonInfoDTO.setLiaisonCertNumber(consignerInfo.getCertNumber());
mgRnrLiaisonInfoDTO.setLiaisonCertType(consignerInfo.getCertType());
mgRnrLiaisonInfoDTO.setLiaisonContactAddress(consignerInfo.getContactAddress());
mgRnrLiaisonInfoDTO.setLiaisonType(RnrLiaisonType.CONSIGNEE.getCode());
mgRnrLiaisonInfoDTO.setTenantNo(UserSubjectUtil.getTenantNo());
mgRnrLiaisonInfoDTO.setUuid(CuscStringUtils.generateUuid());
mgRnrLiaisonInfoDTO.setRnrId(rnrRelationDTO.getInfo().getUuid());
mgRnrLiaisonInfoDTO.setOperator(UserSubjectUtil.getUserId());
mgRnrLiaisonInfoDTO.setCreator(UserSubjectUtil.getUserId());
mgRnrLiaisonInfoDTO.setRnrBizzType(requestDTO.getRnrBizzTypeEnum());
mgRnrLiaisonInfoDTO.setLiaisonGender(consignerInfo.getGender());
mgRnrLiaisonInfoDTO.setLiaisonExpiredDate(consignerInfo.getCertExpirationDate());
liaisonInfoDTOS.add(mgRnrLiaisonInfoDTO);
return liaisonInfoDTOS;
}
/**
* 获取实名文件信息
*
* @param requestDTO 请求消息
*/
private List<MgRnrFileDTO> getMgRnrFileDTOs(PersonalRequestDTO requestDTO, RnrRelationDTO rnrRelationDTO) {
List<MgRnrFileDTO> mgRnrFileDTOS = new ArrayList<>();
String rnrId = rnrRelationDTO.getInfo().getUuid();
int rnrBizzTypeEnum = requestDTO.getRnrBizzTypeEnum();
//证件照片
List<String> certPic = requestDTO.getCertPic();
for (int i = 0; i < certPic.size(); i++) {
String pic = certPic.get(i);
Integer fileType = FileUtil.getFileType(requestDTO.getCertType(), i);
if (fileType != null) {
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, pic, fileType, rnrBizzTypeEnum));
}
}
if (requestDTO.getIsConsigner()) {
String consignerId = rnrRelationDTO.getRnrLiaisonList().get(0).getUuid();
//委托人照片
List<String> consignerPic = requestDTO.getConsignerInfo().getCertPic();
for (int i = 0; i < consignerPic.size(); i++) {
String pic = consignerPic.get(i);
Integer fileType = FileUtil.getFileType(requestDTO.getConsignerInfo().getCertType(), i);
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, pic, fileType, consignerId, rnrBizzTypeEnum));
}
//委托书
for (String attorney : requestDTO.getConsignerInfo().getAttorneyLetterPic()) {
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, attorney, RnrFileType.LETTER_ATTORNEY.getCode(), consignerId, rnrBizzTypeEnum));
}
//活体视频
if (StringUtils.isNotBlank(requestDTO.getLiveVerificationVideo())) {
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, requestDTO.getLiveVerificationVideo(), RnrFileType.LIVENESS_VIDEO.getCode(), consignerId, rnrBizzTypeEnum));
}
} else {
//活体视频
if (StringUtils.isNotBlank(requestDTO.getLiveVerificationVideo())) {
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, requestDTO.getLiveVerificationVideo(), RnrFileType.LIVENESS_VIDEO.getCode(), rnrBizzTypeEnum));
}
}
//二手车,购车合同,购车发票,过户合同
if (requestDTO.getCustomerType() == CustomerTypeEnum.USED_CAR_OWNER.getCode()) {
if (!CollectionUtils.isEmpty(requestDTO.getPurchaseInvoicePic())) {
for (String invoice : requestDTO.getPurchaseInvoicePic()) {
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, invoice, RnrFileType.CAR_PURCHASE_INVOICE.getCode(), rnrBizzTypeEnum));
}
}
for (String contract : requestDTO.getPurchaseContractPic()) {
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, contract, RnrFileType.CAR_PURCHASE_CONTRACT.getCode(), rnrBizzTypeEnum));
}
for (String transfer : requestDTO.getTransferCertificatePic()) {
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, transfer, RnrFileType.CAR_TRANSFER_CERTIFICATE.getCode(), rnrBizzTypeEnum));
}
}
//入网合同
if (!CollectionUtils.isEmpty(requestDTO.getContractPic())) {
for (String contractPic : requestDTO.getContractPic()) {
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId, contractPic, RnrFileType.VEHUCLE_BIND.getCode(), rnrBizzTypeEnum));
}
}
//责任告知书
if (!CollectionUtils.isEmpty(requestDTO.getDutyPic())) {
for (String duty:requestDTO.getDutyPic()) {
mgRnrFileDTOS.add(FileUtil.newFileDTO(rnrId,duty, RnrFileType.DUTY_FILE.getCode(), rnrBizzTypeEnum));
}
}
return mgRnrFileDTOS;
}
}
package com.cusc.nirvana.user.rnr.customer.service.impl;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil;
import com.cusc.nirvana.user.eiam.client.OrganizationClient;
import com.cusc.nirvana.user.eiam.dto.OrganizationDTO;
import com.cusc.nirvana.user.eiam.dto.UserOrganDTO;
import com.cusc.nirvana.user.exception.CuscUserException;
import com.cusc.nirvana.user.rnr.customer.config.CustomerConfig;
import com.cusc.nirvana.user.rnr.customer.constants.ResponseCode;
import com.cusc.nirvana.user.rnr.customer.dto.ProtocolManageDTO;
import com.cusc.nirvana.user.rnr.customer.dto.ProtocolManageOneDTO;
import com.cusc.nirvana.user.rnr.customer.dto.ProtocolManageUrlDTO;
import com.cusc.nirvana.user.rnr.customer.service.IProtocolManageService;
import com.cusc.nirvana.user.rnr.fp.client.FileSystemClient;
import com.cusc.nirvana.user.rnr.fp.client.FpRnrProtocolManageClient;
import com.cusc.nirvana.user.rnr.fp.dto.FileDownloadDTO;
import com.cusc.nirvana.user.rnr.fp.dto.FileRecordDTO;
import com.cusc.nirvana.user.rnr.fp.dto.FpRnrProtocolManageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @className: IProtocolManageServiceImpl
* @description: 协议管理
* @author: jk
* @date: 2022/6/10 13:39
* @version: 1.0
**/
@Service
@Slf4j
public class IProtocolManageServiceImpl implements IProtocolManageService {
@Resource
private FpRnrProtocolManageClient fpRnrProtocolManageClient;
@Resource
private FileSystemClient fileSystemClient;
@Resource
private CustomerConfig customerConfig;
@Resource
private OrganizationClient organizationClient;
@Override
public Response<List<ProtocolManageDTO>> query() {
//通过组织id出协议文件
FpRnrProtocolManageDTO fpRnrProtocolManageDTO = new FpRnrProtocolManageDTO();
fpRnrProtocolManageDTO.setTenantNo(UserSubjectUtil.getTenantNo());
fpRnrProtocolManageDTO.setType("1");
Response<List<FpRnrProtocolManageDTO>> responseList = fpRnrProtocolManageClient.queryByList(fpRnrProtocolManageDTO);
if (!responseList.isSuccess()) {
throw new CuscUserException(ResponseCode.SYS_BUSY.getCode(), ResponseCode.SYS_BUSY.getMsg());
}
List<FpRnrProtocolManageDTO> rnrProtocolManageDTOList = responseList.getData();
if (CollectionUtils.isEmpty(rnrProtocolManageDTOList)) {
return Response.createSuccess(rnrProtocolManageDTOList);
}
FpRnrProtocolManageDTO fpRnrProtocolManage = rnrProtocolManageDTOList.get(0);
ProtocolManageDTO protocolManageDTO = new ProtocolManageDTO();
String orgId = fpRnrProtocolManage.getOrgId();
ProtocolManageOneDTO protocolManageOneDTO = new ProtocolManageOneDTO();
BeanUtils.copyProperties(fpRnrProtocolManage, protocolManageOneDTO);
//将对象属性转为map
Map<String, String> map = convertToMap(protocolManageOneDTO);
Map<String, Object> mapReturn = new HashMap<>();
//并行调用查询文件路径
map.entrySet().stream().map(entry -> {
if(!StringUtils.isEmpty(entry.getValue())) {
FileDownloadDTO fileRecordDTO = new FileDownloadDTO();
fileRecordDTO.setUuid(entry.getValue());
Response<FileRecordDTO> fileRecordDTOResponse = fileSystemClient.getUrl(fileRecordDTO);
if (!fileRecordDTOResponse.isSuccess()) {
throw new CuscUserException(ResponseCode.SYS_BUSY.getCode(), ResponseCode.SYS_BUSY.getMsg());
}
ProtocolManageUrlDTO protocolManageUrlDTO = new ProtocolManageUrlDTO();
protocolManageUrlDTO.setFileUrl(fileRecordDTOResponse.getData().getAccessUrl());
// protocolManageUrlDTO.setFileName(fileRecordDTOResponse.getData().getFileName());
protocolManageUrlDTO.setUuid(fileRecordDTOResponse.getData().getUuid());
mapReturn.put(entry.getKey(), protocolManageUrlDTO);
}else {
mapReturn.put(entry.getKey(), "");
}
return mapReturn;
//将路径塞进map对应的key中
// entry.setValue(fileRecordDTOResponse.getData().getPath());
}).collect(Collectors.toList());
mapReturn.put("id", fpRnrProtocolManage.getId());
mapReturn.put("uuid", fpRnrProtocolManage.getUuid());
mapReturn.put("orgId", fpRnrProtocolManage.getOrgId());
//通过反射将map key对应value塞进对应bean属性中
// Object obj= toBean(map1,ProtocolManageDTO.class);
// protocolManageDTO = (ProtocolManageDTO)obj;
// protocolManageDTO.setOrgId(orgId);
return Response.createSuccess(mapReturn);
}
@Override
public Response<List<ProtocolManageDTO>> noLogin() {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setTenantNo(customerConfig.getTenantNo());
organizationDTO.setParentId("0");
organizationDTO.setBizType(1);
Response<List<OrganizationDTO>> re = organizationClient.queryByList(organizationDTO);
if(!re.isSuccess()){
throw new CuscUserException("","获取组织信息失败");
}
//通过组织id出协议文件
FpRnrProtocolManageDTO fpRnrProtocolManageDTO = new FpRnrProtocolManageDTO();
fpRnrProtocolManageDTO.setTenantNo(customerConfig.getTenantNo());
fpRnrProtocolManageDTO.setType("1");
Response<List<FpRnrProtocolManageDTO>> responseList = fpRnrProtocolManageClient.queryByList(fpRnrProtocolManageDTO);
if (!responseList.isSuccess()) {
throw new CuscUserException(ResponseCode.SYS_BUSY.getCode(), ResponseCode.SYS_BUSY.getMsg());
}
List<FpRnrProtocolManageDTO> rnrProtocolManageDTOList = responseList.getData();
if (CollectionUtils.isEmpty(rnrProtocolManageDTOList)) {
return Response.createSuccess(rnrProtocolManageDTOList);
}
FpRnrProtocolManageDTO fpRnrProtocolManage = rnrProtocolManageDTOList.get(0);
ProtocolManageDTO protocolManageDTO = new ProtocolManageDTO();
String orgId = fpRnrProtocolManage.getOrgId();
ProtocolManageOneDTO protocolManageOneDTO = new ProtocolManageOneDTO();
BeanUtils.copyProperties(fpRnrProtocolManage, protocolManageOneDTO);
//将对象属性转为map
Map<String, String> map = convertToMap(protocolManageOneDTO);
Map<String, Object> mapReturn = new HashMap<>();
//并行调用查询文件路径
map.entrySet().stream().map(entry -> {
if(!StringUtils.isEmpty(entry.getValue())) {
FileDownloadDTO fileRecordDTO = new FileDownloadDTO();
fileRecordDTO.setUuid(entry.getValue());
Response<FileRecordDTO> fileRecordDTOResponse = fileSystemClient.getUrl(fileRecordDTO);
if (!fileRecordDTOResponse.isSuccess()) {
throw new CuscUserException(ResponseCode.SYS_BUSY.getCode(), ResponseCode.SYS_BUSY.getMsg());
}
ProtocolManageUrlDTO protocolManageUrlDTO = new ProtocolManageUrlDTO();
protocolManageUrlDTO.setFileUrl(fileRecordDTOResponse.getData().getAccessUrl());
// protocolManageUrlDTO.setFileName(fileRecordDTOResponse.getData().getFileName());
protocolManageUrlDTO.setUuid(fileRecordDTOResponse.getData().getUuid());
if (StringUtils.isEmpty(UserSubjectUtil.getUserId()) && ("logoPc".equals(entry.getKey()) || "logoH5".equals(entry.getKey()))) {
mapReturn.put(entry.getKey(), protocolManageUrlDTO);
}
}else {
mapReturn.put(entry.getKey(), "");
}
return mapReturn;
//将路径塞进map对应的key中
// entry.setValue(fileRecordDTOResponse.getData().getPath());
}).collect(Collectors.toList());
mapReturn.put("id", fpRnrProtocolManage.getId());
mapReturn.put("uuid", fpRnrProtocolManage.getUuid());
mapReturn.put("orgId", fpRnrProtocolManage.getOrgId());
mapReturn.put("organName",re.getData().get(0).getOrganName());
//通过反射将map key对应value塞进对应bean属性中
// Object obj= toBean(map1,ProtocolManageDTO.class);
// protocolManageDTO = (ProtocolManageDTO)obj;
// protocolManageDTO.setOrgId(orgId);
return Response.createSuccess(mapReturn);
}
//将java对象转为map为了方便调用文件查询接口
public static Map<String, String> convertToMap(Object obj) {
try {
if (obj instanceof Map) {
return (Map)obj;
}
Map<String, String> returnMap = org.apache.commons.beanutils.BeanUtils.describe(obj);
returnMap.remove("class");
return returnMap;
} catch (IllegalAccessException e1) {
e1.getMessage();
} catch (InvocationTargetException e2) {
e2.getMessage();
} catch (NoSuchMethodException e3) {
e3.getMessage();
}
return new HashMap();
}
}
package com.cusc.nirvana.user.rnr.customer.service.impl;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.exception.CuscUserException;
import com.cusc.nirvana.user.rnr.customer.service.INewVinCardService;
import com.cusc.nirvana.user.rnr.fp.client.NewVinCardClient;
import com.cusc.nirvana.user.rnr.fp.client.SimVehicleRelClient;
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.MgRnrCardInfoClient;
import com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* @author stayAnd
* @date 2022/5/18
*/
@Service
public class NewVinCardServiceImpl implements INewVinCardService {
@Resource
private NewVinCardClient newVinCardClient;
@Resource
private SimVehicleRelClient simVehicleRelClient;
@Resource
private MgRnrCardInfoClient cardInfoClient;
@Override
public Response<VinCardResultDTO> queryUnBindCardByVin(VinCardQueryDTO queryDTO) {
MgRnrCardInfoDTO mgRnrCardInfoDTO = new MgRnrCardInfoDTO();
List<String> list = new ArrayList<>();
list.add(queryDTO.getVin());
mgRnrCardInfoDTO.setVinList(list);
Response<List<MgRnrCardInfoDTO>> mgRnrCardInfo = cardInfoClient.queryBindListByVin(mgRnrCardInfoDTO);
if(!mgRnrCardInfo.isSuccess()){
throw new CuscUserException(mgRnrCardInfo.getCode(),mgRnrCardInfo.getMsg());
}
for(MgRnrCardInfoDTO mgRnrCardInfos: mgRnrCardInfo.getData()){
if(mgRnrCardInfos.getRnrStatus()==0){
return Response.createError("该车实名审核中");
}else {
return Response.createError("该车已实名");
}
}
return newVinCardClient.queryUnBindCardByVin(queryDTO);
}
@Override
public VinCardCheckResultDTO checkVinCard(VinCardCheckDTO vinCardCheckDTO) {
//paramCheck(vinCardCheckDTO);
if (!CollectionUtils.isEmpty(vinCardCheckDTO.getIccidList()) && vinCardCheckDTO.getIccidList().stream().distinct().count() != vinCardCheckDTO.getIccidList().size()) {
throw new CuscUserException(ResponseCode.SYSTEM_ERROR.getCode(),"请不要输入同样的iccid");
}
//todo 是否允许补录
//查询是否允许补录
IccidListDTO mgRnrCardInfoDTO = new IccidListDTO();
mgRnrCardInfoDTO.setIccidList(vinCardCheckDTO.getIccidList());
Response<List<IccidDetailDTO>> iccids = simVehicleRelClient.queryByIccids(mgRnrCardInfoDTO);
if (!iccids.isSuccess()) {
throw new CuscUserException(iccids.getCode(), iccids.getMsg());
}
for(IccidDetailDTO iccidDetailDTO:iccids.getData()){
if (!iccidDetailDTO.getRealBySelf()) {
throw new CuscUserException("", desensitization(iccidDetailDTO.getIccid())+"不可以补录");
}
}
Response<VinCardCheckResultDTO> checkResponse = newVinCardClient.checkVinCard(vinCardCheckDTO);
if (!checkResponse.isSuccess()) {
throw new CuscUserException(checkResponse.getCode(),checkResponse.getMsg());
}
return checkResponse.getData();
}
@Override
public VinCheckResultDTO checkVin(VinCheckRequestDTO requestDTO) {
if (requestDTO.getVinList().stream().distinct().count() != requestDTO.getVinList().size()) {
throw new CuscUserException(ResponseCode.SYSTEM_ERROR.getCode(),"请不要输入同样的iccid");
}
Response<VinCheckResultDTO> response = newVinCardClient.checkVin(requestDTO);
if (!response.isSuccess()) {
throw new CuscUserException(response.getCode(),response.getMsg());
}
//是否允许补录
if(null != response.getData()) {
for (VinCheckResultDTO.VinCheckDetailDTO vinCheckDetailDTO : response.getData().getCheckList()) {
Response<List<VinIccidDTO>> iccids = simVehicleRelClient.getIccidByVin(vinCheckDetailDTO.getVin());
if (!iccids.isSuccess()) {
throw new CuscUserException(iccids.getCode(), iccids.getMsg());
}
String msg = "";
for (VinIccidDTO vinIccidDTO : iccids.getData()) {
if (!vinIccidDTO.getRealBySelf()) {
msg = msg.concat("当前VIN下iccid为" + desensitization(vinIccidDTO.getIccid()) + "不可以补录;");
}
}
if (!StringUtils.isEmpty(msg)) {
vinCheckDetailDTO.setErrorMsg(msg);
vinCheckDetailDTO.setCheckResult(false);
}
}
}
return response.getData();
}
private String desensitization(String parameter){
String reposen =parameter.substring(0,4)+"***"+parameter.substring(parameter.length()-4,parameter.length());
return reposen;
}
}
package com.cusc.nirvana.user.rnr.customer.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.customer.service.ISmsService;
import com.cusc.nirvana.user.rnr.customer.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);
}
}
package com.cusc.nirvana.user.rnr.customer.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.customer.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: jk
* @description: 用户相关
* @date: 2022/6/8 9:28
* @version: 1.0
*/
@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);
}
}
}
package com.cusc.nirvana.user.rnr.customer.service.impl;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.customer.constants.ResponseCode;
import com.cusc.nirvana.user.rnr.customer.dto.EffectiveTimeDTO;
import com.cusc.nirvana.user.rnr.customer.service.ValidationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @className: ValidationServiceImpl
* @description: jk
* @date: 2022/7/22 9:50
* @version: 1.0
**/
@Service
@Slf4j
public class ValidationServiceImpl implements ValidationService {
@Value("${effectiveTime:}")
private String effectiveTime;
@Override
public Response checkEffectiveTime() {
EffectiveTimeDTO effectiveTimeDTO = new EffectiveTimeDTO();
String startTime = effectiveTime.split("-")[0];
String endTime = effectiveTime.split("-")[1];
effectiveTimeDTO.setStartTime(startTime);
effectiveTimeDTO.setEndTime(endTime);
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
String data = String.valueOf(hour) + ":"+String.valueOf(minute)+ ":"+String.valueOf(second);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
try {
Date date = simpleDateFormat.parse(data);
long ts = date.getTime();
long start = simpleDateFormat.parse(startTime).getTime();
long end = simpleDateFormat.parse(endTime).getTime();
if(start >= ts || end <= ts){
effectiveTimeDTO.setVisit(false);
return Response.createError(ResponseCode.NO_EFFECTIVE_TIME.getMsg()+",\n服务时间为"+effectiveTime,ResponseCode.NO_EFFECTIVE_TIME.getCode());
}
} catch (ParseException e) {
effectiveTimeDTO.setVisit(false);
return Response.createError(ResponseCode.NO_EFFECTIVE_TIME.getMsg()+",\n服务时间为"+effectiveTime,ResponseCode.NO_EFFECTIVE_TIME.getCode());
}
effectiveTimeDTO.setVisit(true);
return Response.createSuccess(effectiveTimeDTO);
}
}
package com.cusc.nirvana.user.rnr.customer.service.impl;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.customer.dto.*;
import com.cusc.nirvana.user.rnr.customer.dto.FileDownloadDTO;
import com.cusc.nirvana.user.rnr.customer.service.IFileService;
import com.cusc.nirvana.user.rnr.customer.service.IVehicleCardService;
import com.cusc.nirvana.user.rnr.customer.util.DesensitizationUtil;
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.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.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author yubo
* @since 2022-04-18 09:26
*/
@Service
@Slf4j
public class VehicleCardServiceImpl implements IVehicleCardService {
@Autowired
IFileService fileService;
@Autowired
VinCardClient vinCardClient;
@Autowired
CardUnBindClient cardUnBindClient;
@Value("${fileTemplate.manufacturer.fileSize: 500}")
private String fileSize;
@Resource
private FileSystemClient fileSystemClient;
/**
* 车卡关系和卡校验
*
* @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<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
Response<VinCardInfoDTO> response = vinCardClient.queryVinCard(vin);
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());
}
}
package com.cusc.nirvana.user.rnr.customer.util;
import org.apache.commons.lang3.StringUtils;
/**
* 脱敏工具类
*
* @author yubo
* @since 2022-05-03 10:26
*/
public class DesensitizationUtil {
/**
* 手机号脱敏
*
* @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;
}
}
package com.cusc.nirvana.user.rnr.customer.util;
import com.cusc.nirvana.user.auth.authentication.plug.user.UserSubjectUtil;
import com.cusc.nirvana.user.exception.CuscUserException;
import com.cusc.nirvana.user.rnr.fp.common.ResponseCode;
import com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum;
import com.cusc.nirvana.user.rnr.mg.dto.MgRnrFileDTO;
import com.cusc.nirvana.user.util.CuscStringUtils;
/**
* 文件处理类
*
* @author yubo
* @since 2022-04-19 10:12
*/
public class FileUtil {
//创建文件信息
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;
}
/**
* 获取文件类型
*
* @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();
}
}
package com.cusc.nirvana.user.rnr.customer.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 ******************************/
}
package com.cusc.nirvana.user.rnr.customer.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);
}
}
package com.cusc.nirvana.user.rnr.customer.util;
import com.cusc.nirvana.common.result.Response;
import com.cusc.nirvana.user.rnr.customer.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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Optional;
/**
* 校验工具类
*
* @author yubo
* @since 2022-04-19 13:49
*/
public class ValidationUtil {
@Value("${effectiveTime}")
private String effectiveTime;
/**
* 检查手机格式
*
* @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 (size < 2) {
return Response.createError("证件正反面照片不能为空", ResponseCode.INVALID_DATA.getCode());
}
return Response.createSuccess();
}
/**
* 判断时间是否在有效期内
*/
public Response checkEffectiveTime(){
String startTime = effectiveTime.split("-")[0];
String endTime = effectiveTime.split("-")[1];
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
String data = String.valueOf(hour) + ":"+String.valueOf(minute)+ ":"+String.valueOf(second);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
try {
Date date = simpleDateFormat.parse(data);
long ts = date.getTime();
long start = simpleDateFormat.parse(startTime).getTime();
long end = simpleDateFormat.parse(endTime).getTime();
if(start >= ts || end <= ts){
return Response.createError(String.valueOf(com.cusc.nirvana.user.rnr.customer.constants.ResponseCode.NO_EFFECTIVE_TIME.getCode()),com.cusc.nirvana.user.rnr.customer.constants.ResponseCode.NO_EFFECTIVE_TIME.getMsg());
}
String res = String.valueOf(ts);
} catch (ParseException e) {
e.printStackTrace();
}
return Response.createSuccess();
}
}
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
spring:
application:
name: local-rnr-customer
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment