@ -4,6 +4,8 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil ;
import cn.hutool.core.lang.Assert ;
import cn.hutool.core.util.ObjectUtil ;
import com.fasterxml.jackson.databind.JsonNode ;
import com.fasterxml.jackson.databind.ObjectMapper ;
import com.ibeetl.admin.core.conf.PasswordConfig ;
import com.ibeetl.admin.core.entity.CoreUser ;
import com.ibeetl.admin.core.service.CoreUserService ;
@ -18,6 +20,7 @@ import com.ibeetl.jlw.entity.dto.StudentEditPasswordDTO;
import com.ibeetl.jlw.entity.dto.StudentRegisterDTO ;
import com.ibeetl.jlw.service.* ;
import com.ibeetl.jlw.service.api.ApiIndexBaseService ;
import com.ibeetl.jlw.util.HttpJsonRequest ;
import com.ibeetl.jlw.web.query.TeacherOpenCourseMergeStudentQuery ;
import com.ibeetl.jlw.web.query.TeacherOpenCourseNoticeQuery ;
import org.checkerframework.checker.units.qual.A ;
@ -27,10 +30,7 @@ import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotNull ;
import java.math.BigDecimal ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.* ;
import java.util.stream.Collectors ;
import static cn.jlw.util.CacheUserUtil.getStudent ;
@ -75,6 +75,14 @@ public class ApiStudentService {
private HsValuesService hsValuesService ;
@Autowired
private UserStockTradesService userStockTradesService ;
@Autowired
private StudentAccountCrowdfundingSystemService studentAccountCrowdfundingSystemService ;
@Autowired
private StudentAccountEquityInvestmentSystemService studentAccountEquityInvestmentSystemService ;
@Autowired
private StudentAccountP2pSystemService studentAccountP2pSystemService ;
@Autowired
private StudentAccountMockTradingSystemService studentAccountMockTradingSystemService ;
/ * *
* 学 生 端 - 首 页 数 据
@ -91,6 +99,8 @@ public class ApiStudentService {
// 学生ID
final Long studentId = ( ( Student ) identityInfo ) . getStudentId ( ) ;
CoreUser coreUser = currentUserInfo . getCoreUser ( ) ;
// 获取该学生的学校信息
StudentExtendSchoolInfo studentExtendSchoolInfo = studentService . getStudentExtendSchoolInfo ( studentId . toString ( ) ) ;
@ -163,6 +173,36 @@ public class ApiStudentService {
// pieMaps.add(map7);
//我的收益率
//获取众筹收益
StudentAccountCrowdfundingSystem cfEarnings = studentAccountCrowdfundingSystemService . getInfo ( studentId ) ;
List < StudentAccountEquityInvestmentSystem > accountEquityInvestmentSystems = studentAccountEquityInvestmentSystemService . getInfo ( studentId ) ;
Double pevcEarnings = getPevcEarnings ( coreUser . getOldId ( ) ) ;
StudentAccountEquityInvestmentSystem accountEquityInvestmentSystem = accountEquityInvestmentSystems = = null ? null : accountEquityInvestmentSystems . get ( 0 ) ;
StudentAccountP2pSystem p2pEarnings = studentAccountP2pSystemService . getValuesByStudentId ( studentId ) ;
StudentAccountMockTradingSystem qhEarnings = studentAccountMockTradingSystemService . getByStudentIdAndAppId ( studentId , - 16L ) ;
StudentAccountMockTradingSystem gpEarnings = studentAccountMockTradingSystemService . getByStudentIdAndAppId ( studentId , 16L ) ;
//总资产
Double initialTotalAssets = 0D ;
if ( cfEarnings ! = null ) {
initialTotalAssets = initialTotalAssets + cfEarnings . getInitialCapital ( ) . doubleValue ( ) ;
}
if ( accountEquityInvestmentSystem ! = null ) {
initialTotalAssets = initialTotalAssets + accountEquityInvestmentSystem . getInitialCapital ( ) . doubleValue ( ) ;
}
if ( p2pEarnings ! = null ) {
initialTotalAssets = initialTotalAssets + p2pEarnings . getInitialCapital ( ) . doubleValue ( ) ;
}
if ( qhEarnings ! = null ) {
initialTotalAssets = initialTotalAssets + qhEarnings . getInitialCapital ( ) . doubleValue ( ) ;
}
if ( gpEarnings ! = null ) {
initialTotalAssets = initialTotalAssets + gpEarnings . getInitialCapital ( ) . doubleValue ( ) ;
}
Double cf = cfEarnings = = null ? 0D : cfEarnings . getCumulativeIncome ( ) . doubleValue ( ) ;
Double p2p = p2pEarnings = = null ? 0D : p2pEarnings . getCumulativeIncome ( ) . doubleValue ( ) ;
List < HsValues > all = hsValuesService . findAll ( ) ;
Map < String , Object > lineMap = new HashMap < > ( ) ;
if ( all ! = null & & all . size ( ) > 0 ) {
@ -170,14 +210,15 @@ public class ApiStudentService {
List < String > yList = new ArrayList < > ( ) ;
List < String > yList1 = new ArrayList < > ( ) ;
List < List < String > > yLists = new ArrayList < > ( ) ;
Map < String , BigDecimal > stockTrades = userStockTradesService . findListByStudentId ( studentId ) ;
Map < String , Object > stockTrades = userStockTradesService . findListByStudentId ( studentId ) ;
for ( HsValues values : all ) {
xList . add ( values . getCreateTimeStr ( ) ) ;
yList . add ( String . valueOf ( values . getHsValue ( ) * 100 ) ) ;
if ( stockTrades ! = null ) {
BigDecimal accRate = stockTrades . get ( values . getCreateTimeStr ( ) ) ;
//accRate乘以100
double accumulatedTotalProfitLoss = stockTrades . get ( values . getCreateTimeStr ( ) ) = = null ? 0 : ( Double ) stockTrades . get ( values . getCreateTimeStr ( ) ) ;
Double accRate = ( accumulatedTotalProfitLoss + pevcEarnings + cf + p2p ) / initialTotalAssets * 100 ;
//模拟交易累计盈亏
yList1 . add ( accRate = = null ? "0" : String . valueOf ( accRate ) ) ;
}
}
@ -320,4 +361,20 @@ public class ApiStudentService {
. studentInfo ( studentExtendSchoolInfo ) . activeInfo ( studentActiveInfo )
. build ( ) ;
}
private Double getPevcEarnings ( Long userId ) {
String url = "http://120.79.161.177:8029/Account/GetZyAmount?UserId=" + userId ;
String ret = HttpJsonRequest . sendPostRequest ( url , null , "UserId=" + userId , "application/x-www-form-urlencoded" ) ;
double resultValue = 0 ;
ObjectMapper objectMapper = new ObjectMapper ( ) ;
try {
JsonNode jsonNode = objectMapper . readTree ( ret ) ;
resultValue = jsonNode . get ( "result" ) . asDouble ( ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
// 获取result字段的值
return resultValue ;
}
}