#
18516761980
2022-07-25 2c37b04bc0e5e2eae772166f514ff67113668f17
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
package com.slcf.controller;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.slcf.pojo.UserBean;
import com.slcf.pojo.WorkMastBean;
import com.slcf.bean.LocDetailCondition;
import com.slcf.pojo.LocationBean;
import com.slcf.pojo.StationBean;
import com.slcf.pojo.SysLogBean;
import com.slcf.service.WaitPakInService;
import com.slcf.service.WorkFileService;
import com.slcf.service.WorkNoService;
import com.slcf.util.AuthorityCode;
import com.slcf.util.CommonMethod;
import com.slcf.util.DateTimeUtil;
import com.slcf.service.CrnService;
import com.slcf.service.LocDetailService;
import com.slcf.service.LocationService;
import com.slcf.service.MatCodeService;
import com.slcf.service.OperateService;
import com.slcf.service.RoleService;
import com.slcf.service.RowNoService;
import com.slcf.service.StaDescService;
import com.slcf.service.StationService;
import com.slcf.service.SysLogService;
 
/**
 * 空托盘控制器层
 * @author admin
 * @date 2018年12月4日
 */
@Controller
@RequestMapping("/work")
public class EmptyController {
 
    @Resource
    WaitPakInService waitPakInService;
    @Autowired
    SysLogService sysLogService;
    @Autowired
    MatCodeService matCodeService;
    @Autowired
    StaDescService staDescService;
    @Autowired
    StationService stationService;
    @Autowired
    WorkNoService workNoService;
    @Autowired
    WorkFileService workFileService;
    @Autowired
    RowNoService rowNoService;
    @Autowired
    LocationService locationService;
    @Autowired
    CrnService crnService;
    @Autowired
    OperateService operateService;
    @Autowired
    LocDetailService locDetailService;
    @Autowired
    RoleService roleService;
    
    @RequestMapping("/goEmptyIn.action")
    public String goEmptyInPage(HttpServletRequest request){
        try {
            String rid = request.getSession().getAttribute("ROLEID").toString();
            String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid), 
                    AuthorityCode.EmptyInCode);
            request.getSession().setAttribute("AUTHCODE",authCode);
            // 插入日志
            UserBean user = (UserBean) request.getSession().getAttribute("USER");
            SysLogBean sysLog = new SysLogBean();
            sysLog.setLogin_no(user.getUser_account());
            sysLog.setMachine_ip(request.getRemoteAddr());
            sysLog.setForm_no("goEmptyIn.action");
            sysLog.setTts_keyname("访问空托盘入库");
            sysLog.setModi_user(user.getUser_account());
            sysLogService.insertSysLog(sysLog);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return "emptyIn";
    }
    
    @RequestMapping("/goEmptyOut.action")
    public String goEmptyOutPage(HttpServletRequest request){
        try {
            String rid = request.getSession().getAttribute("ROLEID").toString();
            String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid), 
                    AuthorityCode.EmptyOutCode);
            request.getSession().setAttribute("AUTHCODE",authCode);
            // 插入日志
            UserBean user = (UserBean) request.getSession().getAttribute("USER");
            SysLogBean sysLog = new SysLogBean();
            sysLog.setLogin_no(user.getUser_account());
            sysLog.setMachine_ip(request.getRemoteAddr());
            sysLog.setForm_no("goEmptyOut.action");
            sysLog.setTts_keyname("访问空托盘出库");
            sysLog.setModi_user(user.getUser_account());
            sysLogService.insertSysLog(sysLog);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return "emptyOut";
    }
    
    @RequestMapping("/goLocMove.action")
    public String goLocMovePage(HttpServletRequest request){
        try {
            String rid = request.getSession().getAttribute("ROLEID").toString();
            String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid), 
                    AuthorityCode.LocMoveCode);
            request.getSession().setAttribute("AUTHCODE",authCode);
            // 插入日志
            UserBean user = (UserBean) request.getSession().getAttribute("USER");
            SysLogBean sysLog = new SysLogBean();
            sysLog.setLogin_no(user.getUser_account());
            sysLog.setMachine_ip(request.getRemoteAddr());
            sysLog.setForm_no("goLocMove.action");
            sysLog.setTts_keyname("访问库位移转");
            sysLog.setModi_user(user.getUser_account());
            sysLogService.insertSysLog(sysLog);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return "locMove";
    }
    
    @RequestMapping("/goLocCheck.action")
    public String goLocCheckPage(HttpServletRequest request){
        try {
            String rid = request.getSession().getAttribute("ROLEID").toString();
            String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid), 
                    AuthorityCode.LocCheckCode);
            request.getSession().setAttribute("AUTHCODE",authCode);
            // 插入日志
            UserBean user = (UserBean) request.getSession().getAttribute("USER");
            SysLogBean sysLog = new SysLogBean();
            sysLog.setLogin_no(user.getUser_account());
            sysLog.setMachine_ip(request.getRemoteAddr());
            sysLog.setForm_no("goLocCheck.action");
            sysLog.setTts_keyname("访问库存盘点");
            sysLog.setModi_user(user.getUser_account());
            sysLogService.insertSysLog(sysLog);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return "locCheck";
    }
    ////////////////////////////////////////////////////////////////////////////
    /**
     * 空托盘入库启动
     * @return
     */
    @ResponseBody
    @RequestMapping("/emptyStoreIn.action")
    public Map<String,Object> emptyStoreIn(
            @RequestParam("stn_no")int stn_no,HttpServletRequest request) throws Exception{
        Map<String,Object> map=new HashMap<String, Object>();
        try {
            CommonMethod commonMethod = new CommonMethod(workFileService,workNoService,crnService,
                    stationService,locationService,rowNoService,staDescService);
            
            UserBean user=(UserBean)request.getSession().getAttribute("USER");
            WorkMastBean workMast = new WorkMastBean();
            
            //判断站点是否正常
            StationBean station = stationService.queryStationById(stn_no);
            Map<String,Object> mapStation = commonMethod.checkStationStatus(station);
            if((Integer)mapStation.get("code")==1) {
                map.put("code", 1);
                map.put("msg", mapStation.get("msg"));
                return map;
            }
            
            int wrk_no = commonMethod.getNewWorkNo(workNoService.queryWorkNoById(0));
            if(wrk_no<=0) {
                map.put("code", 1);
                map.put("msg", "生成工作号失败,请联系管理员");
                return map;
            }else {
                WorkMastBean workFile = workFileService.queryWorkMastById(wrk_no);
                if(workFile!=null) {
                    map.put("code", 1);
                    map.put("msg", "生成工作号" + wrk_no + "在工作档中已存在");
                    return map;
                }
            }
            
            String loc_no = "";
            loc_no = commonMethod.getLocNo(10, rowNoService.queryRowNoById(1), stn_no, station.getCtn_type());
            if(loc_no.equals("")) {
                map.put("code", 1);
                map.put("msg", "查询可用库位失败,请检查堆垛机、设备状态");
                return map;
            }
            int crn_no = Integer.parseInt(loc_no.substring(0,2));
            crn_no = (crn_no+1) / 2;
            int e_staNo = commonMethod.getIoStaNo(10, crn_no, stn_no);
            if(e_staNo<=0) {
                map.put("code", 1);
                map.put("msg", "获取堆垛机站点失败");
                return map;
            }
            String io_time = DateTimeUtil.getStringDateTime(19);
            workMast.setWrk_no(wrk_no);
            workMast.setIo_time(io_time);
            workMast.setWrk_sts(1);
            workMast.setIo_type(10);
            workMast.setIo_pri(10);
            workMast.setCrn_no(crn_no);
            workMast.setSource_sta_no(stn_no);
            workMast.setSta_no(e_staNo);
            workMast.setLoc_no(loc_no);
            workMast.setFull_plt("N");
            workMast.setPicking("N");
            workMast.setExit_mk("N");
            workMast.setEmpty_mk("Y");
            workMast.setLink_mis("N");
            workMast.setModi_user(user.getUser_account());
            
            map = operateService.insertEmptyStoreIn(workMast, station, user);
            
            if((Integer)map.get("code")==0) {
                // 插入日志
//                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("emptyStoreIn.action");
                sysLog.setTts_keyname("启动空板入库:" + workMast.getWrk_no() + "-" + workMast.getLoc_no());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(RuntimeException e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 空托盘出库启动
     * @return
     */
    @ResponseBody
    @RequestMapping("/emptyRetrieve.action")
    public Map<String,Object> emptyRetrieve(@RequestParam("ids")String[] ids,
            @RequestParam("stn_no")int stn_no,HttpServletRequest request) throws Exception{
        Map<String,Object> map=new HashMap<String, Object>();
        try {
            CommonMethod commonMethod = new CommonMethod(workFileService,workNoService,crnService,
                    stationService,locationService,rowNoService,staDescService);
            
            UserBean user=(UserBean)request.getSession().getAttribute("USER");
            WorkMastBean workMast = new WorkMastBean();
            
//            workMast.setWrk_no(wrk_no);
//            workMast.setIo_time(io_time);
            workMast.setWrk_sts(11);
            workMast.setIo_type(110);
            workMast.setIo_pri(13);
            workMast.setSta_no(stn_no);
//            workMast.setCrn_no(crn_no);
//            workMast.setSource_sta_no(stn_no);
//            workMast.setSta_no(e_staNo);
//            workMast.setLoc_no(loc_no);
            workMast.setFull_plt("N");
            workMast.setPicking("N");
            workMast.setExit_mk("N");
            workMast.setEmpty_mk("Y");
            workMast.setLink_mis("N");
            workMast.setModi_user(user.getUser_account());
            
            map = operateService.insertemptyRetrieve(workMast, ids, stn_no, user, commonMethod);
            
            if((Integer)map.get("code")==0) {
                // 插入日志
//                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("emptyRetrieve.action");
                sysLog.setTts_keyname("启动空托盘出库:" + workMast.getWrk_no() + "-" + workMast.getLoc_no());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(RuntimeException e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    //////////////////////库位移转///////////////////////////////////////////
    @ResponseBody
    @RequestMapping("/locDetlList.action")
    public Map<String,Object> querylocDetlListByPages(LocDetailCondition locDetailCon){
        Map<String,Object> map = new HashMap<String, Object>();
        if(locDetailCon.getLoc_no()==null || locDetailCon.getLoc_no().equals("")) {
            return map;
        }
        map=locDetailService.queryLocDetailList(locDetailCon);
        return map;
    }
    
    /**
     * 检查旧库位状态
     * @param loc_no
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkOldLoc.action")
    public Map<String,Object> checkOldLoc(@RequestParam("loc_no")String loc_no){        
        Map<String,Object> map=new HashMap<String, Object>();
        try {
            LocationBean location = locationService.queryLocationById(loc_no);
            if(location!=null){
                if(location.getLoc_sts().equals("F") || location.getLoc_sts().equals("D")) {
                    map.put("msg", "库位可用");
                }else {
                    map.put("msg", "库位不是在库状态");
                }
            }else{
                map.put("msg", "库位不存在");
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 检查旧库位状态
     * @param loc_no
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkNewLoc.action")
    public Map<String,Object> checkNewLoc(@RequestParam("loc_no")String loc_no){        
        Map<String,Object> map=new HashMap<String, Object>();
        try {
            LocationBean location = locationService.queryLocationById(loc_no);
            if(location!=null){
                if(location.getLoc_sts().equals("O")) {
                    map.put("msg", "库位可用");
                }else {
                    map.put("msg", "库位不是空库位状态");
                }
            }else{
                map.put("msg", "库位不存在");
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 库位移转
     * @return
     */
    @ResponseBody
    @RequestMapping("/locMove.action")
    public Map<String,Object> locMove(@RequestParam("old_loc_no")String old_loc_no,
            @RequestParam("new_loc_no")String new_loc_no,HttpServletRequest request) throws Exception{
        Map<String,Object> map=new HashMap<String, Object>();
        try {
            CommonMethod commonMethod = new CommonMethod(workFileService,workNoService,crnService,
                    stationService,locationService,rowNoService,staDescService);
            
            UserBean user=(UserBean)request.getSession().getAttribute("USER");
            WorkMastBean workMast = new WorkMastBean();
            
            String emptyMk = "N";
            LocationBean location = locationService.queryLocationById(old_loc_no);
            if(location!=null) {
                String loc_sts = location.getLoc_sts();
                if(loc_sts.equals("D")) {
                    emptyMk="Y";
                }
            }
            
            int wrk_no = commonMethod.getNewWorkNo(workNoService.queryWorkNoById(0));
            if(wrk_no<=0) {
                map.put("code", 1);
                map.put("msg", "生成工作号失败,请联系管理员");
                return map;
            }else {
                WorkMastBean workFile = workFileService.queryWorkMastById(wrk_no);
                if(workFile!=null) {
                    map.put("code", 1);
                    map.put("msg", "生成工作号" + wrk_no + "在工作档中已存在");
                    return map;
                }
            }
            
            int crn_no = Integer.parseInt(old_loc_no.substring(0,2));
            crn_no = (crn_no+1)/2;
//            int e_staNo = commonMethod.getIoStaNo(crn_no,"I",stn_no);
            String io_time = DateTimeUtil.getStringDateTime(19);
            workMast.setWrk_no(wrk_no);
            workMast.setIo_time(io_time);
            workMast.setWrk_sts(11);
            workMast.setIo_type(11);
            workMast.setIo_pri(10);
            workMast.setCrn_no(crn_no);
//            workMast.setSource_sta_no(stn_no);
//            workMast.setSta_no(e_staNo);
            workMast.setSource_loc_no(old_loc_no);
            workMast.setLoc_no(new_loc_no);
            workMast.setFull_plt("N");
            workMast.setPicking("N");
            workMast.setExit_mk("N");
            workMast.setEmpty_mk(emptyMk);
            workMast.setLink_mis("N");
            workMast.setModi_user(user.getUser_account());
            
            map = operateService.insertLocMove(workMast, old_loc_no, new_loc_no, user);
            
            if((Integer)map.get("code")==0) {
                // 插入日志
//                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("locMove.action");
                sysLog.setTts_keyname("启动库位移转:" + workMast.getWrk_no() + "-" + workMast.getLoc_no());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(RuntimeException e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    ////////////////////////////////库存盘点//////////////////////////
    /**
     * 检查旧库位状态
     * @param loc_no
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkChkLoc.action")
    public Map<String,Object> checkChkLoc(@RequestParam("loc_no")String loc_no){        
        Map<String,Object> map=new HashMap<String, Object>();
        try {
            LocationBean location = locationService.queryLocationById(loc_no);
            if(location!=null){
                if(location.getLoc_sts().equals("F")) {
                    map.put("msg", "库位可用");
                }else {
                    map.put("msg", "库位不是在库状态");
                }
            }else{
                map.put("msg", "库位不存在");
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 盘点出库启动
     * @return
     */
    @ResponseBody
    @RequestMapping("/locCheck.action")
    public Map<String,Object> locCheck(@RequestParam("old_loc_no")String value,@RequestParam("chk_type")int chk_type,
            @RequestParam("stn_no")int stn_no,HttpServletRequest request) throws Exception{
        Map<String,Object> map=new HashMap<String, Object>();
        try {
            CommonMethod commonMethod = new CommonMethod(workFileService,workNoService,crnService,
                    stationService,locationService,rowNoService,staDescService);
            
            UserBean user=(UserBean)request.getSession().getAttribute("USER");
            String locs = "";
            switch(chk_type) {
                case 0:  //指定库位
                    map = operateService.insertLocCheck(value, stn_no, user, commonMethod);
                    break;
                case 1:  //全盘
                    locs = locationService.getLocationListBySts("F");
                    List<String> listLoc = Arrays.asList(locs.split(","));
                    
                    if(listLoc!=null && listLoc.size()>0) {
                        for(String loc_no : listLoc) {
                            map = operateService.insertLocCheck(loc_no, stn_no, user, commonMethod);
                        }
                    }else {
                        map.put("code", 1);
                        map.put("msg", "无在库资料");
                        return map;
                    }
                    break;
                case 2:  //百分比盘点
                    locs = locationService.getLocationListBySts("F");
                    String[] array = locs.split(",");
                    List<String> list = new ArrayList<String>(array.length); 
                    Collections.addAll(list, array);
//                    list = Arrays.asList(locs.split(","));  //静态list不能做增删操作
                    
                    int count = (list.size()*Integer.parseInt(value))/100;
                    List<String> arrayList = getListByQty(list,count);
                    if(arrayList!=null && arrayList.size()>0) {
                        for (String loc_no : arrayList) {
                            map = operateService.insertLocCheck(loc_no, stn_no, user, commonMethod);
                        }
                    }else {
                        map.put("code", 1);
                        map.put("msg", "无在库资料");
                        return map;
                    }
                    break;
            }
            
            if((Integer)map.get("code")==0) {
                // 插入日志
//                UserBean user = (UserBean) request.getSession().getAttribute("USER");
                SysLogBean sysLog = new SysLogBean();
                sysLog.setLogin_no(user.getUser_account());
                sysLog.setMachine_ip(request.getRemoteAddr());
                sysLog.setForm_no("locCheck.action");
                sysLog.setTts_keyname("启动盘点出库");
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(RuntimeException e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 从原list中随机获取指定数量元素的list
     * @param list
     * @param count
     * @return
     */
    private List<String> getListByQty(List<String> list, int count){
        List<String> result = new ArrayList<String>();
        try {
            Random r = new Random();
            int index = 0;
            for (int i = 0; i < count; i++) {
                index = r.nextInt(list.size() - i);
                result.add(list.get(index));
                list.remove(index);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    //测试代码
    public static void main(String[] args) {
        List<String> ids = new ArrayList<String>();
        ids.add("aa");
        ids.add("bb");
        ids.add("cc");
        ids.add("dd");
        ids.add("ee");
        ids.add("ff");
        Random r = new Random();
        List<String> ret = new ArrayList<String>();
        int index = 0;
        for (int i = 0; i < 2; i++) {
            index = r.nextInt(ids.size() - i);
            ret.add(ids.get(index));
            ids.remove(index);
        }
        for (String str : ret) {
            System.out.print(str + " ");
        }
    }
    
    
}