diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/UserMainServiceImpl.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/UserMainServiceImpl.java index 6642caa..d075e37 100644 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/UserMainServiceImpl.java +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/UserMainServiceImpl.java @@ -98,7 +98,7 @@ public class UserMainServiceImpl implements UserMainService { int insertRow = userRelationService.insertRelationChain(userId, invitationCode);//插入推荐关系 userInfoService.saveUser(userId,tel, insertRow > 0);//插入用户其他信息 - ResultDTO ethResult = ethFeign.initWallets(userId); +/* ResultDTO ethResult = ethFeign.initWallets(userId); if (ethResult.getCode() != BaseConstant.REQUEST_SUCCESS) { throw new RPCException(ethResult.getCode(), ethResult.getMsg()); } @@ -109,7 +109,7 @@ public class UserMainServiceImpl implements UserMainService { ResultDTO btcResult = btcFeign.createWallet(userId); if (btcResult.getCode() != BaseConstant.REQUEST_SUCCESS) { throw new RPCException(btcResult.getCode(), btcResult.getMsg()); - } + }*/ return user; } 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/ExamController.java similarity index 51% rename from blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java rename to blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/ExamController.java index d490bb3..fd461c1 100644 --- 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/ExamController.java @@ -4,31 +4,29 @@ import com.blockchain.common.base.constant.YyyfConstant; import com.blockchain.common.base.dto.ResultDTO; import com.blockchain.common.base.dto.YyyfUserDto; import com.blockchain.common.base.util.YyyfUserDtoUtils; -import com.blockchain.server.yyyf.controller.api.StudentAnswerApi; +import com.blockchain.server.yyyf.controller.api.ExamApi; import com.blockchain.server.yyyf.dto.AssessUserDto; import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.entity.AssessUserTarget; -import com.blockchain.server.yyyf.enums.UserEnums; -import com.blockchain.server.yyyf.exceprion.UserException; +import com.blockchain.server.yyyf.entity.YyyfMoney; +import com.blockchain.server.yyyf.enums.YyyfEnums; +import com.blockchain.server.yyyf.exceprion.YyyfException; import com.blockchain.server.yyyf.service.AssessUserService; import com.blockchain.server.yyyf.service.AssessUserTargetService; +import com.blockchain.server.yyyf.service.YyyfMoneyService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.SneakyThrows; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import java.math.BigDecimal; import java.util.Date; -import java.util.List; import java.util.concurrent.TimeUnit; /** @@ -37,27 +35,29 @@ import java.util.concurrent.TimeUnit; * 学生成绩控制器 */ @RestController -@Api(StudentAnswerApi.CONTROLLER_API) -@RequestMapping("/studentAnswer") -public class StudentAnswerController { +@Api(ExamApi.CONTROLLER_API) +@RequestMapping("/exam") +public class ExamController { - private static Logger LOG = LoggerFactory.getLogger(StudentAnswerController.class); + private static Logger LOG = LoggerFactory.getLogger(ExamController.class); @Autowired private AssessUserTargetService assessUserTargetService; @Autowired private AssessUserService assessUserService; + @Autowired + private YyyfMoneyService yyyfMoneyService; @Autowired private RedisTemplate redisTemplate; @PostMapping("/saveAnswer") - @ApiOperation(value = StudentAnswerApi.SaveAnswer.METHOD_NAME, - notes = StudentAnswerApi.SaveAnswer.METHOD_NOTE) - public ResultDTO saveAnswer(@ApiParam(StudentAnswerApi.SaveAnswer.METHOD_YYYF_USER_ID) @RequestParam(name = "yyyfUserId") Integer yyyfUserId, - @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_ASSESS_USER_ID) @RequestParam(name = "assessUserId") String assessUserId, - @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STUDENT_TASK_RATE) @RequestParam(name = "taskRate") Double taskRate, - @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STARGE_ID) @RequestParam(name = "code") String code) { + @ApiOperation(value = ExamApi.SaveAnswer.METHOD_NAME, + notes = ExamApi.SaveAnswer.METHOD_NOTE) + public ResultDTO saveAnswer(@ApiParam(ExamApi.SaveAnswer.METHOD_YYYF_USER_ID) @RequestParam(name = "yyyfUserId") Integer yyyfUserId, + @ApiParam(ExamApi.SaveAnswer.METHOD_ASSESS_USER_ID) @RequestParam(name = "assessUserId") String assessUserId, + @ApiParam(ExamApi.SaveAnswer.METHOD_STUDENT_TASK_RATE) @RequestParam(name = "taskRate") Double taskRate, + @ApiParam(ExamApi.SaveAnswer.METHOD_STARGE_ID) @RequestParam(name = "code") String code) { AssessUserTarget assessUserTarget = this.assessUserTargetService.selectByAssessUserAndCode(assessUserId, code); Integer answer = -1; @@ -79,15 +79,15 @@ public class StudentAnswerController { redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); } else { - throw new UserException(UserEnums.NO_INDICATORS_FOUND); + throw new YyyfException(YyyfEnums.NO_INDICATORS_FOUND); } return ResultDTO.requstSuccess(answer); } @SneakyThrows @GetMapping("/submit") - @ApiOperation(value = StudentAnswerApi.Submit.METHOD_NAME, - notes = StudentAnswerApi.Submit.METHOD_NOTE) + @ApiOperation(value = ExamApi.Submit.METHOD_NAME, + notes = ExamApi.Submit.METHOD_NOTE) public ResultDTO submit(HttpServletRequest request) { YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate); @@ -100,4 +100,35 @@ public class StudentAnswerController { return ResultDTO.requstSuccess(assessUserDto); } + @GetMapping("/reStart") + @ApiOperation(value = ExamApi.Restart.METHOD_NAME, + notes = ExamApi.Restart.METHOD_NOTE) + public ResultDTO reStart(HttpServletRequest request) { + + YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate); + String assessUserId = yyyfUserDto.getAssessUserId(); + AssessUser assessUser = this.assessUserService.selectById(assessUserId); + if(assessUser.getAchieveMentType()==1){ + throw new YyyfException(YyyfEnums.FODBID_EXAM_RESTART); + } + Date now=new Date(); + assessUser.setStartTime(now); + this.assessUserService.update(assessUser); + + //区块链原始金额还原 + YyyfMoney yyyfMoney=new YyyfMoney(); + yyyfMoney.setAssessUserId(assessUser.getId()); + yyyfMoney.setAliPay(assessUser.getAlipayInitMoney()); + yyyfMoney.setWxPay(assessUser.getWechatInitMoney()); + yyyfMoney.setBankCard(assessUser.getBankcardInitMoney()); + yyyfMoney.setBtc(BigDecimal.ZERO); + yyyfMoney.setEth(BigDecimal.ZERO); + yyyfMoney.setUsdt(BigDecimal.ZERO); + yyyfMoney.setUpdateTime(now); + + this.yyyfMoneyService.update(yyyfMoney); + + return ResultDTO.requstSuccess(); + } + } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/TeachingGradeController.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/TeachingGradeController.java index dd0bc69..d0a3f00 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/TeachingGradeController.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/TeachingGradeController.java @@ -5,7 +5,6 @@ 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.train.dto.TrainCaseTargetDto; -import com.blockchain.server.yyyf.controller.api.StudentAnswerApi; import com.blockchain.server.yyyf.controller.api.TeachingGradeApi; import com.blockchain.server.yyyf.dto.ExamDetailsDto; import com.blockchain.server.yyyf.dto.OverviewDto; diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/YyyfMoneyController.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/YyyfMoneyController.java new file mode 100644 index 0000000..eb84f82 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/YyyfMoneyController.java @@ -0,0 +1,49 @@ +package com.blockchain.server.yyyf.controller; + +import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.server.yyyf.controller.api.YyyfMoneyApi; +import com.blockchain.server.yyyf.dto.TransactResultDto; +import com.blockchain.server.yyyf.entity.YyyfMoney; +import com.blockchain.server.yyyf.service.YyyfMoneyService; +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.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.math.BigDecimal; + +/** + * @author Mr.Xu + * @version 1.0 + * @className MoneyController + * @description + * @date 2020-05-26 20:50 + */ +@RestController +@Api(YyyfMoneyApi.CONTROLLER_API) +@RequestMapping("/yyyfMoney") +public class YyyfMoneyController { + + @Autowired + private YyyfMoneyService yyyfMoneyService; + + private static Logger LOG = LoggerFactory.getLogger(YyyfMoneyController.class); + @PostMapping("/transact") + @ApiOperation(value = YyyfMoneyApi.Transact.METHOD_NAME, + notes = YyyfMoneyApi.Transact.METHOD_NOTE) + public ResultDTO transact(@ApiParam(YyyfMoneyApi.Transact.METHOD_ASSESS_USER_ID) @RequestParam(name = "assessUserId",required =true) String assessUserId, + @ApiParam(YyyfMoneyApi.Transact.METHOD_OUT) @RequestParam(name = "out",required =true) String out, + @ApiParam(YyyfMoneyApi.Transact.METHOD_IN) @RequestParam(name = "in",required =true) String in, + @ApiParam(YyyfMoneyApi.Transact.METHOD_AMOUNT) @RequestParam(name = "amount",required =true) BigDecimal amount) { + + TransactResultDto transactResultDto=this.yyyfMoneyService.transact(assessUserId,out,in,amount); + + return ResultDTO.requstSuccess(transactResultDto); + } +} 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/ExamApi.java similarity index 81% rename from blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java rename to blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/ExamApi.java index 0c9621b..638a14c 100644 --- 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/ExamApi.java @@ -4,7 +4,7 @@ package com.blockchain.server.yyyf.controller.api; * @author huangxl * @create 2018-11-16 14:51 */ -public class StudentAnswerApi { +public class ExamApi { public static final String CONTROLLER_API = "案例答题控制器"; public static class SaveAnswer { @@ -21,4 +21,8 @@ public class StudentAnswerApi { public static final String METHOD_NOTE = "学生提交成绩,状态码(code)1097:禁止重复提交 "; } + public static class Restart { + public static final String METHOD_NAME = "重新开始练习"; + public static final String METHOD_NOTE = "重新开始练习,若考试则抛出异常 "; + } } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/YyyfMoneyApi.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/YyyfMoneyApi.java new file mode 100644 index 0000000..733d990 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/YyyfMoneyApi.java @@ -0,0 +1,20 @@ +package com.blockchain.server.yyyf.controller.api; + +/** + * @author Mr.Xu + * @version 1.0 + * @className MoneyApi + * @description + * @date 2020-05-26 20:59 + */ +public class YyyfMoneyApi { + public static final String CONTROLLER_API = "金钱变化交易器"; + public static class Transact { + public static final String METHOD_NAME = "交易转账"; + public static final String METHOD_NOTE = "out为转出币种,in为转入币种"; + public static final String METHOD_ASSESS_USER_ID= "assessUser的主键ID"; + public static final String METHOD_OUT="转出币种"; + public static final String METHOD_IN="转入币种"; + public static final String METHOD_AMOUNT="转入金额"; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/TransactResultDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/TransactResultDto.java new file mode 100644 index 0000000..ff25ef9 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/TransactResultDto.java @@ -0,0 +1,37 @@ +package com.blockchain.server.yyyf.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author Mr.Xu + * @version 1.0 + * @className TransactDto + * @description + * @date 2020-05-26 21:41 + */ +@ApiModel(description = "交易转账结果") +@Data +public class TransactResultDto { + + @ApiModelProperty("转出币种") + private String out; + @ApiModelProperty("转入币种") + private String in; + @ApiModelProperty("转出币种剩余金额") + private BigDecimal outSurplus; + @ApiModelProperty("转入剩余金额") + private BigDecimal inSurplus; + + @ApiModelProperty("转出币种原金额") + private BigDecimal outOriginal; + @ApiModelProperty("转入原金额") + private BigDecimal inOriginal; + + @ApiModelProperty("交易金额") + private BigDecimal amount; + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/YyyfMoney.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/YyyfMoney.java new file mode 100644 index 0000000..02753a1 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/YyyfMoney.java @@ -0,0 +1,41 @@ +package com.blockchain.server.yyyf.entity; + +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author Mr.Xu + * @version 1.0 + * @className YyyfMoney + * @description + * @date 2020-05-26 21:30 + */ +@Table(name = "Yyyf_money") +@Data +public class YyyfMoney implements Serializable { + private static final long serialVersionUID = 8690026237757740821L; + @Id + @Column(name = "assess_user_id") + private String assessUserId; + @Column(name = "ali_pay") + private BigDecimal aliPay; + @Column(name = "wx_pay") + private BigDecimal wxPay; + @Column(name = "bank_card") + private BigDecimal bankCard; + @Column(name = "btc") + private BigDecimal btc; + @Column(name = "usdt") + private BigDecimal usdt; + @Column(name = "eth") + private BigDecimal eth; + + @Column(name = "update_time") + private Date updateTime; +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/UserEnums.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/UserEnums.java deleted file mode 100644 index aabde4a..0000000 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/UserEnums.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.blockchain.server.yyyf.enums; - -/** - * @author huangxl - * @data 2019/2/21 20:53 - */ -public enum UserEnums { - NO_INDICATORS_FOUND(1096,"查不到指标","No indicators found","查不到指標"), - PROHIBIT_DUPLICATE_SUBMISSION(1097,"禁止重复提交","Prohibit duplicate submission","禁止重複提交"), - USER_NOT_FORBID_OTHER_USER(1098, "禁止登录他人账号", "The user does not allow login other user's accout", "禁止登錄他人賬號"), - USER_NOT_BIND_YYYF(1099, "该用户未绑定以渔有方或者以渔有方登录已失效", "The user does not bind yyyf", "該用戶未綁定以漁有方或者以漁有方登錄已失效"), - USER_EXISTS(1100, "该用户已存在", "The user already exists", "該用戶已存在"), - USER_NOT_EXISTS(1101, "不存在该用户", "The user does not exist", "不存在該用戶"), - LOGIN_PASSWORD_ERROR(1102, "用户名密码错误", "Wrong username and password", "用戶名密碼錯誤"), - LOGIN_FORBIDDEN(1103, "你被列入黑名单,禁止登录", "You are blacklisted from logging in", "你被列入黑名單,禁止登錄"), - SMS_VERIFY_FAIL(1104, "手机号验证码错误", "Wrong verification code for mobile phone number", "手機號驗證碼錯誤"), - SMS_CODE_NOT_EXIST(1105, "请先获取验证码信息", "Please get the captcha information first", "請先獲取驗證碼資訊"), - PHONE_FORMAT_ERROR(1106, "手机号格式不正确", "The phone number format is not correct", "手機號格式不正確"), - FORMAT_ERROR(1106, "手机号或邮箱格式不正确", "The phone number or email format is not correct", "手機號或郵箱格式不正確"), - VERIFY_CODE_TYPE_ERROR(1107, "没有此类型短信", "There is no text message of this type", "沒有此類型短信"), - VERIFY_CODE_OVER_COUNT(1108, "今日获取验证码到达上限", "The upper limit of the captcha is reached today", "今日獲取驗證碼到達上限"), - USER_PHONE_EXISTS(1109, "该手机号或邮箱已存在", "The phone number or email address already exists", "該手機號或郵箱已存在"), - USER_PASSWORD_ERROR_FORMAT(1110, "密码只能是6-16位数字、字母和特殊字符的组合", "Passwords can only be 6-16 digit combinations of Numbers, letters, and special characters", "密碼只能是6-16位數字、字母和特殊字元的組合"), - INVALID_INVITATION_CODE(1111, "无效的邀请码信息", "Invalid invitation code information", "無效的邀請碼資訊"), - INVALID_NICK_NAME(1112, "昵称不能包含特殊字符", "Nicknames cannot contain special characters", "昵稱不能包含特殊字元"), - PHONE_NOT_CHANGE(1113, "手机号码与当前用户一致", "The phone number is the same as the current user", "手機號碼與當前用戶一致"), - GOOGLE_SECRET_KEY_FAIL(1114, "获取谷歌安全码失败", "Failed to get Google security code", "獲取穀歌安全碼失敗"), - GOOGLE_SECRET_KEY_EXIST(1115, "你已绑定谷歌验证器,请勿重复绑定", "You have bound the Google validator. Do not repeat the binding", "你已綁定穀歌驗證器,請勿重複綁定"), - GOOGLE_AUTH_FAIL(1116, "谷歌验证器验证失败", "Google verifier validation failed", "穀歌驗證器驗證失敗"), - FILE_UPLOAD_ERROR(1117, "文件上传失败", "File upload failed", "文檔上傳失敗"), - FILE_UPLOAD_LIMIT(1118, "文件上传失败,上传文件次数过多!", "File upload failed, too many times!", "文檔上傳失敗,上傳檔次數過多!"), - FILE_UPLOAD_FORMAT_ERROR(1119, "文件地址错误", "File address error", "文檔地址錯誤"), - FILE_UPLOAD_DEFICIENCY(1120, "请先上传文件", "Please upload the file first", "請先上傳文檔"), - AUTH_WAIT(1121, "认证审核中,请勿重复申请!", "Please do not repeat the application during the certification audit!", "認證審核中,請勿重複申請!"), - AUTH_YES(1122, "你已完成认证!", "You have completed the certification!", "你已完成認證!"), - AUTH_BASIC_BEFORE(1123, "请先完成初级认证!", "Please complete the primary certification first!", "請先完成初級認證!"), - EMAIL_FORMAT_ERROR(1124, "无效的邮箱格式!", "Invalid mailbox format!", "無效的郵箱格式!"), - EMAIL_VERIFY_FAIL(1125, "邮箱验证失败!", "Mailbox authentication failed!", "郵箱驗證失敗!"), - EMAIL_BIND_REPEAT(1126, "绑定失败,你已绑定邮箱", "Failed to bind. You have bound your mailbox", "綁定失敗,你已綁定郵箱"), - PASSWORD_EXIST(1127, "设置失败,你已经设置过密码了", "Setup failed. You have already set the password", "設置失敗,你已經設置過密碼了"), - EMAIL_EXIST(1128, "绑定失败,该邮箱已被绑定!", "The mailbox has been bound!", "綁定失敗,該郵箱已被綁定!"), - PASSWORD_NOT_MATCH(1129, "密码不匹配", "Password mismatch", "密碼不匹配"), - TRANSACTION_FORBIDDEN(1130, "你被列入黑名单,禁止交易!", "You're blacklisted! No trading!", "你被列入黑名單,禁止交易!"), - CANNOT_FOUND_INTERNATIONAL(1131, "找不到该国家信息", "Country information not available", "找不到該國家信息"), - VERIFY_CODE_DID_NOT_FIND(1034, "验证码已过期或没有获取", "The captcha is expired or not available", "驗證碼已過期或沒有獲取"), - VERIFY_CODE_DID_NOT_MATCH(1035, "您输入的验证码不匹配", "The verification code you entered does not match", "您輸入的驗證碼不匹配"), - WITHDRAW_FORBIDDEN(1136, "你被列入黑名单,禁止提现!", "You are blacklisted and no withdrawal is allowed!", "你被列入黑名單,禁止提現!"), - TRANSACTION_NOT_PASS_HIGH_AUTH(1137, "操作失败,您未通过高级认证!", "Operation failed. You did not pass advanced certification!", "操作失敗,您未通過高級認證!"), - TRANSACTION_NOT_PASS_LOW_AUTH(1137, "操作失败,您未通过初级认证!", "Operation failed. You did not pass primary certification!", "操作失敗,您未通過初級認證!"), - SEND_CODE_ERROR(1138, "验证码发送失败!", "Verification code failed to send!", "驗證碼發送失敗!"), - ; - - - private int code; - private String hkmsg; - private String enMsg; - private String cnmsg; - - UserEnums(int code, String cnmsg, String enMsg, String hkmsg) { - this.code = code; - this.cnmsg = cnmsg; - this.enMsg = enMsg; - this.hkmsg = hkmsg; - } - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getHkmsg() { - return hkmsg; - } - - public void setHkmsg(String hkmsg) { - this.hkmsg = hkmsg; - } - - public String getEnMsg() { - return enMsg; - } - - public void setEnMsg(String enMsg) { - this.enMsg = enMsg; - } - - public String getCnmsg() { - return cnmsg; - } - - public void setCnmsg(String cnmsg) { - this.cnmsg = cnmsg; - } -} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/YyyfEnums.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/YyyfEnums.java new file mode 100644 index 0000000..baa9dc8 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/YyyfEnums.java @@ -0,0 +1,59 @@ +package com.blockchain.server.yyyf.enums; + +/** + * @author huangxl + * @data 2019/2/21 20:53 + */ +public enum YyyfEnums { + MONEY_LOW(1094,"转出币种余额不足","Insufficient transfer out currency balance","轉出幣種餘額不足"), + FODBID_EXAM_RESTART(1095,"考试禁止重新开始","The exam is not allowed to restart","考試禁止重新開始"), + NO_INDICATORS_FOUND(1096,"查不到指标","No indicators found","查不到指標"), + PROHIBIT_DUPLICATE_SUBMISSION(1097,"禁止重复提交","Prohibit duplicate submission","禁止重複提交"), + + ; + + + private int code; + private String hkmsg; + private String enMsg; + private String cnmsg; + + YyyfEnums(int code, String cnmsg, String enMsg, String hkmsg) { + this.code = code; + this.cnmsg = cnmsg; + this.enMsg = enMsg; + this.hkmsg = hkmsg; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getHkmsg() { + return hkmsg; + } + + public void setHkmsg(String hkmsg) { + this.hkmsg = hkmsg; + } + + public String getEnMsg() { + return enMsg; + } + + public void setEnMsg(String enMsg) { + this.enMsg = enMsg; + } + + public String getCnmsg() { + return cnmsg; + } + + public void setCnmsg(String cnmsg) { + this.cnmsg = cnmsg; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/exceprion/UserException.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/exceprion/YyyfException.java similarity index 89% rename from blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/exceprion/UserException.java rename to blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/exceprion/YyyfException.java index 087f59a..dbfba74 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/exceprion/UserException.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/exceprion/YyyfException.java @@ -3,7 +3,7 @@ package com.blockchain.server.yyyf.exceprion; import com.blockchain.common.base.constant.BaseConstant; import com.blockchain.common.base.exception.BaseException; import com.blockchain.common.base.util.HttpRequestUtil; -import com.blockchain.server.yyyf.enums.UserEnums; +import com.blockchain.server.yyyf.enums.YyyfEnums; import lombok.Data; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -15,16 +15,16 @@ import javax.servlet.http.HttpServletRequest; * @data 2019/2/21 20:51 */ @Data -public class UserException extends BaseException { +public class YyyfException extends BaseException { protected int code; protected String msg; - public UserException(int code, String msg) { + public YyyfException(int code, String msg) { this.code = code; this.msg = msg; } - public UserException(UserEnums rs) { + public YyyfException(YyyfEnums rs) { ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); //可能是定时器调用,避免获取request空指针 if (servletRequestAttributes == null) { diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/YyyfMoneyMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/YyyfMoneyMapper.java new file mode 100644 index 0000000..ec6517b --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/YyyfMoneyMapper.java @@ -0,0 +1,16 @@ +package com.blockchain.server.yyyf.mapper; + +import com.blockchain.server.yyyf.entity.YyyfMoney; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + +/** + * @author Mr.Xu + * @version 1.0 + * @className YyyfMoneyMapper + * @description + * @date 2020-05-26 21:34 + */ +@Repository +public interface YyyfMoneyMapper extends Mapper { +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/YyyfMoneyService.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/YyyfMoneyService.java new file mode 100644 index 0000000..80098de --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/YyyfMoneyService.java @@ -0,0 +1,36 @@ +package com.blockchain.server.yyyf.service; + +import com.blockchain.server.yyyf.dto.TransactResultDto; +import com.blockchain.server.yyyf.entity.YyyfMoney; + +import java.math.BigDecimal; + +public interface YyyfMoneyService { + /** + * @description 交易转账 + * @author Mr.Xu + * @date 2020-05-26 21:51:15 + * @param [assessUserId, out, in, amount] + * @return com.blockchain.server.yyyf.dto.TransactResultDto + **/ + TransactResultDto transact(String assessUserId, String out, String in, BigDecimal amount); + + + /** + * @description 插入 + * @author Mr.Xu + * @date 2020-05-26 22:48:08 + * @param [yyyfMoney] + * @return void + **/ + void insert(YyyfMoney yyyfMoney); + + /** + * @description 更新 + * @author Mr.Xu + * @date 2020-05-26 22:48:19 + * @param [yyyfMoney] + * @return void + **/ + void update(YyyfMoney yyyfMoney); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java index ecfa677..627ffeb 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java @@ -7,10 +7,12 @@ import com.blockchain.server.yyyf.dto.ExamDto; import com.blockchain.server.yyyf.dto.YyyfStudentAnswerDto; import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.entity.AssessUserTarget; -import com.blockchain.server.yyyf.enums.UserEnums; -import com.blockchain.server.yyyf.exceprion.UserException; +import com.blockchain.server.yyyf.entity.YyyfMoney; +import com.blockchain.server.yyyf.enums.YyyfEnums; +import com.blockchain.server.yyyf.exceprion.YyyfException; import com.blockchain.server.yyyf.mapper.AssessUserMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; +import com.blockchain.server.yyyf.mapper.YyyfMoneyMapper; import com.blockchain.server.yyyf.service.AssessUserService; import com.blockchain.server.yyyf.utils.HttpClientUtil; import com.blockchain.server.yyyf.utils.IdGenerator; @@ -26,6 +28,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import tk.mybatis.mapper.entity.Example; +import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -50,6 +53,8 @@ public class AssessUserServiceImpl implements AssessUserService { private AssessUserMapper assessUserMapper; @Autowired private AssessUserTargetMapper assessUserTargetMapper; + @Autowired + private YyyfMoneyMapper yyyfMoneyMapper; @Value("${yyyf.url}") @@ -104,7 +109,20 @@ public class AssessUserServiceImpl implements AssessUserService { assessUserTarget.setId(IdGenerator.uuid()); list.add(assessUserTarget); } + + //区块链原始金额存入 + YyyfMoney yyyfMoney=new YyyfMoney(); + yyyfMoney.setAssessUserId(assessUser.getId()); + yyyfMoney.setAliPay(assessUser.getAlipayInitMoney()); + yyyfMoney.setWxPay(assessUser.getWechatInitMoney()); + yyyfMoney.setBankCard(assessUser.getBankcardInitMoney()); + yyyfMoney.setBtc(BigDecimal.ZERO); + yyyfMoney.setEth(BigDecimal.ZERO); + yyyfMoney.setUsdt(BigDecimal.ZERO); + yyyfMoney.setUpdateTime(new Date()); + this.assessUserMapper.insert(assessUser); + this.yyyfMoneyMapper.insert(yyyfMoney); this.assessUserTargetMapper.batchInsert(list); } @@ -120,7 +138,7 @@ public class AssessUserServiceImpl implements AssessUserService { AssessUser assessUser = this.selectAssessUserById(assessUserId); if (assessUser.getEndTime() != null) { - throw new UserException(UserEnums.PROHIBIT_DUPLICATE_SUBMISSION); + throw new YyyfException(YyyfEnums.PROHIBIT_DUPLICATE_SUBMISSION); } Double totalScore = 0d; //获取指标信息 diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/YyyfMoneyServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/YyyfMoneyServiceImpl.java new file mode 100644 index 0000000..4845280 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/YyyfMoneyServiceImpl.java @@ -0,0 +1,92 @@ +package com.blockchain.server.yyyf.service.impl; + +import com.blockchain.server.yyyf.dto.TransactResultDto; +import com.blockchain.server.yyyf.entity.YyyfMoney; +import com.blockchain.server.yyyf.enums.YyyfEnums; +import com.blockchain.server.yyyf.exceprion.YyyfException; +import com.blockchain.server.yyyf.mapper.YyyfMoneyMapper; +import com.blockchain.server.yyyf.service.YyyfMoneyService; +import lombok.SneakyThrows; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.lang.reflect.Method; +import java.math.BigDecimal; + +/** + * @author Mr.Xu + * @version 1.0 + * @className YyyfMoneyServiceImpl + * @description + * @date 2020-05-26 21:36 + */ +@Transactional(rollbackFor = Exception.class) +@Service +public class YyyfMoneyServiceImpl implements YyyfMoneyService { + + + @Autowired + private YyyfMoneyMapper yyyfMoneyMapper; + + + @SneakyThrows + @Override + public TransactResultDto transact(String assessUserId, String out, String in, BigDecimal amount) { + + YyyfMoney yyyfMoney = this.yyyfMoneyMapper.selectByPrimaryKey(assessUserId); + BigDecimal outOriginal = null; + BigDecimal inOriginal = null; + Class aClass = yyyfMoney.getClass(); + + String outField = out.substring(0, 1).toUpperCase().concat(out.substring(1)); + String inField = in.substring(0, 1).toUpperCase().concat(in.substring(1)); + + Method outGetMethod = aClass.getMethod("get".concat(outField)); + //转出的原始金额 + outOriginal = (BigDecimal) outGetMethod.invoke(yyyfMoney); + + Method inGetMethod = aClass.getMethod("get".concat(inField)); + //转入的原始金额 + inOriginal = (BigDecimal) inGetMethod.invoke(yyyfMoney); + + if (outOriginal.compareTo(amount) == -1) { + throw new YyyfException(YyyfEnums.MONEY_LOW); + } + //转出币种后的余额 + BigDecimal outSurplus = outOriginal.subtract(amount); + //转入币种后的余额 + BigDecimal inSurplus = inOriginal.add(amount); + + Method outSetMethod = aClass.getMethod("set".concat(outField),BigDecimal.class); + Method inSetMethod = aClass.getMethod("set".concat(inField),BigDecimal.class); + + outSetMethod.invoke(yyyfMoney,outSurplus); + inSetMethod.invoke(yyyfMoney,inSurplus); + + this.yyyfMoneyMapper.updateByPrimaryKeySelective(yyyfMoney); + + TransactResultDto transactResultDto = new TransactResultDto(); + + transactResultDto.setAmount(amount); + transactResultDto.setOut(out); + transactResultDto.setOutOriginal(outOriginal); + transactResultDto.setOutSurplus(outSurplus); + transactResultDto.setIn(in); + transactResultDto.setInOriginal(inOriginal); + transactResultDto.setInSurplus(inSurplus); + + + return transactResultDto; + } + + @Override + public void insert(YyyfMoney yyyfMoney) { + this.yyyfMoneyMapper.insert(yyyfMoney); + } + + @Override + public void update(YyyfMoney yyyfMoney) { + this.yyyfMoneyMapper.updateByPrimaryKeySelective(yyyfMoney); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/YyyfMoneyMapper.xml b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/YyyfMoneyMapper.xml new file mode 100644 index 0000000..d52d2f6 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/YyyfMoneyMapper.xml @@ -0,0 +1,5 @@ + + + + +