From 0a84e930b2436fa65a2090c6b845585f7dc69ceb Mon Sep 17 00:00:00 2001 From: unclekh <5177787+unclekh@user.noreply.gitee.com> Date: Tue, 12 May 2020 07:35:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E7=AD=94=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/base/constant/BaseConstant.java | 1 + .../common/base/constant/YyyfConstant.java | 6 +- .../common/base/dto/SessionUserDTO.java | 1 + .../user/controller/LoginController.java | 59 ++++++++---- .../server/user/entity/YyyfUser.java | 44 +++++++++ .../server/user/mapper/YyyfUserMapper.java | 16 ++++ .../server/user/service/YyyfUserService.java | 26 ++++++ .../service/impl/YyyfUserServiceImpl.java | 63 +++++++++++++ .../main/resources/mapper/YyyfUserMapper.xml | 6 ++ .../server/train/dto/ExamPaperDto.java | 42 +++++++++ .../server/train/dto/TrainCaseTargetDto.java | 39 ++++++++ .../yyyf/controller/LoginController.java | 66 ++++++------- .../controller/StudentAnswerController.java | 93 +++++++++++++++++++ .../yyyf/controller/api/StudentAnswerApi.java | 18 ++++ .../server/yyyf/dto/ExamPaperDto.java | 32 ------- .../server/yyyf/dto/StudentAnswerDto.java | 4 +- .../yyyf/dto/StudentTrainCaseTargetDto.java | 19 ++++ .../server/yyyf/dto/YyyfLoginDto.java | 2 - pom.xml | 4 +- 19 files changed, 445 insertions(+), 96 deletions(-) create mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java create mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/YyyfUserMapper.java create mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java create mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java create mode 100644 blockchain-server/blockchain-server-user/src/main/resources/mapper/YyyfUserMapper.xml create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/ExamPaperDto.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/TrainCaseTargetDto.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java delete mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/ExamPaperDto.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/StudentTrainCaseTargetDto.java diff --git a/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/constant/BaseConstant.java b/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/constant/BaseConstant.java index ded7080..0b851e6 100644 --- a/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/constant/BaseConstant.java +++ b/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/constant/BaseConstant.java @@ -16,5 +16,6 @@ public class BaseConstant { public static final int REQUEST_SUCCESS = 200;// 成功标识 + public static final String YYYF_TOKEN_HEADER = "X-Requested-YyyfToken";//yyyfToken } diff --git a/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/constant/YyyfConstant.java b/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/constant/YyyfConstant.java index 50ea71d..79e48bc 100644 --- a/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/constant/YyyfConstant.java +++ b/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/constant/YyyfConstant.java @@ -19,8 +19,8 @@ public class YyyfConstant { //Submitted public static final String SUBMITTED="您的考试已提交,不允许再次进入"; - - public static final String EXAM_PAPER_KEY="examPaperKey"; + /**案例缓存Key*/ + public static final String EXAM_PAPER_KEY="zhiXinLianExamPaperKey"; /**参加考试的人员id key*/ public static final String JOIN_EXAM_STU_IDS_KEY="joinExamStuIds"; @@ -31,4 +31,6 @@ public class YyyfConstant { /**以渔有方与智信链用户绑定的cookies*/ public static final String YYYF_ZHIXINLIAN_USER_KEY="yyyfZhixinlianUserKey"; + + } \ No newline at end of file diff --git a/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/dto/SessionUserDTO.java b/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/dto/SessionUserDTO.java index 6ec6391..935604e 100644 --- a/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/dto/SessionUserDTO.java +++ b/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/dto/SessionUserDTO.java @@ -12,4 +12,5 @@ public class SessionUserDTO extends BaseDTO{ private String id;//用户id private String tel;//手机号 private Long timestamp;//时间戳 + private Integer yyyfUserId; } diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java index 5b38663..c57e4d4 100644 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java @@ -5,6 +5,7 @@ import com.blockchain.common.base.constant.TokenTypeEnums; import com.blockchain.common.base.dto.ResultDTO; import com.blockchain.common.base.dto.SessionUserDTO; import com.blockchain.common.base.dto.TokenDTO; +import com.blockchain.common.base.dto.YyyfUserDto; import com.blockchain.common.base.util.HttpRequestUtil; import com.blockchain.common.base.util.RSACoderUtils; import com.blockchain.common.base.util.SSOHelper; @@ -18,14 +19,10 @@ import com.blockchain.server.user.common.utils.SmsCodeUtils; import com.blockchain.server.user.controller.api.LoginApi; import com.blockchain.server.user.dto.UserBaseDTO; import com.blockchain.server.user.entity.UserMain; -import com.blockchain.server.user.service.PushUserService; -import com.blockchain.server.user.service.SmsCountService; -import com.blockchain.server.user.service.UserLoginService; -import com.blockchain.server.user.service.UserMainService; +import com.blockchain.server.user.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +31,6 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; -import java.util.Date; /** * @author huangxl @@ -63,6 +59,9 @@ public class LoginController { @Autowired private RedisTemplate redisTemplate; + @Autowired + private YyyfUserService yyyfUserService; + @PostMapping("/password") @ApiOperation(value = LoginApi.PassWorldLogin.METHOD_NAME, notes = LoginApi.PassWorldLogin.METHOD_NOTE) @@ -71,7 +70,7 @@ public class LoginController { @ApiParam(LoginApi.PassWorldLogin.METHOD_API_CLIENT_ID) @RequestParam(name = "clientId", required = false) String clientId, HttpServletRequest request) { UserMain userMain = userLoginService.handleLoginByPassword(tel, password); - return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); + return handleAppAfterLogin(userMain, clientId, getUserLocale(request), request); } @PostMapping("/loginByCode") @@ -85,7 +84,7 @@ public class LoginController { UserMain userMain = userLoginService.handleLoginByPhoneCode(tel); // userMainService.selectByMobilePhone(tel); smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_LOGIN); - return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); + return handleAppAfterLogin(userMain, clientId, getUserLocale(request), request); } @PostMapping("/register") @@ -103,7 +102,7 @@ public class LoginController { smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_REGISTER); UserMain userMain = userMainService.handleRegister(tel, invitationCode, internationalCode, password, nickName); smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_REGISTER); - return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); + return handleAppAfterLogin(userMain, clientId, getUserLocale(request), request); } @PostMapping("/sendLoginCode") @@ -168,21 +167,21 @@ public class LoginController { @ApiOperation(value = LoginApi.PassWorldLoginPC.METHOD_NAME, notes = LoginApi.PassWorldLoginPC.METHOD_NOTE) public ResultDTO loginByPasswordPC(@ApiParam(LoginApi.PassWorldLoginPC.METHOD_API_TEL) @RequestParam(name = "tel") String tel, - @ApiParam(LoginApi.PassWorldLoginPC.METHOD_API_PASS) @RequestParam(name = "password") String password) { + @ApiParam(LoginApi.PassWorldLoginPC.METHOD_API_PASS) @RequestParam(name = "password") String password, HttpServletRequest request) { UserMain userMain = userLoginService.handleLoginByPassword(tel, password); - return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); + return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); } @PostMapping("/loginByCode2") @ApiOperation(value = LoginApi.SmsCodeLoginPC.METHOD_NAME, notes = LoginApi.SmsCodeLoginPC.METHOD_NOTE) public ResultDTO loginBysmsCodePC(@ApiParam(LoginApi.SmsCodeLoginPC.METHOD_API_TEL) @RequestParam(name = "tel") String tel, - @ApiParam(LoginApi.SmsCodeLoginPC.METHOD_API_CODE) @RequestParam(name = "code") String code) { + @ApiParam(LoginApi.SmsCodeLoginPC.METHOD_API_CODE) @RequestParam(name = "code") String code, HttpServletRequest request) { smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_LOGIN); UserMain userMain = userLoginService.handleLoginByPhoneCode(tel); // userMainService.selectByMobilePhone(tel); smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_LOGIN); - return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); + return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); } @PostMapping("/register2") @@ -193,12 +192,12 @@ public class LoginController { @ApiParam(LoginApi.RegisterPC.METHOD_API_INVITATION_CODE) @RequestParam(value = "invitationCode", required = false) String invitationCode, @ApiParam(LoginApi.RegisterPC.METHOD_API_PASSWORD) @RequestParam(value = "password", required = false) String password, @ApiParam(LoginApi.RegisterPC.METHOD_API_INTERNATIONAL_CODE) @RequestParam(value = "internationalCode", required = false, defaultValue = InternationalConstant.DEFAULT_CODE) String internationalCode, - @ApiParam(LoginApi.RegisterPC.METHOD_API_NICK_NAME) @RequestParam(value = "nickName", required = false) String nickName + @ApiParam(LoginApi.RegisterPC.METHOD_API_NICK_NAME) @RequestParam(value = "nickName", required = false) String nickName, HttpServletRequest request ) { smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_REGISTER); UserMain userMain = userMainService.handleRegister(tel, invitationCode, internationalCode, password, nickName); smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_REGISTER); - return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); + return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); } @PostMapping("/loginout2") @@ -216,11 +215,12 @@ public class LoginController { * @param tel 手机号 * @param timestamp 时间撮 */ - private void setUserToRedis(String id, String tel, long timestamp, String tokenType) { + private void setUserToRedis(String id, String tel, long timestamp, String tokenType, Integer yyyfUserId) { SessionUserDTO userDTO = new SessionUserDTO(); userDTO.setId(id); userDTO.setTel(tel); userDTO.setTimestamp(timestamp); + userDTO.setYyyfUserId(yyyfUserId); SSOHelper.setUser(userDTO, redisTemplate, tokenType); } @@ -242,10 +242,10 @@ public class LoginController { /** * App登录成功之后的处理 */ - private ResultDTO handleAppAfterLogin(UserMain userMain, String clientId, String userLocale) { + private ResultDTO handleAppAfterLogin(UserMain userMain, String clientId, String userLocale, HttpServletRequest request) { //保存用户客户端信息,用于消息通知 handleAfterLoginToSavePushUser(userMain.getId(), clientId, userLocale); - return handleAfterLogin(userMain, TokenTypeEnums.APP.getValue()); + return handleAfterLogin(userMain, TokenTypeEnums.APP.getValue(), request); } /*** @@ -269,12 +269,31 @@ public class LoginController { /** * 登录成功之后的处理 */ - private ResultDTO handleAfterLogin(UserMain userMain, String tokenType) { + private ResultDTO handleAfterLogin(UserMain userMain, String tokenType, HttpServletRequest request) { + + + Integer yyyfUserId = null; + String yyyfTtoken = request.getHeader(BaseConstant.YYYF_TOKEN_HEADER); + + //如果有token,拿到用户信息,与以渔有方进行绑定 + if (redisTemplate.hasKey(yyyfTtoken)) { + YyyfUserDto yyyfUserDto = (YyyfUserDto) redisTemplate.opsForValue().get(yyyfTtoken); + yyyfUserId = yyyfUserDto.getId(); + String userId =userMain.getId(); + int count = this.yyyfUserService.selectCountByYyyfUserIdAndUserId(yyyfUserId, userId); + if (count == 0) { + this.yyyfUserService.saveUser(yyyfUserId, userId, yyyfUserDto.getName()); + this.redisTemplate.delete(yyyfTtoken); + } + + } + long timestamp = System.currentTimeMillis(); - setUserToRedis(userMain.getId(), userMain.getMobilePhone(), timestamp, tokenType); + setUserToRedis(userMain.getId(), userMain.getMobilePhone(), timestamp, tokenType, yyyfUserId); String token = generateToken(userMain.getMobilePhone(), timestamp, tokenType); UserBaseDTO userBaseDTO = userMainService.selectUserInfoById(userMain.getId()); userBaseDTO.setToken(token); + return ResultDTO.requstSuccess(userBaseDTO); } diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java new file mode 100644 index 0000000..b0fb656 --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java @@ -0,0 +1,44 @@ +package com.blockchain.server.user.entity; + +import com.blockchain.common.base.entity.BaseModel; +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * YyyfUser 以渔有方与区块链用户关联 + * @date 2019-02-21 13:37:18 + * @version 1.0 + */ +@Table(name = "yyyf_user") +@Data +public class YyyfUser extends BaseModel { + + /** + * 以渔有方用户id + */ + @Column(name = "yyyf_user_id") + private Integer yyyfUserId; + /** + * 区块链用户id + */ + @Column(name = "user_id") + private String userId; + + /** + * 以渔有方用户姓名 + */ + @Column(name = "yyyf_user_name") + private String yyyfUserName; + + + /** + * 创建时间 + */ + @Column(name = "create_time") + private java.util.Date createTime; + + +} \ No newline at end of file diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/YyyfUserMapper.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/YyyfUserMapper.java new file mode 100644 index 0000000..8818546 --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/YyyfUserMapper.java @@ -0,0 +1,16 @@ +package com.blockchain.server.user.mapper; + +import com.blockchain.server.user.entity.UserInfo; +import com.blockchain.server.user.entity.YyyfUser; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + +/** + * AppUUserInfoMapper 数据访问类 + * @date 2019-02-21 13:37:18 + * @version 1.0 + */ +@Repository +public interface YyyfUserMapper extends Mapper { + +} \ No newline at end of file diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java new file mode 100644 index 0000000..202cbed --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java @@ -0,0 +1,26 @@ +package com.blockchain.server.user.service; + +/** + * @author huangxl + * @create 2019-02-23 18:21 + */ +public interface YyyfUserService { + + /** + * 保存用户信息 + * @param userId 用户id + * @param email + * @param hasRelation 是否有关系链信息 + */ + void saveUser(Integer yyyfUserId,String userId, String yyyfName); + + /** + * @description + * @author Mr.Xu + * @date 2020/5/4 13:42 + * @param [yyyfUserId, userId] + * @return com.blockchain.server.user.entity.YyyfUser + **/ + int selectCountByYyyfUserIdAndUserId(Integer yyyfUserId,String userId); + +} diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java new file mode 100644 index 0000000..9ef299b --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java @@ -0,0 +1,63 @@ +package com.blockchain.server.user.service.impl; + +import com.blockchain.common.base.enums.BaseResultEnums; +import com.blockchain.common.base.exception.BaseException; +import com.blockchain.common.base.util.ExceptionPreconditionUtils; +import com.blockchain.server.user.common.constants.other.RedisConstant; +import com.blockchain.server.user.common.constants.other.StringFormatConstant; +import com.blockchain.server.user.common.constants.sql.UserOptConstant; +import com.blockchain.server.user.common.enums.SmsCountEnum; +import com.blockchain.server.user.common.enums.UserEnums; +import com.blockchain.server.user.common.exceprion.UserException; +import com.blockchain.server.user.common.utils.CheckUtils; +import com.blockchain.server.user.common.utils.FileUploadHelper; +import com.blockchain.server.user.common.utils.GoogleAuthenticatorUtils; +import com.blockchain.server.user.entity.UserInfo; +import com.blockchain.server.user.entity.YyyfUser; +import com.blockchain.server.user.mapper.UserInfoMapper; +import com.blockchain.server.user.mapper.YyyfUserMapper; +import com.blockchain.server.user.service.UserOptLogService; +import com.blockchain.server.user.service.YyyfUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import tk.mybatis.mapper.entity.Example; + +import java.util.Date; +import java.util.List; +import java.util.Random; +import java.util.UUID; + +/** + * @author huangxl + * @create 2019-02-23 18:23 + */ +@Service +public class YyyfUserServiceImpl implements YyyfUserService { + + @Autowired + private YyyfUserMapper yyyfUserMapper; + + @Transactional + @Override + public void saveUser(Integer yyyfUserId, String userId, String yyyfName) { + YyyfUser yyyfUser=new YyyfUser(); + yyyfUser.setYyyfUserId(yyyfUserId); + yyyfUser.setUserId(userId); + yyyfUser.setYyyfUserName(yyyfName); + yyyfUser.setCreateTime(new Date()); + this.yyyfUserMapper.insert(yyyfUser); + } + + @Override + public int selectCountByYyyfUserIdAndUserId(Integer yyyfUserId, String userId) { + Example example=new Example(YyyfUser.class); + Example.Criteria criteria=example.createCriteria(); + criteria.andCondition("yyyf_user_id = " ,yyyfUserId) + .andCondition("user_id = ",userId); + return this.yyyfUserMapper.selectCountByExample(example); + } + + +} diff --git a/blockchain-server/blockchain-server-user/src/main/resources/mapper/YyyfUserMapper.xml b/blockchain-server/blockchain-server-user/src/main/resources/mapper/YyyfUserMapper.xml new file mode 100644 index 0000000..7fb5639 --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/resources/mapper/YyyfUserMapper.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/ExamPaperDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/ExamPaperDto.java new file mode 100644 index 0000000..d3086e3 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/ExamPaperDto.java @@ -0,0 +1,42 @@ +package com.blockchain.server.train.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class ExamPaperDto implements Serializable { + private static final long serialVersionUID = 1L; + /** + * id + */ + private String id; + + /** + * 指标名称 + */ + private String name; + + /** + * 任务目标运算符:1大于2小于 + */ + private Integer taskOperate; + /** + * 任务目标比率 + */ + private Double taskRate; + /** + * 任务分数 + */ + private Double taskScore; + /** + * 指标代码 + */ + private String code; + + /** + * 指标id + */ + private String targeId; +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/TrainCaseTargetDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/TrainCaseTargetDto.java new file mode 100644 index 0000000..b947ab1 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/TrainCaseTargetDto.java @@ -0,0 +1,39 @@ +package com.blockchain.server.train.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * Desc: 案例指标 dto + * + * @author qianqian.zhang + * @date 2020-04-21 17:43 + **/ +@Data +public class TrainCaseTargetDto implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 指标id + */ + private String id; + + /** + * 指标名称 + */ + private String name; + + /** + * 任务目标运算符:1大于2小于 + */ + private Integer taskOperate; + /** + * 任务目标比率 + */ + private Double taskRate; + /** + * 任务分数 + */ + private Double taskScore; +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/LoginController.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/LoginController.java index e4c963f..0cf95d0 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/LoginController.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/LoginController.java @@ -5,6 +5,7 @@ import com.blockchain.common.base.dto.ResultDTO; import com.blockchain.common.base.dto.TokenDTO; import com.blockchain.common.base.dto.YyyfUserDto; import com.blockchain.common.base.util.RSACoderUtils; +import com.blockchain.server.train.dto.ExamPaperDto; import com.blockchain.server.yyyf.controller.api.LoginApi; import com.blockchain.server.yyyf.dto.*; import com.blockchain.server.yyyf.service.AssessUserService; @@ -48,15 +49,14 @@ public class LoginController { @PostMapping("/login") @ApiOperation(value = LoginApi.YyyfLogin.METHOD_NAME, notes = LoginApi.YyyfLogin.METHOD_NOTE) - public ResultDTO loginyyyf(@ApiParam(LoginApi.YyyfLogin.METHOD_API_YYYFLOGINREQUESTVO) @Valid YyyfLoginRequestVo yyyfLoginRequestVo) { + public ResultDTO loginyyyf(@ApiParam(LoginApi.YyyfLogin.METHOD_API_YYYFLOGINREQUESTVO) @Valid YyyfLoginRequestVo yyyfLoginRequestVo) { //存到redis中用于以渔有方用户与智信链用户进行绑定 - YyyfUserDto yyyfUserDto=new YyyfUserDto(); + YyyfUserDto yyyfUserDto = new YyyfUserDto(); //登录返回的Data YyyfLoginDto yyyfLoginDto = new YyyfLoginDto(); yyyfLoginDto.setStatus(0); - String userName =null; - + String userName = null; try { userName = new String(new BASE64Decoder().decodeBuffer(yyyfLoginRequestVo.getUserName().replaceAll(" ", "+")), "UTF-8"); //根据案例id,考核id封装相关信息。 @@ -64,7 +64,7 @@ public class LoginController { //0 考试 1 练习 2 不计分 3 教师、管理员的案例管理 int reqType = yyyfLoginRequestVo.getReqType().intValue(); int userType = yyyfLoginRequestVo.getUserType().intValue(); - Integer classId =yyyfLoginRequestVo.getClassId(); + Integer classId = yyyfLoginRequestVo.getClassId(); Integer userId = yyyfLoginRequestVo.getUserId(); Integer schoolId = yyyfLoginRequestVo.getSchoolId(); @@ -85,7 +85,7 @@ public class LoginController { //将参加考试的人员缓存 HashOperations> studentOpsForHash = redisTemplate.opsForHash(); //参加考试的人员id - List joinStuIds =null; + List joinStuIds = null; //考试id和案列id缓存 String caseKey = YyyfConstant.CASE_KEY + userId; @@ -96,7 +96,7 @@ public class LoginController { if (this.assessUserService.selectScore(examId, userId) != null) { yyyfLoginDto.setStatus(2); yyyfLoginDto.setMsg(YyyfConstant.SUBMITTED); - return handleAfterLogin(yyyfLoginDto,yyyfUserDto); + return handleAfterLogin(yyyfLoginDto, yyyfUserDto); } ExamDto examDto = examDtoOpsForHash.get(YyyfConstant.EXAM_KEY, examId); @@ -110,7 +110,7 @@ public class LoginController { examDtoOpsForHash.put(YyyfConstant.EXAM_KEY, examId, examDto); } - joinStuIds=studentOpsForHash.get(YyyfConstant.JOIN_EXAM_STU_IDS_KEY, examId); + joinStuIds = studentOpsForHash.get(YyyfConstant.JOIN_EXAM_STU_IDS_KEY, examId); if (joinStuIds == null) { joinStuIds = new ArrayList(); } @@ -122,20 +122,20 @@ public class LoginController { } else { yyyfLoginDto.setStatus(1); yyyfLoginDto.setMsg(YyyfConstant.NO_ENTRY_INTO_PRACTICE); - return handleAfterLogin(yyyfLoginDto,yyyfUserDto); + return handleAfterLogin(yyyfLoginDto, yyyfUserDto); } - }else { + } else { if (redisTemplate.hasKey(caseKey)) { Map examMsgMap = (Map) redisTemplate.opsForValue().get(caseKey); - joinStuIds=studentOpsForHash.get(YyyfConstant.JOIN_EXAM_STU_IDS_KEY, examMsgMap.get("examId")); + joinStuIds = studentOpsForHash.get(YyyfConstant.JOIN_EXAM_STU_IDS_KEY, examMsgMap.get("examId")); } //缓存是考试,要进入练习,则不让进入 if (joinStuIds != null && joinStuIds.stream() .filter(stuIds -> (stuIds.equals(userId))).count() != 0) { yyyfLoginDto.setStatus(1); yyyfLoginDto.setMsg(YyyfConstant.NO_ENTRY_INTO_PRACTICE); - return handleAfterLogin(yyyfLoginDto,yyyfUserDto); + return handleAfterLogin(yyyfLoginDto, yyyfUserDto); } ValueOperations studentAnsweValueOperations = redisTemplate.opsForValue(); @@ -143,8 +143,8 @@ public class LoginController { StudentAnswerDto studentAnswerDto = (StudentAnswerDto) studentAnsweValueOperations.get(studentAnswerDtoKey); if (studentAnswerDto != null) { //答题结果、且未提交 - Map result = studentAnswerDto.getResult(); - if (result != null && result.size() > 0 && result.get("isSubmit")==null ) { + Map result = studentAnswerDto.getResult(); + if (result != null && result.size() > 0 && result.get("isSubmit") == null) { yyyfLoginDto.setStatus(3); yyyfLoginDto.setMsg(YyyfConstant.INCOMPLETE_PRACTICE); PractiseTipDto practiseTipDto = new PractiseTipDto(); @@ -161,7 +161,7 @@ public class LoginController { redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS); redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); - return handleAfterLogin(yyyfLoginDto,yyyfUserDto); + return handleAfterLogin(yyyfLoginDto, yyyfUserDto); } } } @@ -188,37 +188,31 @@ public class LoginController { map.put("examPaperId", examPaperId); map.put("examId", examId); - HashOperations examPaperOpsForHash = redisTemplate.opsForHash(); - ExamPaperDto examPaperDto = examPaperOpsForHash.get(YyyfConstant.EXAM_PAPER_KEY, examPaperId); - if (examPaperDto == null) { - // examPaperDto = this.projectManageService.getExamPaperDtoById(examPaperId); - examPaperOpsForHash.put(YyyfConstant.EXAM_PAPER_KEY, examPaperId, examPaperDto); - } - redisTemplate.opsForValue().set(caseKey, map); redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS); redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); } } catch (IOException e) { - LOG.error(e.getMessage(),e); + LOG.error(e.getMessage(), e); } - return handleAfterLogin(yyyfLoginDto,yyyfUserDto); + return handleAfterLogin(yyyfLoginDto, yyyfUserDto); } - /** - * 登录成功之后的处理 - */ - private ResultDTO handleAfterLogin(YyyfLoginDto yyyfLoginDto, YyyfUserDto yyyfUserDto) { - int status = yyyfLoginDto.getStatus(); - String token = generateToken(String.valueOf(yyyfUserDto.getId()), System.currentTimeMillis(), YyyfConstant.YYYF_ZHIXINLIAN_USER_KEY); - yyyfLoginDto.setYyyfUserToken(token); - if(status==1){ - //到时看要不要设定时长 - redisTemplate.opsForValue().set(token,yyyfUserDto); - } - return ResultDTO.requstSuccess(yyyfLoginDto); + /** + * 登录成功之后的处理 + */ + private ResultDTO handleAfterLogin(YyyfLoginDto yyyfLoginDto, YyyfUserDto yyyfUserDto) { + int status = yyyfLoginDto.getStatus(); + String token = generateToken(String.valueOf(yyyfUserDto.getId()), System.currentTimeMillis(), + YyyfConstant.YYYF_ZHIXINLIAN_USER_KEY); + yyyfLoginDto.setYyyfUserToken(token); + if (status != 2) { + //到时看要不要设定时长 + redisTemplate.opsForValue().set(token, yyyfUserDto); } + return ResultDTO.requstSuccess(yyyfLoginDto); + } /** * 生成token返回前端 diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java new file mode 100644 index 0000000..3469072 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java @@ -0,0 +1,93 @@ +package com.blockchain.server.yyyf.controller; + +import com.blockchain.common.base.constant.YyyfConstant; +import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.server.train.dto.ExamPaperDto; +import com.blockchain.server.yyyf.controller.api.StudentAnswerApi; +import com.blockchain.server.yyyf.dto.StudentAnswerDto; +import com.blockchain.server.yyyf.service.AssessUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * @author huangxl + * @data 2019/2/21 15:06 + * 用户注册, 登录控制器 + */ +@RestController +@Api(StudentAnswerApi.CONTROLLER_API) +@RequestMapping("/loginFromYyyf") +public class StudentAnswerController { + + private static final Logger LOG = LoggerFactory.getLogger(StudentAnswerController.class); + + @Autowired + private AssessUserService assessUserService; + + @Autowired + private RedisTemplate redisTemplate; + + @PostMapping("/studentAnswer") + @ApiOperation(value = StudentAnswerApi.StudentAnswer.METHOD_NAME, + notes = StudentAnswerApi.StudentAnswer.METHOD_NOTE) + public ResultDTO studentAnswer(@ApiParam(StudentAnswerApi.StudentAnswer.METHOD_YYYF_USER_ID) @RequestParam(name = "yyyfUserId")String yyyfUserId, + @ApiParam(StudentAnswerApi.StudentAnswer.METHOD_STUDENT_TASK_RATE) @RequestParam(name = "taskRate")String taskRate, + @ApiParam(StudentAnswerApi.StudentAnswer.METHOD_STARGE_ID) @RequestParam(name = "targeId")String targeId) { + + + String caseKey = YyyfConstant.CASE_KEY + yyyfUserId; + String studentAnswerDtoKey = null; + /* if (redisTemplate.hasKey(caseKey)) { + Map map = (Map) redisTemplate.opsForValue().get(caseKey); + String caseId=map.get("examPaperId"); + + studentAnswerDtoKey = YyyfConstant.ANSER_KEY +yyyfUserId + caseId; + + ValueOperations studentAnsweValueOperations = redisTemplate.opsForValue(); + StudentAnswerDto studentAnswerDto = (StudentAnswerDto) studentAnsweValueOperations.get(studentAnswerDtoKey); + + if (studentAnswerDto == null || (studentAnswerDto != null && studentAnswerDto.getTotalScore() != null)) { + return; + } + ExamPaperDto examPaperDto = (ExamPaperDto) redisTemplate.opsForHash().get(YyyfConstant.EXAM_PAPER_KEY, studentAnswerDto.getExamPaperId()); + //交易id + String trxId = studentAnswer.value(); + Map result = studentAnswerDto.getResult(); + if (result == null) { + result = new HashMap<>(); + } + AtomicBoolean flag = new AtomicBoolean(false); + examPaperDto.getTradeList().stream().forEach(bd -> { + if (bd.getId().equals(trxId)) { + flag.set(true); + } + }); + if (flag.get()) { + result.put(trxId, 1); + studentAnswerDto.setResult(result); + studentAnsweValueOperations.set(studentAnswerDtoKey, studentAnswerDto); + } + redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); + redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS); + }*/ + return new ResultDTO(); + } + + + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java new file mode 100644 index 0000000..4e17d93 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java @@ -0,0 +1,18 @@ +package com.blockchain.server.yyyf.controller.api; + +/** + * @author huangxl + * @create 2018-11-16 14:51 + */ +public class StudentAnswerApi { + public static final String CONTROLLER_API = "案例答题控制器"; + + public static class StudentAnswer { + public static final String METHOD_NAME = "学生答题"; + public static final String METHOD_NOTE = "学生答题统一调用"; + public static final String METHOD_YYYF_USER_ID = "以渔有方用户id"; + public static final String METHOD_STUDENT_TASK_RATE="学生任务目标比率"; + public static final String METHOD_STARGE_ID="指标id"; + } + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/ExamPaperDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/ExamPaperDto.java deleted file mode 100644 index 456a08f..0000000 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/ExamPaperDto.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.blockchain.server.yyyf.dto; - -import lombok.Data; - -import java.util.List; - -@Data -public class ExamPaperDto { - /** - * id - */ - private String id; - /** - * 案例名称 - */ - private String name; - /** - * 案例数据 - */ - List caseDataList; - - /** - * 计分交易数据 - */ - List tradeList; - - /** - * 案例内容描述 - */ - private String content; - -} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/StudentAnswerDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/StudentAnswerDto.java index dcc62a3..0d161f0 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/StudentAnswerDto.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/StudentAnswerDto.java @@ -17,9 +17,9 @@ public class StudentAnswerDto extends ExamDto { */ private String userName; /** - * 答题结果 0答错,1答对 + * 答题结果,value 是学生的指标 */ - private Map result; + private Map result; /** * 总分 diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/StudentTrainCaseTargetDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/StudentTrainCaseTargetDto.java new file mode 100644 index 0000000..b7310a7 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/StudentTrainCaseTargetDto.java @@ -0,0 +1,19 @@ +package com.blockchain.server.yyyf.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Mr.Xu + * @version 1.0 + * @className StudentTrainCaseTargetDto + * @description + * @date 2020-05-07 20:30 + */ +@Data +public class StudentTrainCaseTargetDto implements Serializable { + private static final long serialVersionUID = -7079847727022972640L; + + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/YyyfLoginDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/YyyfLoginDto.java index 35e8d5e..fef5e1b 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/YyyfLoginDto.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/YyyfLoginDto.java @@ -3,8 +3,6 @@ package com.blockchain.server.yyyf.dto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import lombok.Getter; -import lombok.Setter; import java.io.Serializable; diff --git a/pom.xml b/pom.xml index d0fc253..edf54a7 100644 --- a/pom.xml +++ b/pom.xml @@ -33,8 +33,8 @@ latest - zhixinlian:zhi123xin678lian@10.10.17.84 - 10.10.17.84 + zhixinlian:zhi123xin678lian@127.0.0.1 + 127.0.0.1