TTInfoDetailController.java
5.08 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
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.bsth.controller.schedule;
import com.bsth.common.ResponseCode;
import com.bsth.controller.BaseController;
import com.bsth.entity.CarPark;
import com.bsth.entity.LineInformation;
import com.bsth.entity.schedule.TTInfoDetail;
import com.bsth.repository.schedule.TTInfoDetailRepository;
import com.bsth.service.CarParkService;
import com.bsth.service.LineInformationService;
import com.bsth.service.schedule.TTInfoDetailServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Created by xu on 16/7/2.
*/
@RestController
@RequestMapping("tidc")
public class TTInfoDetailController extends BaseController<TTInfoDetail, Long> {
@Autowired
private TTInfoDetailServiceImpl ttInfoDetailService;
@Autowired
private CarParkService carParkService;
@Autowired
private LineInformationService lineInformationService;
@Autowired
private TTInfoDetailRepository ttInfoDetailRepository;
@RequestMapping(value = "/dataImportExtend", method = RequestMethod.POST)
public Map<String, Object> uploadDataAndImport(
MultipartFile file, String xlmc, String ttinfoname) throws Exception {
Map<String, Object> resultMap = new HashMap<>();
try {
// 查找lineinformation对象,没有报错
Map<String, Object> param = new HashMap<>();
param.put("line.name_eq", xlmc);
Iterator<LineInformation> lineInformationIterator = lineInformationService.list(param).iterator();
if (!lineInformationIterator.hasNext()) {
// 没有lineinformation,报错
resultMap.put("status", ResponseCode.ERROR);
resultMap.put("msg", "没有lineinfomation,线路名称=" + xlmc);
} else {
String tcccode = lineInformationIterator.next().getCarPark();
if (StringUtils.isEmpty(tcccode)) {
// 没有停车场code,报错
resultMap.put("status", ResponseCode.ERROR);
resultMap.put("msg", "线路lineinfomation没有停车场code信息,线路名称=" + xlmc);
} else {
// 使用停车场code查找停车场
param.clear();;
param.put("parkCode_eq", tcccode);
Iterator<CarPark> carParkIterator = carParkService.list(param).iterator();
if (!carParkIterator.hasNext()) {
// 指定的停车场code没有找到停车场信息,报错
resultMap.put("status", ResponseCode.ERROR);
resultMap.put("msg", "没有找到停车场信息,停车场code=" + tcccode);
} else {
String tccname = carParkIterator.next().getParkName();
if (StringUtils.isEmpty(tccname)) {
// 没有停车场名字,报错
resultMap.put("status", ResponseCode.ERROR);
resultMap.put("msg", "停车场信息没有停车场名字,停车场code=" + tcccode);
} else {
ttInfoDetailService.fileDataImport(file, xlmc, ttinfoname, tccname);
resultMap.put("status", ResponseCode.SUCCESS);
resultMap.put("msg", "导入成功");
}
}
}
}
} catch (Exception exp) {
exp.printStackTrace();
throw exp;
}
return resultMap;
}
@RequestMapping(value = "/edit/{xlid}/{ttid}", method = RequestMethod.GET)
public Object getEditInfo(
@PathVariable("xlid") Integer xlid,
@PathVariable("ttid") Long ttid) throws Exception {
// TODO:返回类型需要修正
return ttInfoDetailService.getEditInfo(xlid, ttid);
}
/**
* 覆写方法,因为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 TTInfoDetail t){
return baseService.save(t);
}
@Override
public TTInfoDetail findById(@PathVariable("id") Long aLong) {
return ttInfoDetailRepository.findOneExtend(aLong);
}
@RequestMapping(value = "/bcdetail", method = RequestMethod.GET)
public List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId) {
return ttInfoDetailRepository.findBcdetails(xlId, ttinfoId, lpId);
}
}