Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
0a3de7088c
@ -0,0 +1,14 @@
|
|||||||
|
package com.cdzy.operations.mapper;
|
||||||
|
|
||||||
|
import com.cdzy.operations.model.entity.EbikeBikeConfiguration;
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆相关配置 映射层
|
||||||
|
*
|
||||||
|
* @author yanglei
|
||||||
|
* @since 2025-12-03 16:21
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface EbikeBikeConfigurationMapper extends BaseMapper<EbikeBikeConfiguration> {
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package com.cdzy.operations.model.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置项 实体类
|
||||||
|
*
|
||||||
|
* @author yanglei
|
||||||
|
* @since 2025-12-03 16:31
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class EbikeBikeConfigurationDto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运营商id
|
||||||
|
*/
|
||||||
|
@NotNull(message = "运营商id不能为空")
|
||||||
|
private Long operatorId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置项时长
|
||||||
|
*/
|
||||||
|
@NotNull(message = "配置项时长不能为空")
|
||||||
|
private Integer configurationDuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置项描述
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "配置项描述不能为空")
|
||||||
|
private String configurationDescription;
|
||||||
|
}
|
||||||
@ -0,0 +1,79 @@
|
|||||||
|
package com.cdzy.operations.model.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆相关配置 实体类
|
||||||
|
*
|
||||||
|
* @author yanglei
|
||||||
|
* @since 2025-12-03 16:18
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table("ebike_bike_configuration")
|
||||||
|
public class EbikeBikeConfiguration implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作主键id
|
||||||
|
*/
|
||||||
|
@Id
|
||||||
|
private Long batteryId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运营商id
|
||||||
|
*/
|
||||||
|
private Long operatorId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置项时长
|
||||||
|
*/
|
||||||
|
private Integer configurationDuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置项描述
|
||||||
|
*/
|
||||||
|
private String configurationDescription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Column(onInsertValue = "now()")
|
||||||
|
private LocalDateTime createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private Long createdBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
@Column(onUpdateValue = "now()")
|
||||||
|
private LocalDateTime updatedTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改人
|
||||||
|
*/
|
||||||
|
private Long updatedBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除与否
|
||||||
|
*/
|
||||||
|
private Boolean isDeleted;
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
package com.cdzy.operations.service;
|
||||||
|
|
||||||
|
import com.cdzy.operations.model.dto.EbikeBikeConfigurationDto;
|
||||||
|
import com.cdzy.operations.model.entity.EbikeBikeConfiguration;
|
||||||
|
import com.mybatisflex.core.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆相关配置 服务层
|
||||||
|
*
|
||||||
|
* @author yanglei
|
||||||
|
* @since 2025-12-03 16:22
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface EbikeBikeConfigurationService extends IService<EbikeBikeConfiguration> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据运营商id获取配置项(sql会自动拼接运营商id)
|
||||||
|
*
|
||||||
|
* @return 配置项
|
||||||
|
*/
|
||||||
|
List<EbikeBikeConfiguration> getConfigurationByOperationId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置项保存
|
||||||
|
*
|
||||||
|
* @param configurationDto 配置项参数
|
||||||
|
*/
|
||||||
|
void saveConfiguration(EbikeBikeConfigurationDto configurationDto);
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
package com.cdzy.operations.service.impl;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.cdzy.operations.mapper.EbikeBikeConfigurationMapper;
|
||||||
|
import com.cdzy.operations.model.dto.EbikeBikeConfigurationDto;
|
||||||
|
import com.cdzy.operations.model.entity.EbikeBikeConfiguration;
|
||||||
|
import com.cdzy.operations.service.EbikeBikeConfigurationService;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.cdzy.operations.model.entity.table.EbikeBikeConfigurationTableDef.EBIKE_BIKE_CONFIGURATION;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆相关配置 实现类
|
||||||
|
*
|
||||||
|
* @author yanglei
|
||||||
|
* @since 2025-12-03 16:22
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class EbikeBikeConfigurationServiceImpl extends ServiceImpl<EbikeBikeConfigurationMapper, EbikeBikeConfiguration> implements EbikeBikeConfigurationService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<EbikeBikeConfiguration> getConfigurationByOperationId() {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
.select(EBIKE_BIKE_CONFIGURATION.ALL_COLUMNS);
|
||||||
|
return this.mapper.selectListByQuery(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveConfiguration(EbikeBikeConfigurationDto configurationDto) {
|
||||||
|
EbikeBikeConfiguration configuration = EbikeBikeConfiguration.builder()
|
||||||
|
.operatorId(configurationDto.getOperatorId())
|
||||||
|
.configurationDuration(configurationDto.getConfigurationDuration())
|
||||||
|
.configurationDescription(configurationDto.getConfigurationDescription())
|
||||||
|
.createdBy(StpUtil.getLoginIdAsLong())
|
||||||
|
.build();
|
||||||
|
this.mapper.insert(configuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -204,63 +204,61 @@ public class EbikeFaultReportServiceImpl extends ServiceImpl<EbikeFaultReportMap
|
|||||||
.updateBy(ebikeFaultReportDto.getUserId())
|
.updateBy(ebikeFaultReportDto.getUserId())
|
||||||
.build();
|
.build();
|
||||||
this.updateById(userFaultReport);
|
this.updateById(userFaultReport);
|
||||||
List<EbikeFaultFileDto> attachmentFiles = ebikeFaultReportDto.getAttachmentFiles();
|
|
||||||
// 更新文件信息
|
|
||||||
if (!CollectionUtils.isEmpty(attachmentFiles)) {
|
|
||||||
List<EbikeFaultFile> existingFiles = ebikeAttachmentFileService.queryFiles(ebikeFaultReportDto.getReportId());
|
|
||||||
|
|
||||||
Set<Long> existingFileIds = existingFiles.stream()
|
// 文件处理
|
||||||
|
List<EbikeFaultFileDto> attachments = ebikeFaultReportDto.getAttachmentFiles();
|
||||||
|
if (!CollectionUtils.isEmpty(attachments)) {
|
||||||
|
List<EbikeFaultFile> existingFiles = ebikeAttachmentFileService.queryFiles(ebikeFaultReportDto.getReportId());
|
||||||
|
Set<Long> existingIds = existingFiles.stream()
|
||||||
.map(EbikeFaultFile::getFileId)
|
.map(EbikeFaultFile::getFileId)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 分离前端数据,无id的新增,有id的对比
|
Set<Long> incomingIds = new HashSet<>();
|
||||||
Set<Long> incomingFileIds = new HashSet<>();
|
List<EbikeFaultFile> toInsert = new ArrayList<>();
|
||||||
List<EbikeFaultFile> filesToInsert = new ArrayList<>();
|
|
||||||
|
|
||||||
for (EbikeFaultFileDto dto : attachmentFiles) {
|
for (EbikeFaultFileDto f : attachments) {
|
||||||
if (dto.getFileId() != null) {
|
if (f.getFileId() != null) {
|
||||||
incomingFileIds.add(dto.getFileId());
|
incomingIds.add(f.getFileId());
|
||||||
} else {
|
} else {
|
||||||
// fileId 为空,则是新文件,插入数据
|
toInsert.add(EbikeFaultFile.builder()
|
||||||
EbikeFaultFile newFile = EbikeFaultFile.builder()
|
|
||||||
.reportId(ebikeFaultReportDto.getReportId())
|
.reportId(ebikeFaultReportDto.getReportId())
|
||||||
.fileName(dto.getFileName())
|
.fileName(f.getFileName())
|
||||||
.fileUrl(dto.getFileUrl())
|
.fileUrl(f.getFileUrl())
|
||||||
//.createBy(userId)
|
.build());
|
||||||
.build();
|
|
||||||
filesToInsert.add(newFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对比incomingFileIds与existingFileIds的id,在existingFileIds数据库存在,但是不在incomingFileIds存在的已经被删除
|
// 删除:存在但前端没传
|
||||||
List<Long> fileIdsToDelete = existingFileIds.stream()
|
existingIds.removeAll(incomingIds);
|
||||||
.filter(id -> !incomingFileIds.contains(id))
|
if (!existingIds.isEmpty()) {
|
||||||
.collect(Collectors.toList());
|
ebikeAttachmentFileService.removeByIds(new ArrayList<>(existingIds));
|
||||||
|
|
||||||
// 根据主键id删除文件数据
|
|
||||||
if (!fileIdsToDelete.isEmpty()) {
|
|
||||||
ebikeAttachmentFileService.removeByIds(fileIdsToDelete);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插入新文件
|
// 新增
|
||||||
if (!filesToInsert.isEmpty()) {
|
if (!toInsert.isEmpty()) {
|
||||||
ebikeAttachmentFileService.saveBatch(filesToInsert);
|
ebikeAttachmentFileService.saveBatch(toInsert);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Integer> faultPart = ebikeFaultReportDto.getFaultPart();
|
|
||||||
List<Integer> existingFaultParts = ebikeFaultPartService.getFaultPartByReportId(ebikeFaultReportDto.getReportId());
|
|
||||||
|
|
||||||
// 需要删除的
|
// 故障部位处理
|
||||||
List<Integer> toDelete = existingFaultParts.stream()
|
List<Integer> newParts = ebikeFaultReportDto.getFaultPart();
|
||||||
.filter(part -> !faultPart.contains(part))
|
List<Integer> oldParts = ebikeFaultPartService.getFaultPartByReportId(ebikeFaultReportDto.getReportId());
|
||||||
|
|
||||||
|
// 删除:旧有但新数据没有的
|
||||||
|
List<Integer> toDelete = oldParts.stream()
|
||||||
|
.filter(part -> !newParts.contains(part))
|
||||||
.toList();
|
.toList();
|
||||||
|
if (!toDelete.isEmpty()) {
|
||||||
|
ebikeFaultPartService.removeByIds(toDelete);
|
||||||
|
}
|
||||||
|
|
||||||
// 需要新增的
|
// 新增:新有但旧数据没有的
|
||||||
List<Integer> toInsert = faultPart.stream()
|
List<Integer> toInsertParts = newParts.stream()
|
||||||
.filter(part -> !existingFaultParts.contains(part))
|
.filter(part -> !oldParts.contains(part))
|
||||||
.toList();
|
.toList();
|
||||||
List<EbikeFaultPart> partsToSave = toInsert.stream()
|
if (!toInsertParts.isEmpty()) {
|
||||||
|
List<EbikeFaultPart> parts = toInsertParts.stream()
|
||||||
.map(fp -> EbikeFaultPart.builder()
|
.map(fp -> EbikeFaultPart.builder()
|
||||||
.reportId(ebikeFaultReportDto.getReportId())
|
.reportId(ebikeFaultReportDto.getReportId())
|
||||||
.faultPart(fp)
|
.faultPart(fp)
|
||||||
@ -268,11 +266,7 @@ public class EbikeFaultReportServiceImpl extends ServiceImpl<EbikeFaultReportMap
|
|||||||
.createBy(ebikeFaultReportDto.getUserId())
|
.createBy(ebikeFaultReportDto.getUserId())
|
||||||
.build())
|
.build())
|
||||||
.toList();
|
.toList();
|
||||||
if (!toDelete.isEmpty()) {
|
ebikeFaultPartService.saveBatch(parts);
|
||||||
ebikeFaultPartService.removeByIds(toDelete);
|
|
||||||
}
|
|
||||||
if (!partsToSave.isEmpty()) {
|
|
||||||
ebikeFaultPartService.saveBatch(partsToSave);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user