装车前检测排序修改

This commit is contained in:
funny 2026-05-11 17:05:28 +08:00
parent dc779f5b12
commit edb387a8a5
6 changed files with 118 additions and 24 deletions

View File

@ -92,8 +92,9 @@ public class QmsPdiDeliveryItemController extends BaseController {
*/
@GetMapping("/search")
public ApiResult<List<QmsPdiDetectionRulesDeliveryItem>> search(
@NotNull(message = "PDI检测规则ID不能为空") @RequestParam Long detectionRulesId) {
return ApiResult.success(deliveryItemControllerService.search(detectionRulesId));
@NotNull(message = "PDI检测规则ID不能为空") @RequestParam Long detectionRulesId,
@RequestParam(defaultValue = "true") Boolean isAsc) {
return ApiResult.success(deliveryItemControllerService.search(detectionRulesId, isAsc));
}
/**

View File

@ -54,20 +54,12 @@ public class QmsPdiDeliveryItemControllerService {
.map(QmsPdiDetectionRulesDeliveryItem::getSort)
.orElse(0);
// 将已有数据的sort全部+1
if (maxSort > 0) {
deliveryItemService.lambdaUpdate()
.eq(QmsPdiDetectionRulesDeliveryItem::getDetectionRulesId, request.getDetectionRulesId())
.setSql("sort = sort + 1")
.update();
}
String operator = UserUtil.getUserName();
LocalDateTime now = LocalDateTime.now();
QmsPdiDetectionRulesDeliveryItem entity = new QmsPdiDetectionRulesDeliveryItem()
.setDetectionRulesId(request.getDetectionRulesId())
.setChecklist(request.getChecklist())
.setSort(1) // 新数据sort=1
.setSort(maxSort + 1) // 追加到最后
.setCreateBy(operator)
.setCreateTime(now);
deliveryItemService.save(entity);
@ -131,10 +123,49 @@ public class QmsPdiDeliveryItemControllerService {
if (CollectionUtil.isEmpty(data)) {
throw new NflgException(STATE.BusinessError, "导入文件内容为空");
}
// 过滤掉检查项为空的数据
List<QmsPdiDeliveryItemExportDTO> validData = data.stream()
.filter(dto -> StrUtil.isNotBlank(dto.getChecklist()))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(validData)) {
throw new NflgException(STATE.BusinessError, "导入数据中检查项均为空,请检查文件");
}
// 查询数据库中该检测规则的最大sort值
Integer maxSort = deliveryItemService.lambdaQuery()
.eq(QmsPdiDetectionRulesDeliveryItem::getDetectionRulesId, detectionRulesId)
.orderByDesc(QmsPdiDetectionRulesDeliveryItem::getSort)
.last("LIMIT 1")
.oneOpt()
.map(QmsPdiDetectionRulesDeliveryItem::getSort)
.orElse(0);
// 判断导入数据中是否有空的sort值
boolean hasEmptySort = validData.stream().anyMatch(dto -> dto.getSort() == null);
// 计算起始sort值
int startSort = maxSort + 1;
// 处理排序逻辑
if (hasEmptySort) {
// 情况A存在空值 - 按Excel顺序从起始值递增
for (int i = 0; i < validData.size(); i++) {
validData.get(i).setSort(startSort + i);
}
} else {
// 情况B全部有值 - 先按sort排序再从起始值递增
validData.sort(java.util.Comparator.comparingInt(QmsPdiDeliveryItemExportDTO::getSort));
for (int i = 0; i < validData.size(); i++) {
validData.get(i).setSort(startSort + i);
}
}
// 转换为实体并保存
String operator = UserUtil.getUserName();
LocalDateTime now = LocalDateTime.now();
List<QmsPdiDetectionRulesDeliveryItem> entities = data.stream()
.filter(dto -> StrUtil.isNotBlank(dto.getChecklist()))
List<QmsPdiDetectionRulesDeliveryItem> entities = validData.stream()
.map(dto -> new QmsPdiDetectionRulesDeliveryItem()
.setDetectionRulesId(detectionRulesId)
.setChecklist(dto.getChecklist())
@ -142,9 +173,7 @@ public class QmsPdiDeliveryItemControllerService {
.setCreateBy(operator)
.setCreateTime(now))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(entities)) {
throw new NflgException(STATE.BusinessError, "导入数据中检查项均为空,请检查文件");
}
deliveryItemService.saveBatch(entities);
markMaintained(detectionRulesId);
}
@ -155,12 +184,33 @@ public class QmsPdiDeliveryItemControllerService {
* 查询PDI发货前检查项列表
*
* @param detectionRulesId PDI检测规则ID必传
* @param isAsc 是否升序true=升序默认false=降序
*/
public List<QmsPdiDetectionRulesDeliveryItem> search(Long detectionRulesId) {
return deliveryItemService.lambdaQuery()
public List<QmsPdiDetectionRulesDeliveryItem> search(Long detectionRulesId, Boolean isAsc) {
// 1. 查询所有数据按sort升序
List<QmsPdiDetectionRulesDeliveryItem> allItems = deliveryItemService.lambdaQuery()
.eq(QmsPdiDetectionRulesDeliveryItem::getDetectionRulesId, detectionRulesId)
.orderByAsc(QmsPdiDetectionRulesDeliveryItem::getSort)
.list();
// 2. 重新赋值sort从1开始连续递增
for (int i = 0; i < allItems.size(); i++) {
allItems.get(i).setSort(i + 1);
}
// 3. 批量更新数据库
if (!allItems.isEmpty()) {
deliveryItemService.updateBatchById(allItems);
}
// 4. 如果是降序反转列表
boolean ascending = isAsc == null || isAsc; // 默认升序
if (!ascending) {
java.util.Collections.reverse(allItems);
}
// 5. 返回
return allItems;
}
/**

View File

@ -39,6 +39,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
@ -306,20 +307,49 @@ public class QmsPdiStatusItemControllerService {
// 获取排序方向默认升序
boolean ascending = isAsc == null || isAsc;
Page<QmsPdiDetectionRulesStatusItem> page = statusItemService.lambdaQuery()
// 1. 查询所有数据不分页按sort升序
List<QmsPdiDetectionRulesStatusItem> allItems = statusItemService.lambdaQuery()
.eq(QmsPdiDetectionRulesStatusItem::getDetectionRulesId, detectionRulesId)
.eq(QmsPdiDetectionRulesStatusItem::getStatus, status)
.orderBy(true, ascending, QmsPdiDetectionRulesStatusItem::getSort)
.page(new Page<>(pageNum, pageSize));
.orderByAsc(QmsPdiDetectionRulesStatusItem::getSort)
.list();
List<QmsPdiStatusItemGroupVO.QmsPdiStatusItemVO> voList = page.getRecords().stream()
// 2. 重新赋值sort从1开始连续递增
for (int i = 0; i < allItems.size(); i++) {
allItems.get(i).setSort(i + 1);
}
// 3. 批量更新数据库
if (!allItems.isEmpty()) {
statusItemService.updateBatchById(allItems);
}
// 4. 按排序方向分页
int total = allItems.size();
int fromIndex = (pageNum - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, total);
List<QmsPdiDetectionRulesStatusItem> pagedItems;
if (fromIndex >= total) {
pagedItems = List.of();
} else {
pagedItems = allItems.subList(fromIndex, toIndex);
// 如果是降序反转列表
if (!ascending) {
pagedItems = new ArrayList<>(pagedItems);
java.util.Collections.reverse(pagedItems);
}
}
// 5. 转换为VO
List<QmsPdiStatusItemGroupVO.QmsPdiStatusItemVO> voList = pagedItems.stream()
.map(this::toVO)
.collect(Collectors.toList());
PageData<QmsPdiStatusItemGroupVO.QmsPdiStatusItemVO> pd = new PageData<>();
pd.setPage(pageNum);
pd.setPageSize(pageSize);
pd.setTotal((int) page.getTotal());
pd.setTotal(total);
pd.setItems(voList);
return pd;
}

View File

@ -82,6 +82,9 @@ public class QmsPdiTaskRecordControllerService {
* 分页查询关联检测规则质检人帮办人
*/
public PageData<QmsPdiTaskRecordPageVO> search(QmsPdiTaskRecordSearchQO request) {
// 填充当前登录用户ID用于数据权限过滤
request.setCurrentUserId(UserUtil.getUserId());
Page<QmsPdiTaskRecordPageVO> page = taskRecordService.search(request);
PageData<QmsPdiTaskRecordPageVO> result = new PageData<>();
result.setItems(page.getRecords());

View File

@ -45,7 +45,7 @@ public class QmsPdiTaskRecordSearchQO {
private String warehouseNo;
/**
* 检验类型必传0=静态1=动态2=特殊
* 检验类型必传0=新机检测1=库存检测
*/
@NotNull(message = "检验类型不能为空")
private Integer inspectionType;
@ -59,4 +59,9 @@ public class QmsPdiTaskRecordSearchQO {
* 每页条数
*/
private Integer pageSize = 20;
/**
* 当前登录用户ID用于数据权限过滤由系统自动填充
*/
private Long currentUserId;
}

View File

@ -51,6 +51,11 @@
<if test="request.warehouseNo != null and request.warehouseNo != ''">
AND t.warehouse_no = #{request.warehouseNo}
</if>
<!-- 权限校验:当前登录用户只能看到自己负责的数据 -->
AND (
r.inspector_id = #{request.currentUserId}
OR t.assistant_id = #{request.currentUserId}
)
<!-- 合格物料过滤inspection_enable=0/1/3不校验inspection_enable=2校验自身结果+检测项结果(type=2除外) -->
AND (
t.inspection_enable IN (0, 1, 3)