You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.0 KiB
Java
85 lines
3.0 KiB
Java
package com.glxp.api.req.dev;
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.glxp.api.entity.dev.DeviceCheckItemDictEntity;
|
|
import com.glxp.api.entity.dev.DevicePlanDetailEntity;
|
|
import com.glxp.api.entity.dev.DevicePlanDetailItemEntity;
|
|
import com.glxp.api.exception.JsonException;
|
|
import com.glxp.api.service.dev.DeviceCheckItemDictService;
|
|
import com.glxp.api.service.dev.DevicePlanDetailService;
|
|
import lombok.Data;
|
|
|
|
import javax.validation.constraints.NotEmpty;
|
|
import javax.validation.constraints.NotNull;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Data
|
|
public class DevicePlanDetailItemParam {
|
|
|
|
/**
|
|
* 计划id
|
|
*/
|
|
@NotNull(message = "计划标识不能为空")
|
|
Long planId;
|
|
|
|
Long productId;
|
|
|
|
/**
|
|
* 设备编码
|
|
*/
|
|
String deviceCode;
|
|
|
|
|
|
@NotEmpty(message = "巡检项目不能为空")
|
|
Set<String> itemCodes;
|
|
|
|
|
|
public void valid(DevicePlanDetailService devicePlanDetailService) {
|
|
DevicePlanDetailEntity one = devicePlanDetailService.getOne(Wrappers.lambdaQuery(DevicePlanDetailEntity.class)
|
|
.eq(DevicePlanDetailEntity::getPlanId, planId)
|
|
.eq(DevicePlanDetailEntity::getProductId, productId)
|
|
.eq(StrUtil.isNotBlank(deviceCode), DevicePlanDetailEntity::getDeviceCode, deviceCode)
|
|
.last("limit 1")
|
|
);
|
|
if (one == null) {
|
|
throw new JsonException("未找到该计划中的设备,无法操作");
|
|
}
|
|
}
|
|
|
|
public List<DevicePlanDetailItemEntity> getEntity(DeviceCheckItemDictService deviceCheckItemDictService) {
|
|
List<DeviceCheckItemDictEntity> list = deviceCheckItemDictService.listByIds(itemCodes);
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
throw new JsonException("所有项目编码都不存在,疑似非法操作");
|
|
}
|
|
if (list.size() != itemCodes.size()) {
|
|
Map<String, List<DeviceCheckItemDictEntity>> collect = list.stream().collect(Collectors.groupingBy(DeviceCheckItemDictEntity::getCode));
|
|
itemCodes.forEach(i -> {
|
|
boolean b = collect.containsKey(i);
|
|
if (!b) {
|
|
throw new JsonException(String.format("项目编码[%s]不存在", i));
|
|
}
|
|
});
|
|
}
|
|
List<DevicePlanDetailItemEntity> entityList = new ArrayList<>();
|
|
list.forEach(i -> {
|
|
DevicePlanDetailItemEntity build = DevicePlanDetailItemEntity.builder()
|
|
.planId(planId)
|
|
.productId(productId)
|
|
.deviceCode(StrUtil.blankToDefault(deviceCode, ""))
|
|
.itemCode(i.getCode())
|
|
.name(i.getName())
|
|
.content(i.getContent())
|
|
.build();
|
|
entityList.add(build);
|
|
});
|
|
return entityList;
|
|
}
|
|
|
|
}
|