ScheduleRule1FlatController.java
4.72 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.bsth.controller.schedule;
import com.bsth.controller.BaseController;
import com.bsth.entity.schedule.EmployeeConfigInfo;
import com.bsth.entity.schedule.GuideboardInfo;
import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
import com.bsth.repository.schedule.ScheduleRule1FlatRepository;
import com.bsth.service.schedule.EmployeeConfigInfoService;
import com.bsth.service.schedule.GuideboardInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
* Created by xu on 16/7/4.
*/
@RestController
@RequestMapping("sr1fc")
public class ScheduleRule1FlatController extends BaseController<ScheduleRule1Flat, Long> {
@Autowired
private ScheduleRule1FlatRepository scheduleRule1FlatRepository;
@Autowired
private GuideboardInfoService guideboardInfoService;
@Autowired
private EmployeeConfigInfoService employeeConfigInfoService;
@Override
public ScheduleRule1Flat findById(@PathVariable("id") Long aLong) {
return scheduleRule1FlatRepository.findOneExtend(aLong);
}
/**
* 覆写方法,因为form提交的方式参数不全,改用 json形式提交 @RequestBody
* @Title: save
* @Description: TODO(持久化对象)
* @param @param t
* @param @return 设定文件
* @return Map<String,Object> {status: 1(成功),-1(失败)}
* @throws
*/
@RequestMapping(method = RequestMethod.POST)
public Map<String, Object> save(@RequestBody ScheduleRule1Flat t){
// TODO:根据编码查找id,不做错误检测,暂时这样做,以后前端直接传过来
// 1、查找路牌配置id
Map<String, Object> param1 = new HashMap<>();
param1.put("xl.id_eq", t.getXl().getId());
param1.put("lpName_eq", null);
String[] lpNames = t.getLpNames().split(",");
String[] lpIds = new String[lpNames.length];
for (int i = 0; i < lpNames.length; i++) {
param1.put("lpName_eq", lpNames[i]);
Iterable<GuideboardInfo> guideboardInfos = guideboardInfoService.list(param1);
if (!guideboardInfos.iterator().hasNext()) {
throw new RuntimeException("路牌:" + lpNames[i] + "没有找到!");
}
lpIds[i] = guideboardInfos.iterator().next().getId().toString();
}
t.setLpIds(StringUtils.join(lpIds, ","));
// 2、查找人员配置id(这里要考虑分班的情况,先用-隔开,在用,隔开)
Map<String, Object> param2 = new HashMap<>();
param2.put("xl.id_eq", t.getXl().getId());
param2.put("dbbm_eq", null);
String[] ryDbbms = t.getRyDbbms().split(",");
String[] ryIds = new String[ryDbbms.length];
for (int j = 0; j < ryDbbms.length; j++) {
if (ryDbbms[j].indexOf("-") == -1) {
param2.put("dbbm_eq", ryDbbms[j]);
Iterable<EmployeeConfigInfo> employeeConfigInfos = employeeConfigInfoService.list(param2);
if (!employeeConfigInfos.iterator().hasNext()) {
throw new RuntimeException("搭班编码::" + ryDbbms[j] + "没有找到!");
}
ryIds[j] = employeeConfigInfos.iterator().next().getId().toString();
} else {
String[] fbRyDbbms = ryDbbms[j].split("-");
if (fbRyDbbms.length != 2) {
throw new RuntimeException("搭班编码:" + ryDbbms[j] + "错误!");
}
String[] fbRyIds = new String[2];
param2.put("dbbm_eq", fbRyDbbms[0]);
Iterable<EmployeeConfigInfo> employeeConfigInfos = employeeConfigInfoService.list(param2);
if (!employeeConfigInfos.iterator().hasNext()) {
throw new RuntimeException("搭班编码::" + fbRyDbbms[0] + "没有找到!");
}
fbRyIds[0] = employeeConfigInfos.iterator().next().getId().toString();
param2.put("dbbm_eq", fbRyDbbms[1]);
employeeConfigInfos = employeeConfigInfoService.list(param2);
if (!employeeConfigInfos.iterator().hasNext()) {
throw new RuntimeException("搭班编码::" + fbRyDbbms[1] + "没有找到!");
}
fbRyIds[1] = employeeConfigInfos.iterator().next().getId().toString();
ryIds[j] = StringUtils.join(fbRyIds, "-");
}
}
t.setRyConfigIds(StringUtils.join(ryIds, ","));
return baseService.save(t);
}
}