parent
d466e2cf6d
commit
03bf3cd4e6
@ -1,166 +0,0 @@ |
||||
package com.community.pocket.api.android; |
||||
|
||||
import com.community.pocket.entity.po.Forum; |
||||
import com.community.pocket.entity.po.ForumContent; |
||||
import com.community.pocket.entity.po.android.Active; |
||||
import com.community.pocket.entity.po.android.Complain; |
||||
import com.community.pocket.entity.po.android.Token; |
||||
import com.community.pocket.entity.vo.ForumQuery; |
||||
import com.community.pocket.entity.vo.Page; |
||||
import com.community.pocket.entity.vo.Result; |
||||
import com.community.pocket.entity.vo.android.*; |
||||
import com.community.pocket.repository.android.*; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 论坛接口 |
||||
*/ |
||||
//客户端跨域测试
|
||||
@RestController |
||||
public class AndroidForumController { |
||||
|
||||
@Autowired |
||||
private ForumDao forumDao; |
||||
|
||||
@Autowired |
||||
private UserDao userDao; |
||||
|
||||
@Autowired |
||||
private TokenDao tokenDao; |
||||
|
||||
@Autowired |
||||
private ForumContentDao forumContentDao; |
||||
|
||||
@Autowired |
||||
private ActiveDao activeDao; |
||||
|
||||
@Autowired |
||||
private ComplainDao complainDao; |
||||
|
||||
//加载热榜接口
|
||||
@GetMapping("/forum/hot") |
||||
public ForumHotResponse loadHot(Integer num) { |
||||
List<UserHot> userHot = userDao.rankUser(num); |
||||
List<ForumHot> topicHot = forumDao.rankReply(Forum.ForumType.topic, num); |
||||
List<ForumHot> activeHot = forumDao.rankReply(Forum.ForumType.active, num); |
||||
ForumHotResponse response; |
||||
if (userHot != null && topicHot != null && activeHot != null) { |
||||
Hot hot = new Hot(userHot, topicHot, activeHot); |
||||
response = new ForumHotResponse(Result.OK, ForumHotResponse.Msg.ok); |
||||
response.setHot(hot); |
||||
} else { |
||||
response = new ForumHotResponse(Result.FAIL, ForumHotResponse.Msg.fail); |
||||
} |
||||
return response; |
||||
} |
||||
|
||||
//发送活动贴
|
||||
@PostMapping("/forum/sendActive") |
||||
public ForumPostResponse sendActive(ActiveVo activeVo) { |
||||
if (tokenDao.checkToken(activeVo)) { |
||||
Forum forum = forumDao.save(activeVo); |
||||
if (forum != null) { |
||||
ForumContent forumContent = forumContentDao.save(activeVo, forum); |
||||
Active active = activeDao.save(activeVo, forum); |
||||
if (forumContent != null && active != null) { |
||||
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); |
||||
} |
||||
} |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); |
||||
} else { |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); |
||||
} |
||||
} |
||||
|
||||
//发送动态贴
|
||||
@PostMapping("/forum/sendTopic") |
||||
public ForumPostResponse sendTopic(ForumVo forumVo) { |
||||
if (tokenDao.checkToken(forumVo)) { |
||||
Forum forum = forumDao.save(forumVo); |
||||
if (forum != null) { |
||||
ForumContent forumContent = forumContentDao.save(forumVo, forum); |
||||
if (forumContent != null) { |
||||
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); |
||||
} |
||||
} |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); |
||||
} else { |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); |
||||
} |
||||
} |
||||
|
||||
//发送投诉贴
|
||||
@PostMapping("/forum/sendComplain") |
||||
public ForumPostResponse sendComplain(ComplainVo complainVo) { |
||||
if (tokenDao.checkToken(complainVo)) { |
||||
Forum forum = forumDao.save(complainVo); |
||||
if (forum != null) { |
||||
ForumContent forumContent = forumContentDao.save(complainVo, forum); |
||||
Complain complain = complainDao.save(complainVo, forum); |
||||
if (forumContent != null && complain != null) { |
||||
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); |
||||
} |
||||
} |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); |
||||
} else { |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 加载我的帖子 |
||||
*/ |
||||
@GetMapping("/forum/my") |
||||
public ForumMyResponse loadForumMy(ForumQuery forumQuery) { |
||||
Page<ForumDto> forumList = forumDao.loadForum(forumQuery); |
||||
ForumMyResponse response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok); |
||||
response.setForumList(forumList); |
||||
return response; |
||||
|
||||
} |
||||
|
||||
//获取个人信息
|
||||
@GetMapping("/my/info") |
||||
public InfoResponse loadInfo(Token token) { |
||||
if (tokenDao.checkToken(token)) { |
||||
Info myInfo = userDao.queryUser(token.getUsername()); |
||||
if (myInfo != null) { |
||||
InfoResponse response = new InfoResponse(Result.OK, InfoResponse.Msg.ok); |
||||
response.setMyInfo(myInfo); |
||||
return response; |
||||
} else { |
||||
return new InfoResponse(Result.FAIL, InfoResponse.Msg.fail); |
||||
} |
||||
} else { |
||||
return new InfoResponse(Result.FAIL, InfoResponse.Msg.token); |
||||
} |
||||
} |
||||
|
||||
//获取帖子详情数据
|
||||
@GetMapping("/forum/content") |
||||
public ForumDataResponse loadData(QueryForum queryForum) { |
||||
List<ForumContentVo> forumContents = forumContentDao.find(queryForum); |
||||
ForumDataResponse response = new ForumDataResponse(Result.OK, ForumDataResponse.Msg.ok); |
||||
response.setForumContentList(forumContents); |
||||
return response; |
||||
} |
||||
|
||||
//回帖
|
||||
@PostMapping("/forum/content/reply") |
||||
public ForumDataResponse sendReply(ForumReplyForm replyForm) { |
||||
if (tokenDao.checkToken(replyForm)) { |
||||
if (forumContentDao.save(replyForm) != null && forumDao.update(replyForm)) { |
||||
return new ForumDataResponse(Result.OK, ForumDataResponse.Msg.reply_ok); |
||||
} else { |
||||
return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.reply_fail); |
||||
} |
||||
} else { |
||||
return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.token); |
||||
} |
||||
} |
||||
} |
@ -1,84 +0,0 @@ |
||||
package com.community.pocket.api.android; |
||||
|
||||
import com.community.pocket.entity.po.Visitor; |
||||
import com.community.pocket.entity.po.android.VisitorPeople; |
||||
import com.community.pocket.entity.vo.Result; |
||||
import com.community.pocket.entity.vo.android.*; |
||||
import com.community.pocket.repository.android.TokenDao; |
||||
import com.community.pocket.repository.android.VisitorDao; |
||||
import com.community.pocket.repository.android.VisitorPeopleDao; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 访客接口 |
||||
*/ |
||||
@RestController |
||||
public class AndroidVisitorController { |
||||
|
||||
@Autowired |
||||
private VisitorDao visitorDao; |
||||
|
||||
@Autowired |
||||
private VisitorPeopleDao visitorPeopleDao; |
||||
|
||||
@Autowired |
||||
private TokenDao tokenDao; |
||||
|
||||
//访客预约
|
||||
@PostMapping("/visitor/visitor") |
||||
public VisitorResponse appointment(VisitorForm visitorForm) { |
||||
if (tokenDao.checkToken(visitorForm)) { |
||||
if (visitorDao.save(visitorForm) != null) { |
||||
return new VisitorResponse(Result.OK, VisitorResponse.Msg.ok); |
||||
} else { |
||||
return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.fail); |
||||
} |
||||
} else { |
||||
return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.token); |
||||
} |
||||
} |
||||
|
||||
//获取预约人
|
||||
@GetMapping("/visitor/people") |
||||
public VisitorPeopleResponse searchPeople(QueryVisitorPeople visitorPeople) { |
||||
List<VisitorPeople> visitorPeopleList = visitorPeopleDao.loadAll(visitorPeople); |
||||
VisitorPeopleResponse response = new VisitorPeopleResponse(Result.OK, VisitorPeopleResponse.Msg.ok); |
||||
response.setVisitorPeopleList(visitorPeopleList); |
||||
return response; |
||||
} |
||||
|
||||
/** |
||||
* 我的预约 |
||||
*/ |
||||
@GetMapping("/visitor/reservation") |
||||
public VisitorReservationResponse loadReservation(VisitorQuery query) { |
||||
if (tokenDao.checkToken(query)) { |
||||
List<Visitor> visitorList = visitorDao.loadMyReservation(query); |
||||
VisitorReservationResponse response = new VisitorReservationResponse(Result.OK, VisitorReservationResponse.Msg.ok); |
||||
response.setVisitorList(visitorList); |
||||
return response; |
||||
} else { |
||||
return new VisitorReservationResponse(Result.FAIL, VisitorReservationResponse.Msg.fail); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 加载我的访客 |
||||
*/ |
||||
@GetMapping("/visitor/my") |
||||
public VisitorMyResponse loadMy(VisitorQuery query) { |
||||
if (tokenDao.checkToken(query)) { |
||||
List<Visitor> visitorList = visitorDao.loadMyVisitor(query); |
||||
VisitorMyResponse response = new VisitorMyResponse(Result.OK, VisitorMyResponse.Msg.ok); |
||||
response.setVisitorList(visitorList); |
||||
return response; |
||||
} else { |
||||
return new VisitorMyResponse(Result.FAIL, VisitorMyResponse.Msg.fail); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,227 @@ |
||||
package com.community.pocket.api.android; |
||||
|
||||
import com.community.pocket.entity.po.Forum; |
||||
import com.community.pocket.entity.po.ForumContent; |
||||
import com.community.pocket.entity.po.android.Active; |
||||
import com.community.pocket.entity.po.android.Complain; |
||||
import com.community.pocket.entity.po.android.Score; |
||||
import com.community.pocket.entity.po.android.Token; |
||||
import com.community.pocket.entity.vo.ForumQuery; |
||||
import com.community.pocket.entity.vo.Page; |
||||
import com.community.pocket.entity.vo.Result; |
||||
import com.community.pocket.entity.vo.android.*; |
||||
import com.community.pocket.repository.android.*; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 论坛接口 |
||||
*/ |
||||
//客户端跨域测试
|
||||
@RestController |
||||
public class ForumController { |
||||
|
||||
@Autowired |
||||
private ForumDao forumDao; |
||||
|
||||
@Autowired |
||||
private UserDao userDao; |
||||
|
||||
@Autowired |
||||
private TokenService tokenService; |
||||
|
||||
@Autowired |
||||
private ForumContentDao forumContentDao; |
||||
|
||||
@Autowired |
||||
private ActiveDao activeDao; |
||||
|
||||
@Autowired |
||||
private ComplainDao complainDao; |
||||
|
||||
@Autowired |
||||
private ScoreDao scoreDao; |
||||
|
||||
//加载热榜接口
|
||||
@GetMapping("/forum/hot") |
||||
public ForumHotResponse loadHot(Integer num) { |
||||
List<UserHot> userHot = userDao.rankUser(num); |
||||
List<ForumHot> topicHot = forumDao.rankReply(Forum.ForumType.topic, num); |
||||
List<ForumHot> activeHot = forumDao.rankReply(Forum.ForumType.active, num); |
||||
ForumHotResponse response; |
||||
if (userHot != null && topicHot != null && activeHot != null) { |
||||
Hot hot = new Hot(userHot, topicHot, activeHot); |
||||
response = new ForumHotResponse(Result.OK, ForumHotResponse.Msg.ok); |
||||
response.setHot(hot); |
||||
} else { |
||||
response = new ForumHotResponse(Result.FAIL, ForumHotResponse.Msg.fail); |
||||
} |
||||
return response; |
||||
} |
||||
|
||||
//发送活动贴
|
||||
@PostMapping("/forum/sendActive") |
||||
public ForumPostResponse sendActive(ActiveVo activeVo) { |
||||
return tokenService.checkToken(activeVo, new DoCheck<ForumPostResponse, ActiveVo>() { |
||||
@Override |
||||
public ForumPostResponse ok(ActiveVo activeVo) { |
||||
Forum forum = forumDao.save(activeVo); |
||||
if (forum != null) { |
||||
ForumContent forumContent = forumContentDao.save(activeVo, forum); |
||||
Active active = activeDao.save(activeVo, forum); |
||||
if (forumContent != null && active != null) { |
||||
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); |
||||
} |
||||
} |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); |
||||
} |
||||
|
||||
@Override |
||||
public ForumPostResponse fail() { |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
//发送动态贴
|
||||
@PostMapping("/forum/sendTopic") |
||||
public ForumPostResponse sendTopic(ForumVo forumVo) { |
||||
return tokenService.checkToken(forumVo, new DoCheck<ForumPostResponse, ForumVo>() { |
||||
@Override |
||||
public ForumPostResponse ok(ForumVo forumVo) { |
||||
Forum forum = forumDao.save(forumVo); |
||||
if (forum != null) { |
||||
ForumContent forumContent = forumContentDao.save(forumVo, forum); |
||||
if (forumContent != null) { |
||||
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); |
||||
} |
||||
} |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); |
||||
} |
||||
|
||||
@Override |
||||
public ForumPostResponse fail() { |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
//发送结算贴
|
||||
@PostMapping("/forum/sendScore") |
||||
public ForumPostResponse sendScore(ForumScoreVo scoreVo) { |
||||
return tokenService.checkToken(scoreVo, new DoCheck<ForumPostResponse, ForumScoreVo>() { |
||||
@Override |
||||
public ForumPostResponse ok(ForumScoreVo forumVo) { |
||||
Forum forum = forumDao.save(forumVo); |
||||
if (forum != null) { |
||||
ForumContent forumContent = forumContentDao.save(forumVo, forum); |
||||
Score score = scoreDao.save(scoreVo, forum); |
||||
if (forumContent != null && score != null) { |
||||
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); |
||||
} |
||||
} |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); |
||||
} |
||||
|
||||
@Override |
||||
public ForumPostResponse fail() { |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
//发送投诉贴
|
||||
@PostMapping("/forum/sendComplain") |
||||
public ForumPostResponse sendComplain(ComplainVo complainVo) { |
||||
return tokenService.checkToken(complainVo, new DoCheck<ForumPostResponse, ComplainVo>() { |
||||
@Override |
||||
public ForumPostResponse ok(ComplainVo complainVo) { |
||||
Forum forum = forumDao.save(complainVo); |
||||
if (forum != null) { |
||||
ForumContent forumContent = forumContentDao.save(complainVo, forum); |
||||
Complain complain = complainDao.save(complainVo, forum); |
||||
if (forumContent != null && complain != null) { |
||||
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); |
||||
} |
||||
} |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail); |
||||
} |
||||
|
||||
@Override |
||||
public ForumPostResponse fail() { |
||||
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 加载我的帖子 |
||||
*/ |
||||
@GetMapping("/forum/my") |
||||
public ForumMyResponse loadForumMy(ForumQuery forumQuery) { |
||||
Page<ForumDto> forumList = forumDao.loadForum(forumQuery); |
||||
ForumMyResponse response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok); |
||||
response.setForumList(forumList); |
||||
return response; |
||||
|
||||
} |
||||
|
||||
//获取个人信息
|
||||
@GetMapping("/my/info") |
||||
public InfoResponse loadInfo(Token token) { |
||||
return tokenService.checkToken(token, new DoCheck<InfoResponse, Token>() { |
||||
@Override |
||||
public InfoResponse ok(Token token) { |
||||
Info myInfo = userDao.queryUser(token.getUsername()); |
||||
if (myInfo != null) { |
||||
InfoResponse response = new InfoResponse(Result.OK, InfoResponse.Msg.ok); |
||||
response.setMyInfo(myInfo); |
||||
return response; |
||||
} else { |
||||
return new InfoResponse(Result.FAIL, InfoResponse.Msg.fail); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public InfoResponse fail() { |
||||
return new InfoResponse(Result.FAIL, InfoResponse.Msg.token); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
//获取帖子详情数据
|
||||
@GetMapping("/forum/content") |
||||
public ForumDataResponse loadData(QueryForum queryForum) { |
||||
ForumDto forumDto = forumDao.loadForum(queryForum); |
||||
List<ForumContentVo> forumContents = forumContentDao.find(queryForum); |
||||
ForumDataResponse response = new ForumDataResponse(Result.OK, ForumDataResponse.Msg.ok); |
||||
response.setForumContentList(forumContents); |
||||
response.setForumDto(forumDto); |
||||
return response; |
||||
} |
||||
|
||||
//回帖
|
||||
@PostMapping("/forum/content/reply") |
||||
public ForumDataResponse sendReply(ForumReplyForm replyForm) { |
||||
return tokenService.checkToken(replyForm, new DoCheck<ForumDataResponse, ForumReplyForm>() { |
||||
@Override |
||||
public ForumDataResponse ok(ForumReplyForm forumReplyForm) { |
||||
if (forumContentDao.save(replyForm) != null && forumDao.update(replyForm)) { |
||||
return new ForumDataResponse(Result.OK, ForumDataResponse.Msg.reply_ok); |
||||
} else { |
||||
return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.reply_fail); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public ForumDataResponse fail() { |
||||
return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.token); |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,108 @@ |
||||
package com.community.pocket.api.android; |
||||
|
||||
import com.community.pocket.entity.po.Visitor; |
||||
import com.community.pocket.entity.po.android.VisitorPeople; |
||||
import com.community.pocket.entity.vo.Result; |
||||
import com.community.pocket.entity.vo.android.*; |
||||
import com.community.pocket.repository.android.DoCheck; |
||||
import com.community.pocket.repository.android.TokenService; |
||||
import com.community.pocket.repository.android.VisitorDao; |
||||
import com.community.pocket.repository.android.VisitorPeopleDao; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 访客接口 |
||||
*/ |
||||
@RestController |
||||
public class VisitorController { |
||||
|
||||
@Autowired |
||||
private VisitorDao visitorDao; |
||||
|
||||
@Autowired |
||||
private VisitorPeopleDao visitorPeopleDao; |
||||
|
||||
@Autowired |
||||
private TokenService tokenService; |
||||
|
||||
//访客预约
|
||||
@PostMapping("/visitor/visitor") |
||||
public VisitorResponse appointment(VisitorForm visitorForm) { |
||||
return tokenService.checkToken(visitorForm, new DoCheck<VisitorResponse, VisitorForm>() { |
||||
@Override |
||||
public VisitorResponse ok(VisitorForm visitorForm) { |
||||
if (visitorDao.save(visitorForm) != null) { |
||||
return new VisitorResponse(Result.OK, VisitorResponse.Msg.ok); |
||||
} else { |
||||
return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.fail); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public VisitorResponse fail() { |
||||
return new VisitorResponse(Result.FAIL, VisitorResponse.Msg.token); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
//获取预约人
|
||||
@GetMapping("/visitor/people") |
||||
public VisitorPeopleResponse searchPeople(QueryVisitorPeople visitorPeople) { |
||||
List<VisitorPeople> visitorPeopleList = visitorPeopleDao.loadAll(visitorPeople); |
||||
VisitorPeopleResponse response; |
||||
if (visitorPeopleList.isEmpty()) { |
||||
response = new VisitorPeopleResponse(Result.OK, VisitorPeopleResponse.Msg.ok_empty); |
||||
} else { |
||||
response = new VisitorPeopleResponse(Result.OK, VisitorPeopleResponse.Msg.ok); |
||||
} |
||||
response.setVisitorPeopleList(visitorPeopleList); |
||||
return response; |
||||
} |
||||
|
||||
/** |
||||
* 我的预约 |
||||
*/ |
||||
@GetMapping("/visitor/reservation") |
||||
public VisitorReservationResponse loadReservation(VisitorQuery query) { |
||||
return tokenService.checkToken(query, new DoCheck<VisitorReservationResponse, VisitorQuery>() { |
||||
@Override |
||||
public VisitorReservationResponse ok(VisitorQuery visitorQuery) { |
||||
List<Visitor> visitorList = visitorDao.loadMyReservation(query); |
||||
VisitorReservationResponse response = new VisitorReservationResponse(Result.OK, VisitorReservationResponse.Msg.ok); |
||||
response.setVisitorList(visitorList); |
||||
return response; |
||||
} |
||||
|
||||
@Override |
||||
public VisitorReservationResponse fail() { |
||||
return new VisitorReservationResponse(Result.FAIL, VisitorReservationResponse.Msg.token); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 加载我的访客 |
||||
*/ |
||||
@GetMapping("/visitor/my") |
||||
public VisitorMyResponse loadMy(VisitorQuery query) { |
||||
return tokenService.checkToken(query, new DoCheck<VisitorMyResponse, VisitorQuery>() { |
||||
@Override |
||||
public VisitorMyResponse ok(VisitorQuery visitorQuery) { |
||||
List<Visitor> visitorList = visitorDao.loadMyVisitor(query); |
||||
VisitorMyResponse response = new VisitorMyResponse(Result.OK, VisitorMyResponse.Msg.ok); |
||||
response.setVisitorList(visitorList); |
||||
return response; |
||||
} |
||||
|
||||
@Override |
||||
public VisitorMyResponse fail() { |
||||
return new VisitorMyResponse(Result.FAIL, VisitorMyResponse.Msg.token); |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,44 @@ |
||||
package com.community.pocket.api.web; |
||||
|
||||
import com.community.pocket.entity.po.android.MyInfo; |
||||
import com.community.pocket.entity.vo.Page; |
||||
import com.community.pocket.entity.vo.Result; |
||||
import com.community.pocket.entity.vo.android.QueryUserForm; |
||||
import com.community.pocket.entity.vo.web.EditScore; |
||||
import com.community.pocket.entity.vo.web.UserResponse; |
||||
import com.community.pocket.repository.android.UserDao; |
||||
import com.community.pocket.util.BeanUtil; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* web用户接口 |
||||
*/ |
||||
@RestController(BeanUtil.userName) |
||||
public class UserController { |
||||
|
||||
@Autowired |
||||
private UserDao userDao; |
||||
|
||||
//查询用户信息
|
||||
@GetMapping("/api/users") |
||||
public UserResponse loadAll(QueryUserForm queryUserForm) { |
||||
Page<MyInfo> infos = userDao.loadAll(queryUserForm); |
||||
UserResponse response = new UserResponse(Result.OK, UserResponse.Msg.ok); |
||||
response.setMyInfos(infos); |
||||
return response; |
||||
} |
||||
|
||||
//修改信用分
|
||||
@PostMapping("/api/users/score") |
||||
public UserResponse editScore(@RequestBody EditScore editScore) { |
||||
if (userDao.updateScore(editScore)) { |
||||
return new UserResponse(Result.OK, UserResponse.Msg.edit_ok); |
||||
} else { |
||||
return new UserResponse(Result.FAIL, UserResponse.Msg.edit_fail); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
package com.community.pocket.entity.po; |
||||
|
||||
import com.community.pocket.util.TableName; |
||||
import org.springframework.data.mongodb.core.mapping.Document; |
||||
|
||||
//信用分历史记录
|
||||
@Document(TableName.creditScore) |
||||
public class CreditScore { |
||||
//用户名
|
||||
private String username; |
||||
//信用分变化
|
||||
private Integer score; |
||||
//变化前分数
|
||||
private Integer beforeScore; |
||||
//备注
|
||||
private String notes; |
||||
//记录时间
|
||||
private Long time; |
||||
|
||||
public String getUsername() { |
||||
return username; |
||||
} |
||||
|
||||
public void setUsername(String username) { |
||||
this.username = username; |
||||
} |
||||
|
||||
public Integer getScore() { |
||||
return score; |
||||
} |
||||
|
||||
public void setScore(Integer score) { |
||||
this.score = score; |
||||
} |
||||
|
||||
public Integer getBeforeScore() { |
||||
return beforeScore; |
||||
} |
||||
|
||||
public void setBeforeScore(Integer beforeScore) { |
||||
this.beforeScore = beforeScore; |
||||
} |
||||
|
||||
public void setTime(Long time) { |
||||
this.time = time; |
||||
} |
||||
|
||||
public Long getTime() { |
||||
return time; |
||||
} |
||||
|
||||
public String getNotes() { |
||||
return notes; |
||||
} |
||||
|
||||
public void setNotes(String notes) { |
||||
this.notes = notes; |
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
package com.community.pocket.entity.po.android; |
||||
|
||||
import com.community.pocket.util.TableName; |
||||
import org.springframework.data.mongodb.core.mapping.Document; |
||||
|
||||
/** |
||||
* 结算贴 |
||||
*/ |
||||
@Document(TableName.score) |
||||
public class Score { |
||||
private String id; |
||||
//结算分数
|
||||
private Integer activeScore; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public Integer getActiveScore() { |
||||
return activeScore; |
||||
} |
||||
|
||||
public void setActiveScore(Integer activeScore) { |
||||
this.activeScore = activeScore; |
||||
} |
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.community.pocket.entity.vo.android; |
||||
|
||||
/** |
||||
* 结算贴表单 |
||||
*/ |
||||
public class ForumScoreVo extends ForumVo { |
||||
private Integer activeScore; |
||||
|
||||
public Integer getActiveScore() { |
||||
return activeScore; |
||||
} |
||||
|
||||
public void setActiveScore(Integer activeScore) { |
||||
this.activeScore = activeScore; |
||||
} |
||||
} |
@ -0,0 +1,47 @@ |
||||
package com.community.pocket.entity.vo.web; |
||||
|
||||
/** |
||||
* 修改信用分表单 |
||||
*/ |
||||
public class EditScore { |
||||
//用户名
|
||||
private String username; |
||||
//加减分数
|
||||
private Integer score; |
||||
//变化前分数
|
||||
private Integer beforeScore; |
||||
//备注信息
|
||||
private String notes; |
||||
|
||||
public String getUsername() { |
||||
return username; |
||||
} |
||||
|
||||
public void setUsername(String username) { |
||||
this.username = username; |
||||
} |
||||
|
||||
public Integer getScore() { |
||||
return score; |
||||
} |
||||
|
||||
public void setScore(Integer score) { |
||||
this.score = score; |
||||
} |
||||
|
||||
public String getNotes() { |
||||
return notes; |
||||
} |
||||
|
||||
public void setNotes(String notes) { |
||||
this.notes = notes; |
||||
} |
||||
|
||||
public Integer getBeforeScore() { |
||||
return beforeScore; |
||||
} |
||||
|
||||
public void setBeforeScore(Integer beforeScore) { |
||||
this.beforeScore = beforeScore; |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
package com.community.pocket.entity.vo.web; |
||||
|
||||
import com.community.pocket.entity.po.android.MyInfo; |
||||
import com.community.pocket.entity.vo.Page; |
||||
import com.community.pocket.entity.vo.Response; |
||||
import com.community.pocket.entity.vo.Result; |
||||
import com.community.pocket.entity.vo.android.CustomMessage; |
||||
|
||||
public class UserResponse extends Response<UserResponse.Msg> { |
||||
|
||||
private Page<MyInfo> myInfos; |
||||
|
||||
public UserResponse(Result result, Msg message, Object... args) { |
||||
super(result, message, args); |
||||
} |
||||
|
||||
public Page<MyInfo> getMyInfos() { |
||||
return myInfos; |
||||
} |
||||
|
||||
public void setMyInfos(Page<MyInfo> myInfos) { |
||||
this.myInfos = myInfos; |
||||
} |
||||
|
||||
public enum Msg implements CustomMessage { |
||||
//查询成功
|
||||
ok, |
||||
//查询失败
|
||||
fail, |
||||
//修改成功
|
||||
edit_ok, |
||||
//修改失败
|
||||
edit_fail |
||||
} |
||||
} |
@ -0,0 +1,21 @@ |
||||
package com.community.pocket.repository; |
||||
|
||||
import com.community.pocket.entity.po.CreditScore; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
/** |
||||
* 信用分 |
||||
*/ |
||||
@Repository |
||||
public class CreditScoreDao extends BaseDao<CreditScore> { |
||||
|
||||
@Override |
||||
public CreditScore save(CreditScore creditScore) { |
||||
return mongoTemplate.save(creditScore); |
||||
} |
||||
|
||||
@Override |
||||
public Class<CreditScore> entityClass() { |
||||
return CreditScore.class; |
||||
} |
||||
} |
@ -0,0 +1,13 @@ |
||||
package com.community.pocket.repository.android; |
||||
|
||||
import com.community.pocket.entity.po.android.Token; |
||||
|
||||
//令牌校验
|
||||
public interface DoCheck<T, E extends Token> { |
||||
|
||||
//校验成功
|
||||
T ok(E e); |
||||
|
||||
//校验失败
|
||||
T fail(); |
||||
} |
@ -0,0 +1,39 @@ |
||||
package com.community.pocket.repository.android; |
||||
|
||||
import com.community.pocket.entity.po.Forum; |
||||
import com.community.pocket.entity.po.android.Score; |
||||
import com.community.pocket.entity.vo.android.ForumScoreVo; |
||||
import com.community.pocket.repository.BaseDao; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
@Repository |
||||
public class ScoreDao extends BaseDao<Score> { |
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ScoreDao.class); |
||||
|
||||
//保存结算贴
|
||||
public Score save(ForumScoreVo scoreVo, Forum forum) { |
||||
Score score = new Score(); |
||||
score.setId(forum.getId()); |
||||
score.setActiveScore(scoreVo.getActiveScore()); |
||||
return save(score); |
||||
} |
||||
|
||||
@Override |
||||
public Score save(Score score) { |
||||
try { |
||||
return mongoTemplate.save(score); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
LOG.error(e.toString()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public Class<Score> entityClass() { |
||||
return Score.class; |
||||
} |
||||
} |
@ -0,0 +1,25 @@ |
||||
package com.community.pocket.repository.android; |
||||
|
||||
import com.community.pocket.entity.po.android.Token; |
||||
import com.community.pocket.entity.vo.Response; |
||||
import com.community.pocket.entity.vo.android.CustomMessage; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* 令牌校验 |
||||
*/ |
||||
@Service |
||||
public class TokenService { |
||||
|
||||
@Autowired |
||||
private TokenDao tokenDao; |
||||
|
||||
public <T extends Response<F>, E extends Token, F extends CustomMessage> T checkToken(E e, DoCheck<T, E> doCheck) { |
||||
if (tokenDao.checkToken(e)) { |
||||
return doCheck.ok(e); |
||||
} else { |
||||
return doCheck.fail(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,14 @@ |
||||
package com.community.pocket.util; |
||||
|
||||
//解决bean命名冲突
|
||||
public class BeanUtil { |
||||
private static final String webPrefix = "web"; |
||||
|
||||
//web Controller bean重命名,防止同名类默认bean命名冲突
|
||||
//论坛Controller bean name
|
||||
public static final String forumName = webPrefix + "forum"; |
||||
//访客Controller bean name
|
||||
public static final String visitorName = webPrefix + "visitor"; |
||||
//用户Controller bean name
|
||||
public static final String userName = webPrefix + "user"; |
||||
} |
@ -0,0 +1,28 @@ |
||||
package com.community.pocket.util; |
||||
|
||||
import org.springframework.data.mongodb.core.aggregation.LookupOperation; |
||||
|
||||
public class LookupOperationUtil { |
||||
//活动贴
|
||||
//关联帖子外键属性
|
||||
public static final String idKey = "_id"; |
||||
//定义管道操作
|
||||
private static final String activeKey = "activeDto"; |
||||
//关联
|
||||
public static final LookupOperation activeforumLookup = LookupOperation.newLookup().from(TableName.active).localField(idKey).foreignField(idKey).as(activeKey); |
||||
//投诉贴
|
||||
//关联属性
|
||||
private static final String complainKey = "complainDto"; |
||||
//定义管道操作
|
||||
public static final LookupOperation complainforumLookup = LookupOperation.newLookup().from(TableName.complain).localField(idKey).foreignField(idKey).as(complainKey); |
||||
//结算贴
|
||||
private static final String scoreKey = "score"; |
||||
//定义管道操作
|
||||
public static final LookupOperation scoreforumLookup = LookupOperation.newLookup().from(TableName.score).localField(idKey).foreignField(idKey).as(scoreKey); |
||||
//关联属性
|
||||
private static final String infoKey = "info"; |
||||
//关联用户外键属性
|
||||
private static final String usernameKey = "username"; |
||||
//定义管道操作
|
||||
public static final LookupOperation infoLookup = LookupOperation.newLookup().from(TableName.info).localField(usernameKey).foreignField(idKey).as(infoKey); |
||||
} |
@ -0,0 +1,39 @@ |
||||
package com.community.pocket; |
||||
|
||||
import com.community.pocket.entity.po.android.Token; |
||||
import com.community.pocket.repository.BaseDao; |
||||
import com.community.pocket.util.LookupOperationUtil; |
||||
import org.apache.commons.lang3.RandomUtils; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.data.mongodb.core.query.Criteria; |
||||
import org.springframework.data.mongodb.core.query.Query; |
||||
import org.springframework.data.mongodb.core.query.Update; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
import java.util.List; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
//测试令牌
|
||||
@Repository |
||||
public class TestTokenDao extends BaseDao<Token> { |
||||
|
||||
@Value("${token.day}") |
||||
private int day; |
||||
|
||||
public Token loadToken() { |
||||
List<Token> tokenList = mongoTemplate.findAll(entityClass()); |
||||
Token token = tokenList.get(RandomUtils.nextInt(0, tokenList.size() - 1)); |
||||
mongoTemplate.updateFirst(new Query(Criteria.where(LookupOperationUtil.idKey).is(token.getToken())), Update.update("time", System.currentTimeMillis() + TimeUnit.DAYS.toMillis(day)), entityClass()); |
||||
return mongoTemplate.findById(token.getToken(), entityClass()); |
||||
} |
||||
|
||||
@Override |
||||
public Token save(Token token) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public Class<Token> entityClass() { |
||||
return Token.class; |
||||
} |
||||
} |
Loading…
Reference in new issue