diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/SyncFileController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/SyncFileController.java new file mode 100644 index 0000000..338be66 --- /dev/null +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/SyncFileController.java @@ -0,0 +1,82 @@ +package com.mcwl.web.controller.resource; + +import com.mcwl.common.core.domain.R; +import com.mcwl.resource.domain.SyncFile; +import com.mcwl.resource.service.impl.SyncFileServiceImpl; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * comfyui文件加密同步表 + * + * @author DaiZibo + * @date 2025/6/10 + * @apiNote + */ + +@RestController +@RequestMapping("/SyncFile") +@RequiredArgsConstructor +@Api(tags = "comfyui文件加密同步表") +public class SyncFileController { + + + @Autowired + private SyncFileServiceImpl syncFileService; + + @ApiOperation(value = "查看列表") + @PostMapping("/list") + public R> syncFileList() { + + List syncFileList = syncFileService.syncFileList(); + + return R.ok(syncFileList); + } + + + @ApiOperation(value = "新增版本数据") + @PostMapping("/insert") + public R syncFileInsert(@RequestBody SyncFile syncFile) { + + syncFileService.syncFileInsert(syncFile); + + return R.ok(); + } + + + @ApiOperation(value = "根据ID删除数据") + @GetMapping("/delete") + public R syncFileDelete(@RequestParam Long id) { + + syncFileService.syncFileDelete(id); + + return R.ok(); + } + + @ApiOperation(value = "修改数据") + @PostMapping("/update") + public R syncFileUpdate(@RequestBody SyncFile syncFile) { + + syncFileService.syncFileUpdate(syncFile); + + return R.ok(); + } + + @ApiOperation(value = "根据发布时间查询") + @PostMapping("/selectByTime") + public R selectByTime(@RequestBody SyncFile syncFile) { + + return syncFileService.selectByTime(syncFile); + + } + + + + + +} diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsUtils.java b/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsUtils.java index be8bf80..95f14de 100644 --- a/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsUtils.java +++ b/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsUtils.java @@ -14,9 +14,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.time.LocalDateTime; +import java.util.Date; import java.util.HashMap; import java.util.Map; -import java.util.UUID; /** * 华为云obs上传文件工具类 @@ -44,9 +44,10 @@ public class ObsUtils { try { InputStream inputStream = multipartFile.getInputStream(); - String uuid = UUID.randomUUID().toString(); - String ossDefaultPath = getOssDefaultPath(multipartFile.getOriginalFilename(),uuid); - PutObjectResult putObjectResult = obsClient.putObject(bucketName, ossDefaultPath, inputStream); +// String uuid = UUID.randomUUID().toString(); +// String ossDefaultPath = getOssDefaultPath(multipartFile.getOriginalFilename(),uuid); + + PutObjectResult putObjectResult = obsClient.putObject(bucketName, new Date().getTime()+"", inputStream); inputStream.close(); map.put("path",putObjectResult.getObjectUrl()); map.put("objectKey",putObjectResult.getObjectKey()); diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/SyncFile.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/SyncFile.java new file mode 100644 index 0000000..d045fd6 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/SyncFile.java @@ -0,0 +1,56 @@ +package com.mcwl.resource.domain; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * 同步comfyui加密文件表 + * + * @author DaiZibo + * @date 2025/6/10 + * @apiNote + */ + + +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Data +@ApiModel(description = "同步comfyui加密文件表") +@TableName("sync_file") +public class SyncFile { + + @TableId + @ApiModelProperty(value = "主键ID") + private Long id; + + @ApiModelProperty(value = "版本") + private String version; + + @ApiModelProperty(value = "起止时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date startTime; + + @ApiModelProperty(value = "终止时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endTime; + + @ApiModelProperty(value = "代码段") + private String pyCode; + + @ApiModelProperty(value = "文件地址(多个使用,拼接)") + private String filePath; + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/SyncFileMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/SyncFileMapper.java new file mode 100644 index 0000000..596847e --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/SyncFileMapper.java @@ -0,0 +1,20 @@ +package com.mcwl.resource.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mcwl.resource.domain.SyncFile; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author DaiZibo + * @date 2025/6/10 + * @apiNote + */ + +@Mapper +public interface SyncFileMapper extends BaseMapper { + SyncFile selectByTime(SyncFile syncFile); + + SyncFile selectOrderBy(); + + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/SyncFileService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/SyncFileService.java new file mode 100644 index 0000000..4593588 --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/SyncFileService.java @@ -0,0 +1,24 @@ +package com.mcwl.resource.service; + +import com.mcwl.common.core.domain.R; +import com.mcwl.resource.domain.SyncFile; + +import java.util.List; + +/** + * @author DaiZibo + * @date 2025/6/10 + * @apiNote + */ + +public interface SyncFileService { + List syncFileList(); + + void syncFileInsert(SyncFile syncFile); + + void syncFileDelete(Long id); + + void syncFileUpdate(SyncFile syncFile); + + R selectByTime(SyncFile syncFile); +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SyncFileServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SyncFileServiceImpl.java new file mode 100644 index 0000000..999e6bc --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SyncFileServiceImpl.java @@ -0,0 +1,117 @@ +package com.mcwl.resource.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.mcwl.common.constant.HttpStatus; +import com.mcwl.common.core.domain.R; +import com.mcwl.resource.domain.SyncFile; +import com.mcwl.resource.mapper.SyncFileMapper; +import com.mcwl.resource.service.SyncFileService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * comfyui文件同步表 + * @author DaiZibo + * @date 2025/6/10 + * @apiNote + */ + +@Service +public class SyncFileServiceImpl implements SyncFileService { + + @Autowired + private SyncFileMapper syncFileMapper; + + + @Override + public List syncFileList() { + + LambdaQueryWrapper syncFileLambdaQueryWrapper = new LambdaQueryWrapper<>(); + syncFileLambdaQueryWrapper.orderByDesc(SyncFile::getId); + return syncFileMapper.selectList(syncFileLambdaQueryWrapper); + } + + @Override + public void syncFileInsert(SyncFile syncFile) { + + syncFileMapper.insert(syncFile); + } + + @Override + public void syncFileDelete(Long id) { + + syncFileMapper.deleteById(id); + } + + @Override + public void syncFileUpdate(SyncFile syncFile) { + + syncFileMapper.updateById(syncFile); + } + + @Override + public R selectByTime(SyncFile syncFile) { + + //查找指定时间 + SyncFile syncFile1 = syncFileMapper.selectByTime(syncFile); + + //找到指定版本直接返回 + if (syncFile1 != null){ + return R.ok(syncFile1); + } + + //找不到版本判断最新版本 + SyncFile syncFile2 = syncFileMapper.selectOrderBy(); + if (syncFile2.getEndTime() != null){ + + //直接校验是否包含时间 + boolean timeInRange = isTimeInRange(syncFile.getStartTime(), syncFile2.getStartTime(), syncFile2.getEndTime()); + if (timeInRange){ + + return R.ok(syncFile2); + } + }else { + + //校验当前时间 + boolean timeInRange = isTimeInRange(syncFile.getStartTime(), syncFile2.getStartTime(), new Date()); + if (timeInRange){ + + return R.ok(syncFile2); + } + } + + return R.fail(HttpStatus.SHOW_ERROR_MSG,"未找到版本,请检查发布时间是否正确"); + } + + + /** + * 判断时间是否在 [startTime, endTime] 闭区间内(包含边界) + * @param time 待校验的时间 + * @param startTime 区间开始时间 + * @param endTime 区间结束时间 + * @return true:时间在区间内;false:时间不在区间内 或 参数无效 + */ + public static boolean isTimeInRange(Date time, Date startTime, Date endTime) { + // 空值校验(任意参数为 null 时返回 false) + if (time == null || startTime == null || endTime == null) { + return false; + } + + // 转换为时间戳(毫秒级) + long timeMillis = time.getTime(); + long startMillis = startTime.getTime(); + long endMillis = endTime.getTime(); + + // 校验时间区间有效性(开始时间不能晚于结束时间) + if (startMillis > endMillis) { + return false; + } + + // 判断时间是否在 [startMillis, endMillis] 闭区间内 + return timeMillis >= startMillis && timeMillis <= endMillis; + } + +} diff --git a/mcwl-resource/src/main/resources/mapper/resource/SyncFileMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/SyncFileMapper.xml new file mode 100644 index 0000000..ba618e7 --- /dev/null +++ b/mcwl-resource/src/main/resources/mapper/resource/SyncFileMapper.xml @@ -0,0 +1,18 @@ + + + + + + + +