Yansen vor 2 Jahren
Ursprung
Commit
9fd74c17d7

+ 3
- 2
src/main/java/com/yunzhi/nanyang/controller/TaMachineryController.java Datei anzeigen

@@ -81,12 +81,13 @@ public class TaMachineryController extends BaseController {
81 81
                                         @ApiParam("名称") @RequestParam(value ="name", required = false) String name,
82 82
                                         @ApiParam("类型") @RequestParam(value ="typeId", required = false) String typeId,
83 83
                                         @ApiParam("机构ID") @RequestParam(value ="orgId", required = false) String orgId,
84
-                                        @ApiParam("状态") @RequestParam(value ="status", required = false) Integer status) throws Exception{
84
+                                        @ApiParam("状态") @RequestParam(value ="status", required = false) Integer status,
85
+                                        @ApiParam("绑定设备") @RequestParam(value ="isBound", defaultValue = "false") Boolean isBound) throws Exception{
85 86
         checkOrgAccess(orgId);
86 87
 
87 88
         IPage<TaMachinery> pg = new Page<>(pageNum, pageSize);
88 89
 
89
-        IPage<TaMachinery> result = iTaMachineryService.getPageBy(pg, name, typeId, orgId, status);
90
+        IPage<TaMachinery> result = iTaMachineryService.getPageBy(pg, name, typeId, orgId, status, isBound);
90 91
         return ResponseBean.success(result);
91 92
     }
92 93
 

+ 102
- 62
src/main/java/com/yunzhi/nanyang/controller/TaMachineryGpsController.java Datei anzeigen

@@ -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
 }

+ 11
- 0
src/main/java/com/yunzhi/nanyang/controller/TaWorkJobController.java Datei anzeigen

@@ -228,7 +228,18 @@ public class TaWorkJobController extends BaseController {
228 228
         }
229 229
 
230 230
         TaWorkJob taWorkJob = iTaWorkJobService.getDetailBy(id);
231
+        return ResponseBean.success(taWorkJob);
232
+    }
231 233
 
234
+
235
+    /**
236
+     * 根据id查询对象
237
+     * @param id  实体ID
238
+     */
239
+    @RequestMapping(value="/admin/work-job/{id}",method= RequestMethod.GET)
240
+    @ApiOperation(value="获取详情", notes = "获取详情", httpMethod = "GET", response = ResponseBean.class)
241
+    public ResponseBean getDetail(@ApiParam("对象ID") @PathVariable String id) throws Exception {
242
+        TaWorkJob taWorkJob = iTaWorkJobService.getDetailBy(id);
232 243
         return ResponseBean.success(taWorkJob);
233 244
     }
234 245
 }

+ 2
- 2
src/main/java/com/yunzhi/nanyang/controller/TaWorkMessageController.java Datei anzeigen

@@ -51,8 +51,8 @@ public class TaWorkMessageController extends BaseController {
51 51
 
52 52
         IPage<TaWorkMessage> pg = new Page<>(pageNum, pageSize);
53 53
         QueryWrapper<TaWorkMessage> queryWrapper = new QueryWrapper<>();
54
-        queryWrapper.eq(StringUtils.isEmpty(messageType), "message_type", messageType);
55
-        queryWrapper.like(StringUtils.isEmpty(orderNo), "order_no", "%" + orderNo + "%");
54
+        queryWrapper.eq(!StringUtils.isEmpty(messageType), "message_type", messageType);
55
+        queryWrapper.like(!StringUtils.isEmpty(orderNo), "order_no", "%" + orderNo + "%");
56 56
         queryWrapper.orderByDesc("create_date");
57 57
 
58 58
         IPage<TaWorkMessage> result = iTaWorkMessageService.page(pg, queryWrapper);

+ 38
- 26
src/main/java/com/yunzhi/nanyang/controller/TdRawDeviceController.java Datei anzeigen

@@ -1,11 +1,14 @@
1 1
 package com.yunzhi.nanyang.controller;
2 2
 
3
+import com.alibaba.fastjson.JSONObject;
3 4
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 5
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 6
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 7
 import com.yunzhi.nanyang.common.BaseController;
8
+import com.yunzhi.nanyang.common.HttpUtils;
7 9
 import com.yunzhi.nanyang.common.ResponseBean;
8 10
 
11
+import java.time.LocalDateTime;
9 12
 import java.util.List;
10 13
 
11 14
 import com.yunzhi.nanyang.common.StringUtils;
@@ -13,6 +16,7 @@ import io.swagger.annotations.Api;
13 16
 import io.swagger.annotations.ApiOperation;
14 17
 import io.swagger.annotations.ApiParam;
15 18
 import org.springframework.beans.factory.annotation.Autowired;
19
+import org.springframework.beans.factory.annotation.Value;
16 20
 import org.springframework.web.bind.annotation.*;
17 21
 import com.yunzhi.nanyang.entity.TdRawDevice;
18 22
 import com.yunzhi.nanyang.service.TdRawDeviceService;
@@ -28,6 +32,12 @@ import com.yunzhi.nanyang.service.TdRawDeviceService;
28 32
 @RequestMapping("/")
29 33
 public class TdRawDeviceController extends BaseController {
30 34
 
35
+    @Value("${device.server}")
36
+    String deviceServer;
37
+
38
+    @Autowired
39
+    HttpUtils httpUtils;
40
+
31 41
     @Autowired
32 42
     private TdRawDeviceService tdRawDeviceService;
33 43
 
@@ -67,32 +77,34 @@ public class TdRawDeviceController extends BaseController {
67 77
 //        return ResponseBean.success(result);
68 78
 //    }
69 79
 
70
-//    /** 
71
-//     * 新增数据
72
-//     *
73
-//     * @param tdRawDevice 实例对象
74
-//     * @return 实例对象
75
-//     */
76
-//    @ApiOperation("新增数据")
77
-//    @PostMapping("/raw-device")
78
-//    public ResponseBean add(@ApiParam("对象实体") @RequestBody TdRawDevice tdRawDevice) throws Exception {
79
-//        tdRawDeviceService.save(tdRawDevice);
80
-//        return ResponseBean.success(tdRawDevice);
81
-//    }
82
-//    
83
-//    /** 
84
-//     * 更新数据
85
-//     *
86
-//     * @param tdRawDevice 实例对象
87
-//     * @return 实例对象
88
-//     */
89
-//    @ApiOperation("更新数据")
90
-//    @PutMapping("/raw-device/{id}")
91
-//    public ResponseBean edit(@ApiParam("对象实体") @RequestBody TdRawDevice tdRawDevice,
92
-//                            @ApiParam("对象ID") @PathVariable String id ) throws Exception {
93
-//        tdRawDeviceService.updateById(tdRawDevice);
94
-//        return ResponseBean.success(tdRawDevice);
95
-//    }
80
+    /**
81
+     * 新增数据
82
+     *
83
+     * @param tdRawDevice 实例对象
84
+     * @return 实例对象
85
+     */
86
+    @ApiOperation("新增设备")
87
+    @PostMapping("/admin/raw-device")
88
+    public ResponseBean add(@ApiParam("对象实体") @RequestBody TdRawDevice tdRawDevice) throws Exception {
89
+        tdRawDevice.setDeviceStatus(0); // 默认离线
90
+        tdRawDevice.setCreateDate(LocalDateTime.now());
91
+        tdRawDeviceService.save(tdRawDevice);
92
+        return ResponseBean.success(tdRawDevice);
93
+    }
94
+
95
+    /**
96
+     * 同步设备
97
+     *
98
+     * @param
99
+     * @return 实例对象
100
+     */
101
+    @ApiOperation("同步设备")
102
+    @PutMapping("/raw-device/sync")
103
+    public ResponseBean sync() throws Exception {
104
+        String url = deviceServer + "/shensong/syncDevice";
105
+        String s = httpUtils.get(url);
106
+        return JSONObject.parseObject(s, ResponseBean.class);
107
+    }
96 108
 //    
97 109
 //    /** 
98 110
 //     * 通过主键删除数据

+ 1
- 1
src/main/java/com/yunzhi/nanyang/entity/TdRawDevice.java Datei anzeigen

@@ -25,7 +25,7 @@ import lombok.experimental.Accessors;
25 25
 public class TdRawDevice implements Serializable,Cloneable{
26 26
     /** 设备ID */
27 27
     @ApiModelProperty(name = "设备ID",notes = "")
28
-    @TableId(value = "device_id", type = IdType.INPUT)
28
+    @TableId(value = "device_id", type = IdType.UUID)
29 29
     private String deviceId ;
30 30
     /** 设备大类 */
31 31
     @ApiModelProperty(name = "设备大类",notes = "")

+ 2
- 1
src/main/java/com/yunzhi/nanyang/mapper/TaMachineryMapper.java Datei anzeigen

@@ -45,7 +45,8 @@ public interface TaMachineryMapper extends BaseMapper<TaMachinery> {
45 45
                                  @Param("name") String name,
46 46
                                  @Param("typeId") String typeId,
47 47
                                  @Param("orgId") String orgId,
48
-                                 @Param("status") Integer status);
48
+                                 @Param("status") Integer status,
49
+                                 @Param("isBound") Boolean isBound);
49 50
 
50 51
     @Select("SELECT 'machinery' as `name`, count(*) as `value` FROM ta_machinery WHERE `status` > -1")
51 52
     ChartParam statisTotal();

+ 1
- 1
src/main/java/com/yunzhi/nanyang/service/ITaMachineryService.java Datei anzeigen

@@ -33,7 +33,7 @@ public interface ITaMachineryService extends IBaseService<TaMachinery> {
33 33
 
34 34
     boolean updateStatus(String machineryId, String statusColumn, int statusValue);
35 35
 
36
-    IPage<TaMachinery> getPageBy(IPage<TaMachinery> pg, String name, String typeId, String orgId, Integer status);
36
+    IPage<TaMachinery> getPageBy(IPage<TaMachinery> pg, String name, String typeId, String orgId, Integer status, Boolean isBound);
37 37
 
38 38
     ChartParam statisTotal();
39 39
 

+ 2
- 3
src/main/java/com/yunzhi/nanyang/service/impl/TaMachineryServiceImpl.java Datei anzeigen

@@ -1,6 +1,5 @@
1 1
 package com.yunzhi.nanyang.service.impl;
2 2
 
3
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 3
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
5 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
6 5
 import com.yunzhi.nanyang.common.Constants;
@@ -136,8 +135,8 @@ public class TaMachineryServiceImpl extends BaseServiceImpl<TaMachineryMapper, T
136 135
     }
137 136
 
138 137
     @Override
139
-    public IPage<TaMachinery> getPageBy(IPage<TaMachinery> pg, String name, String typeId, String orgId, Integer status) {
140
-        return baseMapper.getPageBy(pg, name, typeId, orgId, status);
138
+    public IPage<TaMachinery> getPageBy(IPage<TaMachinery> pg, String name, String typeId, String orgId, Integer status, Boolean isBound) {
139
+        return baseMapper.getPageBy(pg, name, typeId, orgId, status, isBound);
141 140
     }
142 141
 
143 142
     @Override

+ 3
- 0
src/main/resources/application.yml Datei anzeigen

@@ -41,6 +41,9 @@ hatc:
41 41
   ### 海康接口服务
42 42
   apiServer: http://localhost:7081
43 43
 
44
+device:
45
+  server: http://localhost:7081
46
+
44 47
 ###
45 48
 yz:
46 49
   default:

+ 4
- 0
src/main/resources/mapper/TaMachineryMapper.xml Datei anzeigen

@@ -73,6 +73,10 @@
73 73
         FROM
74 74
             ta_machinery t
75 75
             INNER JOIN ta_org m ON m.org_id = t.org_id
76
+
77
+        <if test="isBound != null and isBound">
78
+            INNER JOIN td_device d on t.machinery_id = d.machinery_id
79
+        </if>
76 80
         WHERE
77 81
             t.`status` &gt; -1
78 82
         <if test="name != null and name != ''">