this is 3.24 update
This commit is contained in:
parent
ec17b8d35e
commit
58a9791b54
7
pom.xml
7
pom.xml
|
@ -197,6 +197,13 @@
|
|||
<!-- <version>2.5.6</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.8</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
@ -161,6 +161,8 @@ public class FileController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param uploadFileRequest 业务名称
|
||||
* @param multipartFile 文件
|
||||
|
@ -182,4 +184,9 @@ public class FileController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -360,8 +360,8 @@ public class GlobalController {
|
|||
* 小程序端预约须知
|
||||
* @return 当前类别的商品列表
|
||||
*/
|
||||
@GetMapping("/update/notice")
|
||||
@Operation(summary = "web端更新预约须知", description = "参数:无,方法名:updateNotice")
|
||||
@GetMapping("/query/notice")
|
||||
@Operation(summary = "web端更新预约须知", description = "参数:无,方法名:queryNotice")
|
||||
public BaseResponse<String> queryNotice() {
|
||||
|
||||
String notice = (String) redisTemplate.opsForValue().get(NOTICE_KEY);
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.cultural.heritage.common.BaseResponse;
|
||||
import com.cultural.heritage.common.ErrorCode;
|
||||
import com.cultural.heritage.common.ResultUtils;
|
||||
import com.cultural.heritage.config.WxAccessToken;
|
||||
import com.cultural.heritage.config.WxWaybillToken;
|
||||
import com.cultural.heritage.constant.FileConstant;
|
||||
import com.cultural.heritage.exception.BusinessException;
|
||||
|
@ -19,6 +20,7 @@ import com.cultural.heritage.model.entity.OrderItems;
|
|||
import com.cultural.heritage.model.entity.User;
|
||||
import com.cultural.heritage.model.vo.good.GoodLogisticsInfoVO;
|
||||
import com.cultural.heritage.model.vo.good.GoodsInfo;
|
||||
import com.cultural.heritage.service.file.IHweiYunOBSService;
|
||||
import com.cultural.heritage.service.order.OrderItemService;
|
||||
import com.cultural.heritage.service.order.OrderService;
|
||||
import com.cultural.heritage.service.user.UserService;
|
||||
|
@ -29,13 +31,16 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -74,7 +79,11 @@ public class WeChatLogisticsController {
|
|||
private OrderItemService orderItemService;
|
||||
|
||||
|
||||
@Resource
|
||||
private IHweiYunOBSService iHweiYunOBSService;
|
||||
|
||||
|
||||
//
|
||||
// /**
|
||||
// * (小程序端)获取接口调用凭据
|
||||
// *
|
||||
|
@ -96,6 +105,29 @@ public class WeChatLogisticsController {
|
|||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* (小程序端)获取接口调用凭据
|
||||
*/
|
||||
@GetMapping("/get/token")
|
||||
@Operation(summary = "(小程序端)获取接口调用凭据", description = "参数:无, 权限:所有人, 方法名:getAccessToken")
|
||||
public BaseResponse<WxAccessToken> getAccessToken() {
|
||||
String accessToken = (String) redisTemplate.opsForValue().get(ACCESS_TOKEN_KEY);
|
||||
if (accessToken == null) {
|
||||
weChatLogisticsService.getAccessToken();
|
||||
accessToken = (String) redisTemplate.opsForValue().get(ACCESS_TOKEN_KEY);
|
||||
}
|
||||
WxAccessToken wxAccessToken = WxAccessToken.builder()
|
||||
.access_token(accessToken)
|
||||
.expires_in("7200").build();
|
||||
return ResultUtils.success(wxAccessToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* (小程序端)根据订单id查询物流信息
|
||||
*/
|
||||
|
@ -109,7 +141,7 @@ public class WeChatLogisticsController {
|
|||
String miniOpenId = loginUser.getMiniOpenId();
|
||||
String accessToken = (String) redisTemplate.opsForValue().get(ACCESS_TOKEN_KEY);
|
||||
if (accessToken == null) {
|
||||
weChatLogisticsService.getAccessToken();
|
||||
weChatLogisticsService.getStableAccessToken();
|
||||
accessToken = (String) redisTemplate.opsForValue().get(ACCESS_TOKEN_KEY);
|
||||
}
|
||||
Long id = commonRequest.getId();
|
||||
|
@ -121,12 +153,37 @@ public class WeChatLogisticsController {
|
|||
QueryWrapper<OrderItems> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("orderId", id);
|
||||
List<OrderItems> orderItemsList = orderItemService.list(queryWrapper);
|
||||
List<GoodLogisticsInfoVO> goodLogisticsInfoVOS = orderItemsList.stream().map(orderItems -> {
|
||||
|
||||
List<GoodLogisticsInfoVO> goodLogisticsInfoVOS = new ArrayList<>();
|
||||
for (OrderItems orderItems : orderItemsList) {
|
||||
GoodSnapshot goodSnapshot = orderItems.getGoodSnapshot();
|
||||
String name = goodSnapshot.getName();
|
||||
String goodImg = FileConstant.SERVER_HOST + goodSnapshot.getGoodImg();
|
||||
return GoodLogisticsInfoVO.builder().goods_name(name).goods_img_url(goodImg).build();
|
||||
}).toList();
|
||||
String goodImg = goodSnapshot.getGoodImg();
|
||||
String[] imgArr = goodImg.split(";");
|
||||
String imgUrl = FileConstant.SERVER_HOST + imgArr[0];
|
||||
String filePath = null;
|
||||
try {
|
||||
URL url = new URL(imgUrl);
|
||||
// 压缩图片到目标质量并返回InputStream
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
Thumbnails.of(url)
|
||||
// .scale(0.2f)
|
||||
.size(70, 70) // 设定压缩后的图片大小
|
||||
.outputQuality(1) // 设置压缩质量
|
||||
.toOutputStream(outputStream);
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||
filePath = RandomStringUtils.randomAlphabetic(16) + ".png";
|
||||
iHweiYunOBSService.fileUpload(byteArrayInputStream, filePath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String resultUrl = FileConstant.SERVER_HOST + filePath;
|
||||
GoodLogisticsInfoVO goodLogisticsInfoVO = GoodLogisticsInfoVO.builder().goods_name(name).goods_img_url(resultUrl).build();
|
||||
goodLogisticsInfoVOS.add(goodLogisticsInfoVO);
|
||||
}
|
||||
|
||||
|
||||
GoodsInfo goodsInfo = GoodsInfo.builder().detail_list(goodLogisticsInfoVOS).build();
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("openid", miniOpenId);
|
||||
|
|
|
@ -4,12 +4,24 @@ import com.obs.services.model.PutObjectResult;
|
|||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 华为云OBS服务接口
|
||||
*/
|
||||
public interface IHweiYunOBSService {
|
||||
|
||||
|
||||
/**
|
||||
* @Description 上传文件(通过流来上传)
|
||||
* @param: uploadFile 上传文件
|
||||
* @param: objectKey 具体的文件名(含存储路径)
|
||||
* @return PutObjectResult
|
||||
*/
|
||||
PutObjectResult fileUpload(InputStream inputStream, String objectKey);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Description 上传文件
|
||||
* @param: uploadFile 上传文件
|
||||
|
|
|
@ -32,7 +32,6 @@ public class HweiYunOBSServiceImpl implements IHweiYunOBSService {
|
|||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* OBS-文件上传
|
||||
* @param uploadFile 文件对象
|
||||
|
@ -65,6 +64,45 @@ public class HweiYunOBSServiceImpl implements IHweiYunOBSService {
|
|||
return putObjectResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Description 上传文件(通过流来上传)
|
||||
* @param: uploadFile 上传文件
|
||||
* @param: objectKey 具体的文件名(含存储路径)
|
||||
* @return PutObjectResult
|
||||
*/
|
||||
@Override
|
||||
public PutObjectResult fileUpload(InputStream inputStream, String objectKey) {
|
||||
ObsClient obsClient = null;
|
||||
PutObjectResult putObjectResult = null;
|
||||
try {
|
||||
String bucketName = hweiOBSConfig.getBucketName();
|
||||
obsClient = hweiOBSConfig.getInstance();
|
||||
long available = inputStream.available();
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectKey, inputStream);
|
||||
|
||||
ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||
objectMetadata.setContentLength(available);
|
||||
putObjectRequest.setMetadata(objectMetadata);
|
||||
// 设置对象访问权限为公共读
|
||||
putObjectRequest.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
|
||||
putObjectResult = obsClient.putObject(putObjectRequest);
|
||||
// 读取该已上传对象的URL
|
||||
} catch (ObsException | IOException e) {
|
||||
log.info("上传文件失败");
|
||||
} finally {
|
||||
hweiOBSConfig.destroy(obsClient);
|
||||
}
|
||||
return putObjectResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* @Description : 文件下载
|
||||
* @author : YBL
|
||||
|
|
|
@ -75,12 +75,12 @@ springdoc:
|
|||
|
||||
|
||||
server:
|
||||
port: 9092
|
||||
# port: 8888
|
||||
# ssl:
|
||||
# key-store: classpath:carboner.cn.jks
|
||||
# key-store-password: 6gsn1hke4m4f7
|
||||
# key-store-type: JKS
|
||||
# port: 9092
|
||||
port: 8888
|
||||
ssl:
|
||||
key-store: classpath:carboner.cn.jks
|
||||
key-store-password: 6gsn1hke4m4f7
|
||||
key-store-type: JKS
|
||||
|
||||
servlet:
|
||||
context-path: /api
|
||||
|
|
Loading…
Reference in New Issue
Block a user