目录
1:圈子
1.1:发布动态
1.1.1:接口分析
接口:http://192.168.136.160:3000/project/19/interface/api/154
1.1.2:流程分析
发布动态:动态发布存入动态表中,在朋友表中查找自己的朋友,在将动态id及相关信息标记自己信息,方便朋友登录时可查看好友动态发现朋友动态
1.1.2:代码实现
与前端交互的app-server模块
controller层实现
@PostMapping
public ResponseEntity fabudongtai(@RequestParam("imageContent") List<MultipartFile> imageContent,PostUpdateVo postUpdateVo){
movementService.fabudongtai(imageContent,postUpdateVo,UserHolder.getUserId(),UserHolder.getMobile());
return ResponseEntity.ok(null);
}
service层实现
public void fabudongtai(List<MultipartFile> imageContent, PostUpdateVo postUpdateVo, Long userId, String mobile) {
for (MultipartFile multipartFile : imageContent) {
String upload = ossTemplate.upload(multipartFile);
System.out.println(upload);
postUpdateVo.getImages().add(upload);
}
movementApi.fabudongtai(postUpdateVo,userId,mobile);
}
统一封装接口的模块
void fabudongtai(PostUpdateVo postUpdateVo, Long userId, String mobile);
提供者模块(提供相关接口的实现)
mongo提供者:
@Override
public void fabudongtai(PostUpdateVo postUpdateVo, Long userId, String mobile) {
//保存动态到mongo动态表中
Movement movement = new Movement();
Long movement1 = idWorker.getNextId("movement");
movement.setPid(movement1);
movement.setUserId(userId);
movement.setTextContent(postUpdateVo.getTextContent());
movement.setMedias(postUpdateVo.getImages().toArray(new String[0]));
movement.setState(0);
movement.setLongitude(Double.valueOf(postUpdateVo.getLongitude()));
movement.setLatitude(Double.valueOf(postUpdateVo.getLatitude()));
movement.setLocationName(postUpdateVo.getLocation());
movement.setCreated(new Date().getTime());
//保存动态表
Movement save = mongoTemplate.save(movement);
//查询好友列表
//构建条件
Query query = new Query();
Criteria criteria = Criteria.where("userId").is(userId);
query.addCriteria(criteria);
List<Friend> friends = mongoTemplate.find(query, Friend.class);
//保存时间线数据
for (Friend friend : friends) {
MovementTimeline movementTimeline = new MovementTimeline(save.getCreated(),friend.getFriendId(),save.getId(),save.getUserId());
mongoTemplate.save(movementTimeline);
}
//处理结束
}
1.2:我的动态
1.2.1:接口分析
接口地址:http://192.168.136.160:3000/project/19/interface/api/142
1.2.2:流程分析
根据自己的id到数据库中找到动态所属的用户id一致即可。
1.2.3:代码实现
与前端交互的app-server模块
controller层实现
@GetMapping("/all")
public ResponseEntity findmovements(PublicPageVo publicPageVo){
ResultList resultList = movementService.findmovements(UserHolder.getUserId(),publicPageVo);
return ResponseEntity.ok(resultList);
}
service层实现
public ResultList findmovements(Long userId, PublicPageVo publicPageVo) {
ResultList findmovements = movementApi.findmovements(userId,publicPageVo);
return findmovements;
}
统一封装接口的模块
public ResultList findmovements(Long userid, PublicPageVo publicPageVo);
mongo提供者模块(提供相关接口的实现)
@Override
public ResultList findmovements(Long userid, PublicPageVo publicPageVo) {
//创建封装信息类
ResultList resultList = new ResultList();
Query query = new Query();
//查询用户详情信息
UserInfo userInfo = userInfoMapper.selectById(userid);
Criteria criteria = Criteria.where("userId").is(userid);
long count = mongoTemplate.count(query, Movement.class);
query.addCriteria(criteria).skip((publicPageVo.getPage()-1)* publicPageVo.getPagesize()).limit(publicPageVo.getPagesize().intValue());
query.with(Sort.by(Sort.Order.desc("created")));
List<Movement> movements = mongoTemplate.find(query, Movement.class);
ArrayList<MovementVo> movementVos = new ArrayList<>();
for (Movement movement : movements) {
//创建封装类
MovementVo movementVo = new MovementVo(movement.getId().toString(),
userInfo.getId(),userInfo.getAvatar(),userInfo.getNickname(),userInfo.getGender(),userInfo.getAge(),
userInfo.getTags().split(","),movement.getTextContent(),movement.getMedias(),"",movement.getCreated().toString()
,movement.getLikeCount(),movement.getCommentCount(),movement.getLoveCount(),0,0);
movementVos.add(movementVo);
}
//设置列表
resultList.setItems(movementVos);
//设置当前页码
resultList.setPage(publicPageVo.getPage().intValue());
//设置总记录数
resultList.setCounts((int) count);
//设置页大小
resultList.setPagesize(publicPageVo.getPagesize().intValue());
//设置总页数
resultList.setPages((int) (count%publicPageVo.getPagesize() == 0 ? count/ publicPageVo.getPagesize():(count/ publicPageVo.getPagesize())+1));
return resultList;
}