|
|
|
|
@ -26,11 +26,13 @@ import org.springblade.modules.business.pojo.dto.DeviceDTO; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.Device; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.DeviceAttach; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.DeviceMaintenance; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.DeviceType; |
|
|
|
|
import org.springblade.modules.business.pojo.vo.DeviceVO; |
|
|
|
|
import org.springblade.modules.business.pojo.vo.PieStatVO; |
|
|
|
|
import org.springblade.modules.business.service.IDeviceAttachService; |
|
|
|
|
import org.springblade.modules.business.service.IDeviceMaintenanceService; |
|
|
|
|
import org.springblade.modules.business.service.IDeviceService; |
|
|
|
|
import org.springblade.modules.business.service.IDeviceTypeService; |
|
|
|
|
import org.springblade.modules.system.pojo.entity.Dept; |
|
|
|
|
import org.springblade.modules.system.pojo.vo.DeptVO; |
|
|
|
|
import org.springblade.modules.system.service.IDeptService; |
|
|
|
|
@ -38,6 +40,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
@ -53,6 +56,7 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceMapper, Device> imp |
|
|
|
|
|
|
|
|
|
private final IDeviceAttachService deviceAttachService; |
|
|
|
|
private final IDeviceMaintenanceService maintenanceService; |
|
|
|
|
private final IDeviceTypeService typeService; |
|
|
|
|
private final IDeptService deptService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@ -73,7 +77,10 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceMapper, Device> imp |
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public boolean add(DeviceDTO device) { |
|
|
|
|
device.setCode("编码格式待定"); |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); |
|
|
|
|
String timestamp = sdf.format(new Date()); |
|
|
|
|
String typeName = device.getTypeName().replace("/", "-"); |
|
|
|
|
device.setCode(typeName + "-" + timestamp); |
|
|
|
|
device.setRunStatus(CommonConstant.DEVICE_RUN_STATUS_WORKING); |
|
|
|
|
boolean save = this.save(device); |
|
|
|
|
// 附件保存
|
|
|
|
|
@ -219,9 +226,32 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceMapper, Device> imp |
|
|
|
|
if(StringUtils.isEmpty(deviceExcel.getCode())){ |
|
|
|
|
throw new ServiceException("设备" + deviceExcel.getName() + "未填写设备编码,请修改后再上传!"); |
|
|
|
|
} |
|
|
|
|
if(StringUtils.isEmpty(deviceExcel.getTypeName())){ |
|
|
|
|
throw new ServiceException("设备" + deviceExcel.getName() + "未填写设备类型,请修改后再上传!"); |
|
|
|
|
} |
|
|
|
|
Device device = BeanUtil.copyProperties(deviceExcel, Device.class); |
|
|
|
|
DeviceMaintenance deviceMaintenance = BeanUtil.copyProperties(deviceExcel, DeviceMaintenance.class); |
|
|
|
|
if (device != null) { |
|
|
|
|
// 根据传入的typeName查询设备id
|
|
|
|
|
String fullTypeName = device.getTypeName(); |
|
|
|
|
String[] typeParts = fullTypeName.split("/"); |
|
|
|
|
String name = typeParts[typeParts.length - 1].trim(); |
|
|
|
|
LambdaQueryWrapper<DeviceType> wrapper = Wrappers.lambdaQuery(DeviceType.class) |
|
|
|
|
.eq(DeviceType::getTypeName, name); |
|
|
|
|
DeviceType deviceType = typeService.getOne(wrapper); |
|
|
|
|
if (deviceType != null) { |
|
|
|
|
StringBuilder parentIds = new StringBuilder(); |
|
|
|
|
getAllParentIdsRecursive(deviceType.getId(), parentIds); |
|
|
|
|
// 移除最后一个逗号
|
|
|
|
|
if (parentIds.length() > 0) { |
|
|
|
|
parentIds.setLength(parentIds.length() - 1); |
|
|
|
|
} else { |
|
|
|
|
parentIds.append(deviceType.getId()); |
|
|
|
|
} |
|
|
|
|
device.setType(parentIds.toString()); |
|
|
|
|
} else { |
|
|
|
|
throw new ServiceException("设备" + deviceExcel.getName() + "的设备类型不存在,请填写正确的设备类型"); |
|
|
|
|
} |
|
|
|
|
//根据编码查询设备
|
|
|
|
|
Device oldDevice = this.getOne(Wrappers.lambdaQuery(Device.class).eq(Device::getCode,device.getCode()).eq(BaseEntity::getIsDeleted,0)); |
|
|
|
|
if (oldDevice != null) { |
|
|
|
|
@ -242,6 +272,29 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceMapper, Device> imp |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 递归方法获取所有上级的 ID 并拼接到 StringBuilder 中 |
|
|
|
|
* |
|
|
|
|
* @param currentId 当前父级 ID |
|
|
|
|
* @param parentIds 拼接结果 |
|
|
|
|
*/ |
|
|
|
|
private void getAllParentIdsRecursive(Long currentId, StringBuilder parentIds) { |
|
|
|
|
if (currentId == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询当前设备类型
|
|
|
|
|
LambdaQueryWrapper<DeviceType> wrapper = Wrappers.lambdaQuery(DeviceType.class) |
|
|
|
|
.eq(DeviceType::getId, currentId); |
|
|
|
|
DeviceType currentType = typeService.getOne(wrapper); |
|
|
|
|
|
|
|
|
|
if (currentType != null) { |
|
|
|
|
// 先递归查询父级,再添加当前 ID
|
|
|
|
|
getAllParentIdsRecursive(currentType.getParentId(), parentIds); |
|
|
|
|
parentIds.append(currentType.getId()).append(","); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<DeviceVO> limsList(Device device) { |
|
|
|
|
|