ZengTao
2024-03-07 a836d3f2c7bfd818060a39b0432f0200301ce1a5
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package com.example.springboot.service;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import org.springframework.stereotype.Component;
 
import com.example.springboot.entity.Queue;
import com.example.springboot.entity.north_glass_buffer1;
@Component
public class JdbcConnections {
    /**
     * 数据库连接参数
     * driver,url,username,password
     */
    private static final String DRIVER = "com.mysql.jdbc.Driver";
    private static final String URL = "jdbc:mysql://localhost:3306/canadames";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "beibo.123/";
    
    private static Connection conn = null;
    private static PreparedStatement ps = null;
    private static ResultSet rs = null;
    
    public  north_glass_buffer1 selectGlass(int glassid) throws SQLException {
        conn = getConn();
        north_glass_buffer1 glass=new north_glass_buffer1();
        String sql = "select ordernumber from north_glass_buffer1 where glassid=?";
         ps = conn.prepareStatement(sql);
         ps.setInt(1, glassid);
         rs= ps.executeQuery();
         while (rs.next()) {
            glass.setordernumber(rs.getString("ordernumber"));
         }
         conn.close();
         return glass;
    }
 
    public  north_glass_buffer1 SelectGlassByGlassIdOrderIdFrameId(String glassid,String orderid,String frameid) throws SQLException {
        conn = getConn();
        north_glass_buffer1 north_glass_buffer1s=new north_glass_buffer1();
        String sql = "select * from north_glass_buffer1 where barcode=? or ordernumber=? or FrameBarcode=?";
         ps = conn.prepareStatement(sql);
         ps.setString(1, glassid);
         ps.setString(2, orderid);
         ps.setString(3, frameid);
         rs= ps.executeQuery();
         while (rs.next()) {
            north_glass_buffer1s.setId(rs.getInt("Id"));
            north_glass_buffer1s.setordernumber(rs.getString("ordernumber"));
            north_glass_buffer1s.setlistnumber(rs.getString("listnumber"));
            north_glass_buffer1s.setboxnumber(rs.getString("boxnumber"));
            north_glass_buffer1s.setbarcode(rs.getString("barcode"));
            north_glass_buffer1s.setglasslength(rs.getDouble("glasslength"));
            north_glass_buffer1s.setglassheight(rs.getDouble("glassheight"));
            north_glass_buffer1s.setglasslengthmm(rs.getDouble("glasslength_mm"));
            north_glass_buffer1s.setglassheightmm(rs.getDouble("glassheight_mm"));
            north_glass_buffer1s.setitemtype(rs.getString("itemtype"));
            north_glass_buffer1s.setslotnumber(rs.getString("slotnumber"));
            north_glass_buffer1s.setdatemodified(rs.getString("datemodified"));
            north_glass_buffer1s.setdatecreated(rs.getString("datecreated"));
            north_glass_buffer1s.setFrameBarcode(rs.getString("FrameBarcode"));
         }
        //  conn.close();
         return north_glass_buffer1s;
    }
    //根据玻璃id,订单id,铝框id查询客户玻璃信息
    public  Queue SelectGlassByGlassIdOrderIdFrameIdQueue(String glassid,String orderid,String frameid) throws SQLException {
        conn = getConn();
        Queue queue=new Queue();
        String sql = "select * from north_glass_buffer1 where barcode=? or ordernumber=? or FrameBarcode=?";
         ps = conn.prepareStatement(sql);
         ps.setString(1, glassid);
         ps.setString(2, orderid);
         ps.setString(3, frameid);
         rs= ps.executeQuery();
         while (rs.next()) {
            queue.setid(rs.getInt("Id"));
            queue.setorderId(rs.getString("ordernumber"));
            queue.setlistId(rs.getString("listnumber"));
            queue.setboxId(rs.getString("boxnumber"));
            queue.setglassId(rs.getString("barcode"));
            queue.setglasswidthmm(rs.getDouble("glasslength"));
            queue.setglassheightmm(rs.getDouble("glassheight"));
            queue.setglasswidth(rs.getDouble("glasslength_mm"));
            queue.setglassheight(rs.getDouble("glassheight_mm"));
            // queue.setitemtype(rs.getString("itemtype"));
            // queue.setslotnumber(rs.getString("slotnumber"));
            // queue.setdatemodified(rs.getString("datemodified"));
            // queue.setdatecreated(rs.getString("datecreated"));
            // queue.setFrameBarcode(rs.getString("FrameBarcode"));
         }
         conn.close();
         return queue;
    }
 
    
 
    //根据玻璃id,订单id,铝框id查询客户玻璃信息
    public  List<north_glass_buffer1> SelectGlassByGlassIdOrderIdFrameIds(String glassid,String orderid,String frameid) throws SQLException {
        conn = getConn();
        // north_glass_buffer1 glass=new north_glass_buffer1();
        List<north_glass_buffer1> glass=new ArrayList<north_glass_buffer1>();
        String sql = "select * from north_glass_buffer1 where position(? in barcode) and position(? in ordernumber) and position(? in FrameBarcode)";
         ps = conn.prepareStatement(sql);
         ps.setString(1, glassid);
         ps.setString(2, orderid);
         ps.setString(3, frameid);
         rs= ps.executeQuery();
         while (rs.next()) {
            north_glass_buffer1 north_glass_buffer1s=new north_glass_buffer1();
 
            north_glass_buffer1s.setId(rs.getInt("Id"));
            north_glass_buffer1s.setordernumber(rs.getString("ordernumber"));
            north_glass_buffer1s.setlistnumber(rs.getString("listnumber"));
            north_glass_buffer1s.setboxnumber(rs.getString("boxnumber"));
            north_glass_buffer1s.setbarcode(rs.getString("barcode"));
            north_glass_buffer1s.setglasslength(rs.getDouble("glasslength"));
            north_glass_buffer1s.setglassheight(rs.getDouble("glassheight"));
            north_glass_buffer1s.setglasslengthmm(rs.getDouble("glasslength_mm"));
            north_glass_buffer1s.setglassheightmm(rs.getDouble("glassheight_mm"));
            north_glass_buffer1s.setitemtype(rs.getString("itemtype"));
            north_glass_buffer1s.setslotnumber(rs.getString("slotnumber"));
            north_glass_buffer1s.setdatemodified(rs.getString("datemodified"));
            north_glass_buffer1s.setdatecreated(rs.getString("datecreated"));
            north_glass_buffer1s.setFrameBarcode(rs.getString("FrameBarcode"));
 
 
            glass.add(north_glass_buffer1s);
            
         }
         conn.close();
         return glass;
    }
 
    //根据铝框id查询客户玻璃信息
    public  List<north_glass_buffer1> SelectGlassByGlassIdOrderIdFrameIdss(String frameid) throws SQLException {
        conn = getConn();
        // north_glass_buffer1 glass=new north_glass_buffer1();
        List<north_glass_buffer1> glass=new ArrayList<north_glass_buffer1>();
        String sql = "select * from north_glass_buffer1 where FrameBarcode=?";
         ps = conn.prepareStatement(sql);
         ps.setString(1, frameid);
         rs= ps.executeQuery();
         while (rs.next()) {
            north_glass_buffer1 north_glass_buffer1s=new north_glass_buffer1();
 
            north_glass_buffer1s.setId(rs.getInt("Id"));
            north_glass_buffer1s.setordernumber(rs.getString("ordernumber"));
            north_glass_buffer1s.setlistnumber(rs.getString("listnumber"));
            north_glass_buffer1s.setboxnumber(rs.getString("boxnumber"));
            north_glass_buffer1s.setbarcode(rs.getString("barcode"));
            north_glass_buffer1s.setglasslength(rs.getDouble("glasslength"));
            north_glass_buffer1s.setglassheight(rs.getDouble("glassheight"));
            north_glass_buffer1s.setglasslengthmm(rs.getDouble("glasslength_mm"));
            north_glass_buffer1s.setglassheightmm(rs.getDouble("glassheight_mm"));
            north_glass_buffer1s.setitemtype(rs.getString("itemtype"));
            north_glass_buffer1s.setslotnumber(rs.getString("slotnumber"));
            north_glass_buffer1s.setdatemodified(rs.getString("datemodified"));
            north_glass_buffer1s.setdatecreated(rs.getString("datecreated"));
            north_glass_buffer1s.setFrameBarcode(rs.getString("FrameBarcode"));
 
 
            glass.add(north_glass_buffer1s);
            
         }
         conn.close();
         return glass;
    }
 
    //根据铝框id查询l铝框是否翻转
    public String SelectFlipByFrameBarcode(String frameBarcode) throws SQLException {
        conn = getConn();
        // north_glass_buffer1 glass=new north_glass_buffer1();
        String flip="";
        String sql1 = "select * from north_glass_buffer1_frames where Barcode=? limit 1";
         ps = conn.prepareStatement(sql1);
         ps.setString(1, frameBarcode);
         rs= ps.executeQuery();
         while (rs.next()) {
            flip=rs.getString("Flip");
            
         }
         conn.close();
         return flip;
    }
    //根据铝框id查询是否铝框摆放
    public String SelectPositionByFrameBarcode(String frameBarcode) throws SQLException {
           conn = getConn();
        // north_glass_buffer1 glass=new north_glass_buffer1();
        String position="";
        String sql1 = "select * from north_glass_buffer1_frames where Barcode=? limit 1";
         ps = conn.prepareStatement(sql1);
         ps.setString(1, frameBarcode);
         rs= ps.executeQuery();
         while (rs.next()) {
            position=rs.getString("position");
         }
         conn.close();
         return position;
    }
 
    //根据铝框id查询铝框宽
    public String SelectFrameLengthByFrameBarcode(String frameBarcode) throws SQLException {
           conn = getConn();
        // north_glass_buffer1 glass=new north_glass_buffer1();
        String position="";
        String sql1 = "select * from north_glass_buffer1_frames where Barcode=? limit 1";
         ps = conn.prepareStatement(sql1);
         ps.setString(1, frameBarcode);
         rs= ps.executeQuery();
         while (rs.next()) {
            position=rs.getString("framelength");
         }
         conn.close();
         return position;
    }
 
    //根据铝框id查询铝框高
    public String SelectFrameHeightByFrameBarcode(String frameBarcode) throws SQLException {
           conn = getConn();
        // north_glass_buffer1 glass=new north_glass_buffer1();
        String position="";
        String sql1 = "select * from north_glass_buffer1_frames where Barcode=? limit 1";
         ps = conn.prepareStatement(sql1);
         ps.setString(1, frameBarcode);
         rs= ps.executeQuery();
         while (rs.next()) {
            position=rs.getString("frameheight");
         }
         conn.close();
         return position;
    }
    
    /**
     * 1. 加载驱动
     * 2. 获取连接    conn
     * 3. 创建语句 ps
     * 4. 执行语句 rs
     * 5. 处理结果
     * 6. 回收资源
     * 
     * 实现CRUD
     *     更新:
     *         1增加
     *         2删除
     *         3修改
     *  查询:
     *      1. 查一个,一个对象
     *      2. 查一组,做成一个对象列表,查全部
     */
    public static Connection getConn() throws SQLException {
        Connection conn = null;
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/canadames?serverTimezone=GMT%2B8&characterEncoding=utf-8", "root", "beibo.123/");
        return conn;
    }
 
    static {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
 
    
 
 
 
}