package com.qianwen.smartman.modules.cps.service.impl;
|
|
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.google.common.collect.Lists;
|
import java.lang.invoke.SerializedLambda;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Optional;
|
import java.util.Set;
|
import java.util.stream.Collectors;
|
import com.qianwen.smartman.common.cache.RegionCache;
|
import com.qianwen.smartman.common.constant.CommonConstant;
|
import com.qianwen.smartman.common.constant.ExcelConstant;
|
import com.qianwen.smartman.common.enums.StatusType;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.smartman.common.utils.ValidatorUtils;
|
import com.qianwen.core.excel.util.ExcelUtil;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
|
import com.qianwen.core.mp.support.Condition;
|
import com.qianwen.core.mp.support.Query;
|
import com.qianwen.core.oss.model.BladeFile;
|
import com.qianwen.core.secure.utils.AuthUtil;
|
import com.qianwen.core.tool.utils.CollectionUtil;
|
import com.qianwen.core.tool.utils.DateUtil;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.cps.convert.DeviceTypeConvert;
|
import com.qianwen.smartman.modules.cps.entity.DeviceType;
|
import com.qianwen.smartman.modules.cps.entity.Machine;
|
import com.qianwen.smartman.modules.cps.excel.DeviceTypeExcel;
|
import com.qianwen.smartman.modules.cps.mapper.DeviceTypeMapper;
|
import com.qianwen.smartman.modules.cps.service.IDeviceTypeService;
|
import com.qianwen.smartman.modules.cps.service.IMachineService;
|
import com.qianwen.smartman.modules.cps.vo.DeviceTypeAddVO;
|
import com.qianwen.smartman.modules.cps.vo.DeviceTypeExcelVO;
|
import com.qianwen.smartman.modules.cps.vo.DeviceTypeUpdateVO;
|
import com.qianwen.smartman.modules.cps.vo.DeviceTypeVO;
|
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.multipart.MultipartFile;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/cps/service/impl/DeviceTypeServiceImpl.class */
|
public class DeviceTypeServiceImpl extends BladeServiceImpl<DeviceTypeMapper, DeviceType> implements IDeviceTypeService {
|
private final OssBuilder ossBuilder;
|
private final IMachineService machineService;
|
|
private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
|
String implMethodName = lambda.getImplMethodName();
|
boolean z = true;
|
switch (implMethodName.hashCode()) {
|
case -274920090:
|
if (implMethodName.equals("getMachineTypeId")) {
|
z = true;
|
break;
|
}
|
break;
|
case -75622813:
|
if (implMethodName.equals("getCode")) {
|
z = true;
|
break;
|
}
|
break;
|
case -75308287:
|
if (implMethodName.equals("getName")) {
|
z = true;
|
break;
|
}
|
break;
|
case 98245393:
|
if (implMethodName.equals("getId")) {
|
z = true;
|
break;
|
}
|
break;
|
case 771206363:
|
if (implMethodName.equals("getTenantId")) {
|
z = true;
|
break;
|
}
|
break;
|
case 803533544:
|
if (implMethodName.equals("getStatus")) {
|
z = true;
|
break;
|
}
|
break;
|
case 1071464927:
|
if (implMethodName.equals("getCreateTime")) {
|
z = false;
|
break;
|
}
|
break;
|
}
|
switch (z) {
|
case false:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/util/Date;")) {
|
return (v0) -> {
|
return v0.getCreateTime();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getName();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getName();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getId();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Machine") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getMachineTypeId();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getStatus();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getStatus();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getStatus();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getStatus();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getStatus();
|
};
|
}
|
break;
|
case RegionCache.VILLAGE_LEVEL /* 5 */:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getTenantId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getTenantId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getTenantId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getTenantId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getTenantId();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/DeviceType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
break;
|
}
|
throw new IllegalArgumentException("Invalid lambda deserialization");
|
}
|
|
public DeviceTypeServiceImpl(final OssBuilder ossBuilder, final IMachineService machineService) {
|
this.ossBuilder = ossBuilder;
|
this.machineService = machineService;
|
}
|
|
@Override // org.springblade.modules.cps.service.IDeviceTypeService
|
public DeviceType createDeviceType(DeviceTypeAddVO deviceTypeAddVO) {
|
Long count = Long.valueOf(count((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getCode();
|
}, deviceTypeAddVO.getCode())).eq((v0) -> {
|
return v0.getStatus();
|
}, CommonConstant.ENABLE)).eq((v0) -> {
|
return v0.getTenantId();
|
}, AuthUtil.getTenantId())));
|
if (count.longValue() > 0) {
|
throw new ServiceException(MessageUtils.message("cps.workstation.device.type.code.already.exists", new Object[0]));
|
}
|
boolean result = checkUnableType(deviceTypeAddVO.getCode());
|
if (result) {
|
throw new ServiceException(MessageUtils.message("cps.work.station.device.already.stop.status", new Object[0]));
|
}
|
DeviceType deviceType = DeviceTypeConvert.INSTANCE.convert(deviceTypeAddVO);
|
save(deviceType);
|
return deviceType;
|
}
|
|
private boolean checkUnableType(String code) {
|
DeviceType deviceType = (DeviceType) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getCode();
|
}, code)).eq((v0) -> {
|
return v0.getStatus();
|
}, CommonConstant.DEACTIVATE));
|
if (deviceType != null) {
|
return Boolean.TRUE.booleanValue();
|
}
|
return Boolean.FALSE.booleanValue();
|
}
|
|
@Override // org.springblade.modules.cps.service.IDeviceTypeService
|
public DeviceType updateDeviceType(DeviceTypeUpdateVO deviceTypeUpdateVO) {
|
Long count = Long.valueOf(count((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getCode();
|
}, checkExistDeviceType(Long.valueOf(deviceTypeUpdateVO.getId().longValue())).getCode())).eq((v0) -> {
|
return v0.getTenantId();
|
}, AuthUtil.getTenantId())).ne((v0) -> {
|
return v0.getId();
|
}, deviceTypeUpdateVO.getId())));
|
if (count.longValue() > 0) {
|
throw new ServiceException(MessageUtils.message("cps.workstation.device.type.code.already.exists", new Object[0]));
|
}
|
DeviceType deviceType = DeviceTypeConvert.INSTANCE.convert(deviceTypeUpdateVO);
|
int nums = this.baseMapper.typeAndonRecord(Lists.newArrayList(new Long[]{deviceTypeUpdateVO.getId()}));
|
if (nums > 0) {
|
throw new ServiceException(MessageUtils.message("machine.type.andon.not.update", new Object[0]));
|
}
|
updateById(deviceType);
|
return deviceType;
|
}
|
|
@Override // org.springblade.modules.cps.service.IDeviceTypeService
|
public IPage<DeviceTypeVO> pageDeviceType(String keyWord, Integer status, Query query) {
|
IPage<DeviceType> page = page(Condition.getPage(query), (Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().eq((v0) -> {
|
return v0.getTenantId();
|
}, AuthUtil.getTenantId())).eq((v0) -> {
|
return v0.getStatus();
|
}, status == null ? CommonConstant.ENABLE : status)).and(Func.isNotEmpty(keyWord), wrapper -> {
|
LambdaUpdateWrapper lambdaUpdateWrapper = (LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) wrapper.likeRight((v0) -> {
|
return v0.getCode();
|
}, keyWord)).or()).likeRight((v0) -> {
|
return v0.getName();
|
}, keyWord);
|
}).orderByDesc((v0) -> {
|
return v0.getCreateTime();
|
}, new SFunction[]{(v0) -> {
|
return v0.getId();
|
}}));
|
return (IPage) Optional.ofNullable(page).map(p -> {
|
Page page2 = new Page(p.getCurrent(), p.getSize(), p.getTotal());
|
page2.setRecords(DeviceTypeConvert.INSTANCE.convert(p.getRecords()));
|
return page2;
|
}).orElse(new Page());
|
}
|
|
@Override // org.springblade.modules.cps.service.IDeviceTypeService
|
public DeviceTypeVO getDeviceTypeById(Long id) {
|
DeviceType deviceType = checkExistDeviceType(id);
|
return DeviceTypeConvert.INSTANCE.convert(deviceType);
|
}
|
|
@Override // org.springblade.modules.cps.service.IDeviceTypeService
|
public Boolean deleteDeviceTypeByIds(List<Long> ids, Integer type) {
|
List<Machine> machineList = this.machineService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getMachineTypeId();
|
}, ids));
|
if (StatusType.REMOVE.getType().equals(type)) {
|
if (CollectionUtil.isNotEmpty(machineList)) {
|
throw new ServiceException(MessageUtils.message("cps.work.station.already.associated.with.the.device", new Object[0]));
|
}
|
int nums = this.baseMapper.typeAndonRecord(ids);
|
if (nums > 0) {
|
throw new ServiceException(MessageUtils.message("machine.type.andon.not.remove", new Object[0]));
|
}
|
return Boolean.valueOf(removeByIds(ids));
|
} else if (CollectionUtil.isNotEmpty(machineList)) {
|
throw new ServiceException(MessageUtils.message("cps.work.station.already.associated.with.the.device.unable", new Object[0]));
|
} else {
|
return Boolean.valueOf(changeStatus(ids, CommonConstant.DEACTIVATE));
|
}
|
}
|
|
@Override // org.springblade.modules.cps.service.IDeviceTypeService
|
public List<DeviceTypeExcel> listDeviceType(String keyword, Integer status) {
|
List<DeviceType> deviceTypes = list((Wrapper) Wrappers.lambdaQuery().eq(status != null, (v0) -> {
|
return v0.getStatus();
|
}, status).and(Func.isNotEmpty(keyword), wrapper -> {
|
LambdaQueryWrapper lambdaQueryWrapper = (LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) wrapper.likeRight((v0) -> {
|
return v0.getCode();
|
}, keyword)).or()).likeRight((v0) -> {
|
return v0.getName();
|
}, keyword);
|
}).eq(Func.isNotEmpty(AuthUtil.getTenantId()), (v0) -> {
|
return v0.getTenantId();
|
}, AuthUtil.getTenantId()).orderByAsc((v0) -> {
|
return v0.getCode();
|
}));
|
List<DeviceTypeExcel> list = DeviceTypeConvert.INSTANCE.convert1(deviceTypes);
|
return list;
|
}
|
|
@Override // org.springblade.modules.cps.service.IDeviceTypeService
|
public BladeFile importDeviceType(List<DeviceTypeExcel> data) {
|
if (Func.isEmpty(data)) {
|
throw new ServiceException(MessageUtils.message("excel.import.data.can.not.be.null", new Object[0]));
|
}
|
if (data.size() > 200) {
|
throw new ServiceException(MessageUtils.message("excel.import.size.failed", new Object[0]));
|
}
|
List<DeviceType> deviceTypes = list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getStatus();
|
}, CommonConstant.ENABLE));
|
Set<String> codeSet = (Set) deviceTypes.stream().map((v0) -> {
|
return v0.getCode();
|
}).collect(Collectors.toSet());
|
Boolean flag = Boolean.TRUE;
|
for (DeviceTypeExcel datum : data) {
|
if (Func.isBlank(datum.getCode())) {
|
datum.setFailReason(MessageUtils.message("cps.work.station.device.code.is.null", new Object[0]));
|
flag = Boolean.FALSE;
|
} else {
|
if (Func.isNotBlank(datum.getCode())) {
|
if (codeSet.contains(datum.getCode())) {
|
datum.setFailReason(MessageUtils.message("cps.workstation.device.type.code.already.exists", new Object[0]));
|
flag = Boolean.FALSE;
|
} else {
|
codeSet.add(datum.getCode());
|
}
|
}
|
boolean result = checkUnableType(datum.getCode());
|
if (result) {
|
datum.setFailReason(MessageUtils.message("cps.work.station.device.already.stop.status", new Object[0]));
|
flag = Boolean.FALSE;
|
} else if (Func.isBlank(datum.getName())) {
|
datum.setFailReason(MessageUtils.message("cps.work.station.device.name.is.null", new Object[0]));
|
flag = Boolean.FALSE;
|
} else if (ValidatorUtils.stringFilter(datum.getCode())) {
|
datum.setFailReason(MessageUtils.message("cps.device.type.code.exist.special.symbols.error", new Object[0]));
|
flag = Boolean.FALSE;
|
} else if (ValidatorUtils.stringFilter(datum.getName())) {
|
datum.setFailReason(MessageUtils.message("cps.device.type.name.exist.special.symbols.error", new Object[0]));
|
flag = Boolean.FALSE;
|
}
|
}
|
}
|
if (!flag.booleanValue()) {
|
MultipartFile multipartFile = ExcelUtil.exportFillTemplateToMultipartFile(ExcelConstant.DIRECTORY + "机器类型导入失败模板" + ExcelConstant.SUFFIX, MessageUtils.message("excel.import.failed.report.name", new Object[0]) + ExcelConstant.SUFFIX, "机器类型表", (List) data.stream().filter(x -> {
|
return Func.isNotEmpty(x.getFailReason());
|
}).collect(Collectors.toList()), (Object) null, (AbstractMergeStrategy) null);
|
BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
|
return bladeFile;
|
}
|
List<DeviceType> list = new ArrayList<>();
|
data.forEach(x2 -> {
|
DeviceType deviceType = DeviceTypeConvert.INSTANCE.convert(x2);
|
list.add(deviceType);
|
});
|
if (CollectionUtil.isNotEmpty(list)) {
|
saveBatch(list);
|
return null;
|
}
|
return null;
|
}
|
|
@Override // org.springblade.modules.cps.service.IDeviceTypeService
|
public List<DeviceTypeVO> getDeviceTypeAllList() {
|
List<DeviceType> list = list();
|
List<DeviceTypeVO> result = DeviceTypeConvert.INSTANCE.convert(list);
|
return result;
|
}
|
|
@Override // org.springblade.modules.cps.service.IDeviceTypeService
|
public BladeFile export(DeviceTypeExcelVO deviceTypeExcelVO) {
|
List<DeviceTypeExcel> list = listDeviceType(deviceTypeExcelVO.getKeyWord(), deviceTypeExcelVO.getStatus());
|
String fileName = String.format("%s-%s.xlsx", "机器类型数据", DateUtil.time());
|
MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, "机器类型数据表", list, DeviceTypeExcel.class);
|
BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
|
return bladeFile;
|
}
|
|
private DeviceType checkExistDeviceType(Long id) {
|
DeviceType deviceType = (DeviceType) getById(id);
|
if (Func.isEmpty(deviceType)) {
|
throw new ServiceException(MessageUtils.message("cps.workstation.the.device.type.no.longer.exists", new Object[0]));
|
}
|
return deviceType;
|
}
|
|
boolean checkCodeIsExist(String code) {
|
DeviceType one = (DeviceType) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getCode();
|
}, code)).eq((v0) -> {
|
return v0.getTenantId();
|
}, AuthUtil.getTenantId()));
|
return Func.isNotEmpty(one);
|
}
|
}
|