大家好!我是程序猿老A,感谢您阅读本文,欢迎一键三连哦。
💞当前专栏:Java毕业设计
精彩专栏推荐👇🏻👇🏻👇🏻
开发环境
- 开发语言:Java
- 框架:ssm
- JDK版本:JDK1.8
- 服务器:tomcat7
- 数据库:mysql 5.7
- 数据库工具:Navicat12
- 开发软件:eclipse/myeclipse/idea
- Maven包:Maven3.3.9
- 浏览器:谷歌浏览器
源码下载地址:
https://download.csdn.net/download/2301_76953549/89117267
论文目录
【如需全文请按文末获取联系】
一、项目简介
理财通通过MySQL数据库与Eclipse工具进行开发,理财通能够实现基金管理,基金自选管理,交易记录管理,基金净值管理,持有基金管理,论坛管理,用户管理等功能。
二、系统设计
2.1软件功能模块设计
在前面分析的管理员功能的基础上,进行接下来的设计工作,最终展示设计的管理员结构图(见下图)。管理员增删改查实验室
2.2数据库设计
管理员功能结构图的绘制结果见图4-1。管理员登录进入本系统操作的功能包括管理基金,管理基金净值,管理基金自选,管理持有基金,管理交易记录,管理论坛帖子,管理公告等。
用户功能结构图的绘制结果见图4-2。用户登录进入本系统操作的功能包括购买基金,查看基金净值,查看基金经理,把基金添加自选,卖出持有基金,查看基金交易记录等。
(1)使用Visio这样的常用的实体属性图绘制工具来绘制基金实体属性图,绘制结果见图4-3。
(2)使用Visio这样的常用的实体属性图绘制工具来绘制用户实体属性图,绘制结果见图4-4。
(3)使用Visio这样的常用的实体属性图绘制工具来绘制交易记录实体属性图,绘制结果见图4-5。
(4)使用Visio这样的常用的实体属性图绘制工具来绘制管理员实体属性图,绘制结果见图4-6。
(5)绘制的上述实体间存在的联系见图4-7。
三、系统项目部分截图
3.1管理员功能实现
基金管理
管理员进入如图5-1所示的基金管理界面之后,管理员点击信息显示栏中最右侧的修改,删除,下架,上架按钮可依次完成基金信息的修改,删除,下架,上架等操作。
基金净值管理
管理员进入如图5-2所示的基金净值管理界面之后,管理员点击信息显示栏中最右侧的修改,删除按钮可依次完成基金净值信息的修改,删除等操作,管理员在当前界面也能添加基金净值,查询基金净值。
基金自选管理
管理员进入如图5-3所示的基金自选管理界面之后,管理员点击信息显示栏右侧的查看,删除按钮可依次完成基金自选信息的查看,删除等操作。
3.2用户功能实现
基金信息
用户进入如图5-5所示的基金信息界面之后,用户把基金添加自选,查看基金的基金经理信息,购买本界面的基金等。
持有基金管理
用户进入如图5-7所示的持有基金管理界面之后,用户可以查询持有基金信息,可以卖出部分持有基金。
交易记录管理
用户进入如图5-8所示的交易记录管理界面之后,用户对已经买入和已经卖出的基金的交易记录信息进行查询和查看,可以删除基金买入或卖出的交易记录信息。
四、部分核心代码
package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.apache.ibatis.javassist.expr.NewArray;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 持有基金
* 后端接口
* @author
* @email
*/
@RestController
@Controller
@RequestMapping("/jijinChiyou")
public class JijinChiyouController {
private static final Logger logger = LoggerFactory.getLogger(JijinChiyouController.class);
@Autowired
private JijinChiyouService jijinChiyouService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;
//级联表service
@Autowired
private JijinService jijinService;// 基金
@Autowired
private JingzhiService jingzhiService;//净值
@Autowired
private JiaoyijiluService jiaoyijiluService; //记录
@Autowired
private YonghuService yonghuService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role))
return R.error(511,"权限为空");
else if("用户".equals(role))
params.put("yonghuId",request.getSession().getAttribute("userId"));
if(params.get("orderBy")==null || params.get("orderBy")==""){
params.put("orderBy","id");
}
PageUtils page = jijinChiyouService.queryPage(params);
//字典表数据转换
List<JijinChiyouView> list =(List<JijinChiyouView>)page.getList();
List<Integer> jijinIds= new ArrayList<>();//基金的id列表
for(JijinChiyouView c:list){
Integer jijinId = c.getJijinId();
jijinIds.add(jijinId);
}
//查询出所有的净值列表
List<JingzhiEntity> jijinJingzhiList = jingzhiService.selectList(new EntityWrapper<JingzhiEntity>().in("jijin_id", jijinIds));
Map<Integer, List<String>> map = new HashMap<>();
try {
for(JingzhiEntity c:jijinJingzhiList){
Integer jijinId = c.getJijinId();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if(map.containsKey(jijinId)){
List<String> strings = map.get(jijinId);
Date oldDate = sdf.parse(strings.get(0));
Date newDate = c.getInsertTime();
if(oldDate.getTime() < newDate.getTime()){
strings = new ArrayList<>();
strings.add(sdf.format(c.getInsertTime()));
strings.add(c.getJingzhiMoney().toString());
map.put(jijinId,strings);
}
}else{
List<String> strings = new ArrayList<>();
strings.add(sdf.format(c.getInsertTime()));
strings.add(c.getJingzhiMoney().toString());
map.put(jijinId,strings);
}
}
} catch (ParseException e) {
e.printStackTrace();
}
for(JijinChiyouView c:list){
List<String> strings = map.get(c.getJijinId());
c.setZuixinjingzhiriqi(strings.get(0));
c.setZuixinjingzhi(Double.parseDouble(strings.get(1)));
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 基金卖出
*/
@RequestMapping("/maichu")
public R maichu(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("maichu方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role))
return R.error(511,"权限为空");
else if(!"用户".equals(role))
return R.error(511,"只有用户才能卖出基金");
//request.getSession().getAttribute("userId")
Integer maichuId = Integer.valueOf(String.valueOf(params.get("maichuId")));
Integer maiFenshu = Integer.valueOf(String.valueOf(params.get("maiFenshu")));
JijinChiyouEntity jijinChiyouEntity = jijinChiyouService.selectById(maichuId);
if(jijinChiyouEntity != null){
if((jijinChiyouEntity.getFenshu()-maiFenshu<0)){
return R.error(511,"卖出份数不能大于持有份数");
}
Integer jijinId = jijinChiyouEntity.getJijinId();
JijinEntity jijinEntity = jijinService.selectById(jijinId);
if(jijinEntity == null){
return R.error(511,"查不到基金");
}
List<JingzhiEntity> jingzhiEntities = jingzhiService.selectList(new EntityWrapper<JingzhiEntity>().eq("jijin_id", jijinEntity.getId()).orderBy("insert_time", false));
if(jingzhiEntities == null || jingzhiEntities.size() < 1 ){
return R.error(511,"查不到基金的净值情况");
}
JingzhiEntity jingzhiEntity = jingzhiEntities.get(0);
Double jingzhiMoney = jingzhiEntity.getJingzhiMoney();
double sumMoney = new BigDecimal(jingzhiMoney).multiply(new BigDecimal(maiFenshu)).doubleValue();
/**
* 持有基金
*/
jijinChiyouEntity.setFenshu(jijinChiyouEntity.getFenshu()-maiFenshu);//现有份数 - 卖出份数
jijinChiyouEntity.setSellSumMoney(jijinChiyouEntity.getSellSumMoney() + sumMoney);//当前总卖出 + 这次总卖出
/**
* 用户
*/
YonghuEntity yonghuEntity = yonghuService.selectById(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
if(yonghuEntity == null){
return R.error(511,"查不到当前登录用户");
}else if(!yonghuEntity.getId().equals(jijinChiyouEntity.getYonghuId())){
return R.error(511,"当前登录用户不是基金持有用户");
}
yonghuEntity.setNewMoney(yonghuEntity.getNewMoney() + sumMoney);
/**
* 基金记录
*/
JiaoyijiluEntity jiaoyijiluEntity = new JiaoyijiluEntity();
jiaoyijiluEntity.setJiaoyijiluTypes(2);
jiaoyijiluEntity.setInsertTime(new Date());
jiaoyijiluEntity.setCreateTime(new Date());
jiaoyijiluEntity.setJijinId(jijinChiyouEntity.getJijinId());
jiaoyijiluEntity.setJiaoyijiluSumMoney(sumMoney);
jiaoyijiluEntity.setJiaoyijiluFenshu(maiFenshu);
jiaoyijiluEntity.setYonghuId(yonghuEntity.getId());
jiaoyijiluService.insert(jiaoyijiluEntity);
yonghuService.updateById(yonghuEntity);
jijinChiyouService.updateById(jijinChiyouEntity);
}else{
return R.error(511,"查不到当前用户持有的基金");
}
return R.ok();
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
JijinChiyouEntity jijinChiyou = jijinChiyouService.selectById(id);
if(jijinChiyou !=null){
//entity转view
JijinChiyouView view = new JijinChiyouView();
BeanUtils.copyProperties( jijinChiyou , view );//把实体数据重构到view中
//级联表
JijinEntity jijin = jijinService.selectById(jijinChiyou.getJijinId());
if(jijin != null){
BeanUtils.copyProperties( jijin , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setJijinId(jijin.getId());
}
//级联表
YonghuEntity yonghu = yonghuService.selectById(jijinChiyou.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setYonghuId(yonghu.getId());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody JijinChiyouEntity jijinChiyou, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,jijinChiyou:{}",this.getClass().getName(),jijinChiyou.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role))
return R.error(511,"权限为空");
else if("用户".equals(role))
jijinChiyou.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
Wrapper<JijinChiyouEntity> queryWrapper = new EntityWrapper<JijinChiyouEntity>()
.eq("jijin_id", jijinChiyou.getJijinId())
.eq("yonghu_id", jijinChiyou.getYonghuId())
.eq("fenshu", jijinChiyou.getFenshu())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
JijinChiyouEntity jijinChiyouEntity = jijinChiyouService.selectOne(queryWrapper);
if(jijinChiyouEntity==null){
jijinChiyou.setInsertTime(new Date());
jijinChiyou.setCreateTime(new Date());
jijinChiyouService.insert(jijinChiyou);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody JijinChiyouEntity jijinChiyou, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,jijinChiyou:{}",this.getClass().getName(),jijinChiyou.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role))
return R.error(511,"权限为空");
else if("用户".equals(role))
jijinChiyou.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
//根据字段查询是否有相同数据
Wrapper<JijinChiyouEntity> queryWrapper = new EntityWrapper<JijinChiyouEntity>()
.notIn("id",jijinChiyou.getId())
.andNew()
.eq("jijin_id", jijinChiyou.getJijinId())
.eq("yonghu_id", jijinChiyou.getYonghuId())
.eq("fenshu", jijinChiyou.getFenshu())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
JijinChiyouEntity jijinChiyouEntity = jijinChiyouService.selectOne(queryWrapper);
if(jijinChiyouEntity==null){
// String role = String.valueOf(request.getSession().getAttribute("role"));
// if("".equals(role)){
// jijinChiyou.set
// }
jijinChiyouService.updateById(jijinChiyou);//根据id更新
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
jijinChiyouService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 批量上传
*/
@RequestMapping("/batchInsert")
public R save( String fileName){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
try {
List<JijinChiyouEntity> jijinChiyouList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
JijinChiyouEntity jijinChiyouEntity = new JijinChiyouEntity();
// jijinChiyouEntity.setJijinId(Integer.valueOf(data.get(0))); //基金 要改的
// jijinChiyouEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的
// jijinChiyouEntity.setFenshu(Integer.valueOf(data.get(0))); //持有份数 要改的
// jijinChiyouEntity.setBuySumMoney(data.get(0)); //总购买金额 要改的
// jijinChiyouEntity.setSellSumMoney(data.get(0)); //总卖出金额 要改的
// jijinChiyouEntity.setInsertTime(date);//时间
// jijinChiyouEntity.setCreateTime(date);//时间
jijinChiyouList.add(jijinChiyouEntity);
//把要查询是否重复的字段放入map中
}
//查询是否重复
jijinChiyouService.insertBatch(jijinChiyouList);
return R.ok();
}
}
}
}catch (Exception e){
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
// 没有指定排序字段就默认id倒序
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
params.put("orderBy","id");
}
PageUtils page = jijinChiyouService.queryPage(params);
//字典表数据转换
List<JijinChiyouView> list =(List<JijinChiyouView>)page.getList();
for(JijinChiyouView c:list)
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
return R.ok().put("data", page);
}
/**
* 前端详情
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
JijinChiyouEntity jijinChiyou = jijinChiyouService.selectById(id);
if(jijinChiyou !=null){
//entity转view
JijinChiyouView view = new JijinChiyouView();
BeanUtils.copyProperties( jijinChiyou , view );//把实体数据重构到view中
//级联表
JijinEntity jijin = jijinService.selectById(jijinChiyou.getJijinId());
if(jijin != null){
BeanUtils.copyProperties( jijin , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setJijinId(jijin.getId());
}
//级联表
YonghuEntity yonghu = yonghuService.selectById(jijinChiyou.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setYonghuId(yonghu.getId());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody JijinChiyouEntity jijinChiyou, HttpServletRequest request){
logger.debug("add方法:,,Controller:{},,jijinChiyou:{}",this.getClass().getName(),jijinChiyou.toString());
Date date = new Date();
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role))
return R.error(511,"权限为空");
else if(!"用户".equals(role))
return R.error(511,"您没有支付权限");
/**
* 计算购买花费总金额
*/
BigDecimal jingzhiMoney;
List<JingzhiEntity> jingzhiEntities = jingzhiService.selectList(new EntityWrapper<JingzhiEntity>().eq("jijin_id", jijinChiyou.getJijinId()).orderBy("insert_time", false));
if(jingzhiEntities != null && jingzhiEntities.size() > 0){
JingzhiEntity jingzhiEntity = jingzhiEntities.get(0);
if(jingzhiEntity != null){
jingzhiMoney = new BigDecimal(jingzhiEntity.getJingzhiMoney());
}else{
return R.error(511,"查不到要购买的基金的净值");
}
}else{
return R.error(511,"查不到要购买的基金的净值列表");
}
Double buySumMoney = jingzhiMoney.multiply(new BigDecimal(jijinChiyou.getFenshu())).doubleValue();//购买总花费金额
/**
* 扣减余额
*/
Integer userId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
YonghuEntity yonghuEntity = yonghuService.selectById(userId);
Double balance = yonghuEntity.getNewMoney() - buySumMoney;
if(balance < 0.0){
return R.error(511,"当次购买金额大于您的余额,请去充值");
}
yonghuEntity.setNewMoney(balance);
yonghuService.updateById(yonghuEntity);
/**
* 更新当前持有基金
*/
JijinChiyouEntity jijinChiyouEntity = jijinChiyouService.selectOne(new EntityWrapper<JijinChiyouEntity>().eq("yonghu_id", userId).eq("jijin_id", jijinChiyou.getJijinId()));
if(jijinChiyouEntity == null){//第一次购买
jijinChiyou.setBuySumMoney(buySumMoney);
jijinChiyou.setSellSumMoney(0.0);
jijinChiyou.setInsertTime(date);
jijinChiyou.setCreateTime(date);
jijinChiyou.setYonghuId(userId);
jijinChiyouService.insert(jijinChiyou);
}else{//之后购买
jijinChiyouEntity.setFenshu(jijinChiyou.getFenshu()+jijinChiyouEntity.getFenshu());
jijinChiyouEntity.setBuySumMoney(jijinChiyouEntity.getBuySumMoney() + buySumMoney);
jijinChiyouService.updateById(jijinChiyouEntity);
}
/**
* 添加购买记录
*/
JiaoyijiluEntity jiaoyijiluEntity = new JiaoyijiluEntity();
jiaoyijiluEntity.setCreateTime(date);
jiaoyijiluEntity.setInsertTime(date);
jiaoyijiluEntity.setJiaoyijiluFenshu(jijinChiyou.getFenshu());
jiaoyijiluEntity.setYonghuId(userId);
jiaoyijiluEntity.setJiaoyijiluSumMoney(buySumMoney);
jiaoyijiluEntity.setJijinId(jijinChiyou.getJijinId());
jiaoyijiluEntity.setJiaoyijiluTypes(1);
jiaoyijiluService.insert(jiaoyijiluEntity);
return R.ok();
}
}
获取源码或论文
如需对应的论文或源码,以及其他定制需求,也可以下方微❤联系。