Commit b06c404d by 涂亚平

人社局测试

1 parent 27a4934c
...@@ -11,9 +11,11 @@ import com.subsidy.common.exception.HttpException; ...@@ -11,9 +11,11 @@ import com.subsidy.common.exception.HttpException;
import com.subsidy.mapper.AdministerMapper; import com.subsidy.mapper.AdministerMapper;
import com.subsidy.mapper.MemberMapper; import com.subsidy.mapper.MemberMapper;
import com.subsidy.mapper.MemberTokensMapper; import com.subsidy.mapper.MemberTokensMapper;
import com.subsidy.mapper.OprMemDictMapper;
import com.subsidy.model.AdministerDO; import com.subsidy.model.AdministerDO;
import com.subsidy.model.MemberDO; import com.subsidy.model.MemberDO;
import com.subsidy.model.MemberTokensDO; import com.subsidy.model.MemberTokensDO;
import com.subsidy.model.OprMemDictDO;
import com.subsidy.util.ConstantUtils; import com.subsidy.util.ConstantUtils;
import com.subsidy.util.JwtUtil; import com.subsidy.util.JwtUtil;
import com.subsidy.util.Localstorage; import com.subsidy.util.Localstorage;
...@@ -55,6 +57,9 @@ public class AuthenticationInterceptor implements HandlerInterceptor { ...@@ -55,6 +57,9 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
@Autowired @Autowired
private MemberTokensMapper memberTokensMapper; private MemberTokensMapper memberTokensMapper;
@Autowired
private OprMemDictMapper oprMemDictMapper;
@Override @Override
@CrossOrigin() @CrossOrigin()
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
...@@ -67,13 +72,6 @@ public class AuthenticationInterceptor implements HandlerInterceptor { ...@@ -67,13 +72,6 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
Method method = handlerMethod.getMethod(); Method method = handlerMethod.getMethod();
TimeRequired timeRequired = method.getAnnotation(TimeRequired.class); TimeRequired timeRequired = method.getAnnotation(TimeRequired.class);
if (timeRequired !=null){
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
if (hour<6){
throw new HttpException(17001);
}
}
LoginRequired methodAnnotation = method.getAnnotation(LoginRequired.class); LoginRequired methodAnnotation = method.getAnnotation(LoginRequired.class);
if (methodAnnotation != null) { if (methodAnnotation != null) {
...@@ -100,6 +98,19 @@ public class AuthenticationInterceptor implements HandlerInterceptor { ...@@ -100,6 +98,19 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
} }
} else if(ConstantUtils.MOBILE_TERMINATE.equals(type)) { } else if(ConstantUtils.MOBILE_TERMINATE.equals(type)) {
MemberDO memberDO = memberMapper.selectById(claimMap.get("id").asLong()); MemberDO memberDO = memberMapper.selectById(claimMap.get("id").asLong());
if (timeRequired !=null){
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
if (hour<6){
OprMemDictDO oprMemDictDO = new OprMemDictDO();
oprMemDictDO.setUserId(memberDO.getId());
oprMemDictDO.setOprType("登出");
oprMemDictDO.setResult(1);
oprMemDictMapper.insert(oprMemDictDO);
throw new HttpException(17001);
}
}
if(memberDO != null) { if(memberDO != null) {
Localstorage.setUser(memberDO); Localstorage.setUser(memberDO);
return true; return true;
......
package com.subsidy.jobs; package com.subsidy.jobs;
import com.alibaba.fastjson.JSONObject;
import com.subsidy.common.ResponseData;
import com.subsidy.service.RenSheJuService; import com.subsidy.service.RenSheJuService;
import com.subsidy.service.RenshejuHistoryService; import com.subsidy.service.RenshejuHistoryService;
import com.subsidy.service.impl.RenshejuHistoryServiceImpl; import com.subsidy.service.impl.RenshejuHistoryServiceImpl;
import com.subsidy.util.websocket.WebSocketUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* 人社局数据对接 * 人社局数据对接
...@@ -83,5 +89,12 @@ public class RenSheJuJob { ...@@ -83,5 +89,12 @@ public class RenSheJuJob {
// renSheJuService.getErrorClass(); // renSheJuService.getErrorClass();
// } // }
@Scheduled(cron = "00 58 23 * * ?")
public void cancelLogin()throws IOException{
ConcurrentHashMap<Long, WebSocketSession> webSocketMap = WebSocketUtil.webSocketMap;
for (Long key : webSocketMap.keySet()){
webSocketMap.get(key).sendMessage(new TextMessage(JSONObject.toJSONString(ResponseData.generateCreatedResponse(17001))));
}
}
} }
...@@ -98,7 +98,7 @@ public interface RenSheJuMapper { ...@@ -98,7 +98,7 @@ public interface RenSheJuMapper {
List<Long> checkClassIds(); List<Long> checkClassIds();
/** /**
* 查看某个班级的成员做过的人脸识别记录 * 查看某个班级的成员做过的人脸识别记录 弃用
*/ */
List<ClassImageChecksVO> classImageChecks(Long classId); List<ClassImageChecksVO> classImageChecks(Long classId);
...@@ -107,5 +107,9 @@ public interface RenSheJuMapper { ...@@ -107,5 +107,9 @@ public interface RenSheJuMapper {
*/ */
List<ClassImageChecksVO> passExamCheck(Long classId); List<ClassImageChecksVO> passExamCheck(Long classId);
/**
* 进入到课程第二次做人脸识别
*/
List<ClassImageChecksVO> studyCheck(Long classId);
} }
...@@ -1157,6 +1157,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple ...@@ -1157,6 +1157,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
return polyvInfoVO; return polyvInfoVO;
} }
@Transactional(rollbackFor = Exception.class)
public String logout(MemberDO memberDO) { public String logout(MemberDO memberDO) {
memberTokensMapper.delete(new QueryWrapper<MemberTokensDO>() memberTokensMapper.delete(new QueryWrapper<MemberTokensDO>()
.lambda() .lambda()
......
package com.subsidy.service.impl; package com.subsidy.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.configure.RenSheConfig; import com.subsidy.common.configure.RenSheConfig;
import com.subsidy.dto.renshe.*; import com.subsidy.dto.renshe.*;
import com.subsidy.mapper.ClassDictMapper; import com.subsidy.mapper.ClassDictMapper;
import com.subsidy.mapper.ImageCheckRecordMapper;
import com.subsidy.mapper.RenSheJuMapper; import com.subsidy.mapper.RenSheJuMapper;
import com.subsidy.mapper.RenshejuHistoryMapper; import com.subsidy.mapper.RenshejuHistoryMapper;
import com.subsidy.model.ClassDictDO; import com.subsidy.model.*;
import com.subsidy.model.ExerciseDoneResultDO;
import com.subsidy.model.OprMemDictDO;
import com.subsidy.model.RenshejuHistoryDO;
import com.subsidy.service.RenSheJuService; import com.subsidy.service.RenSheJuService;
import com.subsidy.util.OSSUtils; import com.subsidy.util.OSSUtils;
import com.subsidy.util.RenSheJuConstant; import com.subsidy.util.RenSheJuConstant;
...@@ -43,6 +42,7 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -43,6 +42,7 @@ public class RenSheJuServiceImpl implements RenSheJuService {
RenshejuHistoryMapper renshejuHistoryMapper; RenshejuHistoryMapper renshejuHistoryMapper;
public RensheResponseVO classBaseInfo() throws IOException { public RensheResponseVO classBaseInfo() throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
.build(); .build();
MediaType mediaType = MediaType.parse("application/json"); MediaType mediaType = MediaType.parse("application/json");
...@@ -55,50 +55,72 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -55,50 +55,72 @@ public class RenSheJuServiceImpl implements RenSheJuService {
//查找前一天产生数据的班级 //查找前一天产生数据的班级
List<Long> classIds = renSheJuMapper.newClasses(); List<Long> classIds = renSheJuMapper.newClasses();
for (Long classId : classIds) { try {
EpidemicSituationClassBasic epidemicSituationClassBasic = new EpidemicSituationClassBasic(); if (classIds.size() > 0) {
//班级基本信息 for (Long classId : classIds) {
ClassBaseInfoVO classBaseInfoVO = renSheJuMapper.classBaseInfo(classId); EpidemicSituationClassBasic epidemicSituationClassBasic = new EpidemicSituationClassBasic();
BeanUtils.copyProperties(classBaseInfoVO, epidemicSituationClassBasic); //班级基本信息
epidemicSituationClassBasic.setDownCode(classBaseInfoVO.getDownCode()); ClassBaseInfoVO classBaseInfoVO = renSheJuMapper.classBaseInfo(classId);
BeanUtils.copyProperties(classBaseInfoVO, epidemicSituationClassBasic);
//章节 epidemicSituationClassBasic.setDownCode(classBaseInfoVO.getDownCode());
List<ChapterList2> chapterLists = renSheJuMapper.classChapters(classId);
ChapterList2 chapterList2 = chapterLists.get(chapterLists.size() - 1); //章节
chapterList2.setIsExam(1); List<ChapterList2> chapterLists = renSheJuMapper.classChapters(classId);
epidemicSituationClassBasic.setChapterList(chapterLists); ChapterList2 chapterList2 = chapterLists.get(chapterLists.size() - 1);
chapterList2.setIsExam(1);
//学员列表 epidemicSituationClassBasic.setChapterList(chapterLists);
List<MemberVO> memberVOS = renSheJuMapper.classMembers(classId);
epidemicSituationClassBasic.setStudentList(memberVOS); //学员列表
List<MemberVO> memberVOS = renSheJuMapper.classMembers(classId);
epidemicSituationClassBasics.add(epidemicSituationClassBasic); epidemicSituationClassBasic.setStudentList(memberVOS);
epidemicSituationClassBasics.add(epidemicSituationClassBasic);
}
classBaseInfoDTO.setEpidemicSituationClassBasic(epidemicSituationClassBasics);
System.out.println(JSONObject.fromObject(classBaseInfoDTO).toString());
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(classBaseInfoDTO).toString());
Request request = new Request.Builder()
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadClass")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_2);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classBaseInfoDTO).toString());
if (200 == response.code()) {
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
} else {
renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
}
renshejuHistoryMapper.insert(renshejuHistoryDO);
return rensheResponseVO;
} else {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_2);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classBaseInfoDTO).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.NO_DATA);
renshejuHistoryMapper.insert(renshejuHistoryDO);
return null;
}
} catch (Exception e) {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_2);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classBaseInfoDTO).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO);
} }
classBaseInfoDTO.setEpidemicSituationClassBasic(epidemicSituationClassBasics);
System.out.println(JSONObject.fromObject(classBaseInfoDTO).toString());
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(classBaseInfoDTO).toString());
// Request request = new Request.Builder()
// .url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadClass")
// .method("POST", body)
// .addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
// .addHeader("Content-Type", "application/json")
// .build();
// Response response = client.newCall(request).execute();
// RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
// RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
// renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_2);
// renshejuHistoryDO.setInputParam(JSONObject.fromObject(classBaseInfoDTO).toString());
// renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
// renshejuHistoryMapper.insert(renshejuHistoryDO);
// System.out.println(rensheResponseVO);
// return rensheResponseVO;
return null; return null;
} }
public RensheResponseVO classHourBehavior() throws IOException { public RensheResponseVO classHourBehavior() throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
.build(); .build();
MediaType mediaType = MediaType.parse("application/json"); MediaType mediaType = MediaType.parse("application/json");
...@@ -108,78 +130,95 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -108,78 +130,95 @@ public class RenSheJuServiceImpl implements RenSheJuService {
classHourBehaviorDTO.setPrivateKey(getSecret()); classHourBehaviorDTO.setPrivateKey(getSecret());
List<ClassHourBasic> classHourBasics = new ArrayList<>(); List<ClassHourBasic> classHourBasics = new ArrayList<>();
try {
//前一天新增视频学习数据的班级 //前一天新增视频学习数据的班级
List<DailyStudyInfoVO> dailyStudyInfoVOS = renSheJuMapper.dailyStudyInfo(); List<DailyStudyInfoVO> dailyStudyInfoVOS = renSheJuMapper.dailyStudyInfo();
for (DailyStudyInfoVO dailyStudyInfoVO : dailyStudyInfoVOS) { for (DailyStudyInfoVO dailyStudyInfoVO : dailyStudyInfoVOS) {
ClassHourBasic classHourBasic = new ClassHourBasic(); ClassHourBasic classHourBasic = new ClassHourBasic();
BeanUtils.copyProperties(dailyStudyInfoVO, classHourBasic); BeanUtils.copyProperties(dailyStudyInfoVO, classHourBasic);
classHourBasic.setDownCode(dailyStudyInfoVO.getDownCode()); classHourBasic.setDownCode(dailyStudyInfoVO.getDownCode());
//上线时间列表 //上线时间列表
//找到当天每次上线下线时间 //找到当天每次上线下线时间
//上线时间 //上线时间
List<OprMemDictDO> loginRecords = renSheJuMapper.loginRecords(dailyStudyInfoVO.getMemberId()); List<OprMemDictDO> loginRecords = renSheJuMapper.loginRecords(dailyStudyInfoVO.getMemberId());
//下线时间 //下线时间
List<OprMemDictDO> loginOutRecords = renSheJuMapper.loginOutRecords(dailyStudyInfoVO.getMemberId()); List<OprMemDictDO> loginOutRecords = renSheJuMapper.loginOutRecords(dailyStudyInfoVO.getMemberId());
List<LoginList> loginLists = new ArrayList<>(); List<LoginList> loginLists = new ArrayList<>();
for (int i = 0; i < loginRecords.size(); i++) { for (int i = 0; i < loginRecords.size(); i++) {
LoginList loginList = new LoginList(); LoginList loginList = new LoginList();
loginList.setIp(loginRecords.get(i).getIpAddress()); loginList.setIp(loginRecords.get(i).getIpAddress());
loginList.setStartTime(Timestamp.valueOf(loginRecords.get(i).getCreateDate()).getTime()); loginList.setStartTime(Timestamp.valueOf(loginRecords.get(i).getCreateDate()).getTime());
loginList.setEndTime(Timestamp.valueOf(loginOutRecords.get(i).getCreateDate()).getTime()); loginList.setEndTime(Timestamp.valueOf(loginOutRecords.get(i).getCreateDate()).getTime());
//查看这个人该时间段的学习记录 //查看这个人该时间段的学习记录
List<ChapterList3> chapterList3s = renSheJuMapper.dailyStudyRecords(dailyStudyInfoVO.getMemberId(), dailyStudyInfoVO.getDownCode(), loginRecords.get(0).getCreateDate().toString().replace("T", " "), loginOutRecords.get(i).getCreateDate().toString().replace("T", " ")); List<ChapterList3> chapterList3s = renSheJuMapper.dailyStudyRecords(dailyStudyInfoVO.getMemberId(), dailyStudyInfoVO.getDownCode(), loginRecords.get(0).getCreateDate().toString().replace("T", " "), loginOutRecords.get(i).getCreateDate().toString().replace("T", " "));
loginList.setChapterList(chapterList3s); if (chapterList3s.size() > 0) {
loginLists.add(loginList); loginList.setChapterList(chapterList3s);
} loginLists.add(loginList);
classHourBasic.setLoginList(loginLists); }
//活跃度列表
List<ActivityList> activityLists = new ArrayList<>();
List<DailyActivitiesVO> activityDetectionDOS = renSheJuMapper.dailyActivities(dailyStudyInfoVO.getDownCode(), dailyStudyInfoVO.getMemberId());
for (DailyActivitiesVO dailyActivitiesVO : activityDetectionDOS) {
ActivityList activityList = new ActivityList();
if (dailyActivitiesVO.getAccess() == 1) {
activityList.setAccess(0);
} else {
activityList.setAccess(1);
activityList.setErrorInfo(2);
} }
activityList.setActivityDetection(2); classHourBasic.setLoginList(loginLists);
activityList.setActivityTime(dailyActivitiesVO.getActivityTime());
activityLists.add(activityList); //活跃度列表
List<ActivityList> activityLists = new ArrayList<>();
List<DailyActivitiesVO> activityDetectionDOS = renSheJuMapper.dailyActivities(dailyStudyInfoVO.getDownCode(), dailyStudyInfoVO.getMemberId());
for (DailyActivitiesVO dailyActivitiesVO : activityDetectionDOS) {
ActivityList activityList = new ActivityList();
if (dailyActivitiesVO.getAccess() == 1) {
activityList.setAccess(0);
} else {
activityList.setAccess(1);
activityList.setErrorInfo(2);
}
if (0 == dailyActivitiesVO.getCheckType()) {
activityList.setActivityDetection(2);
} else {
activityList.setActivityDetection(1);
}
activityList.setActivityTime(dailyActivitiesVO.getActivityTime());
activityLists.add(activityList);
}
classHourBasic.setActivityList(activityLists);
classHourBasics.add(classHourBasic);
} }
classHourBasic.setActivityList(activityLists); classHourBehaviorDTO.setClassHourBasic(classHourBasics);
classHourBasics.add(classHourBasic); System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(classHourBehaviorDTO));
}
classHourBehaviorDTO.setClassHourBasic(classHourBasics);
System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(classHourBehaviorDTO)); RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(classHourBehaviorDTO).toString());
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(classHourBehaviorDTO).toString()); Request request = new Request.Builder()
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadClassHourBehavior")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Request request = new Request.Builder() RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadClassHourBehavior") RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
.method("POST", body) renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_3);
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)") renshejuHistoryDO.setInputParam(JSONObject.fromObject(classHourBehaviorDTO).toString());
.addHeader("Content-Type", "application/json") if (200 == response.code()) {
.build(); renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
Response response = client.newCall(request).execute(); } else {
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class); renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
if (null!=rensheResponseVO.getCtt()){ }
renshejuHistoryMapper.insert(renshejuHistoryDO);
return rensheResponseVO;
} catch (Exception e) {
e.printStackTrace();
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO(); RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_3); renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_3);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(classHourBehaviorDTO).toString()); renshejuHistoryDO.setInputParam(JSONObject.fromObject(classHourBehaviorDTO).toString());
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString()); renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO); renshejuHistoryMapper.insert(renshejuHistoryDO);
} }
System.out.println(rensheResponseVO); return null;
return rensheResponseVO;
} }
public RensheResponseVO uploadChapterBehavior() throws IOException { public RensheResponseVO uploadChapterBehavior() throws IOException {
...@@ -196,80 +235,102 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -196,80 +235,102 @@ public class RenSheJuServiceImpl implements RenSheJuService {
List<DailyExamBasicVO> dailyExamBasicVOS = renSheJuMapper.dailyExamBasic(); List<DailyExamBasicVO> dailyExamBasicVOS = renSheJuMapper.dailyExamBasic();
for (DailyExamBasicVO dailyExamBasicVO : dailyExamBasicVOS) { try {
if (dailyExamBasicVOS.size() > 0) {
//章节课程考试时间列表 for (DailyExamBasicVO dailyExamBasicVO : dailyExamBasicVOS) {
ChapterExamBasic chapterExamBasic = new ChapterExamBasic();
BeanUtils.copyProperties(dailyExamBasicVO, chapterExamBasic); //章节课程考试时间列表
chapterExamBasic.setDownCode(dailyExamBasicVO.getDownCode()); ChapterExamBasic chapterExamBasic = new ChapterExamBasic();
BeanUtils.copyProperties(dailyExamBasicVO, chapterExamBasic);
//最后一节课作为chapterCode chapterExamBasic.setDownCode(dailyExamBasicVO.getDownCode());
String vodId = renSheJuMapper.classVodName(dailyExamBasicVO.getDownCode());
chapterExamBasic.setChapterCode(vodId); //最后一节课作为chapterCode
String vodId = renSheJuMapper.classVodName(dailyExamBasicVO.getDownCode());
//考试活跃度列表 chapterExamBasic.setChapterCode(vodId);
List<ActivityList> activityLists = new ArrayList<>();
List<ExamActivitiesVO> activityDetectionDOS = renSheJuMapper.examActivities(dailyExamBasicVO.getDownCode(), dailyExamBasicVO.getMemberId()); //考试活跃度列表
for (ExamActivitiesVO dailyActivitiesVO : activityDetectionDOS) { List<ActivityList> activityLists = new ArrayList<>();
List<ExamActivitiesVO> activityDetectionDOS = renSheJuMapper.examActivities(dailyExamBasicVO.getDownCode(), dailyExamBasicVO.getMemberId());
for (ExamActivitiesVO dailyActivitiesVO : activityDetectionDOS) {
ActivityList activityList = new ActivityList();
if (null == dailyActivitiesVO.getAccess() || 0 == dailyActivitiesVO.getAccess()) {
activityList.setAccess(1);
activityList.setErrorInfo(1);
} else {
activityList.setAccess(0);
}
activityList.setActivityDetection(1);
activityList.setActivityTime(dailyActivitiesVO.getActivityTime());
activityLists.add(activityList);
}
chapterExamBasic.setActivityList(activityLists);
//考试时间列表
//上线时间
List<OprMemDictDO> loginRecords = renSheJuMapper.loginRecords(dailyExamBasicVO.getMemberId());
//下线时间
List<OprMemDictDO> loginOutRecords = renSheJuMapper.loginOutRecords(dailyExamBasicVO.getMemberId());
List<ExamList> examLists = new ArrayList<ExamList>();
for (int i = 0; i < loginRecords.size(); i++) {
//找到该时间段内的测评
List<ExerciseDoneResultDO> exerciseDoneResultDOS = renSheJuMapper.dailyExerciseDone(dailyExamBasicVO.getMemberId(), loginRecords.get(i).getCreateDate().toString().replace("T", " "), loginOutRecords.get(i).getCreateDate().toString().replace("T", " "));
for (ExerciseDoneResultDO exerciseDoneResultDO : exerciseDoneResultDOS) {
ExamList examList = new ExamList();
examList.setStartTime(Timestamp.valueOf(exerciseDoneResultDO.getStartDate()).getTime());
examList.setEndTime(Timestamp.valueOf(exerciseDoneResultDO.getCreateDate()).getTime());
examList.setIp(loginRecords.get(i).getIpAddress());
examLists.add(examList);
}
}
chapterExamBasic.setExamList(examLists);
chapterExamBasics.add(chapterExamBasic);
}
ActivityList activityList = new ActivityList(); uploadChapterBehaviorDTO.setChapterExamBasic(chapterExamBasics);
if (null == dailyActivitiesVO.getAccess() || 0 == dailyActivitiesVO.getAccess()) {
activityList.setAccess(1); System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(uploadChapterBehaviorDTO));
activityList.setErrorInfo(1);
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(uploadChapterBehaviorDTO).toString());
Request request = new Request.Builder()
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadChapterBehavior")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
System.out.println(rensheResponseVO);
// if (200==response.code()) {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadChapterBehaviorDTO).toString());
if (200 == response.code()) {
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
} else { } else {
activityList.setAccess(0); renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
}
activityList.setActivityDetection(1);
activityList.setActivityTime(dailyActivitiesVO.getActivityTime());
activityLists.add(activityList);
}
chapterExamBasic.setActivityList(activityLists);
//考试时间列表
//上线时间
List<OprMemDictDO> loginRecords = renSheJuMapper.loginRecords(dailyExamBasicVO.getMemberId());
//下线时间
List<OprMemDictDO> loginOutRecords = renSheJuMapper.loginOutRecords(dailyExamBasicVO.getMemberId());
List<ExamList> examLists = new ArrayList<ExamList>();
for (int i = 0; i < loginRecords.size(); i++) {
//找到该时间段内的测评
List<ExerciseDoneResultDO> exerciseDoneResultDOS = renSheJuMapper.dailyExerciseDone(dailyExamBasicVO.getMemberId(), loginRecords.get(i).getCreateDate().toString().replace("T", " "), loginOutRecords.get(i).getCreateDate().toString().replace("T", " "));
for (ExerciseDoneResultDO exerciseDoneResultDO : exerciseDoneResultDOS) {
ExamList examList = new ExamList();
examList.setStartTime(Timestamp.valueOf(exerciseDoneResultDO.getStartDate()).getTime());
examList.setEndTime(Timestamp.valueOf(exerciseDoneResultDO.getCreateDate()).getTime());
examList.setIp(loginRecords.get(i).getIpAddress());
examLists.add(examList);
} }
renshejuHistoryMapper.insert(renshejuHistoryDO);
// }
return rensheResponseVO;
} else {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadChapterBehaviorDTO).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.NO_DATA);
renshejuHistoryMapper.insert(renshejuHistoryDO);
return null;
} }
chapterExamBasic.setExamList(examLists); } catch (Exception e) {
chapterExamBasics.add(chapterExamBasic);
}
uploadChapterBehaviorDTO.setChapterExamBasic(chapterExamBasics);
System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(uploadChapterBehaviorDTO));
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(uploadChapterBehaviorDTO).toString());
Request request = new Request.Builder()
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadChapterBehavior")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
System.out.println(rensheResponseVO);
if (null!=rensheResponseVO.getCtt()){
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO(); RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4); renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_4);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadChapterBehaviorDTO).toString()); renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadChapterBehaviorDTO).toString());
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString()); renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO); renshejuHistoryMapper.insert(renshejuHistoryDO);
} }
return rensheResponseVO; return null;
} }
public RensheResponseVO uploadClassAnswerQuestionBehavior() throws IOException { public RensheResponseVO uploadClassAnswerQuestionBehavior() throws IOException {
...@@ -285,59 +346,79 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -285,59 +346,79 @@ public class RenSheJuServiceImpl implements RenSheJuService {
List<DailyAnswerVO> dailyAnswerVOS = renSheJuMapper.dailyAnswer(); List<DailyAnswerVO> dailyAnswerVOS = renSheJuMapper.dailyAnswer();
HashMap<String, List<AnswerAndQuestionList>> hashMap = new HashMap<>(); try {
for (DailyAnswerVO dailyAnswerVO : dailyAnswerVOS) { if (dailyAnswerVOS.size() > 0) {
HashMap<String, List<AnswerAndQuestionList>> hashMap = new HashMap<>();
for (DailyAnswerVO dailyAnswerVO : dailyAnswerVOS) {
if (!hashMap.containsKey(dailyAnswerVO.getDownCode() + ":" + dailyAnswerVO.getIdentity())) {
List<AnswerAndQuestionList> answerAndQuestionLists = new ArrayList<>();
AnswerAndQuestionList answerAndQuestionList = new AnswerAndQuestionList();
answerAndQuestionList.setAnswer(dailyAnswerVO.getAnswer());
answerAndQuestionList.setQuestion(dailyAnswerVO.getQuestion());
answerAndQuestionLists.add(answerAndQuestionList);
hashMap.put(dailyAnswerVO.getDownCode() + ":" + dailyAnswerVO.getIdentity(), answerAndQuestionLists);
} else {
List<AnswerAndQuestionList> answerAndQuestionLists = hashMap.get(dailyAnswerVO.getDownCode() + ":" + dailyAnswerVO.getIdentity());
AnswerAndQuestionList answerAndQuestionList = new AnswerAndQuestionList();
answerAndQuestionList.setAnswer(dailyAnswerVO.getAnswer());
answerAndQuestionList.setQuestion(dailyAnswerVO.getQuestion());
answerAndQuestionLists.add(answerAndQuestionList);
hashMap.put(dailyAnswerVO.getDownCode() + ":" + dailyAnswerVO.getIdentity(), answerAndQuestionLists);
}
}
if (!hashMap.containsKey(dailyAnswerVO.getDownCode() + ":" + dailyAnswerVO.getIdentity())) { List<AnswerBasic> answerBasics = new ArrayList<>();
List<AnswerAndQuestionList> answerAndQuestionLists = new ArrayList<>();
AnswerAndQuestionList answerAndQuestionList = new AnswerAndQuestionList();
answerAndQuestionList.setAnswer(dailyAnswerVO.getAnswer());
answerAndQuestionList.setQuestion(dailyAnswerVO.getQuestion());
answerAndQuestionLists.add(answerAndQuestionList);
hashMap.put(dailyAnswerVO.getDownCode() + ":" + dailyAnswerVO.getIdentity(), answerAndQuestionLists);
} else {
List<AnswerAndQuestionList> answerAndQuestionLists = hashMap.get(dailyAnswerVO.getDownCode() + ":" + dailyAnswerVO.getIdentity());
AnswerAndQuestionList answerAndQuestionList = new AnswerAndQuestionList();
answerAndQuestionList.setAnswer(dailyAnswerVO.getAnswer());
answerAndQuestionList.setQuestion(dailyAnswerVO.getQuestion());
answerAndQuestionLists.add(answerAndQuestionList);
hashMap.put(dailyAnswerVO.getDownCode() + ":" + dailyAnswerVO.getIdentity(), answerAndQuestionLists);
}
}
List<AnswerBasic> answerBasics = new ArrayList<>(); for (String key : hashMap.keySet()) {
AnswerBasic answerBasic = new AnswerBasic();
String downCode = key.split(":")[0];
String identity = key.split(":")[1];
answerBasic.setDownCode(downCode);
answerBasic.setIdentity(identity);
answerBasic.setAnswerAndQuestionList(hashMap.get(key));
answerBasics.add(answerBasic);
}
for (String key : hashMap.keySet()) { uploadClassAnswerQuestionBehaviorDTO.setAnswerBasic(answerBasics);
AnswerBasic answerBasic = new AnswerBasic(); System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(uploadClassAnswerQuestionBehaviorDTO));
String downCode = key.split(":")[0]; RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(uploadClassAnswerQuestionBehaviorDTO).toString());
String identity = key.split(":")[1]; Request request = new Request.Builder()
answerBasic.setDownCode(downCode); .url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadClassAnswerQuestionBehavior")
answerBasic.setIdentity(identity); .method("POST", body)
answerBasic.setAnswerAndQuestionList(hashMap.get(key)); .addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
answerBasics.add(answerBasic); .addHeader("Content-Type", "application/json")
} .build();
Response response = client.newCall(request).execute();
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
System.out.println(rensheResponseVO);
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_5);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadClassAnswerQuestionBehaviorDTO).toString());
if (200 == response.code()) {
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
} else {
renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
}
renshejuHistoryMapper.insert(renshejuHistoryDO);
uploadClassAnswerQuestionBehaviorDTO.setAnswerBasic(answerBasics); return rensheResponseVO;
System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(uploadClassAnswerQuestionBehaviorDTO)); } else {
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(uploadClassAnswerQuestionBehaviorDTO).toString()); RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
Request request = new Request.Builder() renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_5);
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadClassAnswerQuestionBehavior") renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadClassAnswerQuestionBehaviorDTO).toString());
.method("POST", body) renshejuHistoryDO.setOutputParam(RenSheJuConstant.NO_DATA);
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)") renshejuHistoryMapper.insert(renshejuHistoryDO);
.addHeader("Content-Type", "application/json") return null;
.build(); }
Response response = client.newCall(request).execute(); } catch (Exception e) {
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
System.out.println(rensheResponseVO);
if (null!=rensheResponseVO.getCtt()){
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO(); RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_5); renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_5);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadClassAnswerQuestionBehaviorDTO).toString()); renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadClassAnswerQuestionBehaviorDTO).toString());
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString()); renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO); renshejuHistoryMapper.insert(renshejuHistoryDO);
} }
return null;
return rensheResponseVO;
} }
public List<RensheResponseVO> uploadImage() throws IOException { public List<RensheResponseVO> uploadImage() throws IOException {
...@@ -357,52 +438,59 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -357,52 +438,59 @@ public class RenSheJuServiceImpl implements RenSheJuService {
uploadImage.setPrivateKey(getSecret()); uploadImage.setPrivateKey(getSecret());
uploadImage.setDownCode(String.valueOf(classId)); uploadImage.setDownCode(String.valueOf(classId));
// //查找班级下所有人做过的实名认证记录 // //查找班级下所有人做过的实名认证记录
List<ClassImageChecksVO> classImageChecksVOS = renSheJuMapper.classImageChecks(classId); // List<ClassImageChecksVO> classImageChecksVOS = renSheJuMapper.classImageChecks(classId);
List<ImageDetailList> imageDetailLists = new ArrayList<ImageDetailList>(); List<ImageDetailList> imageDetailLists = new ArrayList<ImageDetailList>();
// try {
for (ClassImageChecksVO classImageChecksVO : classImageChecksVOS) { /**
ImageDetailList imageDetailList = new ImageDetailList(); * 第二次人脸识别
BeanUtils.copyProperties(classImageChecksVO, imageDetailList); */
imageDetailList.setImageBase64(OSSUtils.image2Base64(classImageChecksVO.getImage())); List<ClassImageChecksVO> classImageChecksVOS2 = renSheJuMapper.studyCheck(classId);
imageDetailList.setProcessType(0L);
imageDetailList.setDetectionType(0L); if (classImageChecksVOS2.size() > 0) {
imageDetailLists.add(imageDetailList); for (ClassImageChecksVO cicon : classImageChecksVOS2) {
} ImageDetailList imageDetailList = new ImageDetailList();
BeanUtils.copyProperties(cicon, imageDetailList);
//查找前一天做过考试验证的记录 imageDetailList.setImageBase64("data:image/jpeg;base64," + OSSUtils.image2Base64(cicon.getImage()));
List<ClassImageChecksVO> classImageChecksVOS1 = renSheJuMapper.passExamCheck(classId); imageDetailList.setProcessType(0L);
imageDetailList.setDetectionType(0L);
for (ClassImageChecksVO cic : classImageChecksVOS1) { imageDetailLists.add(imageDetailList);
ImageDetailList imageDetailList = new ImageDetailList(); }
BeanUtils.copyProperties(cic, imageDetailList);
imageDetailList.setImageBase64(OSSUtils.image2Base64(cic.getImage())); uploadImage.setImageDetailList(imageDetailLists);
imageDetailList.setProcessType(2L); System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(uploadImage));
imageDetailList.setDetectionType(1L); RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(uploadImage).toString());
imageDetailLists.add(imageDetailList); Request request = new Request.Builder()
} .url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadImage")
.method("POST", body)
uploadImage.setImageDetailList(imageDetailLists); .addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(uploadImage)); .addHeader("Content-Type", "application/json")
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(uploadImage).toString()); .build();
Request request = new Request.Builder() Response response = client.newCall(request).execute();
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadImage") RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)") RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
.addHeader("Content-Type", "application/json") renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_6);
.build(); renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadImage).toString());
Response response = client.newCall(request).execute(); renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
RensheResponseVO rensheResponseVO= JSON.parseObject(response.body().string(), RensheResponseVO.class); renshejuHistoryMapper.insert(renshejuHistoryDO);
rensheResponseVOS.add(rensheResponseVO);
if (null!=rensheResponseVO.getCtt()){ } else {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_6);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadImage).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.NO_DATA);
renshejuHistoryMapper.insert(renshejuHistoryDO);
}
} catch (Exception e) {
e.printStackTrace();
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO(); RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_6); renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_6);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadImage).toString()); renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadImage).toString());
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString()); renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO); renshejuHistoryMapper.insert(renshejuHistoryDO);
} }
System.out.println(rensheResponseVO); // System.out.println(rensheResponseVO);
rensheResponseVOS.add(rensheResponseVO);
} }
return rensheResponseVOS; return rensheResponseVOS;
...@@ -421,19 +509,30 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -421,19 +509,30 @@ public class RenSheJuServiceImpl implements RenSheJuService {
.method("POST", body) .method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)") .addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
.build(); .build();
Response response = client.newCall(request).execute(); try {
System.out.println(response); Response response = client.newCall(request).execute();
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class); RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
System.out.println(rensheResponseVO);
if (null!=rensheResponseVO.getCtt()){
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO(); RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_7); renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_7);
renshejuHistoryDO.setInputParam(getSecret()); renshejuHistoryDO.setInputParam(getSecret());
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString()); if (200 == response.code()) {
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
} else {
renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
}
renshejuHistoryMapper.insert(renshejuHistoryDO);
return rensheResponseVO;
} catch (Exception e) {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_7);
renshejuHistoryDO.setInputParam(getSecret());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO); renshejuHistoryMapper.insert(renshejuHistoryDO);
} }
return rensheResponseVO; return null;
} }
public RensheResponseVO uploadClassCode() throws IOException { public RensheResponseVO uploadClassCode() throws IOException {
...@@ -460,26 +559,36 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -460,26 +559,36 @@ public class RenSheJuServiceImpl implements RenSheJuService {
uploadClassCodeDTO.setClassCodeBasic(classCodeBasics); uploadClassCodeDTO.setClassCodeBasic(classCodeBasics);
System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(uploadClassCodeDTO)); System.out.println(com.alibaba.fastjson.JSONObject.toJSONString(uploadClassCodeDTO));
try {
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(uploadClassCodeDTO).toString());
Request request = new Request.Builder()
.url(renSheConfig.getUrl() + "/import/downstream/enterprise/uploadClassCode")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
System.out.println(rensheResponseVO);
RequestBody body = RequestBody.create(mediaType, JSONObject.fromObject(uploadClassCodeDTO).toString());
Request request = new Request.Builder()
.url(renSheConfig.getUrl()+"/import/downstream/enterprise/uploadClassCode")
.method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
System.out.println(rensheResponseVO);
if (null!=rensheResponseVO.getCtt()){
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO(); RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_8); renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_8);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadClassCodeDTO).toString()); renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadClassCodeDTO).toString());
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString()); if (200 == response.code()) {
renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_SUCCESS);
} else {
renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
}
renshejuHistoryMapper.insert(renshejuHistoryDO);
return rensheResponseVO;
} catch (Exception e) {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_8);
renshejuHistoryDO.setInputParam(JSONObject.fromObject(uploadClassCodeDTO).toString());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO); renshejuHistoryMapper.insert(renshejuHistoryDO);
} }
return rensheResponseVO; return null;
} }
public RensheResponseVO getErrorClass() throws IOException { public RensheResponseVO getErrorClass() throws IOException {
...@@ -495,17 +604,28 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -495,17 +604,28 @@ public class RenSheJuServiceImpl implements RenSheJuService {
.method("POST", body) .method("POST", body)
.addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)") .addHeader("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)")
.build(); .build();
Response response = client.newCall(request).execute(); try {
RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class); Response response = client.newCall(request).execute();
System.out.println(rensheResponseVO); RensheResponseVO rensheResponseVO = JSON.parseObject(response.body().string(), RensheResponseVO.class);
if (null!=rensheResponseVO.getCtt()){ System.out.println(rensheResponseVO);
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO(); RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_9); renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_9);
renshejuHistoryDO.setInputParam(getSecret()); renshejuHistoryDO.setInputParam(getSecret());
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString()); if (200 == response.code()) {
renshejuHistoryDO.setOutputParam(rensheResponseVO.getCtt().toString());
} else {
renshejuHistoryDO.setOutputParam(RenSheJuConstant.API_ERROR);
}
renshejuHistoryMapper.insert(renshejuHistoryDO);
return rensheResponseVO;
} catch (Exception e) {
RenshejuHistoryDO renshejuHistoryDO = new RenshejuHistoryDO();
renshejuHistoryDO.setInterfaceName(RenSheJuConstant.POST_9);
renshejuHistoryDO.setInputParam(getSecret());
renshejuHistoryDO.setOutputParam(RenSheJuConstant.PUSH_FAIL);
renshejuHistoryMapper.insert(renshejuHistoryDO); renshejuHistoryMapper.insert(renshejuHistoryDO);
} }
return rensheResponseVO; return null;
} }
public RensheStringVO clear() throws IOException { public RensheStringVO clear() throws IOException {
...@@ -543,7 +663,6 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -543,7 +663,6 @@ public class RenSheJuServiceImpl implements RenSheJuService {
.build(); .build();
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
GetSecretVO getSecretVO = JSON.parseObject(response.body().string(), GetSecretVO.class); GetSecretVO getSecretVO = JSON.parseObject(response.body().string(), GetSecretVO.class);
System.out.println(getSecretVO);
return getSecretVO.getCtt().getPrivateKey(); return getSecretVO.getCtt().getPrivateKey();
} }
...@@ -565,7 +684,7 @@ public class RenSheJuServiceImpl implements RenSheJuService { ...@@ -565,7 +684,7 @@ public class RenSheJuServiceImpl implements RenSheJuService {
} }
public void test(){ public void test() {
System.out.println("132222222222222222222222222222"); System.out.println("132222222222222222222222222222");
} }
......
...@@ -47,5 +47,23 @@ public class RenSheJuConstant { ...@@ -47,5 +47,23 @@ public class RenSheJuConstant {
*/ */
public static final String POST_10 = "POST_10_clear"; public static final String POST_10 = "POST_10_clear";
/**
* 调取失败
*/
public static final String API_ERROR = "调取失败";
/**
* 当天没数据
*/
public static final String NO_DATA = "NO_DATA";
/**
* 推送失败
*/
public static final String PUSH_FAIL = "推送失败";
/**
* 推送成功
*/
public static final String PUSH_SUCCESS = "推送成功";
} }
package com.subsidy.util.websocket;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ServerHandshake;
import javax.net.ssl.*;
import java.net.Socket;
import java.net.URI;
import java.nio.ByteBuffer;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
/** @Author huyi @Date 2021/10/15 20:03 @Description: 重连websocket客户端 */
@Slf4j
public class ReConnectWebSocketClient {
/** 字符串消息回调 */
private Consumer<String> msgStr;
/** 字节流消息回调 */
private Consumer<ByteBuffer> msgByte;
/** 异常回调 */
private Consumer<Exception> error;
/** 连接标识 */
private String key;
/** ws服务端连接 */
private URI serverUri;
/** 尝试重连标识 */
private AtomicBoolean tryReconnect;
/** 需要ping标识 */
private AtomicBoolean needPing;
/** websocket连接实体 */
private WebSocketClient webSocketClient;
/** 重连次数 */
private AtomicInteger reConnectTimes;
/** 连接结束标识 */
private AtomicBoolean end;
/** 连接后初始发送报文,这里也可以不需要,如果服务端主动断开连接,重连后可以继续推送报文的话。 */
private String initReConnectReq;
/** 结束回调 */
private Consumer<String> endConsumer;
public ReConnectWebSocketClient(
URI serverUri,
String key,
Consumer<String> msgStr,
Consumer<ByteBuffer> msgByte,
Consumer<Exception> error) {
this.msgStr = msgStr;
this.msgByte = msgByte;
this.error = error;
this.key = key;
this.serverUri = serverUri;
this.tryReconnect = new AtomicBoolean(false);
this.needPing = new AtomicBoolean(true);
this.reConnectTimes = new AtomicInteger(0);
this.end = new AtomicBoolean(false);
this.endConsumer = this::close;
init();
}
/** 初始化连接 */
public void init() {
// 创建连接
createWebSocketClient();
// ping线程
circlePing();
}
private void needReconnect() throws Exception {
ThreadUtil.sleep(10, TimeUnit.SECONDS);
int cul = reConnectTimes.incrementAndGet();
if (cul > 3) {
close("real stop");
throw new Exception("服务端断连,3次重连均失败");
}
log.warn("[{}]第[{}]次断开重连", key, cul);
if (tryReconnect.get()) {
log.error("[{}]第[{}]次断开重连结果 -> 连接正在重连,本次重连请求放弃", key, cul);
needReconnect();
return;
}
try {
tryReconnect.set(true);
if (webSocketClient.isOpen()) {
log.warn("[{}]第[{}]次断开重连,关闭旧连接", key, cul);
webSocketClient.closeConnection(2, "reconnect stop");
}
webSocketClient = null;
createWebSocketClient();
connect();
if (!StrUtil.hasBlank(initReConnectReq)) {
send(initReConnectReq);
}
} catch (Exception exception) {
log.error("[{}]第[{}]次断开重连结果 -> 连接正在重连,重连异常:[{}]", key, cul, exception.getMessage());
needReconnect();
} finally {
tryReconnect.set(false);
}
}
private void createWebSocketClient() {
webSocketClient =
new WebSocketClient(serverUri) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
log.info("[{}]ReConnectWebSocketClient [onOpen]连接成功{}", key, getRemoteSocketAddress());
tryReconnect.set(false);
}
@Override
public void onMessage(String text) {
log.info("[{}]ReConnectWebSocketClient [onMessage]接收到服务端数据:text={}", key, text);
msgStr.accept(text);
}
@Override
public void onMessage(ByteBuffer bytes) {
log.info("[{}]ReConnectWebSocketClient [onMessage]接收到服务端数据:bytes={}", key, bytes);
msgByte.accept(bytes);
}
@Override
public void onWebsocketPong(WebSocket conn, Framedata f) {
log.info(
"[{}]ReConnectWebSocketClient [onWebsocketPong]接收到服务端数据:opcode={}",
key,
f.getOpcode());
}
@Override
public void onClose(int i, String s, boolean b) {
log.info("[{}]ReConnectWebSocketClient [onClose]关闭,s={},b={}", key, s, b);
if (StrUtil.hasBlank(s) || s.contains("https")) {
if (end.get()) {
return;
}
try {
needReconnect();
} catch (Exception exception) {
endConsumer.accept("reconnect error");
error.accept(exception);
}
}
}
@Override
public void onError(Exception e) {
log.info("[{}]ReConnectWebSocketClient [onError]异常,e={}", key, e);
endConsumer.accept("error close");
error.accept(e);
}
};
if (serverUri.toString().contains("wss://")) {
trustAllHosts(webSocketClient);
}
}
public void circlePing() {
new Thread(
() -> {
while (needPing.get()) {
if (webSocketClient.isOpen()) {
webSocketClient.sendPing();
}
ThreadUtil.sleep(5, TimeUnit.SECONDS);
}
log.warn("[{}]Ping循环关闭", key);
})
.start();
}
/**
* 连接
*
* @throws Exception 异常
*/
public void connect() throws Exception {
webSocketClient.connectBlocking(10, TimeUnit.SECONDS);
}
/**
* 发送
*
* @param msg 消息
* @throws Exception 异常
*/
public void send(String msg) throws Exception {
this.initReConnectReq = msg;
if (webSocketClient.isOpen()) {
webSocketClient.send(msg);
}
}
/**
* 关闭
*
* @param msg 关闭消息
*/
public void close(String msg) {
needPing.set(false);
end.set(true);
if (webSocketClient != null) {
webSocketClient.closeConnection(3, msg);
}
}
/**
* 忽略证书
*
* @param client
*/
public void trustAllHosts(WebSocketClient client) {
TrustManager[] trustAllCerts =
new TrustManager[] {
new X509ExtendedTrustManager() {
@Override
public void checkClientTrusted(
X509Certificate[] x509Certificates, String s, Socket socket)
throws CertificateException {}
@Override
public void checkServerTrusted(
X509Certificate[] x509Certificates, String s, Socket socket)
throws CertificateException {}
@Override
public void checkClientTrusted(
X509Certificate[] x509Certificates, String s, SSLEngine sslEngine)
throws CertificateException {}
@Override
public void checkServerTrusted(
X509Certificate[] x509Certificates, String s, SSLEngine sslEngine)
throws CertificateException {}
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
throws CertificateException {}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s)
throws CertificateException {}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
};
try {
SSLContext ssl = SSLContext.getInstance("SSL");
ssl.init(null, trustAllCerts, new java.security.SecureRandom());
SSLSocketFactory socketFactory = ssl.getSocketFactory();
client.setSocketFactory(socketFactory);
} catch (Exception e) {
log.error("ReConnectWebSocketClient trustAllHosts 异常,e={0}", e);
}
}
}
\ No newline at end of file
...@@ -5,6 +5,10 @@ import lombok.Data; ...@@ -5,6 +5,10 @@ import lombok.Data;
@Data @Data
public class ClassImageChecksVO { public class ClassImageChecksVO {
Long classId;
Long memberId;
/** /**
* 检测时间,【13位时间戳】【精确到毫秒】如检测类型为活跃度检测则与【学时信息采集接口】、【考试信息采集接口】activityTime时间保持一致 * 检测时间,【13位时间戳】【精确到毫秒】如检测类型为活跃度检测则与【学时信息采集接口】、【考试信息采集接口】activityTime时间保持一致
*/ */
......
...@@ -9,5 +9,6 @@ public class DailyActivitiesVO { ...@@ -9,5 +9,6 @@ public class DailyActivitiesVO {
private Long activityTime; private Long activityTime;
private Integer checkType;
} }
...@@ -168,7 +168,8 @@ ...@@ -168,7 +168,8 @@
<select id="dailyActivities" resultType="com.subsidy.vo.renshe.DailyActivitiesVO"> <select id="dailyActivities" resultType="com.subsidy.vo.renshe.DailyActivitiesVO">
SELECT SELECT
t1.`status` as access, t1.`status` as access,
unix_timestamp( t1.create_date )*1000 as activityTime unix_timestamp( t1.create_date )*1000 as activityTime,
t1.check_type
FROM FROM
activity_detection t1 activity_detection t1
WHERE WHERE
...@@ -176,7 +177,6 @@ ...@@ -176,7 +177,6 @@
AND t1.delete_date IS NULL AND t1.delete_date IS NULL
AND t1.member_id = #{memberId} AND t1.member_id = #{memberId}
AND t1.class_id = #{classId} AND t1.class_id = #{classId}
and t1.check_type= 0
</select> </select>
<select id="examActivities" resultType="com.subsidy.vo.renshe.ExamActivitiesVO"> <select id="examActivities" resultType="com.subsidy.vo.renshe.ExamActivitiesVO">
...@@ -353,7 +353,7 @@ ...@@ -353,7 +353,7 @@
SELECT SELECT
distinct class_id distinct class_id
FROM FROM
class_member_mapping image_check_record
WHERE WHERE
delete_date IS NULL delete_date IS NULL
AND DATE_FORMAT( DATE_ADD( update_date, INTERVAL 1 DAY ), '%Y-%m-%d' ) = DATE_FORMAT( AND DATE_FORMAT( DATE_ADD( update_date, INTERVAL 1 DAY ), '%Y-%m-%d' ) = DATE_FORMAT(
...@@ -401,4 +401,27 @@ ...@@ -401,4 +401,27 @@
AND t1.result = 1 AND t1.result = 1
</select> </select>
<select id="studyCheck" parameterType="long" resultType="com.subsidy.vo.renshe.ClassImageChecksVO">
SELECT
t1.class_id,
t1.member_id,
t1.photo AS image,
t2.user_name AS studentName,
t2.id_card AS identity,
t2.telephone AS phone,
UNIX_TIMESTAMP( t1.create_date )* 1000 AS activityTime
FROM
image_check_record t1
LEFT JOIN member t2 ON t1.member_id = t2.id
WHERE
class_id = #{classId}
AND DATE_FORMAT( DATE_ADD( t1.create_date, INTERVAL 1 DAY ), '%Y-%m-%d' ) = DATE_FORMAT( NOW(), '%Y-%m-%d' )
AND t1.paper_id IS NULL
AND t1.result = 1
and t1.member_id
GROUP BY t1.class_id,t1.member_id
ORDER BY t1.create_date desc
</select>
</mapper> </mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!