Commit f4c97b60e97377e9c9e0e7b7210b3f77b049b240
1 parent
e899a720
用户设备提交
Showing
5 changed files
with
109 additions
and
21 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/DeviceUserController.java
| ... | ... | @@ -40,19 +40,26 @@ public class DeviceUserController { |
| 40 | 40 | |
| 41 | 41 | @PostMapping("/create") |
| 42 | 42 | @Operation(summary = "创建设备用户关系") |
| 43 | - @PreAuthorize("@ss.hasPermission('garden:device-user:create')") | |
| 43 | + // @PreAuthorize("@ss.hasPermission('garden:device-user:create')") | |
| 44 | 44 | public CommonResult<Long> createDeviceUser(@Valid @RequestBody DeviceUserSaveReqVO createReqVO) { |
| 45 | 45 | return success(deviceUserService.createDeviceUser(createReqVO)); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - @PutMapping("/update") | |
| 48 | + @PutMapping("/update/device") | |
| 49 | 49 | @Operation(summary = "更新设备用户关系") |
| 50 | - @PreAuthorize("@ss.hasPermission('garden:device-user:update')") | |
| 51 | - public CommonResult<Boolean> updateDeviceUser(@Valid @RequestBody DeviceUserSaveReqVO updateReqVO) { | |
| 52 | - deviceUserService.updateDeviceUser(updateReqVO); | |
| 50 | + //@PreAuthorize("@ss.hasPermission('garden:device-user:update')") | |
| 51 | + public CommonResult<Boolean> updateDevice(@Valid @RequestBody DeviceUserUpdateReqVO updateReqVO) { | |
| 52 | + deviceUserService.updateDevice(updateReqVO); | |
| 53 | 53 | return success(true); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | + @GetMapping("/get/device_no") | |
| 57 | + @Operation(summary = "通过设备编码获取设备绑定信息") | |
| 58 | + public CommonResult<DeviceUserRespVO> getDeviceUserByDeviceNo(@RequestParam("device_no") @NotBlank String deviceNo) { | |
| 59 | + DeviceUserRespVO deviceUser = deviceUserService.getDeviceUserByDeviceNo(deviceNo); | |
| 60 | + return success(deviceUser); | |
| 61 | + } | |
| 62 | + | |
| 56 | 63 | @DeleteMapping("/delete") |
| 57 | 64 | @Operation(summary = "删除设备用户关系") |
| 58 | 65 | @Parameter(name = "id", description = "编号", required = true) | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/vo/DeviceUserSaveReqVO.java
| ... | ... | @@ -36,7 +36,6 @@ public class DeviceUserSaveReqVO { |
| 36 | 36 | @Data |
| 37 | 37 | public static class DeviceInfoDO { |
| 38 | 38 | @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") |
| 39 | - @NotEmpty(message = "产品名称不能为空") | |
| 40 | 39 | private String productName; |
| 41 | 40 | |
| 42 | 41 | @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED) | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/vo/DeviceUserUpdateReqVO.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.Valid; | |
| 5 | +import jakarta.validation.constraints.NotEmpty; | |
| 6 | +import jakarta.validation.constraints.NotNull; | |
| 7 | +import jakarta.validation.constraints.Size; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 设备用户关系新增/修改 Request VO") | |
| 13 | +@Data | |
| 14 | +public class DeviceUserUpdateReqVO { | |
| 15 | + | |
| 16 | + @Schema(description = "设备信息") | |
| 17 | + @NotNull | |
| 18 | + @Size(min = 1, message = "道路信息不能为空") | |
| 19 | + @Valid | |
| 20 | + private List<DeviceUserSaveReqVO.DeviceInfoDO> deviceInfoList; | |
| 21 | + | |
| 22 | + @Data | |
| 23 | + public static class DeviceInfoDO { | |
| 24 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | |
| 25 | + @NotEmpty(message = "产品名称不能为空") | |
| 26 | + private String productName; | |
| 27 | + | |
| 28 | + @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 29 | + @NotEmpty(message = "设备标识不能为空") | |
| 30 | + private String deviceNo; | |
| 31 | + | |
| 32 | + @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | |
| 33 | + @NotEmpty(message = "设备名称不能为空") | |
| 34 | + private String deviceName; | |
| 35 | + | |
| 36 | + @Schema(description = "连接状态 : 在线:ONLINE || 离线:OFFLINE || 未连接:INIT", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 37 | + @NotEmpty(message = "连接状态 : 在线:ONLINE || 离线:OFFLINE || 未连接:INIT") | |
| 38 | + private String deviceState; | |
| 39 | + | |
| 40 | + } | |
| 41 | + | |
| 42 | +} | |
| 0 | 43 | \ No newline at end of file | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/deviceuser/DeviceUserService.java
| ... | ... | @@ -5,10 +5,6 @@ import jakarta.validation.*; |
| 5 | 5 | import com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo.*; |
| 6 | 6 | import com.zteits.urbanops.module.garden.dal.dataobject.deviceuser.DeviceUserDO; |
| 7 | 7 | import com.zteits.urbanops.framework.common.pojo.PageResult; |
| 8 | -import com.zteits.urbanops.framework.common.pojo.PageParam; | |
| 9 | -import jakarta.validation.constraints.NotNull; | |
| 10 | -import org.springframework.web.bind.annotation.RequestBody; | |
| 11 | -import org.springframework.web.bind.annotation.RequestParam; | |
| 12 | 8 | |
| 13 | 9 | /** |
| 14 | 10 | * 设备用户关系 Service 接口 |
| ... | ... | @@ -78,4 +74,18 @@ public interface DeviceUserService { |
| 78 | 74 | */ |
| 79 | 75 | DeviceDeptTreeRespVO findDeviceDeptTree(DeviceDeptTreeReqVO reqVO); |
| 80 | 76 | |
| 77 | + /** | |
| 78 | + * IOT更新设备信息 | |
| 79 | + * | |
| 80 | + * @param updateReqVO 更新信息 | |
| 81 | + * @return 更新结果 | |
| 82 | + */ | |
| 83 | + Boolean updateDevice(DeviceUserUpdateReqVO updateReqVO); | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * 通过设备编码查询对象 | |
| 87 | + * @return 设备用户关系树 | |
| 88 | + */ | |
| 89 | + DeviceUserRespVO getDeviceUserByDeviceNo(String deviceNo); | |
| 90 | + | |
| 81 | 91 | } |
| 82 | 92 | \ No newline at end of file | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/deviceuser/DeviceUserServiceImpl.java
| ... | ... | @@ -3,14 +3,16 @@ package com.zteits.urbanops.module.garden.service.deviceuser; |
| 3 | 3 | import cn.hutool.core.collection.CollectionUtil; |
| 4 | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | 5 | import com.alibaba.fastjson.JSONObject; |
| 6 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
| 7 | +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | |
| 6 | 8 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; |
| 7 | 9 | import com.zteits.urbanops.module.garden.util.DeviceDeptTreeUtils; |
| 8 | 10 | import com.zteits.urbanops.module.garden.util.http.OkHttpClientUtil; |
| 9 | 11 | import org.springframework.beans.factory.annotation.Value; |
| 10 | 12 | import org.springframework.stereotype.Service; |
| 11 | 13 | import jakarta.annotation.Resource; |
| 14 | +import org.springframework.util.StringUtils; | |
| 12 | 15 | import org.springframework.validation.annotation.Validated; |
| 13 | -import org.springframework.transaction.annotation.Transactional; | |
| 14 | 16 | |
| 15 | 17 | import java.time.LocalDateTime; |
| 16 | 18 | import java.util.*; |
| ... | ... | @@ -54,15 +56,15 @@ public class DeviceUserServiceImpl implements DeviceUserService { |
| 54 | 56 | deviceUser.setDeptId(createReqVO.getDeptId()); |
| 55 | 57 | deviceUser.setUserId(Long.parseLong(userId)); |
| 56 | 58 | deviceUser.setUserName(userName); |
| 57 | - deviceUser.setCreateTime( now); | |
| 59 | + deviceUser.setCreateTime(now); | |
| 58 | 60 | deviceUser.setCreator(userId); |
| 59 | 61 | deviceUser.setCreatorName(userName); |
| 60 | 62 | deviceUser.setUpdater(userId); |
| 61 | - deviceUser.setUpdateTime( now); | |
| 63 | + deviceUser.setUpdateTime(now); | |
| 62 | 64 | list.add(deviceUser); |
| 63 | 65 | }); |
| 64 | 66 | // 插入 |
| 65 | - deviceUserMapper.insert( list); | |
| 67 | + deviceUserMapper.insert(list); | |
| 66 | 68 | return 1L; |
| 67 | 69 | } |
| 68 | 70 | |
| ... | ... | @@ -84,10 +86,10 @@ public class DeviceUserServiceImpl implements DeviceUserService { |
| 84 | 86 | } |
| 85 | 87 | |
| 86 | 88 | @Override |
| 87 | - public void deleteDeviceUserListByIds(List<Long> ids) { | |
| 89 | + public void deleteDeviceUserListByIds(List<Long> ids) { | |
| 88 | 90 | // 删除 |
| 89 | 91 | deviceUserMapper.deleteByIds(ids); |
| 90 | - } | |
| 92 | + } | |
| 91 | 93 | |
| 92 | 94 | |
| 93 | 95 | private void validateDeviceUserExists(Long id) { |
| ... | ... | @@ -118,19 +120,19 @@ public class DeviceUserServiceImpl implements DeviceUserService { |
| 118 | 120 | params.put("deviceName", reqVO.getDeviceName()); |
| 119 | 121 | params.put("deviceDeptName", reqVO.getDeviceDeptName()); |
| 120 | 122 | String json = OkHttpClientUtil.doPostJson(iotHost + "/deviceApi/findDeviceDeptTree", params); |
| 121 | - JSONObject jsonObject =JSONObject.parseObject(json); | |
| 122 | - if(!jsonObject.getInteger("code").equals(200)){ | |
| 123 | + JSONObject jsonObject = JSONObject.parseObject(json); | |
| 124 | + if (!jsonObject.getInteger("code").equals(200)) { | |
| 123 | 125 | return null; |
| 124 | 126 | } |
| 125 | 127 | |
| 126 | 128 | List<DeviceDeptTreeRespVO> deviceDeptTreeList = JSONArray.parseArray(jsonObject.getString("data"), DeviceDeptTreeRespVO.class); |
| 127 | - if(CollectionUtil.isEmpty(deviceDeptTreeList)){ | |
| 129 | + if (CollectionUtil.isEmpty(deviceDeptTreeList)) { | |
| 128 | 130 | return null; |
| 129 | 131 | } |
| 130 | 132 | //获取所有已绑定设备列表 |
| 131 | 133 | List<DeviceUserDO> list = deviceUserMapper.selectList(); |
| 132 | - if(CollectionUtil.isEmpty(list)){ | |
| 133 | - return deviceDeptTreeList.get(0); | |
| 134 | + if (CollectionUtil.isEmpty(list)) { | |
| 135 | + return deviceDeptTreeList.get(0); | |
| 134 | 136 | } |
| 135 | 137 | List<String> deviceNos = list.stream().map(deviceUserDO -> deviceUserDO.getDeviceNo()).collect(Collectors.toList()); |
| 136 | 138 | // |
| ... | ... | @@ -138,4 +140,32 @@ public class DeviceUserServiceImpl implements DeviceUserService { |
| 138 | 140 | return deviceDeptTreeList.get(0); |
| 139 | 141 | } |
| 140 | 142 | |
| 143 | + @Override | |
| 144 | + public Boolean updateDevice(DeviceUserUpdateReqVO updateReqVO) { | |
| 145 | + updateReqVO.getDeviceInfoList().forEach(deviceInfo -> { | |
| 146 | + UpdateWrapper<DeviceUserDO> updateWrapper = new UpdateWrapper<>(); | |
| 147 | + updateWrapper.lambda().set(!StringUtils.isEmpty(deviceInfo.getProductName()), DeviceUserDO::getProductName, deviceInfo.getProductName()) | |
| 148 | + .set(!StringUtils.isEmpty(deviceInfo.getDeviceName()), DeviceUserDO::getDeviceName, deviceInfo.getDeviceName()) | |
| 149 | + .set(!StringUtils.isEmpty(deviceInfo.getDeviceState()), DeviceUserDO::getDeviceState, deviceInfo.getDeviceState()) | |
| 150 | + .eq(DeviceUserDO::getDeviceNo, deviceInfo.getDeviceNo()); | |
| 151 | + deviceUserMapper.update(updateWrapper); | |
| 152 | + }); | |
| 153 | + | |
| 154 | + return true; | |
| 155 | + } | |
| 156 | + | |
| 157 | + @Override | |
| 158 | + public DeviceUserRespVO getDeviceUserByDeviceNo(String deviceNo) { | |
| 159 | + QueryWrapper<DeviceUserDO> query = new QueryWrapper<>(); | |
| 160 | + query.lambda().eq(DeviceUserDO::getDeviceNo, deviceNo); | |
| 161 | + List<DeviceUserDO> list = deviceUserMapper.selectList(query); | |
| 162 | + if (CollectionUtil.isEmpty(list)) { | |
| 163 | + return null; | |
| 164 | + } | |
| 165 | + | |
| 166 | + DeviceUserRespVO deviceUserRes = new DeviceUserRespVO(); | |
| 167 | + BeanUtils.copyProperties(list.get(0), deviceUserRes); | |
| 168 | + return deviceUserRes; | |
| 169 | + } | |
| 170 | + | |
| 141 | 171 | } |
| 142 | 172 | \ No newline at end of file | ... | ... |