#
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
package com.slcf.controller;
 
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.AdjDetailCondition;
import com.slcf.bean.LocDetailCondition;
import com.slcf.pojo.AdjDetailBean;
import com.slcf.pojo.LocDetailBean;
import com.slcf.pojo.LocationBean;
import com.slcf.pojo.MatCodeBean;
import com.slcf.pojo.SysLogBean;
import com.slcf.service.AdjDetailService;
import com.slcf.service.LocDetailService;
import com.slcf.service.MatCodeService;
import com.slcf.service.RoleService;
import com.slcf.service.LocationService;
import com.slcf.service.SysLogService;
import com.slcf.util.AuthorityCode;
 
/**
 * 库存调整控制器层
 * @author admin
 * @date 2018年11月15日
 */
@Controller
@RequestMapping("/stock")
public class AdjDetailController {
 
    @Resource
    AdjDetailService adjDetailService;
    @Autowired
    LocDetailService locDetailService;
    @Autowired
    MatCodeService matCodeService;
    @Autowired
    LocationService locationService;
    @Autowired
    SysLogService sysLogService;
    @Autowired
    RoleService roleService;
    
    @RequestMapping("goAdjDetail.action")
    public String goAdjDetailPage(HttpServletRequest request){
        try {
            String rid = request.getSession().getAttribute("ROLEID").toString();
            String authCode = roleService.getAuthListByRoleMenu(Integer.parseInt(rid), 
                    AuthorityCode.AdjDetailCode);
            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("goAdjDetail.action");
            sysLog.setTts_keyname("访问:库存调整");
            sysLog.setModi_user(user.getUser_account());
            sysLogService.insertSysLog(sysLog);
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return "adjDetail";
    }
    
    /**
     * 添加
     * @param adjDetail
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/insertAdjLoc.action")
    public Integer insertAdjLoc(AdjDetailCondition adjDetailCon,HttpServletRequest request){
        int result=0;
        try {
            UserBean user=(UserBean)request.getSession().getAttribute("USER");            
            if(adjDetailCon != null) {                                
                LocDetailBean detail = locDetailService.queryLocDetailById(adjDetailCon.getLoc_no(), adjDetailCon.getMat_no());
                if(detail!=null) {//修改
                    int s_qty = detail.getQty();
                    int s_ctns = detail.getCtns();
                    double s_wt = detail.getWt();
                    detail.setQty(s_qty + adjDetailCon.getAdj_qty());
                    detail.setCtns(s_ctns + adjDetailCon.getAdj_ctns());
                    detail.setWt(s_wt + adjDetailCon.getAdj_wt());
                    detail.setMemo(adjDetailCon.getMemo());
                    result = locDetailService.upLocDetail(detail);
                    
                    if(result>0) {
                        AdjDetailBean adjDetail = new AdjDetailBean();
                        adjDetail.setLoc_no(adjDetailCon.getLoc_no());
                        adjDetail.setMat_no(adjDetailCon.getMat_no());
                        adjDetail.setS_qty(s_qty);
                        adjDetail.setS_ctns(s_ctns);
                        adjDetail.setS_wt(s_wt);
                        adjDetail.setAdj_qty(adjDetailCon.getAdj_qty());
                        adjDetail.setAdj_ctns(adjDetailCon.getAdj_ctns());
                        adjDetail.setAdj_wt(adjDetailCon.getAdj_wt());
                        adjDetail.setQty(detail.getQty());
                        adjDetail.setCtns(detail.getCtns());
                        adjDetail.setWt(detail.getWt());
                        adjDetail.setMemo(adjDetailCon.getMemo());
                        adjDetail.setModi_user(user.getUser_account());
                        adjDetailService.insertAdjDetail(adjDetail);
                    }
                }
                else {//插入
                    LocDetailBean locDetail = new LocDetailBean();
                    locDetail.setLoc_no(adjDetailCon.getLoc_no());
                    locDetail.setMat_no(adjDetailCon.getMat_no());
                    locDetail.setQty(adjDetailCon.getAdj_qty());
                    locDetail.setCtns(adjDetailCon.getAdj_ctns());
                    locDetail.setWt(adjDetailCon.getAdj_wt());
                    locDetail.setMemo(adjDetailCon.getMemo());
                    locDetail.setModi_user(user.getUser_account());
                    result = locDetailService.insertLocDetail(locDetail);
                    
                    if(result>0) {
                        AdjDetailBean adjDetail = new AdjDetailBean();
                        adjDetail.setLoc_no(adjDetailCon.getLoc_no());
                        adjDetail.setMat_no(adjDetailCon.getMat_no());
                        adjDetail.setS_qty(0);
                        adjDetail.setS_ctns(0);
                        adjDetail.setS_wt(0);
                        adjDetail.setAdj_qty(adjDetailCon.getAdj_qty());
                        adjDetail.setAdj_ctns(adjDetailCon.getAdj_ctns());
                        adjDetail.setAdj_wt(adjDetailCon.getAdj_wt());
                        adjDetail.setQty(adjDetailCon.getAdj_qty());
                        adjDetail.setCtns(adjDetailCon.getAdj_ctns());
                        adjDetail.setWt(adjDetailCon.getAdj_wt());
                        adjDetail.setMemo(adjDetailCon.getMemo());
                        adjDetail.setModi_user(user.getUser_account());
                        adjDetailService.insertAdjDetail(adjDetail);
                    }
                }                            
                                
            }
 
            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("insertAdjLoc.action");
                sysLog.setTts_keyname("库存调整插入明细:" + adjDetailCon.getLoc_no() + "-"+ adjDetailCon.getMat_no());
                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("/adjLocList.action")
    public Map<String,Object> queryLocDetailListByPages(LocDetailCondition locDetailCon){
        if(locDetailCon.getLoc_no()==null || locDetailCon.getLoc_no().equals("")) {
            return null;
        }
        Map<String,Object>map=locDetailService.queryLocDetailList(locDetailCon);
        return map;
    }
    
    /**
     * 分页查询所有
     * @param pageNumber
     * @param pageSize
     * @return
     */
//    @ResponseBody
//    @RequestMapping("/adjDetailList.action")
//    public Map<String,Object> queryAdjDetailListByPages(AdjDetailCondition adjDetailCon){
//        Map<String,Object>map=adjDetailService.queryAdjDetailList(adjDetailCon);
//        return map;
//    }
    
    /**
     * 根据id查询信息
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryAdjDetailById.action")
    public AdjDetailBean queryAdjDetailById(@RequestParam("did")int id){
        try {
            return adjDetailService.queryAdjDetailById(id);
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 根据id查询信息
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryAdjLocById.action")
    public LocDetailBean queryAdjLocById(@RequestParam("loc_no")String loc_no,
            @RequestParam("mat_no")String mat_no,HttpServletRequest request){
        try {
            return locDetailService.queryLocDetailById(loc_no, mat_no);
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 验证物料编号是否存在
     * @param did
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkCode.action")
    public Map<String,Object> checkMatCode(@RequestParam("did")String id,@RequestParam("loc_no")String loc_no){        
        Map<String,Object> map=new HashMap<String, Object>();
//        boolean flag=userService.validUserAccount(account, uid);
        try {
            MatCodeBean matCode = matCodeService.queryMatCodeById(id);
            LocationBean location = locationService.queryLocationById(loc_no);
            if(matCode!=null && location!=null){
                map.put("msg", "代号可用");
            }else{
                map.put("msg", "库位号/物料号不存在");
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 验证代号是否唯一
     * @param did
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkAdjDetail.action")
    public Map<String,Object> checkAdjDetail(@RequestParam("did")int id){        
        Map<String,Object> map=new HashMap<String, Object>();
//        boolean flag=userService.validUserAccount(account, uid);
        try {
            AdjDetailBean AdjDetail = adjDetailService.queryAdjDetailById(id);
            if(AdjDetail==null){
                map.put("msg", "代号可用");
            }else{
                map.put("msg", "代号不可用");
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return map;
    }
    
    /**
     * 修改信息
     * @param adjDetailCon
     * @return
     */
    @ResponseBody
    @RequestMapping("/upAdjDetail.action")
    public Integer upAdjDetail(AdjDetailCondition adjDetailCon,HttpServletRequest request){
        int result = 0;
        try {
            UserBean user=(UserBean)request.getSession().getAttribute("USER");
            String loc_no = adjDetailCon.getLoc_no();
            String mat_no = adjDetailCon.getMat_no();
            LocDetailBean locDetail = locDetailService.queryLocDetailById(loc_no, mat_no);
            if (locDetail != null) {
                if(adjDetailCon.getAdj_qty()!=0) {
                    int qty = locDetail.getQty()>=adjDetailCon.getAdj_qty() ? (locDetail.getQty() + adjDetailCon.getAdj_qty()) : 0;
                    locDetail.setQty(qty);
                }
                if(adjDetailCon.getAdj_ctns()!=0) {
                    int ctns = locDetail.getCtns()>=adjDetailCon.getAdj_ctns() ? (locDetail.getCtns() + adjDetailCon.getAdj_ctns()) : 0;
                    locDetail.setCtns(ctns);
                }
                if(adjDetailCon.getAdj_wt()!=0 ) {
                    double wt = locDetail.getWt()>=adjDetailCon.getAdj_wt() ? (locDetail.getWt() + adjDetailCon.getAdj_wt()) : 0;
                    locDetail.setWt(wt);
                }
                locDetail.setMemo(adjDetailCon.getMemo());
                result = locDetailService.upLocDetail(locDetail);
                
                if(result>0) {
                    AdjDetailBean adjDetail = new AdjDetailBean();
                    adjDetail.setLoc_no(loc_no);
                    adjDetail.setMat_no(mat_no);
 
                    adjDetail.setS_qty(adjDetailCon.getQty());
                    adjDetail.setS_ctns(adjDetailCon.getCtns());
                    adjDetail.setS_wt(adjDetailCon.getWt());
                    adjDetail.setAdj_qty(adjDetailCon.getAdj_qty());
                    adjDetail.setAdj_ctns(adjDetailCon.getAdj_ctns());
                    adjDetail.setAdj_wt(adjDetailCon.getAdj_wt());
                    adjDetail.setQty(locDetail.getQty());
                    adjDetail.setCtns(locDetail.getCtns());
                    adjDetail.setWt(locDetail.getWt());
                    adjDetail.setMemo(adjDetailCon.getMemo());
                    adjDetail.setModi_user(user.getUser_account());
                    adjDetailService.insertAdjDetail(adjDetail);
                }
            }
            
            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("upAdjDetail.action");
                sysLog.setTts_keyname("库存调整修改明细:" + adjDetailCon.getLoc_no() + "-"+ adjDetailCon.getMat_no());
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除信息
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/delAdjDetl.action")
    public int delAdjDetail(@RequestParam("loc_no")String loc_no,
            @RequestParam("mat_no")String mat_no,HttpServletRequest request){
        int result = 0;
        UserBean user = (UserBean) request.getSession().getAttribute("USER");
        try {                    
            LocDetailBean locDetail = locDetailService.queryLocDetailById(loc_no, mat_no);
            if (locDetail != null) {
                result = locDetailService.delLocDetail(loc_no, mat_no);
 
                if(result>0) {
                    AdjDetailBean adjDetail = new AdjDetailBean();
                    adjDetail.setLoc_no(loc_no);
                    adjDetail.setMat_no(mat_no);
 
                    adjDetail.setS_qty(locDetail.getQty());
                    adjDetail.setS_ctns(locDetail.getCtns());
                    adjDetail.setS_wt(locDetail.getWt());
                    adjDetail.setAdj_qty(0-locDetail.getQty());
                    adjDetail.setAdj_ctns(0-locDetail.getCtns());
                    adjDetail.setAdj_wt(0-locDetail.getWt());
                    adjDetail.setQty(0);
                    adjDetail.setCtns(0);
                    adjDetail.setWt(0);
//                    adjDetail.setMemo("");
                    adjDetail.setModi_user(user.getUser_account());
                    adjDetailService.insertAdjDetail(adjDetail);
                }
            }
            
            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("delAdjDetail.action");
                sysLog.setTts_keyname("库存调整删除明细:" + loc_no+"-"+mat_no);
                sysLog.setModi_user(user.getUser_account());
                sysLogService.insertSysLog(sysLog);
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    /**
     * 查询所有
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAdjDetail.action")
    public List<AdjDetailBean> getAdjDetail(){
        try {
            return adjDetailService.getAdjDetailList();
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }        
    }
    
}