Bläddra i källkod

提交服务商添加,文件上传接口

hxl13994548489 1 månad sedan
förälder
incheckning
bcec743bb9

+ 14 - 0
wash-car/pom.xml

@@ -118,6 +118,19 @@
             <artifactId>common</artifactId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
+        <!--Minio存储-->
+        <dependency>
+            <groupId>io.minio</groupId>
+            <artifactId>minio</artifactId>
+            <version>8.2.1</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
@@ -129,6 +142,7 @@
                 </exclusion>
             </exclusions>
         </dependency>
+
     </dependencies>
 
     <dependencyManagement>

+ 31 - 0
wash-car/src/main/java/com/example/hxds/wash/car/config/InitConfig.java

@@ -0,0 +1,31 @@
+package com.example.hxds.wash.car.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @program: xxkfz-minio
+ * @ClassName Init.java
+ * @author: wust
+ * @create: 2024-03-16 10:34
+ * @description: 项目启动初始化配置
+ **/
+@Component
+@Slf4j
+    public class InitConfig implements InitializingBean {
+
+    @Autowired
+    private MinioUtils minioUtils;
+
+
+    @Autowired
+    private MinioConfig minioConfig;
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        // 项目启动创建Bucket,不存在则进行创建
+        minioUtils.createBucket(minioConfig.getBucketName());
+    }
+}

+ 49 - 0
wash-car/src/main/java/com/example/hxds/wash/car/config/MinioConfig.java

@@ -0,0 +1,49 @@
+package com.example.hxds.wash.car.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import io.minio.MinioClient;
+
+/**
+ * @program: xxkfz-minio
+ * @ClassName MinioConfig.java
+ * @author: 公众号:小小开发者
+ * @create: 2024-03-13 10:53
+ * @description: Minio 配置类
+ **/
+@Data
+@Configuration
+public class MinioConfig {
+
+    /**
+     * 访问地址
+     */
+    @Value("${minio.endpoint}")
+    private String endpoint;
+
+    /**
+     * accessKey类似于用户ID,用于唯一标识你的账户
+     */
+    @Value("${minio.accessKey}")
+    private String accessKey;
+
+    /**
+     * secretKey是你账户的密码
+     */
+    @Value("${minio.secretKey}")
+    private String secretKey;
+
+    /**
+     * 默认存储桶
+     */
+    @Value("${minio.bucketName}")
+    private String bucketName;
+
+    @Bean
+    public MinioClient minioClient() {
+        MinioClient minioClient = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
+        return minioClient;
+    }
+}

+ 389 - 0
wash-car/src/main/java/com/example/hxds/wash/car/config/MinioUtils.java

@@ -0,0 +1,389 @@
+package com.example.hxds.wash.car.config;
+
+import io.minio.*;
+import io.minio.http.Method;
+import io.minio.messages.Bucket;
+import io.minio.messages.DeleteObject;
+import io.minio.messages.Item;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.*;
+
+/**
+ * @program: xxkfz-minio
+ * @ClassName MinioUtils.java
+ * @author: 公众号:小小开发者
+ * @create: 2024-03-13 10:55
+ * @description: MinIO操作工具类
+ **/
+@Slf4j
+@Component
+public class MinioUtils {
+
+    @Autowired
+    private MinioClient minioClient;
+
+
+    /**
+     * 启动SpringBoot容器的时候初始化Bucket
+     * 如果没有Bucket则创建
+     *
+     * @param bucketName
+     */
+    public void createBucket(String bucketName) {
+        try {
+            if (!bucketExists(bucketName)) {
+                minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
+                log.info("创建bucketName = {}完成!", bucketName);
+                return;
+            }
+            log.info("bucketName = {}已存在!策略为:{}", bucketName, getBucketPolicy(bucketName));
+        } catch (Exception e) {
+            log.error("创建bucketName = {}异常!e = {}", bucketName, e);
+        }
+    }
+
+    /**
+     * 判断Bucket是否存在,true:存在,false:不存在
+     *
+     * @param bucketName
+     * @return
+     */
+    @SneakyThrows
+    public boolean bucketExists(String bucketName) {
+        return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
+    }
+
+    /**
+     * 获得Bucket的策略
+     *
+     * @param bucketName
+     * @return
+     */
+    @SneakyThrows
+    public String getBucketPolicy(String bucketName) {
+        return minioClient.getBucketPolicy(GetBucketPolicyArgs.builder().bucket(bucketName).build());
+    }
+
+    /**
+     * 获得所有Bucket列表
+     *
+     * @return
+     */
+    @SneakyThrows
+    public List<Bucket> getAllBuckets() {
+        return minioClient.listBuckets();
+    }
+
+    /**
+     * 根据bucketName获取其相关信息
+     *
+     * @param bucketName
+     * @return
+     */
+    @SneakyThrows(Exception.class)
+    public Optional<Bucket> getBucket(String bucketName) {
+        return getAllBuckets().stream().filter(b -> b.name().equals(bucketName)).findFirst();
+    }
+
+    /**
+     * 根据bucketName删除Bucket,true:删除成功; false:删除失败,文件或已不存在
+     *
+     * @param bucketName
+     * @throws Exception
+     */
+    @SneakyThrows(Exception.class)
+    public void removeBucket(String bucketName) {
+        minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
+    }
+
+
+    /**
+     * 判断文件是否存在
+     *
+     * @param bucketName
+     * @param objectName
+     * @return
+     */
+    public boolean isObjectExist(String bucketName, String objectName) {
+        boolean exist = true;
+        try {
+            minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build());
+        } catch (Exception e) {
+            log.error("[Minio工具类]>>>> 判断文件是否存在, 异常:", e);
+            exist = false;
+        }
+        return exist;
+    }
+
+    /**
+     * 判断文件夹是否存在
+     *
+     * @param bucketName
+     * @param objectName
+     * @return
+     */
+    public boolean isFolderExist(String bucketName, String objectName) {
+        boolean exist = false;
+        try {
+            Iterable<Result<Item>> results = minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).prefix(objectName).recursive(false).build());
+            for (Result<Item> result : results) {
+                Item item = result.get();
+                if (item.isDir() && objectName.equals(item.objectName())) {
+                    exist = true;
+                }
+            }
+        } catch (Exception e) {
+            log.error("[Minio工具类]>>>> 判断文件夹是否存在,异常:", e);
+            exist = false;
+        }
+        return exist;
+    }
+
+    /**
+     * 根据文件前置查询文件
+     *
+     * @param bucketName 存储桶
+     * @param prefix     前缀
+     * @param recursive  是否使用递归查询
+     * @return MinioItem 列表
+     */
+    @SneakyThrows(Exception.class)
+    public List<Item> getAllObjectsByPrefix(String bucketName, String prefix, boolean recursive) {
+        List<Item> list = new ArrayList<>();
+        Iterable<Result<Item>> objectsIterator = minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).prefix(prefix).recursive(recursive).build());
+        if (objectsIterator != null) {
+            for (Result<Item> o : objectsIterator) {
+                Item item = o.get();
+                list.add(item);
+            }
+        }
+        return list;
+    }
+
+    /**
+     * 获取文件流
+     *
+     * @param bucketName 存储桶
+     * @param objectName 文件名
+     * @return 二进制流
+     */
+    @SneakyThrows(Exception.class)
+    public InputStream getObject(String bucketName, String objectName) {
+        return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(objectName).build());
+    }
+
+    /**
+     * 断点下载
+     *
+     * @param bucketName 存储桶
+     * @param objectName 文件名称
+     * @param offset     起始字节的位置
+     * @param length     要读取的长度
+     * @return 二进制流
+     */
+    @SneakyThrows(Exception.class)
+    public InputStream getObject(String bucketName, String objectName, long offset, long length) {
+        return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(objectName).offset(offset).length(length).build());
+    }
+
+    /**
+     * 获取路径下文件列表
+     *
+     * @param bucketName 存储桶
+     * @param prefix     文件名称
+     * @param recursive  是否递归查找,false:模拟文件夹结构查找
+     * @return 二进制流
+     */
+    public Iterable<Result<Item>> listObjects(String bucketName, String prefix, boolean recursive) {
+        return minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).prefix(prefix).recursive(recursive).build());
+    }
+
+    /**
+     * 使用MultipartFile进行文件上传
+     *
+     * @param bucketName  存储桶
+     * @param file        文件名
+     * @param objectName  对象名
+     * @param contentType 类型
+     * @return
+     */
+    @SneakyThrows(Exception.class)
+    public ObjectWriteResponse uploadFile(String bucketName, MultipartFile file, String objectName, String contentType) {
+        InputStream inputStream = file.getInputStream();
+        return minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName).contentType(contentType).stream(inputStream, inputStream.available(), -1).build());
+    }
+
+    /**
+     * 图片上传
+     *
+     * @param bucketName
+     * @param imageBase64
+     * @param imageName
+     * @return
+     */
+    public ObjectWriteResponse uploadImage(String bucketName, String imageBase64, String imageName) {
+        if (!StringUtils.isEmpty(imageBase64)) {
+            InputStream in = base64ToInputStream(imageBase64);
+            String newName = System.currentTimeMillis() + "_" + imageName + ".jpg";
+            String year = String.valueOf(new Date().getYear());
+            String month = String.valueOf(new Date().getMonth());
+            return uploadFile(bucketName, year + "/" + month + "/" + newName, in);
+
+        }
+        return null;
+    }
+
+    public static InputStream base64ToInputStream(String base64) {
+        ByteArrayInputStream stream = null;
+        try {
+            byte[] bytes = Base64.getEncoder().encode(base64.trim().getBytes());
+            stream = new ByteArrayInputStream(bytes);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return stream;
+    }
+
+
+    /**
+     * 上传本地文件
+     *
+     * @param bucketName 存储桶
+     * @param objectName 对象名称
+     * @param fileName   本地文件路径
+     * @return
+     */
+    @SneakyThrows(Exception.class)
+    public ObjectWriteResponse uploadFile(String bucketName, String objectName, String fileName) {
+        return minioClient.uploadObject(UploadObjectArgs.builder().bucket(bucketName).object(objectName).filename(fileName).build());
+    }
+
+    /**
+     * 通过流上传文件
+     *
+     * @param bucketName  存储桶
+     * @param objectName  文件对象
+     * @param inputStream 文件流
+     * @return
+     */
+    @SneakyThrows(Exception.class)
+    public ObjectWriteResponse uploadFile(String bucketName, String objectName, InputStream inputStream) {
+        return minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName).stream(inputStream, inputStream.available(), -1).build());
+    }
+
+    /**
+     * 创建文件夹或目录
+     *
+     * @param bucketName 存储桶
+     * @param objectName 目录路径
+     * @return
+     */
+    @SneakyThrows(Exception.class)
+    public ObjectWriteResponse createDir(String bucketName, String objectName) {
+        return minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName).stream(new ByteArrayInputStream(new byte[]{}), 0, -1).build());
+    }
+
+    /**
+     * 获取文件信息, 如果抛出异常则说明文件不存在
+     *
+     * @param bucketName 存储桶
+     * @param objectName 文件名称
+     * @return
+     */
+    @SneakyThrows(Exception.class)
+    public String getFileStatusInfo(String bucketName, String objectName) {
+        return minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build()).toString();
+    }
+
+    /**
+     * 拷贝文件
+     *
+     * @param bucketName    存储桶
+     * @param objectName    文件名
+     * @param srcBucketName 目标存储桶
+     * @param srcObjectName 目标文件名
+     */
+    @SneakyThrows(Exception.class)
+    public ObjectWriteResponse copyFile(String bucketName, String objectName, String srcBucketName, String srcObjectName) {
+        return minioClient.copyObject(CopyObjectArgs.builder().source(CopySource.builder().bucket(bucketName).object(objectName).build()).bucket(srcBucketName).object(srcObjectName).build());
+    }
+
+    /**
+     * 删除文件
+     *
+     * @param bucketName 存储桶
+     * @param objectName 文件名称
+     */
+    @SneakyThrows(Exception.class)
+    public void removeFile(String bucketName, String objectName) {
+        minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
+    }
+
+    /**
+     * 批量删除文件
+     *
+     * @param bucketName 存储桶
+     * @param keys       需要删除的文件列表
+     * @return
+     */
+    public void removeFiles(String bucketName, List<String> keys) {
+        List<DeleteObject> objects = new LinkedList<>();
+        keys.forEach(s -> {
+            objects.add(new DeleteObject(s));
+            try {
+                removeFile(bucketName, s);
+            } catch (Exception e) {
+                log.error("[Minio工具类]>>>> 批量删除文件,异常:", e);
+            }
+        });
+    }
+
+    /**
+     * 获取文件外链
+     *
+     * @param bucketName 存储桶
+     * @param objectName 文件名
+     * @param expires    过期时间 <=7 秒 (外链有效时间(单位:秒))
+     * @return url
+     */
+    @SneakyThrows(Exception.class)
+    public String getPresignedObjectUrl(String bucketName, String objectName, Integer expires) {
+        GetPresignedObjectUrlArgs args = GetPresignedObjectUrlArgs.builder().expiry(expires).bucket(bucketName).object(objectName).build();
+        return minioClient.getPresignedObjectUrl(args);
+    }
+
+    /**
+     * 获得文件外链
+     *
+     * @param bucketName
+     * @param objectName
+     * @return url
+     */
+    @SneakyThrows(Exception.class)
+    public String getPresignedObjectUrl(String bucketName, String objectName) {
+        GetPresignedObjectUrlArgs args = GetPresignedObjectUrlArgs.builder().bucket(bucketName).object(objectName).method(Method.GET).build();
+        return minioClient.getPresignedObjectUrl(args);
+    }
+
+    /**
+     * 将URLDecoder编码转成UTF8
+     *
+     * @param str
+     * @return
+     * @throws UnsupportedEncodingException
+     */
+    public String getUtf8ByURLDecoder(String str) throws UnsupportedEncodingException {
+        String url = str.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
+        return URLDecoder.decode(url, "UTF-8");
+    }
+}

+ 10 - 7
wash-car/src/main/java/com/example/hxds/wash/car/controller/MerchantController.java

@@ -8,6 +8,7 @@ import com.example.hxds.wash.car.db.pojo.MerchantEntity;
 import com.example.hxds.wash.car.service.MerchantService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.BeanUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -42,17 +43,18 @@ public class MerchantController {
         return R.ok().put("page", pageUtils);
     }
 
-    @PostMapping("/searchMerchantById")
-    @Operation(summary = "通过id查询商户表单")
-    public R deleteDeptByIds(@Valid @RequestBody searchMerchantByIdForm form) {
-        HashMap rows = merchantService.searchMerchantById(form.getId());
-        return R.ok().put("rows", rows);
+    @PostMapping("/searchById")
+    @Operation(summary = "通过id查看账户")
+    public R searchById(@RequestBody UpdateMerchantForm form) {
+        MerchantEntity  merchant = merchantService.searchById(form.getId());
+        return R.ok().put("rows", merchant);
     }
 
     @PostMapping("/insert")
     @Operation(summary = "添加商户")
     public R insert(@Valid @RequestBody InsertMerchantForm form) {
         MerchantEntity merchant = BeanUtil.toBean(form, MerchantEntity.class);
+        merchant.setIsDelete(0);
         int rows = merchantService.insert(merchant);
         return R.ok().put("rows", rows);
     }
@@ -60,8 +62,9 @@ public class MerchantController {
     @PostMapping("/update")
     @Operation(summary = "更新商户")
     public R update(@Valid @RequestBody UpdateMerchantForm form) {
-        MerchantEntity merchant = new MerchantEntity();
-        merchant.setId(form.getId());
+        MerchantEntity merchant = BeanUtil.toBean(form, MerchantEntity.class);
+        MerchantEntity  merchantOld = merchantService.searchById(form.getId());
+        BeanUtils.copyProperties(merchant, merchantOld);
         int rows = merchantService.update(merchant);
         return R.ok().put("rows", rows);
     }

+ 104 - 0
wash-car/src/main/java/com/example/hxds/wash/car/controller/MinioController.java

@@ -0,0 +1,104 @@
+package com.example.hxds.wash.car.controller;
+
+import com.example.hxds.wash.car.config.MinioConfig;
+import com.example.hxds.wash.car.config.MinioUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.InputStream;
+
+/**
+ * @program: xxkfz-minio
+ * @ClassName OSSController.java
+ * @author: wust
+ * @create: 2024-03-13 11:01
+ * @description:
+ **/
+@Slf4j
+@RestController
+@RequestMapping("/oss")
+public class MinioController {
+
+    @Autowired
+    private MinioUtils minioUtils;
+
+    @Autowired
+    private MinioConfig minioConfig;
+
+    /**
+     * 文件上传
+     *
+     * @param file
+     */
+    @PostMapping("/upload")
+    public String upload(@RequestParam("file") MultipartFile file) {
+        try {
+            //文件名
+            String fileName = file.getOriginalFilename();
+            String newFileName = System.currentTimeMillis() + "." + StringUtils.substringAfterLast(fileName, ".");
+            //类型
+            String contentType = file.getContentType();
+            minioUtils.uploadFile(minioConfig.getBucketName(), file, newFileName, contentType);
+            return  newFileName;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "上传失败";
+        }
+    }
+
+    /**
+     * 删除
+     *
+     * @param fileName
+     */
+    @DeleteMapping("/")
+    public void delete(@RequestParam("fileName") String fileName) {
+        minioUtils.removeFile(minioConfig.getBucketName(), fileName);
+    }
+
+    /**
+     * 获取文件信息
+     *
+     * @param fileName
+     * @return
+     */
+    @GetMapping("/info")
+    public String getFileStatusInfo(@RequestParam("fileName") String fileName) {
+        return minioUtils.getFileStatusInfo(minioConfig.getBucketName(), fileName);
+    }
+
+    /**
+     * 获取文件外链
+     *
+     * @param fileName
+     * @return
+     */
+    @GetMapping("/url")
+    public String getPresignedObjectUrl(@RequestParam("fileName") String fileName) {
+        return minioUtils.getPresignedObjectUrl(minioConfig.getBucketName(), fileName);
+    }
+
+    /**
+     * 文件下载
+     *
+     * @param fileName
+     * @param response
+     */
+    @GetMapping("/download")
+    public void download(@RequestParam("fileName") String fileName, HttpServletResponse response) {
+        try {
+            InputStream fileInputStream = minioUtils.getObject(minioConfig.getBucketName(), fileName);
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.setContentType("application/force-download");
+            response.setCharacterEncoding("UTF-8");
+            IOUtils.copy(fileInputStream, response.getOutputStream());
+        } catch (Exception e) {
+            log.error("下载失败");
+        }
+    }
+}

+ 6 - 17
wash-car/src/main/java/com/example/hxds/wash/car/controller/form/InsertMerchantForm.java

@@ -6,7 +6,6 @@ import lombok.Data;
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
-import java.util.Date;
 
 @Data
 @Schema(description = "添加商户表单")
@@ -24,23 +23,19 @@ public class InsertMerchantForm {
     @Schema(description = "商户图片")
     private String imageUrl;
 
-    @NotBlank(message = "openDate")
-    @Schema(description = "商户营业开始时间")
-    private String openDate;
-
-    @NotBlank(message = "closeDate")
-    @Schema(description = "商户营业结束时间")
-    private String closeDate;
+    @NotBlank(message = "merchHours不能为空")
+    @Schema(description = "商户营业时间")
+    private String merchHours;
 
     @NotNull(message = "rating不能为空")
     @Schema(description = "商户评分")
     private Integer rating;
 
-    @NotNull(message = "type不能为空")
+    @NotBlank(message = "type不能为空")
     @Schema(description = "商户类型")
-    private Integer type;
+    private String type;
 
-    @NotBlank(message = "mapAddress不能为空")
+    //@NotBlank(message = "mapAddress不能为空")
     @Schema(description = "地图地址")
     private String mapAddress;
 
@@ -55,11 +50,5 @@ public class InsertMerchantForm {
     @NotNull(message = "isPartner不能为空")
     @Schema(description = "是否合作商户")
     private Integer isPartner;
-    /**
-     * 0-否,1是
-     */
-    @NotNull(message = "isDelete不能为空")
-    @Schema(description = "是否删除")
-    private Integer isDelete;
 
 }

+ 6 - 11
wash-car/src/main/java/com/example/hxds/wash/car/controller/form/UpdateMerchantForm.java

@@ -6,7 +6,6 @@ import lombok.Data;
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
-import java.util.Date;
 
 @Schema(description = "更新商户表单")
 @Data
@@ -28,23 +27,19 @@ public class UpdateMerchantForm {
     @Schema(description = "商户图片")
     private String imageUrl;
 
-    @NotBlank(message = "openDate")
-    @Schema(description = "商户营业开始时间")
-    private String openDate;
-
-    @NotBlank(message = "closeDate")
-    @Schema(description = "商户营业结束时间")
-    private String closeDate;
+    @NotBlank(message = "merchHours不能为空")
+    @Schema(description = "商户营业时间")
+    private String merchHours;
 
     @NotNull(message = "rating不能为空")
     @Schema(description = "商户评分")
     private Integer rating;
 
-    @NotNull(message = "type不能为空")
+    @NotBlank(message = "type不能为空")
     @Schema(description = "商户类型")
-    private Integer type;
+    private String type;
 
-    @NotBlank(message = "mapAddress不能为空")
+    // @NotBlank(message = "mapAddress不能为空")
     @Schema(description = "地图地址")
     private String mapAddress;
 

+ 2 - 0
wash-car/src/main/java/com/example/hxds/wash/car/db/dao/MerchantDao.java

@@ -31,4 +31,6 @@ public interface MerchantDao {
 
 
     int deleteMerchantByIds(@Param("ids") List<String> ids);
+
+    MerchantEntity searchById(Integer id);
 }

+ 2 - 7
wash-car/src/main/java/com/example/hxds/wash/car/db/pojo/MerchantEntity.java

@@ -29,14 +29,9 @@ public class MerchantEntity implements Serializable {
     private String imageUrl;
 
     /**
-     *商户营业开始时间
+     *商户营业
      */
-    private Date openDate;
-
-    /**
-     *商户营业结束时间
-     */
-    private Date closeDate;
+    private String merchHours;
 
     /**
      *商户评分

+ 2 - 0
wash-car/src/main/java/com/example/hxds/wash/car/service/MerchantService.java

@@ -60,4 +60,6 @@ public interface MerchantService {
     HashMap searchMerchantById(int id);
 
     int deleteMerchantByIds(List ids);
+
+    MerchantEntity searchById(Integer id);
 }

+ 5 - 0
wash-car/src/main/java/com/example/hxds/wash/car/service/impl/MerchantServiceImpl.java

@@ -71,4 +71,9 @@ public class MerchantServiceImpl implements MerchantService {
         int rows = merchantDao.deleteMerchantByIds(ids);
         return rows;
     }
+
+    @Override
+    public MerchantEntity searchById(Integer id) {
+        return merchantDao.searchById(id);
+    }
 }

+ 9 - 4
wash-car/src/main/resources/application.yml

@@ -38,9 +38,9 @@ spring:
     type: com.alibaba.druid.pool.DruidDataSource
     druid:
       driver-class-name: com.mysql.cj.jdbc.Driver
-      url: jdbc:mysql://127.0.0.1:3306/wash_car?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
+      url: jdbc:mysql://localhost:3307/wash_car?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
       username: root
-      password: 123456
+      password: root
       initial-size: 4
       max-active: 8
       min-idle: 8
@@ -52,7 +52,7 @@ spring:
   redis:
     database: 5
     host: localhost
-    port: 16379
+    port: 6379
     password: 123456
     jedis:
       pool:
@@ -98,4 +98,9 @@ feign:
     config:
       default:
         connectTimeout: 10000
-        readTimeout: 300000
+        readTimeout: 300000
+minio:
+  endpoint: http://localhost:9001
+  accessKey: admin
+  secretKey: admin123456
+  bucketName: qcfw

+ 21 - 11
wash-car/src/main/resources/mapper/MerchantDao.xml

@@ -10,8 +10,7 @@
         name,
         address,
         image_url as imageUrl,
-        open_date as openDate,
-        close_date as closeDate,
+        merch_hours as merchHours,
         rating,
         type,
         map_address as mapAddress,
@@ -33,8 +32,7 @@
             name,
             address,
             image_url as imageUrl,
-            open_date as openDate,
-            close_date as closeDate,
+            merch_hours as merchHours,
             rating,
             type,
             map_address as mapAddress,
@@ -55,11 +53,8 @@
         <if test="imageUrl!=null">
             ,`image_url`=#{imageUrl}
         </if>
-        <if test="openDate!=null">
-            ,`open_date`=#{openDate}
-        </if>
-        <if test="closeDate!=null">
-            ,`close_date`=#{closeDate}
+        <if test="merchHours!=null">
+            ,`merch_hours`=#{merchHours}
         </if>
         <if test="rating!=null">
             ,`rating`=#{rating}
@@ -86,8 +81,7 @@
         SET name=#{name},
             address=#{address},
             image_url=#{imageUrl},
-            open_date=#{openDate},
-            close_date=#{closeDate},
+            merch_hours=#{merchHours},
             rating=#{rating},
             type=#{type},
             map_address=#{mapAddress},
@@ -138,5 +132,21 @@
     <select id="searchMerchAccountsCount" parameterType="Map" resultType="long">
         SELECT COUNT(*) FROM tb_merch_accounts AS temp
     </select>
+    <select id="searchById" resultType="com.example.hxds.wash.car.db.pojo.MerchantEntity">
+        select
+            id as id,
+            name as name,
+            address as address,
+            image_url as imageUrl,
+            merch_hours as merchHours,
+            rating as rating,
+            type as type,
+            map_address as mapAddress,
+            phone_number as phoneNumber,
+            description as description,
+            is_partner as isPartner
+        from tb_merchants
+        where `id` = #{id}
+    </select>
 
 </mapper>