|
@@ -71,6 +71,7 @@ import com.platform.service.util.SysFileUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.ibatis.exceptions.TooManyResultsException;
|
|
import org.apache.ibatis.exceptions.TooManyResultsException;
|
|
|
|
|
+import org.apache.ibatis.session.RowBounds;
|
|
|
import org.springframework.core.env.Environment;
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
@@ -1313,6 +1314,18 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 上次保养完成时间:取该设备最近一次已完成保养任务的实际结束时间
|
|
|
|
|
+ Weekend<CheckJob> jobWeekend = new Weekend<>(CheckJob.class);
|
|
|
|
|
+ jobWeekend.selectProperties("actualEndTime");
|
|
|
|
|
+ jobWeekend.weekendCriteria()
|
|
|
|
|
+ .andEqualTo(CheckJob::getSbId, vo.getId())
|
|
|
|
|
+ .andEqualTo(CheckJob::getType, CheckStandardTypeEnum.POLLING.getValue())
|
|
|
|
|
+ .andEqualTo(CheckJob::getStatus, CheckJobStatusEnum.FINISHED.getValue());
|
|
|
|
|
+ jobWeekend.setOrderByClause("actual_end_time DESC");
|
|
|
|
|
+ List<CheckJob> finishedJobs = checkJobMapper.selectByExampleAndRowBounds(jobWeekend, new RowBounds(0, 1));
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(finishedJobs)) {
|
|
|
|
|
+ vo.setLastMaintainFinishTime(finishedJobs.get(0).getActualEndTime());
|
|
|
|
|
+ }
|
|
|
// vo.setCurrentAuditUserName(activitiBusinessService.getCurrentAuditUserName(vo.getProcessInstanceId()));
|
|
// vo.setCurrentAuditUserName(activitiBusinessService.getCurrentAuditUserName(vo.getProcessInstanceId()));
|
|
|
return vo;
|
|
return vo;
|
|
|
}
|
|
}
|
|
@@ -1632,8 +1645,6 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String importListByAdd(MultipartFile file) {
|
|
public String importListByAdd(MultipartFile file) {
|
|
|
- int addNum = 0;
|
|
|
|
|
- List<String> modelError = new ArrayList<String>();
|
|
|
|
|
try {
|
|
try {
|
|
|
List<SbInfoVO> items = CustomExcelImportUtil.importSbInfoList(file.getInputStream());
|
|
List<SbInfoVO> items = CustomExcelImportUtil.importSbInfoList(file.getInputStream());
|
|
|
if (!CollectionUtils.isEmpty(items)) {
|
|
if (!CollectionUtils.isEmpty(items)) {
|
|
@@ -1643,8 +1654,11 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
// 用于缓存本次导入新增的生产商,避免同名重复新增
|
|
// 用于缓存本次导入新增的生产商,避免同名重复新增
|
|
|
Map<String, FirmProducer> newProducerMap = new HashMap<>();
|
|
Map<String, FirmProducer> newProducerMap = new HashMap<>();
|
|
|
List<SbPosition> positionList = sbPositionMapper.selectAll();
|
|
List<SbPosition> positionList = sbPositionMapper.selectAll();
|
|
|
|
|
+ List<SbType> typeList = sbTypeMapper.selectAll();
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+ List<String> errors = new ArrayList<>();
|
|
|
for (SbInfoVO item : items) {
|
|
for (SbInfoVO item : items) {
|
|
|
|
|
+ StringBuilder rowErr = new StringBuilder();
|
|
|
item.setUseArea(useArea);
|
|
item.setUseArea(useArea);
|
|
|
item.setUseCompany(useCompany);
|
|
item.setUseCompany(useCompany);
|
|
|
item.setUseProject(useProject);
|
|
item.setUseProject(useProject);
|
|
@@ -1652,34 +1666,31 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
item.setUseGroup(useGroup);
|
|
item.setUseGroup(useGroup);
|
|
|
item.setId(IdGeneratorUtils.getObjectId());
|
|
item.setId(IdGeneratorUtils.getObjectId());
|
|
|
|
|
|
|
|
- // 处理所属车间:将车间名称转换为车间ID(匹配不到则留空,不报错)
|
|
|
|
|
|
|
+ // 处理所属车间:填了但设备位置(t_sb_position)中匹配不到则记录错误;未填写则跳过
|
|
|
if (StringUtils.isNotBlank(item.getPositionName())) {
|
|
if (StringUtils.isNotBlank(item.getPositionName())) {
|
|
|
- log.info("导入第{}行,读取到车间名称:{}", item.getNo(), item.getPositionName());
|
|
|
|
|
boolean findPosition = false;
|
|
boolean findPosition = false;
|
|
|
for (SbPosition position : positionList) {
|
|
for (SbPosition position : positionList) {
|
|
|
if (position.getName().equalsIgnoreCase(item.getPositionName().trim())) {
|
|
if (position.getName().equalsIgnoreCase(item.getPositionName().trim())) {
|
|
|
item.setPositionId(position.getId());
|
|
item.setPositionId(position.getId());
|
|
|
- log.info("导入第{}行,匹配车间成功,车间ID:{}", item.getNo(), position.getId());
|
|
|
|
|
findPosition = true;
|
|
findPosition = true;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!findPosition) {
|
|
if (!findPosition) {
|
|
|
- log.warn("导入第{}行,系统找不到车间名称【{}】,车间ID留空", item.getNo(), item.getPositionName());
|
|
|
|
|
item.setPositionId(null);
|
|
item.setPositionId(null);
|
|
|
|
|
+ rowErr.append("所属车间【").append(item.getPositionName()).append("】在设备位置中未找到;");
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- log.warn("导入第{}行,车间名称为空,跳过车间匹配", item.getNo());
|
|
|
|
|
}
|
|
}
|
|
|
// 是否固定资产:默认为否
|
|
// 是否固定资产:默认为否
|
|
|
if (item.getIsFinancing() == null) {
|
|
if (item.getIsFinancing() == null) {
|
|
|
item.setIsFinancing(SbInfoFinancingEnum.NOT.getValue());
|
|
item.setIsFinancing(SbInfoFinancingEnum.NOT.getValue());
|
|
|
}
|
|
}
|
|
|
- boolean findSaveUser = false;
|
|
|
|
|
|
|
+ // 使用人(保管人):填了但系统中找不到则记录错误
|
|
|
if (StringUtils.isNotBlank(item.getSaveUserName())
|
|
if (StringUtils.isNotBlank(item.getSaveUserName())
|
|
|
&& !"null".equalsIgnoreCase(item.getSaveUserName())) {
|
|
&& !"null".equalsIgnoreCase(item.getSaveUserName())) {
|
|
|
|
|
+ boolean findSaveUser = false;
|
|
|
for (SysUser user : users) {
|
|
for (SysUser user : users) {
|
|
|
- if (user.getRealName().equals(item.getSaveUserName())) {
|
|
|
|
|
|
|
+ if (user.getRealName().equalsIgnoreCase(item.getSaveUserName())) {
|
|
|
item.setSaveUser(user.getUserId());
|
|
item.setSaveUser(user.getUserId());
|
|
|
item.setUseUser(user.getUserId());
|
|
item.setUseUser(user.getUserId());
|
|
|
findSaveUser = true;
|
|
findSaveUser = true;
|
|
@@ -1687,51 +1698,56 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!findSaveUser) {
|
|
if (!findSaveUser) {
|
|
|
- log.warn("新增导入,系统找不到使用人员【{}】,保管人ID留空,后续可手动关联", item.getSaveUserName());
|
|
|
|
|
item.setSaveUser(null);
|
|
item.setSaveUser(null);
|
|
|
item.setUseUser(null);
|
|
item.setUseUser(null);
|
|
|
|
|
+ rowErr.append("使用人(保管人)【").append(item.getSaveUserName()).append("】在系统中未找到;");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 维修人:填了但系统中找不到则记录错误
|
|
|
if (StringUtils.isNotBlank(item.getRepairUserName())
|
|
if (StringUtils.isNotBlank(item.getRepairUserName())
|
|
|
&& !"null".equalsIgnoreCase(item.getRepairUserName())) {
|
|
&& !"null".equalsIgnoreCase(item.getRepairUserName())) {
|
|
|
boolean findRepairUser = false;
|
|
boolean findRepairUser = false;
|
|
|
for (SysUser user : users) {
|
|
for (SysUser user : users) {
|
|
|
- if (user.getRealName().equals(item.getRepairUserName())) {
|
|
|
|
|
|
|
+ if (user.getRealName().equalsIgnoreCase(item.getRepairUserName())) {
|
|
|
item.setRepairUser(user.getUserId());
|
|
item.setRepairUser(user.getUserId());
|
|
|
findRepairUser = true;
|
|
findRepairUser = true;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!findRepairUser) {
|
|
if (!findRepairUser) {
|
|
|
- throw new BusinessException("找不到维修人员,请先添加, 名称" + item.getRepairUserName());
|
|
|
|
|
|
|
+ rowErr.append("维修人【").append(item.getRepairUserName()).append("】在系统中未找到;");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 第二维修人:填了但系统中找不到则记录错误
|
|
|
if (StringUtils.isNotBlank(item.getRepairUserNameSecond())
|
|
if (StringUtils.isNotBlank(item.getRepairUserNameSecond())
|
|
|
&& !"null".equalsIgnoreCase(item.getRepairUserNameSecond())) {
|
|
&& !"null".equalsIgnoreCase(item.getRepairUserNameSecond())) {
|
|
|
boolean findRepairUser = false;
|
|
boolean findRepairUser = false;
|
|
|
for (SysUser user : users) {
|
|
for (SysUser user : users) {
|
|
|
- if (user.getRealName().equals(item.getRepairUserNameSecond())) {
|
|
|
|
|
|
|
+ if (user.getRealName().equalsIgnoreCase(item.getRepairUserNameSecond())) {
|
|
|
item.setRepairUserSecond(user.getUserId());
|
|
item.setRepairUserSecond(user.getUserId());
|
|
|
findRepairUser = true;
|
|
findRepairUser = true;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!findRepairUser) {
|
|
if (!findRepairUser) {
|
|
|
- throw new BusinessException("找不到第二维修人员,请先添加, 名称" + item.getRepairUserNameSecond());
|
|
|
|
|
|
|
+ rowErr.append("第二维修人【").append(item.getRepairUserNameSecond()).append("】在系统中未找到;");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- List<SbType> typeList = sbTypeMapper.selectAll();
|
|
|
|
|
- boolean find = false;
|
|
|
|
|
- for (SbType type : typeList) {
|
|
|
|
|
- if (type.getName().equals(item.getTypeName())) {
|
|
|
|
|
- item.setTypeId(type.getId());
|
|
|
|
|
- find = true;
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ // 设备类型:必填,且必须能在系统中匹配到
|
|
|
|
|
+ if (StringUtils.isBlank(item.getTypeName())) {
|
|
|
|
|
+ rowErr.append("设备类型未填写;");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ boolean findType = false;
|
|
|
|
|
+ for (SbType type : typeList) {
|
|
|
|
|
+ if (type.getName().equalsIgnoreCase(item.getTypeName())) {
|
|
|
|
|
+ item.setTypeId(type.getId());
|
|
|
|
|
+ findType = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!findType) {
|
|
|
|
|
+ rowErr.append("设备类型【").append(item.getTypeName()).append("】在系统中未找到;");
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- if (!find) {
|
|
|
|
|
- throw new BusinessException("找不到设备类型,请先添加:" + item.getTypeName());
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
boolean findProdcuer = false;
|
|
boolean findProdcuer = false;
|
|
@@ -1764,8 +1780,15 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
item.setProducerId(newProducer.getId());
|
|
item.setProducerId(newProducer.getId());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (rowErr.length() > 0) {
|
|
|
|
|
+ errors.add("设备【" + item.getNo() + "】:" + rowErr);
|
|
|
|
|
+ }
|
|
|
addItems.add(item);
|
|
addItems.add(item);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!errors.isEmpty()) {
|
|
|
|
|
+ throw new BusinessException("导入失败,共发现 " + errors.size()
|
|
|
|
|
+ + " 台设备的数据有问题,请修正后重新导入:\n" + String.join("\n", errors));
|
|
|
|
|
+ }
|
|
|
if (!CollectionUtils.isEmpty(addItems)) {
|
|
if (!CollectionUtils.isEmpty(addItems)) {
|
|
|
List<SbInfo> itemsAdd = BeanConverterUtil.copyListProperties(addItems, SbInfo.class);
|
|
List<SbInfo> itemsAdd = BeanConverterUtil.copyListProperties(addItems, SbInfo.class);
|
|
|
mapper.insertListforComplex(itemsAdd);
|
|
mapper.insertListforComplex(itemsAdd);
|
|
@@ -1787,9 +1810,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String importListByUpdateALl(MultipartFile file) {
|
|
public String importListByUpdateALl(MultipartFile file) {
|
|
|
|
|
|
|
|
- int addNum = 0;
|
|
|
|
|
- List<String> modelError = new ArrayList<String>();
|
|
|
|
|
- Set<Integer> newIndexSet = new HashSet<>();
|
|
|
|
|
|
|
+ int newCount = 0;
|
|
|
try {
|
|
try {
|
|
|
List<SbInfoVO> items = CustomExcelImportUtil.importListByUpdateALl(file.getInputStream());
|
|
List<SbInfoVO> items = CustomExcelImportUtil.importListByUpdateALl(file.getInputStream());
|
|
|
if (!CollectionUtils.isEmpty(items)) {
|
|
if (!CollectionUtils.isEmpty(items)) {
|
|
@@ -1798,47 +1819,47 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
// 用于缓存本次导入新增的生产商,避免同名重复新增
|
|
// 用于缓存本次导入新增的生产商,避免同名重复新增
|
|
|
Map<String, FirmProducer> newProducerMap = new HashMap<>();
|
|
Map<String, FirmProducer> newProducerMap = new HashMap<>();
|
|
|
List<SbPosition> positionList = sbPositionMapper.selectAll();
|
|
List<SbPosition> positionList = sbPositionMapper.selectAll();
|
|
|
|
|
+ List<SbType> typeList = sbTypeMapper.selectAll();
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+ List<String> errors = new ArrayList<>();
|
|
|
|
|
+ List<SbInfo> toSave = new ArrayList<>();
|
|
|
|
|
+ List<Boolean> isNewFlags = new ArrayList<>();
|
|
|
for (SbInfoVO item : items) {
|
|
for (SbInfoVO item : items) {
|
|
|
|
|
+ StringBuilder rowErr = new StringBuilder();
|
|
|
// 通过设备编号no查找已有记录,获取ID用于更新(与新增导入保持一致,不依赖Excel中的ID列)
|
|
// 通过设备编号no查找已有记录,获取ID用于更新(与新增导入保持一致,不依赖Excel中的ID列)
|
|
|
SbInfoVO existingInfo = mapper.getByNo(item.getNo());
|
|
SbInfoVO existingInfo = mapper.getByNo(item.getNo());
|
|
|
- if (existingInfo == null) {
|
|
|
|
|
- log.info("更新导入第{}行,设备编号【{}】在系统中不存在,将新增", addNum + 1, item.getNo());
|
|
|
|
|
|
|
+ boolean isNew = (existingInfo == null);
|
|
|
|
|
+ if (isNew) {
|
|
|
item.setId(IdGeneratorUtils.getObjectId());
|
|
item.setId(IdGeneratorUtils.getObjectId());
|
|
|
item.setCreatedTime(now);
|
|
item.setCreatedTime(now);
|
|
|
item.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
|
|
item.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
|
|
|
- newIndexSet.add(addNum);
|
|
|
|
|
} else {
|
|
} else {
|
|
|
item.setId(existingInfo.getId());
|
|
item.setId(existingInfo.getId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 处理所属车间:将车间名称转换为车间ID(匹配不到则留空,不报错)
|
|
|
|
|
|
|
+ // 处理所属车间:填了但设备位置(t_sb_position)中匹配不到则记录错误;未填写则跳过
|
|
|
if (StringUtils.isNotBlank(item.getPositionName())) {
|
|
if (StringUtils.isNotBlank(item.getPositionName())) {
|
|
|
- log.info("更新导入第{}行,读取到车间名称:{}", item.getNo(), item.getPositionName());
|
|
|
|
|
boolean findPosition = false;
|
|
boolean findPosition = false;
|
|
|
for (SbPosition position : positionList) {
|
|
for (SbPosition position : positionList) {
|
|
|
if (position.getName().equalsIgnoreCase(item.getPositionName().trim())) {
|
|
if (position.getName().equalsIgnoreCase(item.getPositionName().trim())) {
|
|
|
item.setPositionId(position.getId());
|
|
item.setPositionId(position.getId());
|
|
|
- log.info("更新导入第{}行,匹配车间成功,车间ID:{}", item.getNo(), position.getId());
|
|
|
|
|
findPosition = true;
|
|
findPosition = true;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!findPosition) {
|
|
if (!findPosition) {
|
|
|
- log.warn("更新导入第{}行,系统找不到车间名称【{}】,车间ID留空", item.getNo(), item.getPositionName());
|
|
|
|
|
item.setPositionId(null);
|
|
item.setPositionId(null);
|
|
|
|
|
+ rowErr.append("所属车间【").append(item.getPositionName()).append("】在设备位置中未找到;");
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- log.warn("更新导入第{}行,车间名称为空,跳过车间匹配", item.getNo());
|
|
|
|
|
}
|
|
}
|
|
|
// 是否固定资产:默认为否
|
|
// 是否固定资产:默认为否
|
|
|
if (item.getIsFinancing() == null) {
|
|
if (item.getIsFinancing() == null) {
|
|
|
item.setIsFinancing(SbInfoFinancingEnum.NOT.getValue());
|
|
item.setIsFinancing(SbInfoFinancingEnum.NOT.getValue());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- boolean findSaveUser = false;
|
|
|
|
|
|
|
+ // 使用人(保管人):填了但系统中找不到则记录错误
|
|
|
if (StringUtils.isNotBlank(item.getSaveUserName())
|
|
if (StringUtils.isNotBlank(item.getSaveUserName())
|
|
|
&& !"null".equalsIgnoreCase(item.getSaveUserName())) {
|
|
&& !"null".equalsIgnoreCase(item.getSaveUserName())) {
|
|
|
|
|
+ boolean findSaveUser = false;
|
|
|
for (SysUser user : users) {
|
|
for (SysUser user : users) {
|
|
|
if (user.getRealName().equalsIgnoreCase(item.getSaveUserName())) {
|
|
if (user.getRealName().equalsIgnoreCase(item.getSaveUserName())) {
|
|
|
item.setSaveUser(user.getUserId());
|
|
item.setSaveUser(user.getUserId());
|
|
@@ -1848,11 +1869,12 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!findSaveUser) {
|
|
if (!findSaveUser) {
|
|
|
- log.warn("更新导入,系统找不到使用人员【{}】,保管人ID留空,后续可手动关联", item.getSaveUserName());
|
|
|
|
|
item.setSaveUser(null);
|
|
item.setSaveUser(null);
|
|
|
item.setUseUser(null);
|
|
item.setUseUser(null);
|
|
|
|
|
+ rowErr.append("使用人(保管人)【").append(item.getSaveUserName()).append("】在系统中未找到;");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 维修人:填了但系统中找不到则记录错误
|
|
|
if (StringUtils.isNotBlank(item.getRepairUserName())
|
|
if (StringUtils.isNotBlank(item.getRepairUserName())
|
|
|
&& !"null".equalsIgnoreCase(item.getRepairUserName())) {
|
|
&& !"null".equalsIgnoreCase(item.getRepairUserName())) {
|
|
|
boolean findRepairUser = false;
|
|
boolean findRepairUser = false;
|
|
@@ -1864,9 +1886,10 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!findRepairUser) {
|
|
if (!findRepairUser) {
|
|
|
- throw new BusinessException("找不到维修人员,请先添加, 名称" + item.getRepairUserName());
|
|
|
|
|
|
|
+ rowErr.append("维修人【").append(item.getRepairUserName()).append("】在系统中未找到;");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 第二维修人:填了但系统中找不到则记录错误
|
|
|
if (StringUtils.isNotBlank(item.getRepairUserNameSecond())
|
|
if (StringUtils.isNotBlank(item.getRepairUserNameSecond())
|
|
|
&& !"null".equalsIgnoreCase(item.getRepairUserNameSecond())) {
|
|
&& !"null".equalsIgnoreCase(item.getRepairUserNameSecond())) {
|
|
|
boolean findRepairUser = false;
|
|
boolean findRepairUser = false;
|
|
@@ -1878,21 +1901,24 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!findRepairUser) {
|
|
if (!findRepairUser) {
|
|
|
- throw new BusinessException("找不到第二维修人员,请先添加, 名称" + item.getRepairUserNameSecond());
|
|
|
|
|
|
|
+ rowErr.append("第二维修人【").append(item.getRepairUserNameSecond()).append("】在系统中未找到;");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- List<SbType> typeList = sbTypeMapper.selectAll();
|
|
|
|
|
- boolean find = false;
|
|
|
|
|
- for (SbType type : typeList) {
|
|
|
|
|
- if (type.getName().equalsIgnoreCase(item.getTypeName())) {
|
|
|
|
|
- item.setTypeId(type.getId());
|
|
|
|
|
- find = true;
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ // 设备类型:必填,且必须能在系统中匹配到
|
|
|
|
|
+ if (StringUtils.isBlank(item.getTypeName())) {
|
|
|
|
|
+ rowErr.append("设备类型未填写;");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ boolean findType = false;
|
|
|
|
|
+ for (SbType type : typeList) {
|
|
|
|
|
+ if (type.getName().equalsIgnoreCase(item.getTypeName())) {
|
|
|
|
|
+ item.setTypeId(type.getId());
|
|
|
|
|
+ findType = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!findType) {
|
|
|
|
|
+ rowErr.append("设备类型【").append(item.getTypeName()).append("】在系统中未找到;");
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- if (!find) {
|
|
|
|
|
- throw new BusinessException("找不到设备类型,请先添加:" + item.getTypeName());
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
boolean findProdcuer = false;
|
|
boolean findProdcuer = false;
|
|
@@ -1925,17 +1951,29 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
item.setProducerId(newProducer.getId());
|
|
item.setProducerId(newProducer.getId());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (newIndexSet.contains(addNum)) {
|
|
|
|
|
- SbInfo newItem = BeanConverterUtil.copyObjectProperties(item, SbInfo.class);
|
|
|
|
|
|
|
+ if (rowErr.length() > 0) {
|
|
|
|
|
+ errors.add("设备【" + item.getNo() + "】:" + rowErr);
|
|
|
|
|
+ }
|
|
|
|
|
+ toSave.add(BeanConverterUtil.copyObjectProperties(item, SbInfo.class));
|
|
|
|
|
+ isNewFlags.add(isNew);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 整批拦下:只要有任何一处问题,全部不入库,汇总报错(事务回滚)
|
|
|
|
|
+ if (!errors.isEmpty()) {
|
|
|
|
|
+ throw new BusinessException("导入失败,共发现 " + errors.size()
|
|
|
|
|
+ + " 台设备的数据有问题,请修正后重新导入:\n" + String.join("\n", errors));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 全部校验通过后再统一写库
|
|
|
|
|
+ for (int idx = 0; idx < toSave.size(); idx++) {
|
|
|
|
|
+ if (isNewFlags.get(idx)) {
|
|
|
List<SbInfo> singleList = new ArrayList<>();
|
|
List<SbInfo> singleList = new ArrayList<>();
|
|
|
- singleList.add(newItem);
|
|
|
|
|
|
|
+ singleList.add(toSave.get(idx));
|
|
|
mapper.insertListforComplex(singleList);
|
|
mapper.insertListforComplex(singleList);
|
|
|
|
|
+ newCount++;
|
|
|
} else {
|
|
} else {
|
|
|
- mapper.updateByPrimaryKeySelective(BeanConverterUtil.copyObjectProperties(item, SbInfo.class));
|
|
|
|
|
|
|
+ mapper.updateByPrimaryKeySelective(toSave.get(idx));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- int newCount = newIndexSet.size();
|
|
|
|
|
int updateCount = items.size() - newCount;
|
|
int updateCount = items.size() - newCount;
|
|
|
return "总计修改导入:" + items.size() + "条,更新" + updateCount + "条,新增" + newCount + "条";
|
|
return "总计修改导入:" + items.size() + "条,更新" + updateCount + "条,新增" + newCount + "条";
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|