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.
udi-wms-java/src/main/java/com/glxp/api/req/dev/DeviceRepairApplyAddParam.java

111 lines
3.7 KiB
Java

package com.glxp.api.req.dev;
import cn.hutool.core.bean.BeanUtil;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.dev.DeviceInfoEntity;
import com.glxp.api.entity.dev.DeviceRepairApplyDetailEntity;
import com.glxp.api.entity.dev.DeviceRepairApplyEntity;
import com.glxp.api.enums.dev.DeviceRepairApplyDetailStatusEnum;
import com.glxp.api.enums.dev.DeviceRepairApplyStatusEnum;
import com.glxp.api.enums.dev.DeviceStatusEnum;
import com.glxp.api.exception.JsonException;
import com.glxp.api.service.dev.DeviceInfoService;
import com.glxp.api.util.SnowflakeUtil;
import com.glxp.api.vo.dev.DeviceInfoVo;
import lombok.Data;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@Data
public class DeviceRepairApplyAddParam {
/**
* 报修人联系方式
*/
@NotBlank(message = "报修人联系方式不能为空")
String applyUserPhone;
@Valid
@NotEmpty(message = "请选择至少一个设备进行报修")
Set<ApplyDetail> details;
Long taskId;
@Data
public static class ApplyDetail {
/**
* 设备编码
*/
@NotBlank(message = "设备编码不能为空")
String deviceCode;
/**
* 问题描述
*/
@NotBlank(message = "问题描述不能为空")
String description;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ApplyDetail that = (ApplyDetail) o;
return Objects.equals(deviceCode, that.deviceCode);
}
@Override
public int hashCode() {
return Objects.hash(deviceCode);
}
}
public void valid() {
}
public DeviceRepairApplyEntity getEntity(AuthAdmin user) {
return DeviceRepairApplyEntity
.builder()
.id(SnowflakeUtil.getId())
.status(DeviceRepairApplyStatusEnum.WAIT_PROCESS)
.applyDeptCode(user.getLocDeptCode())
.applyDeptName(user.getDeptName())
.applyUserId(user.getId())
.applyUserName(user.getEmployeeName())
.applyUserPhone(this.applyUserPhone)
.applyTime(LocalDateTime.now())
.deviceCount(details.size())
.finishCount(0)
.build();
}
public List<DeviceRepairApplyDetailEntity> getDetailEntityList(Long applyId, DeviceInfoService deviceInfoService, AuthAdmin user) {
List<DeviceInfoVo> list = deviceInfoService.listVoByCodes(details.stream().map(ApplyDetail::getDeviceCode).collect(Collectors.toList()), user.getLocDeptCode(), DeviceStatusEnum.NORMAL);
if (list.size() != details.size()) {
throw new JsonException("设备状态异常或信息不符,请确认");
}
Map<String, List<DeviceInfoEntity>> deviceMap = list.stream().collect(Collectors.groupingBy(DeviceInfoEntity::getDeviceCode));
return details.stream().map(d -> {
DeviceInfoEntity info = deviceMap.get(d.getDeviceCode()).get(0);
DeviceRepairApplyDetailEntity build = DeviceRepairApplyDetailEntity.builder()
.applyId(applyId)
.description(d.getDescription())
.status(DeviceRepairApplyDetailStatusEnum.WAIT_DIAGNOSIS)
.build();
BeanUtil.copyProperties(info, build,"status");
return build;
}).collect(Collectors.toList());
}
}