Yansen 2 年前
父节点
当前提交
4a4909f0d1

+ 1
- 1
pom.xml 查看文件

@@ -10,7 +10,7 @@
10 10
 	</parent>
11 11
 	<groupId>com.yunzhi</groupId>
12 12
 	<artifactId>nanyang</artifactId>
13
-	<version>0.0.2</version>
13
+	<version>0.0.3</version>
14 14
 	<name>main-service</name>
15 15
 	<description>Demo project for Spring Boot</description>
16 16
 

+ 101
- 0
src/main/java/com/yunzhi/nanyang/controller/TcBindController.java 查看文件

@@ -0,0 +1,101 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.ResponseBean;
8
+import java.util.List;
9
+import io.swagger.annotations.Api;
10
+import io.swagger.annotations.ApiOperation;
11
+import io.swagger.annotations.ApiParam;
12
+import org.springframework.beans.factory.annotation.Autowired;
13
+import org.springframework.web.bind.annotation.*;
14
+import com.yunzhi.nanyang.entity.TcBind;
15
+import com.yunzhi.nanyang.service.TcBindService;
16
+
17
+ /**
18
+ * 绑定表;(tc_bind)表控制层
19
+ * @author : http://njyunzhi.com
20
+ * @date : 2022-11-22
21
+ */
22
+@Api(tags = "绑定表对象功能接口")
23
+@RestController
24
+@RequestMapping("/")
25
+public class TcBindController extends BaseController {
26
+    
27
+    @Autowired
28
+    private TcBindService tcBindService;
29
+    
30
+    /** 
31
+     * 通过ID查询单条数据 
32
+     *
33
+     * @param serialNo 主键
34
+     * @return 实例对象
35
+     */
36
+    @ApiOperation("通过ID查询单条数据")
37
+    @GetMapping("/tcBind/{id}")
38
+    public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
39
+        return ResponseBean.success(tcBindService.getById(id));
40
+    }
41
+    
42
+    /** 
43
+     * 分页查询
44
+     *
45
+     * @param pageNum 当前页码
46
+     * @param pageSize 每页条数
47
+     * @return 查询结果
48
+     */
49
+    @ApiOperation("分页查询")
50
+    @GetMapping("/tcBind")
51
+    public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+                            @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
53
+        
54
+        IPage<TcBind> pg = new Page<>(pageNum, pageSize);
55
+        // QueryWrapper<TcBind> queryWrapper = new QueryWrapper<>();
56
+        // queryWrapper.orderByDesc("create_date");
57
+        IPage<TcBind> result = tcBindService.page(pg);
58
+        
59
+        return ResponseBean.success(result);
60
+    }
61
+    
62
+    /** 
63
+     * 新增数据
64
+     *
65
+     * @param tcBind 实例对象
66
+     * @return 实例对象
67
+     */
68
+    @ApiOperation("新增数据")
69
+    @PostMapping("/tcBind")
70
+    public ResponseBean add(@ApiParam("对象实体") @RequestBody TcBind tcBind) throws Exception {
71
+        tcBindService.save(tcBind);
72
+        return ResponseBean.success(tcBind);
73
+    }
74
+    
75
+    /** 
76
+     * 更新数据
77
+     *
78
+     * @param tcBind 实例对象
79
+     * @return 实例对象
80
+     */
81
+    @ApiOperation("更新数据")
82
+    @PutMapping("/tcBind/{id}")
83
+    public ResponseBean edit(@ApiParam("对象实体") @RequestBody TcBind tcBind,
84
+                            @ApiParam("对象ID") @PathVariable Integer id ) throws Exception {
85
+        tcBindService.updateById(tcBind);
86
+        return ResponseBean.success(tcBind);
87
+    }
88
+    
89
+    /** 
90
+     * 通过主键删除数据
91
+     *
92
+     * @param serialNo 主键
93
+     * @return 是否成功
94
+     */
95
+    @ApiOperation("通过主键删除数据")
96
+    @DeleteMapping("/tcBind/{id}")
97
+    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
98
+        tcBindService.removeLogicById(id);
99
+        return ResponseBean.success("success");
100
+    }
101
+}

+ 30
- 2
src/main/java/com/yunzhi/nanyang/controller/TdRawDeviceController.java 查看文件

@@ -9,8 +9,10 @@ import com.yunzhi.nanyang.common.*;
9 9
 import java.time.LocalDateTime;
10 10
 import java.util.List;
11 11
 
12
+import com.yunzhi.nanyang.entity.TcBind;
12 13
 import com.yunzhi.nanyang.entity.TdDevice;
13 14
 import com.yunzhi.nanyang.service.ITdDeviceService;
15
+import com.yunzhi.nanyang.service.TcBindService;
14 16
 import io.swagger.annotations.Api;
15 17
 import io.swagger.annotations.ApiOperation;
16 18
 import io.swagger.annotations.ApiParam;
@@ -44,6 +46,9 @@ public class TdRawDeviceController extends BaseController {
44 46
     @Autowired
45 47
     private ITdDeviceService iTdDeviceService;
46 48
 
49
+    @Autowired
50
+    private TcBindService tcBindService;
51
+
47 52
 //    /** 
48 53
 //     * 通过ID查询单条数据 
49 54
 //     *
@@ -107,7 +112,7 @@ public class TdRawDeviceController extends BaseController {
107 112
             return ResponseBean.error("当前设备号已存在");
108 113
         }
109 114
 
110
-
115
+        TcBind tcBind = null;
111 116
         String url = String.format("%s/%s/tdRawDevice/%s", deviceServer, tdRawDevice.getDeviceKind(), tdRawDevice.getDeviceNo());
112 117
         String s = httpUtils.get(url);
113 118
         if (StringUtils.isEmpty(s)) {
@@ -122,13 +127,36 @@ public class TdRawDeviceController extends BaseController {
122 127
                     return ResponseBean.error("验证平台服务出错, 未找到当前设备");
123 128
                 }
124 129
             }
125
-        }
126 130
 
131
+            // 飞防设备在新增的时候,把中间数据采集表也写入
132
+            if ("feifang".equals(tdRawDevice.getDeviceKind())) {
133
+                JSONObject data = resp.getJSONObject("data");
134
+                if (data != null) {
135
+                    tcBind = tcBindService.getByDevice(tdRawDevice.getDeviceKind(), tdRawDevice.getDeviceNo());
136
+                    if (null == tcBind) {
137
+                        tcBind = new TcBind();
138
+                        tcBind.setDeviceType(tdRawDevice.getDeviceKind());
139
+                        tcBind.setDeviceNo(tdRawDevice.getDeviceNo());
140
+                        tcBind.setMachineryType(data.getString("p1"));
141
+                        tcBind.setMachineryName(data.getString("p25"));
142
+                        tcBind.setUserName(data.getString("p8"));
143
+                        tcBind.setPhone(data.getString("p7"));
144
+                        tcBind.setStatus(0);
145
+                        tcBind.setCreateDate(LocalDateTime.now());
146
+                    }
147
+                }
148
+
149
+            }
150
+        }
127 151
 
128 152
         tdRawDevice.setDeviceStatus(0); // 默认离线
129 153
         tdRawDevice.setCreateDate(LocalDateTime.now());
130 154
         tdRawDeviceService.save(tdRawDevice);
131 155
 
156
+        if (tcBind != null && null == tcBind.getSerialNo()) {
157
+            tcBindService.save(tcBind);
158
+        }
159
+
132 160
         return ResponseBean.success(tdRawDevice);
133 161
     }
134 162
 

+ 61
- 0
src/main/java/com/yunzhi/nanyang/entity/TcBind.java 查看文件

@@ -0,0 +1,61 @@
1
+package com.yunzhi.nanyang.entity;
2
+
3
+import io.swagger.annotations.ApiModel;
4
+import io.swagger.annotations.ApiModelProperty;
5
+import com.baomidou.mybatisplus.annotation.IdType;
6
+import com.baomidou.mybatisplus.annotation.TableName;
7
+import com.baomidou.mybatisplus.annotation.TableId;
8
+import java.io.Serializable;
9
+import java.time.LocalDateTime;
10
+import java.util.Date;
11
+import lombok.Data;
12
+import lombok.EqualsAndHashCode;
13
+import lombok.experimental.Accessors;
14
+
15
+ /**
16
+ * 绑定表;
17
+ * @author : http://www.chiner.pro
18
+ * @date : 2022-11-22
19
+ */
20
+@Data
21
+@EqualsAndHashCode(callSuper = false)
22
+@Accessors(chain = true)
23
+@ApiModel(value = "绑定表",description = "")
24
+@TableName("tc_bind")
25
+public class TcBind implements Serializable,Cloneable{
26
+    /** 序号 */
27
+    @ApiModelProperty(name = "序号",notes = "")
28
+    @TableId(value = "serial_no", type = IdType.AUTO)
29
+    private Integer serialNo ;
30
+    /** 设备类型 */
31
+    @ApiModelProperty(name = "设备类型",notes = "")
32
+    private String deviceType ;
33
+    /** 设备号 */
34
+    @ApiModelProperty(name = "设备号",notes = "")
35
+    private String deviceNo ;
36
+    /** 农机类型 */
37
+    @ApiModelProperty(name = "农机类型",notes = "")
38
+    private String machineryType ;
39
+    /** 农机名称 */
40
+    @ApiModelProperty(name = "农机名称",notes = "")
41
+    private String machineryName ;
42
+    /** 农机图片 */
43
+    @ApiModelProperty(name = "农机图片",notes = "")
44
+    private String machineryThumb ;
45
+    /** 归属人 */
46
+    @ApiModelProperty(name = "归属人",notes = "")
47
+    private String userName ;
48
+    /** 手机号 */
49
+    @ApiModelProperty(name = "手机号",notes = "")
50
+    private String phone ;
51
+    /** 身份证号 */
52
+    @ApiModelProperty(name = "身份证号",notes = "")
53
+    private String idCard ;
54
+    /** 状态;0未入库1已入库 */
55
+    @ApiModelProperty(name = "状态",notes = "0未入库1已入库")
56
+    private Integer status ;
57
+    /** 创建时间 */
58
+    @ApiModelProperty(name = "创建时间",notes = "")
59
+    private LocalDateTime createDate ;
60
+
61
+}

+ 17
- 0
src/main/java/com/yunzhi/nanyang/mapper/TcBindMapper.java 查看文件

@@ -0,0 +1,17 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+import com.yunzhi.nanyang.entity.TcBind;
7
+
8
+ /**
9
+ * 绑定表;(tc_bind)表数据库访问层
10
+ * @author : http://njyunzhi.com
11
+ * @date : 2022-11-22
12
+ */
13
+@Mapper
14
+public interface TcBindMapper  extends BaseMapper<TcBind>{
15
+
16
+     TcBind getByDevice(@Param("deviceType") String deviceType,@Param("deviceNo") String deviceNo);
17
+ }

+ 14
- 0
src/main/java/com/yunzhi/nanyang/service/TcBindService.java 查看文件

@@ -0,0 +1,14 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.yunzhi.nanyang.entity.TcBind;
5
+
6
+ /**
7
+ * 绑定表;(tc_bind)表服务接口
8
+ * @author : http://njyunzhi.com
9
+ * @date : 2022-11-22
10
+ */
11
+public interface TcBindService extends IBaseService<TcBind> {
12
+
13
+     TcBind getByDevice(String deviceKind, String deviceNo);
14
+ }

+ 22
- 0
src/main/java/com/yunzhi/nanyang/service/impl/TcBindServiceImpl.java 查看文件

@@ -0,0 +1,22 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.stereotype.Service;
5
+import com.yunzhi.nanyang.entity.TcBind;
6
+import com.yunzhi.nanyang.mapper.TcBindMapper;
7
+import com.yunzhi.nanyang.service.TcBindService;
8
+
9
+/**
10
+ * 绑定表;(tc_bind)表服务实现类
11
+ *
12
+ * @author : http://www.chiner.pro
13
+ * @date : 2022-11-22
14
+ */
15
+@Service
16
+public class TcBindServiceImpl extends BaseServiceImpl<TcBindMapper, TcBind> implements TcBindService {
17
+
18
+    @Override
19
+    public TcBind getByDevice(String deviceKind, String deviceNo) {
20
+        return baseMapper.getByDevice(deviceKind, deviceNo);
21
+    }
22
+}

+ 15
- 0
src/main/resources/mapper/TcBindMapper.xml 查看文件

@@ -0,0 +1,15 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+
4
+<mapper namespace="com.yunzhi.nanyang.mapper.TcBindMapper">
5
+
6
+    <select id="getByDevice" resultType="com.yunzhi.nanyang.entity.TcBind">
7
+        SELECT
8
+            *
9
+        FROM
10
+            tc_bind t
11
+        WHERE
12
+            t.device_type = #{deviceType}
13
+          AND t.device_no = #{deviceNo}
14
+    </select>
15
+</mapper>