package com.ruoyi.basic.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.basic.constant.EipCableTypeConstants;
|
import com.ruoyi.basic.dto.EipCableQueryDto;
|
import com.ruoyi.basic.mapper.EipCableTestDataMapper;
|
import com.ruoyi.basic.pojo.EipCableTestData;
|
import com.ruoyi.basic.service.EipCableService;
|
import com.ruoyi.common.utils.SecurityUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* EIP 线缆对接 Service 实现
|
*/
|
@Service
|
public class EipCableServiceImpl implements EipCableService {
|
|
@Resource
|
private EipCableTestDataMapper eipCableTestDataMapper;
|
|
@Override
|
public IPage<EipCableTestData> pageByCableType(long pageNum, long pageSize, String cableType, EipCableQueryDto query) {
|
validateCableType(cableType);
|
Page<EipCableTestData> page = new Page<>(pageNum, pageSize);
|
LambdaQueryWrapper<EipCableTestData> wrapper = new LambdaQueryWrapper<>();
|
wrapper.eq(EipCableTestData::getCableType, cableType)
|
.like(query.getSampleCode() != null && !query.getSampleCode().trim().isEmpty(),
|
EipCableTestData::getSampleCode, query.getSampleCode())
|
.like(query.getTestType() != null && !query.getTestType().trim().isEmpty(),
|
EipCableTestData::getTestType, query.getTestType())
|
.eq(query.getTestDate() != null, EipCableTestData::getTestDate, query.getTestDate())
|
.orderByDesc(EipCableTestData::getTestDate)
|
.orderByDesc(EipCableTestData::getId);
|
return eipCableTestDataMapper.selectPage(page, wrapper);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public int syncCableData(String cableType) {
|
validateCableType(cableType);
|
String username = resolveUsername();
|
LocalDateTime now = LocalDateTime.now();
|
String batchNo = "EIP" + now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
List<EipCableTestData> dataList = buildDemoData(cableType, batchNo, username, now);
|
int count = 0;
|
for (EipCableTestData data : dataList) {
|
count += eipCableTestDataMapper.insert(data);
|
}
|
return count;
|
}
|
|
private List<EipCableTestData> buildDemoData(String cableType, String batchNo, String username, LocalDateTime now) {
|
String cableTypeName = EipCableTypeConstants.getTypeName(cableType);
|
List<EipCableTestData> list = new ArrayList<>();
|
list.add(buildData(cableType, cableTypeName, batchNo, username, now, 1,
|
"原材料导体电阻试验", "合格", "铜导体原材料批次A", "导体绞合过程抽检", "成品出厂例行检验"));
|
list.add(buildData(cableType, cableTypeName, batchNo, username, now, 2,
|
"原材料绝缘厚度检测", "合格", "绝缘料批次B", "绝缘挤出过程抽检", "成品耐压检验"));
|
list.add(buildData(cableType, cableTypeName, batchNo, username, now, 3,
|
"过程耐压试验", "合格", "护套料批次C", "成缆过程巡检", "成品结构尺寸检验"));
|
list.add(buildData(cableType, cableTypeName, batchNo, username, now, 4,
|
"老化性能试验", "合格", "屏蔽材料批次D", "火花试验过程检", "成品老化性能检验"));
|
list.add(buildData(cableType, cableTypeName, batchNo, username, now, 5,
|
"成品例行试验", "合格", "辅材批次E", "包装前终检", "成品例行放行检验"));
|
return list;
|
}
|
|
private EipCableTestData buildData(String cableType, String cableTypeName, String batchNo, String username,
|
LocalDateTime now, int index, String testType, String testResult,
|
String rawMaterial, String processInspection, String finalInspection) {
|
EipCableTestData data = new EipCableTestData();
|
data.setCableType(cableType);
|
data.setCableTypeName(cableTypeName);
|
data.setSampleCode(cableType.toUpperCase() + "-" + now.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + "-" + index);
|
data.setProductName(cableTypeName + "样品" + index);
|
data.setSpecModel("ZC-" + (10 + index) + "kV-" + index + "*120");
|
data.setTestType(testType);
|
data.setTestResult(testResult);
|
data.setRawMaterial(rawMaterial);
|
data.setProcessInspection(processInspection);
|
data.setFinalInspection(finalInspection);
|
data.setTestDate(LocalDate.now().minusDays(index - 1L));
|
data.setSourceSystem("国网线缆类物联试验平台(模拟)");
|
data.setSyncBatchNo(batchNo);
|
data.setSyncStatus(1);
|
data.setRemark("模拟同步数据,用于前端联调");
|
data.setCreateBy(username);
|
data.setUpdateBy(username);
|
data.setCreateTime(now);
|
data.setUpdateTime(now);
|
return data;
|
}
|
|
private void validateCableType(String cableType) {
|
if (!EipCableTypeConstants.allTypes().contains(cableType)) {
|
throw new RuntimeException("不支持的线缆类型: " + cableType);
|
}
|
}
|
|
private String resolveUsername() {
|
try {
|
String username = SecurityUtils.getUsername();
|
return username == null || username.trim().isEmpty() ? "system" : username;
|
} catch (Exception e) {
|
return "system";
|
}
|
}
|
}
|