fix[订单模块]:排队,oss路径,自动任务,订单状态等逻辑

This commit is contained in:
2025-01-25 13:21:29 +08:00
parent f57ee5edc6
commit 39a7eb0580
26 changed files with 266 additions and 46 deletions
@@ -3,6 +3,7 @@ package com.central.device.controller;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.central.common.model.Result;
import com.central.device.feign.OrderCenterService;
import com.central.device.message.ControlEnum;
import com.central.device.message.ControlMessageConstant;
import com.central.device.util.MapUtil;
@@ -38,6 +39,9 @@ public class ApiDeviceController {
private RequestUtils requestUtils;
private ControlMessageConstant controlMessageConstant = new ControlMessageConstant();
@Autowired
private OrderCenterService orderCenterService;
/**
* 获取设备属性
*/
@@ -66,6 +70,13 @@ public class ApiDeviceController {
JsonObject jsonObject;
String property = MapUtil.getStrValue(param, "control");
String value = MapUtil.getStrValue(param, "order_no");
if (value == null || "".equals(value)) {
return Result.succeed("暂未开放控制权限");
}
Result res = orderCenterService.getOrderExecStatus(value);
if (res.getResp_code() != null && res.getResp_code() == 0){
return Result.succeed("任务正在执行中");
}
try {
if (ControlEnum.contains(ControlEnum.valueOf(property.toUpperCase()))) {
jsonObject = gson.fromJson(controlMessageConstant.CONTROL_MESSAGE_MAP.get(property), JsonObject.class);
@@ -0,0 +1,23 @@
package com.central.device.feign;
import com.central.common.constant.ServiceNameConstants;
import com.central.common.model.Result;
import com.central.device.feign.fallback.OrderCenterServiceFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* user-center模块远程调用
*
* @author lsl
* @version 1.0
* @description user-center模块远程调用
* @create 2025/1/13
**/
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = OrderCenterServiceFallbackFactory.class, dismiss404 = true)
public interface OrderCenterService {
@GetMapping("/status/{orderNo}")
Result getOrderExecStatus(@PathVariable("orderNo") String orderNo);
}
@@ -0,0 +1,32 @@
package com.central.device.feign.fallback;
import com.central.common.model.Result;
import com.central.device.feign.OrderCenterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* 文件中心调用失败回调
*
* @author lsl
* @version 1.0
* @description 用户中心调用失败回调
* @create 2025/1/17 11:33
**/
@Slf4j
@Component
public class OrderCenterServiceFallbackFactory implements FallbackFactory<OrderCenterService> {
@Override
public OrderCenterService create(Throwable cause) {
return new OrderCenterService() {
@Override
public Result getOrderExecStatus(String orderNo) {
return Result.failed(orderNo);
}
};
}
}
@@ -4,10 +4,10 @@ server:
spring:
application:
name: device-center
# cloud:
# nacos:
# discovery:
# ip: 81.70.164.178
cloud:
nacos:
discovery:
ip: 81.70.164.178
# cloud:
# nacos:
# discovery:
@@ -6,6 +6,7 @@ import com.central.common.model.Result;
import com.central.file.service.IFileService;
import com.central.file.utils.HexToJpeg;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -13,7 +14,6 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.LinkedHashMap;
@@ -26,7 +26,7 @@ import java.util.Map;
*/
@RestController
public class FileController {
@Resource
@Autowired
private IFileService fileService;
// @Value("tencent.accessTokenUrl")
@@ -81,8 +81,8 @@ public class FileController {
return fileService.getViewUrl(id);
}
@GetMapping("/files/name")
public String getViewUrlByName(@RequestParam String name) {
@PostMapping("/files/name")
public String getViewUrlByName(@RequestBody String name) {
return fileService.getViewUrlByName(name);
}
@@ -17,4 +17,6 @@ import java.util.Map;
@Mapper
public interface FileMapper extends SuperMapper<FileInfo> {
List<FileInfo> findList(Page<FileInfo> page, @Param("f") Map<String, Object> params);
FileInfo findById(@Param("id") String id);
}
@@ -110,4 +110,9 @@ public abstract class AbstractIFileService extends ServiceImpl<FileMapper, FileI
}
public abstract String getViewUrlByName(String name);
@Override
public FileInfo getFileInfo(String id) {
return baseMapper.selectById(id);
}
}
@@ -66,7 +66,7 @@ public class OssService extends AbstractIFileService {
@Override
public String getViewUrl(String fileId) {
FileInfo fileInfo = baseMapper.selectById(fileId);
FileInfo fileInfo = getFileInfo(fileId);
if (fileInfo != null) {
return ossTemplate.getViewUrl(fileInfo.getName());
}
@@ -82,7 +82,7 @@ public class OssService extends AbstractIFileService {
@Override
public FileInfo getFileInfo(String id) {
return baseMapper.selectById(id);
return baseMapper.findById(id);
}
@Override
@@ -8,7 +8,7 @@ spring:
mybatis-plus:
mapper-locations: classpath:/mapper/*Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.central.file.model
typeAliasesPackage: com.central.common.model
global-config:
db-config:
id-type: INPUT
@@ -4,7 +4,7 @@ server:
spring:
application:
name: file-center
# cloud:
# nacos:
# discovery:
# ip: 119.45.169.13
cloud:
nacos:
discovery:
ip: 119.45.169.13
@@ -25,4 +25,8 @@
<include refid="where" />
order by t.create_time desc
</select>
<select id="findById" resultType="com.central.common.model.FileInfo">
SELECT * FROM file_info WHERE id = #{id}
</select>
</mapper>
@@ -88,7 +88,11 @@ public class OrderController {
})
@GetMapping
public PageResult list(@RequestParam Map<String, Object> params) {
params.put("userId", LoginUserContextHolder.getUser().getId());
LoginAppUser user = LoginUserContextHolder.getUser();
if (user == null) {
return new PageResult<>();
}
params.put("userId", user.getId());
return orderService.findListByUser(params);
}
@@ -106,7 +110,7 @@ public class OrderController {
params.put("userId", user.getId());
// 获取当前日期,格式化为 yyyyMMdd
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
PageResult<Order> result = orderService.findListByUser(params);
if (result.getCount() > 0){
@@ -121,10 +125,20 @@ public class OrderController {
if (list.size() > 0){
for (OrderFile orderFile : list){
Map imgMap = new HashMap();
imgMap.put("url", fileCenterService.getViewUrl(orderFile.getFileId()));
OrderFile file = orderFileService.getOrderFileByFileId(orderFile.getFileId());
if (file != null){
imgMap.put("contentType", file.getFileType());
String url = fileCenterService.getViewUrlByName(orderFile.getFilePath());
url = url.replace("goflyapp.oss-cn-beijing.aliyuncs.com","cdn.goflytec.com");
imgMap.put("url", url);
//@TODO 待优化file_type获取方式
if (url != null && !"".equals(url) ){
if (url.contains(".jpeg")){
imgMap.put("contentType", "image/jpeg");
}else if (url.contains(".png")){
imgMap.put("contentType", "image/png");
}else if (url.contains(".gif")){
imgMap.put("contentType", "image/gif");
}else if (url.contains(".mp4")){
imgMap.put("contentType", "video/mp4");
}
}
resultList.add(imgMap);
}
@@ -205,16 +219,35 @@ public class OrderController {
// 获取排队总览信息
@GetMapping("/queue/info")
public Result<Map> getQueueInfo() {
Double price = 25.0;
LoginAppUser user = LoginUserContextHolder.getUser();
Double price = 6.99;
long execTime = 3; //一单执行时间默认3分钟
Long count = orderService.getOrderCountByStatus(OrderStatus.PAID.getId());
Long userOrderCount = orderService.getOrderCountByStatusAndUser(OrderStatus.PAID.getId(),user.getId());
if (userOrderCount > 0){
count = count - userOrderCount;
}
Map<String, Object> map = new HashMap<>();
map.put("count", count);
map.put("count", count == 0 ? -1 : count);
map.put("time",Math.multiplyExact(count,execTime));
map.put("price",price);
return Result.succeed(map,"获取成功");
}
// 获取排队总览信息
@GetMapping("/queue/info/user")
public Result<Integer> getQueueInfoByUser() {
LoginAppUser user = LoginUserContextHolder.getUser();
Long count = orderService.getOrderCountByStatusAndUser(OrderStatus.PAID.getId(),user.getId());
if (count == 0){
return Result.succeed(0,"该用户未存在待执行订单");
}else if (count > 0 ){
return Result.succeed(1,"存在待执行订单");
}
return Result.succeed(0,"该用户未存在待执行订单");
}
// 获取排队中的订单列表
@GetMapping("/queue")
public Result<List<Order>> getOrdersInQueue() {
@@ -222,6 +255,16 @@ public class OrderController {
return Result.succeed(orders,"获取成功");
}
// 获取排队中的订单列表
@GetMapping("/queue/first")
public Result<Order> getOrdersInQueueFirstOne() {
List<Order> orders = orderService.getOrdersInQueue();
if (orders.size() > 0){
return Result.succeed(orders.get(0),"获取成功");
}
return Result.failed("未存在排队队列");
}
// 处理排队中的订单(模拟消费通知等操作)
@PutMapping("/queue/process")
public Result<String> processOrdersInQueue() {
@@ -243,6 +286,24 @@ public class OrderController {
return Result.failed("未查询到订单数据");
}
@PutMapping("/update")
public Result<String> updateOrderStatusComplete(@RequestBody Map payload) {
Order order = orderService.getOrderByNumber(payload.get("orderNo").toString());
if (order != null) {
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
order.setOrderStatus(OrderStatus.COMPLETE.getId());
boolean res = orderService.updateOrder(order);
if (res){
return Result.succeed("更新成功");
}
}else {
return Result.failed("已更新");
}
}
return Result.failed("未查询到订单数据");
}
/** 商户订单号查询订单 */
@@ -280,4 +341,19 @@ public class OrderController {
}
return Result.failed("请重试");
}
@GetMapping("/status/{orderNo}")
public Result getOrderExecStatus(@PathVariable("orderNo") String orderNo) {
Order order = orderService.getOrderByNumber(orderNo);
if (order == null){
return Result.failed("未查询到订单");
}
if (order.getOrderStatus().equals(OrderStatus.COMPLETE.getId())){
return Result.failed("已执行");
}else if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
return Result.succeed("待执行");
}
return Result.failed("不满足执行条件");
}
}
@@ -102,6 +102,7 @@ public class OrderFileController {
if (!CollectionUtils.isEmpty(orderFiles)) {
for (OrderFile orderFile : orderFiles) {
String viewUrl = fileCenterService.getViewUrl(orderFile.getFileId());
System.out.println("viewUrl:"+ viewUrl);
orderFile.setViewUrl(viewUrl);
}
}else {
@@ -135,7 +136,7 @@ public class OrderFileController {
if (orderFile.getFilePath() != null) {
FileInfo fileInfo = fileCenterService.creatFileInfo(orderFile.getFilePath());
orderFile.setFileId(fileInfo.get);
orderFile.setFileId(fileInfo.getId());
orderFile.setFilePath(fileInfo.getPath());
orderFile.setFileType(fileInfo.getContentType());
orderFile.setTourismId(order.getTourismId());
@@ -40,4 +40,7 @@ public interface FileCenterService {
@PostMapping("/path")
FileInfo creatFileInfo(@RequestBody String path);
@PostMapping("/files/name")
String getViewUrlByName(@RequestBody String name) ;
}
@@ -45,6 +45,11 @@ public class FileCenterServiceFallbackFactory implements FallbackFactory<FileCen
return null;
}
@Override
public String getViewUrlByName(String name) {
return "";
}
};
}
}
@@ -22,7 +22,7 @@ public class OrderTimeoutScheduler {
}
// 每隔一定时间(这里设置为每分钟检查一次,可根据实际情况调整)检查订单超时情况
@Scheduled(fixedRate = 60 * 1000)
@Scheduled(fixedRate = 1 * 1000)
public void checkOrderPaySuccess() {
orderService.updateOrderStatus();
}
@@ -72,6 +72,8 @@ public interface IOrderService extends ISuperService<Order> {
*/
Long getOrderCountByStatus(Integer status);
Long getOrderCountByStatusAndUser(Integer status, Long userId);
/**
* 获取user订单记录
* @param params
@@ -156,6 +156,14 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
}
@Override
public Long getOrderCountByStatusAndUser(Integer status, Long userId) {
return baseMapper.selectCount(new QueryWrapper<Order>()
.eq("order_status", status)
.eq("user_id", userId));
}
@Override
public PageResult findListByUser(Map<String, Object> params) {
Page<Order> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
@@ -4,10 +4,10 @@ server:
spring:
application:
name: order-center
# cloud:
# nacos:
# discovery:
# ip: 119.45.169.13
cloud:
nacos:
discovery:
ip: 119.45.169.13
# cloud:
# nacos:
# discovery:
@@ -34,7 +34,7 @@
</update>
<!-- 查询所有处于排队状态的订单 -->
<select id="getOrdersInQueue" resultType="com.central.order.model.Order">
SELECT * FROM orders WHERE order_status = 1
SELECT * FROM orders WHERE order_status = 1 order by id asc
</select>
<!-- 根据店铺编号和创建时间(当天)查询订单数量 -->
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
@@ -18,6 +20,8 @@ import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("file_info")
@Getter
@Setter
public class FileInfo extends Model<FileInfo> {
private static final long serialVersionUID = -1438078028040922174L;
@@ -142,7 +142,7 @@ public class OssTemplate implements InitializingBean {
public String getViewUrl(String objectName) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, 7);
URL url = ossClient.generatePresignedUrl(fileProperties.getCos().getBucketName(), objectName, cal.getTime());
URL url = ossClient.generatePresignedUrl(fileProperties.getOss().getBucketName(), objectName, cal.getTime());
return url.toString();
}
@@ -31,6 +31,11 @@ zlt.s3.accessKeySecret=mmfSh4gjJm8dck0KaG6fKItpIM3tenWVHS4Ygjlm
zlt.s3.endpoint=http://81.70.164.178:9000
zlt.s3.bucketName=gofly
zlt.oss.secretId=LTAI5tSNV1RvexXpMMCZhxSe
zlt.oss.secretKey=XocJRWU8emwjjvYLTrc04l91VZMkQK
zlt.oss.endpoint=https://oss-cn-beijing.aliyuncs.com
zlt.oss.bucketName=goflyapp
#### cos配置
zlt.cos.secretId=AKIDkMn6B3h7KJ5dIkyzpRr7C6mFUqFWbu1u
zlt.cos.secretKey=jDThssfEZieS4S8bqsgIiAUdbXVVYgdQ
@@ -1,18 +1,22 @@
########################## 统一变量配置 ##########################
##### 数据库配置
zlt.datasource.ip=192.168.28.130
zlt.datasource.ip=127.0.0.1
zlt.datasource.username=root
zlt.datasource.password=1q2w3e4r
zlt.datasource.password=root
##### redis配置
spring.data.redis.host=192.168.28.130
spring.data.redis.host=192.168.2.20
spring.data.redis.port=6379
spring.data.redis.password=ikingtec123456
spring.data.redis.database=8
spring.data.redis.timeout=5000
##### elasticsearch配置
zlt.elasticsearch.uris=192.168.28.130:9200
zlt.elasticsearch.username=
zlt.elasticsearch.password=
zlt.elasticsearch.uris=119.45.169.13:9200
zlt.elasticsearch.username=elastic
zlt.elasticsearch.password=iot123456@
##### sentinel配置
zlt.sentinel.dashboard=192.168.28.130:6999
@@ -22,10 +26,43 @@ zlt.fdfs.web-url=192.168.28.130
zlt.fdfs.trackerList=${zlt.fdfs.web-url}:22122
##### s3配置
zlt.s3.access-key=minioadmin
zlt.s3.accessKeySecret=minioadmin
zlt.s3.endpoint=http://192.168.28.130:9000
zlt.s3.bucketName=test
zlt.s3.access-key=33RdDbIlEFK0z9IJHSqx
zlt.s3.accessKeySecret=mmfSh4gjJm8dck0KaG6fKItpIM3tenWVHS4Ygjlm
zlt.s3.endpoint=http://81.70.164.178:9000
zlt.s3.bucketName=gofly
zlt.oss.secretId=LTAI5tSNV1RvexXpMMCZhxSe
zlt.oss.secretKey=XocJRWU8emwjjvYLTrc04l91VZMkQK
zlt.oss.endpoint=https://oss-cn-beijing.aliyuncs.com
zlt.oss.bucketName=goflyapp
#### cos配置
zlt.cos.secretId=AKIDkMn6B3h7KJ5dIkyzpRr7C6mFUqFWbu1u
zlt.cos.secretKey=jDThssfEZieS4S8bqsgIiAUdbXVVYgdQ
zlt.cos.endpoint=gofly-1333114031.cos.ap-nanjing.myqcloud.com
zlt.cos.bucketName=gofly-1333114031
zlt.cos.region=ap-nanjing
##### 日志链路追踪
zlt.trace.enable=true
zlt.trace.enable=true
zlt.security.tencent.appId=wx30a3c8de94a85584
zlt.security.tencent.appSecret=e64d6e3dcfe88d0daee50e77f5a2ee69
zlt.security.tencent.token=YPbzETU8oe3XguGgwtA4g1DqlFKvw7pT
zlt.security.tencent.encodingAESKey=YPbzETU8oe3XguGgwtA4g1DqlFKvw7pTZiyHTxCiQxh
zlt.security.tencent.templateId=YOUR_TEMPLATE_ID
zlt.security.tencent.jscode2sessionUrl=https://api.weixin.qq.com/sns/jscode2session
zlt.security.tencent.accessTokenUrl=https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${zlt.security.tencent.appId}&secret=${zlt.security.tencent.appSecret}
# 微信支付商户号
zlt.wxpay.merchantId=1703796518
# 商户证书序列号
zlt.wxpay.merchantSerialNumber=11F4AC03C50EB582D3EDE082591D1F9A65388D51
# 微信支付申请的应用ID
zlt.wxpay.appId=wx30a3c8de94a85584
# 微信支付异步通知地址(需外网可访问且与微信支付平台配置一致)
zlt.wxpay.notifyUrl=http://your_domain/weixin/pay/notify
# 商户API私钥路径
zlt.wxpay.privateKeyPath=D:\\wx\\WXCertUtil\\cert\\1703796518_20250114_cert\\apiclient_key.pem
# 商户APIV3密钥
zlt.wxpay.apiV3Key=aIt5Vw3cYXSCSd4L5h14kIyDsoXBow7r
@@ -1,10 +1,10 @@
########################## bootstrap级别通用配置 ##########################
# 默认开发环境
spring.profiles.active=dev
spring.profiles.active=prod
##### nacos(注册中心和配置中心)地址
#spring.cloud.nacos.server-addr=47.94.136.130:8848
spring.cloud.nacos.server-addr=127.0.0.1:8848
spring.cloud.nacos.server-addr=47.94.136.130:8848
#spring.cloud.nacos.server-addr=127.0.0.1:8848
spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=nacos
spring.cloud.nacos.config.file-extension=yml
@@ -138,7 +138,9 @@ zlt:
/user/login, /oauth/authorize,
/api-uaa/tokens/key,
/*/v3/api-docs/**,
/api-order/files/path
/api-order/files/path,
/api-order/update,
/api-order/queue/first
auth:
urlPermission:
#是否开启url级别权限