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 79e48bc..ccf5628 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 @@ -32,5 +32,10 @@ public class YyyfConstant { /**以渔有方与智信链用户绑定的cookies*/ public static final String YYYF_ZHIXINLIAN_USER_KEY="yyyfZhixinlianUserKey"; + /**注册的key*/ + public static final String REGISTER_KEY = "user:sms:register:"; + /**注册码的时效性*/ + public static final int TIME_OUT=10; + } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/inner/BtcWalletInner.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/inner/BtcWalletInner.java index b30d97b..f8bd558 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/inner/BtcWalletInner.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/inner/BtcWalletInner.java @@ -1,6 +1,10 @@ package com.blockchain.server.btc.inner; import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.common.base.util.SSOHelper; +import com.blockchain.server.btc.common.constants.BtcApplicationConstans; +import com.blockchain.server.btc.controller.api.BtcWalletApi; +import com.blockchain.server.btc.dto.BtcWalletDTO; import com.blockchain.server.btc.inner.api.BtcWalletInnerApi; import com.blockchain.server.btc.service.BtcWalletService; import io.swagger.annotations.Api; @@ -12,6 +16,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletRequest; +import java.util.List; + @Api(BtcWalletInnerApi.MARKET_CONTROLLER_API) @RestController @RequestMapping("/inner/wallet") @@ -26,4 +33,10 @@ public class BtcWalletInner { return ResultDTO.requstSuccess(btcWalletService.insertWallet(userOpenId)); } -} \ No newline at end of file + @GetMapping("/getWallets") + public ResultDTO> getWallets(@RequestParam("userId") String userId, + @RequestParam("walletType") String walletType) { + return ResultDTO.requstSuccess(btcWalletService.selectAllByUserOpenId(userId, walletType)); + } + +} diff --git a/blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/inner/CurrencyMarketInnerController.java b/blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/inner/CurrencyMarketInnerController.java index 375ad8b..57626c2 100644 --- a/blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/inner/CurrencyMarketInnerController.java +++ b/blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/inner/CurrencyMarketInnerController.java @@ -1,6 +1,7 @@ package com.blockchain.server.currency.inner; import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.server.currency.dto.CurrencyMarketDTO; import com.blockchain.server.currency.inner.api.CurrencyMarketInnerApi; import com.blockchain.server.currency.service.CurrencyMarketService; import io.swagger.annotations.Api; @@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; import java.util.Date; +import java.util.List; @Api(CurrencyMarketInnerApi.MARKET_CONTROLLER_API) @RestController @@ -36,4 +38,9 @@ public class CurrencyMarketInnerController { return ResultDTO.requstSuccess(null); } + @RequestMapping(value = "/getList", method = RequestMethod.GET) + public List getList() { + return currencyMarketService.getList(); + } + } diff --git a/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/inner/EosWalletInnerController.java b/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/inner/EosWalletInnerController.java index 0f08afb..5436ed7 100644 --- a/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/inner/EosWalletInnerController.java +++ b/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/inner/EosWalletInnerController.java @@ -3,6 +3,8 @@ package com.blockchain.server.eos.inner; import com.blockchain.common.base.dto.ResultDTO; import com.blockchain.common.base.dto.WalletChangeDTO; import com.blockchain.common.base.dto.WalletOrderDTO; +import com.blockchain.common.base.util.SSOHelper; +import com.blockchain.server.eos.dto.WalletDTO; import com.blockchain.server.eos.inner.api.EosWalletApi; import com.blockchain.server.eos.service.EosWalletService; import io.swagger.annotations.Api; @@ -13,6 +15,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; +import java.util.List; + /** * @author Harvey * @date 2019/2/19 18:09 @@ -49,4 +54,10 @@ public class EosWalletInnerController { return ResultDTO.requstSuccess(); } + @GetMapping("/selectWalletByWalletType") + public ResultDTO> selectWalletByWalletType(@RequestParam("userOpenId") String userOpenId, + @RequestParam("walletType") String walletType) { + return ResultDTO.requstSuccess(eosWalletService.listWalletByWalletType(walletType, userOpenId)); + } + } diff --git a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/ConfigWalletParamInner.java b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/ConfigWalletParamInner.java new file mode 100644 index 0000000..c71e679 --- /dev/null +++ b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/ConfigWalletParamInner.java @@ -0,0 +1,24 @@ +package com.blockchain.server.eth.inner; + +import com.blockchain.common.base.dto.GasDTO; +import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.server.eth.common.constants.EthConfigConstants; +import com.blockchain.server.eth.service.IConfigWalletParamService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/inner/walletParam") +public class ConfigWalletParamInner { + @Autowired + private IConfigWalletParamService walletParamService; + + @GetMapping("/getGasConfig") + public ResultDTO getGasConfig(@RequestParam(value = "tokenSymbol", defaultValue = EthConfigConstants.MODULE_TYPE) String tokenSymbol) { + return ResultDTO.requstSuccess(walletParamService.getGasConfig(tokenSymbol)); + } + +} diff --git a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java index 2d166b6..672dda1 100644 --- a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java +++ b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java @@ -1,13 +1,9 @@ package com.blockchain.server.eth.inner; import com.blockchain.common.base.dto.ResultDTO; -import com.blockchain.common.base.dto.SessionUserDTO; import com.blockchain.common.base.util.SSOHelper; -import com.blockchain.server.eth.common.enums.EthWalletEnums; -import com.blockchain.server.eth.common.exception.EthWalletException; -import com.blockchain.server.eth.common.util.RedisPrivateUtil; +import com.blockchain.server.eth.dto.EthWalletDTO; import com.blockchain.server.eth.inner.api.EthWalletApi; -import com.blockchain.server.eth.service.IEthWalletKeyService; import com.blockchain.server.eth.service.IEthWalletService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -16,10 +12,13 @@ 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.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; -import java.util.Date; +import java.util.List; /** * @author YH @@ -60,4 +59,10 @@ public class EthWalletInner { return ResultDTO.requstSuccess(); } + @GetMapping("/getWallets") + public ResultDTO> getWallets(@RequestParam("userId") String userId, + @RequestParam(name = "walletType", required = false) String walletType) { + return ResultDTO.requstSuccess(ethWalletService.selectByUserOpenIdAndWalletType(userId, walletType)); + } + } 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 b9da86a..ec74eb8 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 @@ -19,8 +19,8 @@ import com.blockchain.server.user.common.utils.EmailCodeUtils; 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.AssessUser; import com.blockchain.server.user.entity.UserMain; -import com.blockchain.server.user.entity.YyyfUser; import com.blockchain.server.user.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -60,9 +60,8 @@ public class LoginController { private SmsCodeUtils smsCodeUtils; @Autowired private RedisTemplate redisTemplate; - @Autowired - private YyyfUserService yyyfUserService; + private AssessUserService assessUserService; @PostMapping("/password") @ApiOperation(value = LoginApi.PassWorldLogin.METHOD_NAME, @@ -72,7 +71,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), request); + return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); } @PostMapping("/loginByCode") @@ -86,7 +85,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), request); + return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); } @PostMapping("/register") @@ -104,7 +103,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), request); + return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); } @PostMapping("/sendLoginCode") @@ -169,21 +168,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, HttpServletRequest request) { + @ApiParam(LoginApi.PassWorldLoginPC.METHOD_API_PASS) @RequestParam(name = "password") String password) { UserMain userMain = userLoginService.handleLoginByPassword(tel, password); - return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); + return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); } @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, HttpServletRequest request) { + @ApiParam(LoginApi.SmsCodeLoginPC.METHOD_API_CODE) @RequestParam(name = "code") String code) { 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(), request); + return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); } @PostMapping("/register2") @@ -194,13 +193,15 @@ 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, HttpServletRequest request + @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(), request); + //处理区块链用户id + dealBindYyyfAccount(userMain.getId(),request); + return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); } @PostMapping("/loginout2") @@ -218,12 +219,11 @@ public class LoginController { * @param tel 手机号 * @param timestamp 时间撮 */ - private void setUserToRedis(String id, String tel, long timestamp, String tokenType, Integer yyyfUserId) { + private void setUserToRedis(String id, String tel, long timestamp, String tokenType) { SessionUserDTO userDTO = new SessionUserDTO(); userDTO.setId(id); userDTO.setTel(tel); userDTO.setTimestamp(timestamp); - userDTO.setYyyfUserId(yyyfUserId); SSOHelper.setUser(userDTO, redisTemplate, tokenType); } @@ -245,10 +245,10 @@ public class LoginController { /** * App登录成功之后的处理 */ - private ResultDTO handleAppAfterLogin(UserMain userMain, String clientId, String userLocale, HttpServletRequest request) { + private ResultDTO handleAppAfterLogin(UserMain userMain, String clientId, String userLocale) { //保存用户客户端信息,用于消息通知 handleAfterLoginToSavePushUser(userMain.getId(), clientId, userLocale); - return handleAfterLogin(userMain, TokenTypeEnums.APP.getValue(), request); + return handleAfterLogin(userMain, TokenTypeEnums.APP.getValue()); } /*** @@ -272,11 +272,9 @@ public class LoginController { /** * 登录成功之后的处理 */ - private ResultDTO handleAfterLogin(UserMain userMain, String tokenType, HttpServletRequest request) { - - String userId = userMain.getId(); + private ResultDTO handleAfterLogin(UserMain userMain, String tokenType) { long timestamp = System.currentTimeMillis(); - setUserToRedis(userMain.getId(), userMain.getMobilePhone(), timestamp, tokenType, dealBindYyyfAccount(userId, userMain.getMobilePhone(), request)); + setUserToRedis(userMain.getId(), userMain.getMobilePhone(), timestamp, tokenType); String token = generateToken(userMain.getMobilePhone(), timestamp, tokenType); UserBaseDTO userBaseDTO = userMainService.selectUserInfoById(userMain.getId()); userBaseDTO.setToken(token); @@ -317,26 +315,21 @@ public class LoginController { return ResultDTO.requstSuccess(); } + + /** - * @param [userId, tel, request] + * @param [userId, request] * @return java.lang.String * @description 处理yyyf账号绑定 **/ - private Integer dealBindYyyfAccount(String userId, String tel, HttpServletRequest request) { + private Integer dealBindYyyfAccount(String userId,HttpServletRequest request) { Integer yyyfUserId = null; YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate); //如果有token,拿到用户信息,与以渔有方进行绑定 if (yyyfUserDto != null) { - yyyfUserId = yyyfUserDto.getUserId(); - YyyfUser yyyfUser = this.yyyfUserService.selectByYyyfUserIdAndTel(yyyfUserId, tel); - if (yyyfUser == null) { - this.yyyfUserService.saveUser(yyyfUserId, userId,tel, yyyfUserDto.getUserName()); - // this.redisTemplate.delete(yyyfTtoken); - } else { - if (!yyyfUser.getUserId().equals(userId)) { - throw new UserException(UserEnums.USER_NOT_FORBID_OTHER_USER); - } - } + AssessUser assessUser = assessUserService.selectAssessUserById(yyyfUserDto.getAssessUserId()); + assessUser.setQUserId(userId); + assessUserService.update(assessUser); //通过当前用户id与以渔有方用户关联 redisTemplate.opsForValue().set(BaseConstant.USER_ID_YYYF_USER_KEY.concat(userId),yyyfUserDto); } else { diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/AssessUser.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/AssessUser.java new file mode 100644 index 0000000..8e47bcf --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/AssessUser.java @@ -0,0 +1,146 @@ +package com.blockchain.server.user.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; + +@Table(name = "yyyf_server_assess_user") +@Data +public class AssessUser implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "id") + private String id; + + /** + * 子系统id + */ + @Column(name = "train_id") + private String trainId="0001"; + + /** + * 已发布id + */ + @Column(name = "issue_id") + private String issueId; + + /** + * 子系统练习id(练习才会用到) + */ + @Column(name = "ss_practise_id") + private String ssPractiseId; + + + /** + * 用户id + */ + @Column(name = "user_id") + private Integer userId; + + + /** + * 区块链用户id + */ + @Column(name = "q_user_id") + private String qUserId; + + /** + * 得分 + */ + @Column(name = "total_score") + private Double totalScore; + /** + * 时长 + */ + @Column(name = "duration") + private Integer duration; + /** + * 时长单位 + */ + @Column(name = "duration_unit") + private String durationUnit="m"; + /** + * 开始时间 + */ + @Column(name = "start_time") + private Date startTime; + /** + * 结束时间 + */ + @Column(name = "end_time") + private Date endTime; + /** + * 案例id + */ + @Column(name = "case_id") + private String caseId; + + /** + * 0 练习 1考核 + */ + @Column(name = "achieve_ment_type") + private Integer achieveMentType; + + /** + * 绑定班级 + */ + @Column(name = "class_id") + private String classId; + + /** + * 绑定的课程id + */ + @Column(name = "course_id") + private String courseId; + /** + * 绑定的课程id + */ + @Column(name = "user_name") + private String userName; + + /** + * 用户类型:0学生,1老师,2管理员 + */ + @Column(name = "user_Type") + private Integer userType; + + /** + * 微信账户初始资金 + */ + @Column(name = "wechat_init_money") + private BigDecimal wechatInitMoney; + /** + * 支付宝账户初始资金 + */ + @Column(name = "alipay_init_money") + private BigDecimal alipayInitMoney; + /** + * 银行卡账户初始资金 + */ + @Column(name = "bankcard_init_money") + private BigDecimal bankcardInitMoney; + /** + * 数字钱包初始资产 + */ + @Column(name = "digitwallet_init_money") + private BigDecimal digitwalletInitMoney; + + /** + * 区块链账号 + */ + @Column(name = "tel") + private String tel; + /** + * 密码 + */ + @Column(name = "password") + private String password; +} 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 deleted file mode 100644 index 8170da3..0000000 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java +++ /dev/null @@ -1,50 +0,0 @@ -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; - - /** - * 手机号码 - */ - @Column(name = "mobile_phone") - private String mobilePhone; - - -} \ No newline at end of file diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/AssessUserMapper.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/AssessUserMapper.java new file mode 100644 index 0000000..74dd063 --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/AssessUserMapper.java @@ -0,0 +1,12 @@ +package com.blockchain.server.user.mapper; + + +import com.blockchain.server.user.entity.AssessUser; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface AssessUserMapper extends Mapper { + +} \ 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 deleted file mode 100644 index 8818546..0000000 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/YyyfUserMapper.java +++ /dev/null @@ -1,16 +0,0 @@ -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/AssessUserService.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/AssessUserService.java new file mode 100644 index 0000000..877620e --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/AssessUserService.java @@ -0,0 +1,62 @@ +package com.blockchain.server.user.service; + + + + +import com.blockchain.server.user.entity.AssessUser; + +import java.util.List; + +/** + * @param + * @author huan.xu + * @description 学生用户考核信息表 服务接口类 + * @date 2019-10-31 14:36:49 + * @return + **/ +public interface AssessUserService { + + + + + + + /** + * @description 根据 assessUser 表的id查询assessUser + * @param [assessUserId] + * @return com.gtafeyyyf.model.AssessUser + **/ + AssessUser selectAssessUserById(String assessUserId); + + + + + /** + * @description 插入 + * @author Mr.Xu + * @date 2020-05-13 22:37:12 + * @param [assessUser] + * @return void + **/ + void insert(AssessUser assessUser); + + + + /** + * @description 更新数据 + * @author Mr.Xu + * @date 2020-05-14 22:03:02 + * @param [assessUser] + * @return void + **/ + void update(AssessUser assessUser); + + /** + * @description 根据assessUserId获取答题总表 + * @author Mr.Xu + * @date 2020-06-01 21:51:09 + * @param [assessUserId] + * @return com.blockchain.server.user.entity.AssessUser + **/ + AssessUser selectById(String assessUserId); +} 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 deleted file mode 100644 index 326058f..0000000 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.blockchain.server.user.service; - -import com.blockchain.server.user.entity.YyyfUser; - -/** - * @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 tel,String yyyfName); - - /** - * @description - * @author Mr.Xu - * @date 2020/5/4 13:42 - * @param [yyyfUserId, tel] - * @return com.blockchain.server.user.entity.YyyfUser - **/ - YyyfUser selectByYyyfUserIdAndTel(Integer yyyfUserId, String tel); - -} diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/AssessUserServiceImpl.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/AssessUserServiceImpl.java new file mode 100644 index 0000000..0e876ba --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/AssessUserServiceImpl.java @@ -0,0 +1,72 @@ +package com.blockchain.server.user.service.impl; + +import com.blockchain.common.base.constant.YyyfConstant; + +import com.blockchain.server.user.entity.AssessUser; +import com.blockchain.server.user.mapper.AssessUserMapper; +import com.blockchain.server.user.service.AssessUserService; +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.beans.factory.annotation.Value; +import org.springframework.data.redis.core.HashOperations; +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.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * @author huan.xu + * @version 1.0 + * @className AssessUserServiceImpl + * @description 学生用户考核信息表 服务实现类 + * @date 2019-10-31 14:34 + */ +@Transactional(rollbackFor = Exception.class) +@Service +public class AssessUserServiceImpl implements AssessUserService { + private static Logger LOG = LoggerFactory.getLogger(AssessUserServiceImpl.class); + + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + private AssessUserMapper assessUserMapper; + + + + @Override + public AssessUser selectAssessUserById(String assessUserId) { + + return this.assessUserMapper.selectByPrimaryKey(assessUserId); + } + + + + @Override + public void insert(AssessUser assessUser) { + this.assessUserMapper.insertSelective(assessUser); + } + + @Override + public void update(AssessUser assessUser) { + this.assessUserMapper.updateByPrimaryKey(assessUser); + } + + + + @Override + public AssessUser selectById(String assessUserId) { + return this.assessUserMapper.selectByPrimaryKey(assessUserId); + } + + +} \ No newline at end of file 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 deleted file mode 100644 index 400941a..0000000 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -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 tel, String yyyfName) { - YyyfUser yyyfUser=new YyyfUser(); - yyyfUser.setYyyfUserId(yyyfUserId); - yyyfUser.setUserId(userId); - yyyfUser.setMobilePhone(tel); - yyyfUser.setYyyfUserName(yyyfName); - yyyfUser.setCreateTime(new Date()); - this.yyyfUserMapper.insert(yyyfUser); - } - - @Override - public YyyfUser selectByYyyfUserIdAndTel(Integer yyyfUserId, String tel) { - Example example=new Example(YyyfUser.class); - Example.Criteria criteria=example.createCriteria(); - criteria.andCondition("yyyf_user_id = " ,yyyfUserId) - .andCondition("mobile_phone = ",tel); - return this.yyyfUserMapper.selectOneByExample(example); - } - - -} diff --git a/blockchain-server/blockchain-server-user/src/main/resources/mapper/AssessUserMapper.xml b/blockchain-server/blockchain-server-user/src/main/resources/mapper/AssessUserMapper.xml new file mode 100644 index 0000000..0bd96a1 --- /dev/null +++ b/blockchain-server/blockchain-server-user/src/main/resources/mapper/AssessUserMapper.xml @@ -0,0 +1,5 @@ + + + + + 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 deleted file mode 100644 index 7fb5639..0000000 --- a/blockchain-server/blockchain-server-user/src/main/resources/mapper/YyyfUserMapper.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/pom.xml b/blockchain-server/blockchain-server-yyyf/pom.xml index 0753e77..220da63 100644 --- a/blockchain-server/blockchain-server-yyyf/pom.xml +++ b/blockchain-server/blockchain-server-yyyf/pom.xml @@ -68,6 +68,11 @@ poi-ooxml-schemas 3.10-FINAL + + cn.hutool + hutool-core + 5.3.6 + @@ -87,4 +92,4 @@ - \ No newline at end of file + diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/ExamController.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/ExamController.java index fd461c1..3e607eb 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/ExamController.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/ExamController.java @@ -6,6 +6,8 @@ import com.blockchain.common.base.dto.YyyfUserDto; import com.blockchain.common.base.util.YyyfUserDtoUtils; import com.blockchain.server.yyyf.controller.api.ExamApi; import com.blockchain.server.yyyf.dto.AssessUserDto; +import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; +import com.blockchain.server.yyyf.dto.YyyfLoginDto; import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.entity.AssessUserTarget; import com.blockchain.server.yyyf.entity.YyyfMoney; @@ -26,7 +28,9 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Random; import java.util.concurrent.TimeUnit; /** @@ -62,7 +66,6 @@ public class ExamController { AssessUserTarget assessUserTarget = this.assessUserTargetService.selectByAssessUserAndCode(assessUserId, code); Integer answer = -1; if (assessUserTarget != null) { - assessUserTarget.setStudentRate(taskRate); int compareAnswer = taskRate.compareTo(assessUserTarget.getTaskRate()); //最终指标结果一致 @@ -103,7 +106,7 @@ public class ExamController { @GetMapping("/reStart") @ApiOperation(value = ExamApi.Restart.METHOD_NAME, notes = ExamApi.Restart.METHOD_NOTE) - public ResultDTO reStart(HttpServletRequest request) { + public ResultDTO reStart(HttpServletRequest request) { YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate); String assessUserId = yyyfUserDto.getAssessUserId(); @@ -112,7 +115,20 @@ public class ExamController { throw new YyyfException(YyyfEnums.FODBID_EXAM_RESTART); } Date now=new Date(); + //系统账户初始化 + String tel=new SimpleDateFormat("yyMMddHHmmss").format(now).concat(String.valueOf(yyyfUserDto.getUserId())); + //第一次进入进行注册 + String code=String.format("%06d",new Random().nextInt(1000000)); + redisTemplate.opsForValue().set(YyyfConstant.REGISTER_KEY.concat(tel),code,YyyfConstant.TIME_OUT, TimeUnit.MINUTES); + //本系统密码 + String password=String.format("%08d",new Random().nextInt(10000000)); + + assessUser.setTel(tel); + assessUser.setPassword(password); assessUser.setStartTime(now); + assessUser.setEndTime(null); + + this.assessUserService.update(assessUser); //区块链原始金额还原 @@ -124,11 +140,32 @@ public class ExamController { yyyfMoney.setBtc(BigDecimal.ZERO); yyyfMoney.setEth(BigDecimal.ZERO); yyyfMoney.setUsdt(BigDecimal.ZERO); + yyyfMoney.setEos(BigDecimal.ZERO); yyyfMoney.setUpdateTime(now); this.yyyfMoneyService.update(yyyfMoney); - return ResultDTO.requstSuccess(); + this.assessUserTargetService.restoreByAssessUserId(assessUserId); + + YyyfLoginDto yyyfLoginDto = new YyyfLoginDto(); + yyyfLoginDto.setCode(code); + yyyfLoginDto.setTel(tel); + yyyfLoginDto.setPassword(password); + + return ResultDTO.requstSuccess(yyyfLoginDto); } + + + @SneakyThrows + @GetMapping("/getUserTimeMoneyDto") + @ApiOperation(value = ExamApi.GetUserTimeMoneyDto.METHOD_NAME, + notes = ExamApi.GetUserTimeMoneyDto.METHOD_NOTE) + public ResultDTO getUserTimeMoneyDto(HttpServletRequest request) { + + YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate); + String assessUserId = yyyfUserDto.getAssessUserId(); + UserTimeMoneyDto userTimeMoneyDto =this.assessUserService.getUserTimeMoneyDtoByAssessUserId(assessUserId); + return ResultDTO.requstSuccess(userTimeMoneyDto); + } } 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 25d6ae0..a54c6c3 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 @@ -44,11 +44,6 @@ public class LoginController { private static final Logger LOG = LoggerFactory.getLogger(LoginController.class); - private static final String REGISTER_KEY = "user:sms:register:"; - - private static final int TIME_OUT=10; - - @Autowired private AssessUserService assessUserService; @@ -104,11 +99,11 @@ public class LoginController { AssessUser assessUser = this.assessUserService.selectAssessUserByUserIdAndissueIdForNotEnd(userId, examId); if (assessUser == null) { Date now = new Date(); - String tel=new SimpleDateFormat("yyMMddHHmm").format(now).concat(String.valueOf(userId)); + String tel=new SimpleDateFormat("yyMMddHHmmss").format(now).concat(String.valueOf(userId)); //第一次进入进行注册 String code=String.format("%06d",new Random().nextInt(1000000)); - redisTemplate.opsForValue().set(REGISTER_KEY.concat(tel),code,TIME_OUT, TimeUnit.MINUTES); + redisTemplate.opsForValue().set(YyyfConstant.REGISTER_KEY.concat(tel),code,YyyfConstant.TIME_OUT, TimeUnit.MINUTES); yyyfLoginDto.setCode(code); String password=String.format("%08d",new Random().nextInt(10000000)); @@ -168,32 +163,51 @@ public class LoginController { examDto.setExamPaperId(examPaperId); examDtoOpsForHash.put(YyyfConstant.EXAM_KEY, examId, examDto); } - + yyyfLoginDto.setRemainingTime((examDto.getEndTime().getTime() - new Date().getTime() )/ 1000); joinStuIds = studentOpsForHash.get(YyyfConstant.JOIN_EXAM_STU_IDS_KEY, examId); if (joinStuIds == null) { joinStuIds = new ArrayList(); } + + Map map = new HashMap(); + map.put("examPaperId", examDto.getExamPaperId()); + map.put("examId", examDto.getExamId()); + + redisTemplate.opsForValue().set(caseKey, map); + redisTemplate.expire(caseKey, 30, TimeUnit.DAYS); + //如果等于0 if (joinStuIds.stream() .filter(stuIds -> (stuIds.equals(userId))).count() == 0) { joinStuIds.add(userId); studentOpsForHash.put(YyyfConstant.JOIN_EXAM_STU_IDS_KEY, examId, joinStuIds); } else { - yyyfLoginDto.setStatus(1); + yyyfLoginDto.setStatus(3); yyyfLoginDto.setMsg(YyyfConstant.NO_ENTRY_INTO_PRACTICE); return handleAfterLogin(yyyfLoginDto, yyyfUserDto); } } else { - + String jioinExamId=null; if (redisTemplate.hasKey(caseKey)) { Map examMsgMap = (Map) redisTemplate.opsForValue().get(caseKey); - joinStuIds = studentOpsForHash.get(YyyfConstant.JOIN_EXAM_STU_IDS_KEY, examMsgMap.get("examId")); + jioinExamId= examMsgMap.get("examId"); + joinStuIds = studentOpsForHash.get(YyyfConstant.JOIN_EXAM_STU_IDS_KEY,jioinExamId); } //缓存是考试,要进入练习,则不让进入 if (joinStuIds != null && joinStuIds.stream() .filter(stuIds -> (stuIds.equals(userId))).count() != 0) { - yyyfLoginDto.setStatus(1); + yyyfLoginDto.setStatus(3); yyyfLoginDto.setMsg(YyyfConstant.NO_ENTRY_INTO_PRACTICE); + ExamDto examDto = examDtoOpsForHash.get(YyyfConstant.EXAM_KEY, examId); + yyyfLoginDto.setRemainingTime((examDto.getEndTime().getTime() - new Date().getTime() )/ 1000); + + Map map = new HashMap(); + map.put("examPaperId", examDto.getExamPaperId()); + map.put("examId", examDto.getExamId()); + + redisTemplate.opsForValue().set(caseKey, map); + redisTemplate.expire(caseKey, 30, TimeUnit.DAYS); + return handleAfterLogin(yyyfLoginDto, yyyfUserDto); } @@ -201,14 +215,6 @@ public class LoginController { } //删除强制提醒的缓存 // redisTemplate.delete(YyyfConstant.ANSER_KEY + userId); - - - Map map = new HashMap(); - map.put("examPaperId", examPaperId); - map.put("examId", examId); - - redisTemplate.opsForValue().set(caseKey, map); - redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); yyyfLoginDto.setStatus(1); } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/ExamApi.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/ExamApi.java index 638a14c..538fff7 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/ExamApi.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/ExamApi.java @@ -25,4 +25,9 @@ public class ExamApi { public static final String METHOD_NAME = "重新开始练习"; public static final String METHOD_NOTE = "重新开始练习,若考试则抛出异常 "; } + + public static class GetUserTimeMoneyDto { + 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/dto/UserTimeMoneyDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/UserTimeMoneyDto.java new file mode 100644 index 0000000..08d6d7e --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/UserTimeMoneyDto.java @@ -0,0 +1,38 @@ +package com.blockchain.server.yyyf.dto; + +import com.blockchain.server.yyyf.entity.YyyfMoney; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author Mr.Xu + * @version 1.0 + * @className UserTimeMoneyDto + * @description 包含以渔有方userId、本系统userId、开始时间以及各个币种余额情况 + * @date 2020-06-01 21:23 + */ +@ApiModel("用户余额Dto") +@Data +@EqualsAndHashCode(callSuper = true) +public class UserTimeMoneyDto extends YyyfMoney implements Serializable { + + private static final long serialVersionUID = 5093452353347277920L; + @ApiModelProperty("以渔有方用户id") + private Integer userId; + @ApiModelProperty("本系统用户id") + private String qUserId; + @ApiModelProperty("开始时间") + private Date startTime; + @ApiModelProperty("支付宝初始资金") + private BigDecimal aliPayInit; + @ApiModelProperty("微信支付初始资金") + private BigDecimal wxPayInit; + @ApiModelProperty("银行卡初始资金") + private BigDecimal bankCardInit; +} 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 618d3c9..97633de 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 @@ -14,7 +14,7 @@ public class YyyfLoginDto implements Serializable { @ApiModelProperty("提示信息") private String msg; - @ApiModelProperty("状态:0,失败,1成功,2 考试提交后重复进入,3 练习未提交提醒") + @ApiModelProperty("状态:0,失败,1成功,2 考试提交后重复进入,3 考试未完成提醒") private int status; /*@ApiModelProperty("练习重新开始参数封装") @@ -33,4 +33,6 @@ public class YyyfLoginDto implements Serializable { @ApiModelProperty("昵称") private String nickName; + @ApiModelProperty("剩余时间") + private Long remainingTime; } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUser.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUser.java index 3e03f41..f3e8485 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUser.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUser.java @@ -44,6 +44,14 @@ public class AssessUser implements Serializable { */ @Column(name = "user_id") private Integer userId; + + + /** + * 区块链用户id + */ + @Column(name = "q_user_id") + private String qUserId; + /** * 得分 */ 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 index 02753a1..79ac6df 100644 --- 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 @@ -33,6 +33,8 @@ public class YyyfMoney implements Serializable { private BigDecimal btc; @Column(name = "usdt") private BigDecimal usdt; + @Column(name = "eos") + private BigDecimal eos; @Column(name = "eth") private BigDecimal eth; diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java new file mode 100644 index 0000000..6a9e3b2 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java @@ -0,0 +1,18 @@ +package com.blockchain.server.yyyf.feign; + +import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.server.yyyf.feign.dto.BtcWalletDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; + +@FeignClient("dapp-btc-server") +public interface BtcFeign { + String CONTENT_PATH = "/inner/wallet"; + + @PostMapping(CONTENT_PATH + "/getWallets") + ResultDTO> getWallets(@RequestParam("userId") String userId, + @RequestParam("walletType") String walletType); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java new file mode 100644 index 0000000..c631a0c --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java @@ -0,0 +1,13 @@ +package com.blockchain.server.yyyf.feign; + +import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.server.yyyf.feign.dto.CurrencyMarketDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@FeignClient(name = "dapp-currency-server") +public interface CurrencyFeign { + @GetMapping("/inner/market/getList") + ResultDTO getList(@RequestParam("currencyPair") String currencyPair); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java new file mode 100644 index 0000000..e29f7c3 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java @@ -0,0 +1,14 @@ +package com.blockchain.server.yyyf.feign; + +import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.server.yyyf.feign.dto.EosWalletDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +import java.util.List; + +@FeignClient("dapp-eos-server") +public interface EosFeign { + @GetMapping("/inner/walletTx/selectWalletByWalletType") + ResultDTO> selectWalletByWalletType(String userOpenId, String walletType); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java new file mode 100644 index 0000000..3fff3ae --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java @@ -0,0 +1,20 @@ +package com.blockchain.server.yyyf.feign; + +import com.blockchain.common.base.dto.GasDTO; +import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.server.yyyf.feign.dto.EthWalletDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; + +@FeignClient("dapp-eth-server") +public interface EthFeign { + @GetMapping("/inner/wallet/getWallets") + ResultDTO> getWallets(@RequestParam("userId") String userId, + @RequestParam(name = "walletType") String walletType); + + @GetMapping("/inner/walletParam/getGasConfig") + ResultDTO getGasConfig(String tokenSymbol); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/BtcWalletDTO.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/BtcWalletDTO.java new file mode 100644 index 0000000..3a8322c --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/BtcWalletDTO.java @@ -0,0 +1,29 @@ +package com.blockchain.server.yyyf.feign.dto; + +import com.blockchain.common.base.entity.BaseModel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * BtcWalletDTO 数据传输类 + * + * @version 1.0 + * @date 2019-02-16 15:08:16 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class BtcWalletDTO extends BaseModel { + private String addr; + private Integer tokenId; + private String userOpenId; + private String tokenSymbol; + private Double balance; + private Double freeBalance; + private Double freezeBalance; + private java.util.Date createTime; + private java.util.Date updateTime; + private String walletType; + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/CurrencyMarketDTO.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/CurrencyMarketDTO.java new file mode 100644 index 0000000..04501e7 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/CurrencyMarketDTO.java @@ -0,0 +1,36 @@ +package com.blockchain.server.yyyf.feign.dto; + +import com.blockchain.common.base.dto.BaseDTO; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CurrencyMarketDTO extends BaseDTO implements Comparable { + + private String currencyPair; + private BigDecimal amount; + private Long timestamp; + private float percent; + private double usdAmount; + private double cnyAmount; + private double hkdAmount; + private double eurAmount; + //最低 + private BigDecimal lowest; + //最高 + private BigDecimal highest; + //开盘 + private BigDecimal open; + //成交量 + private BigDecimal total; + + @Override + public int compareTo(CurrencyMarketDTO o) { + return (int) (10000 * o.percent - 10000 * this.percent); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EosWalletDTO.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EosWalletDTO.java new file mode 100644 index 0000000..1826a8a --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EosWalletDTO.java @@ -0,0 +1,29 @@ +package com.blockchain.server.yyyf.feign.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * Wallet 数据传输类 + * @date 2018-11-05 15:10:47 + * @version 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class EosWalletDTO { + private Integer id; + private String tokenName; + private String userOpenId; + private String tokenSymbol; + private BigDecimal balance; + private BigDecimal freeBalance; + private BigDecimal freezeBalance; + private java.util.Date createTime; + private java.util.Date updateTime; + private String walletType; + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EthWalletDTO.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EthWalletDTO.java new file mode 100644 index 0000000..542fdeb --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EthWalletDTO.java @@ -0,0 +1,24 @@ +package com.blockchain.server.yyyf.feign.dto; + +import lombok.Data; + +/** + * EthWallet 数据传输类 + * + * @version 1.0 + * @date 2019-02-16 15:44:06 + */ +@Data +public class EthWalletDTO { + private String addr; + private String tokenAddr; + private String userOpenId; + private String tokenSymbol; + private int tokenDecimals; + private String balance; + private String freeBalance; + private String freezeBalance; + private String walletType; + private java.util.Date createTime; + private java.util.Date updateTime; +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java new file mode 100644 index 0000000..a20f726 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java @@ -0,0 +1,65 @@ +package com.blockchain.server.yyyf.indicators; + +import cn.hutool.core.map.MapUtil; +import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; +import com.blockchain.server.yyyf.entity.AssessUserTarget; +import com.blockchain.server.yyyf.indicators.dto.IndicatorsTypeEnum; +import com.blockchain.server.yyyf.mapper.AssessUserMapper; +import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; +import lombok.AllArgsConstructor; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * @author fengyu + */ +@Service +@AllArgsConstructor +public class DefaultIndicatorsManager implements IndicatorsManager { + private final ApplicationContext applicationContext; + private final AssessUserTargetMapper assessUserTargetMapper; + private final AssessUserMapper assessUserMapper; + + @Override + public Map calculatePageIndicators(String assessUserId) { + List assessUserTargets = assessUserTargetMapper.selectAllStudentAssessUserTargetByIssueId(assessUserId); + Map result = MapUtil.newHashMap(); + assessUserTargets.parallelStream().forEach(assessUser -> { + Float total = this.calculateIndicators(assessUserId, IndicatorsTypeEnum.parseCode(assessUser.getCode())); + result.put(assessUser.getCode(), total); + }); + return result; + } + + @Override + public BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId) { + //feign interface call + UserTimeMoneyDto timeMoneyDto = assessUserMapper.selectCurrentUserTimeMoneyDto(assessUserId, userId); + + + //1.获取 币币总资产 + 法币总资产 + 数字钱包 + 初始资产 + 挂单资金 + //cache rate + //2.计算总资产 转换成RMB + //cache RMB rate + return null; + } + + + /** + * calculate single indicator + * + * @param assessUserId page result id + * @param type indicators type + * @return indicators result + * @author fengyu.wang + * @date 2020-05-27 22:34:19 + */ + private Float calculateIndicators(String assessUserId, IndicatorsTypeEnum type) { + IndicatorsHandler indicatorsHandler = applicationContext.getBean(type.getCode(), IndicatorsHandler.class); + return indicatorsHandler.handleIndicator(assessUserId); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsHandler.java new file mode 100644 index 0000000..9be6507 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators; + +/** + * @author fengyu + */ +public interface IndicatorsHandler { + String HANDLER_NAME = "IndicatorsHandler"; + /** + * handle indicator + * + * @param assessUserId page result id + * @return indicator result + * @author fengyu.wang + * @date 2020-06-03 21:28:18 + */ + Float handleIndicator(String assessUserId); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java new file mode 100644 index 0000000..ab676ac --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java @@ -0,0 +1,31 @@ +package com.blockchain.server.yyyf.indicators; + +import java.math.BigDecimal; +import java.util.Map; + +/** + * @author fengyu + */ +public interface IndicatorsManager { + + /** + * calculate indicator by full exam + * + * @param assessUserId page result id + * @return indicators type -> indicators result + * @author fengyu.wang + * @date 2020-05-27 22:36:01 + */ + Map calculatePageIndicators(String assessUserId); + + /** + * calculate current total asset + * + * @param userId system user id + * @param assessUserId page result id + * @return current total assets (RMB) + * @author fengyu.wang + * @date 2020-06-02 20:15:15 + */ + BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsUtils.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsUtils.java new file mode 100644 index 0000000..a64e434 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsUtils.java @@ -0,0 +1,57 @@ +package com.blockchain.server.yyyf.indicators; + +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; +import lombok.Data; + +import javax.persistence.EntityExistsException; +import java.util.List; + +/** + * @author huan.xu + * @version 1.0 + * @className IndicatorsUtils + * @description + * @date 2020-06-05 10:21 + */ +@Data +public class IndicatorsUtils { + + + /** + * 获取 期初与期末的信息 + * @param reporterList + * @return + */ + public static LastAndFirstAssetsDto getLastAndFirstAssetsDto(List reporterList) { + LastAndFirstAssetsDto result = new LastAndFirstAssetsDto(); + + if (reporterList != null && reporterList.size() > 0) { + //期初资产 + AssetsReporter firstAssets = null; + //交易期内最后一天 + AssetsReporter lastAssets = null; + for (AssetsReporter assetsReporter : reporterList) { + if (assetsReporter.getDays() == 0) { //如果期初资产 + firstAssets = assetsReporter; + } else { + if (lastAssets == null) { //最小的若为null + lastAssets = assetsReporter; + } else { + if (assetsReporter.getDays() > lastAssets.getDays()) { + lastAssets = assetsReporter; + } + } + } + } + result.setFirstAssets(firstAssets); + result.setLastAssets(lastAssets); + return result; + } else { + throw new EntityExistsException("assessUser not exit"); + } + + + } + +} \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java new file mode 100644 index 0000000..6484dcf --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java @@ -0,0 +1,46 @@ +package com.blockchain.server.yyyf.indicators.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * assets recoding day by day + * + * @author fengyu.wang + * @date 2020-05-27 22:59:34 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AssetsReporter { + /** + * primary key + */ + private String id; + /** + * 成绩id + */ + private String assessUserId; + /** + * 币种 + */ + private String coinName; + /** + * 交易天数 + */ + private long days; + /** + * 资产总额 + */ + private BigDecimal assets; + /** + * 创建时间 + */ + private Date createTime; +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsDetail.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsDetail.java new file mode 100644 index 0000000..267d47b --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsDetail.java @@ -0,0 +1,16 @@ +package com.blockchain.server.yyyf.indicators.dto; + +import lombok.Data; + +/** + * indicators persist + * + * @author fengyu.wang + * @date 2020-05-27 22:55:14 + */ +@Data +public class IndicatorsDetail { + private String assessUserId; + private IndicatorsTypeEnum type; + private float indicator; +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsTypeEnum.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsTypeEnum.java new file mode 100644 index 0000000..48b0e2c --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsTypeEnum.java @@ -0,0 +1,46 @@ +package com.blockchain.server.yyyf.indicators.dto; + +import lombok.Getter; + +/** + * @author fengyu + */ + +public enum IndicatorsTypeEnum { + /*年化收益率*/ + ANNUAL_GROWTH_RATE("AnnualGrowthRate"), + /*收益率*/ + GROWTH_RATE("GrowthRate"), + /*累计收益率*/ + TOTAL_GROWTH_RATE("TotalGrowthRate"), + /*波动率*/ + FLUCTUATION_RATE("FluctuationRate"), + /*夏普比率*/ + SHAPE_RATE("ShapeRate"), + /*盈亏比*/ + PROFIT_LOSS_RATE("ProfitLossRate"), + /*最大回撤率*/ + MAX_DRAWDOWN_RATE("MaxDrawdownRate"), + /*最大亏损率*/ + MAX_LOSS_RATE("MaxLossRate"), + /*风险率(资产负债比)*/ + ASSET_LIABILITY_RISK_RATE("AssetLiabilityRiskRate"), + /*TVPI*/ + TVPI("TVPI"); + + @Getter + private final String code; + + IndicatorsTypeEnum(String code) { + this.code = code; + } + + public static IndicatorsTypeEnum parseCode(String code) { + for (IndicatorsTypeEnum value : IndicatorsTypeEnum.values()) { + if (code.equals(value.getCode())) { + return value; + } + } + throw new IllegalArgumentException(); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/LastAndFirstAssetsDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/LastAndFirstAssetsDto.java new file mode 100644 index 0000000..f97eba6 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/LastAndFirstAssetsDto.java @@ -0,0 +1,14 @@ +package com.blockchain.server.yyyf.indicators.dto; +import lombok.Data; +/** + * @author huan.xu + * @version 1.0 + * @className LastAndFirstAssetsReporterDto + * @description + * @date 2020-06-05 10:22 + */ +@Data +public class LastAndFirstAssetsDto { + private AssetsReporter lastAssets; + private AssetsReporter firstAssets; +} \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java new file mode 100644 index 0000000..0578f9f --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java @@ -0,0 +1,44 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsUtils; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; +import com.blockchain.server.yyyf.service.AssetsReporterService; +import lombok.AllArgsConstructor; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author fengyu + */ +@AllArgsConstructor +@Component(AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "AnnualGrowthRate"; + public static final String CACHE_ANNUAL_GROWTH_RATE = "yyyf_indicator_annualGrowthRate"; + public static final String CACHE_KEY_ANNUAL_GROWTH_RATE = "yyyf:annualGrowthRate:"; + + private final AssetsReporterService assetsReporterService; + + @Override + @Cacheable(cacheNames = CACHE_ANNUAL_GROWTH_RATE, + key = "#root.target.CACHE_KEY_ANNUAL_GROWTH_RATE.concat(#assessUserId)", unless = "#result == null") + public Float handleIndicator(String assessUserId) { + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); + + //获取最初、最后交易的信息 + LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); + + AssetsReporter lastAssets = lastAndFirstAssetsDto.getLastAssets(); + AssetsReporter firstAssets = lastAndFirstAssetsDto.getFirstAssets(); + BigDecimal result = lastAssets.getAssets() + .divide(firstAssets.getAssets(), 5, BigDecimal.ROUND_HALF_UP) + .pow((int) (360.0 / lastAssets.getDays())) + .subtract(BigDecimal.valueOf(1)); + return result.multiply(BigDecimal.valueOf(100)).floatValue(); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AssetLiabilityRiskRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AssetLiabilityRiskRateIndicatorsHandler.java new file mode 100644 index 0000000..20baedb --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AssetLiabilityRiskRateIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(AssetLiabilityRiskRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class AssetLiabilityRiskRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "AssetLiabilityRiskRate"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java new file mode 100644 index 0000000..facc38d --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java @@ -0,0 +1,73 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.service.AssetsReporterService; +import lombok.AllArgsConstructor; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import javax.persistence.EntityExistsException; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +/** + * @author fengyu + */ +@AllArgsConstructor +@Component(FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class FluctuationRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "FluctuationRate"; + public static final String CACHE_FLUCTUATION_RATE = "yyyf_indicator_fluctuationRate"; + public static final String CACHE_KEY_FLUCTUATION_RATE = "yyyf:fluctuationRate:"; + + private final AssetsReporterService assetsReporterService; + + @Override + @Cacheable(cacheNames = CACHE_FLUCTUATION_RATE, + key = "#root.target.CACHE_KEY_FLUCTUATION_RATE.concat(#assessUserId)", unless = "#result == null") + public Float handleIndicator(String assessUserId) { + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); + if (reporterList != null && reporterList.size() > 0) { + //排序 + reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); + //总天数 + int dayCount = reporterList.size() - 1; + //每日收益率List + List dayYieldList = new ArrayList(dayCount); + //收益率总和 + BigDecimal totalYield = BigDecimal.ZERO; + //上一天的资产总额 + BigDecimal upAssets = reporterList.get(0).getAssets(); + + //计算总收益率以及每日收益率 + for (AssetsReporter assetsReporter : reporterList) { + if (assetsReporter.getDays() > 0) { + BigDecimal thisAssets = assetsReporter.getAssets(); + BigDecimal subtract = thisAssets.subtract(upAssets); + //当天收益率 + BigDecimal thisYeid = subtract.multiply(BigDecimal.valueOf(100)).divide(upAssets, 5, BigDecimal.ROUND_HALF_UP); + //加入每日收益率集合 + dayYieldList.add(thisYeid); + //总收益率 + totalYield = totalYield.add(thisYeid); + //更换上一天的总额 + upAssets = thisAssets; + } + } + //平均收益率 + BigDecimal avgYeid = totalYield.divide(BigDecimal.valueOf(dayCount), 5, BigDecimal.ROUND_HALF_UP); + //(每日收益率-平均收益率)的平方和 + BigDecimal yeid2Count = BigDecimal.ZERO; + for (BigDecimal yeid : dayYieldList) { + yeid2Count = yeid2Count.add(yeid.subtract(avgYeid).pow(2)); + } + return Float.valueOf(String.format("%.2f", Math.sqrt(BigDecimal.valueOf(360).divide(BigDecimal.valueOf(dayCount - 1), 5, BigDecimal.ROUND_HALF_UP).multiply(yeid2Count).doubleValue()))); + } else { + throw new EntityExistsException("assessUser:" + assessUserId); + } + } + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java new file mode 100644 index 0000000..b2408f3 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java @@ -0,0 +1,35 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsUtils; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; +import com.blockchain.server.yyyf.service.AssetsReporterService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author fengyu + */ +@AllArgsConstructor +@Component(GrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class GrowthRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "GrowthRate"; + + private final AssetsReporterService assetsReporterService; + + @Override + public Float handleIndicator(String assessUserId) { + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); + //获取最初、最后交易的信息 + LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); + + AssetsReporter lastAssets =lastAndFirstAssetsDto.getLastAssets(); + AssetsReporter firstAssets =lastAndFirstAssetsDto.getFirstAssets(); + + return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(firstAssets.getAssets(), 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).floatValue(); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java new file mode 100644 index 0000000..8dbe567 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java @@ -0,0 +1,57 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.service.AssetsReporterService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import javax.persistence.EntityExistsException; +import java.math.BigDecimal; +import java.util.Comparator; +import java.util.List; + +/** + * @author fengyu + */ +@AllArgsConstructor +@Component(MaxDrawdownRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class MaxDrawdownRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "MaxDrawdownRate"; + + + private final AssetsReporterService assetsReporterService; + + @Override + public Float handleIndicator(String assessUserId) { + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); + if (reporterList != null && reporterList.size() > 0) { + //排序 + reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); + + BigDecimal maxDrawdownRate=BigDecimal.ZERO; + //上一天的资产总额 + BigDecimal upAssets =BigDecimal.ZERO; + for (AssetsReporter assetsReporter : reporterList) { + BigDecimal thisAssets=assetsReporter.getAssets(); + //交易第二天开始 + if(assetsReporter.getDays()>1){ + BigDecimal thisDrawdownRate=BigDecimal.ONE.subtract(thisAssets.divide(upAssets,4,BigDecimal.ROUND_HALF_UP)); + if(thisDrawdownRate.compareTo(maxDrawdownRate)==1){ + maxDrawdownRate=thisDrawdownRate; + } + }else{ + //交易的第一天 + if(assetsReporter.getDays()==1){ + maxDrawdownRate=BigDecimal.ONE.subtract(thisAssets.divide(upAssets,4,BigDecimal.ROUND_HALF_UP)); + } + + } + upAssets=thisAssets; + } + return maxDrawdownRate.multiply(BigDecimal.valueOf(100)).floatValue(); + } else { + throw new EntityExistsException("assessUser:" + assessUserId); + } + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java new file mode 100644 index 0000000..a4f42e3 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java @@ -0,0 +1,60 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.service.AssetsReporterService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import javax.persistence.EntityExistsException; +import java.math.BigDecimal; +import java.util.List; + +/** + * @author fengyu + */ +@AllArgsConstructor +@Component(MaxLossRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class MaxLossRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "MaxLossRate"; + private final AssetsReporterService assetsReporterService; + + @Override + public Float handleIndicator(String assessUserId) { + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); + + if (reporterList != null && reporterList.size() > 0) { + //如果期初资产 + AssetsReporter firstAssets = null; + //交易期内资产最小值 + AssetsReporter minAssets = null; + for (AssetsReporter assetsReporter : reporterList) { + if (assetsReporter.getDays() == 0) { //如果期初资产 + firstAssets = assetsReporter; + } else { + if (minAssets == null) { //最小的若为null + minAssets = assetsReporter; + } else { + if (assetsReporter.getAssets().compareTo(minAssets.getAssets()) == -1) { + minAssets = assetsReporter; + } + } + } + } + long minDay = minAssets.getDays(); + int n = (int) (360 / minDay); + + Float result = BigDecimal.ONE.subtract(minAssets.getAssets().divide(firstAssets.getAssets(), 5, BigDecimal.ROUND_HALF_UP).pow(n)) + .setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); + + //负无穷的时候为0 + if (result.isInfinite()) { + result = Float.valueOf(0); + } + return result; + + } else { + throw new EntityExistsException("assessUser:"); + } + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java new file mode 100644 index 0000000..c5aa1c7 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java @@ -0,0 +1,63 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.service.AssetsReporterService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import javax.persistence.EntityExistsException; +import java.math.BigDecimal; +import java.util.Comparator; +import java.util.List; + +/** + * @author fengyu + */ +@AllArgsConstructor +@Component(ProfitLossRateRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "ProfitLossRate"; + + private final AssetsReporterService assetsReporterService; + + @Override + public Float handleIndicator(String assessUserId) { + + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); + if (reporterList != null && reporterList.size() > 0) { + //排序 + reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); + //第一天(上一天)的资产总额 + BigDecimal upAssets = reporterList.get(0).getAssets(); + + //总亏损额 + BigDecimal lossMoneyCount = BigDecimal.ZERO; + //盈利计数 + int profitCount = 0; + //总盈利额 + BigDecimal profitMoneyCount = BigDecimal.ZERO; + for (AssetsReporter assetsReporter : reporterList) { + + BigDecimal thisYeid = assetsReporter.getAssets(); + //盈利 + if (thisYeid.compareTo(upAssets) > 0) { //盈利 + profitCount++; + profitMoneyCount = profitMoneyCount.add(thisYeid).subtract(upAssets); + }else{ + lossMoneyCount = lossMoneyCount.add(thisYeid).subtract(upAssets); + } + upAssets=thisYeid; + } + if (profitCount == 0) { //每天亏损、或者每天既不盈利也不亏损 + return Float.valueOf(0); + }else if(profitCount==(reporterList.size()-1)){ //每天都在盈利 + return Float.POSITIVE_INFINITY; + }else { //计算盈亏比 + return profitMoneyCount.divide(lossMoneyCount,4,BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).floatValue(); + } + } else { + throw new EntityExistsException("assessUser:" + assessUserId); + } + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java new file mode 100644 index 0000000..0f4d64d --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java @@ -0,0 +1,40 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.math.BigDecimal; + +/** + * @author fengyu + */ +@Component(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class ShapeRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "ShapeRate"; + + //无风险利率,配置文件注入,防止后期更改 + @Value("${rate.riskFree}") + private BigDecimal riskFree; + + @Resource(name = AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) + private AnnualGrowthRateIndicatorsHandler annualGrowthRateIndicatorsHandler; + + @Resource(name = FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) + private FluctuationRateIndicatorsHandler fluctuationRateIndicatorsHandler; + + @Override + public Float handleIndicator(String assessUserId) { + + //年化收益率 + Float annualGrowthRate=annualGrowthRateIndicatorsHandler.handleIndicator(assessUserId); + //波动率 + Float fluctuationRate=fluctuationRateIndicatorsHandler.handleIndicator(assessUserId); + + return BigDecimal.valueOf(annualGrowthRate).subtract(riskFree).divide(BigDecimal.valueOf(fluctuationRate),4,BigDecimal.ROUND_HALF_UP) + .floatValue(); + + } + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TVPIIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TVPIIndicatorsHandler.java new file mode 100644 index 0000000..6052a1e --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TVPIIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(TVPIIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class TVPIIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "TVPI"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java new file mode 100644 index 0000000..4fe2f31 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java @@ -0,0 +1,40 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsUtils; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; +import com.blockchain.server.yyyf.service.AssetsReporterService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author fengyu + */ +@AllArgsConstructor +@Component(TotalGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "TotalGrowthRate"; + + private final AssetsReporterService assetsReporterService; + + @Override + public Float handleIndicator(String assessUserId) { + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); + //获取最初、最后交易的信息 + LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); + + AssetsReporter lastAssets =lastAndFirstAssetsDto.getLastAssets(); + AssetsReporter firstAssets =lastAndFirstAssetsDto.getFirstAssets(); + + //充值的总金额 + //todo 不知道如何获取 + BigDecimal rechargeAmount=null; + + return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(rechargeAmount,4,BigDecimal.ROUND_HALF_UP) + .multiply(BigDecimal.valueOf(100)).floatValue(); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java index 29b62b4..b6cf679 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java @@ -2,6 +2,7 @@ package com.blockchain.server.yyyf.mapper; import com.blockchain.server.yyyf.dto.AssessUserDto; +import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; import com.blockchain.server.yyyf.entity.AssessUser; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -31,4 +32,24 @@ public interface AssessUserMapper extends Mapper { void batchUpdateTotalScoreByAssessUserDtoList(@Param("assessUserDtoList") List assessUserDtoList); List selectAssessUserDtoByIssueId(@Param("issueId") String issueId); -} \ No newline at end of file + + /** + * @description 获取未提交的 UserTimeMoneyDto List + * @author Mr.Xu + * @date 2020-06-01 22:05:09 + * @param [] + * @return java.util.List + **/ + List selectUserTimeMoneyDtosForNotEnd(); + + /** + * @description assessUserId通过assessUserId 获取余额情况 + * @author Mr.Xu + * @date 2020-06-02 21:07:23 + * @param [assessUserId] + * @return com.blockchain.server.yyyf.dto.UserTimeMoneyDto + **/ + UserTimeMoneyDto getUserTimeMoneyDtoByAssessUserId(@Param("assessUserId") String assessUserId); + + UserTimeMoneyDto selectCurrentUserTimeMoneyDto(@Param("assessUserId") String assessUserId, @Param("qUserId")String qUserId); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserTargetMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserTargetMapper.java index 8a7e55f..7754f1e 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserTargetMapper.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserTargetMapper.java @@ -26,4 +26,13 @@ public interface AssessUserTargetMapper extends Mapper { List selectAllStudentAssessUserTargetByIssueId(@Param("issueId")String issueId); List getStudentTargetErrorStatisticsDtoListByIssueId(@Param("issueId")String issueId); + + /** + * @description 批量更新指标库最终答题情况 + * @author Mr.Xu + * @date 2020-06-01 22:54:19 + * @param [updateAssessUserTargetList] + * @return void + **/ + void batchUpdateTargetAnswer(@Param("list") List updateAssessUserTargetList); } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssetsReporterMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssetsReporterMapper.java new file mode 100644 index 0000000..b512e82 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssetsReporterMapper.java @@ -0,0 +1,15 @@ +package com.blockchain.server.yyyf.mapper; + +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + +import java.util.List; + +@Repository +public interface AssetsReporterMapper extends Mapper { + + List selectByAssessUserId(String assessUserId); + + void insertBatch(List list); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java index 974ba1f..70fa7bd 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java @@ -3,6 +3,7 @@ package com.blockchain.server.yyyf.service; import com.blockchain.server.train.dto.TrainCaseTargetDto; import com.blockchain.server.yyyf.dto.AssessUserDto; +import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; import com.blockchain.server.yyyf.entity.AssessUser; import java.util.List; @@ -86,4 +87,23 @@ public interface AssessUserService { List getAssessUserListByIssueIdAndUserId(String issueId, Integer userId); AssessUser selectById(String assessUserId); + + + /** + * @description 获取未提交的 UserTimeMoneyDto List + * @author Mr.Xu + * @date 2020-06-01 22:05:09 + * @param [] + * @return java.util.List + **/ + public List selectUserTimeMoneyDtosForNotEnd(); + + /** + * @description assessUserId通过assessUserId 获取余额情况 + * @author Mr.Xu + * @date 2020-06-02 21:06:35 + * @param [assessUserId] + * @return com.blockchain.server.yyyf.dto.UserTimeMoneyDto + **/ + UserTimeMoneyDto getUserTimeMoneyDtoByAssessUserId(String assessUserId); } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserTargetService.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserTargetService.java index 07e27f9..448bc86 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserTargetService.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserTargetService.java @@ -32,4 +32,13 @@ public interface AssessUserTargetService{ List selectAllStudentAssessUserTargetByIssueId(String issueId); List getStudentTargetErrorStatisticsDtoListByIssueId(String issueId); + + /** + * @description 还原指标表 + * @author Mr.Xu + * @date 2020-06-03 00:05:17 + * @param [assessUserId] + * @return void + **/ + void restoreByAssessUserId(String assessUserId); } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssetsReporterService.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssetsReporterService.java new file mode 100644 index 0000000..65ebec0 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssetsReporterService.java @@ -0,0 +1,26 @@ +package com.blockchain.server.yyyf.service; + +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; + +import java.util.List; + +public interface AssetsReporterService { + /** + * save assets reporter item + * + * @param assetsReporterList assetsReporter list + * @author fengyu.wang + * @date 2020-06-05 21:37:21 + */ + void saveList(List assetsReporterList); + + /** + * select assetsReporter list by assessUserId + * + * @param assessUserId exam result id + * @return assetsReporter list + * @author fengyu.wang + * @date 2020-06-05 21:38:09 + */ + List selectAssetsReporterListByAssessUserId(String assessUserId); +} 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 627ffeb..8f57522 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 @@ -4,12 +4,14 @@ import com.blockchain.common.base.constant.YyyfConstant; import com.blockchain.server.train.dto.TrainCaseTargetDto; import com.blockchain.server.yyyf.dto.AssessUserDto; import com.blockchain.server.yyyf.dto.ExamDto; +import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; 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.entity.YyyfMoney; import com.blockchain.server.yyyf.enums.YyyfEnums; import com.blockchain.server.yyyf.exceprion.YyyfException; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; import com.blockchain.server.yyyf.mapper.AssessUserMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import com.blockchain.server.yyyf.mapper.YyyfMoneyMapper; @@ -30,9 +32,8 @@ import tk.mybatis.mapper.entity.Example; import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.concurrent.TimeUnit; /** * @author huan.xu @@ -56,6 +57,9 @@ public class AssessUserServiceImpl implements AssessUserService { @Autowired private YyyfMoneyMapper yyyfMoneyMapper; + //@Autowired + private IndicatorsManager indicatorsManager; + @Value("${yyyf.url}") private String yyyfUrl; @@ -76,7 +80,6 @@ public class AssessUserServiceImpl implements AssessUserService { } - @Override public AssessUser selectAssessUserByUserIdAndissueIdForNotEnd(Integer userId, String issueId) { Example example = new Example(AssessUser.class); @@ -107,11 +110,12 @@ public class AssessUserServiceImpl implements AssessUserService { assessUserTarget.setSort(j++); assessUserTarget.setAnswer(1); assessUserTarget.setId(IdGenerator.uuid()); + assessUserTarget.setStudentRate(0d); list.add(assessUserTarget); } //区块链原始金额存入 - YyyfMoney yyyfMoney=new YyyfMoney(); + YyyfMoney yyyfMoney = new YyyfMoney(); yyyfMoney.setAssessUserId(assessUser.getId()); yyyfMoney.setAliPay(assessUser.getAlipayInitMoney()); yyyfMoney.setWxPay(assessUser.getWechatInitMoney()); @@ -119,6 +123,7 @@ public class AssessUserServiceImpl implements AssessUserService { yyyfMoney.setBtc(BigDecimal.ZERO); yyyfMoney.setEth(BigDecimal.ZERO); yyyfMoney.setUsdt(BigDecimal.ZERO); + yyyfMoney.setEos(BigDecimal.ZERO); yyyfMoney.setUpdateTime(new Date()); this.assessUserMapper.insert(assessUser); @@ -136,7 +141,6 @@ public class AssessUserServiceImpl implements AssessUserService { @Override public AssessUserDto submit(String assessUserId) { AssessUser assessUser = this.selectAssessUserById(assessUserId); - if (assessUser.getEndTime() != null) { throw new YyyfException(YyyfEnums.PROHIBIT_DUPLICATE_SUBMISSION); } @@ -147,11 +151,20 @@ public class AssessUserServiceImpl implements AssessUserService { criteria.andCondition(" assess_user_id = ", assessUserId); List assessUserTargetList = this.assessUserTargetMapper.selectByExample(example); + //获取达标参数 + Map targetResultMap = indicatorsManager.calculatePageIndicators(assessUserId); + //最终更新的指标库答题结果list + List updateAssessUserTargetList = new ArrayList<>(); + for (AssessUserTarget assessUserTarget : assessUserTargetList) { + //计算是否达标 + answerResultForTarget(assessUserTarget, targetResultMap); + Double taskScore = assessUserTarget.getTaskScore(); if (assessUserTarget.getAnswer() == 0) { totalScore += taskScore; } + updateAssessUserTargetList.add(assessUserTarget); } Date startTime = assessUser.getStartTime(); @@ -170,6 +183,8 @@ public class AssessUserServiceImpl implements AssessUserService { } this.update(assessUser); + //批量更新指标最终结果 + this.assessUserTargetMapper.batchUpdateTargetAnswer(updateAssessUserTargetList); AssessUserDto assessUserDto = new AssessUserDto(); BeanUtils.copyProperties(assessUser, assessUserDto); @@ -184,18 +199,25 @@ public class AssessUserServiceImpl implements AssessUserService { List assessUserDtoList = this.assessUserMapper.selectAssessUserDtoByIssueId(issueId); List updateAssessUserDtoList = new ArrayList<>(); List yyyfStudentAnswerDtoList = new ArrayList<>(assessUserDtoList.size()); - + //最终更新的指标库答题结果list + List updateAssessUserTargetList = new ArrayList<>(); Date now = new Date(); for (AssessUserDto assessUserDto : assessUserDtoList) { + //根据assessUserId 获取当时指标情况 + Map targetResultMap = indicatorsManager.calculatePageIndicators(assessUserDto.getId()); List assessUserTargetList = assessUserDto.getAssessUserTargetList(); if (assessUserDto.getEndTime() == null) { Double totalScore = 0d; for (AssessUserTarget assessUserTarget : assessUserTargetList) { + //计算是否达标 + answerResultForTarget(assessUserTarget, targetResultMap); + //计算成绩 Double taskScore = assessUserTarget.getTaskScore(); if (assessUserTarget.getAnswer() == 0) { totalScore += taskScore; } + updateAssessUserTargetList.add(assessUserTarget); } Date startTime = assessUserDto.getStartTime(); assessUserDto.setTotalScore(totalScore); @@ -205,12 +227,13 @@ public class AssessUserServiceImpl implements AssessUserService { long duration = sdf.parse(sdf.format(now)).getTime() - sdf.parse(sdf.format(startTime)).getTime(); assessUserDto.setDuration(Math.toIntExact(duration)); updateAssessUserDtoList.add(assessUserDto); + //指标库更新 + } YyyfStudentAnswerDto yyyfStudentAnswerDto = new YyyfStudentAnswerDto(); BeanUtils.copyProperties(assessUserDto, yyyfStudentAnswerDto); yyyfStudentAnswerDto.setAssessmentId(issueId); yyyfStudentAnswerDtoList.add(yyyfStudentAnswerDto); - redisTemplate.delete(YyyfConstant.CASE_KEY + assessUserDto.getUserId()); } @@ -223,6 +246,7 @@ public class AssessUserServiceImpl implements AssessUserService { if (updateAssessUserDtoList.size() > 0) { this.assessUserMapper.batchUpdateTotalScoreByAssessUserDtoList(assessUserDtoList); + this.assessUserTargetMapper.batchUpdateTargetAnswer(updateAssessUserTargetList); } HttpClientUtil.doPostWithJSON(new StringBuilder().append(yyyfUrl).append(assessmentList).toString(), yyyfStudentAnswerDtoList); @@ -241,9 +265,9 @@ public class AssessUserServiceImpl implements AssessUserService { @Override public int selectCountByByIssueId(String issueId) { - Example example=new Example(AssessUser.class); + Example example = new Example(AssessUser.class); Example.Criteria criteria = example.createCriteria(); - criteria.andCondition("issue_id = ",issueId); + criteria.andCondition("issue_id = ", issueId); return this.assessUserMapper.selectCountByExample(example); } @@ -252,7 +276,7 @@ public class AssessUserServiceImpl implements AssessUserService { Example example = new Example(AssessUser.class); Example.Criteria criteria = example.createCriteria(); criteria.andCondition("issue_id = ", issueId) - .andCondition("user_id = ",userId); + .andCondition("user_id = ", userId); return this.assessUserMapper.selectOneByExample(example); } @@ -261,7 +285,7 @@ public class AssessUserServiceImpl implements AssessUserService { Example example = new Example(AssessUser.class); Example.Criteria criteria = example.createCriteria(); criteria.andCondition("issue_id = ", issueId) - .andCondition("user_id = ",userId); + .andCondition("user_id = ", userId); return this.assessUserMapper.selectByExample(example); } @@ -270,5 +294,37 @@ public class AssessUserServiceImpl implements AssessUserService { return this.assessUserMapper.selectByPrimaryKey(assessUserId); } + @Override + public List selectUserTimeMoneyDtosForNotEnd() { + return this.assessUserMapper.selectUserTimeMoneyDtosForNotEnd(); + } + + @Override + public UserTimeMoneyDto getUserTimeMoneyDtoByAssessUserId(String assessUserId) { + return this.assessUserMapper.getUserTimeMoneyDtoByAssessUserId(assessUserId); + } + + /** + * @param [assessUserTarget, targetResultMap] + * @return void + * @description 计算是否达标 + * @author Mr.Xu + * @date 2020-06-01 22:49:37 + **/ + private void answerResultForTarget(AssessUserTarget assessUserTarget, Map targetResultMap) { + assessUserTarget.setAnswer(1); + Float aFloat = targetResultMap.get(assessUserTarget.getCode()); + Double taskRate = 0d; + if (aFloat != null) { + taskRate = Double.valueOf(aFloat); + assessUserTarget.setStudentRate(taskRate); + int compareAnswer = taskRate.compareTo(assessUserTarget.getTaskRate()); + //最终指标结果一致 + if (assessUserTarget.getTaskOperate().intValue() == compareAnswer) { + assessUserTarget.setAnswer(0); + } + } + + } } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserTargetServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserTargetServiceImpl.java index b7dff30..5cbbab3 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserTargetServiceImpl.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserTargetServiceImpl.java @@ -54,4 +54,16 @@ public class AssessUserTargetServiceImpl implements AssessUserTargetService { return this.assessUserTargetMapper.getStudentTargetErrorStatisticsDtoListByIssueId(issueId); } + @Override + public void restoreByAssessUserId(String assessUserId) { + Example example=new Example(AssessUserTarget.class); + Example.Criteria criteria = example.createCriteria(); + criteria.andCondition(" assess_user_id = " ,assessUserId); + AssessUserTarget assessUserTarget=new AssessUserTarget(); + assessUserTarget.setAnswer(1); + assessUserTarget.setStudentRate(0d); + this.assessUserTargetMapper.updateByExampleSelective(assessUserTarget,example); + + } + } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java new file mode 100644 index 0000000..cf6b2c1 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java @@ -0,0 +1,41 @@ +package com.blockchain.server.yyyf.service.impl; + +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.mapper.AssetsReporterMapper; +import com.blockchain.server.yyyf.service.AssetsReporterService; +import lombok.AllArgsConstructor; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +/** + * @author fengyu + */ +@Service +@AllArgsConstructor +public class AssetsReporterServiceImpl implements AssetsReporterService { + private final AssetsReporterMapper assetsReporterMapper; + private final CacheManager cacheManager; + + public static final String CACHE_ASSETS_REPORTER = "yyyf_assets_reporter"; + public static final String CACHE_KEY_ASSETS_REPORTER = "yyyf:assetsReporter:"; + + @Override + public void saveList(List assetsReporterList) { + //TODO Transaction rollback, retry, log + assetsReporterList.forEach(assetsReporter -> + Optional.ofNullable(cacheManager.getCache(CACHE_ASSETS_REPORTER)) + .ifPresent(cache -> cache.evict(CACHE_KEY_ASSETS_REPORTER.concat(assetsReporter.getAssessUserId())))); + assetsReporterMapper.insertBatch(assetsReporterList); + } + + @Override + @Cacheable(cacheNames = CACHE_ASSETS_REPORTER, + key = "#root.target.CACHE_KEY_ASSETS_REPORTER.concat(#assessUserId)", unless = "#result == null") + public List selectAssetsReporterListByAssessUserId(String assessUserId) { + return assetsReporterMapper.selectByAssessUserId(assessUserId); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java new file mode 100644 index 0000000..6ddae80 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java @@ -0,0 +1,53 @@ +package com.blockchain.server.yyyf.task; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.service.AssessUserService; +import com.blockchain.server.yyyf.service.AssetsReporterService; +import com.blockchain.server.yyyf.utils.IdGenerator; +import lombok.AllArgsConstructor; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author fengyu + */ +@Configuration +@EnableScheduling +@AllArgsConstructor +public class ExamProcessTask { + + private final AssessUserService assessUserService; + private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; + + @Scheduled(cron = "0 1 0 * * ?") + public void processRecording() { + List userTimeMoneyList = this.assessUserService.selectUserTimeMoneyDtosForNotEnd(); + List assetsReporterList = new ArrayList<>(userTimeMoneyList.size()); + DateTime now = DateUtil.date(); + userTimeMoneyList.forEach(entity -> { + BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId(), entity.getAssessUserId()); + assetsReporterList.add(AssetsReporter.builder() + .id(IdGenerator.uuid()) + .assessUserId(entity.getAssessUserId()) + .assets(assets) + .days(DateUtil.between(entity.getStartTime(), now, DateUnit.DAY)) + .coinName("RMB") + .createTime(now) + .build()); + }); + if (!assetsReporterList.isEmpty()) { + assetsReporterService.saveList(assetsReporterList); + } + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml b/blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml index 8dbe479..9a734a7 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml @@ -29,3 +29,4 @@ yyyf: assessment: /api/db/v1.0/assessment #成绩同步(整场考试) assessmentList: /api/db/v1.0/assessmentList + diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml index 1996a94..5ca4b33 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml @@ -34,7 +34,22 @@ - + + + + + + + + + + + + + + + + @@ -99,5 +114,21 @@ WHERE u.id = t.assess_user_id and u.issue_id=#{issueId} + + + diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserTargetMapper.xml b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserTargetMapper.xml index 9da14d4..6f6729e 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserTargetMapper.xml +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserTargetMapper.xml @@ -29,6 +29,13 @@ + + + update yyyf_server_assess_user_target + set answer = #{item.answer,jdbcType=INTEGER},student_rate=#{item.studentRate,jdbcType=DECIMAL} where id = #{item.id,jdbcType=VARCHAR} + + + + select + + from yyyf_assets_reporter + where assess_user_id = #{assessUserId,jdbcType=VARCHAR} + +