|
@@ -2,9 +2,11 @@ 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.TreeRespDTO;
|
|
|
import com.flyer.foster.dto.TreeUpdateDTO;
|
|
|
import com.flyer.foster.entity.FosterRecord;
|
|
|
import com.flyer.foster.entity.Tree;
|
|
|
+import com.flyer.foster.pojo.StpAppUtil;
|
|
|
import com.flyer.foster.service.IFosterRecordService;
|
|
|
import com.flyer.foster.service.ITreeService;
|
|
|
import com.flyer.util.R;
|
|
@@ -12,11 +14,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- * 树
|
|
|
+ * 树(小程序)
|
|
|
*
|
|
|
* @author flyer
|
|
|
* @since 2024-05-09
|
|
@@ -32,6 +35,7 @@ public class AppTreeController {
|
|
|
|
|
|
/**
|
|
|
* 根据果园id查询树
|
|
|
+ *
|
|
|
* @param gardenId
|
|
|
* @return
|
|
|
*/
|
|
@@ -42,21 +46,33 @@ public class AppTreeController {
|
|
|
|
|
|
/**
|
|
|
* 返回区域随机的一棵树
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@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("没有可领养的树!");
|
|
|
+ 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));
|
|
|
+// }
|
|
|
+ int tenantId = StpAppUtil.getTokenSession().getInt("tenantId");
|
|
|
+ Tree tree = new Tree();
|
|
|
+ tree.setGardenId(gardenId);
|
|
|
+ tree.setTenantId(tenantId);
|
|
|
+ tree.setCreatedBy("kelei");
|
|
|
+ tree.setCreatedTime(LocalDateTime.now());
|
|
|
+ tree.setUpdatedBy("kelei");
|
|
|
+ tree.setUpdatedTime(LocalDateTime.now());
|
|
|
+ // 根据果园id创建一颗树
|
|
|
+ iTreeService.save(tree);
|
|
|
+ // 获取新插入的树的信息并返回给前端
|
|
|
+ return R.ok().result(iTreeService.getById(tree.getId()));
|
|
|
}
|
|
|
}
|