From 9963b062c0e49f57dbed3dfc3414b1d10291bfa2 Mon Sep 17 00:00:00 2001 From: "fengyu.wang" Date: Wed, 27 May 2020 23:02:42 +0800 Subject: [PATCH 01/11] indicator design --- .../server/btc/inner/BtcWalletInner.java | 15 +++++- .../inner/CurrencyMarketInnerController.java | 7 +++ .../eos/inner/EosWalletInnerController.java | 11 +++++ .../server/eth/inner/EthWalletInner.java | 6 +++ .../yyyf/indicators/IndicatorsManager.java | 47 +++++++++++++++++++ .../yyyf/indicators/dto/AssetsReporter.java | 21 +++++++++ .../yyyf/indicators/dto/IndicatorsDetail.java | 16 +++++++ .../server/yyyf/task/ExamProcessTask.java | 21 +++++++++ 8 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsDetail.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java 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/EthWalletInner.java b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java index 2d166b6..233af76 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 @@ -60,4 +60,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-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..01df104 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java @@ -0,0 +1,47 @@ +package com.blockchain.server.yyyf.indicators; + +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; + +import java.util.List; +import java.util.Map; + +public interface IndicatorsManager { + /** + * save assets reporter item + * + * @author fengyu.wang + * @date 2020-05-27 22:32:30 + */ + void saveAssetsReporter(List assetsReporterList); + + /** + * get assets reporter item by assessUserId + * + * @param assessUserId page result id + * @author fengyu.wang + * @date 2020-05-27 22:32:49 + */ + List getAssetsReporterListByAssessUserId(String assessUserId); + + /** + * 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 + */ + float calculateIndicators(String assessUserId, String type); + + /** + * 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); + +} 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..b7e6ede --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java @@ -0,0 +1,21 @@ +package com.blockchain.server.yyyf.indicators.dto; + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * assets recoding day by day + * + * @author fengyu.wang + * @date 2020-05-27 22:59:34 + */ +@Data +public class AssetsReporter { + private String assessUserId;//成绩id + private String coinName;//币种 + private int 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..29aab25 --- /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 String type;//indicator type + private float indicator; +} 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..979836e --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java @@ -0,0 +1,21 @@ +package com.blockchain.server.yyyf.task; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; + +@Configuration +@EnableScheduling +public class ExamProcessTask { + + @Scheduled(cron="0 0 0 1/1 * ? *") + public void processRecording() { + //1.获取所有正在进行考核学生id(子系统userId) + //2.获取 币币总资产 + 法币总资产 + 数据钱包 + 初始资产 + 挂单资金 + //3.计算总资产 转换成RMB + + //4.获取学生考核开始时间 计算当前进行到第几天 + //5.获取学生试卷Id assessUserId + //6.保存到DB + } +} From 2e4670a975a2e8384231f70254dbf2b88c4d43ca Mon Sep 17 00:00:00 2001 From: unclekh <5177787+unclekh@user.noreply.gitee.com> Date: Mon, 1 Jun 2020 23:30:03 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E6=AF=8F=E5=A4=A9=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=8C=87=E6=A0=87=EF=BC=9B=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=8C=87=E6=A0=87=E7=BB=93=E7=AE=97=E7=BB=93=E6=9E=9C=E5=B9=B6?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/LoginController.java | 58 +++---- .../server/user/entity/AssessUser.java | 146 ++++++++++++++++++ .../server/user/entity/YyyfUser.java | 50 ------ .../server/user/mapper/AssessUserMapper.java | 12 ++ .../server/user/mapper/YyyfUserMapper.java | 16 -- .../user/service/AssessUserService.java | 62 ++++++++ .../server/user/service/YyyfUserService.java | 28 ---- .../service/impl/AssessUserServiceImpl.java | 72 +++++++++ .../service/impl/YyyfUserServiceImpl.java | 64 -------- .../resources/mapper/AssessUserMapper.xml | 5 + .../main/resources/mapper/YyyfUserMapper.xml | 6 - .../yyyf/controller/ExamController.java | 1 - .../server/yyyf/dto/UserTimeMoneyDto.java | 24 +++ .../server/yyyf/entity/AssessUser.java | 8 + .../server/yyyf/mapper/AssessUserMapper.java | 10 ++ .../yyyf/mapper/AssessUserTargetMapper.java | 9 ++ .../yyyf/service/AssessUserService.java | 11 ++ .../service/impl/AssessUserServiceImpl.java | 68 +++++++- .../server/yyyf/task/ExamProcessTask.java | 22 ++- .../resources/mapper/AssessUserMapper.xml | 17 +- .../mapper/AssessUserTargetMapper.xml | 7 + 21 files changed, 487 insertions(+), 209 deletions(-) create mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/AssessUser.java delete mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java create mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/AssessUserMapper.java delete mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/mapper/YyyfUserMapper.java create mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/AssessUserService.java delete mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java create mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/AssessUserServiceImpl.java delete mode 100644 blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java create mode 100644 blockchain-server/blockchain-server-user/src/main/resources/mapper/AssessUserMapper.xml delete mode 100644 blockchain-server/blockchain-server-user/src/main/resources/mapper/YyyfUserMapper.xml create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/UserTimeMoneyDto.java 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..f971ae0 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,9 @@ 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); + //处理区块链用户id + dealBindYyyfAccount(userMain.getId(),request); + return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); } @PostMapping("/sendLoginCode") @@ -169,21 +170,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 +195,12 @@ public class LoginController { @ApiParam(LoginApi.RegisterPC.METHOD_API_INVITATION_CODE) @RequestParam(value = "invitationCode", required = false) String invitationCode, @ApiParam(LoginApi.RegisterPC.METHOD_API_PASSWORD) @RequestParam(value = "password", required = false) String password, @ApiParam(LoginApi.RegisterPC.METHOD_API_INTERNATIONAL_CODE) @RequestParam(value = "internationalCode", required = false, defaultValue = InternationalConstant.DEFAULT_CODE) String internationalCode, - @ApiParam(LoginApi.RegisterPC.METHOD_API_NICK_NAME) @RequestParam(value = "nickName", required = false) String nickName, HttpServletRequest request + @ApiParam(LoginApi.RegisterPC.METHOD_API_NICK_NAME) @RequestParam(value = "nickName", required = false) String nickName ) { 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); + return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); } @PostMapping("/loginout2") @@ -218,12 +218,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 +244,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 +271,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 +314,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/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..7a86deb 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 @@ -62,7 +62,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()); //最终指标结果一致 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..889328d --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/UserTimeMoneyDto.java @@ -0,0 +1,24 @@ +package com.blockchain.server.yyyf.dto; + +import com.blockchain.server.yyyf.entity.YyyfMoney; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author Mr.Xu + * @version 1.0 + * @className UserTimeMoneyDto + * @description 包含以渔有方userId、本系统userId、开始时间以及各个币种余额情况 + * @date 2020-06-01 21:23 + */ +public class UserTimeMoneyDto extends YyyfMoney implements Serializable { + + private static final long serialVersionUID = 5093452353347277920L; + /**以渔有方用户id**/ + private Integer userId; + /**本系统用户id**/ + private String qUserId; + /**开始时间**/ + private Date startTime; +} 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/mapper/AssessUserMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java index 29b62b4..7e4efd0 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,13 @@ public interface AssessUserMapper extends Mapper { void batchUpdateTotalScoreByAssessUserDtoList(@Param("assessUserDtoList") List assessUserDtoList); List selectAssessUserDtoByIssueId(@Param("issueId") String issueId); + + /** + * @description 获取未提交的 UserTimeMoneyDto List + * @author Mr.Xu + * @date 2020-06-01 22:05:09 + * @param [] + * @return java.util.List + **/ + List selectUserTimeMoneyDtosForNotEnd(); } \ No newline at end of file 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/service/AssessUserService.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java index 974ba1f..23372cb 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,14 @@ 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(); } 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..e6b2118 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; @@ -33,6 +35,8 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; /** * @author huan.xu @@ -56,6 +60,9 @@ public class AssessUserServiceImpl implements AssessUserService { @Autowired private YyyfMoneyMapper yyyfMoneyMapper; + //@Autowired + private IndicatorsManager indicatorsManager; + @Value("${yyyf.url}") private String yyyfUrl; @@ -76,7 +83,6 @@ public class AssessUserServiceImpl implements AssessUserService { } - @Override public AssessUser selectAssessUserByUserIdAndissueIdForNotEnd(Integer userId, String issueId) { Example example = new Example(AssessUser.class); @@ -111,7 +117,7 @@ public class AssessUserServiceImpl implements AssessUserService { } //区块链原始金额存入 - YyyfMoney yyyfMoney=new YyyfMoney(); + YyyfMoney yyyfMoney = new YyyfMoney(); yyyfMoney.setAssessUserId(assessUser.getId()); yyyfMoney.setAliPay(assessUser.getAlipayInitMoney()); yyyfMoney.setWxPay(assessUser.getWechatInitMoney()); @@ -147,11 +153,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 +185,8 @@ public class AssessUserServiceImpl implements AssessUserService { } this.update(assessUser); + //批量更新指标最终结果 + this.assessUserTargetMapper.batchUpdateTargetAnswer(updateAssessUserTargetList); AssessUserDto assessUserDto = new AssessUserDto(); BeanUtils.copyProperties(assessUser, assessUserDto); @@ -184,18 +201,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 +229,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 +248,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 +267,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 +278,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 +287,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 +296,31 @@ public class AssessUserServiceImpl implements AssessUserService { return this.assessUserMapper.selectByPrimaryKey(assessUserId); } + @Override + public List selectUserTimeMoneyDtosForNotEnd() { + return this.assessUserMapper.selectUserTimeMoneyDtosForNotEnd(); + } + + /** + * @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/task/ExamProcessTask.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java index 979836e..448503a 100644 --- 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 @@ -1,16 +1,34 @@ package com.blockchain.server.yyyf.task; +import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; +import com.blockchain.server.yyyf.entity.AssessUser; +import com.blockchain.server.yyyf.service.AssessUserService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; +import java.util.List; + @Configuration @EnableScheduling public class ExamProcessTask { - @Scheduled(cron="0 0 0 1/1 * ? *") + @Autowired + private AssessUserService assessUserService; + + + //下面的原注解报错,先注释掉:llegalStateException: Encountered invalid + // @Scheduled method 'processRecording': Cron expression must consist of 6 fields (found 7 in "0 0 0 1/1 * ? *") + //@Scheduled(cron="0 0 0 1/1 * ? *") + + //每天 00:01:00 执行 + @Scheduled(cron = "0 1 0 * * ?") public void processRecording() { - //1.获取所有正在进行考核学生id(子系统userId) + //1.获取所有正在进行的考核、练习的 学生id(子系统userId),注意可能多个练习和一个考试并存 + //包含以渔有方userId、本系统userId(qUserId)、开始时间(startTime)以及各个币种余额情况 + List userTimeMoneyDtos = this.assessUserService.selectUserTimeMoneyDtosForNotEnd(); + //2.获取 币币总资产 + 法币总资产 + 数据钱包 + 初始资产 + 挂单资金 //3.计算总资产 转换成RMB 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..ef958f1 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,18 @@ - + + + + + + + + + + + + @@ -99,5 +110,9 @@ 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..4c90331 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} where id = #{item.id,jdbcType=VARCHAR} + + + + 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 4c90331..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 @@ -32,7 +32,7 @@ update yyyf_server_assess_user_target - set answer = #{item.answer,jdbcType=INTEGER} where id = #{item.id,jdbcType=VARCHAR} + set answer = #{item.answer,jdbcType=INTEGER},student_rate=#{item.studentRate,jdbcType=DECIMAL} where id = #{item.id,jdbcType=VARCHAR} From db02445950293644380f6a5ac0a09ae07b12039a Mon Sep 17 00:00:00 2001 From: unclekh <5177787+unclekh@user.noreply.gitee.com> Date: Wed, 3 Jun 2020 01:38:11 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=88=E5=86=99=E6=AD=BB=EF=BC=89=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/yyyf/service/impl/AssessUserServiceImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 bf02e6e..b428e05 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 @@ -153,8 +153,7 @@ public class AssessUserServiceImpl implements AssessUserService { List assessUserTargetList = this.assessUserTargetMapper.selectByExample(example); //获取达标参数 - Map targetResultMap =new HashMap<>();// indicatorsManager.calculatePageIndicators(assessUserId); - targetResultMap.put("GrowthRate",20f); + Map targetResultMap = indicatorsManager.calculatePageIndicators(assessUserId); //最终更新的指标库答题结果list List updateAssessUserTargetList = new ArrayList<>(); From 94cb9630a06bcacfc0b0607f3c8a96ee7a00e4c9 Mon Sep 17 00:00:00 2001 From: unclekh <5177787+unclekh@user.noreply.gitee.com> Date: Wed, 3 Jun 2020 20:37:34 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BF=AE=E6=94=B9=E8=80=83=E8=AF=95?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E9=80=BB=E8=BE=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yyyf/controller/ExamController.java | 3 +-- .../yyyf/controller/LoginController.java | 26 ++++++++++++------- .../service/impl/AssessUserServiceImpl.java | 1 - 3 files changed, 18 insertions(+), 12 deletions(-) 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 b010c59..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 @@ -115,9 +115,8 @@ public class ExamController { throw new YyyfException(YyyfEnums.FODBID_EXAM_RESTART); } Date now=new Date(); - System.out.println(now.getTime()); //系统账户初始化 - String tel=new SimpleDateFormat("yyMMddHHmm").format(now).concat(String.valueOf(yyyfUserDto.getUserId())); + 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); 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 9373a41..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 @@ -99,7 +99,7 @@ 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)); @@ -168,6 +168,14 @@ public class LoginController { 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) { @@ -192,6 +200,14 @@ public class LoginController { 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); } @@ -199,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/service/impl/AssessUserServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java index b428e05..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 @@ -141,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); } From 0345bf74493d70843e3d9db1a697d0723507c0a8 Mon Sep 17 00:00:00 2001 From: "fengyu.wang" Date: Wed, 3 Jun 2020 22:32:00 +0800 Subject: [PATCH 07/11] indicator handler --- .../indicators/DefaultIndicatorsManager.java | 6 ++- .../yyyf/indicators/IndicatorsHandler.java | 17 ++++++++ .../AnnualGrowthRateIndicatorsHandler.java | 42 +++++++++++++++++++ ...setLiabilityRiskRateIndicatorsHandler.java | 17 ++++++++ .../FluctuationRateIndicatorsHandler.java | 17 ++++++++ .../handle/GrowthRateIndicatorsHandler.java | 37 ++++++++++++++++ .../MaxDrawdownRateIndicatorsHandler.java | 17 ++++++++ .../handle/MaxLossRateIndicatorsHandler.java | 17 ++++++++ .../ProfitLossRateRateIndicatorsHandler.java | 17 ++++++++ .../handle/ShapeRateIndicatorsHandler.java | 17 ++++++++ .../handle/TVPIIndicatorsHandler.java | 17 ++++++++ .../TotalGrowthRateIndicatorsHandler.java | 17 ++++++++ 12 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AssetLiabilityRiskRateIndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TVPIIndicatorsHandler.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java 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 index 106b22a..3253952 100644 --- 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 @@ -6,6 +6,7 @@ import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.IndicatorsTypeEnum; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import lombok.AllArgsConstructor; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import java.math.BigDecimal; @@ -18,6 +19,7 @@ import java.util.Map; @Service @AllArgsConstructor public class DefaultIndicatorsManager implements IndicatorsManager { + private final ApplicationContext applicationContext; private final AssessUserTargetMapper assessUserTargetMapper; @Override @@ -64,7 +66,7 @@ public class DefaultIndicatorsManager implements IndicatorsManager { * @date 2020-05-27 22:34:19 */ private Float calculateIndicators(String assessUserId, IndicatorsTypeEnum type) { - //indicator impl - return null; + 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/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..e6e822f --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java @@ -0,0 +1,42 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +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(AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "AnnualGrowthRate"; + + private final IndicatorsManager indicatorsManager; + + @Override + public Float handleIndicator(String assessUserId) { + //TODO should be cached + List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + AssetsReporter lastAssets = reporterList + .stream() + .max(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + AssetsReporter firstAssets = reporterList + .stream() + .min(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + BigDecimal result = lastAssets.getAssets() + .divide(firstAssets.getAssets()) + .pow((int) (360.0 / lastAssets.getDays())) + .subtract(BigDecimal.valueOf(1)); + return result.divide(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..0921810 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.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(FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class FluctuationRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "FluctuationRate"; + + @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/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..28d5f27 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java @@ -0,0 +1,37 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +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(GrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class GrowthRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "GrowthRate"; + + private final IndicatorsManager indicatorsManager; + + @Override + public Float handleIndicator(String assessUserId) { + List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + AssetsReporter lastAssets = reporterList + .stream() + .max(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + AssetsReporter firstAssets = reporterList + .stream() + .min(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(firstAssets.getAssets()).divide(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..c3c4cc7 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.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(MaxDrawdownRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class MaxDrawdownRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "MaxDrawdownRate"; + + @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/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..08cb390 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.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(MaxLossRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class MaxLossRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "MaxLossRate"; + + @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/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..d58c537 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.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(ProfitLossRateRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "ProfitLossRate"; + + @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/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..01e3ee5 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.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(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class ShapeRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "AnnualGrowthRate"; + + @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/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..7b78da6 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.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(TotalGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "TotalGrowthRate"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} From c16a12ca1209e104847c4e7a6f8b6b102267fd44 Mon Sep 17 00:00:00 2001 From: "huan.xu" <275942173@qq.com> Date: Thu, 4 Jun 2020 17:57:00 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E6=8C=87=E6=A0=87=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnnualGrowthRateIndicatorsHandler.java | 5 +- .../FluctuationRateIndicatorsHandler.java | 54 ++++++++++++++++++- .../handle/GrowthRateIndicatorsHandler.java | 2 +- .../ProfitLossRateRateIndicatorsHandler.java | 49 ++++++++++++++++- .../handle/ShapeRateIndicatorsHandler.java | 26 ++++++++- .../TotalGrowthRateIndicatorsHandler.java | 29 +++++++++- 6 files changed, 157 insertions(+), 8 deletions(-) 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 index e6e822f..aa51fae 100644 --- 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 @@ -8,6 +8,7 @@ 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; @@ -34,9 +35,9 @@ public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler { .min(Comparator.comparingLong(AssetsReporter::getDays)) .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); BigDecimal result = lastAssets.getAssets() - .divide(firstAssets.getAssets()) + .divide(firstAssets.getAssets(), 5, BigDecimal.ROUND_HALF_UP) .pow((int) (360.0 / lastAssets.getDays())) .subtract(BigDecimal.valueOf(1)); - return result.divide(BigDecimal.valueOf(100)).floatValue(); + return result.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).floatValue(); } } 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 index 0921810..dc1744f 100644 --- 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 @@ -1,17 +1,69 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import lombok.AllArgsConstructor; 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"; + private final IndicatorsManager indicatorsManager; + @Override public Float handleIndicator(String assessUserId) { - return null; + List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(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 index 28d5f27..80cb987 100644 --- 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 @@ -32,6 +32,6 @@ public class GrowthRateIndicatorsHandler implements IndicatorsHandler { .stream() .min(Comparator.comparingLong(AssetsReporter::getDays)) .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); - return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(firstAssets.getAssets()).divide(BigDecimal.valueOf(100)).floatValue(); + 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/ProfitLossRateRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java index d58c537..980bac0 100644 --- 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 @@ -1,17 +1,64 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import lombok.AllArgsConstructor; 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(ProfitLossRateRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "ProfitLossRate"; + private final IndicatorsManager indicatorsManager; + @Override public Float handleIndicator(String assessUserId) { - return null; + + List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(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 index 01e3ee5..a7116f0 100644 --- 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 @@ -1,17 +1,39 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import java.math.BigDecimal; + /** * @author fengyu */ +@AllArgsConstructor @Component(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class ShapeRateIndicatorsHandler implements IndicatorsHandler { - public static final String HANDLER_NAME = "AnnualGrowthRate"; + public static final String HANDLER_NAME = "ShapeRate"; + + //无风险利率,配置文件注入,防止后期更改 + @Value("${rate.riskFree}") + private BigDecimal riskFree; + + private final AnnualGrowthRateIndicatorsHandler annualGrowthRateIndicatorsHandler; + + private final FluctuationRateIndicatorsHandler fluctuationRateIndicatorsHandler; @Override public Float handleIndicator(String assessUserId) { - return null; + + //年化收益率 + 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) + .multiply(BigDecimal.valueOf(100)).floatValue(); + } + } 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 index 7b78da6..2bcd177 100644 --- 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 @@ -1,17 +1,44 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +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(TotalGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "TotalGrowthRate"; + private final IndicatorsManager indicatorsManager; + @Override public Float handleIndicator(String assessUserId) { - return null; + List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + AssetsReporter lastAssets = reporterList + .stream() + .max(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + + //最初的金额 + AssetsReporter firstAssets = reporterList + .stream() + .min(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + //充值的总金额 + //todo 不知道如何获取 + BigDecimal rechargeAmount=null; + + return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(rechargeAmount,4,BigDecimal.ROUND_HALF_UP) + .multiply(BigDecimal.valueOf(100)).floatValue(); } } From 2451f7205ac4ff2182bb5e645825fdc6eb2e046d Mon Sep 17 00:00:00 2001 From: "huan.xu" <275942173@qq.com> Date: Fri, 5 Jun 2020 10:51:07 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=8C=87=E6=A0=87?= =?UTF-8?q?=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yyyf/indicators/IndicatorsUtils.java | 57 +++++++++++++++++++ .../indicators/dto/LastAndFirstAssetsDto.java | 14 +++++ .../AnnualGrowthRateIndicatorsHandler.java | 19 +++---- .../FluctuationRateIndicatorsHandler.java | 1 - .../handle/GrowthRateIndicatorsHandler.java | 20 +++---- .../MaxDrawdownRateIndicatorsHandler.java | 43 +++++++++++++- .../handle/MaxLossRateIndicatorsHandler.java | 45 ++++++++++++++- .../handle/ShapeRateIndicatorsHandler.java | 2 +- .../TotalGrowthRateIndicatorsHandler.java | 18 +++--- 9 files changed, 183 insertions(+), 36 deletions(-) create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsUtils.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/LastAndFirstAssetsDto.java 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/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 index aa51fae..d9851bd 100644 --- 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 @@ -2,14 +2,13 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; import lombok.AllArgsConstructor; 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; /** @@ -26,14 +25,12 @@ public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler { public Float handleIndicator(String assessUserId) { //TODO should be cached List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); - AssetsReporter lastAssets = reporterList - .stream() - .max(Comparator.comparingLong(AssetsReporter::getDays)) - .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); - AssetsReporter firstAssets = reporterList - .stream() - .min(Comparator.comparingLong(AssetsReporter::getDays)) - .orElseThrow(() -> new EntityExistsException("assessUser:" + 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())) 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 index dc1744f..326a5ca 100644 --- 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 @@ -60,7 +60,6 @@ public class FluctuationRateIndicatorsHandler implements IndicatorsHandler { 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 index 80cb987..7c93d1e 100644 --- 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 @@ -2,13 +2,13 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; -import javax.persistence.EntityExistsException; import java.math.BigDecimal; -import java.util.Comparator; import java.util.List; /** @@ -24,14 +24,12 @@ public class GrowthRateIndicatorsHandler implements IndicatorsHandler { @Override public Float handleIndicator(String assessUserId) { List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); - AssetsReporter lastAssets = reporterList - .stream() - .max(Comparator.comparingLong(AssetsReporter::getDays)) - .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); - AssetsReporter firstAssets = reporterList - .stream() - .min(Comparator.comparingLong(AssetsReporter::getDays)) - .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); - return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(firstAssets.getAssets(),4,BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).floatValue(); + //获取最初、最后交易的信息 + 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 index c3c4cc7..e1fffcd 100644 --- 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 @@ -1,17 +1,58 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import lombok.AllArgsConstructor; 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(MaxDrawdownRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class MaxDrawdownRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "MaxDrawdownRate"; + + private final IndicatorsManager indicatorsManager; + @Override public Float handleIndicator(String assessUserId) { - return null; + List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(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 index 08cb390..dad8f98 100644 --- 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 @@ -1,17 +1,60 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +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 IndicatorsManager indicatorsManager; @Override public Float handleIndicator(String assessUserId) { - return null; + List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(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/ShapeRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java index a7116f0..1d3a1a8 100644 --- 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 @@ -32,7 +32,7 @@ public class ShapeRateIndicatorsHandler implements IndicatorsHandler { Float fluctuationRate=fluctuationRateIndicatorsHandler.handleIndicator(assessUserId); return BigDecimal.valueOf(annualGrowthRate).subtract(riskFree).divide(BigDecimal.valueOf(fluctuationRate),4,BigDecimal.ROUND_HALF_UP) - .multiply(BigDecimal.valueOf(100)).floatValue(); + .floatValue(); } 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 index 2bcd177..6be2247 100644 --- 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 @@ -2,7 +2,9 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; @@ -24,16 +26,12 @@ public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { @Override public Float handleIndicator(String assessUserId) { List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); - AssetsReporter lastAssets = reporterList - .stream() - .max(Comparator.comparingLong(AssetsReporter::getDays)) - .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); - - //最初的金额 - AssetsReporter firstAssets = reporterList - .stream() - .min(Comparator.comparingLong(AssetsReporter::getDays)) - .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + //获取最初、最后交易的信息 + LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); + + AssetsReporter lastAssets =lastAndFirstAssetsDto.getLastAssets(); + AssetsReporter firstAssets =lastAndFirstAssetsDto.getFirstAssets(); + //充值的总金额 //todo 不知道如何获取 BigDecimal rechargeAmount=null; From dc0e7f543d0fa924be1a9703623e5936b0a9a6a8 Mon Sep 17 00:00:00 2001 From: "fengyu.wang" Date: Fri, 5 Jun 2020 23:21:45 +0800 Subject: [PATCH 10/11] add cache & assetsReporter impl --- .../indicators/DefaultIndicatorsManager.java | 12 ------ .../yyyf/indicators/IndicatorsManager.java | 21 ---------- .../yyyf/indicators/dto/AssetsReporter.java | 4 ++ .../AnnualGrowthRateIndicatorsHandler.java | 18 +++++---- .../FluctuationRateIndicatorsHandler.java | 11 +++-- .../handle/GrowthRateIndicatorsHandler.java | 6 +-- .../MaxDrawdownRateIndicatorsHandler.java | 7 ++-- .../handle/MaxLossRateIndicatorsHandler.java | 6 +-- .../ProfitLossRateRateIndicatorsHandler.java | 7 ++-- .../handle/ShapeRateIndicatorsHandler.java | 9 +++-- .../TotalGrowthRateIndicatorsHandler.java | 8 ++-- .../yyyf/mapper/AssetsReporterMapper.java | 15 +++++++ .../yyyf/service/AssetsReporterService.java | 26 ++++++++++++ .../impl/AssetsReporterServiceImpl.java | 40 +++++++++++++++++++ .../server/yyyf/task/ExamProcessTask.java | 8 +++- .../src/main/resources/bootstrap.yml | 1 + .../resources/mapper/AssetsReporterMapper.xml | 38 ++++++++++++++++++ 17 files changed, 170 insertions(+), 67 deletions(-) create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssetsReporterMapper.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssetsReporterService.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssetsReporterMapper.xml 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 index 3253952..a212e4d 100644 --- 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 @@ -2,7 +2,6 @@ package com.blockchain.server.yyyf.indicators; import cn.hutool.core.map.MapUtil; import com.blockchain.server.yyyf.entity.AssessUserTarget; -import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.IndicatorsTypeEnum; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import lombok.AllArgsConstructor; @@ -22,17 +21,6 @@ public class DefaultIndicatorsManager implements IndicatorsManager { private final ApplicationContext applicationContext; private final AssessUserTargetMapper assessUserTargetMapper; - @Override - public void saveAssetsReporter(List assetsReporterList) { - //TODO save to db - } - - @Override - public List getAssetsReporterListByAssessUserId(String assessUserId) { - //TODO select from db - return null; - } - @Override public Map calculatePageIndicators(String assessUserId) { List assessUserTargets = assessUserTargetMapper.selectAllStudentAssessUserTargetByIssueId(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 index 4118f70..8fbc58c 100644 --- 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 @@ -1,33 +1,12 @@ package com.blockchain.server.yyyf.indicators; -import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; - import java.math.BigDecimal; -import java.util.List; import java.util.Map; /** * @author fengyu */ public interface IndicatorsManager { - /** - * save assets reporter item - * - * @param assetsReporterList assets reporter list to do save - * @author fengyu.wang - * @date 2020-05-27 22:32:30 - */ - void saveAssetsReporter(List assetsReporterList); - - /** - * get assets reporter item by assessUserId - * - * @param assessUserId page result id - * @return assets reporter list - * @author fengyu.wang - * @date 2020-05-27 22:32:49 - */ - List getAssetsReporterListByAssessUserId(String assessUserId); /** * calculate indicator by full exam 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 index 273e6f7..6484dcf 100644 --- 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 @@ -19,6 +19,10 @@ import java.util.Date; @NoArgsConstructor @AllArgsConstructor public class AssetsReporter { + /** + * primary key + */ + private String id; /** * 成绩id */ 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 index d9851bd..0578f9f 100644 --- 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 @@ -1,11 +1,12 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; -import com.blockchain.server.yyyf.indicators.IndicatorsManager; 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; @@ -18,23 +19,26 @@ import java.util.List; @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 IndicatorsManager indicatorsManager; + 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) { - //TODO should be cached - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); //获取最初、最后交易的信息 LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); - AssetsReporter lastAssets =lastAndFirstAssetsDto.getLastAssets(); - AssetsReporter firstAssets =lastAndFirstAssetsDto.getFirstAssets(); + 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.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).floatValue(); + return result.multiply(BigDecimal.valueOf(100)).floatValue(); } } 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 index 326a5ca..facc38d 100644 --- 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 @@ -1,9 +1,10 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; -import com.blockchain.server.yyyf.indicators.IndicatorsManager; 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; @@ -19,12 +20,16 @@ import java.util.List; @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 IndicatorsManager indicatorsManager; + 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 = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); if (reporterList != null && reporterList.size() > 0) { //排序 reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); 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 index 7c93d1e..b2408f3 100644 --- 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 @@ -1,10 +1,10 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; -import com.blockchain.server.yyyf.indicators.IndicatorsManager; 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; @@ -19,11 +19,11 @@ import java.util.List; public class GrowthRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "GrowthRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); //获取最初、最后交易的信息 LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); 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 index e1fffcd..8dbe567 100644 --- 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 @@ -1,14 +1,13 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; -import com.blockchain.server.yyyf.indicators.IndicatorsManager; 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.ArrayList; import java.util.Comparator; import java.util.List; @@ -21,11 +20,11 @@ public class MaxDrawdownRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "MaxDrawdownRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); if (reporterList != null && reporterList.size() > 0) { //排序 reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); 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 index dad8f98..a4f42e3 100644 --- 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 @@ -1,8 +1,8 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; -import com.blockchain.server.yyyf.indicators.IndicatorsManager; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import com.blockchain.server.yyyf.service.AssetsReporterService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; @@ -17,11 +17,11 @@ import java.util.List; @Component(MaxLossRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class MaxLossRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "MaxLossRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); if (reporterList != null && reporterList.size() > 0) { //如果期初资产 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 index 980bac0..c5aa1c7 100644 --- 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 @@ -1,14 +1,13 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; -import com.blockchain.server.yyyf.indicators.IndicatorsManager; 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.ArrayList; import java.util.Comparator; import java.util.List; @@ -20,12 +19,12 @@ import java.util.List; public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "ProfitLossRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); if (reporterList != null && reporterList.size() > 0) { //排序 reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); 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 index 1d3a1a8..0f4d64d 100644 --- 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 @@ -1,16 +1,15 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; -import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.math.BigDecimal; /** * @author fengyu */ -@AllArgsConstructor @Component(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class ShapeRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "ShapeRate"; @@ -19,9 +18,11 @@ public class ShapeRateIndicatorsHandler implements IndicatorsHandler { @Value("${rate.riskFree}") private BigDecimal riskFree; - private final AnnualGrowthRateIndicatorsHandler annualGrowthRateIndicatorsHandler; + @Resource(name = AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) + private AnnualGrowthRateIndicatorsHandler annualGrowthRateIndicatorsHandler; - private final FluctuationRateIndicatorsHandler fluctuationRateIndicatorsHandler; + @Resource(name = FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) + private FluctuationRateIndicatorsHandler fluctuationRateIndicatorsHandler; @Override public Float handleIndicator(String assessUserId) { 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 index 6be2247..4fe2f31 100644 --- 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 @@ -1,16 +1,14 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; -import com.blockchain.server.yyyf.indicators.IndicatorsManager; 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 javax.persistence.EntityExistsException; import java.math.BigDecimal; -import java.util.Comparator; import java.util.List; /** @@ -21,11 +19,11 @@ import java.util.List; public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "TotalGrowthRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); //获取最初、最后交易的信息 LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); 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/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/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..25d895c --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java @@ -0,0 +1,40 @@ +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) { + 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 index d403f62..de72902 100644 --- 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 @@ -7,6 +7,8 @@ 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; @@ -26,6 +28,7 @@ public class ExamProcessTask { private final AssessUserService assessUserService; private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Scheduled(cron = "0 1 0 * * ?") public void processRecording() { @@ -35,6 +38,7 @@ public class ExamProcessTask { userTimeMoneyList.forEach(entity -> { BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId()); assetsReporterList.add(AssetsReporter.builder() + .id(IdGenerator.uuid()) .assessUserId(entity.getAssessUserId()) .assets(assets) .days(DateUtil.between(entity.getStartTime(), now, DateUnit.DAY)) @@ -42,6 +46,8 @@ public class ExamProcessTask { .createTime(now) .build()); }); - indicatorsManager.saveAssetsReporter(assetsReporterList); + 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/AssetsReporterMapper.xml b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssetsReporterMapper.xml new file mode 100644 index 0000000..858cb31 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssetsReporterMapper.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + id, assess_user_id, coin_name, days, assets, create_time + + + + insert into yyyf_assets_reporter + () + values + + ( + #{assetsReporter.id}, + #{assetsReporter.assess_user_id}, + #{assetsReporter.coin_name}, + #{assetsReporter.days}, + #{assetsReporter.assets}, + #{assetsReporter.create_time} + ) + + + + + From 2333adaf8f7544fffe155353d7fd43da361e0462 Mon Sep 17 00:00:00 2001 From: "fengyu.wang" Date: Sat, 6 Jun 2020 23:06:19 +0800 Subject: [PATCH 11/11] feign api support --- .../eth/inner/ConfigWalletParamInner.java | 24 +++++++++++++ .../server/eth/inner/EthWalletInner.java | 17 +++++---- .../server/yyyf/feign/BtcFeign.java | 18 ++++++++++ .../server/yyyf/feign/CurrencyFeign.java | 13 +++++++ .../server/yyyf/feign/EosFeign.java | 14 ++++++++ .../server/yyyf/feign/EthFeign.java | 20 +++++++++++ .../server/yyyf/feign/dto/BtcWalletDTO.java | 29 +++++++++++++++ .../yyyf/feign/dto/CurrencyMarketDTO.java | 36 +++++++++++++++++++ .../server/yyyf/feign/dto/EosWalletDTO.java | 29 +++++++++++++++ .../server/yyyf/feign/dto/EthWalletDTO.java | 24 +++++++++++++ .../indicators/DefaultIndicatorsManager.java | 7 +++- .../yyyf/indicators/IndicatorsManager.java | 3 +- .../server/yyyf/mapper/AssessUserMapper.java | 4 ++- .../impl/AssetsReporterServiceImpl.java | 1 + .../server/yyyf/task/ExamProcessTask.java | 2 +- .../resources/mapper/AssessUserMapper.xml | 5 +++ 16 files changed, 233 insertions(+), 13 deletions(-) create mode 100644 blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/ConfigWalletParamInner.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/BtcWalletDTO.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/CurrencyMarketDTO.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EosWalletDTO.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EthWalletDTO.java 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 233af76..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 @@ -61,8 +60,8 @@ public class EthWalletInner { } @GetMapping("/getWallets") - public ResultDTO getWallets(@RequestParam("userId") String userId, - @RequestParam(name = "walletType", required = false) String walletType) { + 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-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 index a212e4d..a20f726 100644 --- 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 @@ -1,8 +1,10 @@ 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; @@ -20,6 +22,7 @@ import java.util.Map; public class DefaultIndicatorsManager implements IndicatorsManager { private final ApplicationContext applicationContext; private final AssessUserTargetMapper assessUserTargetMapper; + private final AssessUserMapper assessUserMapper; @Override public Map calculatePageIndicators(String assessUserId) { @@ -33,8 +36,10 @@ public class DefaultIndicatorsManager implements IndicatorsManager { } @Override - public BigDecimal calculateCurrentTotalAssets(String userId) { + public BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId) { //feign interface call + UserTimeMoneyDto timeMoneyDto = assessUserMapper.selectCurrentUserTimeMoneyDto(assessUserId, userId); + //1.获取 币币总资产 + 法币总资产 + 数字钱包 + 初始资产 + 挂单资金 //cache rate 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 index 8fbc58c..ab676ac 100644 --- 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 @@ -22,9 +22,10 @@ public interface IndicatorsManager { * 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); + BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId); } 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 3f6e8bc..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 @@ -50,4 +50,6 @@ public interface AssessUserMapper extends Mapper { * @return com.blockchain.server.yyyf.dto.UserTimeMoneyDto **/ UserTimeMoneyDto getUserTimeMoneyDtoByAssessUserId(@Param("assessUserId") String assessUserId); -} \ No newline at end of file + + 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/service/impl/AssetsReporterServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java index 25d895c..cf6b2c1 100644 --- 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 @@ -25,6 +25,7 @@ public class AssetsReporterServiceImpl implements AssetsReporterService { @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())))); 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 index de72902..6ddae80 100644 --- 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 @@ -36,7 +36,7 @@ public class ExamProcessTask { List assetsReporterList = new ArrayList<>(userTimeMoneyList.size()); DateTime now = DateUtil.date(); userTimeMoneyList.forEach(entity -> { - BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId()); + BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId(), entity.getAssessUserId()); assetsReporterList.add(AssetsReporter.builder() .id(IdGenerator.uuid()) .assessUserId(entity.getAssessUserId()) 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 b45903d..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 @@ -125,5 +125,10 @@ from yyyf_server_assess_user au,yyyf_money m where au.id=m.assess_user_id and au.id=#{assessUserId} +