|
@@ -0,0 +1,393 @@
|
|
|
+package cn.hanghui.outapi.platform.tenant.service.impl;
|
|
|
+
|
|
|
+import cn.hanghui.outapi.platform.common.entity.rest.RestCode;
|
|
|
+import cn.hanghui.outapi.platform.common.entity.rest.RestResult;
|
|
|
+import cn.hanghui.outapi.platform.common.utils.ClassUtil;
|
|
|
+import cn.hanghui.outapi.platform.common.utils.Preconditions;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.dto.TenantDto;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.dto.hhomc.HhOmcDeviceDto;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.dto.hhomc.HhOmcDeviceSearch;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.dto.hhomc.HhOmcDeviceTemplateDto;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.dto.hhomc.HhOmcDeviceTemplateLessVo;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.dto.hhomc.HhOmcDeviceTemplateSearch;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.dto.hhomc.HhOmcDeviceTemplateVo;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.dto.hhomc.HhOmcDeviceVo;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.enums.SystemTypeEnum;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.po.ApplicationType;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.po.DeviceModel;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.po.HhOmcDevice;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.po.HhOmcDeviceTemplate;
|
|
|
+import cn.hanghui.outapi.platform.tenant.entity.po.Purchaser;
|
|
|
+import cn.hanghui.outapi.platform.tenant.mapper.ApplicationTypeMapper;
|
|
|
+import cn.hanghui.outapi.platform.tenant.mapper.DeviceModelMapper;
|
|
|
+import cn.hanghui.outapi.platform.tenant.mapper.HhOmcDeviceMapper;
|
|
|
+import cn.hanghui.outapi.platform.tenant.mapper.HhOmcDeviceTemplateMapper;
|
|
|
+import cn.hanghui.outapi.platform.tenant.mapper.PurchaserMapper;
|
|
|
+import cn.hanghui.outapi.platform.tenant.service.HhOmcDeviceService;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author shisl
|
|
|
+ * @package cn.hanghui.outapi.platform.tenant.service.impl
|
|
|
+ * @class HhOmcDeviceServiceImpl
|
|
|
+ * @date 2024/12/31 上午11:24
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class HhOmcDeviceServiceImpl implements HhOmcDeviceService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CommonImpl commonImpl;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ApplicationTypeMapper applicationTypeMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PurchaserMapper purchaserMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DeviceModelMapper deviceModelMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private HhOmcDeviceMapper hhOmcDeviceMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private HhOmcDeviceTemplateMapper hhOmcDeviceTemplateMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean templateEdit(HhOmcDeviceTemplateDto dto) {
|
|
|
+ checkTemplateDto(dto);
|
|
|
+ Long templateId = dto.getDeviceTemplateId();
|
|
|
+ if (templateId == null) {
|
|
|
+ HhOmcDeviceTemplate template = BeanUtil.copyProperties(dto, HhOmcDeviceTemplate.class);
|
|
|
+ hhOmcDeviceTemplateMapper.insert(template);
|
|
|
+ } else {
|
|
|
+ HhOmcDeviceTemplate base = hhOmcDeviceTemplateMapper.selectById(templateId);
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(base), RestCode.FAIL.getCode(), "模版不存在");
|
|
|
+ BeanUtil.copyProperties(dto, base);
|
|
|
+ hhOmcDeviceTemplateMapper.updateById(base);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkTemplateDto(HhOmcDeviceTemplateDto dto) {
|
|
|
+ //应用类型
|
|
|
+ if (Preconditions.isNotBlank(dto.getApplicationTypeId())) {
|
|
|
+ ApplicationType applicationType = applicationTypeMapper.selectById(dto.getApplicationTypeId());
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(applicationType), RestCode.FAIL.getCode(), "应用类型不存在");
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(applicationType.getIsDeleted()), RestCode.FAIL.getCode(), "应用类型已删除");
|
|
|
+ }
|
|
|
+ //设备类型(硬件)
|
|
|
+ if (Preconditions.isNotBlank(dto.getDeviceModelHardwareId())) {
|
|
|
+ DeviceModel deviceModelHardware = deviceModelMapper.selectById(dto.getDeviceModelHardwareId());
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(deviceModelHardware), RestCode.FAIL.getCode(), "设备类型(硬件)不存在");
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(deviceModelHardware.getIsDeleted()), RestCode.FAIL.getCode(), "设备类型(硬件)已删除");
|
|
|
+ }
|
|
|
+ //设备类型(环境)
|
|
|
+ if (Preconditions.isNotBlank(dto.getDeviceModelEnvironmentId())) {
|
|
|
+ DeviceModel deviceModelEnvironment = deviceModelMapper.selectById(dto.getDeviceModelEnvironmentId());
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(deviceModelEnvironment), RestCode.FAIL.getCode(), "设备类型(环境)不存在");
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(deviceModelEnvironment.getIsDeleted()), RestCode.FAIL.getCode(), "设备类型(环境)已删除");
|
|
|
+ }
|
|
|
+ //系统类型
|
|
|
+ if (Preconditions.isNotBlank(dto.getSystemTypeCode())) {
|
|
|
+ SystemTypeEnum systemTypeEnum = SystemTypeEnum.getEnumByCode(dto.getSystemTypeCode());
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(systemTypeEnum), RestCode.FAIL.getCode(), "系统类型不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<HhOmcDeviceTemplateLessVo> templateList() {
|
|
|
+ LambdaQueryWrapper<HhOmcDeviceTemplate> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ //查询的基础条件
|
|
|
+ wrapper.select(HhOmcDeviceTemplate::getId, HhOmcDeviceTemplate::getTemplateName);
|
|
|
+ wrapper.eq(HhOmcDeviceTemplate::getIsDeleted, Boolean.FALSE);
|
|
|
+ wrapper.orderByDesc(HhOmcDeviceTemplate::getId);
|
|
|
+ List<HhOmcDeviceTemplate> templates = hhOmcDeviceTemplateMapper.selectList(wrapper);
|
|
|
+ return templates.stream().map(p -> new HhOmcDeviceTemplateLessVo()
|
|
|
+ .setDeviceTemplateId(p.getId())
|
|
|
+ .setTemplateName(p.getTemplateName())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<HhOmcDeviceTemplateVo> templatePage(HhOmcDeviceTemplateSearch dto) {
|
|
|
+ Page<HhOmcDeviceTemplate> page = new Page<>(dto.getPageNumber(), dto.getPageSize());
|
|
|
+ LambdaQueryWrapper<HhOmcDeviceTemplate> wrapper = this.getWrapper(dto);
|
|
|
+ IPage<HhOmcDeviceTemplate> iPage = hhOmcDeviceTemplateMapper.selectPage(page, wrapper);
|
|
|
+ Map<Long, ApplicationType> applicationTypeMap = commonImpl.getApplicationTypeMap(iPage, HhOmcDeviceTemplate::getApplicationTypeId);
|
|
|
+ Map<Long, DeviceModel> deviceModelHardwareMap = commonImpl.getDeviceModelMap(iPage, HhOmcDeviceTemplate::getDeviceModelHardwareId);
|
|
|
+ Map<Long, DeviceModel> deviceModelEnvironmentMap = commonImpl.getDeviceModelMap(iPage, HhOmcDeviceTemplate::getDeviceModelEnvironmentId);
|
|
|
+
|
|
|
+ return iPage.convert(t -> {
|
|
|
+ HhOmcDeviceTemplateVo item = BeanUtil.copyProperties(t, HhOmcDeviceTemplateVo.class);
|
|
|
+ item.setDeviceTemplateId(t.getId());
|
|
|
+ if (applicationTypeMap.containsKey(t.getApplicationTypeId())) {
|
|
|
+ item.setApplicationType(applicationTypeMap.get(t.getApplicationTypeId()).getApplicationType());
|
|
|
+ }
|
|
|
+ if (deviceModelHardwareMap.containsKey(t.getDeviceModelHardwareId())) {
|
|
|
+ item.setDeviceModelHardware(deviceModelHardwareMap.get(t.getDeviceModelHardwareId()).getDeviceModel());
|
|
|
+ }
|
|
|
+ if (deviceModelEnvironmentMap.containsKey(t.getDeviceModelEnvironmentId())) {
|
|
|
+ item.setDeviceModelEnvironment(deviceModelEnvironmentMap.get(t.getDeviceModelEnvironmentId()).getDeviceModel());
|
|
|
+ }
|
|
|
+ SystemTypeEnum systemTypeEnum = SystemTypeEnum.getEnumByCode(t.getSystemTypeCode());
|
|
|
+ if (ObjectUtil.isNotNull(systemTypeEnum)) {
|
|
|
+ item.setSystemType(systemTypeEnum.getDesc());
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<HhOmcDeviceTemplate> getWrapper(HhOmcDeviceTemplateSearch dto) {
|
|
|
+ LambdaQueryWrapper<HhOmcDeviceTemplate> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ //查询的传参条件
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getDeviceTemplateId()), HhOmcDeviceTemplate::getId, dto.getDeviceTemplateId());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getApplicationTypeId()), HhOmcDeviceTemplate::getApplicationTypeId, dto.getApplicationTypeId());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getDeviceModelHardwareId()), HhOmcDeviceTemplate::getDeviceModelHardwareId, dto.getDeviceModelHardwareId());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getDeviceModelEnvironmentId()), HhOmcDeviceTemplate::getDeviceModelEnvironmentId, dto.getDeviceModelEnvironmentId());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getSystemTypeCode()), HhOmcDeviceTemplate::getSystemTypeCode, dto.getSystemTypeCode());
|
|
|
+ //查询的基础条件
|
|
|
+ wrapper.eq(HhOmcDeviceTemplate::getIsDeleted, Boolean.FALSE);
|
|
|
+ wrapper.orderByDesc(HhOmcDeviceTemplate::getId);
|
|
|
+ return wrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean templateDelete(Long deviceTemplateId) {
|
|
|
+ HhOmcDeviceTemplate template = hhOmcDeviceTemplateMapper.selectById(deviceTemplateId);
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(template), RestCode.FAIL.getCode(), "模版不存在");
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(template.getIsDeleted()), RestCode.FAIL.getCode(), "模版已删除");
|
|
|
+ hhOmcDeviceTemplateMapper.deleteById(deviceTemplateId);
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HhOmcDeviceTemplateVo templateDetail(Long deviceTemplateId) {
|
|
|
+ HhOmcDeviceTemplate deviceTemplate = hhOmcDeviceTemplateMapper.selectById(deviceTemplateId);
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(deviceTemplate), "模版不存在");
|
|
|
+ ClassUtil.throwBusinessException(deviceTemplate.getIsDeleted(), "模版已删除");
|
|
|
+ HhOmcDeviceTemplateVo templateVo = BeanUtil.copyProperties(deviceTemplate, HhOmcDeviceTemplateVo.class);
|
|
|
+ templateVo.setDeviceTemplateId(deviceTemplate.getId());
|
|
|
+ return templateVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RestResult<Boolean> add(HhOmcDeviceDto dto) {
|
|
|
+ if (dto.getSn() == null) {
|
|
|
+ return RestResult.error("参数有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (checkSn(dto)) { //校验设备是否存在
|
|
|
+ if (dto.getId() != null) {
|
|
|
+ return RestResult.error("数据不存在或已删除");
|
|
|
+ }
|
|
|
+ return RestResult.error("设备已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ HhOmcDevice device = null;
|
|
|
+ if (dto.getId() != null) {
|
|
|
+ device = hhOmcDeviceMapper.selectById(dto.getId());
|
|
|
+ if (device == null || device.getIsDeleted() == null || device.getIsDeleted()) {
|
|
|
+ return RestResult.error("数据不存在或已删除");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ device = new HhOmcDevice();
|
|
|
+ device.setStatus(Boolean.TRUE);
|
|
|
+ device.setCreateTime(new Date());
|
|
|
+ device.setVersion(1);
|
|
|
+ device.setIsDeleted(Boolean.FALSE);
|
|
|
+ device.setFirstAuthTime(new Date());
|
|
|
+ }
|
|
|
+ //处理参数
|
|
|
+ handleParams(device, dto);
|
|
|
+ if (dto.getId() != null) {
|
|
|
+ hhOmcDeviceMapper.updateById(device);
|
|
|
+ } else {
|
|
|
+ hhOmcDeviceMapper.insert(device);
|
|
|
+ }
|
|
|
+ return RestResult.ok(Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleParams(HhOmcDevice device, HhOmcDeviceDto dto) {
|
|
|
+ BeanUtil.copyProperties(dto, device);
|
|
|
+ //购买方
|
|
|
+ if (Preconditions.isNotBlank(dto.getPurchaserId())) {
|
|
|
+ Purchaser purchaser = purchaserMapper.selectById(dto.getPurchaserId());
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(purchaser), "购买方不存在");
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(purchaser.getIsDeleted()), "购买方已删除");
|
|
|
+ device.setPurchaserId(purchaser.getId());
|
|
|
+ }
|
|
|
+ //应用类型
|
|
|
+ if (Preconditions.isNotBlank(dto.getApplicationTypeId())) {
|
|
|
+ ApplicationType applicationType = applicationTypeMapper.selectById(dto.getApplicationTypeId());
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(applicationType), "应用类型不存在");
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(applicationType.getIsDeleted()), "购买方已删除");
|
|
|
+ device.setApplicationTypeId(applicationType.getId());
|
|
|
+ }
|
|
|
+ //设备类型(硬件)
|
|
|
+ if (Preconditions.isNotBlank(dto.getDeviceModelHardwareId())) {
|
|
|
+ DeviceModel deviceModelHardware = deviceModelMapper.selectById(dto.getDeviceModelHardwareId());
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(deviceModelHardware), "设备类型(硬件)不存在");
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(deviceModelHardware.getIsDeleted()), "设备类型(硬件)已删除");
|
|
|
+ device.setDeviceModelHardwareId(deviceModelHardware.getId());
|
|
|
+ }
|
|
|
+ //设备类型(环境)
|
|
|
+ if (Preconditions.isNotBlank(dto.getDeviceModelEnvironmentId())) {
|
|
|
+ DeviceModel deviceModelEnvironment = deviceModelMapper.selectById(dto.getDeviceModelEnvironmentId());
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(deviceModelEnvironment), RestCode.FAIL.getCode(), "设备类型(环境)不存在");
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(deviceModelEnvironment.getIsDeleted()), RestCode.FAIL.getCode(), "设备类型(环境)已删除");
|
|
|
+ device.setDeviceModelEnvironmentId(deviceModelEnvironment.getId());
|
|
|
+
|
|
|
+ }
|
|
|
+ //系统类型
|
|
|
+ if (Preconditions.isNotBlank(dto.getSystemTypeCode())) {
|
|
|
+ SystemTypeEnum systemTypeEnum = SystemTypeEnum.getEnumByCode(dto.getSystemTypeCode());
|
|
|
+ ClassUtil.throwBusinessException(ObjectUtil.isNull(systemTypeEnum), RestCode.FAIL.getCode(), "系统类型不存在");
|
|
|
+ device.setSystemTypeCode(systemTypeEnum.getCode());
|
|
|
+ }
|
|
|
+ device.setUpdateTime(new Date());
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkSn(HhOmcDeviceDto dto) {
|
|
|
+ List<HhOmcDevice> devices = hhOmcDeviceMapper.selectList(Wrappers.lambdaQuery(HhOmcDevice.class).eq(HhOmcDevice::getSn, dto.getSn()).eq(HhOmcDevice::getIsDeleted, Boolean.FALSE));
|
|
|
+ if (devices != null && devices.size() > 0) {
|
|
|
+ if (dto.getId() == null) {
|
|
|
+ return Boolean.TRUE;
|
|
|
+ } else {
|
|
|
+ List<Long> ids = devices.stream().map(HhOmcDevice::getId).collect(Collectors.toList());
|
|
|
+ if (!ids.contains(dto.getId())) {
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RestResult<IPage<HhOmcDeviceVo>> page(HhOmcDeviceSearch dto) {
|
|
|
+ LambdaQueryWrapper<HhOmcDevice> wrapper = this.getDeviceWrapper(dto);
|
|
|
+ Page<HhOmcDevice> page = new Page<>(dto.getPageNumber(), dto.getPageSize());
|
|
|
+ IPage<HhOmcDevice> iPage = hhOmcDeviceMapper.selectPage(page, wrapper);
|
|
|
+
|
|
|
+ Map<Long, Purchaser> purchaserMap = commonImpl.getPurchaserMap(iPage, HhOmcDevice::getPurchaserId);
|
|
|
+ Map<Long, ApplicationType> applicationTypeMap = commonImpl.getApplicationTypeMap(iPage, HhOmcDevice::getApplicationTypeId);
|
|
|
+ Map<Long, DeviceModel> deviceModelHardwareMap = commonImpl.getDeviceModelMap(iPage, HhOmcDevice::getDeviceModelHardwareId);
|
|
|
+ Map<Long, DeviceModel> deviceModelEnvironmentMap = commonImpl.getDeviceModelMap(iPage, HhOmcDevice::getDeviceModelEnvironmentId);
|
|
|
+
|
|
|
+ IPage<HhOmcDeviceVo> convert = iPage.convert(t -> {
|
|
|
+ HhOmcDeviceVo item = BeanUtil.copyProperties(t, HhOmcDeviceVo.class);
|
|
|
+ if (purchaserMap.containsKey(t.getPurchaserId())) {
|
|
|
+ item.setCompanyName(purchaserMap.get(t.getPurchaserId()).getCompanyName());
|
|
|
+ }
|
|
|
+ if (applicationTypeMap.containsKey(t.getApplicationTypeId())) {
|
|
|
+ item.setApplicationType(applicationTypeMap.get(t.getApplicationTypeId()).getApplicationType());
|
|
|
+ }
|
|
|
+ if (deviceModelHardwareMap.containsKey(t.getDeviceModelHardwareId())) {
|
|
|
+ item.setDeviceModelHardware(deviceModelHardwareMap.get(t.getDeviceModelHardwareId()).getDeviceModel());
|
|
|
+ }
|
|
|
+ if (deviceModelEnvironmentMap.containsKey(t.getDeviceModelEnvironmentId())) {
|
|
|
+ item.setDeviceModelEnvironment(deviceModelEnvironmentMap.get(t.getDeviceModelEnvironmentId()).getDeviceModel());
|
|
|
+ }
|
|
|
+ SystemTypeEnum systemTypeEnum = SystemTypeEnum.getEnumByCode(t.getSystemTypeCode());
|
|
|
+ if (ObjectUtil.isNotNull(systemTypeEnum)) {
|
|
|
+ item.setSystemType(systemTypeEnum.getDesc());
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ return RestResult.ok(convert);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<HhOmcDevice> getDeviceWrapper(HhOmcDeviceSearch dto) {
|
|
|
+ LambdaQueryWrapper<HhOmcDevice> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ //查询的传参条件
|
|
|
+ wrapper.like(StrUtil.isNotBlank(dto.getSn()), HhOmcDevice::getSn, dto.getSn());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getPurchaserId()), HhOmcDevice::getPurchaserId, dto.getPurchaserId());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getApplicationTypeId()), HhOmcDevice::getApplicationTypeId, dto.getApplicationTypeId());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getDeviceModelHardwareId()), HhOmcDevice::getDeviceModelHardwareId, dto.getDeviceModelHardwareId());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getDeviceModelEnvironmentId()), HhOmcDevice::getDeviceModelEnvironmentId, dto.getDeviceModelEnvironmentId());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getSystemTypeCode()), HhOmcDevice::getSystemTypeCode, dto.getSystemTypeCode());
|
|
|
+ wrapper.eq(ObjectUtil.isNotNull(dto.getStatus()), HhOmcDevice::getStatus, dto.getStatus());
|
|
|
+ //基础条件
|
|
|
+ wrapper.eq(HhOmcDevice::getIsDeleted, Boolean.FALSE);
|
|
|
+ wrapper.orderByDesc(HhOmcDevice::getId);
|
|
|
+ return wrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RestResult<List<String>> snlist() {
|
|
|
+ List<HhOmcDevice> devices = hhOmcDeviceMapper.selectList(Wrappers.lambdaQuery(HhOmcDevice.class).select(HhOmcDevice::getSn).eq(HhOmcDevice::getStatus, Boolean.TRUE).eq(HhOmcDevice::getIsDeleted, Boolean.FALSE));
|
|
|
+ List<String> sns = devices.stream().map(HhOmcDevice::getSn).collect(Collectors.toList());
|
|
|
+ return RestResult.ok(sns == null || sns.isEmpty() ? Collections.emptyList() : sns);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RestResult<Boolean> del(Long deviceId) {
|
|
|
+ HhOmcDevice device = hhOmcDeviceMapper.selectById(deviceId);
|
|
|
+ if (device != null && device.getIsDeleted() != null && !device.getIsDeleted()) {
|
|
|
+ hhOmcDeviceMapper.deleteById(device);
|
|
|
+ }
|
|
|
+ return RestResult.ok(Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RestResult<Boolean> opeDeviceAuth(Long deviceId, Boolean enableflag) {
|
|
|
+ HhOmcDevice device = hhOmcDeviceMapper.selectById(deviceId);
|
|
|
+ if (device != null && !device.getIsDeleted()) {
|
|
|
+ device.setStatus(enableflag);
|
|
|
+ device.setUpdateTime(new Date());
|
|
|
+ hhOmcDeviceMapper.updateById(device);
|
|
|
+ }
|
|
|
+ return RestResult.ok(Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RestResult<HhOmcDeviceVo> queryConfig(TenantDto dto) {
|
|
|
+ List<HhOmcDevice> devices = hhOmcDeviceMapper.selectList(Wrappers.lambdaQuery(HhOmcDevice.class).eq(HhOmcDevice::getStatus, Boolean.TRUE).eq(HhOmcDevice::getSn, dto.getSn()).eq(HhOmcDevice::getIsDeleted, Boolean.FALSE));
|
|
|
+ if (devices == null || devices.size() == 0) {
|
|
|
+ return RestResult.error("设备商户平台未授权");
|
|
|
+ }
|
|
|
+ HhOmcDeviceVo vo = BeanUtil.copyProperties(devices, HhOmcDeviceVo.class);
|
|
|
+ return RestResult.ok(vo != null ? completeOthers(vo) : null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private HhOmcDeviceVo completeOthers(HhOmcDeviceVo vo) {
|
|
|
+ List<HhOmcDeviceVo> vos = Arrays.asList(vo);
|
|
|
+ Map<Long, Purchaser> purchaserMap = commonImpl.getPurchaserMap(vos, HhOmcDeviceVo::getPurchaserId);
|
|
|
+ Map<Long, ApplicationType> applicationTypeMap = commonImpl.getApplicationTypeMap(vos, HhOmcDeviceVo::getApplicationTypeId);
|
|
|
+ Map<Long, DeviceModel> deviceModelHardwareMap = commonImpl.getDeviceModelMap(vos, HhOmcDeviceVo::getDeviceModelHardwareId);
|
|
|
+ Map<Long, DeviceModel> deviceModelEnvironmentMap = commonImpl.getDeviceModelMap(vos, HhOmcDeviceVo::getDeviceModelEnvironmentId);
|
|
|
+ if (purchaserMap.containsKey(vo.getPurchaserId())) {
|
|
|
+ vo.setCompanyName(purchaserMap.get(vo.getPurchaserId()).getCompanyName());
|
|
|
+ }
|
|
|
+ if (applicationTypeMap.containsKey(vo.getApplicationTypeId())) {
|
|
|
+ vo.setApplicationType(applicationTypeMap.get(vo.getApplicationTypeId()).getApplicationType());
|
|
|
+ }
|
|
|
+ if (deviceModelHardwareMap.containsKey(vo.getDeviceModelHardwareId())) {
|
|
|
+ vo.setDeviceModelHardware(deviceModelHardwareMap.get(vo.getDeviceModelHardwareId()).getDeviceModel());
|
|
|
+ }
|
|
|
+ if (deviceModelEnvironmentMap.containsKey(vo.getDeviceModelEnvironmentId())) {
|
|
|
+ vo.setDeviceModelEnvironment(deviceModelEnvironmentMap.get(vo.getDeviceModelEnvironmentId()).getDeviceModel());
|
|
|
+ }
|
|
|
+ SystemTypeEnum systemTypeEnum = SystemTypeEnum.getEnumByCode(vo.getSystemTypeCode());
|
|
|
+ if (ObjectUtil.isNotNull(systemTypeEnum)) {
|
|
|
+ vo.setSystemType(systemTypeEnum.getDesc());
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+}
|