Skip to content

Commit eb9aa26

Browse files
修改对记账的支出和收入。
1 parent 7a597f8 commit eb9aa26

File tree

22 files changed

+594
-771
lines changed

22 files changed

+594
-771
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 430 additions & 736 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/yjz/notepad/bean/BookkeepingBean.java

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
import lombok.Data;
44

5-
import java.util.Date;
6-
75
/**
86
* author: YJZ
97
* date: 2018/11/27
108
* des:
119
*/
12-
@Data
1310
public class BookkeepingBean {
1411

1512
private Long id;
@@ -28,6 +25,98 @@ public class BookkeepingBean {
2825
// 年月数据
2926
private String addTime;
3027
// 记账详细时间
31-
private Date exactAddTime;
28+
private String exactAddTime;
29+
30+
public BookkeepingBean() {
31+
}
32+
33+
public BookkeepingBean(Long id, Long userId, Long bookTypeId, Long classificationId, Long moneyType, String content, float money, String addTime, String exactAddTime) {
34+
this.id = id;
35+
this.userId = userId;
36+
this.bookTypeId = bookTypeId;
37+
this.classificationId = classificationId;
38+
this.moneyType = moneyType;
39+
this.content = content;
40+
this.money = money;
41+
this.addTime = addTime;
42+
this.exactAddTime = exactAddTime;
43+
}
44+
45+
public Long getUserId() {
46+
return userId;
47+
}
48+
49+
public void setUserId(Long userId) {
50+
this.userId = userId;
51+
}
52+
53+
public Long getBookTypeId() {
54+
return bookTypeId;
55+
}
56+
57+
public void setBookTypeId(Long bookTypeId) {
58+
this.bookTypeId = bookTypeId;
59+
}
60+
61+
public Long getClassificationId() {
62+
return classificationId;
63+
}
64+
65+
public void setClassificationId(Long classificationId) {
66+
this.classificationId = classificationId;
67+
}
68+
69+
public Long getMoneyType() {
70+
return moneyType;
71+
}
72+
73+
public void setMoneyType(Long moneyType) {
74+
this.moneyType = moneyType;
75+
}
76+
77+
public String getContent() {
78+
return content;
79+
}
80+
81+
public void setContent(String content) {
82+
this.content = content;
83+
}
84+
85+
public float getMoney() {
86+
return money;
87+
}
88+
89+
public void setMoney(float money) {
90+
this.money = money;
91+
}
92+
93+
public String getAddTime() {
94+
return addTime;
95+
}
96+
97+
public void setAddTime(String addTime) {
98+
this.addTime = addTime;
99+
}
100+
101+
public String getExactAddTime() {
102+
return exactAddTime;
103+
}
104+
105+
public void setExactAddTime(String exactAddTime) {
106+
this.exactAddTime = exactAddTime;
107+
}
32108

109+
@Override
110+
public String toString() {
111+
return "BookkeepingBean{" +
112+
"userId=" + userId +
113+
", bookTypeId=" + bookTypeId +
114+
", classificationId=" + classificationId +
115+
", moneyType=" + moneyType +
116+
", content='" + content + '\'' +
117+
", money=" + money +
118+
", addTime='" + addTime + '\'' +
119+
", exactAddTime=" + exactAddTime +
120+
'}';
121+
}
33122
}

src/main/java/com/yjz/notepad/bean/UserBookkeepingBean.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public class UserBookkeepingBean {
1212

1313
// 用户ID
1414
private Long userId;
15-
// item 描述
16-
private String des;
1715
// 账本名称
1816
private String name;
1917
// 0收入 1支出

src/main/java/com/yjz/notepad/controller/BookkeepingController.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.yjz.notepad.bean.*;
44
import com.yjz.notepad.service.IBookkeepingService;
55
import org.springframework.stereotype.Controller;
6+
import org.springframework.web.bind.annotation.RequestBody;
67
import org.springframework.web.bind.annotation.RequestMapping;
78
import org.springframework.web.bind.annotation.RequestMethod;
89
import org.springframework.web.bind.annotation.ResponseBody;
@@ -27,10 +28,12 @@ public class BookkeepingController {
2728

2829
@RequestMapping(value = "/add", method = RequestMethod.POST)
2930
@ResponseBody
30-
public Map<String, Object> addBookkeepingDate(BookkeepingBean bookkeepingBean) {
31+
public Map<String, Object> addBookkeepingDate(String as, @RequestBody BookkeepingBean bookkeepingBean) {
32+
System.out.println("bookkeepingBean = " + bookkeepingBean.toString());
33+
System.out.println("as = " + as);
3134
Long isSuccess = service.addBookkeepingDate(bookkeepingBean);
3235
if (isSuccess > 0) {
33-
return R.ok("记账成功");
36+
return R.ok("记账成功", true);
3437
} else {
3538
return R.error("记账失败");
3639
}
@@ -41,11 +44,14 @@ public Map<String, Object> addBookkeepingDate(BookkeepingBean bookkeepingBean) {
4144
public Map<String, Object> getUserMonthDate(Long userId, Long bookType, String yearAndMonth) {
4245
System.out.println("userId = " + userId + " bookType = " + bookType + " monthStr = " + yearAndMonth);
4346
List<UserMonthDate> userMonthDates = service.queryBookkeepingDateByMonth(userId, bookType, yearAndMonth);
47+
HashMap<String, Object> resultMap = new HashMap<>();
4448
if (userMonthDates.size() <= 0) {
45-
return R.error("暂无数据");
49+
resultMap.put("allMonthIn", 0);
50+
resultMap.put("allMonthOut", 0);
51+
resultMap.put("dayData", null);
52+
return R.ok("请求成功", resultMap);
4653
}
4754
List<String> dataList = new ArrayList<>();
48-
HashMap<String, Object> resultMap = new HashMap<>();
4955
// 一个月的总收入
5056
float allMonthIn = 0f;
5157
// 一个月的总支出
@@ -56,12 +62,13 @@ public Map<String, Object> getUserMonthDate(Long userId, Long bookType, String y
5662
if (!dataList.contains(userMonthDate.getExactTime())) {
5763
dataList.add(userMonthDate.getExactTime());
5864
}
65+
// 0 支出 1 收入
5966
if (userMonthDate.getMoneyType() == 0) {
60-
// 收入
61-
allMonthIn += userMonthDate.getMoney();
62-
} else {
6367
// 支出
6468
allMonthOut += userMonthDate.getMoney();
69+
} else {
70+
// 收入
71+
allMonthIn += userMonthDate.getMoney();
6572
}
6673
}
6774
resultMap.put("allMonthIn", allMonthIn);
@@ -75,18 +82,18 @@ public Map<String, Object> getUserMonthDate(Long userId, Long bookType, String y
7582
boolean isChange = true;
7683
for (UserBookkeepingBean userBookkeepingBean : userBookkeepingBeans) {
7784
if (userBookkeepingBean.getMoneyType() == 0) {
78-
// 当天总收入
79-
allIn += userBookkeepingBean.getMoney();
80-
} else {
8185
// 当天总支出
8286
allOut += userBookkeepingBean.getMoney();
87+
} else {
88+
// 当天总收入
89+
allIn += userBookkeepingBean.getMoney();
8390
}
8491
if (isChange) {
8592
exactTimes = userBookkeepingBean.getExactTime();
8693
isChange = false;
8794
}
8895
}
89-
userDayDates.add(new UserDayDate(allIn, allOut,exactTimes, userBookkeepingBeans));
96+
userDayDates.add(new UserDayDate(allIn, allOut, exactTimes, userBookkeepingBeans));
9097
}
9198
resultMap.put("dayData", userDayDates);
9299
return R.ok("请求成功", resultMap);

src/main/java/com/yjz/notepad/controller/UserController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.yjz.notepad.service.IUserService;
77
import com.yjz.notepad.util.StringUtil;
88
import org.springframework.stereotype.Controller;
9+
import org.springframework.web.bind.annotation.RequestBody;
910
import org.springframework.web.bind.annotation.RequestMapping;
1011
import org.springframework.web.bind.annotation.RequestMethod;
1112
import org.springframework.web.bind.annotation.ResponseBody;

src/main/java/com/yjz/notepad/test/BookkeepingTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
1111

1212
import javax.annotation.Resource;
13+
import java.text.SimpleDateFormat;
1314
import java.util.ArrayList;
1415
import java.util.Date;
1516
import java.util.List;
17+
import java.util.Locale;
1618

1719
/**
1820
* author: YJZ
@@ -32,14 +34,17 @@ public class BookkeepingTest {
3234
@Test
3335
public void testAddBookkeepingData() {
3436
BookkeepingBean bookkeepingBean = new BookkeepingBean();
35-
bookkeepingBean.setUserId(19L);
37+
bookkeepingBean.setUserId(2L);
3638
bookkeepingBean.setBookTypeId(1L);
3739
bookkeepingBean.setClassificationId(1L);
3840
bookkeepingBean.setMoneyType(2L);
3941
bookkeepingBean.setContent("外快");
4042
bookkeepingBean.setMoney(1222.7f);
4143
bookkeepingBean.setAddTime("2018-11");
42-
bookkeepingBean.setExactAddTime(new Date());
44+
45+
SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
46+
bookkeepingBean.setExactAddTime(formatDate.format(new Date()));
47+
4348
Long isSuccess = service.addBookkeepingDate(bookkeepingBean);
4449
System.out.println(" isSuccess id = " + isSuccess);
4550
}
@@ -54,12 +59,13 @@ public void testQueryUserByBookkeepingType() {
5459
float allMonthIn = 0f;
5560
float allMonthOut = 0f;
5661
for (UserMonthDate exactDate : userBookkeepingBeans) {
62+
// 0 支出 1 收入
5763
if (exactDate.getMoneyType() == 0) {
58-
// 收入
59-
allMonthIn += exactDate.getMoney();
60-
} else {
6164
// 支出
6265
allMonthOut += exactDate.getMoney();
66+
} else {
67+
// 收入
68+
allMonthIn += exactDate.getMoney();
6369
}
6470
if (!dataList.contains(exactDate.getExactTime())) {
6571
dataList.add(exactDate.getExactTime());

src/main/resource/mapper/BookkeepingDao.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717

1818
<!-- 查询用戶一个月中记账了日期 -->
1919
<select id="queryBookkeepingDateByMonth" resultType="UserMonthDate">
20-
SELECT money_type,money,exact_time FROM bookkeeping WHERE user_id=#{0} AND type_id =#{1} AND add_time=#{2} order by exact_time;
20+
SELECT money_type,money,exact_time FROM bookkeeping WHERE user_id=#{0} AND type_id =#{1} AND add_time=#{2} order by exact_time desc;
2121
</select>
2222

2323
<!-- 查询用户一个月中所有的记账记录 -->
2424
<select id="queryAllBookkeeping" resultType="UserBookkeepingBean">
25-
SELECT b.user_id,b.content,b.money,b.money_type,c.des,t.name,b.exact_time
25+
SELECT b.user_id,b.content,b.money,b.money_type,t.name,b.exact_time
2626
FROM bookkeeping b
2727
LEFT JOIN user u on u.id = b.user_id
28-
LEFT JOIN classification c on c.id = b.classification_id
2928
LEFT JOIN bookkeeping_type t on t.id = b.type_id
30-
WHERE b.user_id=#{0} AND b.type_id=#{1} AND b.exact_time = #{2} ;
29+
WHERE b.user_id=#{0} AND b.type_id=#{1} AND b.exact_time = #{2} order by b.id desc;
3130
</select>
3231

3332
</mapper>
-2.02 KB
Binary file not shown.
-407 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)