From 3df8757ade3bdef3b5a142c846680102589260bc Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Wed, 13 Jul 2022 10:36:37 +0800
Subject: [PATCH] 农事操作,种植记录查询新增,地块,溯源码查询修改

---
 src/main/java/org/springblade/modules/farmplant/controller/FarmPlantController.java |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 107 insertions(+), 1 deletions(-)

diff --git a/src/main/java/org/springblade/modules/farmplant/controller/FarmPlantController.java b/src/main/java/org/springblade/modules/farmplant/controller/FarmPlantController.java
index bfc863e..c34add1 100644
--- a/src/main/java/org/springblade/modules/farmplant/controller/FarmPlantController.java
+++ b/src/main/java/org/springblade/modules/farmplant/controller/FarmPlantController.java
@@ -19,13 +19,19 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.AllArgsConstructor;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.secure.annotation.PreAuth;
 import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.constant.BladeConstant;
+import org.springblade.core.tool.constant.RoleConstant;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.modules.farm.entity.FarmingRecord;
 import org.springblade.modules.farm.service.FarmingRecordService;
@@ -35,8 +41,12 @@
 import org.springblade.modules.farmplant.vo.StrainVO;
 import org.springblade.modules.lang.entity.Land;
 import org.springblade.modules.lang.service.ILandService;
+import org.springblade.modules.system.entity.User;
+import org.springblade.modules.system.vo.UserVO;
+import org.springblade.modules.system.wrapper.UserWrapper;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
+import springfox.documentation.annotations.ApiIgnore;
 
 import javax.validation.Valid;
 import java.text.DecimalFormat;
@@ -95,6 +105,56 @@
 		return R.data(pages);
 	}
 
+
+	/**
+	 * 查询种养记录列表(不分页)
+	 * @param farmPlant
+	 * @return
+	 */
+	@GetMapping("/getFarmPlantList")
+	public R getFarmPlantList(FarmPlantVO farmPlant) {
+		return R.data(farmplantService.getFarmPlantList(farmPlant));
+	}
+
+
+	/**
+	 * 分页统计
+	 */
+	@GetMapping("/pageCount")
+	@ApiOperationSupport(order = 3)
+	@ApiOperation(value = "分页", notes = "传入farmPlant")
+	public R<List<FarmPlantVO>> pageCount(FarmPlantVO farmPlant, Query query) {
+		IPage<FarmPlantVO> pages = farmplantService.selectFarmPlantPage(Condition.getPage(query), farmPlant);
+		List<FarmPlantVO> res = pages.getRecords();
+		List<FarmPlantVO> count = new ArrayList<>();
+		//按种类合并种植物
+		for (int i = 0; i < res.size(); i++) {
+			if (i == 0){
+				count.add(res.get(0));
+			}else {
+				boolean type = false;
+				for (int j = 0; j < count.size(); j++) {
+					if (res.get(i).getStrainId().equals(count.get(j).getStrainId())){
+						FarmPlantVO data = new FarmPlantVO();
+						data.setStrainId(res.get(i).getStrainId());
+						data.setArea((Double.parseDouble(res.get(i).getArea()) + Double.parseDouble(count.get(j).getArea()))+"");
+						data.setStrainName(res.get(i).getStrainName());
+						count.set(j,data);
+						type = false;
+						break;
+					}else{
+						type = true;
+					}
+				}
+				if (type){
+					count.add(res.get(i));
+				}
+			}
+		}
+
+		return R.data(count);
+	}
+
 	/**
 	 * 新增
 	 */
@@ -110,6 +170,8 @@
 			record.setCreateTime(new Date());
 			record.setJobWay(farmPlant.getJobWay());
 			record.setTime(farmPlant.getTransplanTime());
+			record.setDeptId(farmPlant.getDeptId());
+			record.setTenantId(farmPlant.getTenantId());
 			if (farmPlant.getPlantingWay().equals("0")) {
 				//移栽
 				record.setType("10");
@@ -120,7 +182,7 @@
 			}
 			record.setLandId(farmPlant.getLandId());
 			record.setOperator(farmPlant.getCreateUser());
-			record.setRemarks("品种: " + farmPlant.getVarieties());
+			record.setContent("品种: " + farmPlant.getVarieties());
 			//新增
 			farmingRecordService.save(record);
 
@@ -314,4 +376,48 @@
 		return R.data(list);
 	}
 
+
+	/**
+	 * 自定义分页
+	 */
+	@GetMapping("/pagex")
+	@ApiOperationSupport(order = 3)
+	@ApiOperation(value = "分页", notes = "传入farmPlant")
+	public R<IPage<FarmPlantVO>> pagex(FarmPlantVO farmPlant, Query query) {
+		IPage<FarmPlantVO> pages = farmplantService.selectFarmPlantPage(Condition.getPage(query), farmPlant);
+		for (int i = 0; i < pages.getRecords().size(); i++) {
+			//修改种养类型
+			String plantingWay = pages.getRecords().get(i).getPlantingWay();
+			if (plantingWay.equals("0")) {
+				pages.getRecords().get(i).setTy("移栽");
+			}
+			else if (plantingWay.equals("1")) {
+				pages.getRecords().get(i).setTy("直播");
+			} else {
+				pages.getRecords().get(i).setTy("秧苗");
+			}
+			//计算天数
+			Date transplanTime = pages.getRecords().get(i).getTransplanTime();
+			Date date = new Date();
+			Integer integer = daysBetween(transplanTime, date);
+			pages.getRecords().get(i).setFate(integer);
+		}
+		return R.data(pages);
+	}
+
+	/**
+	 * 根据时间阶段计算天数
+	 * @param smdate    开始时间
+	 * @param bdate     结束时间
+	 * @return
+	 */
+	public static Integer daysBetween(Date smdate,Date bdate){
+		Calendar cal = Calendar.getInstance();
+		cal.setTime(smdate);
+		long time1 = cal.getTimeInMillis();
+		cal.setTime(bdate);
+		long time2 = cal.getTimeInMillis();
+		long between_days=(time2-time1)/(1000*3600*24);
+		return Integer.parseInt(String.valueOf(between_days))+1;
+	}
 }

--
Gitblit v1.9.3