ScheduleRule1FlatController.java
2.96 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
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.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);
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++) {
param2.put("dbbm_eq", ryDbbms[j]);
Iterable<EmployeeConfigInfo> employeeConfigInfos = employeeConfigInfoService.list(param2);
ryIds[j] = employeeConfigInfos.iterator().next().getId().toString();
}
t.setRyIds(StringUtils.join(ryIds, ","));
return baseService.save(t);
}
}