BarcodeSettingsController.java
2.9 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
package com.myproject.webapp.controller.barcode;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.myproject.bean.update.Settings;
import com.myproject.exception.ValidateException;
import com.myproject.util.BarcodeRule;
import com.myproject.webapp.controller.system.SettingsController;
import com.myproject.webapp.controller.webService.DataCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;
@Controller
@RequestMapping("/barcode/barcodeSettings.html")
public class BarcodeSettingsController extends SettingsController {
@Autowired
private DataCache dataCache;
@Override
protected String updateView(){
return "barcode/barcodeSettings";
}
@RequestMapping(method = RequestMethod.POST)
protected String submit(@Valid Settings settings, BindingResult result,
final HttpServletRequest request, final HttpServletResponse response) throws Exception {
if(result.hasErrors()) {
return updateView();
} else {
try {
String[] codeRuleList = request.getParameterValues("codeRuleList");
if(codeRuleList != null){
settings.setCodeRuleList(Lists.newArrayList(codeRuleList));
}
for(String codeRule : settings.getCodeRuleList()){
if(!Strings.isNullOrEmpty(codeRule)){
BarcodeRule barcodeRule = BarcodeRule.newRule(codeRule);
if(!barcodeRule.isValidRule()){
throw new ValidateException("barcode.error.noRi","编码规则中必须包含 RI 和 PN");
}
}
}
Settings oldSettings = dataCache.getSettings();
oldSettings.setFontSize(settings.getFontSize());
oldSettings.setPageWidth(settings.getPageWidth());
oldSettings.setPageHeight(settings.getPageHeight());
oldSettings.setPageSpace(settings.getPageSpace());
//oldSettings.setCodeRule(codeRule);
oldSettings.setCodeRuleList(settings.getCodeRuleList());
dataCache.updateSettings(oldSettings);
saveMessage(request, getText("storage.saveSuccess", request.getLocale()));
return "redirect:barcodeSettings.html";
} catch (ValidateException e) {
handValidateException(e, request);
}
return updateView();
}
}
}