Browse Source

2025/8/7

master
Aoi_Tori 5 months ago
parent
commit
8618e44de3
  1. 4
      src/main/java/com/spring/modules/part/controller/PartInformationController.java
  2. 2
      src/main/java/com/spring/modules/part/service/PartInformationService.java
  3. 74
      src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java

4
src/main/java/com/spring/modules/part/controller/PartInformationController.java

@ -749,8 +749,8 @@ public class PartInformationController {
*/
@PostMapping("/readPartFromFile")
public R readPartFromFile(@RequestParam("file") MultipartFile file, @ModelAttribute GetParamInData data, @RequestParam("searchType") String searchType,
@RequestParam("partNos") String partNos, @RequestParam("limit") int limit, @RequestParam("page") int page){
PageUtils list = partInformationService.readPartFromFile(file, data, searchType, partNos, limit, page);
@RequestParam("partNos") String partNos){
PageUtils list = partInformationService.readPartFromFile(file, data, searchType, partNos);
return R.ok().put("rows", list);
}

2
src/main/java/com/spring/modules/part/service/PartInformationService.java

@ -170,5 +170,5 @@ public interface PartInformationService {
void deleteProjectPart(PlmProjectPartData data);
PageUtils readPartFromFile(MultipartFile file, GetParamInData data, String searchType, String partNos, int limit, int page);
PageUtils readPartFromFile(MultipartFile file, GetParamInData data, String searchType, String partNos);
}

74
src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java

@ -23,6 +23,7 @@ import com.spring.modules.Tooling.mapper.ProjectToolingApplyMapper;
import com.spring.modules.Tooling.service.ProjectToolingApplyService;
import com.spring.modules.app.entity.UserEntity;
import com.spring.modules.app.service.UserService;
import com.spring.modules.base.dao.BaseMapper;
import com.spring.modules.base.data.*;
import com.spring.modules.base.entity.Bu;
import com.spring.modules.base.service.TransNoControlService;
@ -192,6 +193,9 @@ public class PartInformationServiceImpl extends ServiceImpl<PartInformationMappe
@Autowired
private TechnicalSpecificationMapper technicalSpecificationMapper;
@Autowired
private BaseMapper baseMapper1;
@Value("${sys-file.file-path}")
private String filePath;
@ -4395,12 +4399,30 @@ public class PartInformationServiceImpl extends ServiceImpl<PartInformationMappe
}
@Override
public PageUtils readPartFromFile(MultipartFile file, GetParamInData data, String searchType, String partNos, int limit, int page) {
public PageUtils readPartFromFile(MultipartFile file, GetParamInData data, String searchType, String partNos) {
int limit, page;
page = 1;
boolean flag = true;
List<String> exceptionList = new ArrayList<>();
List<Integer> emptyPartNoRows = new ArrayList<>();
List<Integer> repeatPartNoRows = new ArrayList<>();
List<Integer> wrongBuNoRows = new ArrayList<>();
List<String> wrongIfsPartNos = new ArrayList<>();
List<PlmProjectPartData> partList = new ArrayList<>();
BuData buData = new BuData();
buData.setSite(data.getOrderRef1());
buData.setActive("Y");
List<BuData> buList = baseMapper1.getBUList(buData);
Map<String,String> buMap = new HashMap();
buList.forEach(bu -> {
buMap.put(bu.getBuNo(),bu.getBuDesc());
});
HashMap<String, Integer> ifsPartNoMap = new HashMap<>();
try (InputStream is = file.getInputStream();
XSSFWorkbook workbook = new XSSFWorkbook(is)) {
XSSFSheet sheet = workbook.getSheetAt(0);
limit = sheet.getLastRowNum();
Set<String> partNoSet = new HashSet<>();
Set<String> partNoSet1 = new HashSet<>();
@ -4409,20 +4431,32 @@ public class PartInformationServiceImpl extends ServiceImpl<PartInformationMappe
XSSFRow row = sheet.getRow(j);
if (row == null || isEmptyRow(row)) continue;
PlmProjectPartData part = new PlmProjectPartData();
// 检验ifs物料编码
part.setFinalPartNo(getStringCellValue(row, 0));
if (part.getFinalPartNo()==null|| part.getFinalPartNo().isEmpty()){
continue;
flag = false;
emptyPartNoRows.add(j);
}
if (j <= 2000) {
if (!partNoSet.add(part.getFinalPartNo())) {
throw new RuntimeException("第" + j + "行出现重复料号");
flag = false;
repeatPartNoRows.add(j);
}
} else {
if (!partNoSet1.add(part.getFinalPartNo())) {
throw new RuntimeException("第" + j + "行出现重复料号");
flag = false;
repeatPartNoRows.add(j);
}
}
ifsPartNoMap.put(part.getFinalPartNo(), j);
part.setBuNo(getStringCellValue(row, 1));
// 检验BU
if (part.getBuNo()!=null&&!part.getBuNo().isEmpty()){
if(buMap.get(part.getBuNo())==null||buMap.get(part.getBuNo()).isEmpty()){
flag = false;
wrongBuNoRows.add(j);
}
}
part.setCustomerPartNo(getStringCellValue(row, 2));
part.setSite(data.getOrderRef1());
part.setProjectId(data.getOrderRef2());
@ -4437,19 +4471,45 @@ public class PartInformationServiceImpl extends ServiceImpl<PartInformationMappe
} catch (Exception e) {
throw new RuntimeException("导入失败: " + e.getMessage(), e);
}
IPage<PartInformationVo> list = new Page<PartInformationVo>(page, limit);
List<PartInformationVo> list1 = new ArrayList<>();
for (PlmProjectPartData part : partList) {
List list2 = getProjectPartList1(part).getList();
if (list2.isEmpty()) continue;
if (list2.isEmpty()) {
wrongIfsPartNos.add(part.getFinalPartNo());
continue;
}
Object item = list2.get(0);
PartInformationVo vo = (PartInformationVo)item;
vo.setCustomerPartNo(part.getCustomerPartNo());
vo.setBuNo(part.getBuNo());
vo.setBuDesc(buMap.get(part.getBuNo()));
vo.setCustomerPartNo(part.getCustomerPartNo());
list1.add(vo);
}
if (flag){
IPage<PartInformationVo> list = new Page<PartInformationVo>(page, limit);
list.setRecords(list1);
return new PageUtils(list);
}else {
IPage<String> list = new Page<String>(page, 4 *limit);
if (emptyPartNoRows.size()>0){
String emptyPartNoRowsStr = "第" + emptyPartNoRows.stream().map(Object::toString).collect(Collectors.joining(",")) + "行料号为空!";
exceptionList.add(emptyPartNoRowsStr);
}
if (repeatPartNoRows.size()>0){
String repeatPartNoRowsStr = "第" + repeatPartNoRows.stream().map(Object::toString).collect(Collectors.joining(",")) + "行出现重复料号!";
exceptionList.add(repeatPartNoRowsStr);
}
if (wrongBuNoRows.size()>0){
String wrongBuNoRowsStr = "第" + wrongBuNoRows.stream().map(Object::toString).collect(Collectors.joining(",")) + "行数据的BU在系统中不存在!";
exceptionList.add(wrongBuNoRowsStr);
}
if (wrongIfsPartNos.size()>0){
String wrongIfsPartNosStr = "系统中不存在以下ifs物料编码:" + wrongIfsPartNos.stream().map(Object::toString).collect(Collectors.joining(",")) + "!";
exceptionList.add(wrongIfsPartNosStr);
}
list.setRecords(exceptionList);
return new PageUtils(list);
}
}
// 检查行是否为空的方法

Loading…
Cancel
Save