From 77dd7d19bb13f19acd273ba92dfd2b866a229c5e Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Sat, 16 Jul 2022 16:20:07 +0800
Subject: [PATCH] 库存

---
 src/main/java/org/springblade/modules/lang/mapper/LandMapper.xml |   91 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 72 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/springblade/modules/lang/mapper/LandMapper.xml b/src/main/java/org/springblade/modules/lang/mapper/LandMapper.xml
index 85dee85..87a2960 100644
--- a/src/main/java/org/springblade/modules/lang/mapper/LandMapper.xml
+++ b/src/main/java/org/springblade/modules/lang/mapper/LandMapper.xml
@@ -56,15 +56,55 @@
         </if>
     </select>
 
+    <!--查询地块列表(不分页)-->
+    <select id="getLandList" resultType="org.springblade.modules.lang.vo.LandVO">
+        SELECT
+        id,
+        land_name,
+        land_area,
+        ST_ASTEXT(land_range) as land_range,
+        url,
+        type,
+        land_type,
+        land_unit,
+        dept_id,
+        farm_id
+        FROM sys_land
+        where is_deleted = 0
+        <if test="land.landType!=null and land.landType != ''">
+            and land_type = #{land.landType}
+        </if>
+        <if test="land.landName!=null and land.landName != ''">
+            and land_name like concat('%', #{land.landName},'%')
+        </if>
+        <if test="land.deptId!=null and land.deptId != ''">
+            and dept_id=#{land.deptId}
+        </if>
+        <if test="land.type!=null and land.type != ''">
+            and type=#{land.type}
+        </if>
+        <if test="land.tenantId!=null and land.tenantId != ''">
+            and tenant_id =#{land.tenantId}
+        </if>
+        <if test="land.farmId!=null and land.farmId != ''">
+            and farm_id =#{land.farmId}
+        </if>
+    </select>
+
     <insert id="saveLandInfo">
         insert into sys_land
-        (user_id,land_name,land_type,land_area,land_range,type,land_unit,dept_id,url)
+        (user_id,land_name,land_type,land_area,land_range,type,land_unit,dept_id,url,farm_id)
         values
         (#{land.userId},#{land.landName},#{land.landType},#{land.landArea},
-        <if test="land.landRange!=null and land.landRange!=''">
-            ST_GeomFromText(${land.landRange}),
-        </if>
-        #{land.type},#{land.landUnit},#{land.deptId},#{land.url})
+        <choose>
+            <when test="land.landRange!=null and land.landRange!=''">
+                ST_GeomFromText(${land.landRange}),
+            </when>
+            <otherwise>
+                null,
+            </otherwise>
+        </choose>
+        #{land.type},#{land.landUnit},#{land.deptId},#{land.url},#{land.farmId})
     </insert>
 
     <!--详情信息(自定义查询)-->
@@ -94,6 +134,7 @@
         </if>
         type = #{land.type},
         land_unit = #{land.landUnit},
+        farm_id = #{land.farmId},
         url = #{land.url},
         where id = #{land.id}
     </update>
@@ -106,11 +147,13 @@
     </select>
     <!--土地总面积-->
     <select id="selectZAre" resultType="java.util.HashMap">
-        SELECT IFNULL(land_area, 0) as area, IFNULL(land_unit, 0) as unit
-        FROM sys_land
+        SELECT IFNULL(land_area, 0) as area, IFNULL(land_unit, 0) as unit FROM sys_land
         WHERE is_deleted = 0
-        <if test="deptId!= null and deptId!=''">
-            and dept_id=#{deptId}
+        <if test="land.farmId!= null and land.farmId!=''">
+            and farm_id=#{land.farmId}
+        </if>
+        <if test="land.deptId!= null and land.deptId!=''">
+            and dept_id=#{land.deptId}
         </if>
     </select>
     <!--土地使用面积-->
@@ -119,8 +162,11 @@
         FROM sys_land
         WHERE is_deleted = 0
         and type = 0
-        <if test="deptId!= null and deptId!=''">
-            and dept_id=#{deptId}
+        <if test="land.farmId!= null and land.farmId!=''">
+            and farm_id=#{land.farmId}
+        </if>
+        <if test="land.deptId!= null and land.deptId!=''">
+            and dept_id=#{land.deptId}
         </if>
     </select>
     <!--土地未使用面积-->
@@ -129,18 +175,25 @@
         FROM sys_land
         WHERE is_deleted = 0
         and type = 1
-        <if test="deptId!= null and deptId!=''">
-            and dept_id=#{deptId}
+        <if test="land.farmId!= null and land.farmId!=''">
+            and farm_id=#{land.farmId}
+        </if>
+        <if test="land.deptId!= null and land.deptId!=''">
+            and dept_id=#{land.deptId}
         </if>
     </select>
+
     <select id="selectNum" resultType="java.util.HashMap">
-        SELECT strain_id
-        FROM `sys_farm_plant`
-        WHERE status = 1
-        <if test="deptId!= null and deptId!=''">
-            and dept_id=#{deptId}
+        SELECT strain_id FROM sys_farm_plant sfp
+        left join sys_land sl on sl.id = sfp.land_id
+        WHERE sfp.status = 1
+        <if test="land.farmId!= null and land.farmId!=''">
+            and sl.farm_id=#{land.farmId}
         </if>
-        GROUP BY strain_id
+        <if test="land.deptId!= null and land.deptId!=''">
+            and sfp.dept_id=#{land.deptId}
+        </if>
+        GROUP BY sfp.strain_id
     </select>
 
 </mapper>

--
Gitblit v1.9.3