pdi方法修改
This commit is contained in:
parent
b8177bf2a0
commit
48367152cb
|
|
@ -2,7 +2,10 @@ package com.nflg.qms.admin.controller;
|
|||
|
||||
import com.nflg.qms.admin.service.QmsPdiComponentBindingControllerService;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.pojo.PageData;
|
||||
import com.nflg.wms.common.pojo.qo.QmsPdiComponentBindingComponentSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.QmsPdiComponentBindingSaveQO;
|
||||
import com.nflg.wms.common.pojo.vo.QmsPdiComponentBindingComponentVO;
|
||||
import com.nflg.wms.common.pojo.vo.QmsPdiComponentBindingSearchVO;
|
||||
import com.nflg.wms.starter.BaseController;
|
||||
import jakarta.annotation.Resource;
|
||||
|
|
@ -37,4 +40,13 @@ public class QmsPdiComponentBindingController extends BaseController {
|
|||
@Valid @NotNull(message = "PDI标准检测规则ID不能为空") @RequestParam Long pdiDetectionRulesId) {
|
||||
return ApiResult.success(componentBindingControllerService.search(pdiDetectionRulesId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询标准检测中已有检测项的部件(同名部件合并)
|
||||
*/
|
||||
@PostMapping("/component/search")
|
||||
public ApiResult<PageData<QmsPdiComponentBindingComponentVO>> searchComponents(
|
||||
@Valid @RequestBody QmsPdiComponentBindingComponentSearchQO request) {
|
||||
return ApiResult.success(componentBindingControllerService.searchComponents(request));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ import cn.hutool.core.collection.CollectionUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.wms.common.constant.STATE;
|
||||
import com.nflg.wms.common.exception.NflgException;
|
||||
import com.nflg.wms.common.pojo.PageData;
|
||||
import com.nflg.wms.common.pojo.qo.QmsPdiComponentBindingComponentSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.QmsPdiComponentBindingSaveQO;
|
||||
import com.nflg.wms.common.pojo.vo.QmsPdiComponentBindingComponentVO;
|
||||
import com.nflg.wms.common.pojo.vo.QmsPdiComponentBindingSearchVO;
|
||||
import com.nflg.wms.repository.entity.FileUploadRecord;
|
||||
import com.nflg.wms.repository.entity.QmsPdiComponentAnagement;
|
||||
|
|
@ -152,6 +155,70 @@ public class QmsPdiComponentBindingControllerService {
|
|||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询标准检测中已有检测项的部件,同名静态/动态部件合并返回。
|
||||
*/
|
||||
public PageData<QmsPdiComponentBindingComponentVO> searchComponents(QmsPdiComponentBindingComponentSearchQO request) {
|
||||
List<Long> componentIds = statusItemService.lambdaQuery()
|
||||
.select(QmsPdiDetectionRulesStatusItem::getComponentsId)
|
||||
.eq(QmsPdiDetectionRulesStatusItem::getDetectionRulesId, request.getDetectionRulesId())
|
||||
.in(QmsPdiDetectionRulesStatusItem::getStatus, (int) STATIC_STATUS, (int) DYNAMIC_STATUS)
|
||||
.isNotNull(QmsPdiDetectionRulesStatusItem::getComponentsId)
|
||||
.list()
|
||||
.stream()
|
||||
.map(QmsPdiDetectionRulesStatusItem::getComponentsId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollectionUtil.isEmpty(componentIds)) {
|
||||
return pageComponents(request, List.of());
|
||||
}
|
||||
|
||||
List<QmsPdiComponentAnagement> components = componentService.lambdaQuery()
|
||||
.eq(QmsPdiComponentAnagement::getDetectionRulesId, request.getDetectionRulesId())
|
||||
.in(QmsPdiComponentAnagement::getId, componentIds)
|
||||
.list();
|
||||
|
||||
components.sort(Comparator
|
||||
.comparing(QmsPdiComponentAnagement::getSort, Comparator.nullsLast(Integer::compareTo))
|
||||
.thenComparing(QmsPdiComponentAnagement::getComponentName, Comparator.nullsLast(String::compareTo))
|
||||
.thenComparing(QmsPdiComponentAnagement::getStatus, Comparator.nullsLast(Short::compareTo))
|
||||
.thenComparing(QmsPdiComponentAnagement::getId, Comparator.nullsLast(Long::compareTo)));
|
||||
|
||||
Map<String, QmsPdiComponentBindingComponentVO> groupMap = new LinkedHashMap<>();
|
||||
for (QmsPdiComponentAnagement component : components) {
|
||||
String componentName = component.getComponentName();
|
||||
QmsPdiComponentBindingComponentVO groupVO = groupMap.computeIfAbsent(componentName, name -> {
|
||||
QmsPdiComponentBindingComponentVO vo = new QmsPdiComponentBindingComponentVO();
|
||||
vo.setComponentName(name);
|
||||
vo.setSort(component.getSort());
|
||||
return vo;
|
||||
});
|
||||
if (groupVO.getSort() == null
|
||||
|| (component.getSort() != null && component.getSort() < groupVO.getSort())) {
|
||||
groupVO.setSort(component.getSort());
|
||||
}
|
||||
|
||||
QmsPdiComponentBindingComponentVO.ComponentStatusVO statusVO =
|
||||
new QmsPdiComponentBindingComponentVO.ComponentStatusVO();
|
||||
statusVO.setComponentId(component.getId());
|
||||
statusVO.setStatus(component.getStatus());
|
||||
statusVO.setStatusName(getStatusName(component.getStatus()));
|
||||
groupVO.getComponents().add(statusVO);
|
||||
}
|
||||
|
||||
List<QmsPdiComponentBindingComponentVO> groupedComponents = new ArrayList<>(groupMap.values());
|
||||
groupedComponents.forEach(group -> group.getComponents().sort(Comparator
|
||||
.comparing(QmsPdiComponentBindingComponentVO.ComponentStatusVO::getStatus, Comparator.nullsLast(Short::compareTo))
|
||||
.thenComparing(QmsPdiComponentBindingComponentVO.ComponentStatusVO::getComponentId, Comparator.nullsLast(Long::compareTo))));
|
||||
groupedComponents.sort(Comparator
|
||||
.comparing(QmsPdiComponentBindingComponentVO::getSort, Comparator.nullsLast(Integer::compareTo))
|
||||
.thenComparing(QmsPdiComponentBindingComponentVO::getComponentName, Comparator.nullsLast(String::compareTo)));
|
||||
|
||||
return pageComponents(request, groupedComponents);
|
||||
}
|
||||
|
||||
private void validateSaveRequest(QmsPdiComponentBindingSaveQO request) {
|
||||
Set<Long> imageIds = request.getItems().stream()
|
||||
.peek(image -> {
|
||||
|
|
@ -287,8 +354,6 @@ public class QmsPdiComponentBindingControllerService {
|
|||
|
||||
private boolean isEffectiveBinding(QmsPdiComponentBinding binding) {
|
||||
return binding.getPdiComponentId() != null
|
||||
&& StrUtil.isNotBlank(binding.getXCoordinatePoint())
|
||||
&& StrUtil.isNotBlank(binding.getYCoordinatePoint())
|
||||
&& isAllowedStatus(binding.getStatus());
|
||||
}
|
||||
|
||||
|
|
@ -310,6 +375,33 @@ public class QmsPdiComponentBindingControllerService {
|
|||
return componentId + "|" + status;
|
||||
}
|
||||
|
||||
private String getStatusName(Short status) {
|
||||
if (Objects.equals(status, STATIC_STATUS)) {
|
||||
return "静态";
|
||||
}
|
||||
if (Objects.equals(status, DYNAMIC_STATUS)) {
|
||||
return "动态";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private PageData<QmsPdiComponentBindingComponentVO> pageComponents(
|
||||
QmsPdiComponentBindingComponentSearchQO request,
|
||||
List<QmsPdiComponentBindingComponentVO> components) {
|
||||
int page = request.getPage() == null || request.getPage() < 1 ? 1 : request.getPage();
|
||||
int pageSize = request.getPageSize() == null || request.getPageSize() < 1 ? 20 : request.getPageSize();
|
||||
int total = components.size();
|
||||
int fromIndex = (page - 1) * pageSize;
|
||||
int toIndex = Math.min(fromIndex + pageSize, total);
|
||||
|
||||
PageData<QmsPdiComponentBindingComponentVO> pageData = new PageData<>();
|
||||
pageData.setPage(page);
|
||||
pageData.setPageSize(pageSize);
|
||||
pageData.setTotal(total);
|
||||
pageData.setItems(fromIndex >= total ? List.of() : components.subList(fromIndex, toIndex));
|
||||
return pageData;
|
||||
}
|
||||
|
||||
private ComponentStatus parseComponentStatusKey(String key) {
|
||||
String[] parts = key.split("\\|", 2);
|
||||
return new ComponentStatus(Long.valueOf(parts[0]), Short.valueOf(parts[1]));
|
||||
|
|
|
|||
|
|
@ -358,18 +358,6 @@ public class QmsPdiStatusItemControllerService {
|
|||
String operator = UserUtil.getUserName();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 查询部件表最大sort(按检测规则ID + 状态独立计算)
|
||||
Integer maxComponentSort = componentAnagementService.lambdaQuery()
|
||||
.eq(QmsPdiComponentAnagement::getDetectionRulesId, detectionRulesId)
|
||||
.eq(QmsPdiComponentAnagement::getStatus, status)
|
||||
.orderByDesc(QmsPdiComponentAnagement::getSort)
|
||||
.last("LIMIT 1")
|
||||
.oneOpt()
|
||||
.map(QmsPdiComponentAnagement::getSort)
|
||||
.orElse(0);
|
||||
|
||||
int currentComponentSort = maxComponentSort;
|
||||
|
||||
// 用于记录已处理的部件
|
||||
Map<String, Long> componentNameToIdMap = new java.util.LinkedHashMap<>();
|
||||
// 记录每个部件下的检测项数量
|
||||
|
|
@ -388,22 +376,17 @@ public class QmsPdiStatusItemControllerService {
|
|||
// 部件已存在,直接使用
|
||||
componentsId = componentNameToIdMap.get(dto.getComponentsDes());
|
||||
} else {
|
||||
// 新部件,插入到部件表
|
||||
currentComponentSort++;
|
||||
// 部件名称:如果以英文字母结束,追加换行符
|
||||
String componentName = appendNewlineIfEndsWithEnglish(dto.getComponentsDes());
|
||||
QmsPdiComponentAnagement component = new QmsPdiComponentAnagement();
|
||||
component.setComponentName(componentName);
|
||||
component.setDetectionRulesId(detectionRulesId);
|
||||
component.setStatus(status != null ? status.shortValue() : null);
|
||||
component.setSort(currentComponentSort);
|
||||
component.setCreateBy(operator);
|
||||
component.setCreateTime(now);
|
||||
componentAnagementService.save(component);
|
||||
|
||||
QmsPdiComponentAnagement component = componentAnagementService.lambdaQuery()
|
||||
.eq(QmsPdiComponentAnagement::getDetectionRulesId, detectionRulesId)
|
||||
.eq(QmsPdiComponentAnagement::getStatus, status)
|
||||
.eq(QmsPdiComponentAnagement::getComponentName, dto.getComponentsDes())
|
||||
.one();
|
||||
if (component == null) {
|
||||
throw new NflgException(STATE.BusinessError, "部件名称不存在,无法导入:" + dto.getComponentsDes());
|
||||
}
|
||||
componentsId = component.getId();
|
||||
componentNameToIdMap.put(dto.getComponentsDes(), componentsId);
|
||||
componentItemCountMap.put(componentsId, 0);
|
||||
componentItemCountMap.put(componentsId, getMaxItemSort(detectionRulesId, status, componentsId));
|
||||
}
|
||||
} else {
|
||||
componentsId = null;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* PDI部件绑定-标准检测部件分页查询参数
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class QmsPdiComponentBindingComponentSearchQO extends PageQO {
|
||||
|
||||
/**
|
||||
* PDI标准检测规则ID
|
||||
*/
|
||||
@NotNull(message = "PDI标准检测规则ID不能为空")
|
||||
private Long detectionRulesId;
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.nflg.wms.common.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PDI部件绑定-标准检测部件分页查询返回值
|
||||
*/
|
||||
@Data
|
||||
public class QmsPdiComponentBindingComponentVO {
|
||||
|
||||
/**
|
||||
* 部件名称
|
||||
*/
|
||||
private String componentName;
|
||||
|
||||
/**
|
||||
* 部件排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 同名部件下不同检测状态的部件ID
|
||||
*/
|
||||
private List<ComponentStatusVO> components = new ArrayList<>();
|
||||
|
||||
@Data
|
||||
public static class ComponentStatusVO {
|
||||
|
||||
/**
|
||||
* 部件ID
|
||||
*/
|
||||
private Long componentId;
|
||||
|
||||
/**
|
||||
* 状态:0=静态,1=动态
|
||||
*/
|
||||
private Short status;
|
||||
|
||||
/**
|
||||
* 状态名称
|
||||
*/
|
||||
private String statusName;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue