博主主页:Java旅途
简介:分享计算机知识、学习路线、系统源码及教程
文末获取源码
记账管理系统基于Spring+SpringMVC+Mybatis开发,系统主要功能如下:
收入项管理
支出项管理
收入方式管理
支出方式管理
添加收入
添加支出
余额管理
历史收支
图表统计
IncomeController
package com.taoxiuxia.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.taoxiuxia.model.Balance;
import com.taoxiuxia.model.Income;
import com.taoxiuxia.model.Item;
import com.taoxiuxia.model.PayMethod;
import com.taoxiuxia.model.SessionUser;
import com.taoxiuxia.service.IIncomeService;
import com.taoxiuxia.service.IItemService;
import com.taoxiuxia.service.IMonthlyStatisticsService;
import com.taoxiuxia.service.IPayMethodService;
import com.taoxiuxia.util.Constants;
import com.taoxiuxia.util.MyDateFormat;
import com.taoxiuxia.util.NumberFormat;
@Controller
@RequestMapping("/incomeController")
public class IncomeController {
private IIncomeService incomeService;
private IItemService itemService;
private IMonthlyStatisticsService monthlyStatisticsService;
private IPayMethodService payMethodService;
public IIncomeService getIncomeService() {
return incomeService;
}
@Autowired
public void setIncomeService(IIncomeService incomeService) {
this.incomeService = incomeService;
}
public IMonthlyStatisticsService getMonthlyStatisticsService() {
return monthlyStatisticsService;
}
@Autowired
public void setMonthlyStatisticsService(IMonthlyStatisticsService monthlyStatisticsService) {
this.monthlyStatisticsService = monthlyStatisticsService;
}
public IItemService getItemService() {
return itemService;
}
@Autowired
public void setItemService(IItemService itemService) {
this.itemService = itemService;
}
public IPayMethodService getPayMethodService() {
return payMethodService;
}
@Autowired
public void setPayMethodService(IPayMethodService payMethodService) {
this.payMethodService = payMethodService;
}
/**
* income页面
*
* @param model
* @return
*/
@RequestMapping("/showIncome")
public String showIncomes(Model model, HttpSession session) {
Map<String, Float> map = monthlyStatistics(session);
SessionUser sessionUser= (SessionUser) session.getAttribute(Constants.SESSION_USER_KEY);
int userId = sessionUser.getUserId();
//页面上的统计信息
model.addAttribute("totalIncome", NumberFormat.save2Decimals(map.get("monthlyIncome")));
model.addAttribute("totalExpenditure", NumberFormat.save2Decimals(map.get("monthlyExpenditure")));
model.addAttribute("notActualExpenditure", NumberFormat.save2Decimals(map.get("notActualExpenditure")));
model.addAttribute("balanceInBeginOfMonth", NumberFormat.save2Decimals(map.get("balanceInBeginOfMonth")));
model.addAttribute("balanceId_InBeginOfMonth", NumberFormat.save2Decimals(map.get("balanceId_InBeginOfMonth")));
model.addAttribute("balanceShould", NumberFormat.save2Decimals(map.get("balanceShould")));
model.addAttribute("actualBalance", NumberFormat.save2Decimals(map.get("actualBalance")));
model.addAttribute("actualBalanceId", NumberFormat.save2Decimals(map.get("actualBalanceId")));
model.addAttribute("actualExpenditure", NumberFormat.save2Decimals(map.get("actualExpenditure")));
// income list
List<Income> incomes = incomeService.loadIncomes(userId);
model.addAttribute("incomes", incomes);
// 收入项 list
List<Item> items = itemService.loadIncomeItems(userId);
model.addAttribute("items", items);
//收入方式list
List<PayMethod> payMethods = payMethodService.loadPayMethods(userId, "in");
model.addAttribute("payMethods", payMethods);
model.addAttribute("sessionUser", sessionUser);
return "pages/income";
}
/**
* 增加income
*
* @param item
* @param money
* @param remark
*/
@RequestMapping("/addIncome")
public void addIncomes(String date, int item, float money, String moneyType, String remark, HttpSession session) {
int userId = Integer.parseInt(session.getAttribute(Constants.USER_ID)+"");
incomeService.addIncome(userId, date, item, money, moneyType, remark);
}
/**
* 修改收入
*
* @param incomeId
* @param money
* @param itemId
* @param remark
*/
@RequestMapping("/changeIncome")
public void changeIncome(int incomeId, float money, String moneyType, int itemId, String remark, String date) {
incomeService.changeIncome(incomeId, money, moneyType, itemId, remark, MyDateFormat.dateFormat(date));
}
/**
* 删除收入
*
* @param incomeId
* @param itemId
*/
@RequestMapping("/deleIncome")
public void deleIncome(int incomeId, HttpSession session) {
incomeService.deleIncome(incomeId);
}
/**
* 在收入和支出页面上 统计部分的内容
* 这部分和ExpenditureController的相同方法完全一样
*
* @param session
* @return
*/
public Map<String,Float> monthlyStatistics(HttpSession session) {
int userId = Integer.parseInt(session.getAttribute(Constants.USER_ID)+"");
Map<String,Float>map = new HashMap<String, Float>();
// 月收入
float monthlyIncome = monthlyStatisticsService.monthlyIncome(userId);
map.put("monthlyIncome", monthlyIncome);
// 月支出
float monthlyExpenditure = monthlyStatisticsService.monthlyExpenditure(userId);
map.put("monthlyExpenditure", monthlyExpenditure);
// 月支出中花呗与信用卡的数额
float notActualExpenditure = monthlyStatisticsService.notActualExpenditure(userId);
map.put("notActualExpenditure", notActualExpenditure);
// 本月实际支出
float actualExpenditure = monthlyExpenditure - notActualExpenditure;
map.put("actualExpenditure", actualExpenditure);
// 本月初(上月末)结余
Balance balance_InBeginOfMonth = monthlyStatisticsService.balanceInBeginOfMonth(userId);
float actualBalance_InBeginOfMonth = balance_InBeginOfMonth.getActualBalance();
map.put("balanceInBeginOfMonth", actualBalance_InBeginOfMonth);
map.put("balanceId_InBeginOfMonth", balance_InBeginOfMonth.getId() + 0f);
// 本月应结余 ==> 月初结余+月收入- (月支出-花呗/信用卡)
float balanceShould = actualBalance_InBeginOfMonth + monthlyIncome - (monthlyExpenditure - notActualExpenditure);
map.put("balanceShould", balanceShould);
// 本月实际结余
Balance balanceOfThisMonth = monthlyStatisticsService.balanceOfThisMonth(userId);
float actualBalance; // 本月实际结余
float actualBalanceId;
if(balanceOfThisMonth == null){
actualBalance = -1;
actualBalanceId = -1;
}else{
actualBalance = balanceOfThisMonth.getActualBalance();
actualBalanceId = balanceOfThisMonth.getId();
}
map.put("actualBalance", actualBalance);
map.put("actualBalanceId", actualBalanceId);
return map;
}
}
PayMethodController
package com.taoxiuxia.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.taoxiuxia.model.PayMethod;
import com.taoxiuxia.model.SessionUser;
import com.taoxiuxia.service.IPayMethodService;
import com.taoxiuxia.util.Constants;
@Controller
@RequestMapping("/payMethodController")
public class PayMethodController {
private Logger logger=LoggerFactory.getLogger(PayMethodController.class);
private IPayMethodService payMethodService;
public IPayMethodService getPayMethodService() {
return payMethodService;
}
@Autowired
public void setPayMethodService(IPayMethodService payMethodService) {
this.payMethodService = payMethodService;
}
/**
* 收支方式管理页面
*
* @param model
* @return
*/
@RequestMapping("/showManagePayMethods")
public String showManagePayMethods(Model model,HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(Constants.SESSION_USER_KEY);
int userId = sessionUser.getUserId();
List<PayMethod> incomePayMethods = payMethodService.loadPayMethods(userId, "in");
List<PayMethod> expenditurePayMethods = payMethodService.loadPayMethods(userId, "ex");
model.addAttribute("incomePayMethods", incomePayMethods);
model.addAttribute("expenditurePayMethods", expenditurePayMethods);
model.addAttribute("sessionUser", sessionUser);
return "pages/managePayMethods";
}
/**
* 修改PayMethod
* @param payMethodId
* @param payMethodName
* @param isCountInThisMonthEx
* @param remark
*/
@RequestMapping("/changePayMethod")
public void changeItem(int payMethodId, String payMethodName, int isCountInThisMonthEx, String remark) {
payMethodService.changePayMethod(payMethodId, payMethodName, isCountInThisMonthEx, remark);
}
/**
* 删除PayMethod
* @param payMethodId
*/
@RequestMapping("/delePayMethod")
public void delePayMethod(int payMethodId) {
payMethodService.delePayMethod(payMethodId);
}
/**
* 增加PayMethod
* @param session
* @param payMethodName
* @param isCountInThisMonthEx
* @param remark
* @param inOrEx
*/
@RequestMapping("/addPayMethod")
public void addItem(HttpSession session,String payMethodName, int isCountInThisMonthEx, String remark, String inOrEx) {
SessionUser sessionUser = (SessionUser) session.getAttribute(Constants.SESSION_USER_KEY);
int userId = sessionUser.getUserId();
payMethodService.addPayMethod(userId, payMethodName, isCountInThisMonthEx, inOrEx, remark);
}
/**
* PayMethod的上移和下移
* @param session
* @param itemId
* @param inOrEx
* @param upAndDown
* @return
*/
@RequestMapping(value = "/upAndDownPayMethod", produces = "application/json;charset=UTF-8")
public @ResponseBody Map<String ,Object> upAndDownPayMethod(HttpSession session, int payMethodId, String inOrEx, String upAndDown) {
Map<String, Object> map = new HashMap<String, Object>();
SessionUser sessionUser = (SessionUser) session.getAttribute(Constants.SESSION_USER_KEY);
int userId = sessionUser.getUserId();
String msg = payMethodService.upAndDownPayMethod(userId, payMethodId, inOrEx, upAndDown);
map.put("info", msg);
return map;
}
}
大家点赞、收藏、关注、评论啦 、👇🏻点开下方卡片👇🏻关注后回复 105