|
|
|
|
@ -5,6 +5,7 @@ package org.springblade.desk.quality.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
|
import jakarta.annotation.Resource; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.Data; |
|
|
|
|
@ -13,7 +14,9 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.desk.basic.pojo.entity.BasicClazz; |
|
|
|
|
import org.springblade.desk.basic.util.QueryUtils; |
|
|
|
|
import org.springblade.desk.dashboard.pojo.vo.DsProModelVO; |
|
|
|
|
import org.springblade.desk.quality.excel.InspectionTemplateExcel; |
|
|
|
|
import org.springblade.desk.quality.mapper.InspectionTemplateMapper; |
|
|
|
|
import org.springblade.desk.quality.pojo.entity.InspectionTemplate; |
|
|
|
|
@ -26,7 +29,12 @@ import org.springblade.system.feign.IDictClient; |
|
|
|
|
import org.springblade.system.feign.IUserClient; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* [检验模板] 服务实现类 |
|
|
|
|
@ -80,4 +88,84 @@ public class InspectionTemplateServiceImpl extends BaseServiceImpl<InspectionTem |
|
|
|
|
public IPage<InspectionTemplate> listSearch(IPage<InspectionTemplate> page, InspectionTemplateSearch search) { |
|
|
|
|
return page.setRecords(baseMapper.listSearch(page, search)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<InspectionTemplateVO> getInspectionTemplateList() { |
|
|
|
|
List<InspectionTemplateVO> inspectionTemplateVOList = baseMapper.selectAll(); |
|
|
|
|
if (CollectionUtils.isEmpty(inspectionTemplateVOList)) { |
|
|
|
|
return List.of(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 1. 按照类别分类构建二级结构(包括category为null的情况)
|
|
|
|
|
Map<String, List<InspectionTemplateVO>> groupByCategory = inspectionTemplateVOList.stream() |
|
|
|
|
.collect(Collectors.groupingBy(vo -> vo.getCategory() == null ? "null" : vo.getCategory())); |
|
|
|
|
|
|
|
|
|
// 2. 构建二级结构的返回列表
|
|
|
|
|
List<InspectionTemplateVO> result = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<InspectionTemplateVO>> entry : groupByCategory.entrySet()) { |
|
|
|
|
String categoryKey = entry.getKey(); |
|
|
|
|
List<InspectionTemplateVO> children = entry.getValue(); |
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(children)) { |
|
|
|
|
// 创建父节点(类别分类)
|
|
|
|
|
InspectionTemplateVO parent = new InspectionTemplateVO(); |
|
|
|
|
|
|
|
|
|
// 判断是否为null的分类
|
|
|
|
|
if ("null".equals(categoryKey)) { |
|
|
|
|
parent.setCategory(null); |
|
|
|
|
parent.setCategoryName("未分类"); |
|
|
|
|
} else { |
|
|
|
|
parent.setCategory(categoryKey); |
|
|
|
|
} |
|
|
|
|
parent.setChildren(children); |
|
|
|
|
|
|
|
|
|
result.add(parent); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 3. 设置类别名称
|
|
|
|
|
for (InspectionTemplateVO vo : result) { |
|
|
|
|
if (vo.getCategory() != null) { |
|
|
|
|
try { |
|
|
|
|
R<String> dicR = dictClient.getValue("InspectionTemplate-Category", vo.getCategory()); |
|
|
|
|
if (dicR != null && dicR.getData() != null) { |
|
|
|
|
vo.setCategoryName(dicR.getData()); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("查询类别名称失败, category: {}", vo.getCategory(), e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 4. 按英文部分排序
|
|
|
|
|
result.sort((o1, o2) -> { |
|
|
|
|
String str1 = o1.getCategoryName(); |
|
|
|
|
String str2 = o2.getCategoryName(); |
|
|
|
|
|
|
|
|
|
if ("未分类".equals(str1)) return 1; |
|
|
|
|
if ("未分类".equals(str2)) return -1; |
|
|
|
|
|
|
|
|
|
String english1 = extractEnglishPrefix(str1); |
|
|
|
|
String english2 = extractEnglishPrefix(str2); |
|
|
|
|
|
|
|
|
|
if (english1 == null && english2 == null) return 0; |
|
|
|
|
if (english1 == null) return 1; |
|
|
|
|
if (english2 == null) return -1; |
|
|
|
|
|
|
|
|
|
return english1.compareTo(english2); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 辅助方法:提取英文前缀
|
|
|
|
|
private String extractEnglishPrefix(String str) { |
|
|
|
|
if (str == null) return null; |
|
|
|
|
Matcher matcher = Pattern.compile("^([A-Za-z]+)").matcher(str); |
|
|
|
|
if (matcher.find()) { |
|
|
|
|
return matcher.group(1); |
|
|
|
|
} |
|
|
|
|
return str; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|