diff --git a/ebike-gateway/src/main/resources/application-dev.yml b/ebike-gateway/src/main/resources/application-dev.yml index 6b4665f..d76ee81 100644 --- a/ebike-gateway/src/main/resources/application-dev.yml +++ b/ebike-gateway/src/main/resources/application-dev.yml @@ -3,6 +3,11 @@ server: spring: application: name: ebike-gateway + servlet: + multipart: + max-file-size: 30MB + max-request-size: 100MB + file-size-threshold: 0B jackson: serialization: write-dates-as-timestamps: false diff --git a/ebike-operations/src/main/resources/application-dev.yml b/ebike-operations/src/main/resources/application-dev.yml index 83093d7..93e99c8 100644 --- a/ebike-operations/src/main/resources/application-dev.yml +++ b/ebike-operations/src/main/resources/application-dev.yml @@ -3,6 +3,11 @@ server: spring: application: name: ebike-operations + servlet: + multipart: + max-file-size: 30MB + max-request-size: 100MB + file-size-threshold: 0B cloud: nacos: server-addr: 127.0.0.1:8848 # nacos diff --git a/ebike-payment/src/main/resources/application-dev.yml b/ebike-payment/src/main/resources/application-dev.yml index 4cad44e..82f5274 100644 --- a/ebike-payment/src/main/resources/application-dev.yml +++ b/ebike-payment/src/main/resources/application-dev.yml @@ -3,6 +3,11 @@ server: spring: application: name: ebike-payment + servlet: + multipart: + max-file-size: 30MB + max-request-size: 100MB + file-size-threshold: 0B cloud: nacos: server-addr: 127.0.0.1:8848 # nacos diff --git a/ebike-staff/src/main/java/com/cdzy/staff/controller/EbikeImgController.java b/ebike-staff/src/main/java/com/cdzy/staff/controller/EbikeImgController.java index 8916ac0..570bef1 100644 --- a/ebike-staff/src/main/java/com/cdzy/staff/controller/EbikeImgController.java +++ b/ebike-staff/src/main/java/com/cdzy/staff/controller/EbikeImgController.java @@ -7,6 +7,8 @@ import com.cdzy.common.model.response.JsonResult; import com.cdzy.staff.model.entity.EbikeImg; import com.cdzy.staff.service.EbikeImgService; import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.query.QueryWrapper; +import io.netty.util.internal.StringUtil; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -14,6 +16,8 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; +import static com.cdzy.staff.model.entity.table.EbikeImgTableDef.EBIKE_IMG; + /** * 图片表 控制层。 * @@ -36,6 +40,8 @@ public class EbikeImgController { @PostMapping("save") public JsonResult save(@RequestBody @Validated EbikeImg ebikeImg) { ebikeImg.setCreatedBy(StpUtil.getLoginIdAsLong()); + String nameWithoutExtension = StringUtil.substringBefore(ebikeImg.getFileUrl(), '.'); + ebikeImg.setImgCode(nameWithoutExtension); ebikeImgService.save(ebikeImg); return JsonResult.success(); } @@ -82,8 +88,10 @@ public class EbikeImgController { * @return 分页对象 */ @GetMapping("page") - public JsonResult> page(PageParam pageParam) { - Page page = ebikeImgService.page(pageParam.getPage()); + public JsonResult> page(PageParam pageParam,String imgName) { + QueryWrapper queryWrapper = QueryWrapper.create() + .where(EBIKE_IMG.IMG_NAME.like(imgName,StringUtil.isNullOrEmpty(imgName))); + Page page = ebikeImgService.page(pageParam.getPage(),queryWrapper); return JsonResult.success(page); } @@ -95,8 +103,8 @@ public class EbikeImgController { * @return 操作结果 */ @PostMapping("upload") - public JsonResult upload(@RequestParam("file") MultipartFile file) throws Exception { - String result = ebikeImgService.upload(file); + public JsonResult upload(@RequestParam("file") MultipartFile file,String imgCode) throws Exception { + String result = ebikeImgService.upload(file,imgCode); return JsonResult.success(Message.SUCCESS, result); } diff --git a/ebike-staff/src/main/java/com/cdzy/staff/model/entity/EbikeImg.java b/ebike-staff/src/main/java/com/cdzy/staff/model/entity/EbikeImg.java index b1616ad..f821530 100644 --- a/ebike-staff/src/main/java/com/cdzy/staff/model/entity/EbikeImg.java +++ b/ebike-staff/src/main/java/com/cdzy/staff/model/entity/EbikeImg.java @@ -41,7 +41,6 @@ public class EbikeImg implements Serializable { /** * 唯一分区编码 */ - @NotNull(message = "图片标识不能为空") private String imgCode; @Column(onInsertValue = "now()") diff --git a/ebike-staff/src/main/java/com/cdzy/staff/service/EbikeImgService.java b/ebike-staff/src/main/java/com/cdzy/staff/service/EbikeImgService.java index 322f45a..29dd576 100644 --- a/ebike-staff/src/main/java/com/cdzy/staff/service/EbikeImgService.java +++ b/ebike-staff/src/main/java/com/cdzy/staff/service/EbikeImgService.java @@ -17,5 +17,5 @@ public interface EbikeImgService extends IService { * @param file 文件 * @return 路径 */ - String upload(MultipartFile file) throws Exception; + String upload(MultipartFile file,String imgCode) throws Exception; } diff --git a/ebike-staff/src/main/java/com/cdzy/staff/service/impl/EbikeImgServiceImpl.java b/ebike-staff/src/main/java/com/cdzy/staff/service/impl/EbikeImgServiceImpl.java index 99ba1eb..e278dbf 100644 --- a/ebike-staff/src/main/java/com/cdzy/staff/service/impl/EbikeImgServiceImpl.java +++ b/ebike-staff/src/main/java/com/cdzy/staff/service/impl/EbikeImgServiceImpl.java @@ -5,6 +5,7 @@ import com.cdzy.staff.mapper.EbikeImgMapper; import com.cdzy.staff.model.entity.EbikeImg; import com.cdzy.staff.service.EbikeImgService; import com.cdzy.staff.utils.MinioUtil; +import com.mybatisflex.core.util.StringUtil; import com.mybatisflex.spring.service.impl.ServiceImpl; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; @@ -28,9 +29,10 @@ public class EbikeImgServiceImpl extends ServiceImpl MinioUtil minioUtil; @Override - public String upload(MultipartFile file) throws Exception { - String objectName = imageUrl + UUID.randomUUID().toString().replace("-", "") + "." + FileNameUtil.extName(file.getOriginalFilename()); + public String upload(MultipartFile file,String imgCode) throws Exception { + String result = StringUtil.hasText(imgCode) ?imgCode:UUID.randomUUID().toString().replace("-", "") + "." + FileNameUtil.extName(file.getOriginalFilename()); + String objectName = imageUrl + result; minioUtil.uploadFile(file.getInputStream(), objectName); - return minioUtil.getShowUrl(objectName); + return result; } } diff --git a/ebike-staff/src/main/resources/application-dev.yml b/ebike-staff/src/main/resources/application-dev.yml index 9040a4e..954c8e3 100644 --- a/ebike-staff/src/main/resources/application-dev.yml +++ b/ebike-staff/src/main/resources/application-dev.yml @@ -3,6 +3,11 @@ server: spring: application: name: ebike-staff + servlet: + multipart: + max-file-size: 30MB + max-request-size: 100MB + file-size-threshold: 0B cloud: nacos: server-addr: 127.0.0.1:8848 # nacos diff --git a/ebike-user/src/main/resources/application-dev.yml b/ebike-user/src/main/resources/application-dev.yml index 6423749..23507fe 100644 --- a/ebike-user/src/main/resources/application-dev.yml +++ b/ebike-user/src/main/resources/application-dev.yml @@ -1,6 +1,11 @@ server: port: 10014 spring: + servlet: + multipart: + max-file-size: 30MB + max-request-size: 100MB + file-size-threshold: 0B application: name: ebike-user cloud: