commit
cd1779b367
65 changed files with 1798 additions and 244 deletions
@ -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<GasDTO> getGasConfig(@RequestParam(value = "tokenSymbol", defaultValue = EthConfigConstants.MODULE_TYPE) String tokenSymbol) { |
||||
return ResultDTO.requstSuccess(walletParamService.getGasConfig(tokenSymbol)); |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
@ -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; |
||||
|
||||
|
||||
} |
@ -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<AssessUser> { |
||||
|
||||
} |
@ -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<YyyfUser> { |
||||
|
||||
} |
@ -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); |
||||
} |
@ -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); |
||||
|
||||
} |
@ -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); |
||||
} |
||||
|
||||
|
||||
} |
@ -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); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,5 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.blockchain.server.user.mapper.AssessUserMapper"> |
||||
|
||||
</mapper> |
@ -1,6 +0,0 @@ |
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!DOCTYPE mapper |
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.blockchain.server.user.mapper.YyyfUserMapper"> |
||||
</mapper> |
@ -0,0 +1,38 @@ |
||||
package com.blockchain.server.yyyf.dto; |
||||
|
||||
import com.blockchain.server.yyyf.entity.YyyfMoney; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
import java.io.Serializable; |
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author Mr.Xu |
||||
* @version 1.0 |
||||
* @className UserTimeMoneyDto |
||||
* @description 包含以渔有方userId、本系统userId、开始时间以及各个币种余额情况 |
||||
* @date 2020-06-01 21:23 |
||||
*/ |
||||
@ApiModel("用户余额Dto") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class UserTimeMoneyDto extends YyyfMoney implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 5093452353347277920L; |
||||
@ApiModelProperty("以渔有方用户id") |
||||
private Integer userId; |
||||
@ApiModelProperty("本系统用户id") |
||||
private String qUserId; |
||||
@ApiModelProperty("开始时间") |
||||
private Date startTime; |
||||
@ApiModelProperty("支付宝初始资金") |
||||
private BigDecimal aliPayInit; |
||||
@ApiModelProperty("微信支付初始资金") |
||||
private BigDecimal wxPayInit; |
||||
@ApiModelProperty("银行卡初始资金") |
||||
private BigDecimal bankCardInit; |
||||
} |
@ -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<List<BtcWalletDTO>> getWallets(@RequestParam("userId") String userId, |
||||
@RequestParam("walletType") String walletType); |
||||
} |
@ -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<CurrencyMarketDTO> getList(@RequestParam("currencyPair") String currencyPair); |
||||
} |
@ -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<List<EosWalletDTO>> selectWalletByWalletType(String userOpenId, String walletType); |
||||
} |
@ -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<List<EthWalletDTO>> getWallets(@RequestParam("userId") String userId, |
||||
@RequestParam(name = "walletType") String walletType); |
||||
|
||||
@GetMapping("/inner/walletParam/getGasConfig") |
||||
ResultDTO<GasDTO> getGasConfig(String tokenSymbol); |
||||
} |
@ -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; |
||||
|
||||
} |
@ -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<CurrencyMarketDTO> { |
||||
|
||||
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); |
||||
} |
||||
} |
@ -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; |
||||
|
||||
} |
@ -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; |
||||
} |
@ -0,0 +1,65 @@ |
||||
package com.blockchain.server.yyyf.indicators; |
||||
|
||||
import cn.hutool.core.map.MapUtil; |
||||
import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; |
||||
import com.blockchain.server.yyyf.entity.AssessUserTarget; |
||||
import com.blockchain.server.yyyf.indicators.dto.IndicatorsTypeEnum; |
||||
import com.blockchain.server.yyyf.mapper.AssessUserMapper; |
||||
import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class DefaultIndicatorsManager implements IndicatorsManager { |
||||
private final ApplicationContext applicationContext; |
||||
private final AssessUserTargetMapper assessUserTargetMapper; |
||||
private final AssessUserMapper assessUserMapper; |
||||
|
||||
@Override |
||||
public Map<String, Float> calculatePageIndicators(String assessUserId) { |
||||
List<AssessUserTarget> assessUserTargets = assessUserTargetMapper.selectAllStudentAssessUserTargetByIssueId(assessUserId); |
||||
Map<String, Float> result = MapUtil.newHashMap(); |
||||
assessUserTargets.parallelStream().forEach(assessUser -> { |
||||
Float total = this.calculateIndicators(assessUserId, IndicatorsTypeEnum.parseCode(assessUser.getCode())); |
||||
result.put(assessUser.getCode(), total); |
||||
}); |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId) { |
||||
//feign interface call
|
||||
UserTimeMoneyDto timeMoneyDto = assessUserMapper.selectCurrentUserTimeMoneyDto(assessUserId, userId); |
||||
|
||||
|
||||
//1.获取 币币总资产 + 法币总资产 + 数字钱包 + 初始资产 + 挂单资金
|
||||
//cache rate
|
||||
//2.计算总资产 转换成RMB
|
||||
//cache RMB rate
|
||||
return null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* calculate single indicator |
||||
* |
||||
* @param assessUserId page result id |
||||
* @param type indicators type |
||||
* @return indicators result |
||||
* @author fengyu.wang |
||||
* @date 2020-05-27 22:34:19 |
||||
*/ |
||||
private Float calculateIndicators(String assessUserId, IndicatorsTypeEnum type) { |
||||
IndicatorsHandler indicatorsHandler = applicationContext.getBean(type.getCode(), IndicatorsHandler.class); |
||||
return indicatorsHandler.handleIndicator(assessUserId); |
||||
} |
||||
} |
@ -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); |
||||
} |
@ -0,0 +1,31 @@ |
||||
package com.blockchain.server.yyyf.indicators; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
public interface IndicatorsManager { |
||||
|
||||
/** |
||||
* calculate indicator by full exam |
||||
* |
||||
* @param assessUserId page result id |
||||
* @return indicators type -> indicators result |
||||
* @author fengyu.wang |
||||
* @date 2020-05-27 22:36:01 |
||||
*/ |
||||
Map<String, Float> calculatePageIndicators(String assessUserId); |
||||
|
||||
/** |
||||
* calculate current total asset |
||||
* |
||||
* @param userId system user id |
||||
* @param assessUserId page result id |
||||
* @return current total assets (RMB) |
||||
* @author fengyu.wang |
||||
* @date 2020-06-02 20:15:15 |
||||
*/ |
||||
BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId); |
||||
} |
@ -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<AssetsReporter> 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"); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,46 @@ |
||||
package com.blockchain.server.yyyf.indicators.dto; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* assets recoding day by day |
||||
* |
||||
* @author fengyu.wang |
||||
* @date 2020-05-27 22:59:34 |
||||
*/ |
||||
@Data |
||||
@Builder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class AssetsReporter { |
||||
/** |
||||
* primary key |
||||
*/ |
||||
private String id; |
||||
/** |
||||
* 成绩id |
||||
*/ |
||||
private String assessUserId; |
||||
/** |
||||
* 币种 |
||||
*/ |
||||
private String coinName; |
||||
/** |
||||
* 交易天数 |
||||
*/ |
||||
private long days; |
||||
/** |
||||
* 资产总额 |
||||
*/ |
||||
private BigDecimal assets; |
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
private Date createTime; |
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.blockchain.server.yyyf.indicators.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* indicators persist |
||||
* |
||||
* @author fengyu.wang |
||||
* @date 2020-05-27 22:55:14 |
||||
*/ |
||||
@Data |
||||
public class IndicatorsDetail { |
||||
private String assessUserId; |
||||
private IndicatorsTypeEnum type; |
||||
private float indicator; |
||||
} |
@ -0,0 +1,46 @@ |
||||
package com.blockchain.server.yyyf.indicators.dto; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
|
||||
public enum IndicatorsTypeEnum { |
||||
/*年化收益率*/ |
||||
ANNUAL_GROWTH_RATE("AnnualGrowthRate"), |
||||
/*收益率*/ |
||||
GROWTH_RATE("GrowthRate"), |
||||
/*累计收益率*/ |
||||
TOTAL_GROWTH_RATE("TotalGrowthRate"), |
||||
/*波动率*/ |
||||
FLUCTUATION_RATE("FluctuationRate"), |
||||
/*夏普比率*/ |
||||
SHAPE_RATE("ShapeRate"), |
||||
/*盈亏比*/ |
||||
PROFIT_LOSS_RATE("ProfitLossRate"), |
||||
/*最大回撤率*/ |
||||
MAX_DRAWDOWN_RATE("MaxDrawdownRate"), |
||||
/*最大亏损率*/ |
||||
MAX_LOSS_RATE("MaxLossRate"), |
||||
/*风险率(资产负债比)*/ |
||||
ASSET_LIABILITY_RISK_RATE("AssetLiabilityRiskRate"), |
||||
/*TVPI*/ |
||||
TVPI("TVPI"); |
||||
|
||||
@Getter |
||||
private final String code; |
||||
|
||||
IndicatorsTypeEnum(String code) { |
||||
this.code = code; |
||||
} |
||||
|
||||
public static IndicatorsTypeEnum parseCode(String code) { |
||||
for (IndicatorsTypeEnum value : IndicatorsTypeEnum.values()) { |
||||
if (code.equals(value.getCode())) { |
||||
return value; |
||||
} |
||||
} |
||||
throw new IllegalArgumentException(); |
||||
} |
||||
} |
@ -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; |
||||
} |
@ -0,0 +1,44 @@ |
||||
package com.blockchain.server.yyyf.indicators.handle; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||
import com.blockchain.server.yyyf.indicators.IndicatorsUtils; |
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.cache.annotation.Cacheable; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@AllArgsConstructor |
||||
@Component(AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler { |
||||
public static final String HANDLER_NAME = "AnnualGrowthRate"; |
||||
public static final String CACHE_ANNUAL_GROWTH_RATE = "yyyf_indicator_annualGrowthRate"; |
||||
public static final String CACHE_KEY_ANNUAL_GROWTH_RATE = "yyyf:annualGrowthRate:"; |
||||
|
||||
private final AssetsReporterService assetsReporterService; |
||||
|
||||
@Override |
||||
@Cacheable(cacheNames = CACHE_ANNUAL_GROWTH_RATE, |
||||
key = "#root.target.CACHE_KEY_ANNUAL_GROWTH_RATE.concat(#assessUserId)", unless = "#result == null") |
||||
public Float handleIndicator(String assessUserId) { |
||||
List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); |
||||
|
||||
//获取最初、最后交易的信息
|
||||
LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); |
||||
|
||||
AssetsReporter lastAssets = lastAndFirstAssetsDto.getLastAssets(); |
||||
AssetsReporter firstAssets = lastAndFirstAssetsDto.getFirstAssets(); |
||||
BigDecimal result = lastAssets.getAssets() |
||||
.divide(firstAssets.getAssets(), 5, BigDecimal.ROUND_HALF_UP) |
||||
.pow((int) (360.0 / lastAssets.getDays())) |
||||
.subtract(BigDecimal.valueOf(1)); |
||||
return result.multiply(BigDecimal.valueOf(100)).floatValue(); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -0,0 +1,73 @@ |
||||
package com.blockchain.server.yyyf.indicators.handle; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.cache.annotation.Cacheable; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.persistence.EntityExistsException; |
||||
import java.math.BigDecimal; |
||||
import java.util.ArrayList; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@AllArgsConstructor |
||||
@Component(FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
public class FluctuationRateIndicatorsHandler implements IndicatorsHandler { |
||||
public static final String HANDLER_NAME = "FluctuationRate"; |
||||
public static final String CACHE_FLUCTUATION_RATE = "yyyf_indicator_fluctuationRate"; |
||||
public static final String CACHE_KEY_FLUCTUATION_RATE = "yyyf:fluctuationRate:"; |
||||
|
||||
private final AssetsReporterService assetsReporterService; |
||||
|
||||
@Override |
||||
@Cacheable(cacheNames = CACHE_FLUCTUATION_RATE, |
||||
key = "#root.target.CACHE_KEY_FLUCTUATION_RATE.concat(#assessUserId)", unless = "#result == null") |
||||
public Float handleIndicator(String assessUserId) { |
||||
List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); |
||||
if (reporterList != null && reporterList.size() > 0) { |
||||
//排序
|
||||
reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); |
||||
//总天数
|
||||
int dayCount = reporterList.size() - 1; |
||||
//每日收益率List
|
||||
List<BigDecimal> dayYieldList = new ArrayList<BigDecimal>(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); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@ |
||||
package com.blockchain.server.yyyf.indicators.handle; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||
import com.blockchain.server.yyyf.indicators.IndicatorsUtils; |
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@AllArgsConstructor |
||||
@Component(GrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
public class GrowthRateIndicatorsHandler implements IndicatorsHandler { |
||||
public static final String HANDLER_NAME = "GrowthRate"; |
||||
|
||||
private final AssetsReporterService assetsReporterService; |
||||
|
||||
@Override |
||||
public Float handleIndicator(String assessUserId) { |
||||
List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); |
||||
//获取最初、最后交易的信息
|
||||
LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); |
||||
|
||||
AssetsReporter lastAssets =lastAndFirstAssetsDto.getLastAssets(); |
||||
AssetsReporter firstAssets =lastAndFirstAssetsDto.getFirstAssets(); |
||||
|
||||
return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(firstAssets.getAssets(), 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).floatValue(); |
||||
} |
||||
} |
@ -0,0 +1,57 @@ |
||||
package com.blockchain.server.yyyf.indicators.handle; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.persistence.EntityExistsException; |
||||
import java.math.BigDecimal; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@AllArgsConstructor |
||||
@Component(MaxDrawdownRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
public class MaxDrawdownRateIndicatorsHandler implements IndicatorsHandler { |
||||
public static final String HANDLER_NAME = "MaxDrawdownRate"; |
||||
|
||||
|
||||
private final AssetsReporterService assetsReporterService; |
||||
|
||||
@Override |
||||
public Float handleIndicator(String assessUserId) { |
||||
List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); |
||||
if (reporterList != null && reporterList.size() > 0) { |
||||
//排序
|
||||
reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); |
||||
|
||||
BigDecimal maxDrawdownRate=BigDecimal.ZERO; |
||||
//上一天的资产总额
|
||||
BigDecimal upAssets =BigDecimal.ZERO; |
||||
for (AssetsReporter assetsReporter : reporterList) { |
||||
BigDecimal thisAssets=assetsReporter.getAssets(); |
||||
//交易第二天开始
|
||||
if(assetsReporter.getDays()>1){ |
||||
BigDecimal thisDrawdownRate=BigDecimal.ONE.subtract(thisAssets.divide(upAssets,4,BigDecimal.ROUND_HALF_UP)); |
||||
if(thisDrawdownRate.compareTo(maxDrawdownRate)==1){ |
||||
maxDrawdownRate=thisDrawdownRate; |
||||
} |
||||
}else{ |
||||
//交易的第一天
|
||||
if(assetsReporter.getDays()==1){ |
||||
maxDrawdownRate=BigDecimal.ONE.subtract(thisAssets.divide(upAssets,4,BigDecimal.ROUND_HALF_UP)); |
||||
} |
||||
|
||||
} |
||||
upAssets=thisAssets; |
||||
} |
||||
return maxDrawdownRate.multiply(BigDecimal.valueOf(100)).floatValue(); |
||||
} else { |
||||
throw new EntityExistsException("assessUser:" + assessUserId); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,60 @@ |
||||
package com.blockchain.server.yyyf.indicators.handle; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.persistence.EntityExistsException; |
||||
import java.math.BigDecimal; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@AllArgsConstructor |
||||
@Component(MaxLossRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
public class MaxLossRateIndicatorsHandler implements IndicatorsHandler { |
||||
public static final String HANDLER_NAME = "MaxLossRate"; |
||||
private final AssetsReporterService assetsReporterService; |
||||
|
||||
@Override |
||||
public Float handleIndicator(String assessUserId) { |
||||
List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); |
||||
|
||||
if (reporterList != null && reporterList.size() > 0) { |
||||
//如果期初资产
|
||||
AssetsReporter firstAssets = null; |
||||
//交易期内资产最小值
|
||||
AssetsReporter minAssets = null; |
||||
for (AssetsReporter assetsReporter : reporterList) { |
||||
if (assetsReporter.getDays() == 0) { //如果期初资产
|
||||
firstAssets = assetsReporter; |
||||
} else { |
||||
if (minAssets == null) { //最小的若为null
|
||||
minAssets = assetsReporter; |
||||
} else { |
||||
if (assetsReporter.getAssets().compareTo(minAssets.getAssets()) == -1) { |
||||
minAssets = assetsReporter; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
long minDay = minAssets.getDays(); |
||||
int n = (int) (360 / minDay); |
||||
|
||||
Float result = BigDecimal.ONE.subtract(minAssets.getAssets().divide(firstAssets.getAssets(), 5, BigDecimal.ROUND_HALF_UP).pow(n)) |
||||
.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); |
||||
|
||||
//负无穷的时候为0
|
||||
if (result.isInfinite()) { |
||||
result = Float.valueOf(0); |
||||
} |
||||
return result; |
||||
|
||||
} else { |
||||
throw new EntityExistsException("assessUser:"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,63 @@ |
||||
package com.blockchain.server.yyyf.indicators.handle; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.persistence.EntityExistsException; |
||||
import java.math.BigDecimal; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@AllArgsConstructor |
||||
@Component(ProfitLossRateRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler { |
||||
public static final String HANDLER_NAME = "ProfitLossRate"; |
||||
|
||||
private final AssetsReporterService assetsReporterService; |
||||
|
||||
@Override |
||||
public Float handleIndicator(String assessUserId) { |
||||
|
||||
List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); |
||||
if (reporterList != null && reporterList.size() > 0) { |
||||
//排序
|
||||
reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); |
||||
//第一天(上一天)的资产总额
|
||||
BigDecimal upAssets = reporterList.get(0).getAssets(); |
||||
|
||||
//总亏损额
|
||||
BigDecimal lossMoneyCount = BigDecimal.ZERO; |
||||
//盈利计数
|
||||
int profitCount = 0; |
||||
//总盈利额
|
||||
BigDecimal profitMoneyCount = BigDecimal.ZERO; |
||||
for (AssetsReporter assetsReporter : reporterList) { |
||||
|
||||
BigDecimal thisYeid = assetsReporter.getAssets(); |
||||
//盈利
|
||||
if (thisYeid.compareTo(upAssets) > 0) { //盈利
|
||||
profitCount++; |
||||
profitMoneyCount = profitMoneyCount.add(thisYeid).subtract(upAssets); |
||||
}else{ |
||||
lossMoneyCount = lossMoneyCount.add(thisYeid).subtract(upAssets); |
||||
} |
||||
upAssets=thisYeid; |
||||
} |
||||
if (profitCount == 0) { //每天亏损、或者每天既不盈利也不亏损
|
||||
return Float.valueOf(0); |
||||
}else if(profitCount==(reporterList.size()-1)){ //每天都在盈利
|
||||
return Float.POSITIVE_INFINITY; |
||||
}else { //计算盈亏比
|
||||
return profitMoneyCount.divide(lossMoneyCount,4,BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).floatValue(); |
||||
} |
||||
} else { |
||||
throw new EntityExistsException("assessUser:" + assessUserId); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,40 @@ |
||||
package com.blockchain.server.yyyf.indicators.handle; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@Component(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
public class ShapeRateIndicatorsHandler implements IndicatorsHandler { |
||||
public static final String HANDLER_NAME = "ShapeRate"; |
||||
|
||||
//无风险利率,配置文件注入,防止后期更改
|
||||
@Value("${rate.riskFree}") |
||||
private BigDecimal riskFree; |
||||
|
||||
@Resource(name = AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
private AnnualGrowthRateIndicatorsHandler annualGrowthRateIndicatorsHandler; |
||||
|
||||
@Resource(name = FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
private FluctuationRateIndicatorsHandler fluctuationRateIndicatorsHandler; |
||||
|
||||
@Override |
||||
public Float handleIndicator(String assessUserId) { |
||||
|
||||
//年化收益率
|
||||
Float annualGrowthRate=annualGrowthRateIndicatorsHandler.handleIndicator(assessUserId); |
||||
//波动率
|
||||
Float fluctuationRate=fluctuationRateIndicatorsHandler.handleIndicator(assessUserId); |
||||
|
||||
return BigDecimal.valueOf(annualGrowthRate).subtract(riskFree).divide(BigDecimal.valueOf(fluctuationRate),4,BigDecimal.ROUND_HALF_UP) |
||||
.floatValue(); |
||||
|
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -0,0 +1,40 @@ |
||||
package com.blockchain.server.yyyf.indicators.handle; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||
import com.blockchain.server.yyyf.indicators.IndicatorsUtils; |
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@AllArgsConstructor |
||||
@Component(TotalGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||
public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { |
||||
public static final String HANDLER_NAME = "TotalGrowthRate"; |
||||
|
||||
private final AssetsReporterService assetsReporterService; |
||||
|
||||
@Override |
||||
public Float handleIndicator(String assessUserId) { |
||||
List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); |
||||
//获取最初、最后交易的信息
|
||||
LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); |
||||
|
||||
AssetsReporter lastAssets =lastAndFirstAssetsDto.getLastAssets(); |
||||
AssetsReporter firstAssets =lastAndFirstAssetsDto.getFirstAssets(); |
||||
|
||||
//充值的总金额
|
||||
//todo 不知道如何获取
|
||||
BigDecimal rechargeAmount=null; |
||||
|
||||
return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(rechargeAmount,4,BigDecimal.ROUND_HALF_UP) |
||||
.multiply(BigDecimal.valueOf(100)).floatValue(); |
||||
} |
||||
} |
@ -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<AssetsReporter> { |
||||
|
||||
List<AssetsReporter> selectByAssessUserId(String assessUserId); |
||||
|
||||
void insertBatch(List<AssetsReporter> list); |
||||
} |
@ -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<AssetsReporter> 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<AssetsReporter> selectAssetsReporterListByAssessUserId(String assessUserId); |
||||
} |
@ -0,0 +1,41 @@ |
||||
package com.blockchain.server.yyyf.service.impl; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.mapper.AssetsReporterMapper; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.cache.CacheManager; |
||||
import org.springframework.cache.annotation.Cacheable; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class AssetsReporterServiceImpl implements AssetsReporterService { |
||||
private final AssetsReporterMapper assetsReporterMapper; |
||||
private final CacheManager cacheManager; |
||||
|
||||
public static final String CACHE_ASSETS_REPORTER = "yyyf_assets_reporter"; |
||||
public static final String CACHE_KEY_ASSETS_REPORTER = "yyyf:assetsReporter:"; |
||||
|
||||
@Override |
||||
public void saveList(List<AssetsReporter> assetsReporterList) { |
||||
//TODO Transaction rollback, retry, log
|
||||
assetsReporterList.forEach(assetsReporter -> |
||||
Optional.ofNullable(cacheManager.getCache(CACHE_ASSETS_REPORTER)) |
||||
.ifPresent(cache -> cache.evict(CACHE_KEY_ASSETS_REPORTER.concat(assetsReporter.getAssessUserId())))); |
||||
assetsReporterMapper.insertBatch(assetsReporterList); |
||||
} |
||||
|
||||
@Override |
||||
@Cacheable(cacheNames = CACHE_ASSETS_REPORTER, |
||||
key = "#root.target.CACHE_KEY_ASSETS_REPORTER.concat(#assessUserId)", unless = "#result == null") |
||||
public List<AssetsReporter> selectAssetsReporterListByAssessUserId(String assessUserId) { |
||||
return assetsReporterMapper.selectByAssessUserId(assessUserId); |
||||
} |
||||
} |
@ -0,0 +1,53 @@ |
||||
package com.blockchain.server.yyyf.task; |
||||
|
||||
import cn.hutool.core.date.DateTime; |
||||
import cn.hutool.core.date.DateUnit; |
||||
import cn.hutool.core.date.DateUtil; |
||||
import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; |
||||
import com.blockchain.server.yyyf.indicators.IndicatorsManager; |
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.service.AssessUserService; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import com.blockchain.server.yyyf.utils.IdGenerator; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.scheduling.annotation.EnableScheduling; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@Configuration |
||||
@EnableScheduling |
||||
@AllArgsConstructor |
||||
public class ExamProcessTask { |
||||
|
||||
private final AssessUserService assessUserService; |
||||
private final IndicatorsManager indicatorsManager; |
||||
private final AssetsReporterService assetsReporterService; |
||||
|
||||
@Scheduled(cron = "0 1 0 * * ?") |
||||
public void processRecording() { |
||||
List<UserTimeMoneyDto> userTimeMoneyList = this.assessUserService.selectUserTimeMoneyDtosForNotEnd(); |
||||
List<AssetsReporter> assetsReporterList = new ArrayList<>(userTimeMoneyList.size()); |
||||
DateTime now = DateUtil.date(); |
||||
userTimeMoneyList.forEach(entity -> { |
||||
BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId(), entity.getAssessUserId()); |
||||
assetsReporterList.add(AssetsReporter.builder() |
||||
.id(IdGenerator.uuid()) |
||||
.assessUserId(entity.getAssessUserId()) |
||||
.assets(assets) |
||||
.days(DateUtil.between(entity.getStartTime(), now, DateUnit.DAY)) |
||||
.coinName("RMB") |
||||
.createTime(now) |
||||
.build()); |
||||
}); |
||||
if (!assetsReporterList.isEmpty()) { |
||||
assetsReporterService.saveList(assetsReporterList); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
||||
<mapper namespace="com.blockchain.server.yyyf.mapper.AssetsReporterMapper"> |
||||
<resultMap id="BaseResultMap" type="com.blockchain.server.yyyf.indicators.dto.AssetsReporter"> |
||||
<id column="id" property="id" jdbcType="VARCHAR"/> |
||||
<result column="assess_user_id" property="assessUserId" jdbcType="VARCHAR"/> |
||||
<result column="coin_name" property="coinName" jdbcType="VARCHAR"/> |
||||
<result column="days" property="days" jdbcType="INTEGER"/> |
||||
<result column="assets" property="assets" jdbcType="DECIMAL"/> |
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> |
||||
</resultMap> |
||||
<sql id="Base_Column_List"> |
||||
id, assess_user_id, coin_name, days, assets, create_time |
||||
</sql> |
||||
|
||||
<insert id="insertBatch" parameterType="java.util.List"> |
||||
insert into yyyf_assets_reporter |
||||
(<include refid="Base_Column_List"/>) |
||||
values |
||||
<foreach collection="list" item="assetsReporter" index="index" separator=","> |
||||
( |
||||
#{assetsReporter.id}, |
||||
#{assetsReporter.assess_user_id}, |
||||
#{assetsReporter.coin_name}, |
||||
#{assetsReporter.days}, |
||||
#{assetsReporter.assets}, |
||||
#{assetsReporter.create_time} |
||||
) |
||||
</foreach> |
||||
</insert> |
||||
|
||||
<select id="selectByAssessUserId" resultMap="BaseResultMap" parameterType="java.lang.String"> |
||||
select |
||||
<include refid="Base_Column_List"/> |
||||
from yyyf_assets_reporter |
||||
where assess_user_id = #{assessUserId,jdbcType=VARCHAR} |
||||
</select> |
||||
</mapper> |
Loading…
Reference in new issue