#
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
package com.slcf.controller;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
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.bean.WaitCheckCondition;
import com.slcf.pojo.WaitCheckBean;
import com.slcf.pojo.MatCodeBean;
import com.slcf.pojo.SysLogBean;
import com.slcf.service.WaitCheckService;
import com.slcf.util.AuthorityCode;
import com.slcf.util.Constants;
import com.slcf.util.DateTimeUtil;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import sun.misc.BASE64Encoder;
 
import com.slcf.service.MatCodeService;
import com.slcf.service.RoleService;
import com.slcf.service.SysLogService;
 
/**
 * 盘点通知档控制器层
 * @author admin
 * @date 2020年1月14日
 */
@Controller
@RequestMapping("/work")
public class WaitCheckController {
 
    @Resource
    WaitCheckService waitCheckService;
    @Autowired
    SysLogService sysLogService;
    @Autowired
    MatCodeService matCodeService;
    @Autowired
    RoleService roleService;
    
    @RequestMapping("/goWaitCheck.action")
    public String goWaitCheckPage(HttpServletRequest request){
        try {
            String rid = request.getSession().getAttribute("ROLEID").toString();
            String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid), 
                    AuthorityCode.WaitCheckCode);
            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("goWaitCheck.action");
            sysLog.setTts_keyname("访问:盘点通知档");
            sysLog.setModi_user(user.getUser_account());
            sysLogService.insertSysLog(sysLog);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return "waitCheck";
    }
    
    /**
     * 添加
     * @param waitCheck
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/addWaitCheck.action")
    public Integer insertWaitCheck(WaitCheckBean waitCheck,HttpServletRequest request){
        int result=0;
        try {
            UserBean user=(UserBean)request.getSession().getAttribute("USER");
//            if(waitCheck.getSheet_no()==null || waitCheck.getSheet_no().equals("")) {
//                int random = (int)(Math.random()*900 + 100);
//                String seq = Integer.toString(random);
//                String sheet_no = DateTimeUtil.getStringDateTime(14);                
//                waitCheck.setSheet_no(sheet_no+seq);
//            }
//            waitCheck.setModi_user(user.getUser_account());
            result = waitCheckService.insertWaitCheck(waitCheck);                                
 
            if(result>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("addWaitCheck.action");
                sysLog.setTts_keyname("插入通知档:" + waitCheck.getLgnum() + "-" + waitCheck.getIvnum());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
            result=0;
        }
        return result;
    }
    
    /**
     * 分页查询所有
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/waitCheckList.action")
    public Map<String,Object> queryWaitCheckListByPages(WaitCheckCondition waitCheckCon){
        Map<String,Object>map=waitCheckService.queryWaitCheckList(waitCheckCon);
        return map;
    }
 
    /**
     * 验证物料编号是否存在
     * @param did
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkMatCode.action")
    public Map<String,Object> checkMatCode(@RequestParam("did")String id){        
        Map<String,Object> map=new HashMap<String, Object>();
//        boolean flag=userService.validUserAccount(account, uid);
        try {
            MatCodeBean matCode = matCodeService.queryMatCodeById(id);
            if(matCode!=null){
                map.put("msg", "代号可用");
                map.put("mat_name_add",matCode.getMat_name());
            }else{
                map.put("msg", "物料号不存在");
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 根据id查询信息
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryWaitCheckById.action")
//    public WaitCheckBean queryWaitCheckById(@RequestParam("sheet_no")String sheet_no,
//            @RequestParam("mat_no")String mat_no,HttpServletRequest request){
    public WaitCheckBean queryWaitCheckById(WaitCheckBean waitCheck,HttpServletRequest request){
        try {
            return waitCheckService.queryWaitCheckById(waitCheck);
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
//    /**
//     * 验证工作代号是否唯一
//     * @param did
//     * @return
//     */
//    @ResponseBody
//    @RequestMapping("/checkWaitCheck.action")
//    public Map<String,Object> checkWaitCheck(@RequestParam("did")int id){        
//        Map<String,Object> map=new HashMap<String, Object>();
////        boolean flag=userService.validUserAccount(account, uid);
//        try {
//            WaitCheckBean WaitCheck = WaitCheckService.queryWaitCheckById(id);
//            if(WaitCheck==null){
//                map.put("msg", "代号可用");
//            }else{
//                map.put("msg", "代号不可用");
//            }
//        }catch(Exception e) {
//            System.out.println(e.getMessage());
//        }
//        return map;
//    }
    
    /**
     * 手工完结入库通知档,反馈ERP
     * @param WaitCheckEntity
     * @return
     */
    @ResponseBody
    @RequestMapping("/overWaitCheck.action")
    public Integer overWaitCheck(WaitCheckBean waitCheck,HttpServletRequest request){
        int result = 0;
        try {
            UserBean user=(UserBean)request.getSession().getAttribute("USER");
            waitCheck.setModi_user(user.getUser_account());
            
            WaitCheckBean waitCheckBean = waitCheckService.queryWaitCheckById(waitCheck);
            String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_SRV/AsrsTrSet";
            result = sendCheckStatus(httpUrl,waitCheckBean);
//            result=waitCheckService.upWaitCheck(waitCheck);
            if(result>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("upWaitCheck.action");
                sysLog.setTts_keyname("修改盘点通知档:" + waitCheck.getLgnum());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    /**
     * 入库完成,调用sap接口上传完成信息
     */
    private int sendCheckStatus(String httpUrl,WaitCheckBean waitCheck) {
        int result = 0;
////        String token = getXCsrfToken(httpUrl);
//        String input = Constants.SAP_USER + ":" + Constants.SAP_PASSWORD;//"ZHANGX:654321";
//        BASE64Encoder base = new BASE64Encoder();
//        String encodedPassword;
//        String token="";
//        String session_value="";
//        try {
//            encodedPassword = base.encode(input.getBytes("UTF-8"));
//            URL url1 = new URL(httpUrl);
//            HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection();
//            connection1.setDoOutput(true);
//            connection1.setDoInput(true);
//            connection1.setRequestMethod("GET");
//            connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
//            connection1.setRequestProperty("x-csrf-token","Fetch");
//            String sessionCookie = connection1.getHeaderField("Set-Cookie");
//            String[] sessionId = sessionCookie.split(";");
//            session_value = sessionId[0];
//            token = connection1.getHeaderField("x-csrf-token");
////            Map<String, List<String>> map = connection1.getHeaderFields();
////            token = map.get("x-csrf-token").toString();
//        } catch (Exception e1) {
//            e1.printStackTrace();
//        }
//        
//        try {
//            JSONObject jsObj = new JSONObject();
//            JSONArray arr = new JSONArray();
//            for(int i=0;i<1;i++) {
//                JSONObject json = new JSONObject();
//                json.put("lgnum",waitCheck.getLgnum());
//                json.put("tbnum",Long.toString(waitCheck.getTbnum()));
//                json.put("tbpos",Integer.toString(waitCheck.getTbpos()));
//                json.put("zmatid",waitCheck.getZmatid());
//                
//                json.put("anfme",Double.toString(waitCheck.getAnfme()));
//                json.put("altme",waitCheck.getAltme());
//                json.put("nltyp","A01");
//                json.put("nlber","001");
//                json.put("nlpla",waitCheck.getLoc_no());
//                arr.add(json);
//            }
//            jsObj.put("item", arr);
//            byte[] buff = jsObj.toString().getBytes();
//            int buffLen = buff.length;
//            //创建连接
//            try {
////                String input = "ZHANGX:654321";
////                BASE64Encoder base = new BASE64Encoder();
////                String encodedPassword = base.encode(input.getBytes("UTF-8"));
//                
//                URL url = new URL(httpUrl);
//                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//                connection.setDoOutput(true);
//                connection.setDoInput(true);
//                connection.setRequestMethod("POST");
//        //        connection.setUseCaches(false);            
//        //        connection.setInstanceFollowRedirects(true);
////                connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
//                connection.setRequestProperty("Cookie", session_value);
//                connection.setRequestProperty("Content-Type","application/json");
//                connection.setRequestProperty("Accept","application/json");
//                connection.setRequestProperty("Content-Length","" + buffLen);
////                connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
//                connection.setRequestProperty("x-csrf-token",token);
//                
//                //POST请求
//                OutputStream out = connection.getOutputStream();
//                out.write(buff);
//                out.close();
//                
//                //读取响应
//                BufferedReader reader = new BufferedReader(new InputStreamReader(
//                        connection.getInputStream()));
//                String lines;
//                StringBuffer sb = new StringBuffer("");
//                while ((lines = reader.readLine()) != null) {
//                    lines = new String(lines.getBytes(), "utf-8");
//                    sb.append(lines);
//                }
//                System.out.println(sb.toString());
//                result = 1;
//            }catch (Exception e) {
//                System.out.println(e.getMessage());
//            }
//        }catch (Exception e) {
//            System.out.println(e.getMessage());
//        }
        return result;
    }
    
    /**
     * 修改信息
     * @param WaitCheckEntity
     * @return
     */
    @ResponseBody
    @RequestMapping("/upWaitCheck.action")
    public Integer upWaitCheck(WaitCheckBean waitCheck,HttpServletRequest request){
        int result = 0;
        try {
            UserBean user=(UserBean)request.getSession().getAttribute("USER");
            waitCheck.setModi_user(user.getUser_account());
            
            result=waitCheckService.upWaitCheck(waitCheck);
            if(result>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("upWaitCheck.action");
                sysLog.setTts_keyname("修改盘点通知档:" + waitCheck.getLgnum());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除信息
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/delWaitCheck.action")
    public int delWaitCheck(WaitCheckBean waitCheckBean,HttpServletRequest request){
        int result = 0;
        try {
            result=waitCheckService.delWaitCheck(waitCheckBean);
            
            if(result>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("delWaitCheck.action");
                sysLog.setTts_keyname("删除通知档资料:" + waitCheckBean.getLgnum() + "-" + waitCheckBean.getIvnum());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    /**
     * 查询所有
     * @return
     */
    @ResponseBody
    @RequestMapping("/getWaitCheck.action")
    public List<WaitCheckBean> getWaitCheck(){
        try {
            return waitCheckService.getWaitCheckList();
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }        
    }
    
    /**
     * 通知档资料转历史档
     * @return
     */
    @ResponseBody
    @RequestMapping("/moveCheckToLog.action")
    public int moveCheckToLog(@RequestParam("ids")String[] sheetNos,
            @RequestParam("matStr")String[] matNos,HttpServletRequest request){
        int result = 0;
        try {
            String sheet_no="", mat_no="";
            for(int i=0;i<sheetNos.length;i++) {
                WaitCheckBean waitCheckBean =new WaitCheckBean();
                waitCheckBean.setLgnum(sheetNos[i]);
                waitCheckBean.setMatnr(matNos[i]);;
                result=waitCheckService.moveToLog(waitCheckBean);
            }            
            if(result>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("moveCheckToLog.action");
                sysLog.setTts_keyname("通知档资料转历史档:" + sheet_no + "-" + mat_no);
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
}