|
@@ -1,9 +1,16 @@
|
|
|
package com.zy.omp.controller.wx;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.zy.omp.common.ServerResponse;
|
|
|
import com.zy.omp.common.controller.BaseController;
|
|
|
+import com.zy.omp.model.Device;
|
|
|
+import com.zy.omp.model.Relation;
|
|
|
import com.zy.omp.service.DeviceInfoStateService;
|
|
|
+import com.zy.omp.service.DeviceService;
|
|
|
+import com.zy.omp.service.RelationService;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
@@ -21,12 +28,69 @@ public class DeviceController extends BaseController {
|
|
|
|
|
|
@Resource
|
|
|
private DeviceInfoStateService deviceInfoStateService;
|
|
|
+ @Resource
|
|
|
+ private RelationService relationService;
|
|
|
+ @Resource
|
|
|
+ private DeviceService deviceService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询用户设备的最新数据
|
|
|
+ */
|
|
|
+ @GetMapping("getLatestState.do")
|
|
|
+ public ServerResponse getLatestState() {
|
|
|
+ return ServerResponse.createBySuccess(deviceInfoStateService.getLatestState(getOpenId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置默认设备
|
|
|
+ */
|
|
|
+ @PostMapping("setDefault.do")
|
|
|
+ public ServerResponse setDefault(String openNum) {
|
|
|
+ relationService.update(new UpdateWrapper<Relation>()
|
|
|
+ .set("isDefault", 1)
|
|
|
+ .eq("openId", getOpenId())
|
|
|
+ .eq("openNum", openNum));
|
|
|
+ return ServerResponse.createBySuccess();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- * 查询用户的所有设备
|
|
|
+ * 更新设备名称
|
|
|
*/
|
|
|
- @GetMapping("getListByOpenId.do")
|
|
|
- public ServerResponse listByUserId() {
|
|
|
- return ServerResponse.createBySuccess(deviceInfoStateService.listByUserId(getOpenId()));
|
|
|
+ @PostMapping("updateName.do")
|
|
|
+ public ServerResponse updateName(Relation relation) {
|
|
|
+ relationService.update(new UpdateWrapper<Relation>()
|
|
|
+ .set("deviceName", relation.getDeviceName())
|
|
|
+ .eq("openId", getOpenId())
|
|
|
+ .eq("openNum", relation.getOpenNum()));
|
|
|
+ return ServerResponse.createBySuccess();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加绑定关系
|
|
|
+ */
|
|
|
+ @PostMapping("bind.do")
|
|
|
+ public ServerResponse bind(String openNum) {
|
|
|
+ //校验设备码有效性
|
|
|
+ if (deviceService.getOne(new QueryWrapper<Device>().eq("openNum", openNum)) == null)
|
|
|
+ return ServerResponse.createByWarning("设备码无效!");
|
|
|
+ //校验是否有绑定关系
|
|
|
+ if (relationService.checkBind(openNum)) return ServerResponse.createByWarning("该设备已经有用户绑定!");
|
|
|
+ Relation relation = new Relation();
|
|
|
+ relation.setOpenNum(openNum);
|
|
|
+ relation.setOpenId(getOpenId());
|
|
|
+ relationService.save(relation);
|
|
|
+ return ServerResponse.createBySuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解除绑定关系
|
|
|
+ */
|
|
|
+ @PostMapping("unbind.do")
|
|
|
+ public ServerResponse unbind(String openNum) {
|
|
|
+ relationService.remove(new QueryWrapper<Relation>()
|
|
|
+ .eq("openNum", openNum)
|
|
|
+ .eq("openId", getOpenId()));
|
|
|
+ return ServerResponse.createBySuccess();
|
|
|
+ }
|
|
|
+
|
|
|
}
|