|
@@ -1,10 +1,19 @@
|
1
|
1
|
package com.yunzhi.nanyang.controller;
|
2
|
2
|
|
|
3
|
+import com.alibaba.fastjson.JSON;
|
|
4
|
+import com.alibaba.fastjson.JSONObject;
|
3
|
5
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
6
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
7
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
8
|
import com.yunzhi.nanyang.common.BaseController;
|
|
9
|
+import com.yunzhi.nanyang.common.Constants;
|
7
|
10
|
import com.yunzhi.nanyang.common.ResponseBean;
|
|
11
|
+import com.yunzhi.nanyang.entity.TaWorkJob;
|
|
12
|
+import com.yunzhi.nanyang.entity.TdDevice;
|
|
13
|
+import com.yunzhi.nanyang.entity.TdHatcDevice;
|
|
14
|
+import com.yunzhi.nanyang.service.ITaMachineryService;
|
|
15
|
+import com.yunzhi.nanyang.service.ITaWorkJobService;
|
|
16
|
+import com.yunzhi.nanyang.service.ITdDeviceService;
|
8
|
17
|
import io.swagger.annotations.Api;
|
9
|
18
|
import io.swagger.annotations.ApiOperation;
|
10
|
19
|
import io.swagger.annotations.ApiParam;
|
|
@@ -20,6 +29,8 @@ import com.yunzhi.nanyang.service.ITaMachineryGpsService;
|
20
|
29
|
import com.yunzhi.nanyang.entity.TaMachineryGps;
|
21
|
30
|
import org.springframework.web.bind.annotation.RestController;
|
22
|
31
|
|
|
32
|
+import java.util.List;
|
|
33
|
+
|
23
|
34
|
/**
|
24
|
35
|
* <p>
|
25
|
36
|
* 农机定位信息 前端控制器
|
|
@@ -39,81 +50,110 @@ public class TaMachineryGpsController extends BaseController {
|
39
|
50
|
@Autowired
|
40
|
51
|
public ITaMachineryGpsService iTaMachineryGpsService;
|
41
|
52
|
|
|
53
|
+ @Autowired
|
|
54
|
+ public ITaWorkJobService iTaWorkJobService;
|
|
55
|
+
|
|
56
|
+ @Autowired
|
|
57
|
+ public ITdDeviceService iTdDeviceService;
|
|
58
|
+
|
42
|
59
|
|
43
|
60
|
/**
|
44
|
61
|
* 分页查询列表
|
45
|
|
- * @param pageNum
|
46
|
|
- * @param pageSize
|
47
|
62
|
* @return
|
48
|
63
|
*/
|
49
|
|
- @RequestMapping(value="/taMachineryGps",method= RequestMethod.GET)
|
|
64
|
+ @RequestMapping(value="/admin/machinery-gps",method= RequestMethod.GET)
|
50
|
65
|
@ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
|
51
|
|
- public ResponseBean taMachineryGpsList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
52
|
|
- @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
|
53
|
|
-
|
54
|
|
- IPage<TaMachineryGps> pg = new Page<>(pageNum, pageSize);
|
55
|
|
- QueryWrapper<TaMachineryGps> queryWrapper = new QueryWrapper<>();
|
56
|
|
- queryWrapper.orderByDesc("create_date");
|
|
66
|
+ public ResponseBean taMachineryGpsList(@ApiParam("作业ID") @RequestParam(value ="jobId") String jobId) throws Exception {
|
57
|
67
|
|
58
|
|
- IPage<TaMachineryGps> result = iTaMachineryGpsService.page(pg, queryWrapper);
|
59
|
|
- return ResponseBean.success(result);
|
60
|
|
- }
|
|
68
|
+ TaWorkJob taWorkJob = iTaWorkJobService.getById(jobId);
|
|
69
|
+ if (null == taWorkJob || taWorkJob.getStatus() == Constants.STATUS_DELETE) {
|
|
70
|
+ return ResponseBean.error("未找到农机作业信息");
|
|
71
|
+ }
|
61
|
72
|
|
62
|
|
- /**
|
63
|
|
- * 保存对象
|
64
|
|
- * @param taMachineryGps 实体对象
|
65
|
|
- * @return
|
66
|
|
- */
|
67
|
|
- @RequestMapping(value="/taMachineryGps",method= RequestMethod.POST)
|
68
|
|
- @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
|
69
|
|
- public ResponseBean taMachineryGpsAdd(@ApiParam("保存内容") @RequestBody TaMachineryGps taMachineryGps) throws Exception{
|
70
|
|
-
|
71
|
|
- if (iTaMachineryGpsService.save(taMachineryGps)){
|
72
|
|
- return ResponseBean.success(taMachineryGps);
|
73
|
|
- }else {
|
74
|
|
- return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
73
|
+ if (taWorkJob.getStatus() < Constants.WORK_DOING) {
|
|
74
|
+ return ResponseBean.error("农机尚未作业");
|
75
|
75
|
}
|
76
|
|
- }
|
77
|
76
|
|
78
|
|
- /**
|
79
|
|
- * 根据id删除对象
|
80
|
|
- * @param id 实体ID
|
81
|
|
- */
|
82
|
|
- @RequestMapping(value="/taMachineryGps/{id}", method= RequestMethod.DELETE)
|
83
|
|
- @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
|
84
|
|
- public ResponseBean taMachineryGpsDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
85
|
|
- if(iTaMachineryGpsService.removeById(id)){
|
86
|
|
- return ResponseBean.success("success");
|
87
|
|
- }else {
|
88
|
|
- return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
77
|
+ if (null == taWorkJob.getStartDate() || null == taWorkJob.getEndDate()) {
|
|
78
|
+ return ResponseBean.error("未找到农机作业时间");
|
89
|
79
|
}
|
90
|
|
- }
|
91
|
80
|
|
92
|
|
- /**
|
93
|
|
- * 修改对象
|
94
|
|
- * @param id 实体ID
|
95
|
|
- * @param taMachineryGps 实体对象
|
96
|
|
- * @return
|
97
|
|
- */
|
98
|
|
- @RequestMapping(value="/taMachineryGps/{id}",method= RequestMethod.PUT)
|
99
|
|
- @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
|
100
|
|
- public ResponseBean taMachineryGpsUpdate(@ApiParam("对象ID") @PathVariable Integer id,
|
101
|
|
- @ApiParam("更新内容") @RequestBody TaMachineryGps taMachineryGps) throws Exception{
|
102
|
|
-
|
103
|
|
- if (iTaMachineryGpsService.updateById(taMachineryGps)){
|
104
|
|
- return ResponseBean.success(iTaMachineryGpsService.getById(id));
|
105
|
|
- }else {
|
106
|
|
- return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
81
|
+ // 获取设备信息
|
|
82
|
+ TdDevice tdDevice = iTdDeviceService.getExistBy("machinery_id", taWorkJob.getMachineryId(), false, true);
|
|
83
|
+ if (null == tdDevice) {
|
|
84
|
+ return ResponseBean.error("未找到作业农机的GPS设备信息");
|
107
|
85
|
}
|
108
|
|
- }
|
109
|
86
|
|
110
|
|
- /**
|
111
|
|
- * 根据id查询对象
|
112
|
|
- * @param id 实体ID
|
113
|
|
- */
|
114
|
|
- @RequestMapping(value="/taMachineryGps/{id}",method= RequestMethod.GET)
|
115
|
|
- @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
|
116
|
|
- public ResponseBean taMachineryGpsGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
117
|
|
- return ResponseBean.success(iTaMachineryGpsService.getById(id));
|
|
87
|
+ // apiconfig 字符串格式一般为
|
|
88
|
+ // {"channel":1,"netType":1,"deviceId":"52bb072175e914ffae1db96cff652817"}
|
|
89
|
+ JSONObject jsonObject = JSON.parseObject(tdDevice.getApiConfig());
|
|
90
|
+ String deviceId = jsonObject.getString("deviceId");
|
|
91
|
+
|
|
92
|
+ QueryWrapper<TaMachineryGps> queryWrapper = new QueryWrapper<>();
|
|
93
|
+ queryWrapper.eq("device_id", deviceId);
|
|
94
|
+ queryWrapper.ge("create_date", taWorkJob.getStartDate());
|
|
95
|
+ queryWrapper.le("create_date", taWorkJob.getEndDate());
|
|
96
|
+ queryWrapper.orderByAsc("create_date");
|
|
97
|
+
|
|
98
|
+ List<TaMachineryGps> result = iTaMachineryGpsService.list(queryWrapper);
|
|
99
|
+ return ResponseBean.success(result);
|
118
|
100
|
}
|
|
101
|
+
|
|
102
|
+// /**
|
|
103
|
+// * 保存对象
|
|
104
|
+// * @param taMachineryGps 实体对象
|
|
105
|
+// * @return
|
|
106
|
+// */
|
|
107
|
+// @RequestMapping(value="/taMachineryGps",method= RequestMethod.POST)
|
|
108
|
+// @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
|
|
109
|
+// public ResponseBean taMachineryGpsAdd(@ApiParam("保存内容") @RequestBody TaMachineryGps taMachineryGps) throws Exception{
|
|
110
|
+//
|
|
111
|
+// if (iTaMachineryGpsService.save(taMachineryGps)){
|
|
112
|
+// return ResponseBean.success(taMachineryGps);
|
|
113
|
+// }else {
|
|
114
|
+// return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
115
|
+// }
|
|
116
|
+// }
|
|
117
|
+//
|
|
118
|
+// /**
|
|
119
|
+// * 根据id删除对象
|
|
120
|
+// * @param id 实体ID
|
|
121
|
+// */
|
|
122
|
+// @RequestMapping(value="/taMachineryGps/{id}", method= RequestMethod.DELETE)
|
|
123
|
+// @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
|
|
124
|
+// public ResponseBean taMachineryGpsDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
|
125
|
+// if(iTaMachineryGpsService.removeById(id)){
|
|
126
|
+// return ResponseBean.success("success");
|
|
127
|
+// }else {
|
|
128
|
+// return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
129
|
+// }
|
|
130
|
+// }
|
|
131
|
+//
|
|
132
|
+// /**
|
|
133
|
+// * 修改对象
|
|
134
|
+// * @param id 实体ID
|
|
135
|
+// * @param taMachineryGps 实体对象
|
|
136
|
+// * @return
|
|
137
|
+// */
|
|
138
|
+// @RequestMapping(value="/taMachineryGps/{id}",method= RequestMethod.PUT)
|
|
139
|
+// @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
|
|
140
|
+// public ResponseBean taMachineryGpsUpdate(@ApiParam("对象ID") @PathVariable Integer id,
|
|
141
|
+// @ApiParam("更新内容") @RequestBody TaMachineryGps taMachineryGps) throws Exception{
|
|
142
|
+//
|
|
143
|
+// if (iTaMachineryGpsService.updateById(taMachineryGps)){
|
|
144
|
+// return ResponseBean.success(iTaMachineryGpsService.getById(id));
|
|
145
|
+// }else {
|
|
146
|
+// return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
|
147
|
+// }
|
|
148
|
+// }
|
|
149
|
+//
|
|
150
|
+// /**
|
|
151
|
+// * 根据id查询对象
|
|
152
|
+// * @param id 实体ID
|
|
153
|
+// */
|
|
154
|
+// @RequestMapping(value="/taMachineryGps/{id}",method= RequestMethod.GET)
|
|
155
|
+// @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
|
|
156
|
+// public ResponseBean taMachineryGpsGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
|
|
157
|
+// return ResponseBean.success(iTaMachineryGpsService.getById(id));
|
|
158
|
+// }
|
119
|
159
|
}
|