ReelNumModifyController.java
3.2 KB
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
package com.myproject.webapp.controller.component;
import com.google.common.base.Strings;
import com.myproject.bean.CodeBean;
import com.myproject.bean.update.Barcode;
import com.myproject.bean.update.Storage;
import com.myproject.bean.update.StoragePos;
import com.myproject.exception.ValidateException;
import com.myproject.manager.IBarcodeManager;
import com.myproject.manager.IStoragePosManager;
import com.myproject.webapp.controller.storage.BaseController;
import com.myproject.webapp.controller.webService.DataCache;
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.ResponseBody;
import javax.servlet.http.HttpServletRequest;
/**
* Created by kangmor on 2016/4/24.
*/
@Controller
public class ReelNumModifyController extends BaseController {
@Autowired
private IBarcodeManager barcodeManager;
@Autowired
private DataCache dataCache;
@Autowired
private IStoragePosManager storagePosManager;
@RequestMapping("/component/ReelNumModify.html")
public String reelNumModify(HttpServletRequest request) {
return "component/reelNumModify";
}
/**
* AJAX 提交修改料盘数量
*/
@RequestMapping(value = "/service/store/modifyReelNum")
@ResponseBody
public String addFeederTask(HttpServletRequest request) {
String barcode = request.getParameter("code");
String num = request.getParameter("num");
if(Strings.isNullOrEmpty(num)){
return "数量不能为空";
}
try{
int newAmount = Integer.valueOf(num);
CodeBean codeBean = dataCache.resolveSingleCode(barcode);
Barcode br = codeBean.getBarcode();
if(br != null){
log.info("更新条码["+br.getBarcode()+"]的数量["+br.getAmount()+"]为:"+newAmount);
br.setAmount(newAmount);
barcodeManager.save(br);
StoragePos pos = storagePosManager.getByBarcode(br.getBarcode());
if(pos != null){
Barcode barcodeInPos = pos.getBarcode();
barcodeInPos.setAmount(newAmount);
storagePosManager.save(pos);
log.info("更新库位["+pos.getPosName()+"]中条码数量为:" + newAmount);
int oldAmount = barcodeInPos.getAmount();
int diffAount = newAmount - oldAmount;
if(diffAount != 0){
//更新库存
Storage storage = dataCache.getStorageById(pos.getStorageId());
dataCache.updateInventoryAmount(storage.getCid(), barcodeInPos.getPartNumber(), diffAount);
}
}
}else{
throw new ValidateException(codeBean.getErrorCode(), codeBean.getParams(),codeBean.getError());
}
}catch (ValidateException ve){
String msg = getText(ve.getMessage(),ve.getParams(),request.getLocale());
return msg;
}catch (Exception e){
return e.getMessage();
}
return "";
}
}