智慧农业后台管理
guoshilong
2022-08-22 32e81fa68cf76e2331eb88a2299ee0ecd8faa7b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.recovery.mapper.RecoveryMapper">
 
    <!--自定义查询采收记录分页数据-->
    <select id="selectRecoveryPage" resultType="org.springblade.modules.recovery.vo.RecoveryVO">
        select sr.*,sl.land_name landName,ss.strain_name strainName,user.real_name as realName from sys_recovery sr
        left join sys_land sl on sl.id = sr.land_id
        left join sys_strain ss on ss.id = sr.strain_id
        left join blade_user user ON user.id = sr.operator
        where 1=1
        <if test="recovery.strainName!=null and recovery.strainName!=''">
            and ss.strain_name like concat ('%',#{recovery.strainName},'%')
        </if>
        <if test="recovery.strainId!=null and recovery.strainId!=''">
            and sr.strain_id = #{recovery.strainId}
        </if>
        <if test="recovery.leaves!=null and recovery.leaves!=''">
            and sr.leaves = #{recovery.leaves}
        </if>
        <if test="recovery.landId!=null and recovery.landId!=''">
            and sr.land_id = #{recovery.landId}
        </if>
        <if test="recovery.jobWay!=null and recovery.jobWay!=''">
            and sr.job_way = #{recovery.jobWay}
        </if>
        <if test="recovery.operator!=null and recovery.operator!=''">
            and sr.operator = #{recovery.operator}
        </if>
        <if test="recovery.farmId != null and recovery.farmId != ''">
            and sl.farm_id = #{recovery.farmId}
        </if>
        <if test="recovery.tenantId!=null and recovery.tenantId!=''">
            and sr.tenant_id = #{recovery.tenantId}
        </if>
        ORDER BY sr.create_time DESC
    </select>
 
    <!--查询当前前缀已有的溯源码编号,取倒数7位的最大值-->
    <select id="getCodePreCount" resultType="java.lang.Integer">
        select ifnull(max(0+RIGHT(code,7)),0) from sys_traceability
        where code like concat('%', #{pre},'%')
    </select>
 
    <!--查询农产品采收记录信息-->
    <select id="getRecoveryDetail" resultType="org.springblade.modules.recovery.vo.RecoveryVO">
        select sr.id,sr.strain_id strainId,sr.land_id landId,sr.time,ss.strain_name strainName,ss.url,sr.farm_plant_id farmPlantId,
        case
           when sfp.plant = '0' then '有机'
           when sfp.plant = 1 then '绿色'
           when sfp.plant = 2 then '无公害'
           else '普通' end as lx,
        sl.farm_id farmId from sys_recovery sr
        left join sys_strain ss on sr.strain_id = ss.id
        left join sys_farm_plant sfp on sfp.id = sr.farm_plant_id
        left join sys_land sl on sl.id = sr.land_id
        where sr.id = #{recoveryId}
    </select>
    <select id="recoveryStatistics" resultType="org.springblade.modules.recovery.vo.RecoveryVO">
        SELECT sr.strain_id,SUM(sr.weight) AS weight,sr.dept_id,strain.strain_name,strain.url
        FROM sys_recovery sr
        LEFT JOIN sys_strain strain ON sr.strain_id = strain.id
        WHERE 1=1
        <if test="recovery.deptId !=null and recovery.deptId !=''">
            AND sr.dept_id = #{recovery.deptId}
        </if>
        <if test="recovery.startTime != null and recovery.startTime !=''">
            AND DATE_FORMAT(sr.create_time,'%Y-%m-%d') &gt;= #{recovery.startTime}
        </if>
        <if test="recovery.endTime != null and recovery.endTime !=''">
            and DATE_FORMAT(sr.create_time,'%Y-%m-%d') &lt;= #{recovery.endTime}
        </if>
        GROUP BY sr.strain_id
    </select>
    <select id="recoveryStatisticsx" resultType="org.springblade.modules.recovery.vo.RecoveryVO">
        SELECT sr.strain_id,SUM(sr.weight) AS weight,sr.dept_id,strain.strain_name,strain.url
        FROM sys_recovery sr
        LEFT JOIN sys_strain strain ON sr.strain_id = strain.id
        WHERE 1=1
        <if test="recovery.deptId !=null and recovery.deptId !=''">
            AND sr.dept_id = #{recovery.deptId}
        </if>
        <if test="recovery.startTime != null and recovery.startTime !=''">
            AND DATE_FORMAT(sr.create_time,'%Y-%m-%d') &gt;= #{recovery.startTime}
        </if>
        <if test="recovery.endTime != null and recovery.endTime !=''">
            and DATE_FORMAT(sr.create_time,'%Y-%m-%d') &lt;= #{recovery.endTime}
        </if>
        <if test="recovery.strainType != null and recovery.strainType !=''">
            AND strain.strain_type = #{recovery.strainType}
        </if>
        GROUP BY sr.strain_id
    </select>
</mapper>