1. 添加minio服务
2. 添加订单状态MQTT测试案例 3. 添加换电步骤MQTT测试案例 4. 添加小程序协议和小程序轮播图实体 5. 添加minio上传和删除
This commit is contained in:
parent
dda394c898
commit
0eb4df7cf9
@ -0,0 +1,69 @@
|
|||||||
|
package com.evotech.hd.common.core.entity.resource;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zrb
|
||||||
|
* @since 2024-12-21
|
||||||
|
*/
|
||||||
|
@TableName("yt_setting_wechat_agreement")
|
||||||
|
@Schema(name = "微信协议")
|
||||||
|
@Data
|
||||||
|
public class WechatAgreement implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(value = "pk_id", type = IdType.AUTO)
|
||||||
|
@Schema(hidden = true)
|
||||||
|
private Integer pkId;
|
||||||
|
|
||||||
|
private String appid;
|
||||||
|
|
||||||
|
@Schema(description = "类型:1-服务条款,2-隐私协议", requiredMode = RequiredMode.REQUIRED)
|
||||||
|
@NotNull
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@Schema(description = "标题", requiredMode = RequiredMode.REQUIRED)
|
||||||
|
@NotBlank
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Schema(description = "协议内容", requiredMode = RequiredMode.REQUIRED)
|
||||||
|
@NotBlank
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Schema(description = "版本")
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
@Schema(description = "状态:1-可用,0-不可用")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "创建人", hidden = true)
|
||||||
|
private String creater;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", hidden = true)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
|
||||||
|
private Date ctime;
|
||||||
|
|
||||||
|
@Schema(description = "更新人", hidden = true)
|
||||||
|
private String updater;
|
||||||
|
|
||||||
|
@Schema(description = "更新时间", hidden = true)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
|
||||||
|
private Date uptime;
|
||||||
|
}
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
package com.evotech.hd.common.core.entity.resource;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zrb
|
||||||
|
* @since 2024-12-21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("yt_setting_wechat_swiper")
|
||||||
|
@Schema(name = "微信轮播图设置")
|
||||||
|
public class WechatSwiper implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(value = "pk_id", type = IdType.AUTO)
|
||||||
|
@Schema(hidden = true)
|
||||||
|
private Integer pkId;
|
||||||
|
|
||||||
|
private String appid;
|
||||||
|
|
||||||
|
@Schema(description = "类型:1-logo,2-轮播图")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@Schema(description = "名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "图片地址")
|
||||||
|
private String picUrl;
|
||||||
|
|
||||||
|
@Schema(description = "排序")
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
@Schema(description = "链接标识")
|
||||||
|
private Integer linkFlag;
|
||||||
|
|
||||||
|
@Schema(description = "外链地址")
|
||||||
|
private String outLinks;
|
||||||
|
|
||||||
|
@Schema(description = "状态:1-可用,0-不可用")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "创建人", hidden = true)
|
||||||
|
private String creater;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", hidden = true)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
|
||||||
|
private Date ctime;
|
||||||
|
|
||||||
|
@Schema(description = "更新人", hidden = true)
|
||||||
|
private String updater;
|
||||||
|
|
||||||
|
@Schema(description = "更新时间", hidden = true)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
|
||||||
|
private Date uptime;
|
||||||
|
}
|
||||||
@ -14,6 +14,7 @@ import com.evotech.hd.cloud.mqtt.enums.StateFunctionTypesEnum;
|
|||||||
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.order.OrderByPlateNumReq;
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.order.OrderByPlateNumReq;
|
||||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.state.OrderStatus;
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.state.OrderStatus;
|
||||||
|
import com.evotech.hd.cloud.mqtt.message.dto.newer.state.SwapStep;
|
||||||
import com.evotech.hd.common.core.entity.Result;
|
import com.evotech.hd.common.core.entity.Result;
|
||||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||||
@ -72,6 +73,21 @@ public class MqttMessageTestController {
|
|||||||
|
|
||||||
return new Result<String>().success("OK");
|
return new Result<String>().success("OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "反馈换电步骤")
|
||||||
|
@PostMapping("/swapStep")
|
||||||
|
@ApiOperationSupport(order = 3)
|
||||||
|
public Result<String> swapStep(@ParameterObject SwapStep swapStep, String stationCode) {
|
||||||
|
|
||||||
|
JSONObject jo = JSONUtil.parseObj(swapStep);
|
||||||
|
|
||||||
|
String topic = mqttTestUtil.getTopic(stationCode, MqttMessageTypeEnum.STATE.getType());
|
||||||
|
MqttMessageHeader header = mqttTestUtil.getHeader(StateFunctionTypesEnum.FUN_SWAPSTEP.getFunction());
|
||||||
|
|
||||||
|
mqttTestUtil.publishMessage(stationCode, jo, topic, header);
|
||||||
|
|
||||||
|
return new Result<String>().success("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import java.util.Date;
|
|||||||
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,8 +17,9 @@ public class OrderStatus {
|
|||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "时间", example = "yyyy-MM-dd HH:mm:ss")
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date statusTime;
|
private Date statusTime;
|
||||||
|
|
||||||
private OrderStatusData statusDate;
|
private OrderStatusData statusData;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,9 @@ package com.evotech.hd.cloud.mqtt.message.dto.newer.state;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,6 +17,8 @@ public class SwapStep {
|
|||||||
|
|
||||||
private Integer step;
|
private Integer step;
|
||||||
|
|
||||||
|
@Schema(description = "时间", example = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date stepTime;
|
private Date stepTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ public class StateMessageService {
|
|||||||
switch (StateFunctionTypesEnum.getFunctionType(header.getFunction())) {
|
switch (StateFunctionTypesEnum.getFunctionType(header.getFunction())) {
|
||||||
case FUN_ORDERSTATUS:
|
case FUN_ORDERSTATUS:
|
||||||
OrderStatus orderStatus = JSONUtil.toBean(dataBody, OrderStatus.class);
|
OrderStatus orderStatus = JSONUtil.toBean(dataBody, OrderStatus.class);
|
||||||
OrderStatusData statusData = JSONUtil.toBean(dataBody.getJSONObject("statusDate"), OrderStatusData.class);
|
OrderStatusData statusData = JSONUtil.toBean(dataBody.getJSONObject("statusData"), OrderStatusData.class);
|
||||||
handleOrderStatus(orderStatus, statusData);
|
handleOrderStatus(orderStatus, statusData);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -83,8 +83,14 @@ public class StateMessageService {
|
|||||||
case 3:
|
case 3:
|
||||||
// 修改订单状态和数据
|
// 修改订单状态和数据
|
||||||
OrderSwapBattery osb = alterOrderStatus(orderStatus, statusData);
|
OrderSwapBattery osb = alterOrderStatus(orderStatus, statusData);
|
||||||
// 换电步骤添加最后一条 TODO
|
// 换电步骤添加最后一条
|
||||||
|
OrderSwapBatteryStep step = new OrderSwapBatteryStep();
|
||||||
|
step.setOrderNo(orderStatus.getOrderNo());
|
||||||
|
step.setStep(8);
|
||||||
|
step.setStepTime(orderStatus.getStatusTime());
|
||||||
|
step.setCtime(new Date());
|
||||||
|
step.setCreater("SYS");
|
||||||
|
orderSwapBatteryStepDao.insert(step);
|
||||||
// 添加2块电池的溯源记录
|
// 添加2块电池的溯源记录
|
||||||
addBatteryTrace(orderStatus, statusData, osb);
|
addBatteryTrace(orderStatus, statusData, osb);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -30,9 +30,18 @@ public class BatteryStationDcServiceImpl implements BatteryStationDcService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Integer> add(BatteryStationDc bsdc) {
|
public Result<Integer> add(BatteryStationDc bsdc) {
|
||||||
bsdc.setCtime(new Date());
|
Date d = new Date();
|
||||||
|
bsdc.setCtime(d);
|
||||||
int n = batteryStationDcDao.insert(bsdc);
|
int n = batteryStationDcDao.insert(bsdc);
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
|
BatteryTrace bt = new BatteryTrace();
|
||||||
|
bt.setBatCode(bsdc.getBatCode());
|
||||||
|
bt.setBeginTime(d);
|
||||||
|
bt.setCreater("SYS");
|
||||||
|
bt.setPointType(bsdc.getSourceFrom());
|
||||||
|
bt.setPointCode(bt.getPointType() == 1? bsdc.getStationCode():bsdc.getSourceCode());
|
||||||
|
bt.setPointName(bt.getPointType() == 1? bsdc.getStationName():"");
|
||||||
|
addTrace(bt);
|
||||||
return new Result<Integer>().success(n);
|
return new Result<Integer>().success(n);
|
||||||
}
|
}
|
||||||
return new Result<Integer>().error("添加电池出错!");
|
return new Result<Integer>().error("添加电池出错!");
|
||||||
|
|||||||
8
pom.xml
8
pom.xml
@ -45,7 +45,8 @@
|
|||||||
<swagger.version>2.2.23</swagger.version>
|
<swagger.version>2.2.23</swagger.version>
|
||||||
<jexl3.version>3.4.0</jexl3.version>
|
<jexl3.version>3.4.0</jexl3.version>
|
||||||
<poi.version>5.3.0</poi.version>
|
<poi.version>5.3.0</poi.version>
|
||||||
<xxl-job.version>2.4.1</xxl-job.version>
|
<xxl-job.version>2.4.2</xxl-job.version>
|
||||||
|
<minio.version>8.5.14</minio.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -148,6 +149,11 @@
|
|||||||
<artifactId>xxl-job-core</artifactId>
|
<artifactId>xxl-job-core</artifactId>
|
||||||
<version>${xxl-job.version}</version>
|
<version>${xxl-job.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.minio</groupId>
|
||||||
|
<artifactId>minio</artifactId>
|
||||||
|
<version>${minio.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
@ -57,6 +57,11 @@
|
|||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-json</artifactId>
|
<artifactId>hutool-json</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.minio</groupId>
|
||||||
|
<artifactId>minio</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
package com.evotech.hd.resource.config.minio;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import io.minio.MinioClient;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties({MinIOConfigProperties.class})
|
||||||
|
@ConditionalOnProperty(prefix = "yt.minio", name = "enable", matchIfMissing = false)
|
||||||
|
public class MinIOConfig {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MinIOConfigProperties minIOConfigProperties;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
MinioClient buildMinioClient() {
|
||||||
|
return MinioClient
|
||||||
|
.builder()
|
||||||
|
.credentials(minIOConfigProperties.getAccessKey(), minIOConfigProperties.getSecretKey())
|
||||||
|
.endpoint(minIOConfigProperties.getEndpoint())
|
||||||
|
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
package com.evotech.hd.resource.config.minio;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@ConditionalOnProperty(prefix = "yt.minio", name = "enable", matchIfMissing = false)
|
||||||
|
@ConfigurationProperties(prefix = "yt.minio", ignoreUnknownFields = true)
|
||||||
|
@Data
|
||||||
|
public class MinIOConfigProperties implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2706961148421781695L;
|
||||||
|
|
||||||
|
private String accessKey;
|
||||||
|
private String secretKey;
|
||||||
|
private String bucket;
|
||||||
|
private String endpoint;
|
||||||
|
private String folderCloud;
|
||||||
|
private String folderWechat;
|
||||||
|
private String urlPrefix;
|
||||||
|
|
||||||
|
}
|
||||||
@ -23,6 +23,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
|
||||||
@Tag(name = "上传接口")
|
@Tag(name = "上传接口")
|
||||||
@ApiSupport(order = 150)
|
@ApiSupport(order = 150)
|
||||||
@ -70,4 +71,21 @@ public class FileUpLoadController {
|
|||||||
return fileUpLoadService.fileUpLoad(file, user, isAlterRandomName);
|
return fileUpLoadService.fileUpLoad(file, user, isAlterRandomName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "图片文件上传, 设置微信先用这个")
|
||||||
|
@PostMapping("/img/upload")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
public Result<String> imgUpLoad(@RequestPart MultipartFile file, @RequestParam Integer useFor) {
|
||||||
|
return fileUpLoadService.imgUpLoad(file, useFor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "图片文件删除, 设置微信先用这个")
|
||||||
|
@PostMapping("/img/del")
|
||||||
|
@ApiOperationSupport(order = 7)
|
||||||
|
public Result<Integer> imgDelete(@NotBlank @RequestParam String url) {
|
||||||
|
return fileUpLoadService.imgDelete(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
package com.evotech.hd.resource.controller;
|
||||||
|
|
||||||
|
|
||||||
|
public class WechatAgreementController {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package com.evotech.hd.resource.controller;
|
||||||
|
|
||||||
|
public class WechatSwiperController {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package com.evotech.hd.resource.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.evotech.hd.common.core.entity.resource.WechatAgreement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zrb
|
||||||
|
* @since 2024-12-21
|
||||||
|
*/
|
||||||
|
public interface WechatAgreementDao extends BaseMapper<WechatAgreement> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package com.evotech.hd.resource.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.evotech.hd.common.core.entity.resource.WechatSwiper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zrb
|
||||||
|
* @since 2024-12-21
|
||||||
|
*/
|
||||||
|
public interface WechatSwiperDao extends BaseMapper<WechatSwiper> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -20,4 +20,8 @@ public interface FileUpLoadService {
|
|||||||
public Result<String> delete(String filePath, Integer fileId, String logId);
|
public Result<String> delete(String filePath, Integer fileId, String logId);
|
||||||
|
|
||||||
public Result<String> fileUpLoad(MultipartFile file, String user, Boolean isAlterRandomName);
|
public Result<String> fileUpLoad(MultipartFile file, String user, Boolean isAlterRandomName);
|
||||||
|
|
||||||
|
public Result<String> imgUpLoad(MultipartFile file, Integer useFor);
|
||||||
|
|
||||||
|
public Result<Integer> imgDelete(String url);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package com.evotech.hd.resource.service.impl;
|
package com.evotech.hd.resource.service.impl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -16,6 +18,7 @@ import com.evotech.hd.common.core.entity.resource.LogUpload;
|
|||||||
import com.evotech.hd.common.core.entity.resource.UploadFile;
|
import com.evotech.hd.common.core.entity.resource.UploadFile;
|
||||||
import com.evotech.hd.common.core.enums.CodeMsg;
|
import com.evotech.hd.common.core.enums.CodeMsg;
|
||||||
import com.evotech.hd.common.core.utils.SnowflakeUtil;
|
import com.evotech.hd.common.core.utils.SnowflakeUtil;
|
||||||
|
import com.evotech.hd.resource.config.minio.MinIOConfigProperties;
|
||||||
import com.evotech.hd.resource.dao.LogUploadDao;
|
import com.evotech.hd.resource.dao.LogUploadDao;
|
||||||
import com.evotech.hd.resource.dao.UploadFileDao;
|
import com.evotech.hd.resource.dao.UploadFileDao;
|
||||||
import com.evotech.hd.resource.entity.request.ListFileRequest;
|
import com.evotech.hd.resource.entity.request.ListFileRequest;
|
||||||
@ -26,6 +29,10 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.core.util.URLUtil;
|
||||||
|
import io.minio.MinioClient;
|
||||||
|
import io.minio.PutObjectArgs;
|
||||||
|
import io.minio.RemoveObjectArgs;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -35,6 +42,12 @@ public class FileUpLoadServiceImpl implements FileUpLoadService {
|
|||||||
private UploadFileDao uploadFileDao;
|
private UploadFileDao uploadFileDao;
|
||||||
@Resource
|
@Resource
|
||||||
private LogUploadDao uploadLogDao;
|
private LogUploadDao uploadLogDao;
|
||||||
|
@Resource
|
||||||
|
private MinioClient minioClient;
|
||||||
|
@Resource
|
||||||
|
private MinIOConfigProperties minIOConfigProperties;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Value("${yt.file.file-path}")
|
@Value("${yt.file.file-path}")
|
||||||
private String filePath;
|
private String filePath;
|
||||||
@ -191,4 +204,50 @@ public class FileUpLoadServiceImpl implements FileUpLoadService {
|
|||||||
return new Result<String>().success(url);
|
return new Result<String>().success(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<String> imgUpLoad(MultipartFile file, Integer useFor) {
|
||||||
|
// 重命名
|
||||||
|
String fileFinalName = IdUtil.fastSimpleUUID() + "." + FileUtil.extName(file.getOriginalFilename());
|
||||||
|
// 上传
|
||||||
|
String filePath = useFor == 1 ? minIOConfigProperties.getFolderWechat() : minIOConfigProperties.getFolderCloud();
|
||||||
|
String filePathName = filePath + "/" + fileFinalName;
|
||||||
|
try {
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
|
PutObjectArgs putObjectArgs = PutObjectArgs.builder()
|
||||||
|
.bucket(minIOConfigProperties.getBucket())
|
||||||
|
.object(filePathName)
|
||||||
|
.contentType(file.getContentType())
|
||||||
|
.stream(inputStream, file.getSize(), -1)
|
||||||
|
.build();
|
||||||
|
minioClient.putObject(putObjectArgs);
|
||||||
|
inputStream.close();
|
||||||
|
String url = minIOConfigProperties.getUrlPrefix() + minIOConfigProperties.getBucket() + "/" + filePathName;
|
||||||
|
return new Result<String>().success(url);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new Result<String>().error("上传文件失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Integer> imgDelete(String url) {
|
||||||
|
URL urlU = URLUtil.url(url);
|
||||||
|
String path = urlU.getPath().substring(1);
|
||||||
|
int index = path.indexOf("/");
|
||||||
|
String bucket = path.substring(0, index);
|
||||||
|
String filePathName = path.substring(index + 1);
|
||||||
|
// 删除Objects
|
||||||
|
RemoveObjectArgs removeObjectArgs = RemoveObjectArgs.builder()
|
||||||
|
.bucket(bucket)
|
||||||
|
.object(filePathName)
|
||||||
|
.build();
|
||||||
|
try {
|
||||||
|
minioClient.removeObject(removeObjectArgs);
|
||||||
|
return new Result<Integer>().success("OK");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new Result<Integer>().error("删除失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
package com.evotech.hd.resource;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.URLUtil;
|
||||||
|
|
||||||
|
public class Test1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String url = "https://static.evo-techina.com/ythd/oauth2.png";
|
||||||
|
System.out.println(URLUtil.getHost(URLUtil.url(url)));
|
||||||
|
System.out.println(URLUtil.getDecodedPath(URLUtil.url(url)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user