Commit 421d9309 by 涂亚平

人脸识别版本备个份

1 parent 6b16f6de
......@@ -43,14 +43,14 @@ public class ImageCheckRecordController {
}
@PostMapping("imageCheck")
@ApiOperation("课程/测评人身核验(权威库:身份证) PC端 id 用户id classId 班级id ")
@ApiOperation("课程/测评人身核验(权威库:身份证) PC端 id 用户id classId 班级id classPlace 1:视频的时候检测 2:测评的时候检测 paperId")
@TimeRequired
public ResponseVO imageCheck(@RequestBody ImageCheckDTO imageCheckDTO) throws Exception {
return ResponseData.generateCreatedResponse(0, imageCheckRecordService.imageCheck(imageCheckDTO));
}
@PostMapping("h5ImageCheck")
@ApiOperation("课程/测评人脸核验(权威库:身份证) 微信浮层H5 id 用户id classId 班级id")
@ApiOperation("课程/测评人脸核验(权威库:身份证) 微信浮层H5 id 用户id classId 班级id classPlace 1:视频的时候检测 2:测评的时候检测 paperId")
@TimeRequired
public ResponseVO h5CheckResult(@RequestBody ImageCheckDTO imageCheckDTO)throws Exception{
return ResponseData.generateCreatedResponse(0,imageCheckRecordService.h5CheckResult(imageCheckDTO));
......@@ -64,7 +64,7 @@ public class ImageCheckRecordController {
}
@PostMapping("h5LoginCheck")
@ApiOperation("签到页做人脸核验 (权威库:身份证) PC端 id 用户id")
@ApiOperation("签到页做人脸核验 (权威库:身份证) id 用户id")
@TimeRequired
public ResponseVO h5LoginCheck(@RequestBody ImageCheckDTO imageCheckDTO)throws Exception{
return ResponseData.generateCreatedResponse(0,imageCheckRecordService.h5LoginCheck(imageCheckDTO));
......
......@@ -15,4 +15,14 @@ public class ImageCheckDTO {
*/
private Long classId;
/**
* 试卷id
*/
private Long paperId;
/**
* 1:视频的时候检测 2:测评的时候检测
*/
private Integer classPlace;
}
......@@ -5,10 +5,7 @@ import com.subsidy.dto.classDict.GetSpareMembersDTO;
import com.subsidy.model.ClassDictDO;
import com.subsidy.model.MemberDO;
import com.subsidy.model.VodDictDO;
import com.subsidy.vo.classdict.ClassAndCompanyInfoVO;
import com.subsidy.vo.classdict.ClassSettingsVO;
import com.subsidy.vo.classdict.GetAllClassesVO;
import com.subsidy.vo.classdict.GetClassBaseInfoVO;
import com.subsidy.vo.classdict.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
......@@ -59,4 +56,9 @@ public interface ClassDictMapper extends BaseMapper<ClassDictDO> {
Integer getClassCount();
List<ClassSettingsVO> getClassSettings(@Param("userId") Long userId);
/**
* 通过班级id查看公司配置
*/
SystemSettings getCompanySettings(Long classId);
}
......@@ -24,4 +24,9 @@ public interface ImageCheckRecordMapper extends BaseMapper<ImageCheckRecordDO> {
*/
List<GetMemberCheckDetailVO> getMemberCheckDetail(Long memberId, Long classId);
/**
* 查看某个人某个课程当天做了几次人脸识别
*/
int checkDailyCount(Long memberId,Long classId,Integer checkPlace,Long paperId);
}
......@@ -7,6 +7,7 @@ import com.subsidy.model.DepartmentDictDO;
import com.subsidy.model.MemberDO;
import com.subsidy.vo.administer.ManageMemberVO;
import com.subsidy.vo.administer.UserRoleVO;
import com.subsidy.vo.classdict.SystemSettings;
import com.subsidy.vo.member.GetAllVO;
import com.subsidy.vo.member.MyCoursesVO;
import com.subsidy.vo.member.StudyPageVO;
......@@ -76,5 +77,10 @@ public interface MemberMapper extends BaseMapper<MemberDO> {
*/
void removeCheckImage(Long id);
/**
* 通过人员id查询公司配置
*/
SystemSettings companySettings(Long memberId);
}
......@@ -23,4 +23,6 @@ public interface OprMemDictMapper extends BaseMapper<OprMemDictDO> {
List<OprMemDictDO> getRecordByDate();
OprMemDictDO getLatestLoginInfo(Long userId);
}
......@@ -31,6 +31,11 @@ public class ImageCheckRecordDO extends BaseModel {
private Long classId;
/**
* 试卷id
*/
private Long paperId;
/**
* 成员id
*/
private Long memberId;
......@@ -70,5 +75,15 @@ public class ImageCheckRecordDO extends BaseModel {
*/
private Integer checkPlace;
/**
* 1:视频的时候检测 2:测评的时候检测
*/
private Integer classPlace;
/**
* 1 核对通过 0 核对不通过
*/
private Integer result;
}
......@@ -38,8 +38,8 @@ public class OprMemDictDO extends BaseModel {
private Integer result;
/**
* 登录ip
* 登录ip ==弃用字段
*/
private String ipAddress;
// private String ipAddress;
}
......@@ -40,6 +40,7 @@ import com.subsidy.util.websocket.WebSocketUtil;
import com.subsidy.vo.classdict.ClassSettingsVO;
import com.subsidy.vo.classdict.GetAllClassesVO;
import com.subsidy.vo.classdict.GetClassBaseInfoVO;
import com.subsidy.vo.classdict.SystemSettings;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -163,6 +164,9 @@ public class ClassDictServiceImpl extends ServiceImpl<ClassDictMapper, ClassDict
public String updateClass(ClassDictDO classDictDO) {
this.baseMapper.updateById(classDictDO);
//班级所在公司
SystemSettings systemSettings = this.baseMapper.getCompanySettings(classDictDO.getId());
List<ClassMemberMappingDO> list = classMemberMappingMapper.selectList(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getClassId, classDictDO.getId()));
......@@ -171,8 +175,10 @@ public class ClassDictServiceImpl extends ServiceImpl<ClassDictMapper, ClassDict
WebSocketSession webSocketSession = WebSocketUtil.webSocketMap.get(classMemberMappingDO.getMemberId());
if(null != webSocketSession && webSocketSession.isOpen()) {
try {
//班级的配置
List<ClassSettingsVO> classSettings = this.baseMapper.getClassSettings(classMemberMappingDO.getMemberId());
String data = JSONObject.toJSONString(ResponseData.generateCreatedResponse(0, classSettings), SerializerFeature.WriteMapNullValue);
systemSettings.setClassSettingsVOS(classSettings);
String data = JSONObject.toJSONString(ResponseData.generateCreatedResponse(0, systemSettings), SerializerFeature.WriteMapNullValue);
webSocketSession.sendMessage(new TextMessage(data));
} catch (Exception e) {
e.printStackTrace();
......
......@@ -39,6 +39,7 @@ import com.subsidy.util.VodUtil;
import com.subsidy.util.websocket.WebSocketUtil;
import com.subsidy.vo.administer.OperatorsVO;
import com.subsidy.vo.classdict.ClassSettingsVO;
import com.subsidy.vo.classdict.SystemSettings;
import com.subsidy.vo.company.CDNStatDetailsVO;
import com.subsidy.vo.company.DataOverviewVO;
import com.subsidy.vo.company.GetAllCompanyVO;
......@@ -293,6 +294,10 @@ public class CompanyDictServiceImpl extends ServiceImpl<CompanyDictMapper, Compa
public String updateCompanySettings(CompanyDictDO companyDictDO) {
this.baseMapper.updateById(companyDictDO);
CompanyDictDO companyDictDO1 = this.baseMapper.selectById(companyDictDO.getId());
SystemSettings systemSettings = new SystemSettings();
BeanUtils.copyProperties(companyDictDO1,systemSettings);
List<ClassMemberMappingDO> list = classMemberMappingMapper.getCLassMemberByCompanyId(companyDictDO.getId());
if(CollectionUtils.isNotEmpty(list)) {
for (ClassMemberMappingDO classMemberMappingDO : list) {
......@@ -300,7 +305,8 @@ public class CompanyDictServiceImpl extends ServiceImpl<CompanyDictMapper, Compa
if(null != webSocketSession && webSocketSession.isOpen()) {
try {
List<ClassSettingsVO> classSettings = classDictMapper.getClassSettings(classMemberMappingDO.getMemberId());
String data = JSONObject.toJSONString(ResponseData.generateCreatedResponse(0, classSettings), SerializerFeature.WriteMapNullValue);
systemSettings.setClassSettingsVOS(classSettings);
String data = JSONObject.toJSONString(ResponseData.generateCreatedResponse(0, systemSettings), SerializerFeature.WriteMapNullValue);
webSocketSession.sendMessage(new TextMessage(data));
} catch (Exception e) {
e.printStackTrace();
......
......@@ -14,9 +14,7 @@ import com.subsidy.model.AccessTokenDO;
import com.subsidy.model.ImageCheckRecordDO;
import com.subsidy.model.MemberDO;
import com.subsidy.service.ImageCheckRecordService;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.DateFormatUtil;
import com.subsidy.vo.image.CheckImageResultVO;
import com.subsidy.vo.token.*;
import org.apache.commons.codec.Charsets;
import org.apache.commons.lang3.StringUtils;
......@@ -24,15 +22,11 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Decoder;
import sun.security.krb5.internal.crypto.Nonce;
//import org.apache.commons.codec.binary.Base64;
import java.io.*;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//import org.apache.commons.codec.binary.Base64;
/**
* <p>
......@@ -72,19 +66,19 @@ public class ImageCheckRecordServiceImpl extends ServiceImpl<ImageCheckRecordMap
}
public SendIdCardInfoVO imageCheck(ImageCheckDTO imageCheckDTO) throws Exception {
return PCCheckIdCard(imageCheckDTO.getId(), imageCheckDTO.getClassId(), 0);
return PCCheckIdCard(imageCheckDTO.getId(), imageCheckDTO.getClassId(), 0,imageCheckDTO.getClassPlace(),imageCheckDTO.getPaperId());
}
public SendIdCardInfoVO h5CheckResult(ImageCheckDTO imageCheckDTO) throws Exception {
return H5IdCheckCard(imageCheckDTO.getId(), imageCheckDTO.getClassId(), 0);
return H5IdCheckCard(imageCheckDTO.getId(), imageCheckDTO.getClassId(), 0,imageCheckDTO.getClassPlace(),imageCheckDTO.getPaperId());
}
public SendIdCardInfoVO loginCheck(ImageCheckDTO imageCheckDTO) throws Exception {
return PCCheckIdCard(imageCheckDTO.getId(), null, 1);
return PCCheckIdCard(imageCheckDTO.getId(), null, 1,null,null);
}
public SendIdCardInfoVO h5LoginCheck(ImageCheckDTO imageCheckDTO) throws Exception {
return H5IdCheckCard(imageCheckDTO.getId(), imageCheckDTO.getClassId(), 1);
return H5IdCheckCard(imageCheckDTO.getId(), null, 1,null,null);
}
/**
......@@ -104,7 +98,7 @@ public class ImageCheckRecordServiceImpl extends ServiceImpl<ImageCheckRecordMap
* H5端调取权威库(身份证)验证 权威库
* 1,签到页 0 班级内
*/
public SendIdCardInfoVO H5IdCheckCard(Long id, Long classId, Integer checkPlace) {
public SendIdCardInfoVO H5IdCheckCard(Long id, Long classId, Integer checkPlace,Integer classPlace,Long paperId) {
getDailyCheckCnt(id);
//获取这个学生的基本信息
MemberDO memberDO = memberMapper.selectById(id);
......@@ -119,6 +113,8 @@ public class ImageCheckRecordServiceImpl extends ServiceImpl<ImageCheckRecordMap
imageCheckRecordDO.setClassId(classId);
imageCheckRecordDO.setCheckType(1);
imageCheckRecordDO.setCheckPlace(checkPlace);
imageCheckRecordDO.setPaperId(paperId);
imageCheckRecordDO.setClassPlace(classPlace);
imageCheckRecordMapper.insert(imageCheckRecordDO);
//获取signTicket
......@@ -169,7 +165,7 @@ public class ImageCheckRecordServiceImpl extends ServiceImpl<ImageCheckRecordMap
* PC端调取权威库(身份证)验证 权威库
* 1,签到页 0 班级内
*/
public SendIdCardInfoVO PCCheckIdCard(Long id, Long classId, Integer checkPlace) {
public SendIdCardInfoVO PCCheckIdCard(Long id, Long classId, Integer checkPlace,Integer classPlace,Long paperId) {
getDailyCheckCnt(id);
//获取这个学生的基本信息
......@@ -184,6 +180,8 @@ public class ImageCheckRecordServiceImpl extends ServiceImpl<ImageCheckRecordMap
imageCheckRecordDO.setClassId(classId);
imageCheckRecordDO.setCheckType(1);
imageCheckRecordDO.setCheckPlace(checkPlace);
imageCheckRecordDO.setPaperId(paperId);
imageCheckRecordDO.setClassPlace(classPlace);
imageCheckRecordMapper.insert(imageCheckRecordDO);
//获取signTicket
......@@ -210,8 +208,8 @@ public class ImageCheckRecordServiceImpl extends ServiceImpl<ImageCheckRecordMap
//获取 NONCE ticket
IdCardTicketsVO nonceTicket = this.nonceTicket(getLatestAccessToken(), memberDO.getId() + "");
//签名2
List<String> signList2 = new ArrayList(Arrays.asList(WBAPPID, memberDO.getId() + "", NONCE, "1.0.0", sendIdCardInfoVO.getResult().getFaceId(), sendIdCardInfoVO.getResult().getOrderNo()));
//签名2 faceId ===>H5FaceId
List<String> signList2 = new ArrayList(Arrays.asList(WBAPPID, memberDO.getId() + "", NONCE, "1.0.0", sendIdCardInfoVO.getResult().getH5faceId(), sendIdCardInfoVO.getResult().getOrderNo()));
String sign2 = sign(signList2, nonceTicket.getValue());
sendIdCardInfoVO.getResult().setWbAppId(WBAPPID);
......@@ -223,7 +221,6 @@ public class ImageCheckRecordServiceImpl extends ServiceImpl<ImageCheckRecordMap
public ImageCheckRecordDO checkResult(CheckResultDTO checkResultDTO) throws Exception {
CheckImageResultVO checkImageResultVO = new CheckImageResultVO();
//获取signTicket
IdCardTicketsVO idCardTicketsVO = this.signTickets(getLatestAccessToken());
......@@ -242,21 +239,26 @@ public class ImageCheckRecordServiceImpl extends ServiceImpl<ImageCheckRecordMap
//存数据库
ImageCheckRecordDO imageCheckRecordDO = imageCheckRecordMapper.selectById(checkResultDTO.getId());
BeanUtils.copyProperties(resultVO, imageCheckRecordDO);
imageCheckRecordMapper.updateById(imageCheckRecordDO);
BeanUtils.copyProperties(imageCheckRecordDO, checkImageResultVO);
try {
if ((Double.valueOf(imageCheckRecordDO.getSimilarity()) > 60)) {
imageCheckRecordDO.setResult(1);
//如果是签到页的认证,则把图片写到member表里
if (imageCheckRecordDO.getCheckPlace()==1){
MemberDO memberDO = memberMapper.selectById(imageCheckRecordDO.getMemberId());
memberDO.setImage(checkImageResultVO.getPhoto());
memberDO.setCheckImage(imageCheckRecordDO.getPhoto());
memberDO.setCheckTime(DateFormatUtil.format(new Date(), DateFormatUtil.FMT_sdf14_L));
memberMapper.updateById(memberDO);
if ((Double.valueOf(imageCheckRecordDO.getSimilarity()) > 60)) {
checkImageResultVO.setResult(true);
}
} else {
checkImageResultVO.setResult(false);
imageCheckRecordDO.setResult(0);
}
}catch (Exception e){
imageCheckRecordDO.setResult(0);
}
imageCheckRecordMapper.updateById(imageCheckRecordDO);
return imageCheckRecordDO;
}
......
......@@ -9,42 +9,8 @@ import com.subsidy.common.configure.QXueYouConfig;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.administer.VerifyCodeDTO;
import com.subsidy.dto.member.*;
import com.subsidy.mapper.ClassDictMapper;
import com.subsidy.mapper.ClassHourDictMapper;
import com.subsidy.mapper.ClassMemberMappingMapper;
import com.subsidy.mapper.CompanyDictMapper;
import com.subsidy.mapper.CourseContentMapper;
import com.subsidy.mapper.CourseFieldMappingMapper;
import com.subsidy.mapper.DepartmentDictMapper;
import com.subsidy.mapper.ExerciseDoneResultMapper;
import com.subsidy.mapper.FileDictMapper;
import com.subsidy.mapper.JobDictMapper;
import com.subsidy.mapper.JobMemberMappingMapper;
import com.subsidy.mapper.MemberDepartmentMappingMapper;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.mapper.OprMemDictMapper;
import com.subsidy.mapper.PaperDictMapper;
import com.subsidy.mapper.RotationImgDictMapper;
import com.subsidy.mapper.SmsVerifyCodeMapper;
import com.subsidy.mapper.VodDictMapper;
import com.subsidy.mapper.VodPlayHistoryMapper;
import com.subsidy.model.ClassDictDO;
import com.subsidy.model.ClassHourDictDO;
import com.subsidy.model.ClassMemberMappingDO;
import com.subsidy.model.CompanyDictDO;
import com.subsidy.model.CourseContentDO;
import com.subsidy.model.DepartmentDictDO;
import com.subsidy.model.ExerciseDoneResultDO;
import com.subsidy.model.FieldDictDO;
import com.subsidy.model.FileDictDO;
import com.subsidy.model.JobDictDO;
import com.subsidy.model.JobMemberMappingDO;
import com.subsidy.model.MemberDO;
import com.subsidy.model.MemberDepartmentMappingDO;
import com.subsidy.model.OprMemDictDO;
import com.subsidy.model.RotationImgDictDO;
import com.subsidy.model.SmsVerifyCodeDO;
import com.subsidy.model.VodDictDO;
import com.subsidy.mapper.*;
import com.subsidy.model.*;
import com.subsidy.service.MemberService;
import com.subsidy.util.*;
//import com.subsidy.util.RedisUtil;
......@@ -135,7 +101,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
private RotationImgDictMapper rotationImgDictMapper;
@Autowired
private VodDictMapper vodDictMapper;
private ImageCheckRecordMapper imageCheckRecordMapper;
@Autowired
private SmsVerifyCodeMapper smsVerifyCodeMapper;
......@@ -719,6 +685,21 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
for (MyCoursesVO myCoursesVO : myCoursesVOS) {
List<FieldDictDO> fieldDictDOS = courseFieldMappingMapper.courseFields(myCoursesVO.getCourseId());
myCoursesVO.setFieldDictDOS(fieldDictDOS);
int count = imageCheckRecordMapper.selectCount(new QueryWrapper<ImageCheckRecordDO>()
.lambda()
.eq(ImageCheckRecordDO::getMemberId, myCoursesDTO.getMemberId())
.eq(ImageCheckRecordDO::getClassId, myCoursesVO.getClassId())
.eq(ImageCheckRecordDO::getCheckPlace, 1)
.eq(ImageCheckRecordDO::getResult, 1));
int checkCnt = imageCheckRecordMapper.checkDailyCount(myCoursesDTO.getMemberId(), myCoursesVO.getClassId(), 1,null);
myCoursesVO.setCheckCnt(checkCnt);
if (count > 0) {
myCoursesVO.setResult(1);
} else {
myCoursesVO.setResult(0);
}
}
return myCoursesVOS;
}
......@@ -855,6 +836,23 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
} else {
queryPapersVO.setResult("待完成");
}
int count = imageCheckRecordMapper.selectCount(new QueryWrapper<ImageCheckRecordDO>()
.lambda()
.eq(ImageCheckRecordDO::getMemberId, contentMemberDTO.getMemberId())
.eq(ImageCheckRecordDO::getClassId, contentMemberDTO.getClassId())
.eq(ImageCheckRecordDO::getPaperId,queryPapersVO.getId())
.eq(ImageCheckRecordDO::getClassPlace, 2)
.eq(ImageCheckRecordDO::getResult, 1));
int checkCnt = imageCheckRecordMapper.checkDailyCount(contentMemberDTO.getMemberId(), contentMemberDTO.getClassId(), 2,queryPapersVO.getId());
queryPapersVO.setCheckCnt(checkCnt);
if (count > 0) {
queryPapersVO.setCheckResult(1);
} else {
queryPapersVO.setCheckResult(0);
}
//截止时间
queryPapersVO.setEndDate(classDictDO.getEndDate());
}
......
......@@ -5,10 +5,16 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.ResponseData;
import com.subsidy.mapper.ClassDictMapper;
import com.subsidy.mapper.CompanyDictMapper;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.mapper.OprMemDictMapper;
import com.subsidy.model.CompanyDictDO;
import com.subsidy.model.MemberDO;
import com.subsidy.model.OprMemDictDO;
import com.subsidy.util.DateFormatUtil;
import com.subsidy.vo.classdict.ClassSettingsVO;
import com.subsidy.vo.classdict.SystemSettings;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
......@@ -19,6 +25,7 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
......@@ -47,12 +54,15 @@ public class WebSocketUtil implements WebSocketHandler {
@Autowired
private ClassDictMapper classDictMapper;
@Autowired
private MemberMapper memberMapper;
private int heartbeatMin = 1; // 断连最小心跳次数
private int heartbeatMax = 2; // 断连最大心跳次数
private int reconnectionSeconds = 60; //每次断连间隔重新连接秒
/**
* 存放建立连接webSocket对象
* 存放建立连接webSocket对象 Map<memberId,session>
*/
public static ConcurrentHashMap<Long, WebSocketSession> webSocketMap = new ConcurrentHashMap();
......@@ -60,124 +70,117 @@ public class WebSocketUtil implements WebSocketHandler {
/**
* 处理成功连接WebSocket 建立直接后调用
* @param session
*/
@Override
public void afterConnectionEstablished(WebSocketSession session) throws IOException {
if(null != session) {
if (null != session) {
String params = session.getUri().getQuery();
Long id = Long.valueOf(params.split("=")[1]);
if(null != webSocketMap && webSocketMap.get(id) != null) {
if(webSocketMap.get(id).isOpen()) {
//webSocketMap的操作
if (null != webSocketMap && webSocketMap.get(id) != null) {
if (webSocketMap.get(id).isOpen()) {
/* 相同账户进行挤号,发送消息给WebSocket通知账户已在其他地方登录 */
webSocketMap.get(id).sendMessage(new TextMessage(JSONObject.toJSONString(ResponseData.generateCreatedResponse(1011))));
webSocketMap.get(id).close();
} else {
/*
* 如果上次连接的WebSocket状态是关闭,
* 上次连接的WebSocket状态是关闭,
* 并且上一次记录时间大于 { heartbeatMax * reconnectionSeconds } 秒(心跳检测机制),则判断为这次登陆是免密码登陆的重新记录上线时间
*/
List<OprMemDictDO> list = oprMemDictMapper.selectList(new QueryWrapper<OprMemDictDO>()
.lambda()
.eq(OprMemDictDO::getUserId, id)
.orderByDesc(OprMemDictDO::getCreateDate));
Calendar calendar = Calendar.getInstance();
calendar.setTime(DateFormatUtil.localDateTimeToDate(list.get(0).getCreateDate()));
calendar.add(Calendar.SECOND,heartbeatMax * reconnectionSeconds);
if(calendar.getTime().after(DateFormatUtil.localDateTimeToDate(list.get(0).getCreateDate()))) {
if(list.get(0).getOprType().equals("登出")) {
OprMemDictDO oprMemDictDO = new OprMemDictDO();
OprMemDictDO oprMemDictDO = oprMemDictMapper.getLatestLoginInfo(id); //最近一次登录
// Calendar calendar = Calendar.getInstance();
// calendar.setTime(DateFormatUtil.localDateTimeToDate(oprMemDictDO.getCreateDate()));
// calendar.add(Calendar.SECOND,heartbeatMax * reconnectionSeconds); //当前时间+最大链接次数,判定为超时
// if(calendar.getTime().after(DateFormatUtil.localDateTimeToDate(oprMemDictDO.getCreateDate()))) {
if (oprMemDictDO.getOprType().equals("登出")) {
//登出过的话就写记录,否则不写
oprMemDictDO.setUserId(id);
oprMemDictDO.setResult(1);
oprMemDictDO.setOprType("登录");
oprMemDictDO.setIpAddress(session.getRemoteAddress().getHostName());
// oprMemDictDO.setIpAddress(session.getRemoteAddress().getHostName());
oprMemDictMapper.insert(oprMemDictDO);
}
}
// }
}
webSocketMap.remove(id);
}
webSocketMap.put(id, session);
/* 班级配置信息 */ //查人的班级
// 数据操作
SystemSettings systemSettings = memberMapper.companySettings(id); //公司配置
List<ClassSettingsVO> classSettings = classDictMapper.getClassSettings(id);
if(CollectionUtils.isNotEmpty(classSettings)) {
String data = JSONObject.toJSONString(ResponseData.generateCreatedResponse(0, classSettings), SerializerFeature.WriteMapNullValue);
systemSettings.setClassSettingsVOS(classSettings);
if (CollectionUtils.isNotEmpty(classSettings)) {
String data = JSONObject.toJSONString(ResponseData.generateCreatedResponse(0, systemSettings), SerializerFeature.WriteMapNullValue);
webSocketMap.get(id).sendMessage(new TextMessage(data));
}
String httpSessionId = session.getId();
String host = session.getUri().getHost();
String query = session.getUri().getQuery();
log.info("----> webSocket connection success");
log.info("parameter:[ httpSessionId: {}, host: {}, {} ]", httpSessionId, host, query);
log.info("connection time: {}", DateFormatUtil.format(new Date(), DateFormatUtil.FMT_sdf14_L));
// String httpSessionId = session.getId();
// String host = session.getUri().getHost();
// String query = session.getUri().getQuery();
// log.info("----> webSocket connection success");
// log.info("parameter:[ httpSessionId: {}, host: {}, {} ]", httpSessionId, host, query);
// log.info("connection time: {}", DateFormatUtil.format(new Date(), DateFormatUtil.FMT_sdf14_L));
}
}
/**
* 处理WebSocket transport error
* @param session
* @param throwable
* @throws Exception
*/
@Override
public void handleTransportError(WebSocketSession session, Throwable throwable) throws Exception {
if(session.isOpen()) {
if (session.isOpen()) {
session.close();
}
String params = session.getUri().getQuery();
Long id = Long.valueOf(params.split("=")[1]);
webSocketMap.remove(id);
log.error("<---- webSocket transport error");
log.error("error message: {}", throwable.getMessage());
// log.error("<---- webSocket transport error");
// log.error("error message: {}", throwable.getMessage());
}
/**
* 在两端WebSocket connection都关闭或transport error发生后执行
* @param session
* @param closeStatus
* @throws Exception
*/
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception{
if(null != session) {
if(null != webSocketMap) {
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
if (null != session) {
if (null != webSocketMap) {
String params = session.getUri().getQuery();
Long id = Long.valueOf(params.split("=")[1]);
heartbeat(webSocketMap.get(id));
}
log.info("<---- webSocket is close");
log.info("session {} close, status: {}", session.getId(), closeStatus);
// log.info("<---- webSocket is close");
// log.info("session {} close, status: {}", session.getId(), closeStatus);
}
}
/**
* 断开连接后进行三次心跳验证判断是否重新连接了,如果没有连接成功则判断为下线
*
* @param session
*/
public void heartbeat(WebSocketSession session) {
ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
ScheduledFuture scheduledFuture = service.scheduleAtFixedRate(new Runnable() {
int beatsNum = heartbeatMin;
@SneakyThrows
@Override
public void run() {
if(null != session && !session.isOpen()) {
while (beatsNum > heartbeatMax) {
if (null != session && !session.isOpen()) {
if (beatsNum > heartbeatMax) { //heartbeatMa:2
String params = session.getUri().getQuery();
Long id = Long.valueOf(params.split("=")[1]);
OprMemDictDO oprMemDictDO = new OprMemDictDO();
oprMemDictDO.setUserId(id);
oprMemDictDO.setResult(1);
oprMemDictDO.setOprType("登出");
oprMemDictDO.setIpAddress(session.getRemoteAddress().getHostName());
// oprMemDictDO.setIpAddress(session.getRemoteAddress().getHostName());
oprMemDictMapper.insert(oprMemDictDO);
taskMap.get(session.getId()).cancel(true);
// break;
}
beatsNum++;
} else if (null != session && session.isOpen()) {
......@@ -191,14 +194,11 @@ public class WebSocketUtil implements WebSocketHandler {
/**
* 接收WebSocket客户端Message
* @param session
* @param message
* @throws Exception
*/
@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
if(message instanceof TextMessage) {
System.out.println(message.getPayload());
if (message instanceof TextMessage) {
// System.out.println(message.getPayload());
}
}
......
package com.subsidy.vo.classdict;
import lombok.Data;
import java.util.List;
@Data
public class SystemSettings {
/**
* 上课时间不晚于23:30,不早于6:30
*/
private Integer timeLimit;
/**
* 签到时记录IP地址
*/
private Integer ipAddressRecord;
/**
* 签到时记录设备型号
*/
private Integer deviceNoRecord;
/**
* 班级配置
*/
private List<ClassSettingsVO> classSettingsVOS;
}
package com.subsidy.vo.image;
import com.subsidy.model.ImageCheckRecordDO;
import lombok.Data;
@Data
public class CheckImageResultVO extends ImageCheckRecordDO {
private Boolean result;
}
......@@ -32,5 +32,9 @@ public class MyCoursesVO {
private Integer isFastPlay;
private Integer result;
private Integer checkCnt;
private List<FieldDictDO> fieldDictDOS;
}
......@@ -21,4 +21,8 @@ public class QueryPapersVO {
private String endDate;
private Integer checkCnt;
private Integer checkResult;
}
......@@ -197,4 +197,19 @@
AND t2.delete_date IS NULL
AND t3.delete_date IS NULL
</select>
<select id="getCompanySettings" parameterType="long" resultType="com.subsidy.vo.classdict.SystemSettings">
SELECT
t2.time_limit,
t2.ip_address_record,
t2.device_no_record
FROM
class_dict t
LEFT JOIN company_dict t2 ON t.company_id = t2.id
WHERE
t.delete_date IS NULL
AND t2.delete_date IS NULL
AND t.id = #{classId}
</select>
</mapper>
......@@ -33,4 +33,26 @@
AND t.member_id = #{memberId}
</select>
<select id="checkDailyCount" resultType="int">
SELECT
count(1)
FROM
image_check_record t
WHERE
t.delete_date IS NULL
<if test="memberId != null and memberId != ''">
AND t.member_id = #{memberId}
</if>
<if test="classId != null and classId != ''">
AND t.class_id = #{classId}
</if>
AND DATE_FORMAT(now(), '%Y-%m-%d') = DATE_FORMAT(t.create_date, '%Y-%m-%d')
<if test="checkPlace != null and checkPlace != ''">
and class_place = #{checkPlace}
</if>
<if test="paperId != null and paperId != ''">
and paper_id = #{paperId}
</if>
</select>
</mapper>
......@@ -330,4 +330,18 @@
<update id="removeCheckImage" parameterType="long">
update member set check_image = null,check_time = null where id = #{id}
</update>
<select id="companySettings" parameterType="long" resultType="com.subsidy.vo.classdict.SystemSettings">
SELECT
t2.time_limit,
t2.ip_address_record,
t2.device_no_record
FROM
member t
LEFT JOIN company_dict t2 ON t.company_id = t2.id
WHERE
t.delete_date IS NULL
AND t2.delete_date IS NULL
AND t.id = #{memberId}
</select>
</mapper>
......@@ -54,4 +54,18 @@
WHERE
create_date &lt; (NOW() - INTERVAL 10 DAY)
</select>
<select id="getLatestLoginInfo" parameterType="long" resultType="com.subsidy.model.OprMemDictDO">
SELECT
t.ip_address,
t.opr_type,
t.result,
t.user_id,
max(t.create_date) as create_date
FROM
opr_mem_dict t
WHERE
t.delete_date IS NULL
AND t.user_id = #{userId}
</select>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!