zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
package com.shlanbao.tzsc.pms.sch.workorder.controller;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
 
import com.shlanbao.tzsc.base.interceptor.PMSXmlDataInterceptor;
import com.shlanbao.tzsc.base.model.*;
import com.shlanbao.tzsc.data.webservice.client.SendMessageClient;
import com.shlanbao.tzsc.utils.tools.RedisUtil;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringEscapeUtils;
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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.shlanbao.tzsc.base.controller.BaseController;
import com.shlanbao.tzsc.pms.sch.workorder.beans.TransmitterOutput;
import com.shlanbao.tzsc.pms.sch.workorder.beans.TransmitterWorkOrderBean;
import com.shlanbao.tzsc.pms.sch.workorder.beans.WorkOrderBean;
import com.shlanbao.tzsc.pms.sch.workorder.service.WorkOrderServiceI;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 工单控制器
 * @author Leejean
 * @create 2014年11月18日下午2:23:51
 */
@Controller
@RequestMapping("/pms/workorder")
public class WorkOrderController extends BaseController {
    @Autowired
    private WorkOrderServiceI workOrderService;
    /**
     * 查询工单
     */
    @ResponseBody
    @RequestMapping("/getAllWorkOrders")
    public DataGrid getAllWorkOrders(WorkOrderBean workOrderBean,PageParams pageParams){
        try {
            workOrderBean.setParam("1,2,3");
            return workOrderService.getAllWorkOrders(workOrderBean,pageParams);
        } catch (Exception e) {
            log.error("查询工单异常", e);
        }
        return null;
    }
    /**
     * 张璐 2015.10.12
     * 查询成型车间工单
     */
    @ResponseBody
    @RequestMapping("/getFormingWorkOrders")
    public DataGrid getFormingWorkOrders(WorkOrderBean workOrderBean,PageParams pageParams){
        try {
            workOrderBean.setParam("4,5");
            return workOrderService.getAllWorkOrders(workOrderBean,pageParams);
        } catch (Exception e) {
            log.error("查询工单异常", e);
        }
        return null;
    }
    /**
     * 查看工单详情
     */
    @RequestMapping("/goToWorkOrderDetail")
    public String goToWorkOrderDetail(HttpServletRequest request,String id){
        request.setAttribute("workOrderId",id);
        return "/pms/sch/workorder/workorderDetail";
    }
    /**
     * 审核工单
     * @author wanchanghuang
     * @create 2018年2月1日8:58:13
     * @param id 工单ID
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkWorkOrderCX")
    public Json checkWorkOrderCX(HttpSession session,String id){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            if(info!=null){
                log.error("成型机单个审核!!!"+id+"  审核人:"+info.getUser().getName());
                String msg = workOrderService.checkWorkOrder(id);
                if (msg == null){
                    json.setSuccess(true);
                    json.setMsg("操作成功!");
                } else {
                    json.setSuccess(true);
                    json.setMsg("工单:"+msg+"非当日工单,无法审核!");
                }
            }else{
                json.setMsg("操作失败!");
            }
        } catch (Exception e) {
            log.error("审核工单失败", e);
            json.setMsg("审核工单失败!");
        }
        return json;
    }
    /**
     * 审核工单
     * @author Leejean
     * @create 2014年11月25日下午3:55:56
     * @param id 工单ID
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkWorkOrder")
    public Json checkWorkOrder(String id){
        Json json = new Json();
        try {
            String msg = workOrderService.checkWorkOrder(id);
            if (msg == null) {
 
                json.setSuccess(true);
                json.setMsg("操作成功!");
 
            }else {
                json.setSuccess(true);
                json.setMsg("工单:"+msg+"非当日工单,无法审核!");
            }
        } catch (Exception e) {
            log.error("审核工单失败", e);
            json.setMsg("审核工单失败!");
        }
        return json;
    }
    /**
     * 批量审核工单(成型车间)
     * @author wanchanghuang
     * @create 2018年2月1日8:55:44
     * @param ids
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkWorkOrdersCX")
    public Json checkWorkOrdersCX(HttpSession session,String ids){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            if(info!=null){
                log.error("成型机批量审核!!!"+ids+"  审核人:"+info.getUser().getName());
                String msg = workOrderService.checkWorkOrders(ids);
                if (msg == null) {
 
                    json.setSuccess(true);
                    json.setMsg("操作成功!");
 
                }else {
                    json.setSuccess(true);
                    json.setMsg(msg);
                }
            }else{
                json.setMsg("操作失败!");
            }
        } catch (Exception e) {
            log.error("审核工单失败", e);
            json.setMsg("审核工单失败!");
        }
        return json;
    }
    /**
     * 批量审核工单(卷包车间)
     * @author Leejean
     * @create 2014年11月25日下午3:56:15
     * @param ids
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkWorkOrders")
    public Json checkWorkOrders(HttpSession session,String ids){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            if(info!=null){
 
                String msg = workOrderService.checkWorkOrders(ids);
                if (msg == null) {
 
                    json.setSuccess(true);
                    json.setMsg("操作成功!");
 
                }else {
                    json.setSuccess(true);
                    json.setMsg(msg);
                }
            }else{
                json.setMsg("操作失败!");
            }
        } catch (Exception e) {
            log.error("审核工单失败", e);
            json.setMsg("审核工单失败!");
        }
        return json;
    }
    /**
     * 修改工单状态(卷包)
     * @author Leejean
     * @create 2014年11月25日下午3:56:30
     * @param id 工单ID
     * @param sts 状态 工单状态
     * (
     * 1,下发 <br>
     * 2,运行 -->运行时在生产实绩中保存val=0的数据,即采集程序只做update操作<br>
     * 3,暂停 -->MES取消撤销工单时<br>
     * 4,完成 -->工单完成,更新工单结束时间<br>
     * 5,终止 -->错误的工单运行时,执行本操作删除生产实绩相关数据<br>
     * 6,结束 -->工单已经反馈<br>
     * 7,锁定 -->MES发起撤销时<br>
     * 8,撤销 -->MES确定撤销时<br>
     * )
     * @return
     */
    @ResponseBody
    @RequestMapping("/editWorkOrderStatus")
    public Json editWorkOrderStatus(HttpSession session,String id,Long sts){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            if(info!=null){
                workOrderService.editWorkOrderStatus(id, sts);
                json.setSuccess(true);
                json.setMsg("操作成功!");
                //工单写入redis
                workOrderWriteToRedis(id,sts);
 
            }else{
                json.setMsg("操作失败!");
            }
        } catch (Exception e) {
            log.error("修改工单状态失败", e);
            json.setSuccess(false);
            json.setMsg("修改工单状态失败!错误原因:"+e.getMessage());
        }
        return json;
    }
 
    
    /**
     * @Author bsw
     * @Description 提前要料时向辅料库发送运行状态
     * @Date 2021/8/5 14:18
     * @Param [session, ids]
     * @return com.shlanbao.tzsc.base.model.Json
     **/
    @ResponseBody
    @RequestMapping("/sendOrderChange")
    public Json sendOrderChange(HttpSession session,String ids) {
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            if(info!=null){
 
                String msg = workOrderService.sendOrderChange(ids);
                if (msg == null) {
 
                    json.setSuccess(true);
                    json.setMsg("操作成功!");
 
                }else {
                    json.setSuccess(true);
                    json.setMsg(msg);
                }
            }else{
                json.setMsg("操作失败!");
            }
        } catch (Exception e) {
            log.error("提前要料失败", e);
            json.setMsg("提前要料失败!");
        }
        return json;
    }
    
    
    @ResponseBody
    @RequestMapping(value = "/sendOrderStatusMsg",method = RequestMethod.POST)
    public Json sendOrderStatusMsg(String type,String xml){
        Json json = new Json();
        try{
            xml = StringEscapeUtils.unescapeXml(xml);
            if ("orderSts".equals(type)){
                SendMessageClient.SendMsgToOrderStsDetail(xml);
                PMSXmlDataInterceptor.getInstance().addLog(true,"工单状态反馈", 1, xml);
            } else if("maintainDetail".equals(type)){
                SendMessageClient.SendMaintainDetail(xml);
                PMSXmlDataInterceptor.getInstance().addLog(true,"设备保养结果反馈", 1, xml);
            } else if("repairDetail".equals(type)){
                SendMessageClient.SendRepairDetail(xml);
                PMSXmlDataInterceptor.getInstance().addLog(true,"维修工单结果反馈", 1, xml);
            } else if("FaultDetail".equals(type)){
                SendMessageClient.SendRepairOrder(xml);
                PMSXmlDataInterceptor.getInstance().addLog(true,"维修请求工单反馈", 1, xml);
            }
 
            json.setSuccess(true);
            json.setMsg("发送成功!");
            /** 日志 1-成功 */
 
        }catch (Exception e ){
            json.setSuccess(false);
            if ("orderSts".equals(type)){
                json.setMsg("向MES发送工单状态信息失败!");
                /** 日志 0-失败*/
                PMSXmlDataInterceptor.getInstance().addLog(true,"工单状态反馈", 0, xml,e.getMessage());
            } else if("maintainDetail".equals(type)){
                json.setMsg("向MES发送保养结果失败!");
                PMSXmlDataInterceptor.getInstance().addLog(true,"设备保养结果反馈", 0, xml,e.getMessage());
            } else if("repairDetail".equals(type)){
                json.setMsg("向MES发送维修结果失败!");
                PMSXmlDataInterceptor.getInstance().addLog(true,"维修工单结果反馈", 0, xml,e.getMessage());
            } else if("FaultDetail".equals(type)){
                json.setMsg("向MES发送维修工单失败!");
                PMSXmlDataInterceptor.getInstance().addLog(true,"维修请求工单反馈", 0, xml,e.getMessage());
            }
 
        }
        return json;
    }
 
 
    /**
     * @title editWorkOrderStatusCX
     * @description 修改工单状态(成型)
     * @author bsw
     * @params [session, id, sts]
     * @updateTime 10:50 2019/8/5 0005
     * @return com.shlanbao.tzsc.base.model.Json
     **/
    @ResponseBody
    @RequestMapping("/editWorkOrderStatusCX")
    public Json editWorkOrderStatusCX(HttpSession session,String id,Long sts){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            if(info!=null){
                log.error("[修改成型机工单状态修改]:"+sts +"    修改人:"+info.getUser().getName());
                workOrderService.editWorkOrderStatus(id, sts);
                //工单写入redis
                workOrderWriteToRedis(id,sts);
                json.setSuccess(true);
                json.setMsg("操作成功!");
            }else{
                json.setMsg("操作失败!");
            }
        } catch (Exception e) {
            log.error("修改工单状态失败", e);
            json.setSuccess(false);
            json.setMsg("修改工单状态失败!错误原因:"+e.getMessage());
        }
        return json;
    }
 
    /**
     * 新增工单页面
     * @author Leejean
     * @create 2014年12月24日下午1:22:48
     * @return
     */
    @RequestMapping("/goToOrderAddJsp")
    public String goToOrderAddJsp(){
        return "/pms/sch/workorder/orderAdd";
    }
 
    /**
     * @title goToOrderAddJspCX
     * @description 成型车间工单新增 页面跳转
     * @author bsw
     * @params []
     * @updateTime 11:43 2019/9/11
     * @return java.lang.String
     **/
    @RequestMapping("/goToOrderAddJspCX")
    public String goToOrderAddJspCX(){
        return "/pms/sch/workorder/orderAddCX";
    }
    /**
     * 编辑工单页面
     * @author Leejean
     * @create 2014年12月24日下午1:22:48
     * @return
     */
    @RequestMapping("/goToOrderEditJsp")
    public String goToOrderEditJsp(){
        return "/pms/sch/workorder/orderEdit";
    }
    /**
     * 新增工单
     * @author Leejean
     * @create 2014年12月24日下午1:22:48
     * @param workOrderBean
     * @return
     */
    @ResponseBody
    @RequestMapping("/addOrder")
    public Json addOrder(WorkOrderBean workOrderBean){
        Json json = new Json();
        try {
            workOrderService.addOrder(workOrderBean);
            json.setSuccess(true);
            json.setMsg("操作成功!");
        } catch (Exception e) {
            log.error("新增工单失败", e);
            json.setMsg(e.getMessage());
        }
        return json;
    }
    /**
     * 跳转至工单选择页面
     * @author Leejean
     * @create 2014年12月2日下午6:49:14
     * @param request
     * @param workshop 车间CODE
     * @return
     */
    @RequestMapping("/goToWorkOrderPickJsp")
    public String goToWorkOrderPickJsp(HttpServletRequest request,String workshop){
        request.setAttribute("workshop", workshop);
        return "/pms/sch/workorder/workorderPicker";
    }
    /**
     * 张璐
     * 成型实绩添加页面跳转
     * @param request
     * @param workshop
     * @return
     */
    @RequestMapping("/goToWorkOrderPickJspCX")
    public String goToWorkOrderPickJspCX(HttpServletRequest request,String workshop){
        request.setAttribute("workshop", workshop);
        return "/pms/sch/workorder/workorderPickerCX";
    }
    /**
     * 实例化所有运行工单的计数参数
     */
    @ResponseBody
    @RequestMapping("/initAllRunnedWorkOrderCalcValues")
    public Json initAllRunnedWorkOrderCalcValues(){
        Json json = new Json();
        try {
            workOrderService.initAllRunnedWorkOrderCalcValues();
            json.setSuccess(true);
            json.setMsg("操作成功!");
        } catch (Exception e) {
            log.error("修改工单状态失败", e);
            json.setMsg("修改工单状态失败!错误原因:"+e.getMessage());
        }
        return json;
    }
 
    //测试方法=================================================================
    /**
     * 新增排班
     * @return
     */
    @RequestMapping("/goToPbWork")
    public String goToPbWork(){
        return "/pms/sch/workorder/orderAddPb";
    }
 
    /**
     * 跳转到成型车间排班窗口
     * @return
     */
    @RequestMapping("/goToPbWorkCX")
    public String goToPbWorkCX(){
        return "/pms/sch/workorder/orderAddPbCX";
    }
 
 
 
 
    /**
     * 批量新增排班
     */
    @ResponseBody
    @RequestMapping("/addPbWork")
    public Json addPbWork(WorkOrderBean workOrderBean){
        Json json=new Json();
        try {
            workOrderService.addPbWork(workOrderBean);
            json.setMsg("新增成功!");
            json.setSuccess(true);
        } catch (Exception e) {
            log.error(message, e);
            json.setMsg(e.getMessage());
            json.setSuccess(false);
        }
        return json;
    }
    /**
     * 新增工单
     * @return
     */
    @RequestMapping("/goToBatckWork")
    public String goToBatckWork(){
        return "/pms/sch/workorder/orderAddWork";
    }
    /**
     * 成型车间批量新增工单
     * @return
     */
    @RequestMapping("/goToBatckWorkCX")
    public String goToBatckWorkCX(){
        return "/pms/sch/workorder/orderAddWorkCX";
    }
    /**
     * 发射工单批量新增
     * @return
     */
    @RequestMapping("/goToBatckWorkFSJ")
    public String goToBatckWorkFSJ(){
        return "/pms/sch/workorder_FSJ/orderAddWork";
    }
    /**
     * 删除工单
     * @author Leejean
     * @create 2014年11月25日下午3:56:15
     * @param ids
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteWorkOrders")
    public Json deleteWorkOrders(String ids,String eqpName,String team,String date,String mat,HttpSession session){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            if(info!=null){
                workOrderService.deleteWorkOrders(ids,eqpName,team,date,mat,info);
                json.setSuccess(true);
                json.setMsg("操作成功!");
            }else{
                json.setMsg("操作失败!");
            }
 
        } catch (Exception e) {
            log.error("审核工单删除", e);
            json.setMsg("审核工单删除!");
        }
        return json;
    }
 
    /**
     * 删除工单
     * @author Leejean
     * @create 2014年11月25日下午3:56:15
     * @param ids
     * @return
     */
    @ResponseBody
    @RequestMapping("/beatchDeleteWorkOrders")
    public Json beatchDeleteWorkOrders(String ids,String eqpName,String team,String date,String mat,HttpSession session){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            workOrderService.deleteBeatchWorkOrders(ids,eqpName,team,date,mat,info);
            json.setSuccess(true);
            json.setMsg("操作成功!");
        } catch (Exception e) {
            log.error("审核工单删除", e);
            json.setMsg("审核工单删除!");
        }
        return json;
    }
 
 
    /**
     * 批量新增工单
     */
    @ResponseBody
    @RequestMapping("/saveBatckWork")
    public Json saveBatckWork(String id, HttpServletRequest request){
        Json json=new Json();
        try {
                WorkOrderBean bean = new WorkOrderBean();
                bean.setType(Long.parseLong(request.getParameter("type")));
                bean.setQty(Double.parseDouble(request.getParameter("qty")));
                bean.setUnitId(request.getParameter("unitId"));
                bean.setMatId(request.getParameter("matId"));
                bean.setBomVersion(request.getParameter("bomVersion"));
                bean.setParameterSetRevision(request.getParameter("paramVersion"));
                bean.setStim(request.getParameter("date1").trim() + " 00:00:00");
                bean.setEtim(request.getParameter("date2").trim() + " 23:59:59");
                // 填充BEAN
                String[] eqps  =request.getParameter("equipmentId").split(",");
                boolean mes = true;
                for (String eqp:eqps) {
                    bean.setEquipmentId(eqp);
                    mes=workOrderService.saveBatckWork(bean);
                }
                if(mes){
                    json.setMsg("新增成功!");
                    json.setSuccess(true);
                }else{
                    json.setMsg("新增失败,没有排班!");
                    json.setSuccess(false);
                }
 
        } catch (Exception e) {
            log.error(message, e);
            json.setMsg(e.getMessage());
            json.setSuccess(false);
        }
        return json;
    }
 
    /**
     * 批量新增工单(发射机)
     */
    @ResponseBody
    @RequestMapping("/saveBatckWorkFSJ")
    public Json saveBatckWorkFSJ(String id, HttpServletRequest request){
        Json json=new Json();
        try {
            String type = request.getParameter("type");
            String equipmentId = request.getParameter("equipmentId");
            String qty = request.getParameter("qty");
            String unitId = request.getParameter("unitId");
            String matId = request.getParameter("matId");
            String date1=request.getParameter("date1");
            String date2=request.getParameter("date2");
 
            TransmitterWorkOrderBean bean = new TransmitterWorkOrderBean();
            bean.setOrderType(type);
            bean.setQty(Double.parseDouble(qty));
            bean.setUnit(unitId);
            bean.setMaterialCode(matId);
            // 填充BEAN
            String[] eqps  =equipmentId.split(",");
            boolean mes = true;
            for (String eqp:eqps) {
                bean.setEqpId(eqp);
                mes=workOrderService.saveBatckWorkFSJ(bean,date1,date2);
            }
            if(mes){
                json.setMsg("新增成功!");
                json.setSuccess(true);
            }else{
                json.setMsg("新增失败,没有排班!");
                json.setSuccess(false);
            }
 
 
        } catch (Exception e) {
            log.error(message, e);
            json.setMsg("新增失败!"+e.getMessage());
            json.setSuccess(false);
        }
        return json;
    }
 
 
    /**
     * 运行时间
     *
     * @return
     * Rengj
     */
    @RequestMapping("/goToEditRunTime")
    public String goToEditRunTime(String ids,HttpSession session){
        session.setAttribute("workOrderRunTime", workOrderService.getRuntime(ids));
        session.setAttribute("runTimeIds", ids);
        return "/pms/sch/workorder/runTimeEdit";
    }
 
 
    /**
     * 修改运行时间
     * @author Rengj
     * @return
     */
    @ResponseBody
    @RequestMapping("/addRunTime")
    public Json addRunTime(String stim,String etim,HttpSession session){
         String result ="";
        Json json = new Json();
        try {
            String ids= String.valueOf(session.getAttribute("runTimeIds"));
            result = workOrderService.editRuntime(stim,etim, ids);
            json.setSuccess(true);
            json.setMsg(result);
            session.removeAttribute("runTimeIds");
        } catch (Exception e) {
            log.error("修改运行时间", e);
            json.setMsg(result);
        }
        return json;
    }
 
 
    /**
     * 查询发射机工单
     */
    @ResponseBody
    @RequestMapping("/getAllFSJOrders")
    public DataGrid getAllFSJOrders(TransmitterWorkOrderBean workOrderBean,PageParams pageParams){
        try {
            return workOrderService.getAllFSJOrders(workOrderBean,pageParams);
        } catch (Exception e) {
            log.error("查询工单异常", e);
        }
        return null;
    }
    /**
     * 查看工单详情
     */
    @RequestMapping("/goToFSJOrderDetail")
    public String goToFSJOrderDetail(HttpServletRequest request,String id){
        request.setAttribute("workOrderId",id);
        return "/pms/sch/workorder_FSJ/workorderDetail";
    }
 
    /**
     * @title checkFSJOrder
     * @description 发射工单审核
     * @author bsw
     * @params [id]
     * @updateTime 10:54 2019/8/5 0005
     * @return com.shlanbao.tzsc.base.model.Json
     **/
    @ResponseBody
    @RequestMapping("/checkFSJOrder")
    public Json checkFSJOrder(String id){
        Json json = new Json();
        try {
            workOrderService.checkFSJOrder(id);
            json.setSuccess(true);
            json.setMsg("操作成功!");
        } catch (Exception e) {
            log.error("审核工单失败", e);
            json.setMsg("审核工单失败!");
        }
        return json;
    }
    /**
     * @title checkFSJOrders
     * @description 批量审核发射工单
     * @author bsw
     * @params [session, ids]
     * @updateTime 10:55 2019/8/5 0005
     * @return com.shlanbao.tzsc.base.model.Json
     **/
    @ResponseBody
    @RequestMapping("/checkFSJOrders")
    public Json checkFSJOrders(HttpSession session,String ids){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            if(info!=null){
                log.error("发射机工单审核:"+ids+"   审核人:"+info.getUser().getName());
                workOrderService.checkFSJOrders(ids);
                json.setSuccess(true);
                json.setMsg("操作成功!");
            }else{
                json.setMsg("操作失败!");
            }
        } catch (Exception e) {
            log.error("审核工单失败", e);
            json.setMsg("审核工单失败!");
        }
        return json;
    }
    /**
     * @title editFSJOrderStatus
     * @description 编辑发射机工单状态
     * @author bsw
     * @params [id, sts]
     * @updateTime 10:55 2019/8/5 0005
     * @return com.shlanbao.tzsc.base.model.Json
     **/
    @ResponseBody
    @RequestMapping("/editFSJOrderStatus")
    public Json editFSJOrderStatus(String id,Long sts){
        Json json = new Json();
        try {
            workOrderService.editFSJOrderStatus(id, sts);
            //工单写入redis
            transmitterWorkOrderWriteToRedis(id,sts);
            json.setSuccess(true);
            json.setMsg("操作成功!");
        } catch (Exception e) {
            log.error("修改工单状态失败", e);
            json.setSuccess(false);
            json.setMsg("修改工单状态失败!错误原因:"+e.getMessage());
        }
        return json;
    }
    /**
     * @title goToFSJOrderAddJsp
     * @description 跳转到发射机工单新增页面
     * @author bsw
     * @params []
     * @updateTime 10:56 2019/8/5 0005
     * @return java.lang.String
     **/
    @RequestMapping("/goToFSJOrderAddJsp")
    public String goToFSJOrderAddJsp(){
        return "/pms/sch/workorder_FSJ/orderAdd";
    }
    /**
     * @title goToFSJOrderEditJsp
     * @description 跳转到发射机工单编辑页面
     * @author bsw
     * @params []
     * @updateTime 10:56 2019/8/5 0005
     * @return java.lang.String
     **/
    @RequestMapping("/goToFSJOrderEditJsp")
    public String goToFSJOrderEditJsp(){
        return "/pms/sch/workorder_FSJ/orderEdit";
    }
    /**
     * @title addFSJOrder
     * @description 新增发射机工单-保存至数据库
     * @author bsw
     * @params [workOrderBean]
     * @updateTime 10:56 2019/8/5 0005
     * @return com.shlanbao.tzsc.base.model.Json
     **/
    @ResponseBody
    @RequestMapping("/addFSJOrder")
    public Json addFSJOrder(TransmitterWorkOrderBean workOrderBean){
        Json json = new Json();
        try {
            workOrderService.addFSJOrder(workOrderBean);
            json.setSuccess(true);
            json.setMsg("操作成功!");
        } catch (Exception e) {
            log.error("新增工单失败", e);
            json.setMsg("新增工单失败!");
        }
        return json;
    }
    /**
     * @title deleteFSJOrders
     * @description 发射机工单删除
     * @author bsw
     * @params [ids, eqpName, team, date, mat, session]
     * @updateTime 10:57 2019/8/5 0005
     * @return com.shlanbao.tzsc.base.model.Json
     **/
    @ResponseBody
    @RequestMapping("/deleteFSJOrders")
    public Json deleteFSJOrders(String ids,String eqpName,String team,String date,String mat,HttpSession session){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            workOrderService.deleteFSJOrders(ids,eqpName,team,date,mat,info);
            json.setSuccess(true);
            json.setMsg("操作成功!");
        } catch (Exception e) {
            log.error("审核工单删除", e);
            json.setMsg("审核工单删除!");
        }
        return json;
    }
 
    /**
     * @title beatchDeleteFSJOrders
     * @description 发射机工单批量删除
     * @author bsw
     * @params [ids, eqpName, team, date, mat, session]
     * @updateTime 10:57 2019/8/5 0005
     * @return com.shlanbao.tzsc.base.model.Json
     **/
    @ResponseBody
    @RequestMapping("/beatchDeleteFSJOrders")
    public Json beatchDeleteFSJOrders(String ids,String eqpName,String team,String date,String mat,HttpSession session){
        Json json = new Json();
        try {
            SessionInfo info=(SessionInfo) session.getAttribute("sessionInfo");
            if(info!=null){
//                workOrderService.deleteBeatchWorkOrders(ids,eqpName,team,date,mat,info);
                workOrderService.deleteBeatchFSJOrders(ids,eqpName,team,date,mat,info);
                json.setSuccess(true);
                json.setMsg("操作成功!");
            }else{
                json.setSuccess(false);
                json.setMsg("操作失败!");
            }
        } catch (Exception e) {
            log.error("审核工单删除", e);
            json.setMsg("审核工单删除!");
        }
        return json;
    }
    /**
     * @title goToEditFSJRunTime
     * @description 跳转到发射机工单运行时间编辑页面
     * @author bsw
     * @params [ids, session]
     * @updateTime 10:58 2019/8/5 0005
     * @return java.lang.String
     **/
    @RequestMapping("/goToEditFSJRunTime")
    public String goToEditFSJRunTime(String ids,HttpSession session){
        session.setAttribute("FSJOrderRunTime", workOrderService.getFSJRuntime(ids));
        session.setAttribute("FSJrunTimeIds", ids);
        return "/pms/sch/workorder_FSJ/runTimeEdit";
    }
 
    /**
     * @title goToEditFSJDatas
     * @description 跳转至发射机生产消耗数据编辑页面
     * @author bsw
     * @params [id, request]
     * @updateTime 10:59 2019/8/5 0005
     * @return java.lang.String
     **/
    @RequestMapping("/goToEditFSJDatas")
    public String goToEditFSJDatas(String id,HttpServletRequest request){
        //查询发射机消耗实际
        request.setAttribute("transmitterBean", workOrderService.querytransmitterOutPut(id));
        //session.setAttribute("FSJrunTimeIds", ids);
        return "/pms/sch/workorder_FSJ/outputEdit";
    }
 
    /**
     * 保存修改后的数据
     *  步骤:
     *    1:获得调整后的数据
     *    2:原始数据-调整后的数据=调整值
     *    3:修改详细调整后的数;
     *    4:修改主工单总发射量-调整值
     *    因为发射量调整了,总发射量也会跟着变,所以要修改主表总发射量
     * @return
     * @author wanchanghuang
     */
    @ResponseBody
    @RequestMapping("/saveFSJDatas")
    public Json saveFSJDatas( TransmitterOutput tobean,HttpServletRequest request){
            Json json = new Json();
            try {
                workOrderService.saveFSJDatas(tobean);
                json.setSuccess(true);
                json.setMsg("修改成功!!!");
            } catch (Exception e) {
                log.error("修改发射机量失败!!!", e);
                json.setMsg("修改失败!!!");
            }
            return json;
    }
 
 
 
    /**
     * 修改运行时间
     * @author Rengj
     * @return
     */
    @ResponseBody
    @RequestMapping("/addFSJRunTime")
    public Json addFSJRunTime(String stim,String etim,HttpSession session){
         String result ="";
        Json json = new Json();
        try {
            String ids= String.valueOf(session.getAttribute("FSJrunTimeIds"));
            result = workOrderService.editFSJRuntime(stim,etim, ids);
            json.setSuccess(true);
            json.setMsg(result);
            session.removeAttribute("FSJrunTimeIds");
        } catch (Exception e) {
            log.error("修改运行时间", e);
            json.setMsg(result);
        }
        return json;
    }
    /**
     * 查询发射机工单
     */
    @ResponseBody
    @RequestMapping("/getAllFSJOrderDetails")
    public DataGrid getAllFSJOrderDetails(TransmitterWorkOrderBean workOrderBean,PageParams pageParams){
        try {
            return workOrderService.getAllFSJOrderDetails(workOrderBean,pageParams);
        } catch (Exception e) {
            log.error("查询工单异常", e);
        }
        return null;
    }
 
 
    /**
     * bom版本下拉查询
     * @param matid
     * @return
     * @auther bsw
     * @date 2019-07-09
     */
    @ResponseBody
    @RequestMapping("/getBomVersionByProd")
    public List<Combobox> getBomVersionByProd(String matid){
        return workOrderService.queryBomVersionByProd(matid);
    }
    /**
     * 工艺参数版本下拉查询
     * @param matid
     * @return
     * @auther bsw
     * @date 2019-07-09
     *
     */
    @ResponseBody
    @RequestMapping("/getParamVersionByProd")
    public List<Combobox> getParamVersionByProd(String matid){
        return workOrderService.getParamVersionByProd(matid);
    }
    /**
     * 获取bom明细
     * @param bomVersion
     * @return
     * @auther bsw
     * @date 2019-07-09
     */
    @ResponseBody
    @RequestMapping("/getBomDetail")
    public DataGrid getBomDetail(String bomVersion){
        return workOrderService.getBomDetail(bomVersion);
    }
 
 
    /**
     * 卷包机与成型机工单状态缓存redis
     * @param id   工单id
     * @param sts  工单状态
     */
    private void workOrderWriteToRedis(String id,Long sts) throws Exception{
        //根据id获取工单详情
        WorkOrderBean workOrderById = workOrderService.getWorkOrderById(id);
        //运行工单时保存到redis
        writeToRedis(sts, workOrderById != null, workOrderById.getEqpcode(), JSONObject.fromObject(workOrderById));
    }
 
    /**
     * 发射机工单状态缓存redis
     * @param id   工单id
     * @param sts  工单状态
     */
    private void transmitterWorkOrderWriteToRedis(String id,Long sts) throws Exception{
        //根据id获取工单详情
        TransmitterWorkOrderBean workOrderById = workOrderService.getFSJOrderById(id);
        //运行工单时保存到redis
        writeToRedis(sts, workOrderById!=null, workOrderById.getEquCode(), JSONObject.fromObject(workOrderById));
    }
 
    /**
     * 工单状态缓存redis
     * @param sts
     * @param b
     * @param equCode
     * @param jsonObject
     */
    private void writeToRedis(Long sts, boolean b, String equCode, JSONObject jsonObject) {
        if (b && sts == 2) {
            //在redis创建工单集
            if (!RedisUtil.hasKey("workorder")) RedisUtil.setMap("workorder", new HashMap<>());
            //存入redis
            RedisUtil.addMap("workorder", equCode, jsonObject.toString());
            //修改为其他状态则从redis移除该工单
        } else {
            RedisUtil.delMapKey(equCode, "workorder");
        }
    }
 
 
 
}