From 72b971c98c46531064d74b68fc8fe8864ed0b544 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 08 Nov 2022 09:04:56 +0800
Subject: [PATCH] 大屏溯源统计次数sql修改
---
src/main/java/org/springblade/modules/farm/mapper/FarmingRecordMapper.xml | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 255 insertions(+), 21 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 3323445..2bad5bd 100644
--- a/src/main/java/org/springblade/modules/farm/mapper/FarmingRecordMapper.xml
+++ b/src/main/java/org/springblade/modules/farm/mapper/FarmingRecordMapper.xml
@@ -4,6 +4,95 @@
<!--自定义查询农事记录分页数据-->
<select id="selectFarmingRecordPage" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
+ 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>
+ <if test="farmingRecord.type!=null and farmingRecord.type!=''">
+ and sfr.type = #{farmingRecord.type}
+ </if>
+ <if test="farmingRecord.stockId!=null and farmingRecord.stockId!=''">
+ and sfr.stock_id = #{farmingRecord.stockId}
+ </if>
+ <if test="farmingRecord.jobWay!=null and farmingRecord.jobWay!=''">
+ and sfr.job_way = #{farmingRecord.jobWay}
+ </if>
+ <if test="farmingRecord.operator!=null and farmingRecord.operator!=''">
+ and sfr.operator = #{farmingRecord.operator}
+ </if>
+ <if test="farmingRecord.deptId!=null and farmingRecord.deptId!=''">
+ and sfr.dept_id = #{farmingRecord.deptId}
+ </if>
+ <if test="farmingRecord.tenantId!=null and farmingRecord.tenantId!=''">
+ and sfr.tenant_id = #{farmingRecord.tenantId}
+ </if>
+ <if test="farmingRecord.strainId!=null and farmingRecord.strainId!=''">
+ and sfr.strain_id = #{farmingRecord.strainId}
+ </if>
+ <if test="farmingRecord.farmId!=null and farmingRecord.farmId!=''">
+ and sl.farm_id = #{farmingRecord.farmId}
+ </if>
+ ORDER BY sfr.create_time DESC
+ </select>
+
+ <!--自定义查询农事记录分页数据-->
+ <select id="selectFarmingRecordPageByNz" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
+ SELECT
+ sfr.*,
+ sl.land_name landName,
+ user.real_name,
+ strain.strain_name,
+ sf.factory_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
+ LEFT JOIN sys_stockfactory sf on sf.id = sfr.stock_id
+ WHERE
+ 1 =1 AND sfr.stock_id IS NOT NULL
+ <if test="farmingRecord.landId!=null and farmingRecord.landId!=''">
+ and sfr.land_id = #{farmingRecord.landId}
+ </if>
+ <if test="farmingRecord.type!=null and farmingRecord.type!=''">
+ and sfr.type = #{farmingRecord.type}
+ </if>
+ <if test="farmingRecord.stockId!=null and farmingRecord.stockId!=''">
+ and sfr.stock_id = #{farmingRecord.stockId}
+ </if>
+ <if test="farmingRecord.jobWay!=null and farmingRecord.jobWay!=''">
+ and sfr.job_way = #{farmingRecord.jobWay}
+ </if>
+ <if test="farmingRecord.operator!=null and farmingRecord.operator!=''">
+ and sfr.operator = #{farmingRecord.operator}
+ </if>
+ <if test="farmingRecord.deptId!=null and farmingRecord.deptId!=''">
+ and sfr.dept_id = #{farmingRecord.deptId}
+ </if>
+ <if test="farmingRecord.tenantId!=null and farmingRecord.tenantId!=''">
+ and sfr.tenant_id = #{farmingRecord.tenantId}
+ </if>
+ <if test="farmingRecord.strainId!=null and farmingRecord.strainId!=''">
+ and sfr.strain_id = #{farmingRecord.strainId}
+ </if>
+ <if test="farmingRecord.farmId!=null and farmingRecord.farmId!=''">
+ and sl.farm_id = #{farmingRecord.farmId}
+ </if>
+ ORDER BY sfr.create_time DESC
+ </select>
+
+ <select id="selectFarmingRecordPages" 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
@@ -22,36 +111,181 @@
<if test="farmingRecord.operator!=null and farmingRecord.operator!=''">
and sfr.operator = #{farmingRecord.operator}
</if>
+ <if test="farmingRecord.deptId!=null and farmingRecord.deptId!=''">
+ and sfr.dept_id = #{farmingRecord.deptId}
+ </if>
+ <if test="farmingRecord.tenantId!=null and farmingRecord.tenantId!=''">
+ and sfr.tenant_id = #{farmingRecord.tenantId}
+ </if>
+ <if test="farmingRecord.strainId!=null and farmingRecord.strainId!=''">
+ and sfr.strain_id = #{farmingRecord.strainId}
+ </if>
</select>
<!--查询统计本年农事记录操作总数-->
<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 ss
+ LEFT JOIN sys_land sl ON sl.id = ss.land_id
where 1=1
- and YEAR(time)=YEAR(NOW())
+ and YEAR (time)= YEAR (NOW())
+ <if test="farmId != null and farmId != ''">
+ and sl.farm_id = #{sale.farmId}
+ </if>
</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
- from sys_farming_record
+ select ss.type,case when ss.type = 0 then '施肥'
+ when ss.type = 1 then '翻耕'
+ when ss.type = 2 then '灌溉'
+ when ss.type = 3 then '起垄'
+ when ss.type = 4 then '用药'
+ when ss.type = 5 then '追肥'
+ when ss.type = 6 then '除草'
+ when ss.type = 7 then '修剪'
+ when ss.type = 8 then '浸种'
+ when ss.type = 9 then '拌种'
+ when ss.type = 10 then '移栽'
+ when ss.type = 11 then '直播'
+ when ss.type = 12 then '采收'
+ else '其他' end as name,
+ ifnull(count(*), 0) value
+ from sys_farming_record ss
+ LEFT JOIN sys_land sl ON sl.id = ss.land_id
where 1=1
- and YEAR(time)=YEAR(NOW())
- group by type
+ and YEAR (time)= YEAR (NOW())
+ <if test="farmId != null and farmId != ''">
+ and sl.farm_id = #{sale.farmId}
+ </if>
+ group by ss.type
+ </select>
+
+ <!--今年农资使用量-->
+ <select id="selectJyCount" resultType="java.lang.Double">
+ SELECT IFNULL(SUM(census), 0) AS jynum FROM sys_farming_record sfr
+ left join sys_land sl on sl.id = sfr.land_id
+ WHERE
+ YEAR(sfr.time) = YEAR(NOW())
+ AND sfr.stock_id != ""
+ and sl.farm_id=#{farmId}
+ </select>
+ <!--去年农资使用量-->
+ <select id="selectQyCount" resultType="java.lang.Double">
+ SELECT IFNULL(SUM(census), 0) AS qynum from sys_farming_record sfr
+ left join sys_land sl on sl.id = sfr.land_id
+ WHERE
+ YEAR (sfr.time) = YEAR ( date_sub(now()
+ , INTERVAL 1 YEAR))
+ and sl.farm_id=#{farmId}
+ </select>
+
+ <!--本月农资使用量-->
+ <select id="selectByCount" resultType="java.lang.Double">
+ SELECT IFNULL(SUM(census), 0) AS bynum from sys_farming_record sfr
+ left join sys_land sl on sl.id = sfr.land_id
+ WHERE DATE_FORMAT(sfr.time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
+ and sl.farm_id=#{farmId}
+ </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,ss1.agricultural_name agriculturalName
+ 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
+ left join sys_stockfactory ss1 on ss1.id = sfr.stock_id
+ where 1=1
+ <if test="farm.landId!=null and farm.landId!=''">
+ and sfr.land_id = #{farm.landId}
+ </if>
+ <if test="farm.type!=null and farm.type!=''">
+ and sfr.type = #{farm.type}
+ </if>
+ <if test="farm.stockId!=null and farm.stockId!=''">
+ and sfr.stock_id = #{farm.stockId}
+ </if>
+ <if test="farm.jobWay!=null and farm.jobWay!=''">
+ and sfr.job_way = #{farm.jobWay}
+ </if>
+ <if test="farm.operator!=null and farm.operator!=''">
+ and sfr.operator = #{farm.operator}
+ </if>
+ <if test="farm.deptId!=null and farm.deptId!=''">
+ and sfr.dept_id = #{farm.deptId}
+ </if>
+ <if test="farm.farmId!=null and farm.farmId!=''">
+ and sl.farm_id = #{farm.farmId}
+ </if>
+ <if test="farm.strainId!=null and farm.strainId!=''">
+ and sfr.strain_id = #{farm.strainId}
+ </if>
+ <if test="farm.startTime!=null and farm.startTime!=''">
+ and sfr.create_time >= #{farm.startTime}
+ </if>
+ <if test="farm.endTime!=null and farm.endTime!=''">
+ and sfr.create_time <= #{farm.endTime}
+ </if>
+ order by sfr.time desc,sfr.create_time desc
+ </select>
+ <select id="getDetails" resultType="org.springblade.modules.farm.vo.FarmingRecordVO">
+ SELECT sfr.*,land.land_name,
+ bdb.dict_value AS typeName,
+ strain.strain_name AS strainName,
+ stock.agriculturalType,
+ stock.agricultural_name,
+ bu.name AS realName
+ FROM sys_farming_record sfr
+ LEFT JOIN sys_land land ON land.id = sfr.land_id
+ LEFT JOIN blade_dict_biz bdb ON bdb.dict_key = sfr.type
+ LEFT JOIN sys_strain strain ON strain.id = sfr.strain_id
+ LEFT JOIN (
+ SELECT stf.id,stf.agricultural_name,bdb1.dict_value AS agriculturalType
+ FROM sys_stockfactory stf
+ LEFT JOIN blade_dict_biz bdb1 ON stf.type = bdb1.dict_key
+ WHERE bdb1.code = "stockType" GROUP BY stf.id,stf.agricultural_name,bdb1.dict_value
+ ) stock ON sfr.stock_id = stock.id
+ LEFT JOIN blade_user bu ON bu.id = sfr.operator
+ WHERE bdb.code = "farmingType" AND sfr.id = #{FarmingRecordVO.id}
</select>
</mapper>
--
Gitblit v1.9.3