面试通过函详情及通过函生成和OSS服务器上传文件

This commit is contained in:
pserimal
2023-06-15 19:02:01 +08:00
parent 3fb8e439ec
commit d80c70deb7
15 changed files with 266 additions and 65 deletions

View File

@@ -41,6 +41,11 @@
<groupId>com.aliyun</groupId>
<artifactId>ons20190214</artifactId>
</dependency>
<!-- OSS -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>

View File

@@ -0,0 +1,64 @@
package com.cool.store.oss;
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.PutObjectRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.InputStream;
@Component
@Slf4j
public class OSSServer {
@Value("${oss.accessKeyId:null}")
private String accessKeyId;
@Value("${oss.accessKeySecret:null}")
private String accessKeySecret;
@Value("${oss.endpoint:null}")
private String endpoint;
@Value("${oss.bucket:null}")
private String bucket;
@Value("${corp.id:null}")
private String corpId;
/**
* 服务端上传文件的方法
* ObjectName 为文件存放位置 + 名字,不可包含 bucket
*/
public String uploadFileServer(InputStream inputStream, String objectName) {
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
// 创建PutObjectRequest对象。
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, objectName, inputStream);
// 创建PutObject请求。
ossClient.putObject(putObjectRequest);
return "http://" + bucket + "." + endpoint + "/" + objectName;
} catch (OSSException oe) {
log.error("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
log.error("Error Message:" + oe.getErrorMessage());
log.error("Error Code:" + oe.getErrorCode());
log.error("Request ID:" + oe.getRequestId());
log.error("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
log.error("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
log.error("Error Message:" + ce.getMessage());
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
return null;
}
}

View File

@@ -1,9 +1,11 @@
package com.cool.store.service;
import com.cool.store.dto.partner.EnterInterviewDto;
import com.cool.store.request.EntrustOthersReq;
import com.cool.store.request.FinishInterviewReq;
import com.cool.store.request.GetInterviewListReq;
import com.cool.store.request.ModifyInterviewTimeReq;
import com.cool.store.vo.EnterInterviewVO;
import com.cool.store.vo.interview.InterviewVO;
import java.util.List;
@@ -39,4 +41,13 @@ public interface InterviewService {
* @param request
*/
void finishInterview(FinishInterviewReq request);
/**
* 进入面试间的方法
* 修改一些面试状态
* 最后返回 userSign 用于进入腾讯云音视频房间
* @return userSign 进入视频所需签名
*/
EnterInterviewVO enterInterviewRoom(EnterInterviewDto dto);
}

View File

@@ -1,7 +1,7 @@
package com.cool.store.service;
import com.cool.store.dto.partner.EnterInterviewDto;
import com.cool.store.vo.PartnerEnterInterviewVO;
import com.cool.store.vo.EnterInterviewVO;
import com.cool.store.vo.PartnerInterviewInfoVO;
import com.cool.store.vo.PartnerPassLetterDetailVO;
@@ -20,7 +20,7 @@ public interface PartnerInterviewService {
* 最后返回 userSign 用于进入腾讯云音视频房间
* @return userSign 进入视频所需签名
*/
PartnerEnterInterviewVO enterInterviewRoom(EnterInterviewDto dto);
EnterInterviewVO enterInterviewRoom(EnterInterviewDto dto);
/**
* 获取通知函详情

View File

@@ -2,8 +2,11 @@ package com.cool.store.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.cool.store.dto.partner.EnterInterviewDto;
import com.cool.store.entity.HyPartnerInterviewDO;
import com.cool.store.entity.HyPartnerInterviewPlanDO;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.mapper.HyPartnerInterviewMapper;
import com.cool.store.mapper.HyPartnerInterviewPlanMapper;
import com.cool.store.request.EntrustOthersReq;
@@ -11,10 +14,14 @@ import com.cool.store.request.FinishInterviewReq;
import com.cool.store.request.GetInterviewListReq;
import com.cool.store.request.ModifyInterviewTimeReq;
import com.cool.store.service.InterviewService;
import com.cool.store.utils.TRTCUtils;
import com.cool.store.vo.EnterInterviewVO;
import com.cool.store.vo.interview.InterviewVO;
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 org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@@ -28,9 +35,18 @@ import java.util.List;
@Service
public class InterviewServiceImpl implements InterviewService {
@Value("${trtc.sdkAppId}")
private Long sdkAppId;
@Value("${trtc.secretKey}")
private String key;
@Autowired
private HyPartnerInterviewPlanMapper hyPartnerInterviewPlanMapper;
@Autowired
private HyPartnerInterviewMapper interviewMapper;
@Autowired
private HyPartnerInterviewMapper hyPartnerInterviewMapper;
@Override
@@ -97,6 +113,35 @@ public class InterviewServiceImpl implements InterviewService {
}
/**
* 进入面试间的方法
* 修改一些面试状态
* 最后返回 userSign 用于进入腾讯云音视频房间
*
* @return userSign 进入视频所需签名
*/
@Override
@Transactional
public EnterInterviewVO enterInterviewRoom(EnterInterviewDto dto) {
try {
//1. 将面试状态改为 --> 2已开始
interviewMapper.updateInterviewStatus(dto.getInterviewId(), 2);
//3. 修改面试实际开始时间,以第一个人进来的时间为准,后续不再修改
interviewMapper.updateActualStartTime(dto.getInterviewId(), DateUtil.now());
//4. 修改加盟商或面试官进入面试时间
interviewMapper.updateEnterTime(dto.getInterviewId(), dto.getUserType(), DateUtil.now());
//5. 加盟商如果进入了,就修改面试计划表 is_partner_interview 字段
interviewMapper.updateWhetherPartnerEnter(dto.getInterviewId());
//6. 查询对应的面试官id、姓名及加盟商姓名
EnterInterviewVO vo = interviewMapper.getInterviewerByInterviewId(dto.getInterviewId());
//生成 userSign
String userSig = TRTCUtils.genUserSig(sdkAppId, key, dto.getUserId());
vo.setUserSign(userSig);
return vo;
} catch (Exception e) {
throw new ServiceException(ErrorCodeEnum.INTERVIEW_ENTER_FAIL);
}
}
}

View File

@@ -2,16 +2,16 @@ package com.cool.store.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.ObjectUtil;
import com.cool.store.dto.partner.EnterInterviewDto;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.mapper.HyPartnerInterviewMapper;
import com.cool.store.oss.OSSServer;
import com.cool.store.service.PartnerInterviewService;
import com.cool.store.utils.PDFUtils;
import com.cool.store.utils.PassLetterUtils;
import com.cool.store.utils.TRTCUtils;
import com.cool.store.vo.PartnerEnterInterviewVO;
import com.cool.store.vo.EnterInterviewVO;
import com.cool.store.vo.PartnerInterviewInfoVO;
import com.cool.store.vo.PartnerPassLetterDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,8 +19,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.*;
@Service
public class PartnerInterviewServiceImpl implements PartnerInterviewService {
@@ -28,6 +27,9 @@ public class PartnerInterviewServiceImpl implements PartnerInterviewService {
@Autowired
private HyPartnerInterviewMapper interviewMapper;
@Autowired
private OSSServer ossServer;
@Value("${trtc.sdkAppId}")
private Long sdkAppId;
@@ -54,7 +56,7 @@ public class PartnerInterviewServiceImpl implements PartnerInterviewService {
*/
@Override
@Transactional
public PartnerEnterInterviewVO enterInterviewRoom(EnterInterviewDto dto) {
public EnterInterviewVO enterInterviewRoom(EnterInterviewDto dto) {
try {
//1. 将面试状态改为 --> 2已开始
interviewMapper.updateInterviewStatus(dto.getInterviewId(), 2);
@@ -64,13 +66,11 @@ public class PartnerInterviewServiceImpl implements PartnerInterviewService {
interviewMapper.updateEnterTime(dto.getInterviewId(), dto.getUserType(), DateUtil.now());
//5. 加盟商如果进入了,就修改面试计划表 is_partner_interview 字段
interviewMapper.updateWhetherPartnerEnter(dto.getInterviewId());
//6. 查询对应的面试官id
String interviewId = interviewMapper.getInterviewerByInterviewId(dto.getInterviewId());
//6. 查询对应的面试官id、姓名及加盟商姓名
EnterInterviewVO vo = interviewMapper.getInterviewerByInterviewId(dto.getInterviewId());
//生成 userSign
String userSig = TRTCUtils.genUserSig(sdkAppId, key, dto.getUserId());
PartnerEnterInterviewVO vo = new PartnerEnterInterviewVO();
vo.setUserSign(userSig);
vo.setInterviewerId(interviewId);
return vo;
} catch (Exception e) {
throw new ServiceException(ErrorCodeEnum.INTERVIEW_ENTER_FAIL);
@@ -84,17 +84,8 @@ public class PartnerInterviewServiceImpl implements PartnerInterviewService {
@Override
public PartnerPassLetterDetailVO passLetterDetail(String interviewId) {
PartnerPassLetterDetailVO vo = interviewMapper.getPassLetterDetail(interviewId);
//有效期为审批通过次日起第 60 天的 23:59:59由此倒推 createTime
DateTime expiryDate = DateUtil.parseDate(vo.getExpiryDate());
DateTime createTime = DateUtil.offsetDay(expiryDate, -61);
vo.setCreateTime(DateUtil.format(createTime, "yyyy-MM-dd"));
//解析意向开店区域为市级行政区
String verifyCity = vo.getVerifyCity();
if (verifyCity == null) {
String passCode = PassLetterUtils.genPassLetter(vo.getPartnerName(), verifyCity, vo.getPassCode(), createTime);
vo.setPassCode(passCode);
return vo;
}
String[] split = verifyCity.split("/");
//根据长度来取市级行政区域
if (split.length == 2) {
@@ -106,9 +97,35 @@ public class PartnerInterviewServiceImpl implements PartnerInterviewService {
} else {
System.out.println("wrong");
}
String passCode = PassLetterUtils.genPassLetter(vo.getPartnerName(), verifyCity, vo.getPassCode(), createTime);
vo.setPassCode(passCode);
// TODO 调用生成通过函和修改数据库数据的方法
String passCode = genPassLetterAndUpdateDB(vo, interviewId);
//再查一次 vo
vo = interviewMapper.getPassLetterDetail(interviewId);
//有效期为审批通过次日起第 60 天的 23:59:59由此倒推 createTime
DateTime expiryDate = DateUtil.parseDate(vo.getExpiryDate());
DateTime createTime = DateUtil.offsetDay(expiryDate, -60);
vo.setCreateTime(DateUtil.format(createTime, "yyyy-MM-dd"));
return vo;
}
/**
* TODO 暂时将生成 passLetter 并上传 OSS 和修改数据库对应信息的方法放在这里,实际应该在 800 的回调方法中
* @return passCode
*/
private String genPassLetterAndUpdateDB(PartnerPassLetterDetailVO passLetterDetail, String interviewId) {
//已经有 passCode 的话就不要再生成了,默认上游全部数据都正确
if (ObjectUtil.isEmpty(passLetterDetail.getPassCode())) {
DateTime createTime = DateUtil.date();
String code = passLetterDetail.getPassCode() == null ? PassLetterUtils.genPassCode(createTime) : passLetterDetail.getPassCode();
ByteArrayOutputStream outputStream = PassLetterUtils.genPassLetter(passLetterDetail.getPartnerName(), code, passLetterDetail.getVerifyCity(), createTime);
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
String passFileUrl = ossServer.uploadFileServer(inputStream, "partner/passLetter/" + code + ".pdf");
//计算有效期截至日期
DateTime expiryDate = DateUtil.offsetDay(createTime, 60);
String expiryDateStr = DateUtil.format(expiryDate, "yyyy-MM-dd") + " 23:59:59";
interviewMapper.updatePassLetterInfo(code, passFileUrl, expiryDateStr, interviewId);
}
return passLetterDetail.getPassCode();
}
}