广丰卷烟厂数采质量分析系统
baoshiwei
13 小时以前 d143af7023cfd4a0ced6f0ecf04ae3b3a06fd1dc
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?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.dromara.qa.md.mapper.WeighingBoxMapper">
 
    <resultMap type="org.dromara.qa.md.domain.WeighingBox" id="WeighingBoxResult">
        <id property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="code" column="code"/>
        <result property="weight" column="weight"/>
        <result property="unit" column="unit"/>
        <result property="location" column="location"/>
        <result property="calibCycleDays" column="calib_cycle_days"/>
        <result property="remindDays" column="remind_days"/>
        <result property="lastCalibDate" column="last_calib_date"/>
        <result property="nextCalibDate" column="next_calib_date"/>
        <result property="activeStatus" column="active_status"/>
        <result property="description" column="description"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
 
    <sql id="selectWeighingBoxVo">
        select id, name, code, weight, unit, location, calib_cycle_days, remind_days, last_calib_date, next_calib_date, active_status, description, del_flag, create_by, create_time, update_by, update_time from qm_weighing_box
    </sql>
 
    <select id="selectPageList" resultType="org.dromara.qa.md.domain.WeighingBox">
        <include refid="selectWeighingBoxVo"/>
        <where>
            del_flag = '0'
            <if test="weighingBox.name != null and weighingBox.name != ''">
                and name like concat('%', #{weighingBox.name}, '%')
            </if>
            <if test="weighingBox.code != null and weighingBox.code != ''">
                and code like concat('%', #{weighingBox.code}, '%')
            </if>
            <if test="weighingBox.activeStatus != null">
                and active_status = #{weighingBox.activeStatus}
            </if>
        </where>
        order by create_time desc
    </select>
 
    <select id="selectWeighingBoxList" parameterType="org.dromara.qa.md.domain.WeighingBox" resultMap="WeighingBoxResult">
        <include refid="selectWeighingBoxVo"/>
        <where>
            <if test="delFlag != null">
                and del_flag = #{delFlag}
            </if>
            <if test="name != null and name != ''">
                and name like concat('%', #{name}, '%')
            </if>
            <if test="code != null and code != ''">
                and code like concat('%', #{code}, '%')
            </if>
            <if test="location != null and location != ''">
                and location like concat('%', #{location}, '%')
            </if>
            <if test="activeStatus != null">
                and active_status = #{activeStatus}
            </if>
        </where>
        order by create_time desc
    </select>
 
    <select id="selectActiveWeighingBoxes" resultMap="WeighingBoxResult">
        <include refid="selectWeighingBoxVo"/>
        where del_flag = 0 and active_status = 1
    </select>
 
    <update id="batchUpdateStatus">
        update qm_weighing_box set active_status = #{activeStatus} where id in
        <foreach collection="boxIds" item="id" open="(" separator="," close=")">
            ${id}
        </foreach>
    </update>
 
    <update id="batchUpdateCalibConfig">
        update qm_weighing_box set calib_cycle_days = #{calibCycleDays}, remind_days = #{remindDays} where id in
        <foreach collection="boxIds" item="id" open="(" separator="," close=")">
            ${id}
        </foreach>
    </update>
 
    <!-- 带校准状态过滤的查询 -->
    <select id="selectWeighingBoxListWithCalibStatus" parameterType="org.dromara.qa.md.domain.WeighingBox" resultMap="WeighingBoxResult">
        select * from (
            select 
                id, name, code, weight, unit, location, calib_cycle_days, remind_days, 
                last_calib_date, next_calib_date, active_status, description, 
                del_flag, create_by, create_time, update_by, update_time,
                case 
                    when next_calib_date is null then 'unset'
                    when current_date > next_calib_date then 'overdue'
                    when current_date + interval '1 day' * remind_days >= next_calib_date then 'warning'
                    else 'normal'
                end as calib_status
            from qm_weighing_box
            where del_flag = 0
        ) as box
        where 1=1
        <if test="name != null and name != ''">
            and box.name like concat('%', #{name}, '%')
        </if>
        <if test="code != null and code != ''">
            and box.code like concat('%', #{code}, '%')
        </if>
        <if test="location != null and location != ''">
            and box.location like concat('%', #{location}, '%')
        </if>
        <if test="activeStatus != null">
            and box.active_status = #{activeStatus}
        </if>
        <if test="calibStatus != null and calibStatus != ''">
            and box.calib_status = #{calibStatus}
        </if>
        order by box.create_time desc
    </select>
 
    <!-- 带校准状态过滤的计数 -->
    <select id="selectWeighingBoxCountWithCalibStatus" parameterType="org.dromara.qa.md.domain.WeighingBox" resultType="java.lang.Long">
        select count(*) from (
            select
        id, name, code, weight, unit, location, calib_cycle_days, remind_days,
        last_calib_date, next_calib_date, active_status, description,
        del_flag, create_by, create_time, update_by, update_time,
                case 
                    when next_calib_date is null then 'unset'
                    when current_date > next_calib_date then 'overdue'
                    when current_date + interval '1 day' * remind_days >= next_calib_date then 'warning'
                    else 'normal'
                end as calib_status
            from qm_weighing_box
            where del_flag = 0
        ) as box
        where 1=1
        <if test="name != null and name != ''">
            and box.name like concat('%', #{name}, '%')
        </if>
        <if test="code != null and code != ''">
            and box.code like concat('%', #{code}, '%')
        </if>
        <if test="location != null and location != ''">
            and box.location like concat('%', #{location}, '%')
        </if>
        <if test="activeStatus != null">
            and box.active_status = #{activeStatus}
        </if>
        <if test="calibStatus != null and calibStatus != ''">
            and box.calib_status = #{calibStatus}
        </if>
    </select>
 
</mapper>