27 changed files with 893 additions and 16 deletions
@ -0,0 +1,20 @@ |
|||
package org.dromara.business.feign; |
|||
|
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
|
|||
import java.util.List; |
|||
|
|||
@FeignClient(name = "gateway",path = "sample") |
|||
public interface FeignDeviceGroup { |
|||
|
|||
|
|||
@GetMapping("/manage/api/v1/device/group/feign/user") |
|||
public List<Integer> listDeviceGroup(@RequestParam("userId") Long userId); |
|||
|
|||
|
|||
@GetMapping("/manage/api/v1/device/group/feign/device") |
|||
public List<String> listDevice(@RequestParam("userId") Long userId); |
|||
} |
@ -0,0 +1,114 @@ |
|||
package org.dromara.sample.manage.controller; |
|||
|
|||
import cn.hutool.core.lang.Dict; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.dromara.common.core.domain.R; |
|||
import org.dromara.common.satoken.utils.LoginHelper; |
|||
import org.dromara.common.sdk.common.HttpResultResponse; |
|||
import org.dromara.common.sdk.common.PaginationData; |
|||
import org.dromara.sample.manage.model.dto.DeviceProDTO; |
|||
import org.dromara.sample.manage.model.entity.DeviceProEntity; |
|||
import org.dromara.sample.manage.model.entity.DeviceProUserEntity; |
|||
import org.dromara.sample.manage.service.IDeviceProService; |
|||
import org.dromara.system.api.model.LoginUser; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.List; |
|||
|
|||
@RestController |
|||
@Slf4j |
|||
@RequestMapping("${url.manage.prefix}${url.manage.version}/device/group") |
|||
@Tag(name = "无人机设备项目模块") |
|||
public class DeviceProController { |
|||
|
|||
|
|||
@Autowired |
|||
private IDeviceProService deviceProService; |
|||
|
|||
//1、查询项目组
|
|||
|
|||
/** |
|||
* 查询项目组 |
|||
* @param page |
|||
* @param pageSize |
|||
* @return |
|||
*/ |
|||
@Operation(summary = "查询项目组", description = "查询项目组") |
|||
@GetMapping("/page") |
|||
public HttpResultResponse<PaginationData<DeviceProEntity>> pageDevicePro( |
|||
@RequestParam(name = "pageNum", defaultValue = "1") Long page, |
|||
@RequestParam(name = "pageSize", defaultValue = "10") Long pageSize, |
|||
DeviceProDTO deviceProDTO) { |
|||
Page<DeviceProEntity> pageQuery = new Page<>(page, pageSize); |
|||
PaginationData<DeviceProEntity> devices = deviceProService.listDeviceProEntityMap(pageQuery,deviceProDTO); |
|||
|
|||
return HttpResultResponse.success(devices); |
|||
} |
|||
|
|||
//2、添加项目组
|
|||
/** |
|||
* 新增/更新项目 |
|||
* @param deviceProEntity |
|||
* @return |
|||
*/ |
|||
@Operation(summary = "新增/更新项目。", description = "新增/更新项目。") |
|||
@PostMapping("/update") |
|||
public HttpResultResponse<Boolean> updateDevicePro(@RequestBody DeviceProEntity deviceProEntity) { |
|||
return HttpResultResponse.success(deviceProService.updateDevicePro(deviceProEntity)); |
|||
} |
|||
|
|||
|
|||
//3、删除项目组
|
|||
@Operation(summary = "删除项目组。", description = "删除项目组。") |
|||
@DeleteMapping("/delete") |
|||
public HttpResultResponse<Boolean> deleteDevicePro(@RequestBody List<Long> ids) { |
|||
return HttpResultResponse.success(deviceProService.deleteIds(ids)); |
|||
} |
|||
|
|||
/** |
|||
* 新增/更新项目人员。 |
|||
* @param userEntity |
|||
* @return |
|||
*/ |
|||
@Operation(summary = "新增/更新项目人员。", description = "新增/更新项目人员。") |
|||
@PostMapping("/{proId}/update") |
|||
public HttpResultResponse<Boolean> updateDeviceProUser(@RequestBody List<DeviceProUserEntity> userEntity,@PathVariable Long proId) { |
|||
return HttpResultResponse.success(deviceProService.updateDeviceProUser(userEntity,proId)); |
|||
} |
|||
|
|||
/** |
|||
* 设备绑定项目组 |
|||
*/ |
|||
@Operation(summary = "设备绑定项目组", description = "设备绑定项目组") |
|||
@PostMapping("/bind") |
|||
public HttpResultResponse<Boolean> updateDevice(@RequestBody Dict dict) { |
|||
return HttpResultResponse.success(deviceProService.updateDevice(dict)); |
|||
} |
|||
|
|||
/** |
|||
* 根据人员获取项目组(feign调用接口) |
|||
*/ |
|||
@GetMapping("/feign/user") |
|||
public List<Integer> listDeviceGroup(@RequestParam("userId") Long userId) { |
|||
log.info("----------------------------开始调用feign接口查询项目组----------------------------"); |
|||
List<Integer> result = deviceProService.listDeviceGroup(userId); |
|||
log.info("----------------------------调用feign接口查询项目组结束----------------------------"); |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 根据人员获取当前人员所拥有的机场(feign调用接口) |
|||
*/ |
|||
@GetMapping("/feign/device") |
|||
public List<String> listDevice(@RequestParam("userId") Long userId) { |
|||
log.info("----------------------------开始调用feign接口查询项目所属机场----------------------------"); |
|||
List<String> result = deviceProService.listDevice(userId); |
|||
log.info("----------------------------调用feign接口查询项目组所属机场----------------------------"); |
|||
return result; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,21 @@ |
|||
package org.dromara.sample.manage.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.dromara.sample.manage.model.dto.DeviceProDTO; |
|||
import org.dromara.sample.manage.model.dto.DeviceQrtzDTO; |
|||
import org.dromara.sample.manage.model.entity.DeviceProEntity; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @auther yq |
|||
* @data 2025/3/20 |
|||
*/ |
|||
public interface IDeviceProMapper extends BaseMapper<DeviceProEntity> { |
|||
|
|||
Page<DeviceProEntity> listDeviceProEntityMap(Page page, @Param("condition") DeviceProDTO deviceProDTO); |
|||
|
|||
|
|||
} |
@ -0,0 +1,16 @@ |
|||
package org.dromara.sample.manage.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.dromara.sample.manage.model.entity.DeviceProEntity; |
|||
import org.dromara.sample.manage.model.entity.DeviceProUserEntity; |
|||
|
|||
/** |
|||
* @auther yq |
|||
* @data 2025/3/20 |
|||
*/ |
|||
public interface IDeviceProUserMapper extends BaseMapper<DeviceProUserEntity> { |
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,47 @@ |
|||
package org.dromara.sample.manage.model.dto; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import org.dromara.sample.manage.model.entity.DeviceQrtzDateEntity; |
|||
import org.dromara.sample.manage.model.entity.DeviceQrtzFileEntity; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @auther yq |
|||
* @data 2025/3/20 |
|||
*/ |
|||
@Data |
|||
@Builder |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
public class DeviceProDTO { |
|||
/** |
|||
机场sn |
|||
*/ |
|||
private String deviceSn; |
|||
|
|||
/** |
|||
机场名称 |
|||
*/ |
|||
private String deviceName; |
|||
|
|||
/** |
|||
机场昵称 |
|||
*/ |
|||
private String nickname; |
|||
|
|||
/** |
|||
分配人员姓名 |
|||
*/ |
|||
private String realname; |
|||
|
|||
/** |
|||
分配人员 |
|||
*/ |
|||
private Integer userId; |
|||
} |
@ -0,0 +1,57 @@ |
|||
package org.dromara.sample.manage.model.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import org.dromara.common.mybatis.core.domain.BaseEntity; |
|||
|
|||
import java.io.Serializable; |
|||
import java.time.LocalDateTime; |
|||
import java.util.ArrayList; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* The entity class of the device |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Data |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
@TableName(value = "manage_device_pro") |
|||
public class DeviceProEntity extends BaseEntity implements Serializable { |
|||
|
|||
@TableId(type = IdType.ASSIGN_ID) |
|||
private Integer id; |
|||
|
|||
@TableField(value = "pro_name") |
|||
private String proName; |
|||
|
|||
@TableField(value = "bind_code") |
|||
private String bindCode; |
|||
|
|||
@TableField(value = "bind_type") |
|||
private Integer bindType; |
|||
|
|||
@TableField(value = "workspace_id") |
|||
private String workspaceId; |
|||
|
|||
@TableField(value = "nick_name") |
|||
private String nickName; |
|||
|
|||
@TableField(value = "dept_name") |
|||
private String deptName; |
|||
|
|||
@TableField(exist = false) |
|||
private List<DeviceProUserEntity> deviceProUserEntityList = new ArrayList<>(); |
|||
|
|||
@TableField(exist = false) |
|||
private List<DeviceEntity> deviceEntityList = new ArrayList<>(); |
|||
|
|||
} |
@ -0,0 +1,47 @@ |
|||
package org.dromara.sample.manage.model.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import org.dromara.common.mybatis.core.domain.BaseEntity; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* The entity class of the device |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Data |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
@TableName(value = "manage_device_pro_user") |
|||
public class DeviceProUserEntity extends BaseEntity implements Serializable { |
|||
|
|||
@TableId(type = IdType.ASSIGN_ID) |
|||
private Integer id; |
|||
|
|||
@TableField(value = "device_pro_id") |
|||
private Integer deviceProId; |
|||
|
|||
@TableField(value = "user_id") |
|||
private Long userId; |
|||
|
|||
@TableField(value = "user_name") |
|||
private String userName; |
|||
|
|||
@TableField(value = "nick_name") |
|||
private String nickName; |
|||
|
|||
@TableField(value = "dept_name") |
|||
private String deptName; |
|||
|
|||
} |
@ -0,0 +1,46 @@ |
|||
package org.dromara.sample.manage.service; |
|||
|
|||
import cn.hutool.core.lang.Dict; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.dromara.common.sdk.cloudapi.device.ControlSourceEnum; |
|||
import org.dromara.common.sdk.cloudapi.device.DeviceOsdHost; |
|||
import org.dromara.common.sdk.cloudapi.device.DockModeCodeEnum; |
|||
import org.dromara.common.sdk.cloudapi.device.DroneModeCodeEnum; |
|||
import org.dromara.common.sdk.common.HttpResultResponse; |
|||
import org.dromara.common.sdk.common.PaginationData; |
|||
import org.dromara.common.sdk.config.version.GatewayManager; |
|||
import org.dromara.common.websocket.dto.BizCodeEnum; |
|||
import org.dromara.sample.manage.model.dto.*; |
|||
import org.dromara.sample.manage.model.entity.DeviceProEntity; |
|||
import org.dromara.sample.manage.model.entity.DeviceProUserEntity; |
|||
import org.dromara.sample.manage.model.param.DeviceQueryParam; |
|||
|
|||
import java.util.Collection; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
|
|||
/** |
|||
* @author sean.zhou |
|||
* @date 2021/11/10 |
|||
* @version 0.1 |
|||
*/ |
|||
public interface IDeviceProService { |
|||
|
|||
PaginationData<DeviceProEntity> listDeviceProEntityMap(Page page, DeviceProDTO deviceProDTO); |
|||
|
|||
Boolean saveAndUpdate(DeviceProEntity deviceProEntity); |
|||
|
|||
Boolean deleteIds(List<Long> ids); |
|||
|
|||
Boolean updateDevicePro(DeviceProEntity deviceProEntity); |
|||
|
|||
Boolean updateDeviceProUser(List<DeviceProUserEntity> userEntity,Long proId); |
|||
|
|||
Boolean updateDevice(Dict dict); |
|||
|
|||
List<Integer> listDeviceGroup(Long userId); |
|||
|
|||
List<String> listDevice(Long userId); |
|||
} |
@ -0,0 +1,28 @@ |
|||
package org.dromara.sample.manage.service; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import org.dromara.common.sdk.cloudapi.device.ControlSourceEnum; |
|||
import org.dromara.common.sdk.cloudapi.device.DeviceOsdHost; |
|||
import org.dromara.common.sdk.cloudapi.device.DockModeCodeEnum; |
|||
import org.dromara.common.sdk.cloudapi.device.DroneModeCodeEnum; |
|||
import org.dromara.common.sdk.common.HttpResultResponse; |
|||
import org.dromara.common.sdk.common.PaginationData; |
|||
import org.dromara.common.sdk.config.version.GatewayManager; |
|||
import org.dromara.common.websocket.dto.BizCodeEnum; |
|||
import org.dromara.sample.manage.model.dto.DeviceDTO; |
|||
import org.dromara.sample.manage.model.dto.DeviceFirmwareUpgradeDTO; |
|||
import org.dromara.sample.manage.model.dto.TopologyDeviceDTO; |
|||
import org.dromara.sample.manage.model.param.DeviceQueryParam; |
|||
|
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
|
|||
/** |
|||
* @author sean.zhou |
|||
* @date 2021/11/10 |
|||
* @version 0.1 |
|||
*/ |
|||
public interface IDeviceProUserService { |
|||
|
|||
|
|||
} |
@ -0,0 +1,241 @@ |
|||
package org.dromara.sample.manage.service.impl; |
|||
|
|||
import cn.hutool.core.collection.ListUtil; |
|||
import cn.hutool.core.lang.Dict; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.ibatis.executor.BatchResult; |
|||
import org.dromara.common.core.exception.ServiceException; |
|||
import org.dromara.common.satoken.utils.LoginHelper; |
|||
import org.dromara.common.sdk.cloudapi.device.*; |
|||
import org.dromara.common.sdk.cloudapi.firmware.*; |
|||
import org.dromara.common.sdk.cloudapi.firmware.api.AbstractFirmwareService; |
|||
import org.dromara.common.sdk.cloudapi.property.api.AbstractPropertyService; |
|||
import org.dromara.common.sdk.cloudapi.tsa.DeviceIconUrl; |
|||
import org.dromara.common.sdk.cloudapi.tsa.TopologyDeviceModel; |
|||
import org.dromara.common.sdk.common.*; |
|||
import org.dromara.common.sdk.config.version.GatewayManager; |
|||
import org.dromara.common.sdk.exception.CloudSDKException; |
|||
import org.dromara.common.sdk.mqtt.IMqttTopicService; |
|||
import org.dromara.common.sdk.mqtt.MqttGatewayPublish; |
|||
import org.dromara.common.sdk.mqtt.events.EventsSubscribe; |
|||
import org.dromara.common.sdk.mqtt.osd.OsdSubscribe; |
|||
import org.dromara.common.sdk.mqtt.property.PropertySetReplyResultEnum; |
|||
import org.dromara.common.sdk.mqtt.property.PropertySetSubscribe; |
|||
import org.dromara.common.sdk.mqtt.requests.RequestsSubscribe; |
|||
import org.dromara.common.sdk.mqtt.services.ServicesReplyData; |
|||
import org.dromara.common.sdk.mqtt.services.ServicesSubscribe; |
|||
import org.dromara.common.sdk.mqtt.services.TopicServicesResponse; |
|||
import org.dromara.common.sdk.mqtt.state.StateSubscribe; |
|||
import org.dromara.common.sdk.mqtt.status.StatusSubscribe; |
|||
import org.dromara.common.websocket.dto.BizCodeEnum; |
|||
import org.dromara.sample.common.error.CommonErrorEnum; |
|||
import org.dromara.sample.component.mqtt.model.EventsReceiver; |
|||
import org.dromara.sample.control.model.enums.DroneAuthorityEnum; |
|||
import org.dromara.sample.manage.mapper.IDeviceMapper; |
|||
import org.dromara.sample.manage.mapper.IDeviceProMapper; |
|||
import org.dromara.sample.manage.mapper.IDeviceProUserMapper; |
|||
import org.dromara.sample.manage.mapper.IDeviceQrtzMapper; |
|||
import org.dromara.sample.manage.model.dto.*; |
|||
import org.dromara.sample.manage.model.entity.DeviceEntity; |
|||
import org.dromara.sample.manage.model.entity.DeviceProEntity; |
|||
import org.dromara.sample.manage.model.entity.DeviceProUserEntity; |
|||
import org.dromara.sample.manage.model.entity.DeviceQrtzDateEntity; |
|||
import org.dromara.sample.manage.model.enums.DeviceFirmwareStatusEnum; |
|||
import org.dromara.sample.manage.model.enums.PropertySetFieldEnum; |
|||
import org.dromara.sample.manage.model.enums.UserTypeEnum; |
|||
import org.dromara.sample.manage.model.param.DeviceQueryParam; |
|||
import org.dromara.sample.manage.model.receiver.BasicDeviceProperty; |
|||
import org.dromara.sample.manage.service.*; |
|||
import org.dromara.sample.websocket.service.IWebSocketMessageService; |
|||
import org.dromara.system.api.model.LoginUser; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.util.CollectionUtils; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import java.time.LocalDateTime; |
|||
import java.util.Collection; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* |
|||
* @author sean.zhou |
|||
* @version 0.1 |
|||
* @date 2021/11/10 |
|||
*/ |
|||
@Service |
|||
@Slf4j |
|||
@Transactional |
|||
public class DeviceProServiceImpl implements IDeviceProService { |
|||
@Autowired |
|||
private IDeviceProMapper deviceProMapper; |
|||
|
|||
@Autowired |
|||
private IDeviceMapper deviceMapper; |
|||
|
|||
@Autowired |
|||
private IDeviceProUserMapper deviceProUserMapper; |
|||
|
|||
@Override |
|||
public PaginationData<DeviceProEntity> listDeviceProEntityMap(Page page, DeviceProDTO deviceProDTO) { |
|||
Page<DeviceProEntity> pagination = deviceProMapper.listDeviceProEntityMap(page, deviceProDTO); |
|||
|
|||
return new PaginationData<DeviceProEntity>(pagination.getRecords(), new Pagination(pagination.getCurrent(), pagination.getSize(), pagination.getTotal())); |
|||
} |
|||
|
|||
@Override |
|||
public Boolean updateDevicePro(DeviceProEntity deviceProEntity) { |
|||
if(ObjectUtil.isNotEmpty(deviceProEntity.getId())){ |
|||
return deviceProMapper.updateById(deviceProEntity) > 0 ; |
|||
}else { |
|||
deviceProEntity.setDeptName(LoginHelper.getDeptName()); |
|||
deviceProEntity.setNickName(LoginHelper.getUsername()); |
|||
return deviceProMapper.insert(deviceProEntity) > 0; |
|||
} |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public Boolean deleteIds(List<Long> ids) { |
|||
|
|||
List<DeviceEntity> deviceEntityList = deviceMapper.selectList(new LambdaQueryWrapper<DeviceEntity>().in(DeviceEntity::getProId, ids)); |
|||
|
|||
deviceEntityList.forEach(deviceEntity -> { |
|||
deviceMapper.updatePor(deviceEntity.getId(),null); |
|||
}); |
|||
|
|||
|
|||
//todo人员是否要删除
|
|||
List<DeviceProUserEntity> proUserEntityList = deviceProUserMapper.selectList(new LambdaQueryWrapper<DeviceProUserEntity>().in(DeviceProUserEntity::getDeviceProId, ids)); |
|||
|
|||
|
|||
return deviceProMapper.deleteByIds(ids)>0; |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public Boolean updateDeviceProUser(List<DeviceProUserEntity> userEntity,Long proId) { |
|||
try { |
|||
//先清除原来的项目组成员
|
|||
deviceProUserMapper.delete(new LambdaQueryWrapper<DeviceProUserEntity>().eq(DeviceProUserEntity::getDeviceProId, proId)); |
|||
|
|||
if (ObjectUtil.isNotEmpty(userEntity)) { |
|||
//添加新的项目组成员
|
|||
deviceProUserMapper.insert(userEntity); |
|||
} |
|||
|
|||
return true; |
|||
} catch (ServiceException e) { |
|||
log.error(e.getMessage(),e); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 绑定设备的项目组 |
|||
* @param dict |
|||
* @return |
|||
*/ |
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public Boolean updateDevice(Dict dict) { |
|||
Long deviceId = dict.getLong("deviceId"); |
|||
Long proId = dict.getLong("proId"); |
|||
|
|||
if (ObjectUtil.hasEmpty(deviceId, proId)) { |
|||
throw new ServiceException("【deviceId】或【proId】参数为空!"); |
|||
} |
|||
|
|||
LambdaUpdateWrapper<DeviceEntity> wrapper = new LambdaUpdateWrapper<>(); |
|||
wrapper.set(DeviceEntity::getProId, proId); |
|||
wrapper.eq(DeviceEntity::getId, deviceId); |
|||
|
|||
return deviceMapper.update(wrapper) > 0; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前成员所属项目组 |
|||
* @param userId |
|||
* @return |
|||
*/ |
|||
@Override |
|||
public List<Integer> listDeviceGroup(Long userId) { |
|||
LambdaQueryWrapper<DeviceProUserEntity> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(DeviceProUserEntity::getUserId,userId); |
|||
List<DeviceProUserEntity> proUserEntityList = deviceProUserMapper.selectList(wrapper); |
|||
if (ObjectUtil.isNotEmpty(proUserEntityList)){ |
|||
List<Integer> proIdList = proUserEntityList.stream().map(DeviceProUserEntity::getDeviceProId).distinct().toList(); |
|||
LambdaQueryWrapper<DeviceProEntity> queryWrapper = new LambdaQueryWrapper<>(); |
|||
queryWrapper.in(DeviceProEntity::getId, proIdList); |
|||
return deviceProMapper.selectList(queryWrapper).stream().map(DeviceProEntity::getId).distinct().toList(); |
|||
} |
|||
|
|||
return ListUtil.empty(); |
|||
} |
|||
|
|||
@Override |
|||
public List<String> listDevice(Long userId) { |
|||
LambdaQueryWrapper<DeviceProUserEntity> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(DeviceProUserEntity::getUserId,userId); |
|||
List<DeviceProUserEntity> proUserEntityList = deviceProUserMapper.selectList(wrapper); |
|||
if (ObjectUtil.isNotEmpty(proUserEntityList)){ |
|||
List<Integer> proIdList = proUserEntityList.stream().map(DeviceProUserEntity::getDeviceProId).distinct().toList(); |
|||
LambdaQueryWrapper<DeviceProEntity> queryWrapper = new LambdaQueryWrapper<>(); |
|||
queryWrapper.in(DeviceProEntity::getId, proIdList); |
|||
List<Integer> groupIdList = deviceProMapper.selectList(queryWrapper).stream().map(DeviceProEntity::getId).distinct().toList(); |
|||
|
|||
if (ObjectUtil.isEmpty(groupIdList)){ |
|||
return ListUtil.empty(); |
|||
} |
|||
|
|||
return deviceMapper.selectList(new LambdaQueryWrapper<DeviceEntity>().in(DeviceEntity::getProId, groupIdList)).stream().map(DeviceEntity::getDeviceSn).distinct().toList(); |
|||
} |
|||
|
|||
return ListUtil.empty(); |
|||
} |
|||
|
|||
@Override |
|||
public Boolean saveAndUpdate(DeviceProEntity entity) { |
|||
boolean flag = true; |
|||
//项目信息
|
|||
if(entity.getId() != null){ |
|||
flag = deviceProMapper.updateById(entity) > 0 ; |
|||
}else { |
|||
LoginUser loginUser = LoginHelper.getLoginUser(); |
|||
entity.setCreateBy(loginUser.getUserId()); |
|||
entity.setCreateTime(new Date()); |
|||
entity.setCreateDept(loginUser.getDeptId()); |
|||
flag = deviceProMapper.insert(entity) > 0; |
|||
} |
|||
//设备项目绑定
|
|||
if(entity.getDeviceEntityList().size() >= 0 && flag){ |
|||
for (DeviceEntity deviceEntity : deviceMapper.selectList(new QueryWrapper<DeviceEntity>().eq("pro_id", entity.getId()))) { |
|||
deviceMapper.updatePor(deviceEntity.getId(),null); |
|||
} |
|||
entity.getDeviceEntityList().stream().forEach(itme->{ |
|||
itme.setProId(entity.getId()); |
|||
}); |
|||
flag = deviceMapper.updateById(entity.getDeviceEntityList(),100).size() > 0; |
|||
} |
|||
//设备项目绑定
|
|||
if(entity.getDeviceProUserEntityList().size() >= 0 && flag){ |
|||
deviceProUserMapper.delete(new QueryWrapper<DeviceProUserEntity>().eq("pro_id",entity.getId())); |
|||
entity.getDeviceProUserEntityList().stream().forEach(itme->{ |
|||
itme.setDeviceProId(entity.getId()); |
|||
}); |
|||
flag = deviceProUserMapper.insert(entity.getDeviceProUserEntityList(),100).size() > 0; |
|||
} |
|||
return flag; |
|||
} |
|||
} |
@ -0,0 +1,8 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="org.dromara.sample.manage.mapper.IDeviceProUserMapper"> |
|||
|
|||
|
|||
</mapper> |
@ -0,0 +1,11 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="org.dromara.sample.manage.mapper.IDeviceMapper"> |
|||
|
|||
|
|||
<update id="updatePor"> |
|||
update manage_device set pro_id =#{proId} where id=#{id} |
|||
</update> |
|||
</mapper> |
@ -0,0 +1,69 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="org.dromara.sample.manage.mapper.IDeviceProMapper"> |
|||
<resultMap id="listDeviceProEntityMap" type="org.dromara.sample.manage.model.entity.DeviceProEntity"> |
|||
<result column="pro_id" property="id" jdbcType="VARCHAR"/> |
|||
<result column="pro_name" property="proName" jdbcType="VARCHAR"/> |
|||
<result column="bind_code" property="bindCode" jdbcType="VARCHAR"/> |
|||
<result column="bind_type" property="bindType" jdbcType="VARCHAR"/> |
|||
<collection property="deviceProUserEntityList" ofType="org.dromara.sample.manage.model.entity.DeviceProUserEntity"> |
|||
<result column="pro_user_id" property="id"/> |
|||
<result column="device_pro_id" property="deviceProId"/> |
|||
<result column="user_id" property="userId"/> |
|||
<result column="nick_name" property="nickName"/> |
|||
</collection> |
|||
<collection property="deviceEntityList" ofType="org.dromara.sample.manage.model.entity.DeviceEntity"> |
|||
<result column="device_id" property="id"/> |
|||
<result column="device_sn" property="deviceSn"/> |
|||
<result column="device_name" property="deviceName"/> |
|||
<result column="device_type" property="deviceType"/> |
|||
<result column="sub_type" property="subType"/> |
|||
<result column="domain" property="domain"/> |
|||
<result column="child_sn" property="childSn"/> |
|||
<result column="workspace_id" property="workspaceId"/> |
|||
<result column="device_pro_number" property="proId"/> |
|||
<result column="device_nick_name" property="nickname"/> |
|||
</collection> |
|||
</resultMap> |
|||
<select id="listDeviceProEntityMap" resultMap="listDeviceProEntityMap"> |
|||
SELECT |
|||
dp.id pro_id, |
|||
dp.pro_name, |
|||
dp.bind_code, |
|||
dp.bind_type, |
|||
dpu.user_id pro_user_id, |
|||
dpu.device_pro_id, |
|||
dpu.user_id, |
|||
dpu.nick_name, |
|||
d.id device_id, |
|||
d.device_sn, |
|||
d.device_name, |
|||
d.device_type, |
|||
d.sub_type, |
|||
d.domain, |
|||
d.child_sn, |
|||
d.workspace_id, |
|||
d.pro_id device_pro_number, |
|||
d.nickname device_nick_name |
|||
FROM |
|||
manage_device_pro dp |
|||
LEFT JOIN manage_device d ON dp.id = d.pro_id |
|||
LEFT JOIN manage_device_pro_user dpu ON dp.id = dpu.device_pro_id |
|||
<where> |
|||
<if test="condition.deviceSn != null and condition.deviceSn != ''"> |
|||
and d.device_sn like concat(concat('%',#{condition.deviceSn}),'%') |
|||
</if> |
|||
<if test="condition.deviceName != null and condition.deviceName != ''"> |
|||
and d.device_name like concat(concat('%',#{condition.deviceName}),'%') |
|||
</if> |
|||
<if test="condition.nickname != null and condition.nickname != ''"> |
|||
and dpu.nickname like concat(concat('%',#{condition.nickname}),'%') |
|||
</if> |
|||
<if test="condition.userId != null and condition.userId != ''"> |
|||
and dpu.user_id = #{condition.userId} |
|||
</if> |
|||
</where> |
|||
</select> |
|||
</mapper> |
Loading…
Reference in new issue