Skip to content

Commit 27edecf

Browse files
添加查询个人接口
1 parent 346e39f commit 27edecf

33 files changed

+295
-226
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
.gitignore
3+
src/main/webapp/WEB-INF/views/
4+
src/main/webapp/js/
5+
target/generated-sources/
6+
target/notepad/WEB-INF/classes/com/yjz/notepad/dao/impl/

.idea/workspace.xml

Lines changed: 223 additions & 213 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/controller/BookkeepingController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Map<String, Object> addBookkeepingDate(String as, @RequestBody Bookkeepin
4141

4242
@RequestMapping(value = "/month_list", method = RequestMethod.POST)
4343
@ResponseBody
44-
public Map<String, Object> getUserMonthDate(Long userId, Long bookType, String yearAndMonth) {
44+
public Map<String, Object> getUserMonthDate(Long userId, Long bookType, String yearAndMonth, int currentPage, int pageSize) {
4545
System.out.println("userId = " + userId + " bookType = " + bookType + " monthStr = " + yearAndMonth);
4646
List<UserMonthDate> userMonthDates = service.queryBookkeepingDateByMonth(userId, bookType, yearAndMonth);
4747
HashMap<String, Object> resultMap = new HashMap<>();
@@ -74,10 +74,14 @@ public Map<String, Object> getUserMonthDate(Long userId, Long bookType, String y
7474
resultMap.put("allMonthIn", allMonthIn);
7575
resultMap.put("allMonthOut", allMonthOut);
7676
List<UserDayDate> userDayDates = new ArrayList<>();
77-
for (String exactTime : dataList) {
77+
78+
int length = dataList.size() > currentPage * pageSize ? currentPage * pageSize : dataList.size();
79+
80+
for (int i = currentPage * pageSize - pageSize; i < length; i++) {
81+
String exactTime = dataList.get(i);
7882
float allIn = 0f;
7983
float allOut = 0f;
80-
List<UserBookkeepingBean> userBookkeepingBeans = service.queryAllBookkeeping(userId, bookType, exactTime);
84+
List<UserBookkeepingBean> userBookkeepingBeans = service.queryAllBookkeeping(userId, bookType, exactTime, currentPage, pageSize);
8185
String exactTimes = "";
8286
boolean isChange = true;
8387
for (UserBookkeepingBean userBookkeepingBean : userBookkeepingBeans) {
@@ -96,6 +100,7 @@ public Map<String, Object> getUserMonthDate(Long userId, Long bookType, String y
96100
}
97101
userDayDates.add(new UserDayDate(allIn, allOut, exactTimes, userBookkeepingBeans));
98102
}
103+
99104
resultMap.put("dayData", userDayDates);
100105
return R.ok("请求成功", resultMap);
101106
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.springframework.web.bind.annotation.ResponseBody;
1313

1414
import javax.annotation.Resource;
15+
import javax.ws.rs.GET;
1516
import java.util.ArrayList;
1617
import java.util.Date;
1718
import java.util.HashMap;
@@ -58,6 +59,17 @@ public HashMap<String, Object> add(User user) {
5859
}
5960
}
6061

62+
@RequestMapping(value = "/query", method = RequestMethod.GET)
63+
@ResponseBody
64+
public HashMap<String, Object> query(Long id) {
65+
User user = userService.queryUserById(id);
66+
if (user == null) {
67+
return R.error("该用户不存在");
68+
} else {
69+
return R.ok("查詢成功", user);
70+
}
71+
}
72+
6173
@RequestMapping(value = "/login", method = RequestMethod.POST)
6274
@ResponseBody
6375
public HashMap<String, Object> login(User user) {

src/main/java/com/yjz/notepad/dao/IBookkeepingDao.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ public interface IBookkeepingDao {
3232
List<UserMonthDate> queryBookkeepingDateByMonth(Long userID, Long bookType, String yearAndMonth);
3333

3434
/**
35-
* 查询用户某个月所有的记账记录
35+
* 查询用户某个月某一天所有的记账记录
3636
*
37-
* @param userID 用戶id
37+
* @param userID 用戶id
3838
* @param exactTime 添加的某一天
39-
* @param bookType 记账本类型
39+
* @param bookType 记账本类型
40+
* @param currentPage 当前的页面
41+
* @param pageSize 一页显示多少条
4042
* @return 用户某个月所有的记账记录
4143
*/
42-
List<UserBookkeepingBean> queryAllBookkeeping(Long userID, Long bookType, String exactTime);
44+
List<UserBookkeepingBean> queryAllBookkeeping(Long userID, Long bookType, String exactTime,int currentPage,int pageSize);
4345

4446
}

src/main/java/com/yjz/notepad/dao/IUserDao.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public interface IUserDao {
2424
*/
2525
Long addUserByObject(User user);
2626

27+
/**
28+
* 查询单个用户
29+
*
30+
* @param id 用戶id
31+
* @return userBean
32+
*/
33+
User queryUserById(Long id);
34+
2735
/**
2836
* @param id userID
2937
* @return 成功的状态

src/main/java/com/yjz/notepad/service/IBookkeepingService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ public interface IBookkeepingService {
3838
* @param userID 用戶id
3939
* @param exactTime 添加的某一天
4040
* @param bookType 记账本类型
41+
* @param currentPage 当前的页面
42+
* @param pageSize 一页显示多少条
4143
* @return 用户某个月所有的记账记录
4244
*/
43-
List<UserBookkeepingBean> queryAllBookkeeping(Long userID, Long bookType, String exactTime);
45+
List<UserBookkeepingBean> queryAllBookkeeping(Long userID, Long bookType, String exactTime,int currentPage,int pageSize);
4446

4547
}

src/main/java/com/yjz/notepad/service/IUserService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public interface IUserService {
1414
/**
1515
* @param user user
1616
* @return 插入的主键ID
17-
*
1817
*/
1918
Long addUserByObject(User user);
2019

@@ -24,6 +23,14 @@ public interface IUserService {
2423
*/
2524
int deleteUserById(Long id);
2625

26+
/**
27+
* 查询单个用户
28+
*
29+
* @param id 用戶id
30+
* @return userBean
31+
*/
32+
User queryUserById(Long id);
33+
2734
/**
2835
* 查詢全部
2936
*

src/main/java/com/yjz/notepad/service/impl/BookkeepingServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public List<UserMonthDate> queryBookkeepingDateByMonth(Long userID, Long bookTyp
3232
}
3333

3434
@Override
35-
public List<UserBookkeepingBean> queryAllBookkeeping(Long userID, Long bookType, String exactTime) {
36-
return bookkeepingDao.queryAllBookkeeping(userID, bookType, exactTime);
35+
public List<UserBookkeepingBean> queryAllBookkeeping(Long userID, Long bookType, String exactTime,int currentPage,int pageSize) {
36+
return bookkeepingDao.queryAllBookkeeping(userID, bookType, exactTime,currentPage,pageSize);
3737
}
3838
}

src/main/java/com/yjz/notepad/service/impl/UserServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public int deleteUserById(Long id) {
2929
return userDao.deleteUserById(id);
3030
}
3131

32+
@Override
33+
public User queryUserById(Long id) {
34+
return userDao.queryUserById(id);
35+
}
36+
3237
@Override
3338
public List<User> queryUserAll() {
3439
return userDao.queryUserAll();

0 commit comments

Comments
 (0)