智慧农业后台管理
guoshilong
2022-09-03 a86b3b4258011a094cacf70c65bfacd535fd573b
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
95
96
97
98
99
100
101
102
103
104
105
106
<?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.processInv.mapper.ProcessInvMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="processInvResultMap" type="org.springblade.modules.processInv.vo.ProcessInvVO">
        <result column="id" property="id"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="strain_id" property="strainId"/>
        <result column="product_id" property="productId"/>
        <result column="product_inventory_num" property="productInventoryNum"/>
        <result column="machining_tp" property="tpurl"/>
        <result column="machining_type" property="processName"/>
        <result column="strain_name" property="strainName"/>
    </resultMap>
 
    <select id="selectProcessInvPage" resultMap="processInvResultMap">
        select inv.*,m.machining_tp,
               m.machining_type,strain_name
        from sys_process_inv inv
        LEFT JOIN sys_machining m ON m.id = inv.product_id
        LEFT JOIN sys_strain strain ON strain.id = inv.strain_id
        LEFT JOIN sys_farm_product_stock fps ON inv.fps_id = fps.id
        LEFT JOIN sys_land land ON land.id = fps.land_id
        where inv.is_deleted = 0
        <if test="processInv.fpsId != null and processInv.fpsId != ''">
            AND inv.fps_id = #{processInv.fpsId}
        </if>
        <if test="processInv.farmId != null and processInv.farmId !=''">
            AND land.farm_id = #{processInv.farmId}
        </if>
    </select>
 
    <select id="selectBySPId" resultType="org.springblade.modules.processInv.entity.ProcessInv">
        SELECT id,strain_id,product_id,product_inventory_num,create_time,update_user,update_time,status,is_deleted
        FROM sys_process_inv
        WHERE is_deleted = 0 AND strain_id = #{strainId} AND product_id = #{productId}
    </select>
 
    <select id="selectBySFId" resultType="org.springblade.modules.processInv.entity.ProcessInv">
        SELECT id,strain_id,product_id,product_inventory_num,create_time,update_user,update_time,status,is_deleted
        FROM sys_process_inv
        WHERE is_deleted = 0 AND strain_id = #{strainId} AND product_id = #{fpsId}
    </select>
 
    <insert id="add">
        INSERT INTO sys_process_inv (strain_id,product_id,product_inventory_num,create_time,status,is_deleted,fps_id)
        VALUES (#{processInv.strainId},#{processInv.productId},#{processInv.productInventoryNum},NOW(),1,0,#{processInv.fpsId})
    </insert>
 
    <select id="stockCompare" resultType="java.lang.Boolean">
        SELECT
            CASE
                WHEN
                    product_inventory_num >= #{saleNum} THEN
                    TRUE ELSE FALSE
                END result
        FROM
            sys_process_inv
        WHERE
            id = #{proid}
    </select>
 
    <update id="stockReduce">
        UPDATE sys_process_inv SET product_inventory_num = product_inventory_num - #{saleNum}
        WHERE
            id = #{proid}
    </update>
 
    <delete id="del">
        DELETE FROM sys_process_inv WHERE id = #{id}
    </delete>
 
    <select id="getLand" resultType="org.springblade.modules.processInv.vo.ProcessInvVO">
        SELECT inv.id,inv.fps_id,fps.land_id
        FROM sys_process_inv inv
        LEFT JOIN sys_farm_product_stock fps ON inv.fps_id = fps.id
        WHERE inv.is_deleted = 0
        <if test="processInv.id != null and processInv.id != ''">
            AND inv.id = #{processInv.id}
        </if>
    </select>
    <select id="findById" resultType="org.springblade.modules.processInv.entity.ProcessInv">
        SELECT id,strain_id,product_id,product_inventory_num,create_time,update_user,update_time,status,is_deleted
        FROM sys_process_inv
        WHERE is_deleted = 0 AND id = #{prodId}
    </select>
    <select id="statisticsStock" resultType="java.lang.Double">
        SELECT SUM(inv.product_inventory_num) as sum
        FROM sys_process_inv inv
        LEFT JOIN sys_farm_product_stock sfps ON sfps.id = inv.fps_id
        LEFT JOIN sys_land land ON land.id = sfps.land_id
        WHERE 1=1 AND inv.is_deleted = 0
        <if test="year!=null and year!=''">
            and YEAR ( inv.create_time ) = #{year}
        </if>
        <if test="farmId!=null and farmId!=''">
            and land.farm_id = #{farmId}
        </if>
    </select>
 
</mapper>