yangys
2024-09-27 26f8e5990686bdba2119024a260d986266506757
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
159
160
161
162
163
164
165
166
167
168
169
170
171
<?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="com.qianwen.mdc.mapper.MachiningDataNcMapper">
  <resultMap id="BaseResultMap" type="com.qianwen.mdc.domain.MachiningDataNc">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="machine_id" jdbcType="INTEGER" property="machineId" />
    <result column="start_time" jdbcType="INTEGER" property="startTime" />
    <result column="end_time" jdbcType="INTEGER" property="endTime" />
    <result column="state" jdbcType="VARCHAR" property="state" />
  </resultMap>
  <!-- 机床状态分布,老方法,以后可能取消 -->
  <select id="getNCStateListBy" resultType="java.util.HashMap">
    select
      d.id,
      m.name name,
      d.start_time stateStart,
      d.end_time stateEnd,
      d.state,
      w.name workshopName,
      s.name sectionName,
      a.category
    from
      machining_data_nc_his d
      left join mdc_machine m on d.machine_id = m.id
      left join mdc_workshop w on m.workshop_id = w.id
      left join mdc_section s on m.section_id = s.id
      left join mdc_machine_account a on a.machine_id = m.id
    where
      (
        d.start_time &lt; #{startTime} and d.end_time &gt; #{startTime}
        or d.start_time BETWEEN #{startTime} and #{endTime}
      )
      and d.state != ""
    <if test="workshop != null and workshop != ''">
      and w.name = #{workshop}
    </if>
    <if test="section != null and section != ''">
      and s.name = #{section}
    </if>
    <if test="list !=null and list.size() > 0">
      and m.name in
      <foreach collection="list" open="(" separator="," close=")" item="machineName">
        #{machineName}
      </foreach>
    </if>
    union all
    select
      d.id,
      m.name name,
      d.start_time stateStart,
      d.end_time stateEnd,
      d.state,
      w.name workshopName,
      s.name sectionName,
      a.category
    from
      machining_data_nc d
      left join machine m on d.machine_id = m.id
      left join mdc_workshop w on m.workshop_id = w.id
      left join mdc_section s on m.section_id = s.id
      left join mdc_machine_account a on a.machine_id = m.id
    where
     (
       d.start_time &lt; #{startTime} and d.end_time &gt; #{startTime}
       or d.start_time BETWEEN #{startTime} and #{endTime}
     )
     and d.state != ""
    <if test="workshop != null and workshop != ''">
      and w.name = #{workshop}
    </if>
    <if test="section != null and section != ''">
      and s.name = #{section}
    </if>
    <if test="list !=null and list.size() > 0">
      and m.name in
      <foreach collection="list" open="(" separator="," close=")" item="machineName">
        #{machineName}
      </foreach>
    </if>
    order by sectionName asc, name asc, stateStart asc
  </select>
  
  <!-- 机床状态分布,yangys -->
  <select id="ncStateDistribute" resultType="com.qianwen.mdc.dto.NcDistributeResultDTO">
    select
      d.id,
      m.name name,
      d.start_time stateStart,
      d.end_time stateEnd,
      d.state,
      w.name workshopName,
      s.name sectionName,
      a.category
    from
      machining_data_nc_his d
      left join machine m on d.machine_id = m.id
      left join workshop w on m.workshop_id = w.id
      left join section s on m.section_id = s.id
      left join machine_account a on a.machine_id = m.id
    where
      (
        d.start_time &lt; #{startTime} and d.end_time &gt; #{startTime}
        or d.start_time BETWEEN #{startTime} and #{endTime}
      )
      and d.state &lt;&gt; ''
    <if test="workshopId != null">
      and m.workshop_id = #{workshopId}
    </if>
    <if test="sectionId != null">
      and m.section_id = #{sectionId}
    </if>
    <if test="machineIds != null">
      and m.id in
      <foreach collection="machineIds" open="(" separator="," close=")" item="machineId">
        #{machineId}
      </foreach>
    </if>
    union all
    select
      d.id,
      m.name name,
      d.start_time stateStart,
      d.end_time stateEnd,
      d.state,
      w.name workshopName,
      s.name sectionName,
      a.category
    from
      machining_data_nc d
      left join machine m on d.machine_id = m.id
      left join workshop w on m.workshop_id = w.id
      left join section s on m.section_id = s.id
      left join machine_account a on a.machine_id = m.id
    where
      (
        d.start_time &lt; #{startTime} and d.end_time &gt; #{startTime}
        or d.start_time BETWEEN #{startTime} and #{endTime}
      )
      and d.state &lt;&gt; ''
    <if test="workshopId != null">
      and m.workshop_id = #{workshopId}
    </if>
    <if test="sectionId != null">
      and m.section_id = #{sectionId}
    </if>
    <if test="machineIds != null">
      and m.id in
      <foreach collection="machineIds" open="(" separator="," close=")" item="machineId">
        #{machineId}
      </foreach>
    </if>
    order by stateStart asc
  </select>
  
  
  <select id="machineLastList" resultMap="BaseResultMap">
      select id,machine_id,start_time,end_time,state
 
       from machining_data_nc where machine_id=#{machineId} order by end_time desc limit 1
  </select>
  <!-- 
  <select id="machineLastListByTTTTime" resultMap="BaseResultMap">
      select id,machine_id,start_time,end_time,state
 
       from machining_data_nc where machine_id=#{machineId} order by end_time desc limit 1
  </select>
   -->
</mapper>