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/farm/mapper/FarmingRecordMapper.xml |  132 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 110 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/springblade/modules/farm/mapper/FarmingRecordMapper.xml b/src/main/java/org/springblade/modules/farm/mapper/FarmingRecordMapper.xml
index a4c69a5..06562e3 100644
--- a/src/main/java/org/springblade/modules/farm/mapper/FarmingRecordMapper.xml
+++ b/src/main/java/org/springblade/modules/farm/mapper/FarmingRecordMapper.xml
@@ -4,9 +4,18 @@
 
     <!--自定义查询农事记录分页数据-->
     <select id="selectFarmingRecordPage" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
-        select sfr.*,sl.land_name landName from sys_farming_record sfr
-        left join sys_land sl on sl.id = sfr.land_id
-        where 1=1
+        SELECT
+        sfr.*,
+        sl.land_name landName,
+        user.real_name,
+        strain.strain_name
+        FROM
+        sys_farming_record sfr
+        LEFT JOIN sys_land sl ON sl.id = sfr.land_id
+        LEFT JOIN blade_user user on sfr.operator = user.id
+        LEFT JOIN sys_strain strain on sfr.strain_id = strain.id
+        WHERE
+        1 =1
         <if test="farmingRecord.landId!=null and farmingRecord.landId!=''">
             and sfr.land_id = #{farmingRecord.landId}
         </if>
@@ -65,32 +74,111 @@
 
     <!--查询统计本年农事记录操作总数-->
     <select id="getFarmingCount" resultType="java.lang.Integer">
-        select ifnull(count(*),0) count from sys_farming_record
+        select ifnull(count(*), 0) count
+        from sys_farming_record
         where 1=1
-        and YEAR(time)=YEAR(NOW())
+          and YEAR (time)= YEAR (NOW())
+          and dept_id=#{deptId}
     </select>
 
     <!--查询统计本年农事记录操作总数-->
     <select id="getFarmingStatis" resultType="org.springblade.modules.farm.vo.FarmingStatisVO">
-        select
-        case when type=0 then '施肥'
-         when type=1 then '翻耕'
-         when type=2 then '灌溉'
-         when type=3 then '起垄'
-         when type=4 then '用药'
-         when type=5 then '追肥'
-         when type=6 then '除草'
-         when type=7 then '修剪'
-         when type=8 then '浸种'
-         when type=9 then '拌种'
-         when type=10 then '移栽'
-         when type=11 then '直播'
-         when type=12 then '采收'
-         else '其他' end as name,
-        ifnull(count(*),0) value
+        select case
+                   when type = 0 then '施肥'
+                   when type = 1 then '翻耕'
+                   when type = 2 then '灌溉'
+                   when type = 3 then '起垄'
+                   when type = 4 then '用药'
+                   when type = 5 then '追肥'
+                   when type = 6 then '除草'
+                   when type = 7 then '修剪'
+                   when type = 8 then '浸种'
+                   when type = 9 then '拌种'
+                   when type = 10 then '移栽'
+                   when type = 11 then '直播'
+                   when type = 12 then '采收'
+                   else '其他' end as name,
+               ifnull(count(*), 0) value
         from sys_farming_record
         where 1=1
-        and YEAR(time)=YEAR(NOW())
+          and YEAR (time)= YEAR (NOW())
+          and dept_id=#{deptId}
         group by type
     </select>
+
+    <!--今年农资使用量-->
+    <select id="selectJyCount" resultType="java.lang.Double">
+        SELECT IFNULL(SUM(census), 0) AS jynum
+        FROM sys_farming_record
+        WHERE
+            YEAR ( time ) = YEAR ( NOW( ) )
+          AND stock_id != NULL
+          and dept_id=#{deptId}
+    </select>
+    <!--去年农资使用量-->
+    <select id="selectQyCount" resultType="java.lang.Double">
+        SELECT IFNULL(SUM(census), 0) AS qynum
+        FROM sys_farming_record
+        WHERE
+            YEAR (time) = YEAR ( date_sub(now()
+            , INTERVAL 1 YEAR))
+          and dept_id=#{deptId}
+    </select>
+
+    <!--本月农资使用量-->
+    <select id="selectByCount" resultType="java.lang.Double">
+        SELECT IFNULL(SUM(census), 0) AS bynum
+        FROM sys_farming_record
+        WHERE DATE_FORMAT(time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
+          and dept_id = #{deptId}
+    </select>
+
+    <!--查询农事记录信息(种植开始起)-->
+    <select id="getFarmingRecordByFarmPlantId" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
+        select bu.real_name realName,sfr.time,case
+                   when type = 0 then '施肥'
+                   when type = 1 then '翻耕'
+                   when type = 2 then '灌溉'
+                   when type = 3 then '起垄'
+                   when type = 4 then '用药'
+                   when type = 5 then '追肥'
+                   when type = 6 then '除草'
+                   when type = 7 then '修剪'
+                   when type = 8 then '浸种'
+                   when type = 9 then '拌种'
+                   when type = 10 then '移栽'
+                   when type = 11 then '直播'
+                   when type = 12 then '采收'
+                   else '其他' end as typeName
+        from sys_farming_record sfr
+        left join blade_user bu on bu.id = sfr.operator
+        where land_id = #{recovery.landId}
+        and strain_id = #{recovery.strainId}
+        order by sfr.time asc,sfr.create_time asc
+    </select>
+
+    <!--查询农事操作记录(不分页)-->
+    <select id="getFarmingRecordListfarm" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
+        select sfr.*,case
+                   when sfr.type = 0 then '施肥'
+                   when sfr.type = 1 then '翻耕'
+                   when sfr.type = 2 then '灌溉'
+                   when sfr.type = 3 then '起垄'
+                   when sfr.type = 4 then '用药'
+                   when sfr.type = 5 then '追肥'
+                   when sfr.type = 6 then '除草'
+                   when sfr.type = 7 then '修剪'
+                   when sfr.type = 8 then '浸种'
+                   when sfr.type = 9 then '拌种'
+                   when sfr.type = 10 then '移栽'
+                   when sfr.type = 11 then '直播'
+                   when sfr.type = 12 then '采收'
+                   else '其他' end as typeName,sl.land_name landName,ss.strain_name strainName,bu.real_name realName
+        from sys_farming_record sfr
+        left join blade_user bu on bu.id = sfr.operator
+		left join sys_land sl on sl.id = sfr.land_id
+		left join sys_strain ss on ss.id = sfr.strain_id
+        where sl.farm_id = #{farm.farmId}
+        order by sfr.time desc,sfr.create_time desc
+    </select>
 </mapper>

--
Gitblit v1.9.3