From 5e59bec0dca711eecc96e6de4d9f1f995b4b9ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B2=85?= <907037276@qq.com> Date: Wed, 17 Jan 2024 19:35:15 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81swagger=E6=8E=A5=E5=8F=A3=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tudentAccountMockTradingSystemService.java | 4 ++ .../jlw/service/UserStockTradesService.java | 62 ++++++++++++---- .../api/student/ApiStudentService.java | 71 +++++++++++++++++-- .../com/ibeetl/jlw/web/TestController.java | 5 +- .../main/resources/sql/jlw/userStockTrades.md | 2 +- 5 files changed, 120 insertions(+), 24 deletions(-) diff --git a/web/src/main/java/com/ibeetl/jlw/service/StudentAccountMockTradingSystemService.java b/web/src/main/java/com/ibeetl/jlw/service/StudentAccountMockTradingSystemService.java index 2ba1046b..2429e5c3 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/StudentAccountMockTradingSystemService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/StudentAccountMockTradingSystemService.java @@ -46,6 +46,10 @@ public class StudentAccountMockTradingSystemService extends CoreBaseService { return null; } - public Map findListByStudentId(Long studentId) { - List> maps = userStockTradesDao.findListByStudentId(studentId); - Map resultMap = new HashMap<>(); - if (maps == null || maps.size() == 0) { - maps = userStockTradesDao.findListByStudentId(4048L); - } - for (Map map : maps) { - String strCreateTime = (String) map.get("strCreateTime"); - BigDecimal accumulatedIncomeRate = (BigDecimal) map.get("accumulatedIncomeRate"); - resultMap.put(strCreateTime, accumulatedIncomeRate); + private static List> partitionList(List list, int batchSize) { + List> partitions = new ArrayList<>(); + for (int i = 0; i < list.size(); i += batchSize) { + int end = Math.min(i + batchSize, list.size()); + partitions.add(list.subList(i, end)); } - return resultMap; + return partitions; } @@ -199,14 +197,48 @@ public class UserStockTradesService extends CoreBaseService { } } + public Map findListByStudentId(Long studentId) { + List> maps = userStockTradesDao.findListByStudentId(studentId); + Map resultMap = new HashMap<>(); + if (maps == null || maps.size() == 0) { + maps = userStockTradesDao.findListByStudentId(4048L); + } + for (Map map : maps) { + String strCreateTime = (String) map.get("strCreateTime"); + BigDecimal accumulatedTotalProfitLoss = (BigDecimal) map.get("accumulatedTotalProfitLoss"); + resultMap.put(strCreateTime, accumulatedTotalProfitLoss.doubleValue()); + } + return resultMap; + } + //定时获取交易数据 - @Scheduled(cron = "0 32 11 * * ?") - public void fetchTransactionData() { + @Scheduled(cron = "0 30 0 * * ?") + public void threadRun() { + ExecutorService executorService = Executors.newFixedThreadPool(10); + + // 获取所有学生数据 List students = studentService.getAll(); - int i =0; + // 定义每个线程处理的学生数量 + int batchSize = 2000; + // 将学生列表分成多个子列表 + List> studentBatches = partitionList(students, batchSize); + + // 提交每个子列表的任务给线程池 + for (List batch : studentBatches) { + executorService.submit(() -> fetchTransactionData(batch)); + } + + // 关闭线程池 + executorService.shutdown(); + } + + + public void fetchTransactionData(List students) { +// List students = studentService.getAll(); + int i = 0; SimpleDateFormat stringDateFormat = new SimpleDateFormat("yyyy-MM-dd"); for (Student student : students) { - System.out.println("-------------------已处理:"+i++); + System.out.println("-------------------已处理:" + i++); if (StringUtils.hasText(student.getAccountIdByStock())) { if (userStockTradesDao.findBySecTypeAndStudentIdAndCreateTime(student.getStudentId(), 1, stringDateFormat.format(new java.util.Date())) == null) { UserStockTrades userStockTrades = getUserStockTrades(student.getAccountIdByStock()); diff --git a/web/src/main/java/com/ibeetl/jlw/service/api/student/ApiStudentService.java b/web/src/main/java/com/ibeetl/jlw/service/api/student/ApiStudentService.java index f6c619bc..1186f53c 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/api/student/ApiStudentService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/api/student/ApiStudentService.java @@ -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 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 all = hsValuesService.findAll(); Map lineMap = new HashMap<>(); if (all != null && all.size() > 0) { @@ -170,14 +210,15 @@ public class ApiStudentService { List yList = new ArrayList<>(); List yList1 = new ArrayList<>(); List> yLists = new ArrayList<>(); - Map stockTrades = userStockTradesService.findListByStudentId(studentId); + Map 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; + } } diff --git a/web/src/main/java/com/ibeetl/jlw/web/TestController.java b/web/src/main/java/com/ibeetl/jlw/web/TestController.java index 14601c2e..a063df2e 100644 --- a/web/src/main/java/com/ibeetl/jlw/web/TestController.java +++ b/web/src/main/java/com/ibeetl/jlw/web/TestController.java @@ -14,6 +14,7 @@ import com.ibeetl.jlw.entity.dto.CreateUserDTO; import com.ibeetl.jlw.enums.GenderEnum; import com.ibeetl.jlw.service.*; import com.ibeetl.jlw.util.ZhiYunJDBCUtil; +import com.ibeetl.jlw.web.query.SchoolClassQuery; import com.ibeetl.jlw.web.query.UniversitiesCollegesJurisdictionExperimentalSystemQuery; import com.ibeetl.jlw.web.query.UniversityFacultyQuery; import com.ibeetl.jlw.web.query.UniversitySystemQuery; @@ -632,7 +633,9 @@ public class TestController { @ApiOperation("修改班级2.0id") @PostMapping("updateOldClassId.json") public void updateOldClassId() throws SQLException { - List classes = schoolClassService.getAll(); + SchoolClassQuery query = new SchoolClassQuery(); + query.setUniversitiesCollegesId(184L); + List classes = schoolClassService.getValuesByQuery(query); Connection connection = openConn(); PreparedStatement ps = null; for (SchoolClass schoolClass : classes) { diff --git a/web/src/main/resources/sql/jlw/userStockTrades.md b/web/src/main/resources/sql/jlw/userStockTrades.md index 0a6bf9a0..8aab4951 100644 --- a/web/src/main/resources/sql/jlw/userStockTrades.md +++ b/web/src/main/resources/sql/jlw/userStockTrades.md @@ -5,7 +5,7 @@ select * from user_stock_trades where student_id=#studentId# and str_create_time findListByStudentId === - select str_create_time,accumulated_income_rate from user_stock_trades where student_id=#studentId# + select str_create_time,sum(accumulated_total_profit_loss) as accumulatedTotalProfitLoss from user_stock_trades where student_id=#studentId# group by str_create_time