|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.jwt.JWTUtil;
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
|
import com.ibeetl.admin.core.service.CoreBaseService;
|
|
|
import com.ibeetl.admin.core.service.CoreUserService;
|
|
|
import com.ibeetl.admin.core.util.PlatformException;
|
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
|
import com.ibeetl.admin.core.web.JsonReturnCode;
|
|
|
import com.ibeetl.jlw.dao.*;
|
|
|
import com.ibeetl.jlw.entity.*;
|
|
|
import com.ibeetl.jlw.enums.AccountTypeEnum;
|
|
|
import com.ibeetl.jlw.web.query.ResourcesApplicationCourseQuery;
|
|
|
import com.ibeetl.jlw.web.query.ResourcesApplicationQuery;
|
|
|
import com.ibeetl.jlw.web.query.StudentAccountAssetAllocationQuery;
|
|
|
import com.ibeetl.jlw.web.query.StudentAccountEquityInvestmentSystemQuery;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.beetl.sql.core.SqlId;
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.validation.constraints.NotBlank;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.SQLException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
import static cn.hutool.core.collection.IterUtil.getFirst;
|
|
|
import static com.ibeetl.admin.core.util.StreamUtils.listJoin;
|
|
|
import static java.util.Collections.emptyList;
|
|
|
|
|
|
/**
|
|
|
* 资产账户管理 Service
|
|
|
* 当分布式ID开启后请勿使用insert(*,true)
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
@Validated
|
|
|
public class StudentAccountAssetAllocationService extends CoreBaseService<StudentAccountAssetAllocation> {
|
|
|
|
|
|
@Autowired
|
|
|
private StudentAccountAssetAllocationDao studentAccountAssetAllocationDao;
|
|
|
@Autowired
|
|
|
private LoginTodoService loginTodoService;
|
|
|
@Autowired
|
|
|
private ResourcesApplicationService resourcesApplicationService;
|
|
|
@Autowired
|
|
|
private ResourcesApplicationCourseService resourcesApplicationCourseService;
|
|
|
@Autowired
|
|
|
private CourseInfoService courseInfoService;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private UniversitiesCollegesDao universitiesCollegesDao;
|
|
|
|
|
|
@Autowired
|
|
|
private UniversitiesCollegesJurisdictionExperimentalSystemDao universitiesCollegesJurisdictionExperimentalSystemDao;
|
|
|
|
|
|
@Autowired
|
|
|
private ResourcesApplicationDao resourcesApplicationDao;
|
|
|
|
|
|
@Autowired
|
|
|
private StudentAccountTradingRecordSheetDao studentAccountTradingRecordSheetDao;
|
|
|
|
|
|
@Autowired
|
|
|
private StudentAccountP2pSystemService studentAccountP2pSystemService;
|
|
|
@Autowired
|
|
|
private StudentAccountCrowdfundingSystemService studentAccountCrowdfundingSystemService;
|
|
|
@Autowired
|
|
|
private StudentAccountEquityInvestmentSystemService studentAccountEquityInvestmentSystemService;
|
|
|
@Autowired
|
|
|
private StudentAccountMockTradingSystemService studentAccountMockTradingSystemService;
|
|
|
|
|
|
private final static String URL = "jdbc:sqlserver://120.79.161.177:1433;databaseName=Test.Zhiyun_v2.0;trustServerCertificate=true;encrypt=true";
|
|
|
|
|
|
public PageQuery<StudentAccountAssetAllocation> queryByCondition(PageQuery query) {
|
|
|
PageQuery ret = studentAccountAssetAllocationDao.queryByCondition(query);
|
|
|
queryListAfter(ret.getList());
|
|
|
return ret;
|
|
|
}
|
|
|
private final static String USER = "sa";
|
|
|
|
|
|
public void deleteByList(List list) {
|
|
|
String ids = "";
|
|
|
ToolUtils.deleteNullList(list);
|
|
|
for (int i = 0; null != list && i < list.size(); i++) {
|
|
|
ids += list.get(i).toString() + (i == list.size() - 1 ? "" : ",");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(ids)) {
|
|
|
studentAccountAssetAllocationDao.deleteStudentAccountAssetAllocationByIds(ids);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void deleteStudentAccountAssetAllocation(String ids) {
|
|
|
try {
|
|
|
studentAccountAssetAllocationDao.deleteStudentAccountAssetAllocationByIds(ids);
|
|
|
} catch (Exception e) {
|
|
|
throw new PlatformException("批量删除资产账户管理失败", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public String addAll(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery) {
|
|
|
String msg = "";
|
|
|
List<StudentAccountAssetAllocation> studentAccountAssetAllocationList = new ArrayList<>();
|
|
|
try {
|
|
|
studentAccountAssetAllocationList = JSON.parseArray(studentAccountAssetAllocationQuery.getStudentAccountAssetAllocationJsonStr(), StudentAccountAssetAllocation.class);
|
|
|
} catch (Exception e) {
|
|
|
try {
|
|
|
studentAccountAssetAllocationList.add(JSONObject.parseObject(studentAccountAssetAllocationQuery.getStudentAccountAssetAllocationJsonStr(), StudentAccountAssetAllocation.class));
|
|
|
} catch (Exception e1) {
|
|
|
}
|
|
|
}
|
|
|
ToolUtils.deleteNullList(studentAccountAssetAllocationList);
|
|
|
if (null != studentAccountAssetAllocationList && studentAccountAssetAllocationList.size() > 0) {
|
|
|
for (int i = 0; i < studentAccountAssetAllocationList.size(); i++) {
|
|
|
StudentAccountAssetAllocation studentAccountAssetAllocation = studentAccountAssetAllocationList.get(i);
|
|
|
studentAccountAssetAllocation.setUserId(studentAccountAssetAllocationQuery.getUserId());
|
|
|
studentAccountAssetAllocation.setOrgId(studentAccountAssetAllocationQuery.getOrgId());
|
|
|
}
|
|
|
insertBatch(studentAccountAssetAllocationList);
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
public JsonResult add(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery) {
|
|
|
String msg = "";
|
|
|
StudentAccountAssetAllocation studentAccountAssetAllocation = studentAccountAssetAllocationQuery.pojo();
|
|
|
studentAccountAssetAllocationDao.insert(studentAccountAssetAllocation);
|
|
|
studentAccountAssetAllocationQuery.setId(studentAccountAssetAllocation.getId());
|
|
|
JsonResult jsonResult = new JsonResult();
|
|
|
jsonResult.setData(studentAccountAssetAllocation.getId());//自增的ID丢进去
|
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
|
jsonResult.setMsg(msg);
|
|
|
return jsonResult;
|
|
|
}
|
|
|
|
|
|
public String edit(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery) {
|
|
|
String msg = "";
|
|
|
StudentAccountAssetAllocation studentAccountAssetAllocation = studentAccountAssetAllocationQuery.pojo();
|
|
|
studentAccountAssetAllocationDao.updateTemplateById(studentAccountAssetAllocation);
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
public String updateGivenByIds(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery) {
|
|
|
String msg = "";
|
|
|
if (StringUtils.isNotBlank(studentAccountAssetAllocationQuery.get_given())) {
|
|
|
boolean flag = studentAccountAssetAllocationDao.updateGivenByIds(studentAccountAssetAllocationQuery) > 0;
|
|
|
if (!flag) {
|
|
|
msg = "更新指定参数失败";
|
|
|
}
|
|
|
} else {
|
|
|
msg = "指定参数为空";
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
public List<StudentAccountAssetAllocation> getValues(Object paras) {
|
|
|
return sqlManager.select(SqlId.of("jlw.studentAccountAssetAllocation.getStudentAccountAssetAllocationValues"), StudentAccountAssetAllocation.class, paras);
|
|
|
}
|
|
|
|
|
|
public List<StudentAccountAssetAllocation> getValuesByQuery(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery) {
|
|
|
return studentAccountAssetAllocationDao.getValuesByQuery(studentAccountAssetAllocationQuery);
|
|
|
}
|
|
|
|
|
|
public List<StudentAccountAssetAllocation> getValuesByQueryNotWithPermission(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery) {
|
|
|
return studentAccountAssetAllocationDao.getValuesByQueryNotWithPermission(studentAccountAssetAllocationQuery);
|
|
|
}
|
|
|
|
|
|
public StudentAccountAssetAllocation getInfo(Long id) {
|
|
|
StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery = new StudentAccountAssetAllocationQuery();
|
|
|
studentAccountAssetAllocationQuery.setId(id);
|
|
|
List<StudentAccountAssetAllocation> list = studentAccountAssetAllocationDao.getValuesByQuery(studentAccountAssetAllocationQuery);
|
|
|
if (null != list && list.size() > 0) {
|
|
|
return list.get(0);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public StudentAccountAssetAllocation getInfo(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery) {
|
|
|
List<StudentAccountAssetAllocation> list = studentAccountAssetAllocationDao.getValuesByQuery(studentAccountAssetAllocationQuery);
|
|
|
if (null != list && list.size() > 0) {
|
|
|
return list.get(0);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public StudentAccountAssetAllocation getByApplicationIdAndStudentId(Long applicationId, Long studentId) {
|
|
|
return studentAccountAssetAllocationDao.getByApplicationIdAndStudentId(applicationId, studentId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能描述: <br>
|
|
|
* 通过token、updateVersion来更新属性
|
|
|
*
|
|
|
* @param applicationToken
|
|
|
* @param param
|
|
|
* @Author: 87966
|
|
|
* @Date: 2023/3/6 16:31
|
|
|
*/
|
|
|
public void updateByApplicationToken(@NotBlank(message = "applicationToken 传递的token不能为空!") String applicationToken, StudentAccountAssetAllocationQuery param) {
|
|
|
|
|
|
// 获取资金账户信息
|
|
|
List<StudentAccountAssetAllocation> accountAssetAllocationList = getByApplicationToken(applicationToken, param);
|
|
|
|
|
|
Assert.isTrue(accountAssetAllocationList.size() == 1, "无法对多个账户进行修改操作!");
|
|
|
|
|
|
Assert.notNull(param.getUpdateVersion(), "更新操作,updateVersion 为必传项!");
|
|
|
|
|
|
// 主键拿过来
|
|
|
param.setId(accountAssetAllocationList.get(0).getId());
|
|
|
|
|
|
updateTemplate(param.pojo());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能描述: <br>
|
|
|
* 通过token获取资金账户
|
|
|
*
|
|
|
* @param applicationToken token
|
|
|
* @param param 一些参数
|
|
|
* @return {@link List< StudentAccountAssetAllocation>}
|
|
|
* @Author: 87966
|
|
|
* @Date: 2023/3/6 16:32
|
|
|
*/
|
|
|
public List<StudentAccountAssetAllocation> getByApplicationToken(
|
|
|
@NotBlank(message = "applicationToken 传递的token不能为空!") String applicationToken, StudentAccountAssetAllocationQuery param) {
|
|
|
|
|
|
LoginTodo loginTodo = validateAndGetLoginTodo(applicationToken);
|
|
|
|
|
|
// 学生ID
|
|
|
final String studentId = loginTodo.getStudentId();
|
|
|
|
|
|
Assert.notEmpty(studentId, "该接口只允许学生访问!");
|
|
|
|
|
|
// 应用ID
|
|
|
final String applicationId = loginTodo.getApplicationId();
|
|
|
// 院校ID
|
|
|
final String universitiesCollegesId = loginTodo.getSchoolId();
|
|
|
|
|
|
Assert.isTrue(StrUtil.isAllNotEmpty(studentId, applicationId, universitiesCollegesId), "学生ID、应用ID、院校ID,都不能为空!");
|
|
|
|
|
|
// 从token中获取必要条件
|
|
|
copyInfoByApplicationToken(loginTodo, param);
|
|
|
|
|
|
List<StudentAccountAssetAllocation> accountAssetAllocation = getValuesByQueryNotWithPermission(param);
|
|
|
|
|
|
Assert.notNull(accountAssetAllocation, "未查询到账户列表信息!");
|
|
|
|
|
|
return accountAssetAllocation;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证并返回登录信息
|
|
|
*
|
|
|
* @param applicationToken 回传的token
|
|
|
* @return
|
|
|
*/
|
|
|
public LoginTodo validateAndGetLoginTodo(String applicationToken) {
|
|
|
LoginTodo payload = loginTodoService.getPayloadByString(applicationToken);
|
|
|
|
|
|
Assert.notNull(payload, "回传的token,不是有效的加密串!");
|
|
|
|
|
|
ResourcesApplication resourcesApplication = resourcesApplicationService.queryById(payload.getApplicationId());
|
|
|
|
|
|
Assert.notNull(resourcesApplication, "未查询到应用的相关信息!");
|
|
|
boolean verify = JWTUtil.verify(applicationToken, resourcesApplication.getLinkSecretKey().getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
|
Assert.isTrue(verify, "token被修改过,更新失败!");
|
|
|
|
|
|
return payload;
|
|
|
}
|
|
|
private final static String PASSWORD = "sztzjy@2017";
|
|
|
|
|
|
/**
|
|
|
* 应用授权后开通资金账户权限
|
|
|
*
|
|
|
* @param orgId
|
|
|
*/
|
|
|
public void updateApplicationAuthority(Long orgId) {
|
|
|
|
|
|
List<UniversitiesCollegesJurisdictionExperimentalSystem> experimentalSystems = universitiesCollegesJurisdictionExperimentalSystemDao.getSQLManager()
|
|
|
.lambdaQuery(UniversitiesCollegesJurisdictionExperimentalSystem.class)
|
|
|
.andEq(UniversitiesCollegesJurisdictionExperimentalSystem::getOrgId, orgId).select();
|
|
|
|
|
|
StudentAccountAssetAllocationQuery allocationQuery = new StudentAccountAssetAllocationQuery();
|
|
|
allocationQuery.setOrgId(orgId);
|
|
|
List<StudentAccountAssetAllocation> valuesByQuery = studentAccountAssetAllocationDao.getValuesByQuery(allocationQuery);
|
|
|
|
|
|
//获取所以的资金账号
|
|
|
for (StudentAccountAssetAllocation accountAssetAllocation : valuesByQuery) {
|
|
|
int state = 1;
|
|
|
//获取添加院校权限,对账号进行限制
|
|
|
for (UniversitiesCollegesJurisdictionExperimentalSystem item : experimentalSystems) {
|
|
|
|
|
|
if (ObjectUtil.equals(accountAssetAllocation.getApplicationId(), item.getTypeId()) && ObjectUtil.isNotNull(item.getUseEndTime()) && DateUtil.endOfDay(item.getUseEndTime()).getTime() >= System.currentTimeMillis() && (ObjectUtil.equals(item.getUseType(), 1) || ObjectUtil.equals(item.getUseType(), 2))) {
|
|
|
//后期添加应用开发权限,新增的时候已经有应用添加了
|
|
|
state = 2;
|
|
|
} else if (ObjectUtil.isEmpty(accountAssetAllocation.getApplicationId())) {
|
|
|
//新增学生账号,应用还没有添加,后面才添加,授权权限的时候获取应用ID设置
|
|
|
ResourcesApplicationQuery resourcesApplicationQuery = new ResourcesApplicationQuery();
|
|
|
if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.P2P_ACCOUNT.getText())) {
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("P2P网络借贷公司");
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.CROWDFUNDING_ACCOUNT.getText())) {
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("众筹公司");
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.EQUITY_FUND_INVESTMENT_ACCOUNT.getText())) {
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("证券交易");
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.FUTURES_INVESTMENT_ACCOUNT.getText())) {
|
|
|
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("证券交易");
|
|
|
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.EQUITY_INVESTMENT_ACCOUNT.getText())) {
|
|
|
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("投资银行");
|
|
|
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.EQUITY_FUND_QUANTITATIVE_TRADING_ACCOUNT.getText())) {
|
|
|
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("智能交易");
|
|
|
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.FUTURES_QUANTITATIVE_TRADING_ACCOUNT.getText())) {
|
|
|
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("智能交易");
|
|
|
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.BLOCKCHAIN_ASSET_ACCOUNT.getText())) {
|
|
|
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("数字资产");
|
|
|
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.MARGIN_ACCOUNT.getText())) {
|
|
|
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("融资融券");
|
|
|
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.INSURANCE_ACCOUNT.getText())) {
|
|
|
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("保险公司");
|
|
|
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.SUPPLY_CHAIN_ASSET_ACCOUNT.getText())) {
|
|
|
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("供应链金融服务公司");
|
|
|
|
|
|
} else if (ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.FINANCIAL_ACCOUNT.getText())) {
|
|
|
resourcesApplicationQuery.setApplicationSecondLevelRelation("智能理财");
|
|
|
}
|
|
|
|
|
|
if (ObjectUtil.isNotNull(resourcesApplicationQuery.getApplicationSecondLevelRelation())) {
|
|
|
List<ResourcesApplication> resourcesApplicationList = resourcesApplicationDao.getValuesByQuery(resourcesApplicationQuery);
|
|
|
if (CollectionUtil.isNotEmpty(resourcesApplicationList)) {
|
|
|
if (ObjectUtil.equals(item.getTypeId(), resourcesApplicationList.get(0).getResourcesApplicationId())) {
|
|
|
accountAssetAllocation.setApplicationId(item.getTypeId());
|
|
|
state = 2;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
accountAssetAllocation.setState(state);
|
|
|
|
|
|
if (ObjectUtil.equals(state, 2)) {
|
|
|
|
|
|
if(accountAssetAllocation!=null){
|
|
|
accountAssetAllocation.setInitialCapital(accountAssetAllocation.getInitialCapital()==null?new BigDecimal(0):accountAssetAllocation.getInitialCapital());
|
|
|
accountAssetAllocation.setAvailableFunds(accountAssetAllocation.getAvailableFunds()==null?new BigDecimal(0):accountAssetAllocation.getAvailableFunds());
|
|
|
accountAssetAllocation.setInitialInvestmentCapital(accountAssetAllocation.getInitialInvestmentCapital()==null?new BigDecimal(0):accountAssetAllocation.getInitialInvestmentCapital());
|
|
|
accountAssetAllocation.setInitialCapital(Objects.equals(accountAssetAllocation.getInitialCapital().compareTo(BigDecimal.ZERO), 0) ? new BigDecimal(1000000) : accountAssetAllocation.getInitialCapital());
|
|
|
accountAssetAllocation.setAvailableFunds(Objects.equals(accountAssetAllocation.getAvailableFunds().compareTo(BigDecimal.ZERO), 0) ? new BigDecimal(1000000) : accountAssetAllocation.getAvailableFunds());
|
|
|
accountAssetAllocation.setInitialInvestmentCapital(Objects.equals(accountAssetAllocation.getInitialInvestmentCapital().compareTo(BigDecimal.ZERO), 0) ? new BigDecimal(1000000) : accountAssetAllocation.getInitialInvestmentCapital());
|
|
|
accountAssetAllocation.setUpdateTime(new Date());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (!ObjectUtil.equals(accountAssetAllocation.getApplicationId(), -1L) &&
|
|
|
!ObjectUtil.equals(accountAssetAllocation.getApplicationId(), -2L) &&
|
|
|
!ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.OPTIONS_INVESTMENT_ACCOUNT.getText()) &&
|
|
|
!ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.FOREX_INVESTMENT_ACCOUNT.getText()) &&
|
|
|
!ObjectUtil.equals(accountAssetAllocation.getName().getText(), AccountTypeEnum.TRUST_ACCOUNT.getText())) {
|
|
|
studentAccountAssetAllocationDao.updateById(accountAssetAllocation);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 激活该校的所有学生用户的股票/期货账户
|
|
|
*
|
|
|
* @param orgId
|
|
|
*/
|
|
|
public void allOpenAccount(Long orgId) {
|
|
|
|
|
|
StudentAccountAssetAllocationQuery allocationQuery = new StudentAccountAssetAllocationQuery();
|
|
|
allocationQuery.setOrgId(orgId);
|
|
|
allocationQuery.setState(1);
|
|
|
List<StudentAccountAssetAllocation> valuesByQuery = studentAccountAssetAllocationDao.getValuesByQuery(allocationQuery);
|
|
|
|
|
|
for (StudentAccountAssetAllocation accountAssetAllocation : valuesByQuery) {
|
|
|
accountAssetAllocation.setState(2);
|
|
|
accountAssetAllocation.setInitialCapital(Objects.equals(accountAssetAllocation.getInitialCapital().compareTo(BigDecimal.ZERO), 0) ? new BigDecimal(1000000) : accountAssetAllocation.getInitialCapital());
|
|
|
accountAssetAllocation.setAvailableFunds(Objects.equals(accountAssetAllocation.getAvailableFunds().compareTo(BigDecimal.ZERO), 0) ? new BigDecimal(1000000) : accountAssetAllocation.getAvailableFunds());
|
|
|
accountAssetAllocation.setInitialInvestmentCapital(Objects.equals(accountAssetAllocation.getInitialInvestmentCapital().compareTo(BigDecimal.ZERO), 0) ? new BigDecimal(1000000) : accountAssetAllocation.getInitialInvestmentCapital());
|
|
|
accountAssetAllocation.setUpdateTime(new Date());
|
|
|
studentAccountAssetAllocationDao.updateById(accountAssetAllocation);
|
|
|
}
|
|
|
}
|
|
|
@Autowired
|
|
|
private CoreUserService coreUserService;
|
|
|
|
|
|
// 打开数据库连接
|
|
|
public static Connection openConn() throws SQLException {
|
|
|
try {
|
|
|
Connection connection = DriverManager.getConnection(URL, USER, PASSWORD);
|
|
|
if (connection != null) {
|
|
|
System.out.println("成功建立数据库连接");
|
|
|
return connection;
|
|
|
} else {
|
|
|
throw new SQLException("无法建立数据库连接");
|
|
|
}
|
|
|
} catch (SQLException e) {
|
|
|
throw new SQLException("无法建立数据库连接: " + e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 关闭数据库连接
|
|
|
public static void closeConn(Connection connection) {
|
|
|
if (connection != null) {
|
|
|
try {
|
|
|
connection.close();
|
|
|
System.out.println("数据库连接已关闭");
|
|
|
} catch (SQLException e) {
|
|
|
System.err.println("无法关闭数据库连接: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public PageQuery<StudentAccountAssetAllocation> queryByConditionQuery(PageQuery query) {
|
|
|
|
|
|
|
|
|
PageQuery ret = studentAccountAssetAllocationDao.queryByConditionQuery(query);
|
|
|
queryListAfter(ret.getList());
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用户在创建的时候,紧跟着就要创建资金账户
|
|
|
*/
|
|
|
public void createFundAccountWithUserCreated(Long studentId, Long oldUserId, Long orgId) throws SQLException {
|
|
|
//开设7个账户,现金账户100万,银行账户0元,其他应用的账户开设,但是未被激活,没有初始资金
|
|
|
AccountTypeEnum[] values = AccountTypeEnum.values();
|
|
|
UniversitiesColleges universitiesColleges = universitiesCollegesDao.getByOrgId(orgId);
|
|
|
boolean lock = false;
|
|
|
//1: 个人,2: 机构
|
|
|
for (int j = 1; j < 3; j++) {
|
|
|
|
|
|
for (int i = 0; i < values.length; i++) {
|
|
|
if (values[i].getText().equals("现金账户")) continue;
|
|
|
StudentAccountAssetAllocation allocation = new StudentAccountAssetAllocation();
|
|
|
allocation.setStudentId(studentId);
|
|
|
//先默认不开通,条件符合就开通
|
|
|
allocation.setState(1);
|
|
|
ResourcesApplicationQuery query = new ResourcesApplicationQuery();
|
|
|
|
|
|
if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.P2P_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("P2P网络借贷公司");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.CROWDFUNDING_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("众筹公司");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.EQUITY_FUND_INVESTMENT_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("证券交易");
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.FUTURES_INVESTMENT_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("证券交易");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.EQUITY_INVESTMENT_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("投资银行");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.EQUITY_FUND_QUANTITATIVE_TRADING_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("智能交易");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.FUTURES_QUANTITATIVE_TRADING_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("智能交易");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.BLOCKCHAIN_ASSET_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("数字资产");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.MARGIN_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("融资融券");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.INSURANCE_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("保险公司");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.SUPPLY_CHAIN_ASSET_ACCOUNT.getText())) {
|
|
|
|
|
|
query.setApplicationSecondLevelRelation("供应链金融服务公司");
|
|
|
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.FINANCIAL_ACCOUNT.getText())) {
|
|
|
query.setApplicationSecondLevelRelation("智能理财");
|
|
|
} else if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.FOREX_INVESTMENT_ACCOUNT.getText())) {
|
|
|
query.setApplicationSecondLevelRelation("外汇");
|
|
|
}
|
|
|
if (ObjectUtil.equals(values[i].getText(), AccountTypeEnum.BANK_ACCOUNT.getText())) {
|
|
|
allocation.setState(2);
|
|
|
allocation.setApplicationId(ObjectUtil.equals(values[i].getText(), AccountTypeEnum.BANK_ACCOUNT.getText()) ? -2L : -1L);
|
|
|
|
|
|
allocation.setInitialCapital(ObjectUtil.equals(values[i].getText(), AccountTypeEnum.BANK_ACCOUNT.getText()) ?
|
|
|
new BigDecimal(2000000) : BigDecimal.ZERO);
|
|
|
allocation.setAvailableFunds(ObjectUtil.equals(values[i].getText(), AccountTypeEnum.BANK_ACCOUNT.getText()) ?
|
|
|
new BigDecimal(2000000) : BigDecimal.ZERO);
|
|
|
allocation.setInitialInvestmentCapital(ObjectUtil.equals(values[i].getText(), AccountTypeEnum.BANK_ACCOUNT.getText()) ?
|
|
|
new BigDecimal(2000000) : BigDecimal.ZERO);
|
|
|
} else {
|
|
|
if (ObjectUtil.isNotNull(query.getApplicationSecondLevelRelation())) {
|
|
|
List<ResourcesApplication> applications = resourcesApplicationDao.getValuesByQuery(query);
|
|
|
if (CollectionUtil.isNotEmpty(applications)) {
|
|
|
if (lock && applications.get(0).getResourcesApplicationId() == 16) {
|
|
|
allocation.setApplicationId(-16L);
|
|
|
} else {
|
|
|
allocation.setApplicationId(applications.get(0).getResourcesApplicationId());
|
|
|
}
|
|
|
List<UniversitiesCollegesJurisdictionExperimentalSystem> experimentalSystems = universitiesCollegesJurisdictionExperimentalSystemDao.getNotExpireApply(orgId, applications.get(0).getResourcesApplicationId().toString());
|
|
|
allocation.setState(CollectionUtil.isNotEmpty(experimentalSystems) ? 2 : 1);
|
|
|
Double money = 0D;
|
|
|
if (values[i].getText().equals(AccountTypeEnum.P2P_ACCOUNT.getText())) {
|
|
|
money = 2000000D;
|
|
|
} else if (values[i].getText().equals(AccountTypeEnum.CROWDFUNDING_ACCOUNT.getText())) {
|
|
|
money = 2000000D;
|
|
|
|
|
|
} else if (values[i].getText().equals(AccountTypeEnum.EQUITY_FUND_INVESTMENT_ACCOUNT.getText())) {
|
|
|
money = 2000000D;
|
|
|
} else if (values[i].getText().equals(AccountTypeEnum.FUTURES_INVESTMENT_ACCOUNT.getText())) {
|
|
|
money = 2000000D;
|
|
|
} else if (values[i].getText().equals(AccountTypeEnum.EQUITY_INVESTMENT_ACCOUNT.getText())) {
|
|
|
if (j == 1) {
|
|
|
money = 2000000D;
|
|
|
} else {
|
|
|
money = 10000000D;
|
|
|
}
|
|
|
} else if (values[i].getText().equals(AccountTypeEnum.FOREX_INVESTMENT_ACCOUNT.getText())) {
|
|
|
money = 2000000D;
|
|
|
} else if (values[i].getText().equals(AccountTypeEnum.SUPPLY_CHAIN_ASSET_ACCOUNT.getText())) {
|
|
|
money = 2000000D;
|
|
|
} else if (values[i].getText().equals(AccountTypeEnum.BLOCKCHAIN_ASSET_ACCOUNT.getText())) {
|
|
|
money = 2000000D;
|
|
|
} else if (values[i].getText().equals(AccountTypeEnum.FINANCIAL_ACCOUNT.getText())) {
|
|
|
money = 2000000D;
|
|
|
} else if (values[i].getText().equals(AccountTypeEnum.INSURANCE_ACCOUNT.getText())) {
|
|
|
money = 2000000D;
|
|
|
}
|
|
|
allocation.setInitialCapital(CollectionUtil.isNotEmpty(experimentalSystems) ?
|
|
|
new BigDecimal(money) : BigDecimal.ZERO);
|
|
|
allocation.setAvailableFunds(CollectionUtil.isNotEmpty(experimentalSystems) ?
|
|
|
new BigDecimal(money) : BigDecimal.ZERO);
|
|
|
allocation.setInitialInvestmentCapital(CollectionUtil.isNotEmpty(experimentalSystems) ?
|
|
|
new BigDecimal(money) : BigDecimal.ZERO);
|
|
|
allocation.setTotalAssetsOfSubAccounts(CollectionUtil.isNotEmpty(experimentalSystems) ?
|
|
|
new BigDecimal(money) : BigDecimal.ZERO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
allocation.setUniversitiesCollegesId(universitiesColleges.getUniversitiesCollegesId());
|
|
|
allocation.setName(values[i]);
|
|
|
allocation.setUpdateTime(new Date());
|
|
|
allocation.setCreateTime(new Date());
|
|
|
allocation.setIsDel(1);
|
|
|
allocation.setOrgId(orgId);
|
|
|
allocation.setUpdateVersion(-1L);
|
|
|
allocation.setIsInstitution(j);
|
|
|
studentAccountAssetAllocationDao.insert(allocation);
|
|
|
if (allocation != null && allocation.getApplicationId() != null) {
|
|
|
|
|
|
if (allocation.getApplicationId() == 4 && j == 1) {
|
|
|
StudentAccountP2pSystem p2pSystem = new StudentAccountP2pSystem();
|
|
|
p2pSystem.setStudentId(studentId);
|
|
|
p2pSystem.setApplicationId(4L);
|
|
|
p2pSystem.setUniversitiesCollegesId(universitiesColleges.getUniversitiesCollegesId());
|
|
|
p2pSystem.setState(Long.valueOf(allocation.getState()));
|
|
|
p2pSystem.setInitialInvestmentCapital(new BigDecimal(2000000));
|
|
|
p2pSystem.setAvailableBalance(new BigDecimal(2000000));
|
|
|
p2pSystem.setInitialCapital(new BigDecimal(2000000));
|
|
|
p2pSystem.setTotalAssets(new BigDecimal(2000000));
|
|
|
p2pSystem.setIsDel(1L);
|
|
|
p2pSystem.setIsInstitution(1L);
|
|
|
p2pSystem.setUserId(allocation.getUserId());
|
|
|
studentAccountP2pSystemService.add(p2pSystem);
|
|
|
createBaseAccount(p2pSystem.getApplicationId(), oldUserId, 2000000D);
|
|
|
} else if (allocation.getApplicationId() == 5 && j == 1) {
|
|
|
|
|
|
StudentAccountCrowdfundingSystem crowdfundingSystem = new StudentAccountCrowdfundingSystem();
|
|
|
crowdfundingSystem.setStudentId(studentId);
|
|
|
crowdfundingSystem.setApplicationId(5L);
|
|
|
crowdfundingSystem.setUniversitiesCollegesId(universitiesColleges.getUniversitiesCollegesId());
|
|
|
crowdfundingSystem.setState(Long.valueOf(allocation.getState()));
|
|
|
crowdfundingSystem.setInitialInvestmentCapital(new BigDecimal(2000000));
|
|
|
crowdfundingSystem.setAvailableBalance(new BigDecimal(2000000));
|
|
|
crowdfundingSystem.setInitialCapital(new BigDecimal(2000000));
|
|
|
crowdfundingSystem.setTotalAssets(new BigDecimal(2000000));
|
|
|
crowdfundingSystem.setIsDel(1L);
|
|
|
crowdfundingSystem.setIsInstitution(1L);
|
|
|
crowdfundingSystem.setUserId(allocation.getUserId());
|
|
|
studentAccountCrowdfundingSystemService.add(crowdfundingSystem);
|
|
|
createBaseAccount(crowdfundingSystem.getApplicationId(), oldUserId, 2000000D);
|
|
|
} else if (allocation.getApplicationId() == 16 && j == 1 && !lock) {
|
|
|
lock = true;
|
|
|
StudentAccountMockTradingSystem mockTradingSystem = new StudentAccountMockTradingSystem();
|
|
|
mockTradingSystem.setStudentId(studentId);
|
|
|
mockTradingSystem.setApplicationId(16L);
|
|
|
mockTradingSystem.setUniversitiesCollegesId(universitiesColleges.getUniversitiesCollegesId());
|
|
|
mockTradingSystem.setState(Long.valueOf(allocation.getState()));
|
|
|
mockTradingSystem.setInitialInvestmentCapital(new BigDecimal(2000000));
|
|
|
mockTradingSystem.setAvailableCapital(new BigDecimal(2000000));
|
|
|
mockTradingSystem.setInitialCapital(new BigDecimal(2000000));
|
|
|
mockTradingSystem.setTotalAssets(new BigDecimal(2000000));
|
|
|
mockTradingSystem.setIsDel(1L);
|
|
|
mockTradingSystem.setIsInstitution(1L);
|
|
|
mockTradingSystem.setUserId(allocation.getUserId());
|
|
|
studentAccountMockTradingSystemService.add(mockTradingSystem);
|
|
|
createBaseAccount(mockTradingSystem.getApplicationId(), oldUserId, 2000000D);
|
|
|
StudentAccountMockTradingSystem mockTradingSystem1 = new StudentAccountMockTradingSystem();
|
|
|
mockTradingSystem1.setStudentId(studentId);
|
|
|
mockTradingSystem1.setApplicationId(-16L);
|
|
|
mockTradingSystem1.setUniversitiesCollegesId(universitiesColleges.getUniversitiesCollegesId());
|
|
|
mockTradingSystem1.setState(Long.valueOf(allocation.getState()));
|
|
|
mockTradingSystem1.setInitialInvestmentCapital(new BigDecimal(2000000));
|
|
|
mockTradingSystem1.setAvailableCapital(new BigDecimal(2000000));
|
|
|
mockTradingSystem1.setInitialCapital(new BigDecimal(2000000));
|
|
|
mockTradingSystem1.setTotalAssets(new BigDecimal(2000000));
|
|
|
mockTradingSystem1.setIsDel(1L);
|
|
|
mockTradingSystem1.setIsInstitution(1L);
|
|
|
mockTradingSystem1.setUserId(allocation.getUserId());
|
|
|
studentAccountMockTradingSystemService.add(mockTradingSystem1);
|
|
|
createBaseAccount(mockTradingSystem1.getApplicationId(), oldUserId, 2000000D);
|
|
|
} else if (allocation.getApplicationId() == 18 && j == 1) {
|
|
|
StudentAccountEquityInvestmentSystem investmentSystem = new StudentAccountEquityInvestmentSystem();
|
|
|
investmentSystem.setStudentId(studentId);
|
|
|
investmentSystem.setApplicationId(18L);
|
|
|
investmentSystem.setUniversitiesCollegesId(universitiesColleges.getUniversitiesCollegesId());
|
|
|
investmentSystem.setState(Long.valueOf(allocation.getState()));
|
|
|
investmentSystem.setInitialInvestmentCapital(new BigDecimal(2000000));
|
|
|
investmentSystem.setOwnFunds(new BigDecimal(2000000));
|
|
|
investmentSystem.setInitialCapital(new BigDecimal(2000000));
|
|
|
investmentSystem.setIsDel(1L);
|
|
|
investmentSystem.setIsInstitution(1L);
|
|
|
investmentSystem.setUserId(allocation.getUserId());
|
|
|
studentAccountEquityInvestmentSystemService.add(investmentSystem);
|
|
|
createBaseAccount(investmentSystem.getApplicationId(), oldUserId, 2000000D);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//在2.0创建基础资金账户
|
|
|
public void createBaseAccount(Long applicationId, Long oldUserId, Double initialCapital) throws SQLException {
|
|
|
String sql = "";
|
|
|
Date currentDate = new Date();
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
String formattedDate = dateFormat.format(currentDate);
|
|
|
if (applicationId == 4L) {
|
|
|
sql = "INSERT INTO [dbo].[ExaP2PAssetAllocation]( [ApplicationId], [InitialCapital], [InitialInvestmentCapital], " +
|
|
|
"[The_Total_AssetsOf], [AvailableFunds], [InvestmentFunds], " +
|
|
|
"[Borrowed_Funds], [Freeze_Funds], [Cumulative_of_return], [TotalAssets_Rate_Return], " +
|
|
|
"[Return_on_equity], [TotalDailyInvestment], [TotalWeeklyInvestment], " +
|
|
|
"[TotalMonthlyInvestment], [UserId], [IsDeleted], [DeleterUserId], " +
|
|
|
"[DeletionTime], [LastModificationTime], [LastModifierUserId], [CreationTime], " +
|
|
|
"[CreatorUserId]) VALUES (" + applicationId + ", " + initialCapital + ", " + initialCapital + ", " + initialCapital + ", " + initialCapital + ", 0, 0, 0, 0, 0, " +
|
|
|
"0, 0, 0, 0, " + oldUserId + ", " +
|
|
|
"'0', NULL, NULL, NULL, NULL, '" + formattedDate + "', " + oldUserId + ")";
|
|
|
String sql1 = "INSERT INTO [dbo].[P2PAccount]([UserId], [Balance], [IsDeleted], [DeleterUserId], " +
|
|
|
"[DeletionTime], [LastModificationTime], [LastModifierUserId], [CreationTime], " +
|
|
|
"[CreatorUserId], [TotalInvestmentIncome]) VALUES ("+oldUserId+", "+initialCapital+", '0', NULL, NULL, " +
|
|
|
"'"+formattedDate+"', NULL, '"+formattedDate+"', "+oldUserId+", 0)";
|
|
|
runJdbc(sql1);
|
|
|
} else if (applicationId == 5L) {
|
|
|
sql = "INSERT INTO [dbo].[ExaTheRaiseAssetAllocation]([ApplicationId], [InitialCapital], [InitialInvestmentCapital], " +
|
|
|
"[The_Total_AssetsOf], [AvailableFunds], [InvestmentFunds], " +
|
|
|
"[TheTotalAmountOfTheRaise], [TheTotalAmountOfFrozen], [Cumulative_of_return], [ReturnOnInvestmentOwnCapital], " +
|
|
|
"[ReturnOnCrowdfundingInvestment], [UserId], [IsDeleted], [DeleterUserId], [DeletionTime], " +
|
|
|
"[LastModificationTime], [LastModifierUserId], [CreationTime], " +
|
|
|
"[CreatorUserId]) VALUES (" + applicationId + ", " + initialCapital + ", " + initialCapital + ", " + initialCapital + ", " + initialCapital + ", 0, 0, 0, 0, 0, 0, " +
|
|
|
"" + oldUserId + ", '0', " +
|
|
|
"NULL, NULL, NULL, NULL, '" + formattedDate + "', " + oldUserId + ")";
|
|
|
String sql1 = "INSERT INTO [dbo].[CFAccount]([UserId], [TotalInvestmentIncome], [Balance], " +
|
|
|
"[IsDeleted], [DeleterUserId], [DeletionTime], [LastModificationTime], [LastModifierUserId], " +
|
|
|
"[CreationTime], [CreatorUserId]) VALUES ( "+oldUserId+", .00, "+initialCapital+", '0', NULL, NULL, '"+formattedDate+"', " +
|
|
|
"NULL, '"+formattedDate+"', NULL)";
|
|
|
runJdbc(sql1);
|
|
|
} else if (applicationId == 16L || applicationId == -16L) {
|
|
|
Integer secType;
|
|
|
secType = applicationId == 16L ? 1 : 4;
|
|
|
sql = "INSERT INTO [dbo].[ExaMNJYAssetAllocation]( [ApplicationId], [InitialCapital], " +
|
|
|
"[InitialInvestmentCapital], [TotalAssets], [AvailableFunds], [Market_value], [Accumulative_total_profit_and_loss], " +
|
|
|
"[Cumulative_rate_of_return], [Annualized_rate_of_return], [Kumar_ratio], [Sharpe_ratio], " +
|
|
|
"[The_biggest_back_test], [Asset_Investment_Rate], [Return_on_equity], [UserId], " +
|
|
|
"[SecType], [IsDeleted], [DeleterUserId], [DeletionTime], [LastModificationTime], " +
|
|
|
"[LastModifierUserId], [CreationTime], [CreatorUserId]) VALUES (" + applicationId + ", " + initialCapital + ", " + initialCapital + ", " + initialCapital + ", " + initialCapital + ", 0, 0, 0, 0, 0, 0, " +
|
|
|
"0, 0, 0, " + oldUserId + ", " + secType + ", '0', NULL, NULL, '" + formattedDate + "', NULL, '" + formattedDate + "', " + oldUserId + ")";
|
|
|
} else if (applicationId == 18L) {
|
|
|
sql = "INSERT INTO [dbo].[ExaPEVCAssetAllocation]([ApplicationId], [InitialInvestmentCapital], " +
|
|
|
"[InitialCapital], [TotalAssets], [InvestmentFunds], [LPAmount], [LPInvestmentAmount], " +
|
|
|
"[GPInvestmentAmount], [LhAmount], [FreeMoney], [Bank_loan], [BankInvestmentFunds], " +
|
|
|
"[FreeInvestment_funds], [Return_On_investment], [Return_on_net_asset_investment], " +
|
|
|
"[Return_on_total_assets], [UserId], [IsDeleted], [DeleterUserId], [DeletionTime], " +
|
|
|
"[LastModificationTime], [LastModifierUserId], [CreationTime], [CreatorUserId]) " +
|
|
|
"VALUES (" + applicationId + ", " + initialCapital + ", " + initialCapital + ", "
|
|
|
+ initialCapital + ", 0, 0, 0, 0, 0, " + initialCapital + ", 0, 0, 0, 0, 0, 0, " + oldUserId + ", " +
|
|
|
"'0', NULL, NULL, NULL, NULL, '" + formattedDate + "', " + oldUserId + ")";
|
|
|
sendPostRequest("http://120.79.161.177:8029/Account/InsertPevcFunding", "UserId=" + oldUserId);
|
|
|
}
|
|
|
runJdbc(sql);
|
|
|
}
|
|
|
|
|
|
//运行jdbc
|
|
|
public void runJdbc(String sql) throws SQLException {
|
|
|
Connection conn = openConn();
|
|
|
PreparedStatement ps = conn.prepareStatement(sql);
|
|
|
ps.executeUpdate();
|
|
|
closeConn(conn);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 转账
|
|
|
*
|
|
|
* @param toAccountsApplicationId
|
|
|
* @param outAccountsApplicationId
|
|
|
* @param money
|
|
|
* @param studentId
|
|
|
* @param coreUser
|
|
|
* @return
|
|
|
*/
|
|
|
public JsonResult<String> transferAccounts(Long toAccountsApplicationId, Long outAccountsApplicationId, BigDecimal money, Long studentId, CoreUser coreUser) {
|
|
|
|
|
|
if (ObjectUtil.isEmpty(money)) {
|
|
|
return JsonResult.failMessage("转账金额为空");
|
|
|
}
|
|
|
|
|
|
BigDecimal transfer = money.setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
//转出账户
|
|
|
StudentAccountAssetAllocationQuery outAccounts = new StudentAccountAssetAllocationQuery();
|
|
|
outAccounts.setState(2);
|
|
|
outAccounts.setApplicationId(outAccountsApplicationId);
|
|
|
outAccounts.setStudentId(studentId);
|
|
|
List<StudentAccountAssetAllocation> outAccountsList = studentAccountAssetAllocationDao.getValuesByQuery(outAccounts);
|
|
|
if (CollectionUtil.isEmpty(outAccountsList)) {
|
|
|
return JsonResult.failMessage("转出账号未开通");
|
|
|
}
|
|
|
StudentAccountAssetAllocation outAccountAssetAllocation = outAccountsList.get(0);
|
|
|
|
|
|
BigDecimal availableFunds = outAccountAssetAllocation.getAvailableFunds();
|
|
|
|
|
|
//转入账户
|
|
|
StudentAccountAssetAllocationQuery toAccounts = new StudentAccountAssetAllocationQuery();
|
|
|
toAccounts.setState(2);
|
|
|
toAccounts.setApplicationId(toAccountsApplicationId);
|
|
|
toAccounts.setStudentId(studentId);
|
|
|
List<StudentAccountAssetAllocation> toAccountsList = studentAccountAssetAllocationDao.getValuesByQuery(toAccounts);
|
|
|
|
|
|
if (CollectionUtil.isEmpty(toAccountsList)) {
|
|
|
return JsonResult.failMessage("转入账号未开通");
|
|
|
}
|
|
|
|
|
|
StudentAccountAssetAllocation toAccountAssetAllocation = toAccountsList.get(0);
|
|
|
|
|
|
if (ObjectUtil.equals(outAccountAssetAllocation.getName(), toAccountAssetAllocation.getName())) {
|
|
|
return JsonResult.failMessage("不能转入相同账户");
|
|
|
}
|
|
|
|
|
|
if (!ObjectUtil.equals(outAccountAssetAllocation.getName(), AccountTypeEnum.BANK_ACCOUNT) && !ObjectUtil.equals(toAccountAssetAllocation.getName(), AccountTypeEnum.BANK_ACCOUNT)) {
|
|
|
return JsonResult.failMessage("只能转入银行账号");
|
|
|
}
|
|
|
|
|
|
if (Objects.equals(availableFunds.compareTo(BigDecimal.ZERO), 0)) {
|
|
|
return JsonResult.failMessage("可用资金不足");
|
|
|
}
|
|
|
|
|
|
if (availableFunds.compareTo(transfer) < 0) {
|
|
|
return JsonResult.failMessage("超出可用资金总额");
|
|
|
}
|
|
|
|
|
|
outAccountAssetAllocation.setAvailableFunds(availableFunds.subtract(transfer));
|
|
|
outAccountAssetAllocation.setInitialInvestmentCapital(outAccountAssetAllocation.getApplicationId() == -1 ? availableFunds : availableFunds.subtract(transfer));
|
|
|
if (outAccountAssetAllocation.getTransferOutAmount() == null) {
|
|
|
outAccountAssetAllocation.setTransferOutAmount(BigDecimal.ZERO);
|
|
|
}
|
|
|
outAccountAssetAllocation.setTransferOutAmount(outAccountAssetAllocation.getTransferOutAmount().add(transfer));
|
|
|
studentAccountAssetAllocationDao.updateById(outAccountAssetAllocation);
|
|
|
|
|
|
if (toAccountAssetAllocation.getTransferOutAmount() == null) {
|
|
|
toAccountAssetAllocation.setTransferOutAmount(BigDecimal.ZERO);
|
|
|
}
|
|
|
if (toAccountAssetAllocation.getTransferinAmount() == null) {
|
|
|
toAccountAssetAllocation.setTransferinAmount(BigDecimal.ZERO);
|
|
|
}
|
|
|
toAccountAssetAllocation.setInitialInvestmentCapital(toAccountAssetAllocation.getInitialInvestmentCapital().add(transfer));
|
|
|
toAccountAssetAllocation.setAvailableFunds(toAccountAssetAllocation.getAvailableFunds().add(transfer));
|
|
|
toAccountAssetAllocation.setTransferinAmount(toAccountAssetAllocation.getTransferinAmount().add(transfer));
|
|
|
studentAccountAssetAllocationDao.updateById(toAccountAssetAllocation);
|
|
|
|
|
|
StudentAccountTradingRecordSheet tradingRecordSheet = new StudentAccountTradingRecordSheet();
|
|
|
tradingRecordSheet.setTransactionAmount(transfer);
|
|
|
tradingRecordSheet.setTransferType(toAccountAssetAllocation.getName().toString());
|
|
|
tradingRecordSheet.setExitType(outAccountAssetAllocation.getName().name());
|
|
|
tradingRecordSheet.setCreateTime(new Date());
|
|
|
tradingRecordSheet.setStudentId(studentId);
|
|
|
tradingRecordSheet.setOrgId(coreUser.getOrgId());
|
|
|
studentAccountTradingRecordSheetDao.insert(tradingRecordSheet);
|
|
|
|
|
|
|
|
|
if (outAccountAssetAllocation.getApplicationId() == 18 || toAccountAssetAllocation.getApplicationId() == 18) {
|
|
|
String url = "http://120.79.161.177:8029/Account/UpdatePevcAvailable";
|
|
|
String postData;
|
|
|
if (outAccountAssetAllocation.getApplicationId() == 18) {
|
|
|
postData = "UserId=" + coreUser.getId() + "&&Money=" + money + "&&CZId=" + 1;
|
|
|
} else {
|
|
|
postData = "UserId=" + coreUser.getId() + "&&Money=" + money + "&&CZId=" + 2;
|
|
|
}
|
|
|
String result = sendPostRequest(url, postData);
|
|
|
StudentAccountAssetAllocationQuery updateQuery = new StudentAccountAssetAllocationQuery();
|
|
|
updateQuery.setApplicationId(Long.valueOf(18));
|
|
|
updateQuery.setStudentId(studentId);
|
|
|
List<StudentAccountAssetAllocation> updateAccount = studentAccountAssetAllocationDao.getValuesByQuery(updateQuery);
|
|
|
StudentAccountAssetAllocation allocation = updateAccount.get(0);
|
|
|
studentAccountEquityInvestmentSystemService.updateByTransfer(allocation.getAvailableFunds(), allocation.getInitialCapital(), allocation.getInitialInvestmentCapital(),
|
|
|
allocation.getInitialInvestmentCapital(), allocation.getInitialInvestmentCapital(), studentId);
|
|
|
String sql = "update ExaPEVCAssetAllocation set FreeMoney =" + allocation.getAvailableFunds()
|
|
|
+ " where UserId = " + coreUser.getOldId() + "";
|
|
|
try{
|
|
|
runJdbc(sql);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (outAccountAssetAllocation.getApplicationId() == 4 || toAccountAssetAllocation.getApplicationId() == 4) {
|
|
|
updateStudentAccountByApplicationId(studentId, coreUser.getOldId(), 4);
|
|
|
}
|
|
|
|
|
|
if (outAccountAssetAllocation.getApplicationId() == 5 || toAccountAssetAllocation.getApplicationId() == 5) {
|
|
|
updateStudentAccountByApplicationId(studentId, coreUser.getOldId(), 5);
|
|
|
}
|
|
|
|
|
|
if (outAccountAssetAllocation.getApplicationId() == 16 || toAccountAssetAllocation.getApplicationId() == 16) {
|
|
|
updateStudentAccountByApplicationId(studentId, coreUser.getOldId(), 16);
|
|
|
}
|
|
|
if (outAccountAssetAllocation.getApplicationId() == -16 || toAccountAssetAllocation.getApplicationId() == -16) {
|
|
|
updateStudentAccountByApplicationId(studentId, coreUser.getOldId(), -16);
|
|
|
}
|
|
|
|
|
|
return JsonResult.success();
|
|
|
}
|
|
|
|
|
|
|
|
|
// 创建一个方法来执行更新子系统资产表操作
|
|
|
public void updateStudentAccountByApplicationId(long studentId, Long oldUserId, int applicationId) {
|
|
|
StudentAccountAssetAllocationQuery updateQuery = new StudentAccountAssetAllocationQuery();
|
|
|
updateQuery.setApplicationId((long) applicationId);
|
|
|
updateQuery.setStudentId(studentId);
|
|
|
List<StudentAccountAssetAllocation> updateAccount = studentAccountAssetAllocationDao.getValuesByQuery(updateQuery);
|
|
|
if (!updateAccount.isEmpty()) {
|
|
|
StudentAccountAssetAllocation allocation = updateAccount.get(0);
|
|
|
switch (applicationId) {
|
|
|
case 4:
|
|
|
studentAccountP2pSystemService.updateByTransfer(allocation.getAvailableFunds(), allocation.getInitialCapital(), allocation.getInitialInvestmentCapital(), studentId);
|
|
|
String sql = "update ExaP2PAssetAllocation set AvailableFunds =" + allocation.getAvailableFunds() + " ," +
|
|
|
"InitialCapital = " + allocation.getInitialCapital() + " , InitialInvestmentCapital =" + allocation.getInitialInvestmentCapital() + " where UserId = " + oldUserId + "";
|
|
|
try {
|
|
|
runJdbc(sql);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
break;
|
|
|
case 5:
|
|
|
studentAccountCrowdfundingSystemService.updateByTransfer(allocation.getAvailableFunds(), allocation.getInitialCapital(), allocation.getInitialInvestmentCapital(), studentId);
|
|
|
String sql1 = "update ExaTheRaiseAssetAllocation set AvailableFunds = " + allocation.getAvailableFunds() + ",InitialCapital = " + allocation.getInitialCapital() + "," +
|
|
|
"InitialInvestmentCapital =" + allocation.getInitialInvestmentCapital() + " where UserId =" + oldUserId + " ";
|
|
|
try {
|
|
|
runJdbc(sql1);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
break;
|
|
|
case 16:
|
|
|
studentAccountMockTradingSystemService.updateByTransfer(allocation.getAvailableFunds(), allocation.getInitialCapital(), allocation.getInitialInvestmentCapital(), studentId, Long.valueOf(16));
|
|
|
String sql2 = "update ExaMNJYAssetAllocation set AvailableFunds =" + allocation.getAvailableFunds() + " ,InitialCapital= " + allocation.getInitialCapital() + ", " +
|
|
|
"InitialInvestmentCapital =" + allocation.getInitialInvestmentCapital() + " where UserId =" + oldUserId + " and ApplicationId = 16";
|
|
|
try {
|
|
|
runJdbc(sql2);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
break;
|
|
|
case -16:
|
|
|
studentAccountMockTradingSystemService.updateByTransfer(allocation.getAvailableFunds(), allocation.getInitialCapital(), allocation.getInitialInvestmentCapital(), studentId, Long.valueOf(-16));
|
|
|
String sql3 = "update ExaMNJYAssetAllocation set AvailableFunds =" + allocation.getAvailableFunds() + " ,InitialCapital= " + allocation.getInitialCapital() + ", " +
|
|
|
"InitialInvestmentCapital =" + allocation.getInitialInvestmentCapital() + " where UserId =" + oldUserId + " and ApplicationId = -16";
|
|
|
try {
|
|
|
runJdbc(sql3);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<StudentAccountAssetAllocation> getInfoByStudentId(Long studentId) {
|
|
|
return studentAccountAssetAllocationDao.getInfo(studentId);
|
|
|
}
|
|
|
|
|
|
//获取个人投资账户
|
|
|
|
|
|
public List<StudentAccountAssetAllocation> getInfoByStudentIdAnIsInstitution(Long studentId) {
|
|
|
return studentAccountAssetAllocationDao.getInfoByStudentIdAnIsInstitution(studentId);
|
|
|
}
|
|
|
|
|
|
public static String sendPostRequest(String url, String postData) {
|
|
|
try {
|
|
|
URL apiUrl = new URL(url);
|
|
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
|
|
|
connection.setRequestMethod("POST");
|
|
|
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
|
connection.setRequestProperty("Content-Length", String.valueOf(postData.length()));
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
|
try (OutputStream os = connection.getOutputStream()) {
|
|
|
byte[] input = postData.getBytes("UTF-8");
|
|
|
os.write(input, 0, input.length);
|
|
|
}
|
|
|
|
|
|
int responseCode = connection.getResponseCode();
|
|
|
|
|
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
|
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
|
|
String inputLine;
|
|
|
StringBuilder response = new StringBuilder();
|
|
|
|
|
|
while ((inputLine = in.readLine()) != null) {
|
|
|
response.append(inputLine);
|
|
|
}
|
|
|
|
|
|
return response.toString();
|
|
|
}
|
|
|
} else {
|
|
|
System.out.println("接口请求错误:" + responseCode);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取转账账户
|
|
|
*
|
|
|
* @param studentId
|
|
|
* @return
|
|
|
*/
|
|
|
public List<StudentAccountAssetAllocation> getCapitalAccount(Long studentId) {
|
|
|
List<StudentAccountAssetAllocation> select = studentAccountAssetAllocationDao.getSQLManager().lambdaQuery(StudentAccountAssetAllocation.class)
|
|
|
.andEq(StudentAccountAssetAllocation::getStudentId, studentId)
|
|
|
.andEq(StudentAccountAssetAllocation::getState, 2)
|
|
|
.andNotIn(StudentAccountAssetAllocation::getApplicationId, Arrays.asList(-1))
|
|
|
.select();
|
|
|
return select;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 拷贝一些必要的信息
|
|
|
*
|
|
|
* @param loginTodo
|
|
|
* @param param
|
|
|
*/
|
|
|
private void copyInfoByApplicationToken(LoginTodo loginTodo, StudentAccountAssetAllocationQuery param) {
|
|
|
|
|
|
Assert.notNull(loginTodo);
|
|
|
Assert.notNull(param);
|
|
|
|
|
|
// 从token中获取必要条件
|
|
|
param.setStudentId(Long.valueOf(loginTodo.getStudentId()));
|
|
|
param.setApplicationId(Long.valueOf(loginTodo.getApplicationId()));
|
|
|
param.setUniversitiesCollegesId(Long.valueOf(loginTodo.getSchoolId()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新资产账户的金额,指定某些字段
|
|
|
* 只能操作,可用资金字段(availableFunds)
|
|
|
*
|
|
|
* @param applicationToken
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
public void updateAccountAvailableFunds(String applicationToken, StudentAccountAssetAllocationQuery param) {
|
|
|
|
|
|
Assert.notNull(param.getAvailableFunds(), "availableFunds 可用资金不能为空!");
|
|
|
Assert.notNull(param.getUpdateVersion(), "updateVersion 更新版本不能为空!");
|
|
|
Assert.notNull(param.getName(), "name 账户名称不能为空!");
|
|
|
|
|
|
// 已开通状态:2
|
|
|
param.setState(2);
|
|
|
// 这里1代表未删除,是正常状态
|
|
|
param.setIsDel(1);
|
|
|
List<StudentAccountAssetAllocation> accountAssetAllocations = getByApplicationToken(applicationToken, param);
|
|
|
|
|
|
Assert.notEmpty(accountAssetAllocations, "未查询到账户信息!");
|
|
|
Assert.isTrue(accountAssetAllocations.size() == 1, "本次查询到多个账户,无法同时操作多个账户!");
|
|
|
|
|
|
StudentAccountAssetAllocation accountAssetAllocation = getFirst(accountAssetAllocations);
|
|
|
|
|
|
// 预扣资金,先看下是否能够被扣除
|
|
|
BigDecimal remainingAvailableFundsAfterDeduction = accountAssetAllocation
|
|
|
.getAvailableFunds().subtract(param.getAvailableFunds()).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
// 这种情况,是不够扣除的。比较预扣资金,是否小于0
|
|
|
boolean isLessZero = NumberUtil.isLess(remainingAvailableFundsAfterDeduction, BigDecimal.ZERO);
|
|
|
|
|
|
Assert.isFalse(isLessZero, "用户余额不足,无法完成本次操作!");
|
|
|
|
|
|
StudentAccountAssetAllocation updatePO = new StudentAccountAssetAllocation();
|
|
|
updatePO.setId(accountAssetAllocation.getId());
|
|
|
updatePO.setAvailableFunds(remainingAvailableFundsAfterDeduction);
|
|
|
updatePO.setUpdateVersion(param.getUpdateVersion());
|
|
|
|
|
|
updateTemplate(updatePO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能描述: <br>
|
|
|
* 通过token获取应用绑定的课程信息
|
|
|
*
|
|
|
* @param applicationToken 跳转时候,传递的token
|
|
|
* @return {@link List< CourseInfo>}
|
|
|
* @Author: lx
|
|
|
* @Date: 2023/3/22 21:24
|
|
|
*/
|
|
|
public List<CourseInfo> getApplicationBindCourseInfo(String applicationToken) {
|
|
|
LoginTodo loginTodo = validateAndGetLoginTodo(applicationToken);
|
|
|
|
|
|
String applicationId = loginTodo.getApplicationId();
|
|
|
|
|
|
if (StrUtil.isBlank(applicationId)) {
|
|
|
return emptyList();
|
|
|
}
|
|
|
|
|
|
ResourcesApplicationCourseQuery query = new ResourcesApplicationCourseQuery();
|
|
|
query.setResourcesApplicationId(Long.valueOf(applicationId));
|
|
|
List<ResourcesApplicationCourse> list = resourcesApplicationCourseService.getValuesByQueryNotWithPermission(query);
|
|
|
|
|
|
String courseInfoIds = listJoin(list, ResourcesApplicationCourse::getCourseInfoId);
|
|
|
|
|
|
return courseInfoService.getByIds(courseInfoIds);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|