|
@@ -1,9 +1,11 @@
|
|
package com.flyer.foster.controller.app;
|
|
package com.flyer.foster.controller.app;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
import com.flyer.foster.dto.TreeAddDTO;
|
|
import com.flyer.foster.dto.TreeAddDTO;
|
|
import com.flyer.foster.dto.TreeUpdateDTO;
|
|
import com.flyer.foster.dto.TreeUpdateDTO;
|
|
import com.flyer.foster.entity.FosterRecord;
|
|
import com.flyer.foster.entity.FosterRecord;
|
|
import com.flyer.foster.entity.Tree;
|
|
import com.flyer.foster.entity.Tree;
|
|
|
|
+import com.flyer.foster.service.IFosterRecordService;
|
|
import com.flyer.foster.service.ITreeService;
|
|
import com.flyer.foster.service.ITreeService;
|
|
import com.flyer.util.R;
|
|
import com.flyer.util.R;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -11,6 +13,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 树
|
|
* 树
|
|
@@ -24,6 +27,9 @@ public class AppTreeController {
|
|
@Autowired
|
|
@Autowired
|
|
private ITreeService iTreeService;
|
|
private ITreeService iTreeService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFosterRecordService iFosterRecordService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据果园id查询树
|
|
* 根据果园id查询树
|
|
* @param gardenId
|
|
* @param gardenId
|
|
@@ -38,10 +44,19 @@ public class AppTreeController {
|
|
* 返回区域随机的一棵树
|
|
* 返回区域随机的一棵树
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- @GetMapping("/getRandomTree/{areaId}")
|
|
|
|
- public R getRandomTree(@PathVariable Integer areaId){
|
|
|
|
- List<Tree> list = iTreeService.lambdaQuery().eq(Tree::getAreaId, areaId).list();
|
|
|
|
-
|
|
|
|
- return R.ok().result(null);
|
|
|
|
|
|
+ @GetMapping("/getRandomTree/{gardenId}")
|
|
|
|
+ public R getRandomTree(@PathVariable Integer gardenId){
|
|
|
|
+ List<FosterRecord> records = iFosterRecordService.lambdaQuery().eq(FosterRecord::getGardenId, gardenId).list();
|
|
|
|
+ //已认养的树
|
|
|
|
+ List<Integer> fosteredIds = records.stream().map(FosterRecord::getTreeId).collect(Collectors.toList());
|
|
|
|
+ LambdaQueryChainWrapper<Tree> queryChainWrapper = iTreeService.lambdaQuery().eq(Tree::getGardenId, gardenId);
|
|
|
|
+ if(fosteredIds.size() > 0){
|
|
|
|
+ queryChainWrapper = queryChainWrapper.notIn(Tree::getId, fosteredIds);
|
|
|
|
+ }
|
|
|
|
+ List<Tree> list = queryChainWrapper.list();
|
|
|
|
+ if(list.size() > 0){
|
|
|
|
+ return R.ok().result(list.get(0));
|
|
|
|
+ }
|
|
|
|
+ return R.error().message("没有可领养的树!");
|
|
}
|
|
}
|
|
}
|
|
}
|