智慧农业后台管理
guoshilong
2022-11-08 72b971c98c46531064d74b68fc8fe8864ed0b544
src/main/java/org/springblade/modules/farmplant/mapper/FarmPlantMapper.xml
@@ -4,11 +4,167 @@
    <!--自定义查询农场养殖记录分页数据-->
    <select id="selectFarmPlantPage" resultType="org.springblade.modules.farmplant.vo.FarmPlantVO">
        select sfp.*,ss.strain_name strainName,ss.url,sl.land_name landName,sl.land_area area,land_unit landUnit from
        select DISTINCT sfp.*,ss.strain_name strainName,ss.url,sl.land_name landName,sl.land_area area,land_unit landUnit,bdb.dict_value dica,a.farm_id AS otherFarmId
        ,(SELECT IFNULL(SUM(r.weight),0) from sys_recovery r where sfp.land_id = r.land_id and sfp.strain_id = r.strain_id) as outputNum
        from
        sys_farm_plant sfp
        left join sys_strain ss on ss.id = sfp.strain_id
        left join sys_land sl on sl.id = sfp.land_id
        LEFT JOIN (
        SELECT l.id,l.land_name,l.farm_id FROM sys_land l
        ) a ON a.id = sfp.other_land_id
        LEFT JOIN sys_farm farm ON farm.id = a.farm_id
        LEFT JOIN blade_dict_biz bdb ON bdb.dict_key = sl.land_unit
        where 1=1
        AND bdb.code = "landunit"
        <if test="farmPlant.plant!=null and farmPlant.plant!=''">
            and sfp.plant = #{farmPlant.plant}
        </if>
        <if test="farmPlant.year!=null and farmPlant.year!=''">
            and sfp.create_time like concat('%',#{farmPlant.year},'%')
        </if>
        <if test="farmPlant.landId!=null and farmPlant.landId!=''">
            and sfp.land_id = #{farmPlant.landId}
        </if>
        <if test="farmPlant.strainId!=null and farmPlant.strainId!=''">
            and sfp.strain_id = #{farmPlant.strainId}
        </if>
        <if test="farmPlant.plantingWay!=null and farmPlant.plantingWay!=''">
            and sfp.planting_way = #{farmPlant.plantingWay}
        </if>
        <if test="farmPlant.jobWay!=null and farmPlant.jobWay!=''">
            and sfp.job_way = #{farmPlant.jobWay}
        </if>
        <if test="farmPlant.status!=null and farmPlant.status!=''">
            and sfp.status = #{farmPlant.status}
        </if>
        <if test="farmPlant.strainName!=null and farmPlant.strainName!=''">
            and ss.strain_name like concat('%',#{farmPlant.strainName},'%')
        </if>
        <if test="farmPlant.varieties!=null and farmPlant.varieties!=''">
            and sfp.varieties like concat('%',#{farmPlant.varieties},'%')
        </if>
        <if test="farmPlant.landName!=null and farmPlant.landName!=''">
            and sl.land_name like concat('%',#{farmPlant.landName},'%')
        </if>
        <if test="farmPlant.startTime!=null and farmPlant.startTime!=''">
            and sfp.transplan_time &gt;= #{farmPlant.startTime}
        </if>
        <if test="farmPlant.endTime!=null and farmPlant.endTime!=''">
            and sfp.transplan_time &lt;= #{farmPlant.endTime}
        </if>
        <if test="farmPlant.deptId!=null and farmPlant.deptId!=''">
            and sfp.dept_id = #{farmPlant.deptId}
        </if>
        <if test="farmPlant.tenantId!=null and farmPlant.tenantId!=''">
            and sfp.tenant_id = #{farmPlant.tenantId}
        </if>
        <if test="farmPlant.farmId!=null and farmPlant.farmId!=''">
            and sl.farm_id = #{farmPlant.farmId}
        </if>
        <if test="farmPlant.transplanTimeStart !=null and farmPlant.transplanTimeStart!= ''">
            and sfp.transplan_time >= #{farmPlant.transplanTimeStart}
        </if>
        <if test="farmPlant.transplanTimeEnd !=null and farmPlant.transplanTimeEnd!= ''">
            and sfp.transplan_time &lt; #{farmPlant.transplanTimeEnd}
        </if>
        <if test="farmPlant.otherLandId !=null and farmPlant.otherLandId !=''">
            AND sfp.other_land_id = #{farmPlant.otherLandId}
        </if>
        order by sfp.id desc
    </select>
    <select id="selectFarmPlantPageCount" resultType="org.springblade.modules.farmplant.vo.FarmPlantVO">
        SELECT b.strain_id,b.strainName,SUM(b.area) AS area,b.url,b.tenant_id,b.dept_id FROM
        (
            SELECT
            a.strain_id,a.strainName,SUM(TRUNCATE(a.land_area,3)) area,a.url,a.tenant_id,a.dept_id,a.planting_way
        FROM
            (
                SELECT
                sfp.*,
                ss.strain_name AS strainName,
                ss.url,
                sl.land_name AS landName,
                land_unit AS landUnit,
                ( CASE WHEN land_unit = 2 THEN FORMAT(sl.land_area * 0.0015,3) WHEN land_unit = 1 THEN sl.land_area * 0.1 ELSE
                sl.land_area END ) land_area
                FROM
                sys_farm_plant sfp
                LEFT JOIN sys_strain ss ON ss.id = sfp.strain_id
                LEFT JOIN sys_land sl ON sl.id = sfp.land_id
                WHERE
                1 = 1
                <if test="farmPlant.plant!=null and farmPlant.plant!=''">
                    and sfp.plant = #{farmPlant.plant}
                </if>
                <if test="farmPlant.year!=null and farmPlant.year!=''">
                    and sfp.create_time like concat('%',#{farmPlant.year},'%')
                </if>
                <if test="farmPlant.landId!=null and farmPlant.landId!=''">
                    and sfp.land_id = #{farmPlant.landId}
                </if>
                <if test="farmPlant.strainId!=null and farmPlant.strainId!=''">
                    and sfp.strain_id = #{farmPlant.strainId}
                </if>
                <if test="farmPlant.plantingWay!=null and farmPlant.plantingWay!=''">
                    and sfp.planting_way = #{farmPlant.plantingWay}
                </if>
                <if test="farmPlant.jobWay!=null and farmPlant.jobWay!=''">
                    and sfp.job_way = #{farmPlant.jobWay}
                </if>
                <if test="farmPlant.status!=null and farmPlant.status!=''">
                    and sfp.status = #{farmPlant.status}
                </if>
                <if test="farmPlant.strainName!=null and farmPlant.strainName!=''">
                    and ss.strain_name like concat('%',#{farmPlant.strainName},'%')
                </if>
                <if test="farmPlant.varieties!=null and farmPlant.varieties!=''">
                    and sfp.varieties like concat('%',#{farmPlant.varieties},'%')
                </if>
                <if test="farmPlant.startTime!=null and farmPlant.startTime!=''">
                    and sfp.transplan_time &gt;= #{farmPlant.startTime}
                </if>
                <if test="farmPlant.endTime!=null and farmPlant.endTime!=''">
                    and sfp.transplan_time &lt;= #{farmPlant.endTime}
                </if>
                <if test="farmPlant.deptId!=null and farmPlant.deptId!=''">
                    and sfp.dept_id = #{farmPlant.deptId}
                </if>
                <if test="farmPlant.tenantId!=null and farmPlant.tenantId!=''">
                    and sfp.tenant_id = #{farmPlant.tenantId}
                </if>
                <if test="farmPlant.farmId!=null and farmPlant.farmId!=''">
                    and sl.farm_id = #{farmPlant.farmId}
                </if>ORDER BY
                sfp.id
                DESC
            ) a
            GROUP BY
            a.strain_id,a.dept_id,a.planting_way HAVING planting_way !=2
        ) b
        GROUP BY
        b.strain_id,b.dept_id
    </select>
    <select id="selectFarmPlantPageCountYM" resultType="org.springblade.modules.farmplant.vo.FarmPlantVO">
        SELECT
        a.strain_id,a.strainName,SUM(TRUNCATE(a.land_area,3)) area,a.url,a.tenant_id,a.dept_id,a.planting_way
        FROM
        (
        SELECT
        sfp.*,
        ss.strain_name AS strainName,
        ss.url,
        sl.land_name AS landName,
        land_unit AS landUnit,
        ( CASE WHEN land_unit = 2 THEN FORMAT(sl.land_area * 0.0015,3) WHEN land_unit = 1 THEN sl.land_area * 0.1 ELSE sl.land_area END ) land_area
        FROM
        sys_farm_plant sfp
        LEFT JOIN sys_strain ss ON ss.id = sfp.strain_id
        LEFT JOIN sys_land sl ON sl.id = sfp.land_id
        WHERE
        1 = 1
        <if test="farmPlant.plant!=null and farmPlant.plant!=''">
            and sfp.plant = #{farmPlant.plant}
        </if>
@@ -51,13 +207,23 @@
        <if test="farmPlant.farmId!=null and farmPlant.farmId!=''">
            and sl.farm_id = #{farmPlant.farmId}
        </if>
        order by sfp.id desc
        ORDER BY
        sfp.id DESC
        ) a
        GROUP BY
        a.strain_id,a.dept_id,a.planting_way HAVING planting_way !=0 AND planting_way !=1
    </select>
    <!--自定义查询农场养殖记录分页数据-->
    <select id="getFarmPlantStatistics" resultType="org.springblade.modules.farmplant.vo.FarmPlantVO">
        select sfp.strain_id,ss.strain_name strainName,sum(sl.land_area) areas,land_unit landUnit from sys_farm_plant
        sfp
        SELECT a.strain_id,a.strainName,SUM(TRUNCATE(a.land_area,3)) areas FROM
        (
        select sfp.strain_id,
        ss.strain_name strainName,
        ( CASE WHEN land_unit = 2 THEN FORMAT(sl.land_area * 0.0015,3) WHEN land_unit = 1 THEN sl.land_area * 0.1 ELSE sl.land_area END ) land_area,
        land_unit landUnit
        from
        sys_farm_plant sfp
        left join sys_strain ss on ss.id = sfp.strain_id
        left join sys_land sl on sl.id = sfp.land_id
        where 1=1
@@ -73,7 +239,11 @@
        <if test="farmPlant.tenantId!=null and farmPlant.tenantId!=''">
            and sfp.tenant_id = #{farmPlant.tenantId}
        </if>
        group by sfp.strain_id,strain_name,land_unit
        <if test="farmPlant.status !=null and farmPlant.status!=''">
            and sfp.status = #{farmPlant.status}
        </if>
        ) a
        GROUP BY a.strain_id,a.strainName
    </select>
    <!--查询农场养殖记录数据-->
@@ -89,8 +259,8 @@
        <if test="farmPlant.endTime!=null and farmPlant.endTime!=''">
            and sfp.transplan_time &lt;= #{farmPlant.endTime}
        </if>
        <if test="farmPlant.deptId!=null and farmPlant.deptId!=''">
            and sfp.dept_id = #{farmPlant.deptId}
        <if test="farmPlant.farmId!=null and farmPlant.farmId!=''">
            and sl.farm_id = #{farmPlant.farmId}
        </if>
        <if test="farmPlant.tenantId!=null and farmPlant.tenantId!=''">
            and sfp.tenant_id = #{farmPlant.tenantId}
@@ -103,7 +273,7 @@
    <!--已种植农产品列表-->
    <select id="strainTree" resultType="org.springblade.modules.farmplant.entity.Strain">
        select ss.id, ss.strain_name strainName
        select ss.id, ss.strain_name strainName,ss.url
        from sys_farm_plant sfp
                 left join sys_strain ss on ss.id = sfp.strain_id
        where sfp.status = "1"
@@ -112,7 +282,14 @@
    <select id="selectCount" resultType="java.lang.Integer">
        SELECT IFNULL(COUNT(*), 0) as num
        FROM (SELECT strain_id FROM `sys_farm_plant` WHERE STATUS = 1 GROUP BY strain_id) a
        FROM (SELECT strain_id
        FROM `sys_farm_plant` ss
        LEFT JOIN sys_land sl ON sl.id = ss.land_id
        WHERE  ss.STATUS = 1
        <if test="farmPlant.farmId != null and farmPlant.farmId != ''">
            and sl.farm_id = #{farmPlant.farmId}
        </if>
        GROUP BY strain_id) a
    </select>
    <!--种植品种监管 0:有机 code=1(当天) =2(月) =3(年)-->
@@ -286,15 +463,17 @@
    <!--小程序查询农场养殖记录数据-->
    <select id="getFarmPlantStatisticsCountz" resultType="org.springblade.modules.farmplant.vo.FarmPlantVO">
        SELECT
        sfp.strain_id,
        SELECT a.strain_id,a.strainName,SUM(TRUNCATE(a.land_area,3)) areas,a.url FROM
        (
        select sfp.strain_id,ss.url,
        ss.strain_name strainName,
        sum( sl.land_area ) area,
        ( CASE WHEN land_unit = 2 THEN FORMAT(sl.land_area * 0.0015,3) WHEN land_unit = 1 THEN sl.land_area * 0.1 ELSE sl.land_area END ) land_area,
        land_unit landUnit
        FROM
        from
        sys_farm_plant sfp
        LEFT JOIN sys_strain ss ON ss.id = sfp.strain_id
        LEFT JOIN sys_land sl ON sl.id = sfp.land_id where 1=1
        left join sys_strain ss on ss.id = sfp.strain_id
        left join sys_land sl on sl.id = sfp.land_id
        where 1=1
        <if test="farmPlant.startTime!=null and farmPlant.startTime!=''">
            and sfp.transplan_time &gt;= #{farmPlant.startTime}
        </if>
@@ -304,28 +483,210 @@
        <if test="farmPlant.deptId!=null and farmPlant.deptId!=''">
            and sfp.dept_id = #{farmPlant.deptId}
        </if>
        <if test="farmPlant.status!=null and farmPlant.status!=''">
            and sfp.status = #{farmPlant.status}
        </if>
        <if test="farmPlant.tenantId!=null and farmPlant.tenantId!=''">
            and sfp.tenant_id = #{farmPlant.tenantId}
        </if>
        group by sfp.strain_id,strain_name,land_unit
        <if test="farmPlant.status !=null and farmPlant.status!=''">
            and sfp.status = #{farmPlant.status}
        </if>
        ) a
        GROUP BY a.strain_id,a.strainName
    </select>
    <!--查询种养记录列表(不分页)-->
    <select id="getFarmPlantList" resultType="org.springblade.modules.farmplant.vo.FarmPlantVO">
<!--        SELECT-->
<!--        a.strain_id,a.strainName,SUM(TRUNCATE(a.land_area,3)) area,a.url-->
<!--        FROM-->
<!--        (-->
<!--        SELECT-->
<!--        sfp.*,-->
<!--        ss.strain_name AS strainName,-->
<!--        ss.url,-->
<!--        sl.land_name AS landName,-->
<!--        land_unit AS landUnit,-->
<!--        ( CASE WHEN land_unit = 2 THEN FORMAT(sl.land_area * 0.0015,3) WHEN land_unit = 1 THEN sl.land_area * 0.1 ELSE sl.land_area END ) land_area-->
<!--        FROM-->
<!--        sys_farm_plant sfp-->
<!--        LEFT JOIN sys_strain ss ON ss.id = sfp.strain_id-->
<!--        LEFT JOIN sys_land sl ON sl.id = sfp.land_id-->
<!--        WHERE-->
<!--        1 = 1-->
<!--        <if test="farmPlant.plant!=null and farmPlant.plant!=''">-->
<!--            and sfp.plant = #{farmPlant.plant}-->
<!--        </if>-->
<!--        <if test="farmPlant.year!=null and farmPlant.year!=''">-->
<!--            and sfp.create_time like concat('%',#{farmPlant.year},'%')-->
<!--        </if>-->
<!--        <if test="farmPlant.landId!=null and farmPlant.landId!=''">-->
<!--            and sfp.land_id = #{farmPlant.landId}-->
<!--        </if>-->
<!--        <if test="farmPlant.strainId!=null and farmPlant.strainId!=''">-->
<!--            and sfp.strain_id = #{farmPlant.strainId}-->
<!--        </if>-->
<!--        <if test="farmPlant.plantingWay!=null and farmPlant.plantingWay!=''">-->
<!--            and sfp.planting_way = #{farmPlant.plantingWay}-->
<!--        </if>-->
<!--        <if test="farmPlant.jobWay!=null and farmPlant.jobWay!=''">-->
<!--            and sfp.job_way = #{farmPlant.jobWay}-->
<!--        </if>-->
<!--        <if test="farmPlant.status!=null and farmPlant.status!=''">-->
<!--            and sfp.status = #{farmPlant.status}-->
<!--        </if>-->
<!--        <if test="farmPlant.strainName!=null and farmPlant.strainName!=''">-->
<!--            and ss.strain_name like concat('%',#{farmPlant.strainName},'%')-->
<!--        </if>-->
<!--        <if test="farmPlant.varieties!=null and farmPlant.varieties!=''">-->
<!--            and sfp.varieties like concat('%',#{farmPlant.varieties},'%')-->
<!--        </if>-->
<!--        <if test="farmPlant.startTime!=null and farmPlant.startTime!=''">-->
<!--            and sfp.transplan_time &gt;= #{farmPlant.startTime}-->
<!--        </if>-->
<!--        <if test="farmPlant.endTime!=null and farmPlant.endTime!=''">-->
<!--            and sfp.transplan_time &lt;= #{farmPlant.endTime}-->
<!--        </if>-->
<!--        <if test="farmPlant.deptId!=null and farmPlant.deptId!=''">-->
<!--            and sfp.dept_id = #{farmPlant.deptId}-->
<!--        </if>-->
<!--        <if test="farmPlant.tenantId!=null and farmPlant.tenantId!=''">-->
<!--            and sfp.tenant_id = #{farmPlant.tenantId}-->
<!--        </if>-->
<!--        <if test="farmPlant.farmId!=null and farmPlant.farmId!=''">-->
<!--            and sl.farm_id = #{farmPlant.farmId}-->
<!--        </if>-->
<!--        ORDER BY-->
<!--        sfp.id DESC-->
<!--        ) a-->
<!--        GROUP BY-->
<!--        a.strain_id,a.dept_id-->
        SELECT b.strain_id,b.strainName,SUM(b.area) AS area,b.url,b.tenant_id,b.dept_id FROM
        (
        SELECT
        a.strain_id,a.strainName,SUM(TRUNCATE(a.land_area,3)) area,a.url,a.tenant_id,a.dept_id,a.planting_way
        FROM
        (
        SELECT
        sfp.*,
        ss.strain_name strainName,
        ss.strain_name AS strainName,
        ss.url,
        sl.land_area area,
        sl.land_unit landUnit
        sl.land_name AS landName,
        land_unit AS landUnit,
        ( CASE WHEN land_unit = 2 THEN FORMAT(sl.land_area * 0.0015,3) WHEN land_unit = 1 THEN sl.land_area * 0.1 ELSE
        sl.land_area END ) land_area
        FROM
        sys_farm_plant sfp
        LEFT JOIN sys_strain ss ON ss.id = sfp.strain_id
        LEFT JOIN sys_land sl ON sl.id = sfp.land_id
        where 1=1
        WHERE
        1 = 1
        <if test="farmPlant.plant!=null and farmPlant.plant!=''">
            and sfp.plant = #{farmPlant.plant}
        </if>
        <if test="farmPlant.year!=null and farmPlant.year!=''">
            and sfp.create_time like concat('%',#{farmPlant.year},'%')
        </if>
        <if test="farmPlant.landId!=null and farmPlant.landId!=''">
            and sfp.land_id = #{farmPlant.landId}
        </if>
        <if test="farmPlant.strainId!=null and farmPlant.strainId!=''">
            and sfp.strain_id = #{farmPlant.strainId}
        </if>
        <if test="farmPlant.plantingWay!=null and farmPlant.plantingWay!=''">
            and sfp.planting_way = #{farmPlant.plantingWay}
        </if>
        <if test="farmPlant.jobWay!=null and farmPlant.jobWay!=''">
            and sfp.job_way = #{farmPlant.jobWay}
        </if>
        <if test="farmPlant.status!=null and farmPlant.status!=''">
            and sfp.status = #{farmPlant.status}
        </if>
        <if test="farmPlant.strainName!=null and farmPlant.strainName!=''">
            and ss.strain_name like concat('%',#{farmPlant.strainName},'%')
        </if>
        <if test="farmPlant.varieties!=null and farmPlant.varieties!=''">
            and sfp.varieties like concat('%',#{farmPlant.varieties},'%')
        </if>
        <if test="farmPlant.startTime!=null and farmPlant.startTime!=''">
            and sfp.transplan_time &gt;= #{farmPlant.startTime}
        </if>
        <if test="farmPlant.endTime!=null and farmPlant.endTime!=''">
            and sfp.transplan_time &lt;= #{farmPlant.endTime}
        </if>
        <if test="farmPlant.deptId!=null and farmPlant.deptId!=''">
            and sfp.dept_id = #{farmPlant.deptId}
        </if>
        <if test="farmPlant.tenantId!=null and farmPlant.tenantId!=''">
            and sfp.tenant_id = #{farmPlant.tenantId}
        </if>
        <if test="farmPlant.farmId!=null and farmPlant.farmId!=''">
            and sl.farm_id = #{farmPlant.farmId}
        </if>ORDER BY
        sfp.id
        DESC
        ) a
        GROUP BY
        a.strain_id,
        a.dept_id,
        a.tenant_id,
        a.planting_way HAVING planting_way !=2
        ) b
        GROUP BY
        b.strain_id,
        b.dept_id,
        b.tenant_id
    </select>
    <select id="getFarmPlantYMList" resultType="org.springblade.modules.farmplant.vo.FarmPlantVO">
        SELECT
        a.strain_id,a.strainName,SUM(TRUNCATE(a.land_area,3)) area,a.url,a.tenant_id,a.dept_id,a.planting_way
        FROM
        (
        SELECT
        sfp.*,
        ss.strain_name AS strainName,
        ss.url,
        sl.land_name AS landName,
        land_unit AS landUnit,
        ( CASE WHEN land_unit = 2 THEN FORMAT(sl.land_area * 0.0015,3) WHEN land_unit = 1 THEN sl.land_area * 0.1 ELSE sl.land_area END ) land_area
        FROM
        sys_farm_plant sfp
        LEFT JOIN sys_strain ss ON ss.id = sfp.strain_id
        LEFT JOIN sys_land sl ON sl.id = sfp.land_id
        WHERE
        1 = 1
        <if test="farmPlant.plant!=null and farmPlant.plant!=''">
            and sfp.plant = #{farmPlant.plant}
        </if>
        <if test="farmPlant.year!=null and farmPlant.year!=''">
            and sfp.create_time like concat('%',#{farmPlant.year},'%')
        </if>
        <if test="farmPlant.landId!=null and farmPlant.landId!=''">
            and sfp.land_id = #{farmPlant.landId}
        </if>
        <if test="farmPlant.strainId!=null and farmPlant.strainId!=''">
            and sfp.strain_id = #{farmPlant.strainId}
        </if>
        <if test="farmPlant.plantingWay!=null and farmPlant.plantingWay!=''">
            and sfp.planting_way = #{farmPlant.plantingWay}
        </if>
        <if test="farmPlant.jobWay!=null and farmPlant.jobWay!=''">
            and sfp.job_way = #{farmPlant.jobWay}
        </if>
        <if test="farmPlant.status!=null and farmPlant.status!=''">
            and sfp.status = #{farmPlant.status}
        </if>
        <if test="farmPlant.strainName!=null and farmPlant.strainName!=''">
            and ss.strain_name like concat('%',#{farmPlant.strainName},'%')
        </if>
        <if test="farmPlant.varieties!=null and farmPlant.varieties!=''">
            and sfp.varieties like concat('%',#{farmPlant.varieties},'%')
        </if>
        <if test="farmPlant.startTime!=null and farmPlant.startTime!=''">
            and sfp.transplan_time &gt;= #{farmPlant.startTime}
        </if>
        <if test="farmPlant.endTime!=null and farmPlant.endTime!=''">
            and sfp.transplan_time &lt;= #{farmPlant.endTime}
        </if>
        <if test="farmPlant.deptId!=null and farmPlant.deptId!=''">
            and sfp.dept_id = #{farmPlant.deptId}
        </if>
@@ -335,6 +696,11 @@
        <if test="farmPlant.farmId!=null and farmPlant.farmId!=''">
            and sl.farm_id = #{farmPlant.farmId}
        </if>
        ORDER BY
        sfp.id DESC
        ) a
        GROUP BY
        a.strain_id,a.dept_id,a.tenant_id,a.planting_way HAVING planting_way !=0 AND planting_way !=1
    </select>
</mapper>