Przeglądaj źródła

用户模块 更新设备信息

songfuqiang 2 lat temu
rodzic
commit
fe475e0134

+ 6 - 2
backend-core/src/main/java/cn/kdan/pdf/backend/core/controller/DeviceController.java

@@ -1,12 +1,16 @@
 package cn.kdan.pdf.backend.core.controller;
 
+import cn.kdan.pdf.backend.core.params.RelationParam;
 import cn.kdan.pdf.backend.core.service.DeviceService;
+import constant.CommonConstant;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import pojo.AppRequestParam;
 import pojo.AppResultMap;
+import pojo.Device;
 
 /**
  * @author sfq
@@ -20,8 +24,8 @@ public class DeviceController {
     private DeviceService deviceService;
 
     @PutMapping("/updateInfo")
-    public AppResultMap updateInfo(AppRequestParam param){
-        return new AppResultMap();
+    public AppResultMap<Device> updateInfo(@RequestBody AppRequestParam<RelationParam> param){
+        return new AppResultMap(CommonConstant.SUCCESS,CommonConstant.CODE_SUCCESS,deviceService.updateInfo(param.getData()));
     }
 
 }

+ 8 - 0
backend-core/src/main/java/cn/kdan/pdf/backend/core/service/DeviceService.java

@@ -1,6 +1,8 @@
 package cn.kdan.pdf.backend.core.service;
 
 import cn.kdan.pdf.backend.core.model.Devices;
+import cn.kdan.pdf.backend.core.params.RelationParam;
+import pojo.Device;
 
 /**
  * @author : SongFuQiang
@@ -30,4 +32,10 @@ public interface DeviceService {
      */
     void update(Devices device, String uuid);
 
+    /**
+     * 更新设备信息
+     * @param param device+location
+     * @return device
+     */
+    Device updateInfo(RelationParam param);
 }

+ 23 - 0
backend-core/src/main/java/cn/kdan/pdf/backend/core/service/impl/DeviceServiceImpl.java

@@ -3,12 +3,17 @@ package cn.kdan.pdf.backend.core.service.impl;
 import cn.kdan.pdf.backend.core.mapper.DevicesMapper;
 import cn.kdan.pdf.backend.core.model.Devices;
 import cn.kdan.pdf.backend.core.model.DevicesExample;
+import cn.kdan.pdf.backend.core.model.Members;
+import cn.kdan.pdf.backend.core.params.RelationParam;
 import cn.kdan.pdf.backend.core.service.DeviceService;
+import cn.kdan.pdf.backend.core.service.MemberService;
 import exception.BackendRuntimeException;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import pojo.Device;
 
 import javax.annotation.Resource;
 import java.util.Date;
@@ -24,6 +29,8 @@ public class DeviceServiceImpl implements DeviceService {
 
     @Resource
     private DevicesMapper devicesMapper;
+    @Resource
+    private MemberService memberService;
 
     @Override
     @Transactional(rollbackFor = BackendRuntimeException.class)
@@ -65,4 +72,20 @@ public class DeviceServiceImpl implements DeviceService {
         example.createCriteria().andMemberIdEqualTo(device.getMemberId()).andUuidEqualTo(uuid);
         devicesMapper.updateByExample(device,example);
     }
+
+    @Override
+    @Transactional(rollbackFor = BackendRuntimeException.class)
+    public Device updateInfo(RelationParam param) {
+        Members currentUser = memberService.getCurrentUser();
+        DevicesExample example = new DevicesExample();
+        example.createCriteria().andMemberIdEqualTo(currentUser.getId());
+        List<Devices> devices = devicesMapper.selectByExample(example);
+        Device device = param.getDevice();
+        if(!CollectionUtils.isEmpty(devices)){
+            Devices dev = devices.get(0);
+            BeanUtils.copyProperties(device,dev);
+            devicesMapper.updateByExample(dev,example);
+        }
+        return device;
+    }
 }