use of com.ch999.haha.admin.entity.AdoptionRequest in project haha by hahafreeasair666.
the class AdoptionRequestServiceImpl method addAdoptionRequest.
@Override
public Boolean addAdoptionRequest(Integer id, Integer userId) {
// 先校验是否申请过
Wrapper<AdoptionRequest> wrapper = new EntityWrapper<>();
wrapper.eq("newsid", id).eq("userid", userId);
if (CollectionUtils.isNotEmpty(this.selectList(wrapper))) {
return false;
}
// 由于前一步已经验证了能否领养,这一步就直接存到领养请求表里面
AdoptionRequest AdoptionRequest = new AdoptionRequest(id, userId);
return this.insert(AdoptionRequest);
}
use of com.ch999.haha.admin.entity.AdoptionRequest in project haha by hahafreeasair666.
the class AdoptionRequestServiceImpl method getMyAdoptionList.
@Override
public PageVO<MyAdoptionVO> getMyAdoptionList(Integer userId, Integer currentPage) {
Integer size = 10;
Wrapper<AdoptionRequest> wrapper = new EntityWrapper<>();
wrapper.eq("userid", userId);
List<MyAdoptionVO> list = new ArrayList<>();
List<AdoptionRequest> adoptionRequests = this.selectList(wrapper);
PageVO<MyAdoptionVO> pageVO = new PageVO<>();
pageVO.setTotalPage((int) Math.ceil(adoptionRequests.size() / (double) size));
pageVO.setCurrentPage(currentPage);
if (CollectionUtils.isNotEmpty(adoptionRequests)) {
if (adoptionRequests.size() > size * (currentPage - 1)) {
adoptionRequests = adoptionRequests.subList(size * (currentPage - 1), size * currentPage > adoptionRequests.size() ? adoptionRequests.size() : size * currentPage);
} else {
adoptionRequests = new ArrayList<>();
}
adoptionRequests.forEach(li -> {
News news = newsService.selectById(li.getNewsId());
MyAdoptionVO myAdoptionVO = new MyAdoptionVO();
myAdoptionVO.setNewsId(li.getNewsId());
myAdoptionVO.setTitle(news.getTitle());
// 组装领养成功与否状态
Adoption adoption = adoptionService.selectOne(new EntityWrapper<Adoption>().eq("adoptionid", li.getNewsId()));
if (adoption.getIsAdoption()) {
myAdoptionVO.setIsSuccess(adoption.getUserId().equals(userId) ? 1 : 2);
} else {
myAdoptionVO.setIsSuccess(0);
}
myAdoptionVO.setPic(getOnePicPath(news));
list.add(myAdoptionVO);
});
}
pageVO.setList(list);
return pageVO;
}
use of com.ch999.haha.admin.entity.AdoptionRequest in project haha by hahafreeasair666.
the class AdoptionRequestServiceImpl method handleAdoptionInfo.
@Override
public Boolean handleAdoptionInfo(Integer loginUserId, Integer adoptionId, Integer userId) {
News news = newsService.selectById(adoptionId);
if (news == null || !news.getCreateUserId().equals(loginUserId) || !news.getIsAdoptionNews()) {
return null;
}
Wrapper<Adoption> wrapper = new EntityWrapper<>();
wrapper.eq("adoptionid", adoptionId).eq("isadoption", 0);
List<Adoption> adoptions = adoptionService.selectList(wrapper);
if (CollectionUtils.isNotEmpty(adoptions)) {
Wrapper<AdoptionRequest> wrapper1 = new EntityWrapper<>();
wrapper1.eq("newsid", adoptionId).eq("userid", userId);
List<AdoptionRequest> adoptionRequests = this.selectList(wrapper1);
if (CollectionUtils.isEmpty(adoptionRequests)) {
return null;
}
adoptionRequests.get(0).setIsSuccess(true);
adoptions.get(0).setIsAdoption(true);
adoptions.get(0).setUserId(userId);
adoptions.get(0).setAdoptionTime(new Date());
return this.updateById(adoptionRequests.get(0)) && adoptionService.updateById(adoptions.get(0));
}
return null;
}
use of com.ch999.haha.admin.entity.AdoptionRequest in project haha by hahafreeasair666.
the class AdoptionRequestServiceImpl method cancelAdoptionRequest.
@Override
public Boolean cancelAdoptionRequest(Integer userId, Integer adoptionId) {
// 先校验能不能取消
Adoption adoption = adoptionService.selectOne(new EntityWrapper<Adoption>().eq("adoptionid", adoptionId));
AdoptionRequest adoptionRequest = this.selectOne(new EntityWrapper<AdoptionRequest>().eq("newsid", adoptionId).eq("userid", userId));
if (adoption.getUserId() != null || adoptionRequest == null) {
return false;
}
adoptionRequest.setIsDel(true);
return this.updateById(adoptionRequest);
}
Aggregations