!23 fix(订单中心):首页统计优化
Merge pull request !23 from Iamasoldier/feature_lsl
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
# TourismWithDistance 类修复
|
||||
|
||||
## 问题描述
|
||||
|
||||
`TourismWithDistance` 类被误删,导致以下功能无法正常工作:
|
||||
- 查询附近景区列表接口 `/tourism/nearby`
|
||||
- 景区距离计算和显示
|
||||
- 景区订单展示图片URL设置
|
||||
|
||||
## 解决方案
|
||||
|
||||
### 1. 重新创建 TourismWithDistance 类
|
||||
|
||||
在 `zlt-business/order-center/src/main/java/com/central/order/model/TourismWithDistance.java` 中重新创建了该类:
|
||||
|
||||
```java
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TourismWithDistance extends Tourism {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 距离(公里)
|
||||
*/
|
||||
private BigDecimal distance;
|
||||
|
||||
/**
|
||||
* 距离描述(如:1.2km)
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String distanceDesc;
|
||||
|
||||
/**
|
||||
* 景区订单展示图片URL
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String orderShowImageUrl;
|
||||
|
||||
/**
|
||||
* 获取距离描述
|
||||
* @return 距离描述字符串
|
||||
*/
|
||||
public String getDistanceDesc() {
|
||||
if (distance == null) {
|
||||
return "未知距离";
|
||||
}
|
||||
|
||||
if (distance.compareTo(BigDecimal.ONE) < 0) {
|
||||
// 小于1公里,显示为米
|
||||
int meters = distance.multiply(new BigDecimal("1000")).intValue();
|
||||
return meters + "m";
|
||||
} else {
|
||||
// 大于等于1公里,显示为公里
|
||||
return distance.setScale(1, BigDecimal.ROUND_HALF_UP) + "km";
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 类特性
|
||||
|
||||
#### 2.1 继承关系
|
||||
- 继承自 `Tourism` 类,拥有所有景区基本信息
|
||||
- 使用 `@EqualsAndHashCode(callSuper = true)` 确保正确的继承行为
|
||||
|
||||
#### 2.2 新增字段
|
||||
- `distance`: 距离(公里),BigDecimal 类型,精确计算
|
||||
- `distanceDesc`: 距离描述,如 "1.2km" 或 "500m"
|
||||
- `orderShowImageUrl`: 景区订单展示图片URL
|
||||
|
||||
#### 2.3 智能距离描述
|
||||
- 自动根据距离大小选择合适的单位(米/公里)
|
||||
- 小于1公里显示为米,如 "500m"
|
||||
- 大于等于1公里显示为公里,如 "1.2km"
|
||||
- 支持自定义距离描述
|
||||
|
||||
### 3. 使用场景
|
||||
|
||||
#### 3.1 查询附近景区
|
||||
```java
|
||||
@GetMapping("/nearby")
|
||||
public Result<List<TourismWithDistance>> findNearbyTourisms(
|
||||
@RequestParam BigDecimal longitude,
|
||||
@RequestParam BigDecimal latitude,
|
||||
@RequestParam(required = false) Double radius,
|
||||
@RequestParam(required = false) Integer limit) {
|
||||
// 返回包含距离信息的景区列表
|
||||
}
|
||||
```
|
||||
|
||||
#### 3.2 数据库查询
|
||||
在 `TourismMapper.xml` 中,SQL 查询会自动计算距离:
|
||||
|
||||
```xml
|
||||
<select id="findNearbyTourisms" resultType="com.central.order.model.TourismWithDistance">
|
||||
<![CDATA[
|
||||
SELECT
|
||||
*,
|
||||
(
|
||||
6371 * acos(
|
||||
cos(radians(#{latitude})) *
|
||||
cos(radians(latitude)) *
|
||||
cos(radians(longitude) - radians(#{longitude})) +
|
||||
sin(radians(#{latitude})) *
|
||||
sin(radians(latitude))
|
||||
)
|
||||
) AS distance
|
||||
FROM tourisms
|
||||
WHERE is_del = 0
|
||||
AND status = 1
|
||||
AND longitude IS NOT NULL
|
||||
AND latitude IS NOT NULL
|
||||
HAVING distance <= #{radius}
|
||||
ORDER BY distance ASC
|
||||
]]>
|
||||
</select>
|
||||
```
|
||||
|
||||
### 4. 前端类型定义
|
||||
|
||||
在 `zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts` 中:
|
||||
|
||||
```typescript
|
||||
type TourismWithDistance = Tourism & {
|
||||
distance?: number; // 距离(公里)
|
||||
distanceDesc?: string; // 距离描述
|
||||
orderShowImageUrl?: string; // 景区订单展示图片URL
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 单元测试
|
||||
|
||||
创建了完整的单元测试 `TourismWithDistanceTest.java`,测试:
|
||||
- 距离描述计算
|
||||
- 继承关系
|
||||
- 订单展示图片URL
|
||||
- 自定义距离描述
|
||||
|
||||
## 修复效果
|
||||
|
||||
### ✅ 已修复的功能
|
||||
1. **查询附近景区接口** - 正常返回包含距离信息的景区列表
|
||||
2. **距离计算** - 自动计算并格式化距离显示
|
||||
3. **景区图片** - 支持设置和获取订单展示图片
|
||||
4. **类型安全** - 完整的类型定义和继承关系
|
||||
|
||||
### 🔧 技术特点
|
||||
- **精确计算**: 使用 BigDecimal 进行距离计算,避免浮点数精度问题
|
||||
- **智能显示**: 根据距离大小自动选择合适的单位
|
||||
- **类型安全**: 完整的 Lombok 注解和继承关系
|
||||
- **测试覆盖**: 完整的单元测试确保功能正确性
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 后端使用
|
||||
```java
|
||||
// 查询附近景区
|
||||
List<TourismWithDistance> nearbyTourisms = tourismService.findNearbyTourisms(
|
||||
new BigDecimal("116.397128"),
|
||||
new BigDecimal("39.916527"),
|
||||
10.0, // 10公里半径
|
||||
20 // 最多返回20个
|
||||
);
|
||||
|
||||
// 获取距离描述
|
||||
for (TourismWithDistance tourism : nearbyTourisms) {
|
||||
System.out.println(tourism.getTourismName() + ": " + tourism.getDistanceDesc());
|
||||
}
|
||||
```
|
||||
|
||||
### 前端使用
|
||||
```typescript
|
||||
// 调用附近景区接口
|
||||
const response = await findNearbyTourisms({
|
||||
longitude: 116.397128,
|
||||
latitude: 39.916527,
|
||||
radius: 10,
|
||||
limit: 20
|
||||
});
|
||||
|
||||
// 显示景区信息
|
||||
response.data.forEach(tourism => {
|
||||
console.log(`${tourism.tourismName}: ${tourism.distanceDesc}`);
|
||||
});
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **数据库字段**: 确保 `tourisms` 表中有 `longitude` 和 `latitude` 字段
|
||||
2. **索引优化**: 建议为经纬度字段添加索引以提高查询性能
|
||||
3. **距离计算**: 使用球面距离公式,适用于地球表面的距离计算
|
||||
4. **性能考虑**: 对于大量数据,建议添加适当的查询限制和缓存机制
|
||||
@@ -110,6 +110,7 @@ CREATE TABLE IF NOT EXISTS `t_coupon` (
|
||||
`valid_end_time` datetime NOT NULL COMMENT '有效期结束时间',
|
||||
`used_time` datetime DEFAULT NULL COMMENT '使用时间',
|
||||
`used_order_no` varchar(64) DEFAULT NULL COMMENT '使用订单号',
|
||||
`cancel_time` datetime DEFAULT NULL COMMENT '退券时间',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
|
||||
|
||||
+89
-20
@@ -19,6 +19,11 @@ import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.central.order.model.CtripCreateOrderRequest;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripOrderBody;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripOrderItem;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripPassenger;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripContact;
|
||||
|
||||
/**
|
||||
* 优惠券管理控制器
|
||||
@@ -121,29 +126,93 @@ public class CouponController {
|
||||
*/
|
||||
@Operation(summary = "携程创建优惠券接口")
|
||||
@PostMapping("/ctrip/create")
|
||||
public Result<Boolean> createCouponFromCtrip(
|
||||
@RequestParam String ctripCouponId,
|
||||
@RequestParam String userPhone,
|
||||
@RequestParam String couponName,
|
||||
@RequestParam Integer couponType,
|
||||
@RequestParam BigDecimal amount,
|
||||
@RequestParam(required = false) BigDecimal minAmount,
|
||||
@RequestParam(required = false) Integer discountRate,
|
||||
@RequestParam String validStartTime,
|
||||
@RequestParam String validEndTime) {
|
||||
// 幂等校验
|
||||
if (couponService.existsByUserPhoneAndCtripCouponId(userPhone, ctripCouponId)) {
|
||||
return Result.succeed(true);
|
||||
public Result<Boolean> createCouponFromCtripJson(@RequestBody CtripCreateOrderRequest request) {
|
||||
log.info("携程创建券请求:{}", request);
|
||||
|
||||
try {
|
||||
// 验证请求头
|
||||
if (request.getHeader() == null || request.getBody() == null) {
|
||||
return Result.failed("请求格式错误");
|
||||
}
|
||||
|
||||
// 从body中提取订单信息
|
||||
CtripOrderBody body = request.getBody();
|
||||
if (body.getItems() == null || body.getItems().isEmpty()) {
|
||||
return Result.failed("订单项不能为空");
|
||||
}
|
||||
|
||||
// 获取第一个订单项
|
||||
CtripOrderItem item = body.getItems().get(0);
|
||||
|
||||
// 获取乘客信息
|
||||
String userPhone = null;
|
||||
String userName = null;
|
||||
if (item.getPassengers() != null && !item.getPassengers().isEmpty()) {
|
||||
CtripPassenger passenger = item.getPassengers().get(0);
|
||||
userPhone = passenger.getMobile();
|
||||
userName = passenger.getName();
|
||||
}
|
||||
|
||||
// 获取联系人信息作为备选
|
||||
if (userPhone == null && body.getContacts() != null && !body.getContacts().isEmpty()) {
|
||||
CtripContact contact = body.getContacts().get(0);
|
||||
userPhone = contact.getMobile();
|
||||
userName = contact.getName();
|
||||
}
|
||||
|
||||
if (userPhone == null) {
|
||||
return Result.failed("无法获取用户手机号");
|
||||
}
|
||||
|
||||
// 构建优惠券信息
|
||||
String ctripCouponId = body.getOtaOrderId(); // 使用otaOrderId作为携程券ID
|
||||
String couponName = userName != null ? userName + "的携程优惠券" : "携程订单优惠券"; // 个性化名称
|
||||
Integer couponType = 1; // 默认类型:满减券
|
||||
BigDecimal amount = item.getSalePrice(); // 使用销售价格作为券面额
|
||||
BigDecimal minAmount = item.getPrice(); // 使用原价作为最低消费
|
||||
String validStartTime = item.getUseStartDate();
|
||||
String validEndTime = item.getUseEndDate();
|
||||
|
||||
// 幂等校验
|
||||
if (couponService.existsByUserPhoneAndCtripCouponId(userPhone, ctripCouponId)) {
|
||||
log.info("携程优惠券已存在,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
return Result.succeed(true);
|
||||
}
|
||||
|
||||
// 时间解析
|
||||
Date startTime = parseDate(validStartTime);
|
||||
Date endTime = parseDate(validEndTime);
|
||||
|
||||
// 验证时间
|
||||
if (startTime == null || endTime == null) {
|
||||
return Result.failed("时间格式错误");
|
||||
}
|
||||
|
||||
if (endTime.before(startTime)) {
|
||||
return Result.failed("结束时间不能早于开始时间");
|
||||
}
|
||||
|
||||
// 创建优惠券
|
||||
boolean result = couponService.createCouponFromCtrip(ctripCouponId, userPhone, couponName,
|
||||
couponType, amount, minAmount, null,
|
||||
startTime, endTime);
|
||||
|
||||
if (result) {
|
||||
log.info("携程优惠券创建成功,userPhone: {}, ctripCouponId: {}, amount: {}", userPhone, ctripCouponId, amount);
|
||||
return Result.succeed(true);
|
||||
} else {
|
||||
log.error("携程优惠券创建失败,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
return Result.failed("优惠券创建失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程创建券请求失败", e);
|
||||
return Result.failed("处理请求失败:" + e.getMessage());
|
||||
}
|
||||
// 时间解析
|
||||
Date startTime = parseDate(validStartTime);
|
||||
Date endTime = parseDate(validEndTime);
|
||||
boolean result = couponService.createCouponFromCtrip(ctripCouponId, userPhone, couponName,
|
||||
couponType, amount, minAmount, discountRate,
|
||||
startTime, endTime);
|
||||
return Result.succeed(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 携程取消优惠券接口
|
||||
*/
|
||||
|
||||
+28
-1
@@ -15,6 +15,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import com.central.order.model.vo.FilterOptions;
|
||||
import com.central.order.mapper.DashboardMapper;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -24,6 +27,7 @@ import java.util.Map;
|
||||
public class DashboardController {
|
||||
|
||||
private final IDashboardService dashboardService;
|
||||
private final DashboardMapper dashboardMapper;
|
||||
|
||||
@Operation(summary = "获取首页统计数据")
|
||||
@GetMapping("/statistics")
|
||||
@@ -32,7 +36,8 @@ public class DashboardController {
|
||||
@Parameter(description = "二维码ID") @RequestParam(required = false) String qrcodeId,
|
||||
@Parameter(description = "设备编号") @RequestParam(required = false) String deviceSn,
|
||||
@Parameter(description = "开始时间") @RequestParam(required = false) String startTime,
|
||||
@Parameter(description = "结束时间") @RequestParam(required = false) String endTime) {
|
||||
@Parameter(description = "结束时间") @RequestParam(required = false) String endTime,
|
||||
@Parameter(description = "是否包含测试二维码") @RequestParam(required = false, defaultValue = "false") Boolean includeTestQrcodes) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("tourismId", tourismId);
|
||||
@@ -40,6 +45,7 @@ public class DashboardController {
|
||||
params.put("deviceSn", deviceSn);
|
||||
params.put("startTime", startTime);
|
||||
params.put("endTime", endTime);
|
||||
params.put("includeTestQrcodes", includeTestQrcodes);
|
||||
|
||||
DashboardStatisticsVO statistics = dashboardService.getDashboardStatistics(params);
|
||||
return Result.succeed(statistics, "获取首页统计数据成功");
|
||||
@@ -48,4 +54,25 @@ public class DashboardController {
|
||||
return Result.failed("获取统计数据失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取二维码选项")
|
||||
@GetMapping("/qrcode/options")
|
||||
public Result<Map<String, Object>> getQrcodeOptions(
|
||||
@Parameter(description = "景区ID") @RequestParam(required = false) Long tourismId,
|
||||
@Parameter(description = "是否包含测试二维码") @RequestParam(required = false, defaultValue = "false") Boolean includeTestQrcodes) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("tourismId", tourismId);
|
||||
params.put("includeTestQrcodes", includeTestQrcodes);
|
||||
|
||||
List<FilterOptions.OptionItem> qrcodeList = dashboardMapper.getQrcodeOptions(params);
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("qrcodeList", qrcodeList);
|
||||
|
||||
return Result.succeed(result, "获取二维码选项成功");
|
||||
} catch (Exception e) {
|
||||
log.error("获取二维码选项失败", e);
|
||||
return Result.failed("获取二维码选项失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+109
-15
@@ -201,7 +201,7 @@ public class OrderController {
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
|
||||
order.setUserId(user.getId());
|
||||
order.setTenantId(TenantContextHolder.getTenant());
|
||||
|
||||
|
||||
List<Order> userOrderList = orderService.getOrderCountByStatusAndUser(user.getId(),OrderStatus.PAID.getId(),OrderStatus.UNPAID.getId());
|
||||
if (!userOrderList.isEmpty()){
|
||||
@@ -213,8 +213,8 @@ public class OrderController {
|
||||
if (qrCode.getStatus().equals(CommonStatus.UNABLE.getId())){
|
||||
return Result.failed("该二维码已过期");
|
||||
}
|
||||
order.setTenantId(qrCode.getTenantId());
|
||||
//设置订单所属tenantId
|
||||
TenantContextHolder.setTenant(qrCode.getTenantId());
|
||||
order.setTourismId(qrCode.getTourismId());
|
||||
order.setDeviceSn(qrCode.getDeviceSn());
|
||||
order.setOrderAmount(qrCode.getPrice());
|
||||
@@ -480,19 +480,29 @@ public class OrderController {
|
||||
@AuditLog(operation = "'机库更新订单完成状态:' + #payload")
|
||||
@PutMapping("/update")
|
||||
public Result<String> updateOrderStatusCompleted(@RequestBody Map payload) {
|
||||
Order order = orderService.getOrderByNumber(payload.get("orderNo").toString());
|
||||
Assert.notNull(order,"订单数据不能为空");
|
||||
if (order.getOrderStatus().equals(OrderStatus.DOING.getId())
|
||||
|| order.getOrderStatus().equals(OrderStatus.UPLOADED.getId())
|
||||
|| order.getOrderStatus().equals(OrderStatus.UPLOADING.getId())){
|
||||
order.setOrderStatus(OrderStatus.COMPLETE.getId());
|
||||
if (orderService.updateOrder(order)){
|
||||
return Result.succeed("更新成功");
|
||||
try {
|
||||
TenantContextHolder.setTenant("webApp");
|
||||
Order order = orderService.getOrderByNumber(payload.get("orderNo").toString());
|
||||
Assert.notNull(order,"订单数据不能为空");
|
||||
if (order.getOrderStatus().equals(OrderStatus.DOING.getId())
|
||||
|| order.getOrderStatus().equals(OrderStatus.UPLOADED.getId())
|
||||
|| order.getOrderStatus().equals(OrderStatus.UPLOADING.getId())){
|
||||
order.setOrderStatus(OrderStatus.COMPLETE.getId());
|
||||
log.info("更新订单时,租户ID:{}", TenantContextHolder.getTenant());
|
||||
if (orderService.updateOrder(order)){
|
||||
return Result.succeed("更新成功");
|
||||
}
|
||||
}else {
|
||||
return Result.failed("已更新");
|
||||
}
|
||||
}else {
|
||||
return Result.failed("已更新");
|
||||
return Result.failed("未查询到订单数据");
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
return Result.failed("未查询到订单数据");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Operation(summary = "取消订单")
|
||||
@@ -507,6 +517,21 @@ public class OrderController {
|
||||
return Result.failed("请重试");
|
||||
}
|
||||
|
||||
@Operation(summary = "删除订单(逻辑删除)")
|
||||
@DeleteMapping("/{orderNo}")
|
||||
public Result<String> deleteOrder(@PathVariable("orderNo") String orderNo) {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
order.setIsDel(1);
|
||||
boolean res = orderService.updateOrder(order);
|
||||
if (res) {
|
||||
return Result.succeed("删除成功");
|
||||
}
|
||||
return Result.failed("删除失败,请重试");
|
||||
}
|
||||
|
||||
@Operation(summary = "后台管理更新订单")
|
||||
@PostMapping("/update/order")
|
||||
public Result updateOrder(@RequestBody Order order) {
|
||||
@@ -647,6 +672,75 @@ public class OrderController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单号查询订单素材
|
||||
*/
|
||||
@Operation(summary = "根据订单号查询订单素材")
|
||||
@GetMapping("/user/files/{orderNo}")
|
||||
public Result<Map<String, Object>> getOrderFilesByOrderNo(@PathVariable("orderNo") String orderNo) {
|
||||
// 校验订单是否存在
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
|
||||
Map<String, Object> orderFileMap = new HashMap<>();
|
||||
orderFileMap.put("time", sdf.format(order.getCreateTime()));
|
||||
orderFileMap.put("addr", tourismService.getTourismById(order.getTourismId()).getTourismAddress());
|
||||
orderFileMap.put("orderNo", order.getOrderNo());
|
||||
|
||||
// 只查一次所有文件
|
||||
List<OrderFile> allFiles = orderFileService.getOrderFileByOrderNo(orderNo);
|
||||
|
||||
// aiVideo
|
||||
List<OrderFile> aiVideoFiles = allFiles.stream()
|
||||
.filter(f -> "ai_video".equals(f.getFileTag()))
|
||||
.toList();
|
||||
String aiVideoUrl = null;
|
||||
if (!aiVideoFiles.isEmpty()) {
|
||||
aiVideoUrl = fileCenterService.getViewUrlByPath(aiVideoFiles.get(0).getFilePath()).replace(cdnOssUrl, cdnUrl);
|
||||
}
|
||||
orderFileMap.put("aiVideo", aiVideoUrl);
|
||||
|
||||
// 图片素材
|
||||
List<OrderFile> imgFiles = allFiles.stream()
|
||||
.filter(f -> "image/jpeg".equals(f.getFileType()))
|
||||
.toList();
|
||||
List<Map<String,String>> imgList = new ArrayList<>();
|
||||
Map<String, String> fileMap = new HashMap<>();
|
||||
fileMap.put("style", fileStyle);
|
||||
for (OrderFile orderFile : imgFiles){
|
||||
Map<String,String> imgMap = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
imgMap.put("url", url.replace(cdnOssUrl, cdnUrl));
|
||||
imgMap.put("contentType", orderFile.getFileType());
|
||||
imgMap.put("path", orderFile.getFilePath());
|
||||
fileMap.put("path",orderFile.getFilePath());
|
||||
imgMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
|
||||
imgList.add(imgMap);
|
||||
}
|
||||
orderFileMap.put("imgList", imgList);
|
||||
|
||||
// 视频素材
|
||||
List<OrderFile> videoFiles = allFiles.stream()
|
||||
.filter(f -> "raw_video".equals(f.getFileTag()))
|
||||
.toList();
|
||||
List<Map<String,String>> videoList = new ArrayList<>();
|
||||
for (OrderFile orderFile : videoFiles){
|
||||
Map<String,String> videoMap = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
videoMap.put("url", url.replace(cdnOssUrl, cdnUrl));
|
||||
videoMap.put("contentType", orderFile.getFileType());
|
||||
videoMap.put("path", orderFile.getFilePath());
|
||||
fileMap.put("path",orderFile.getFilePath());
|
||||
videoMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
|
||||
videoList.add(videoMap);
|
||||
}
|
||||
orderFileMap.put("videoList", videoList);
|
||||
|
||||
return Result.succeed(orderFileMap, "查询成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将分的价格转换为元的str,方便前端显示
|
||||
* @param str
|
||||
@@ -758,8 +852,8 @@ public class OrderController {
|
||||
.toList();
|
||||
String aiVideoUrl = null;
|
||||
if (!aiVideoFiles.isEmpty()) {
|
||||
fileMap.put("path", aiVideoFiles.get(0).getFilePath());
|
||||
aiVideoUrl = fileCenterService.getViewUrlByPathStyle(fileMap);
|
||||
// fileMap.put("path", aiVideoFiles.get(0).getFilePath());
|
||||
aiVideoUrl = fileCenterService.getViewUrlByPath(aiVideoFiles.get(0).getFilePath()).replace(cdnOssUrl, cdnUrl);
|
||||
}
|
||||
orderFileMap.put("aiVideo", aiVideoUrl);
|
||||
|
||||
|
||||
+11
@@ -1,6 +1,7 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.*;
|
||||
import com.central.order.constants.EditTaskStatus;
|
||||
import com.central.order.enums.OrderStatus;
|
||||
@@ -179,6 +180,7 @@ public class OrderFileController {
|
||||
@PostMapping("/path")
|
||||
public Result createOrderFileForPath(@RequestBody OrderFile orderFile) {
|
||||
try {
|
||||
TenantContextHolder.setTenant("webApp");
|
||||
if (orderFile == null || orderFile.getOrderNo() == null) {
|
||||
log.warn("参数为空,orderFile: {}", orderFile);
|
||||
return Result.failed(orderFile,"参数为空");
|
||||
@@ -247,6 +249,8 @@ public class OrderFileController {
|
||||
} catch (Exception e) {
|
||||
log.error("素材记录创建异常", e);
|
||||
return Result.failed(orderFile,"素材记录创建异常: " + e.getMessage());
|
||||
}finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,6 +290,13 @@ public class OrderFileController {
|
||||
log.info("二维码已开启一键成片功能,开始触发一键成片: orderNo={}, codeId={}",
|
||||
order.getOrderNo(), order.getCodeId());
|
||||
|
||||
// 检查是否存在进行中的编辑任务
|
||||
EditTask existingTask = editTaskService.getTaskByOrderSn(order.getOrderNo());
|
||||
if (existingTask != null && EditTaskStatus.isProcessing(existingTask.getStatus())) {
|
||||
log.info("已存在进行中的编辑任务: orderNo={}, taskId={}", order.getOrderNo(), existingTask.getId());
|
||||
return ;
|
||||
}
|
||||
|
||||
//触发一键成片
|
||||
// 1. 创建新任务
|
||||
EditTask task = editTaskService.createTask(order.getOrderNo(), order.getUserId());
|
||||
|
||||
+7
-1
@@ -1,5 +1,6 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysUser;
|
||||
@@ -9,12 +10,12 @@ import com.central.order.feign.UserCenterService;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.model.QrCode;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import com.central.order.service.IRefundService;
|
||||
import com.central.order.service.IWxTemplateMessageService;
|
||||
import com.central.wechat.config.WxPayConfigFactory;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.feign.WechatConfigService;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import com.wechat.pay.java.service.refund.RefundService;
|
||||
import com.wechat.pay.java.service.refund.model.AmountReq;
|
||||
import com.wechat.pay.java.service.refund.model.CreateRequest;
|
||||
@@ -116,6 +117,7 @@ public class RefundController {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<com.central.order.model.Refund> approveOrder(@RequestBody com.central.order.model.Refund refund) {
|
||||
|
||||
log.info("审批退款单,订单号: {}, 退款单号: {}", refund.getOrderNo(), refund.getRefundNo());
|
||||
// 检查订单是否存在
|
||||
Order order = orderService.getOrderByNumber(refund.getOrderNo());
|
||||
Assert.notNull(order, "ORDER DATA不存在");
|
||||
@@ -145,6 +147,8 @@ public class RefundController {
|
||||
public Result<String> autoRefundProcess(@RequestBody Map payload) {
|
||||
String orderNo = payload.get("orderNo").toString();
|
||||
Assert.notNull(orderNo,"订单数据不能为空");
|
||||
//机库端触发异常后自动创建退款单,没有带请求头信息,因此没有租户ID @TODO
|
||||
TenantContextHolder.setTenant("webApp");
|
||||
log.info("收到自动退款请求,订单号: {}", orderNo);
|
||||
try {
|
||||
|
||||
@@ -214,6 +218,8 @@ public class RefundController {
|
||||
} catch (Exception e) {
|
||||
log.error("退款流程测试失败,订单号: {},异常: {}", orderNo, e.getMessage(), e);
|
||||
return Result.failed("退款流程测试失败:" + e.getMessage());
|
||||
}finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+84
-2
@@ -6,6 +6,7 @@ import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
import com.central.order.service.ITourismService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -18,17 +19,21 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Tourism information
|
||||
* 景区管理控制器
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:51:47
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "Tourism管理")
|
||||
@Tag(name = "景区管理")
|
||||
@RequestMapping("/tourism")
|
||||
@RequiredArgsConstructor
|
||||
public class TourismController {
|
||||
@@ -91,4 +96,81 @@ public class TourismController {
|
||||
return Result.failed("获取景区设备列表失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询附近景区列表
|
||||
*/
|
||||
@Operation(summary = "查询附近景区列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "longitude", description = "经度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "latitude", description = "纬度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "radius", description = "搜索半径(公里),默认10km", required = false, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "limit", description = "返回数量限制,默认20个", required = false, in = ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping("/nearby")
|
||||
public Result<List<TourismWithDistance>> findNearbyTourisms(
|
||||
@RequestParam BigDecimal longitude,
|
||||
@RequestParam BigDecimal latitude,
|
||||
@RequestParam(required = false) Double radius,
|
||||
@RequestParam(required = false) Integer limit) {
|
||||
try {
|
||||
log.info("查询附近景区,经度: {}, 纬度: {}, 半径: {}km, 限制数量: {}", longitude, latitude, radius, limit);
|
||||
List<TourismWithDistance> tourisms = tourismService.findNearbyTourisms(longitude, latitude, radius, limit);
|
||||
return Result.succeed(tourisms, "查询附近景区成功");
|
||||
} catch (Exception e) {
|
||||
log.error("查询附近景区失败", e);
|
||||
return Result.failed("查询附近景区失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度范围查询景区
|
||||
*/
|
||||
@Operation(summary = "根据经纬度范围查询景区")
|
||||
@Parameters({
|
||||
@Parameter(name = "minLongitude", description = "最小经度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "maxLongitude", description = "最大经度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "minLatitude", description = "最小纬度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "maxLatitude", description = "最大纬度", required = true, in = ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping("/bounds")
|
||||
public Result<List<Tourism>> findTourismsByBounds(
|
||||
@RequestParam BigDecimal minLongitude,
|
||||
@RequestParam BigDecimal maxLongitude,
|
||||
@RequestParam BigDecimal minLatitude,
|
||||
@RequestParam BigDecimal maxLatitude) {
|
||||
try {
|
||||
log.info("根据经纬度范围查询景区,经度范围: [{}, {}], 纬度范围: [{}, {}]",
|
||||
minLongitude, maxLongitude, minLatitude, maxLatitude);
|
||||
List<Tourism> tourisms = tourismService.findTourismsByBounds(minLongitude, maxLongitude, minLatitude, maxLatitude);
|
||||
return Result.succeed(tourisms, "查询景区成功");
|
||||
} catch (Exception e) {
|
||||
log.error("根据经纬度范围查询景区失败", e);
|
||||
return Result.failed("查询景区失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新景区经纬度信息
|
||||
*/
|
||||
@Operation(summary = "更新景区经纬度信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "景区ID", required = true, in = ParameterIn.PATH),
|
||||
@Parameter(name = "longitude", description = "经度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "latitude", description = "纬度", required = true, in = ParameterIn.QUERY)
|
||||
})
|
||||
@PutMapping("/{id}/location")
|
||||
public Result updateTourismLocation(
|
||||
@PathVariable Long id,
|
||||
@RequestParam BigDecimal longitude,
|
||||
@RequestParam BigDecimal latitude) {
|
||||
try {
|
||||
log.info("更新景区经纬度信息,景区ID: {}, 经度: {}, 纬度: {}", id, longitude, latitude);
|
||||
return tourismService.updateTourismLocation(id, longitude, latitude);
|
||||
} catch (Exception e) {
|
||||
log.error("更新景区经纬度信息失败", e);
|
||||
return Result.failed("更新景区经纬度信息失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,5 +1,6 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.order.enums.OrderStatus;
|
||||
import com.central.order.enums.RefundState;
|
||||
import com.central.order.model.Order;
|
||||
@@ -69,6 +70,8 @@ public class WxPayController {
|
||||
WechatConfig config = wechatConfigService.getConfigBySerialNumber(serial);
|
||||
Assert.notNull(config,"支付配置参数为空,请确认参数是否正确配置");
|
||||
String tenantId = config.getTenantId();
|
||||
log.info("订单支付回调租户ID设置,租户ID:{}", tenantId);
|
||||
TenantContextHolder.setTenant(tenantId);
|
||||
|
||||
// 创建通知解析器
|
||||
NotificationParser notificationParser;
|
||||
@@ -120,7 +123,7 @@ public class WxPayController {
|
||||
* 处理服务商模式下的支付结果
|
||||
*/
|
||||
private void handleSubMerchantPaymentResult(Transaction transaction, WechatConfig config) {
|
||||
|
||||
|
||||
log.info("处理服务商模式支付结果,子商户号:{}", config.getSubMchId());
|
||||
|
||||
String outTradeNo = transaction.getOutTradeNo();
|
||||
@@ -211,6 +214,8 @@ public class WxPayController {
|
||||
WechatConfig config = wechatConfigService.getConfigBySerialNumber(serial);
|
||||
Assert.notNull(config,"支付配置参数为空,请确认参数是否正确配置");
|
||||
String tenantId = config.getTenantId();
|
||||
log.info("订单退款回调租户ID设置,租户ID:{}", tenantId);
|
||||
TenantContextHolder.setTenant(tenantId);
|
||||
|
||||
// 创建通知解析器
|
||||
NotificationParser notificationParser;
|
||||
@@ -262,7 +267,7 @@ public class WxPayController {
|
||||
* 处理服务商模式下的退款结果
|
||||
*/
|
||||
private void handleSubMerchantRefundResult(RefundNotification notification, WechatConfig config) {
|
||||
|
||||
|
||||
log.info("处理服务商模式退款结果,子商户号:{}", config.getSubMchId());
|
||||
|
||||
// 获取退款通知中的关键信息
|
||||
|
||||
+160
-84
@@ -14,21 +14,26 @@ public interface DashboardMapper {
|
||||
// 基础订单统计(支持筛选)
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COUNT(*) FROM orders WHERE is_del = 0",
|
||||
"SELECT COUNT(*) FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
"</if>",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND code_id = #{p.qrcodeId}",
|
||||
" AND o.code_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND o.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND o.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND o.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
@@ -36,15 +41,21 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COUNT(*) FROM orders WHERE is_del = 0 AND DATE(create_time) = CURDATE()",
|
||||
"SELECT COUNT(*) FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
"</if>",
|
||||
"AND DATE(o.create_time) = CURDATE()",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND code_id = #{p.qrcodeId}",
|
||||
" AND o.code_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND o.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
@@ -52,15 +63,21 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COUNT(*) FROM orders WHERE is_del = 0 AND DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)",
|
||||
"SELECT COUNT(*) FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
"</if>",
|
||||
"AND DATE(o.create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND code_id = #{p.qrcodeId}",
|
||||
" AND o.code_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND o.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
@@ -68,21 +85,27 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COUNT(*) FROM orders WHERE is_del = 0 AND order_status = 3",
|
||||
"SELECT COUNT(*) FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
"</if>",
|
||||
"AND o.order_status = 3",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND code_id = #{p.qrcodeId}",
|
||||
" AND o.code_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND o.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND o.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND o.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
@@ -91,18 +114,22 @@ public interface DashboardMapper {
|
||||
// 对账相关统计
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COALESCE(SUM(order_amount), 0)",
|
||||
"FROM orders",
|
||||
"WHERE is_del = 0",
|
||||
"AND (order_status = 3 OR order_status = 8)",
|
||||
"SELECT COALESCE(SUM(o.order_amount), 0)",
|
||||
"FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
"</if>",
|
||||
"AND (o.order_status = 3 OR o.order_status = 8)",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND o.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND o.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
@@ -110,23 +137,26 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COALESCE(SUM(platform_amount), 0)",
|
||||
"FROM order_statistics",
|
||||
"SELECT COALESCE(SUM(os.platform_amount), 0)",
|
||||
"FROM order_statistics os",
|
||||
"WHERE 1=1",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND os.qrcode_id IN (SELECT code_id FROM qrcodes WHERE is_test = 0)",
|
||||
"</if>",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND os.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND qrcode_id = #{p.qrcodeId}",
|
||||
" AND os.qrcode_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND os.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND os.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND os.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
@@ -134,23 +164,26 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COALESCE(SUM(tourism_amount), 0)",
|
||||
"FROM order_statistics",
|
||||
"SELECT COALESCE(SUM(os.tourism_amount), 0)",
|
||||
"FROM order_statistics os",
|
||||
"WHERE 1=1",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND os.qrcode_id IN (SELECT code_id FROM qrcodes WHERE is_test = 0)",
|
||||
"</if>",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND os.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND qrcode_id = #{p.qrcodeId}",
|
||||
" AND os.qrcode_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND os.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND os.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND os.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
@@ -161,7 +194,11 @@ public interface DashboardMapper {
|
||||
"SELECT COALESCE(SUM(CAST(r.refund_amount AS SIGNED)), 0)",
|
||||
"FROM orders_refund r",
|
||||
"JOIN orders o ON r.order_no = o.order_no",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE r.status = 8",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
"</if>",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
@@ -179,22 +216,26 @@ public interface DashboardMapper {
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT",
|
||||
" DATE_FORMAT(create_time, '%Y-%m-%d') as date,",
|
||||
" DATE_FORMAT(o.create_time, '%Y-%m-%d') as date,",
|
||||
" 'orders' as type,",
|
||||
" COUNT(*) as value",
|
||||
"FROM orders",
|
||||
"WHERE is_del = 0",
|
||||
" AND create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)",
|
||||
"FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
"</if>",
|
||||
" AND o.create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND code_id = #{p.qrcodeId}",
|
||||
" AND o.code_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND o.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')",
|
||||
"GROUP BY DATE_FORMAT(o.create_time, '%Y-%m-%d')",
|
||||
"ORDER BY date",
|
||||
"</script>"
|
||||
})
|
||||
@@ -203,7 +244,7 @@ public interface DashboardMapper {
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT",
|
||||
" CASE order_status",
|
||||
" CASE o.order_status",
|
||||
" WHEN 0 THEN '待支付'",
|
||||
" WHEN 1 THEN '已支付排队中'",
|
||||
" WHEN 2 THEN '已取消'",
|
||||
@@ -217,24 +258,28 @@ public interface DashboardMapper {
|
||||
" ELSE '其他'",
|
||||
" END as type,",
|
||||
" COUNT(*) as value",
|
||||
"FROM orders",
|
||||
"WHERE is_del = 0",
|
||||
"FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND q.is_test = 0",
|
||||
"</if>",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND code_id = #{p.qrcodeId}",
|
||||
" AND o.code_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND o.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND o.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND o.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"GROUP BY order_status",
|
||||
"GROUP BY o.order_status",
|
||||
"</script>"
|
||||
})
|
||||
List<DistributionDataVO> getOrderDistribution(@Param("p") Map<String, Object> params);
|
||||
@@ -243,77 +288,108 @@ public interface DashboardMapper {
|
||||
"<script>",
|
||||
"SELECT",
|
||||
" '平台分账' as type,",
|
||||
" COALESCE(SUM(platform_amount), 0) as value",
|
||||
"FROM order_statistics",
|
||||
" COALESCE(SUM(os.platform_amount), 0) as value",
|
||||
"FROM order_statistics os",
|
||||
"WHERE 1=1",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND os.qrcode_id IN (SELECT code_id FROM qrcodes WHERE is_test = 0)",
|
||||
"</if>",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND os.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND qrcode_id = #{p.qrcodeId}",
|
||||
" AND os.qrcode_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND os.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND os.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND os.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"UNION ALL",
|
||||
"SELECT",
|
||||
" '景区分账' as type,",
|
||||
" COALESCE(SUM(tourism_amount), 0) as value",
|
||||
"FROM order_statistics",
|
||||
" COALESCE(SUM(os.tourism_amount), 0) as value",
|
||||
"FROM order_statistics os",
|
||||
"WHERE 1=1",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND os.qrcode_id IN (SELECT code_id FROM qrcodes WHERE is_test = 0)",
|
||||
"</if>",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND os.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND qrcode_id = #{p.qrcodeId}",
|
||||
" AND os.qrcode_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND os.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND os.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND os.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"UNION ALL",
|
||||
"SELECT",
|
||||
" '退款金额' as type,",
|
||||
" COALESCE(SUM(refund_amount), 0) as value",
|
||||
"FROM order_statistics",
|
||||
" COALESCE(SUM(os.refund_amount), 0) as value",
|
||||
"FROM order_statistics os",
|
||||
"WHERE 1=1",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND os.qrcode_id IN (SELECT code_id FROM qrcodes WHERE is_test = 0)",
|
||||
"</if>",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
" AND os.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND qrcode_id = #{p.qrcodeId}",
|
||||
" AND os.qrcode_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND device_sn = #{p.deviceSn}",
|
||||
" AND os.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND create_time >= #{p.startTime}",
|
||||
" AND os.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
"<if test='p.endTime != null and p.endTime != \"\"'>",
|
||||
" AND create_time <= #{p.endTime}",
|
||||
" AND os.create_time <= #{p.endTime}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
List<IncomeDataVO> getIncomeBreakdown(@Param("p") Map<String, Object> params);
|
||||
|
||||
// 筛选选项
|
||||
@Select("SELECT id as value, tourism_name as label FROM tourisms WHERE is_del = 0 ORDER BY tourism_name")
|
||||
@Select("SELECT id as value, tourism_name as label FROM tourisms WHERE is_del = 0 ORDER BY create_time DESC")
|
||||
List<FilterOptions.OptionItem> getTourismOptions();
|
||||
|
||||
@Select("SELECT code_id as value, CONCAT(name, ' | ', device_sn) as label FROM qrcodes WHERE is_del = 0 ORDER BY name")
|
||||
List<FilterOptions.OptionItem> getQrcodeOptions();
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT code_id as value, name as label FROM qrcodes",
|
||||
"WHERE is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND is_test = 0",
|
||||
"</if>",
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"ORDER BY create_time DESC",
|
||||
"</script>"
|
||||
})
|
||||
List<FilterOptions.OptionItem> getQrcodeOptions(@Param("p") Map<String, Object> params);
|
||||
|
||||
@Select("SELECT DISTINCT device_sn as value, device_sn as label FROM orders WHERE device_sn IS NOT NULL AND device_sn != '' ORDER BY device_sn")
|
||||
List<FilterOptions.OptionItem> getDeviceOptions();
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT DISTINCT device_sn as value, device_sn as label FROM qrcodes",
|
||||
"WHERE is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
" AND is_test = 0",
|
||||
"</if>",
|
||||
"AND device_sn IS NOT NULL",
|
||||
"ORDER BY device_sn",
|
||||
"</script>"
|
||||
})
|
||||
List<FilterOptions.OptionItem> getDeviceOptions(@Param("p") Map<String, Object> params);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.central.order.mapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.db.mapper.SuperMapper;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -40,4 +42,34 @@ public interface TourismMapper extends SuperMapper<Tourism> {
|
||||
*/
|
||||
List<Map<String, Object>> getDevicesByTourismId(@Param("tourismId") Long tourismId);
|
||||
|
||||
/**
|
||||
* 查询附近景区列表
|
||||
* @param longitude 经度
|
||||
* @param latitude 纬度
|
||||
* @param radius 搜索半径(公里)
|
||||
* @param limit 返回数量限制
|
||||
* @return 附近景区列表(包含距离信息)
|
||||
*/
|
||||
List<TourismWithDistance> findNearbyTourisms(
|
||||
@Param("longitude") BigDecimal longitude,
|
||||
@Param("latitude") BigDecimal latitude,
|
||||
@Param("radius") Double radius,
|
||||
@Param("limit") Integer limit
|
||||
);
|
||||
|
||||
/**
|
||||
* 根据经纬度范围查询景区
|
||||
* @param minLongitude 最小经度
|
||||
* @param maxLongitude 最大经度
|
||||
* @param minLatitude 最小纬度
|
||||
* @param maxLatitude 最大纬度
|
||||
* @return 景区列表
|
||||
*/
|
||||
List<Tourism> findTourismsByBounds(
|
||||
@Param("minLongitude") BigDecimal minLongitude,
|
||||
@Param("maxLongitude") BigDecimal maxLongitude,
|
||||
@Param("minLatitude") BigDecimal minLatitude,
|
||||
@Param("maxLatitude") BigDecimal maxLatitude
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程创建订单请求
|
||||
*/
|
||||
@Data
|
||||
public class CtripCreateOrderRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
private CtripHeader header;
|
||||
|
||||
/**
|
||||
* 请求体
|
||||
*/
|
||||
private CtripOrderBody body;
|
||||
|
||||
/**
|
||||
* 携程请求头
|
||||
*/
|
||||
@Data
|
||||
public static class CtripHeader {
|
||||
private String requestTime;
|
||||
private String accountId;
|
||||
private String sign;
|
||||
private String serviceName;
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单体
|
||||
*/
|
||||
@Data
|
||||
public static class CtripOrderBody {
|
||||
private String otaOrderId;
|
||||
private String sequenceId;
|
||||
private List<CtripOrderItem> items;
|
||||
private List<CtripContact> contacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单项
|
||||
*/
|
||||
@Data
|
||||
public static class CtripOrderItem {
|
||||
private List<CtripPassenger> passengers;
|
||||
private java.math.BigDecimal cost;
|
||||
private Integer quantity;
|
||||
private java.math.BigDecimal salePrice;
|
||||
private String remark;
|
||||
private String useEndDate;
|
||||
private String locale;
|
||||
private String useStartDate;
|
||||
private String priceCurrency;
|
||||
private List<Object> adjunctions;
|
||||
private java.math.BigDecimal price;
|
||||
private String PLU;
|
||||
private Object deposit;
|
||||
private String distributionChannel;
|
||||
private String costCurrency;
|
||||
private String salePriceCurrency;
|
||||
private CtripExpressDelivery expressDelivery;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程乘客信息
|
||||
*/
|
||||
@Data
|
||||
public static class CtripPassenger {
|
||||
private String cardIssuePlace;
|
||||
private String lastName;
|
||||
private String cardIssueCountry;
|
||||
private Integer shoeSize;
|
||||
private String gender;
|
||||
private String cardIssueDate;
|
||||
private String intlCode;
|
||||
private String nationalityName;
|
||||
private String mobile;
|
||||
private String cardType;
|
||||
private Integer weight;
|
||||
private Integer myopiaDegreeL;
|
||||
private String birthDate;
|
||||
private String cardNo;
|
||||
private String ageType;
|
||||
private Integer myopiaDegreeR;
|
||||
private String firstName;
|
||||
private String birthPlace;
|
||||
private String nationalityCode;
|
||||
private String name;
|
||||
private String passengerId;
|
||||
private String cardValidDate;
|
||||
private Integer height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程联系人信息
|
||||
*/
|
||||
@Data
|
||||
public static class CtripContact {
|
||||
private String intlCode;
|
||||
private String name;
|
||||
private String mobile;
|
||||
private String optionalMobile;
|
||||
private String optionalIntlCode;
|
||||
private String email;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程快递信息
|
||||
*/
|
||||
@Data
|
||||
public static class CtripExpressDelivery {
|
||||
private String type;
|
||||
}
|
||||
}
|
||||
@@ -99,4 +99,10 @@ public class QrCode extends SuperEntity {
|
||||
@Schema(description = "素材数量")
|
||||
private Integer materialCount;
|
||||
|
||||
/**
|
||||
* 是否为测试二维码(0:否,1:是)
|
||||
*/
|
||||
@Schema(description = "是否为测试二维码")
|
||||
private Integer isTest;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Device information
|
||||
* 景区信息实体类
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:51:47
|
||||
@@ -34,6 +35,16 @@ public class Tourism extends SuperEntity {
|
||||
private String tourismPhone;
|
||||
private String tourismEmail;
|
||||
|
||||
/**
|
||||
* 景区经度
|
||||
*/
|
||||
private BigDecimal longitude;
|
||||
|
||||
/**
|
||||
* 景区纬度
|
||||
*/
|
||||
private BigDecimal latitude;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 景区信息实体类(包含距离信息)
|
||||
* 用于查询附近景区时返回距离信息
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:51:47
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TourismWithDistance extends Tourism {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 距离(公里)
|
||||
*/
|
||||
private BigDecimal distance;
|
||||
|
||||
/**
|
||||
* 距离描述(如:1.2km)
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String distanceDesc;
|
||||
|
||||
/**
|
||||
* 景区订单展示图片URL
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String orderShowImageUrl;
|
||||
|
||||
/**
|
||||
* 获取距离描述
|
||||
* @return 距离描述字符串
|
||||
*/
|
||||
public String getDistanceDesc() {
|
||||
if (distance == null) {
|
||||
return "未知距离";
|
||||
}
|
||||
|
||||
if (distance.compareTo(BigDecimal.ONE) < 0) {
|
||||
// 小于1公里,显示为米
|
||||
int meters = distance.multiply(new BigDecimal("1000")).intValue();
|
||||
return meters + "m";
|
||||
} else {
|
||||
// 大于等于1公里,显示为公里
|
||||
return distance.setScale(1, BigDecimal.ROUND_HALF_UP) + "km";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置距离描述
|
||||
* @param distanceDesc 距离描述
|
||||
*/
|
||||
public void setDistanceDesc(String distanceDesc) {
|
||||
this.distanceDesc = distanceDesc;
|
||||
}
|
||||
}
|
||||
+13
-8
@@ -1,12 +1,15 @@
|
||||
package com.central.order.scheduler;
|
||||
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.order.service.IOrderService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
@@ -18,14 +21,16 @@ public class OrderScheduler {
|
||||
// 每隔一定时间(这里设置为每分钟检查一次,可根据实际情况调整)检查订单超时情况
|
||||
@Scheduled(fixedRate = 60 * 1000)
|
||||
public void checkOrderTimeout() {
|
||||
orderService.checkAndHandleOrderTimeout();
|
||||
log.debug("开始执行订单超时检查任务");
|
||||
try {
|
||||
TenantContextHolder.setTenant("webApp");
|
||||
orderService.checkAndHandleOrderTimeout();
|
||||
log.debug("订单超时检查任务执行完成");
|
||||
} catch (Exception e) {
|
||||
log.error("订单超时检查任务执行失败", e);
|
||||
} finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// 每隔一定时间(这里设置为每分钟检查一次,可根据实际情况调整)检查是否存在未服务完成的订单
|
||||
// @Scheduled(fixedRate = 60 * 1000)
|
||||
public void processOrdersInQueue() {
|
||||
orderService.processOrdersInQueue();
|
||||
}
|
||||
@Scheduled(fixedRate = 2 * 60 * 1000)
|
||||
public void processOrdersCompleted() {}
|
||||
}
|
||||
|
||||
+34
-1
@@ -4,11 +4,14 @@ import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.service.ISuperService;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Firmware file information
|
||||
* 景区信息服务接口
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:52:54
|
||||
@@ -43,5 +46,35 @@ public interface ITourismService extends ISuperService<Tourism> {
|
||||
* @return 设备列表
|
||||
*/
|
||||
java.util.List<java.util.Map<String, Object>> getDevicesByTourismId(Long tourismId);
|
||||
|
||||
/**
|
||||
* 查询附近景区列表
|
||||
* @param longitude 经度
|
||||
* @param latitude 纬度
|
||||
* @param radius 搜索半径(公里)
|
||||
* @param limit 返回数量限制
|
||||
* @return 附近景区列表(包含距离信息)
|
||||
*/
|
||||
List<TourismWithDistance> findNearbyTourisms(BigDecimal longitude, BigDecimal latitude, Double radius, Integer limit);
|
||||
|
||||
/**
|
||||
* 根据经纬度范围查询景区
|
||||
* @param minLongitude 最小经度
|
||||
* @param maxLongitude 最大经度
|
||||
* @param minLatitude 最小纬度
|
||||
* @param maxLatitude 最大纬度
|
||||
* @return 景区列表
|
||||
*/
|
||||
List<Tourism> findTourismsByBounds(BigDecimal minLongitude, BigDecimal maxLongitude,
|
||||
BigDecimal minLatitude, BigDecimal maxLatitude);
|
||||
|
||||
/**
|
||||
* 更新景区经纬度信息
|
||||
* @param id 景区ID
|
||||
* @param longitude 经度
|
||||
* @param latitude 纬度
|
||||
* @return 更新结果
|
||||
*/
|
||||
Result updateTourismLocation(Long id, BigDecimal longitude, BigDecimal latitude);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -31,7 +31,7 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
statistics.setChartStats(getChartStatistics(params));
|
||||
|
||||
// 3. 获取筛选选项
|
||||
statistics.setFilterOptions(getFilterOptions());
|
||||
statistics.setFilterOptions(getFilterOptions(params));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取仪表盘统计数据失败", e);
|
||||
@@ -102,17 +102,17 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
/**
|
||||
* 获取筛选选项
|
||||
*/
|
||||
private FilterOptions getFilterOptions() {
|
||||
private FilterOptions getFilterOptions(Map<String, Object> params) {
|
||||
FilterOptions options = new FilterOptions();
|
||||
|
||||
// 获取景区列表
|
||||
options.setTourismList(dashboardMapper.getTourismOptions());
|
||||
|
||||
// 获取二维码列表
|
||||
options.setQrcodeList(dashboardMapper.getQrcodeOptions());
|
||||
options.setQrcodeList(dashboardMapper.getQrcodeOptions(params));
|
||||
|
||||
// 获取设备列表
|
||||
options.setDeviceList(dashboardMapper.getDeviceOptions());
|
||||
options.setDeviceList(dashboardMapper.getDeviceOptions(params));
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
+5
@@ -187,6 +187,7 @@ public class MediaServiceImpl implements IMediaService {
|
||||
Map<String, String> clips = new HashMap<>();
|
||||
List<OrderFile> videoFiles = taskData.getVideoFiles();
|
||||
//@TODO 后期需要通过模板参数进行动态设置clips参数
|
||||
|
||||
clips.put("1", fileCenterService.getViewUrlByPath(videoFiles.get(4).getFilePath()));
|
||||
clips.put("2", fileCenterService.getViewUrlByPath(videoFiles.get(5).getFilePath()));
|
||||
clips.put("3", fileCenterService.getViewUrlByPath(videoFiles.get(6).getFilePath()));
|
||||
@@ -195,6 +196,10 @@ public class MediaServiceImpl implements IMediaService {
|
||||
clips.put("6", fileCenterService.getViewUrlByPath(videoFiles.get(2).getFilePath()));
|
||||
clips.put("7", fileCenterService.getViewUrlByPath(videoFiles.get(3).getFilePath()));
|
||||
|
||||
if (taskData.getVideoFiles().size() > 7) {
|
||||
clips.put("8", fileCenterService.getViewUrlByPath(videoFiles.get(7).getFilePath()));
|
||||
}
|
||||
|
||||
return JSON.toJSONString(clips);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("构建剪辑参数失败: " + e.getMessage());
|
||||
|
||||
+33
-7
@@ -3,14 +3,15 @@ package com.central.order.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.lock.DistributedLock;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.order.enums.OrderStatus;
|
||||
import com.central.order.event.OrderStatusChangeEvent;
|
||||
import com.central.order.feign.UserCenterService;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.feign.UserCenterService;
|
||||
import com.central.order.mapper.OrderFileMapper;
|
||||
import com.central.order.mapper.OrderMapper;
|
||||
import com.central.order.mapper.TourismFileMapper;
|
||||
@@ -127,14 +128,33 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
// 检查并处理订单超时逻辑,5分钟超时后自动取消
|
||||
@Override
|
||||
public void checkAndHandleOrderTimeout() {
|
||||
log.info("开始检查订单超时情况");
|
||||
|
||||
List<Order> orders = baseMapper.getOrdersByStatus(OrderStatus.UNPAID.getId());
|
||||
log.info("查询到 {} 个待支付订单", orders.size());
|
||||
|
||||
long currentTime = new Date().getTime();
|
||||
int timeoutCount = 0;
|
||||
|
||||
for (Order order : orders) {
|
||||
long elapsedTime = currentTime - order.getCreateTime().getTime();
|
||||
if (TimeUnit.MILLISECONDS.toMinutes(elapsedTime) >= 5) {
|
||||
long elapsedMinutes = TimeUnit.MILLISECONDS.toMinutes(elapsedTime);
|
||||
|
||||
log.info("订单检查: orderNo={}, createTime={}, elapsedMinutes={}, userId={}, tourismId={}",
|
||||
order.getOrderNo(),
|
||||
order.getCreateTime(),
|
||||
elapsedMinutes,
|
||||
order.getUserId(),
|
||||
order.getTourismId());
|
||||
|
||||
if (elapsedMinutes >= 5) {
|
||||
log.info("订单超时,准备取消: orderNo={}, elapsedMinutes={}", order.getOrderNo(), elapsedMinutes);
|
||||
baseMapper.updateOrderStatus(order.getId(), OrderStatus.CANCELED.getId());
|
||||
timeoutCount++;
|
||||
}
|
||||
}
|
||||
|
||||
log.info("订单超时检查完成: 总订单数={}, 超时取消数={}", orders.size(), timeoutCount);
|
||||
}
|
||||
|
||||
// 获取所有处于排队状态的订单,用于后续按顺序处理
|
||||
@@ -176,12 +196,18 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
@Override
|
||||
public boolean updateOrder(Order order) {
|
||||
try {
|
||||
|
||||
log.info("更新订单状态时租户ID: tenantId={}", TenantContextHolder.getTenant());
|
||||
|
||||
// 获取原订单信息
|
||||
Order oldOrder = getById(order.getId());
|
||||
boolean result = super.saveOrUpdateIdempotency(order, lock,
|
||||
ORDER_LOCK + order.getOrderNo(),
|
||||
new QueryWrapper<Order>().eq("order_no", order.getOrderNo()),
|
||||
"订单已存在");
|
||||
if (oldOrder == null) {
|
||||
log.error("订单不存在,无法更新: orderId={}", order.getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 使用updateById进行更新,避免INSERT操作
|
||||
boolean result = updateById(order);
|
||||
|
||||
// 如果更新成功且状态发生变化,发布事件
|
||||
if (result && !order.getOrderStatus().equals(oldOrder.getOrderStatus())) {
|
||||
@@ -206,7 +232,7 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单失败", e);
|
||||
log.error("更新订单失败: orderId={}, orderNo={}", order.getId(), order.getOrderNo(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
+121
-1
@@ -6,16 +6,22 @@ import com.central.common.model.Result;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.order.mapper.TourismMapper;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
import com.central.order.model.TourismFile;
|
||||
import com.central.order.service.ITourismService;
|
||||
import com.central.order.service.ITourismFileService;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Order information
|
||||
* 景区信息服务实现类
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:52:54
|
||||
@@ -24,6 +30,12 @@ import java.util.Map;
|
||||
@Service
|
||||
public class TourismServiceImpl extends SuperServiceImpl<TourismMapper, Tourism> implements ITourismService {
|
||||
|
||||
@Autowired
|
||||
private ITourismFileService tourismFileService;
|
||||
|
||||
@Autowired
|
||||
private FileCenterService fileCenterService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param params
|
||||
@@ -52,4 +64,112 @@ public class TourismServiceImpl extends SuperServiceImpl<TourismMapper, Tourism>
|
||||
return baseMapper.getDevicesByTourismId(tourismId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TourismWithDistance> findNearbyTourisms(BigDecimal longitude, BigDecimal latitude, Double radius, Integer limit) {
|
||||
log.info("查询附近景区,经度: {}, 纬度: {}, 半径: {}km, 限制数量: {}", longitude, latitude, radius, limit);
|
||||
|
||||
// 参数验证
|
||||
if (longitude == null || latitude == null) {
|
||||
log.warn("经纬度参数不能为空");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
if (radius == null || radius <= 0) {
|
||||
radius = 1000.0; // 默认10公里
|
||||
}
|
||||
|
||||
if (limit == null || limit <= 0) {
|
||||
limit = 20; // 默认返回20个
|
||||
}
|
||||
|
||||
List<TourismWithDistance> tourisms = baseMapper.findNearbyTourisms(longitude, latitude, radius, limit);
|
||||
log.info("查询到附近景区数量: {}", tourisms.size());
|
||||
|
||||
// 为每个景区添加订单展示图片
|
||||
for (TourismWithDistance tourism : tourisms) {
|
||||
try {
|
||||
// 查询景区的订单展示图片(type=6)
|
||||
List<TourismFile> tourismFiles = tourismFileService.getByTourismId(tourism.getId());
|
||||
if (tourismFiles != null && !tourismFiles.isEmpty()) {
|
||||
// 查找订单展示图(type=6)
|
||||
TourismFile orderShowFile = tourismFiles.stream()
|
||||
.filter(file -> file.getType() == 6)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (orderShowFile != null && orderShowFile.getImageUrl() != null) {
|
||||
// 获取图片的完整URL
|
||||
String imageUrl = fileCenterService.getViewUrlByPath(orderShowFile.getImageUrl());
|
||||
tourism.setOrderShowImageUrl(imageUrl);
|
||||
log.debug("景区 {} 设置订单展示图片: {}", tourism.getTourismName(), imageUrl);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("获取景区 {} 订单展示图片失败: {}", tourism.getTourismName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return tourisms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tourism> findTourismsByBounds(BigDecimal minLongitude, BigDecimal maxLongitude,
|
||||
BigDecimal minLatitude, BigDecimal maxLatitude) {
|
||||
log.info("根据经纬度范围查询景区,经度范围: [{}, {}], 纬度范围: [{}, {}]",
|
||||
minLongitude, maxLongitude, minLatitude, maxLatitude);
|
||||
|
||||
// 参数验证
|
||||
if (minLongitude == null || maxLongitude == null || minLatitude == null || maxLatitude == null) {
|
||||
log.warn("经纬度范围参数不能为空");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
List<Tourism> tourisms = baseMapper.findTourismsByBounds(minLongitude, maxLongitude, minLatitude, maxLatitude);
|
||||
log.info("查询到景区数量: {}", tourisms.size());
|
||||
|
||||
return tourisms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result updateTourismLocation(Long id, BigDecimal longitude, BigDecimal latitude) {
|
||||
log.info("更新景区经纬度信息,景区ID: {}, 经度: {}, 纬度: {}", id, longitude, latitude);
|
||||
|
||||
// 参数验证
|
||||
if (id == null) {
|
||||
return Result.failed("景区ID不能为空");
|
||||
}
|
||||
|
||||
if (longitude == null || latitude == null) {
|
||||
return Result.failed("经纬度不能为空");
|
||||
}
|
||||
|
||||
// 验证经纬度范围
|
||||
if (longitude.compareTo(BigDecimal.valueOf(-180)) < 0 || longitude.compareTo(BigDecimal.valueOf(180)) > 0) {
|
||||
return Result.failed("经度范围应在-180到180之间");
|
||||
}
|
||||
|
||||
if (latitude.compareTo(BigDecimal.valueOf(-90)) < 0 || latitude.compareTo(BigDecimal.valueOf(90)) > 0) {
|
||||
return Result.failed("纬度范围应在-90到90之间");
|
||||
}
|
||||
|
||||
// 查询景区是否存在
|
||||
Tourism tourism = getById(id);
|
||||
if (tourism == null) {
|
||||
return Result.failed("景区不存在");
|
||||
}
|
||||
|
||||
// 更新经纬度
|
||||
tourism.setLongitude(longitude);
|
||||
tourism.setLatitude(latitude);
|
||||
|
||||
boolean result = updateById(tourism);
|
||||
if (result) {
|
||||
log.info("景区经纬度更新成功,景区ID: {}", id);
|
||||
return Result.succeed(tourism, "经纬度更新成功");
|
||||
} else {
|
||||
log.error("景区经纬度更新失败,景区ID: {}", id);
|
||||
return Result.failed("经纬度更新失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ knife4j:
|
||||
zlt:
|
||||
#多租户配置
|
||||
tenant:
|
||||
enable: false
|
||||
enable: true
|
||||
ignoreTables:
|
||||
- edit_task
|
||||
- home_carousel
|
||||
@@ -40,16 +40,13 @@ zlt:
|
||||
- profit_sharing
|
||||
- order_statistics
|
||||
ignoreSqls:
|
||||
# 查询全部列表
|
||||
# - com.central.order.mapper.OrderMapper.findList
|
||||
# 获取某个订单
|
||||
# - com.central.order.mapper.OrderMapper.getOrderByNumber
|
||||
noIgnoreSqls:
|
||||
- com.central.order.mapper.OrderMapper.findList
|
||||
- com.central.order.mapper.TourismMapper.findList
|
||||
- com.central.order.mapper.OrderFileMapper.findList
|
||||
- com.central.order.mapper.QrCodeMapper.findList
|
||||
- com.central.order.mapper.QrCodeMapper.save
|
||||
# 移除所有ignoreSqls配置,让所有SQL都经过租户过滤处理
|
||||
# 这样webApp租户的特殊处理逻辑才能生效
|
||||
# 该接口是白名单接口查询中的逻辑,来例如:机库直接创建数据没有携带租户ID
|
||||
- com.central.order.mapper.OrderMapper.getOrderByNumber
|
||||
- com.central.order.mapper.OrderMapper.getOrdersByStatus
|
||||
# update和delete类型的操作mybatisPlus不支持,原因是数据隔离级别
|
||||
# - com.central.order.mapper.OrderMapper.updateOrderStatus
|
||||
# 微信支付商户号
|
||||
tencent:
|
||||
merchantId: ${zlt.wxpay.merchantId}
|
||||
@@ -88,7 +85,7 @@ tencent:
|
||||
file:
|
||||
oss-url: goflyapp.oss-cn-beijing.aliyuncs.com
|
||||
cdn-url: cdn.goflytec.com
|
||||
style: image/resize,m_mfit,w_300,h_250
|
||||
style: image/resize,m_mfit,w_218,h_160
|
||||
#审计日志
|
||||
# audit-log:
|
||||
# enabled: true
|
||||
@@ -140,4 +137,4 @@ cdn:
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
com.central.order.controller.OrderFileController: DEBUG
|
||||
com.central.order.controller.OrderFileController: DEBUG
|
||||
|
||||
@@ -4,10 +4,10 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: order-center
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# ip: 81.70.164.178
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
ip: 81.70.164.178
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<!-- 动态获取参数采用备参 -->
|
||||
<select id="findListByUser" resultType="com.central.order.model.Order">
|
||||
select id,order_no,tourism_id,device_sn,workspace_id,code_id,user_id,order_amount,order_status,create_time,update_time from orders t WHERE t.user_id = #{param2.userId}
|
||||
and t.is_del = 0
|
||||
<if test="param2.orderStatusList != null and param2.orderStatusList.size() > 0">
|
||||
and t.order_status in
|
||||
<foreach collection="param2.orderStatusList" item="status" open="(" separator="," close=")">
|
||||
|
||||
@@ -36,4 +36,42 @@
|
||||
AND t.is_del = 0
|
||||
ORDER BY q.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询附近景区列表 -->
|
||||
<select id="findNearbyTourisms" resultType="com.central.order.model.TourismWithDistance">
|
||||
<![CDATA[
|
||||
SELECT
|
||||
*,
|
||||
(
|
||||
6371 * acos(
|
||||
cos(radians(#{latitude})) *
|
||||
cos(radians(latitude)) *
|
||||
cos(radians(longitude) - radians(#{longitude})) +
|
||||
sin(radians(#{latitude})) *
|
||||
sin(radians(latitude))
|
||||
)
|
||||
) AS distance
|
||||
FROM tourisms
|
||||
WHERE is_del = 0
|
||||
AND status = 1
|
||||
AND longitude IS NOT NULL
|
||||
AND latitude IS NOT NULL
|
||||
HAVING distance <= #{radius}
|
||||
ORDER BY distance ASC
|
||||
]]>
|
||||
<if test="limit != null and limit > 0">
|
||||
LIMIT #{limit}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 根据经纬度范围查询景区 -->
|
||||
<select id="findTourismsByBounds" resultType="com.central.order.model.Tourism">
|
||||
SELECT * FROM tourisms
|
||||
WHERE is_del = 0
|
||||
AND status = 1
|
||||
AND longitude BETWEEN #{minLongitude} AND #{maxLongitude}
|
||||
AND latitude BETWEEN #{minLatitude} AND #{maxLatitude}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* TourismWithDistance 类单元测试
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19 17:51:47
|
||||
*/
|
||||
public class TourismWithDistanceTest {
|
||||
|
||||
@Test
|
||||
public void testDistanceDesc() {
|
||||
TourismWithDistance tourism = new TourismWithDistance();
|
||||
|
||||
// 测试小于1公里的距离
|
||||
tourism.setDistance(new BigDecimal("0.5"));
|
||||
assertEquals("500m", tourism.getDistanceDesc());
|
||||
|
||||
// 测试等于1公里的距离
|
||||
tourism.setDistance(BigDecimal.ONE);
|
||||
assertEquals("1.0km", tourism.getDistanceDesc());
|
||||
|
||||
// 测试大于1公里的距离
|
||||
tourism.setDistance(new BigDecimal("2.5"));
|
||||
assertEquals("2.5km", tourism.getDistanceDesc());
|
||||
|
||||
// 测试null距离
|
||||
tourism.setDistance(null);
|
||||
assertEquals("未知距离", tourism.getDistanceDesc());
|
||||
|
||||
// 测试0距离
|
||||
tourism.setDistance(BigDecimal.ZERO);
|
||||
assertEquals("0m", tourism.getDistanceDesc());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInheritance() {
|
||||
TourismWithDistance tourism = new TourismWithDistance();
|
||||
|
||||
// 测试继承自Tourism的属性
|
||||
tourism.setTourismName("测试景区");
|
||||
tourism.setTourismAddress("测试地址");
|
||||
tourism.setLongitude(new BigDecimal("116.397128"));
|
||||
tourism.setLatitude(new BigDecimal("39.916527"));
|
||||
|
||||
assertEquals("测试景区", tourism.getTourismName());
|
||||
assertEquals("测试地址", tourism.getTourismAddress());
|
||||
assertEquals(new BigDecimal("116.397128"), tourism.getLongitude());
|
||||
assertEquals(new BigDecimal("39.916527"), tourism.getLatitude());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderShowImageUrl() {
|
||||
TourismWithDistance tourism = new TourismWithDistance();
|
||||
|
||||
// 测试设置和获取订单展示图片URL
|
||||
String imageUrl = "https://example.com/image.jpg";
|
||||
tourism.setOrderShowImageUrl(imageUrl);
|
||||
|
||||
assertEquals(imageUrl, tourism.getOrderShowImageUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistanceDescCustom() {
|
||||
TourismWithDistance tourism = new TourismWithDistance();
|
||||
|
||||
// 测试自定义距离描述
|
||||
String customDesc = "约1.2公里";
|
||||
tourism.setDistanceDesc(customDesc);
|
||||
|
||||
assertEquals(customDesc, tourism.getDistanceDesc());
|
||||
}
|
||||
}
|
||||
+65
@@ -467,4 +467,69 @@ public class SysUserController {
|
||||
return config != null ? Result.succeed(config) : Result.failed("未找到配置");
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注销账户
|
||||
*/
|
||||
@PostMapping("/users/account/logout")
|
||||
@Operation(summary = "用户注销账户")
|
||||
public Result<String> logout() {
|
||||
try {
|
||||
SysUser currentUser = LoginUserUtils.getCurrentSysUser();
|
||||
if (currentUser != null) {
|
||||
// 检查是否为超级管理员
|
||||
if (checkAdmin(currentUser.getId())) {
|
||||
return Result.failed("超级管理员账户不能注销");
|
||||
}
|
||||
|
||||
log.info("用户 {} 执行账户注销操作", currentUser.getUsername());
|
||||
|
||||
// 执行用户账户彻底注销(删除所有相关数据)
|
||||
boolean success = appUserService.completelyDeleteUser(currentUser.getId());
|
||||
|
||||
if (success) {
|
||||
log.info("用户 {} 账户彻底注销成功", currentUser.getUsername());
|
||||
return Result.succeed("账户彻底注销成功");
|
||||
} else {
|
||||
log.error("用户 {} 账户彻底注销失败", currentUser.getUsername());
|
||||
return Result.failed("账户彻底注销失败,请重试");
|
||||
}
|
||||
} else {
|
||||
return Result.failed("用户未登录");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("用户账户彻底注销失败", e);
|
||||
return Result.failed("账户彻底注销失败,请重试");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试彻底删除用户(仅用于测试)
|
||||
*/
|
||||
@PostMapping("/users/test/delete/{userId}")
|
||||
@Operation(summary = "测试彻底删除用户")
|
||||
public Result<String> testCompletelyDeleteUser(@PathVariable Long userId) {
|
||||
try {
|
||||
log.info("开始测试彻底删除用户,用户ID: {}", userId);
|
||||
|
||||
// 检查是否为超级管理员
|
||||
if (checkAdmin(userId)) {
|
||||
return Result.failed("超级管理员账户不能删除");
|
||||
}
|
||||
|
||||
// 执行用户彻底删除
|
||||
boolean success = appUserService.completelyDeleteUser(userId);
|
||||
|
||||
if (success) {
|
||||
log.info("用户彻底删除测试成功,用户ID: {}", userId);
|
||||
return Result.succeed("用户彻底删除测试成功");
|
||||
} else {
|
||||
log.error("用户彻底删除测试失败,用户ID: {}", userId);
|
||||
return Result.failed("用户彻底删除测试失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("用户彻底删除测试异常,用户ID: {}", userId, e);
|
||||
return Result.failed("用户彻底删除测试异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
package com.central.user.controller;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.user.service.ITenantService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 统一租户管理控制器
|
||||
* 负责系统级租户管理,其他微服务通过Feign调用
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/tenant")
|
||||
@Tag(name = "租户管理", description = "系统级租户管理")
|
||||
public class TenantController {
|
||||
|
||||
@Autowired
|
||||
private ITenantService tenantService;
|
||||
|
||||
/**
|
||||
* 设置当前租户
|
||||
*/
|
||||
@PostMapping("/set")
|
||||
@Operation(summary = "设置当前租户")
|
||||
public Result<String> setCurrentTenant(
|
||||
@Parameter(description = "租户ID", required = true)
|
||||
@RequestParam String tenantId) {
|
||||
return tenantService.setCurrentTenant(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前租户
|
||||
*/
|
||||
@GetMapping("/current")
|
||||
@Operation(summary = "获取当前租户")
|
||||
public Result<String> getCurrentTenant() {
|
||||
try {
|
||||
String tenantId = tenantService.getCurrentTenant();
|
||||
log.debug("获取当前租户: {}", tenantId);
|
||||
return Result.succeed(tenantId, "获取租户成功");
|
||||
} catch (Exception e) {
|
||||
log.error("获取租户失败", e);
|
||||
return Result.failed("获取租户失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除当前租户
|
||||
*/
|
||||
@PostMapping("/clear")
|
||||
@Operation(summary = "清除当前租户")
|
||||
public Result<String> clearCurrentTenant() {
|
||||
return tenantService.clearCurrentTenant();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否为 webApp 租户
|
||||
*/
|
||||
@GetMapping("/check-webapp")
|
||||
@Operation(summary = "检查是否为 webApp 租户")
|
||||
public Result<Boolean> isWebAppTenant() {
|
||||
try {
|
||||
boolean isWebApp = tenantService.isWebAppTenant();
|
||||
log.debug("检查是否为 webApp 租户: {}", isWebApp);
|
||||
return Result.succeed(isWebApp, "检查成功");
|
||||
} catch (Exception e) {
|
||||
log.error("检查租户类型失败", e);
|
||||
return Result.failed("检查租户类型失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户信息
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
@Operation(summary = "获取租户信息")
|
||||
public Result<Object> getTenantInfo() {
|
||||
try {
|
||||
Map<String, Object> tenantInfo = tenantService.getTenantInfo();
|
||||
log.debug("获取租户信息: {}", tenantInfo);
|
||||
return Result.succeed(tenantInfo, "获取租户信息成功");
|
||||
} catch (Exception e) {
|
||||
log.error("获取租户信息失败", e);
|
||||
return Result.failed("获取租户信息失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证租户权限
|
||||
*/
|
||||
@PostMapping("/validate")
|
||||
@Operation(summary = "验证租户权限")
|
||||
public Result<Object> validateTenantPermission(
|
||||
@Parameter(description = "租户ID", required = true)
|
||||
@RequestParam String tenantId,
|
||||
@Parameter(description = "操作类型", required = true)
|
||||
@RequestParam String operation) {
|
||||
return tenantService.validateTenantPermission(tenantId, operation);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有租户列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取所有租户列表")
|
||||
public Result<List<Map<String, Object>>> getAllTenants() {
|
||||
return tenantService.getAllTenants();
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换租户
|
||||
*/
|
||||
@PostMapping("/switch")
|
||||
@Operation(summary = "切换租户")
|
||||
public Result<Object> switchTenant(
|
||||
@Parameter(description = "目标租户ID", required = true)
|
||||
@RequestParam String targetTenantId) {
|
||||
return tenantService.switchTenant(targetTenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户状态
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
@Operation(summary = "获取租户状态")
|
||||
public Result<Object> getTenantStatus() {
|
||||
try {
|
||||
Map<String, Object> status = tenantService.getTenantStatus();
|
||||
log.debug("获取租户状态: {}", status);
|
||||
return Result.succeed(status, "获取租户状态成功");
|
||||
} catch (Exception e) {
|
||||
log.error("获取租户状态失败", e);
|
||||
return Result.failed("获取租户状态失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户统计信息
|
||||
*/
|
||||
@GetMapping("/statistics")
|
||||
@Operation(summary = "获取租户统计信息")
|
||||
public Result<Map<String, Object>> getTenantStatistics() {
|
||||
return tenantService.getTenantStatistics();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新租户
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建新租户")
|
||||
public Result<String> createTenant(@RequestBody Map<String, Object> tenantInfo) {
|
||||
return tenantService.createTenant(tenantInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除租户
|
||||
*/
|
||||
@DeleteMapping("/{tenantId}")
|
||||
@Operation(summary = "删除租户")
|
||||
public Result<String> deleteTenant(
|
||||
@Parameter(description = "租户ID", required = true)
|
||||
@PathVariable String tenantId) {
|
||||
return tenantService.deleteTenant(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新租户信息
|
||||
*/
|
||||
@PutMapping("/{tenantId}")
|
||||
@Operation(summary = "更新租户信息")
|
||||
public Result<String> updateTenant(
|
||||
@Parameter(description = "租户ID", required = true)
|
||||
@PathVariable String tenantId,
|
||||
@RequestBody Map<String, Object> tenantInfo) {
|
||||
return tenantService.updateTenant(tenantId, tenantInfo);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.central.user.feign;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* 设备中心服务Feign客户端
|
||||
* 用于清理用户相关的设备数据
|
||||
*/
|
||||
@FeignClient(name = "device-center", fallback = DeviceCenterServiceFallback.class)
|
||||
public interface DeviceCenterService {
|
||||
|
||||
/**
|
||||
* 删除用户相关的所有设备数据
|
||||
* @param userId 用户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/devices/user/{userId}")
|
||||
Result<String> deleteUserDevices(@PathVariable("userId") String userId);
|
||||
|
||||
/**
|
||||
* 删除用户相关的所有航线文件
|
||||
* @param userId 用户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/wayline-files/user/{userId}")
|
||||
Result<String> deleteUserWaylineFiles(@PathVariable("userId") String userId);
|
||||
|
||||
/**
|
||||
* 删除用户相关的所有任务记录
|
||||
* @param userId 用户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/wayline-jobs/user/{userId}")
|
||||
Result<String> deleteUserWaylineJobs(@PathVariable("userId") String userId);
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.central.user.feign;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 设备中心服务降级处理
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DeviceCenterServiceFallback implements DeviceCenterService {
|
||||
|
||||
@Override
|
||||
public Result<String> deleteUserDevices(String userId) {
|
||||
log.error("设备中心服务不可用,无法删除用户设备数据,用户ID: {}", userId);
|
||||
return Result.failed("设备中心服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> deleteUserWaylineFiles(String userId) {
|
||||
log.error("设备中心服务不可用,无法删除用户航线文件,用户ID: {}", userId);
|
||||
return Result.failed("设备中心服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> deleteUserWaylineJobs(String userId) {
|
||||
log.error("设备中心服务不可用,无法删除用户任务记录,用户ID: {}", userId);
|
||||
return Result.failed("设备中心服务不可用");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.central.user.feign;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* 订单中心服务Feign客户端
|
||||
* 用于清理用户相关的订单数据
|
||||
*/
|
||||
@FeignClient(name = "order-center", fallback = OrderCenterServiceFallback.class)
|
||||
public interface OrderCenterService {
|
||||
|
||||
/**
|
||||
* 删除用户相关的所有订单数据
|
||||
* @param userId 用户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/orders/user/{userId}")
|
||||
Result<String> deleteUserOrders(@PathVariable("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 删除用户相关的所有订单文件
|
||||
* @param userId 用户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/order-files/user/{userId}")
|
||||
Result<String> deleteUserOrderFiles(@PathVariable("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 删除用户相关的所有消息
|
||||
* @param userId 用户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/messages/user/{userId}")
|
||||
Result<String> deleteUserMessages(@PathVariable("userId") Long userId);
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.central.user.feign;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 订单中心服务降级处理
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class OrderCenterServiceFallback implements OrderCenterService {
|
||||
|
||||
@Override
|
||||
public Result<String> deleteUserOrders(Long userId) {
|
||||
log.error("订单中心服务不可用,无法删除用户订单数据,用户ID: {}", userId);
|
||||
return Result.failed("订单中心服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> deleteUserOrderFiles(Long userId) {
|
||||
log.error("订单中心服务不可用,无法删除用户订单文件,用户ID: {}", userId);
|
||||
return Result.failed("订单中心服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> deleteUserMessages(Long userId) {
|
||||
log.error("订单中心服务不可用,无法删除用户消息,用户ID: {}", userId);
|
||||
return Result.failed("订单中心服务不可用");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.central.user.feign;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 租户服务Feign客户端
|
||||
* 供其他微服务调用租户管理功能
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19
|
||||
*/
|
||||
@FeignClient(name = "user-center", fallback = TenantServiceFallback.class)
|
||||
public interface TenantService {
|
||||
|
||||
/**
|
||||
* 设置当前租户
|
||||
* @param tenantId 租户ID
|
||||
* @return 设置结果
|
||||
*/
|
||||
@PostMapping("/tenant/set")
|
||||
Result<String> setCurrentTenant(@RequestParam("tenantId") String tenantId);
|
||||
|
||||
/**
|
||||
* 获取当前租户
|
||||
* @return 租户ID
|
||||
*/
|
||||
@GetMapping("/tenant/current")
|
||||
Result<String> getCurrentTenant();
|
||||
|
||||
/**
|
||||
* 清除当前租户
|
||||
* @return 清除结果
|
||||
*/
|
||||
@PostMapping("/tenant/clear")
|
||||
Result<String> clearCurrentTenant();
|
||||
|
||||
/**
|
||||
* 检查是否为 webApp 租户
|
||||
* @return 是否为 webApp 租户
|
||||
*/
|
||||
@GetMapping("/tenant/check-webapp")
|
||||
Result<Boolean> isWebAppTenant();
|
||||
|
||||
/**
|
||||
* 获取租户信息
|
||||
* @return 租户信息
|
||||
*/
|
||||
@GetMapping("/tenant/info")
|
||||
Result<Object> getTenantInfo();
|
||||
|
||||
/**
|
||||
* 验证租户权限
|
||||
* @param tenantId 租户ID
|
||||
* @param operation 操作类型
|
||||
* @return 权限验证结果
|
||||
*/
|
||||
@PostMapping("/tenant/validate")
|
||||
Result<Object> validateTenantPermission(
|
||||
@RequestParam("tenantId") String tenantId,
|
||||
@RequestParam("operation") String operation);
|
||||
|
||||
/**
|
||||
* 获取所有租户列表
|
||||
* @return 租户列表
|
||||
*/
|
||||
@GetMapping("/tenant/list")
|
||||
Result<Object> getAllTenants();
|
||||
|
||||
/**
|
||||
* 切换租户
|
||||
* @param targetTenantId 目标租户ID
|
||||
* @return 切换结果
|
||||
*/
|
||||
@PostMapping("/tenant/switch")
|
||||
Result<Object> switchTenant(@RequestParam("targetTenantId") String targetTenantId);
|
||||
|
||||
/**
|
||||
* 获取租户状态
|
||||
* @return 租户状态
|
||||
*/
|
||||
@GetMapping("/tenant/status")
|
||||
Result<Object> getTenantStatus();
|
||||
|
||||
/**
|
||||
* 获取租户统计信息
|
||||
* @return 统计信息
|
||||
*/
|
||||
@GetMapping("/tenant/statistics")
|
||||
Result<Map<String, Object>> getTenantStatistics();
|
||||
|
||||
/**
|
||||
* 创建新租户
|
||||
* @param tenantInfo 租户信息
|
||||
* @return 创建结果
|
||||
*/
|
||||
@PostMapping("/tenant/create")
|
||||
Result<String> createTenant(@RequestBody Map<String, Object> tenantInfo);
|
||||
|
||||
/**
|
||||
* 删除租户
|
||||
* @param tenantId 租户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/tenant/{tenantId}")
|
||||
Result<String> deleteTenant(@PathVariable("tenantId") String tenantId);
|
||||
|
||||
/**
|
||||
* 更新租户信息
|
||||
* @param tenantId 租户ID
|
||||
* @param tenantInfo 租户信息
|
||||
* @return 更新结果
|
||||
*/
|
||||
@PutMapping("/tenant/{tenantId}")
|
||||
Result<String> updateTenant(@PathVariable("tenantId") String tenantId, @RequestBody Map<String, Object> tenantInfo);
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.central.user.feign;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 租户服务降级处理
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TenantServiceFallback implements TenantService {
|
||||
|
||||
@Override
|
||||
public Result<String> setCurrentTenant(String tenantId) {
|
||||
log.error("租户服务不可用,无法设置租户: {}", tenantId);
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> getCurrentTenant() {
|
||||
log.error("租户服务不可用,无法获取当前租户");
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> clearCurrentTenant() {
|
||||
log.error("租户服务不可用,无法清除当前租户");
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> isWebAppTenant() {
|
||||
log.error("租户服务不可用,无法检查租户类型");
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Object> getTenantInfo() {
|
||||
log.error("租户服务不可用,无法获取租户信息");
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Object> validateTenantPermission(String tenantId, String operation) {
|
||||
log.error("租户服务不可用,无法验证租户权限,租户: {}, 操作: {}", tenantId, operation);
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Object> getAllTenants() {
|
||||
log.error("租户服务不可用,无法获取租户列表");
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Object> switchTenant(String targetTenantId) {
|
||||
log.error("租户服务不可用,无法切换租户: {}", targetTenantId);
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Object> getTenantStatus() {
|
||||
log.error("租户服务不可用,无法获取租户状态");
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Map<String, Object>> getTenantStatistics() {
|
||||
log.error("租户服务不可用,无法获取租户统计信息");
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> createTenant(Map<String, Object> tenantInfo) {
|
||||
log.error("租户服务不可用,无法创建租户");
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> deleteTenant(String tenantId) {
|
||||
log.error("租户服务不可用,无法删除租户: {}", tenantId);
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> updateTenant(String tenantId, Map<String, Object> tenantInfo) {
|
||||
log.error("租户服务不可用,无法更新租户信息: {}", tenantId);
|
||||
return Result.failed("租户服务不可用");
|
||||
}
|
||||
}
|
||||
@@ -109,4 +109,11 @@ public interface ISysUserService extends ISuperService<SysUser> {
|
||||
* 删除用户
|
||||
*/
|
||||
boolean delUser(Long id);
|
||||
|
||||
/**
|
||||
* 彻底删除用户及其所有相关数据
|
||||
* @param userId 用户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
boolean completelyDeleteUser(Long userId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 租户服务接口
|
||||
* 统一管理系统中所有租户相关功能
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19
|
||||
*/
|
||||
public interface ITenantService {
|
||||
|
||||
/**
|
||||
* 设置当前租户
|
||||
* @param tenantId 租户ID
|
||||
* @return 设置结果
|
||||
*/
|
||||
Result<String> setCurrentTenant(String tenantId);
|
||||
|
||||
/**
|
||||
* 获取当前租户
|
||||
* @return 租户ID
|
||||
*/
|
||||
String getCurrentTenant();
|
||||
|
||||
/**
|
||||
* 清除当前租户
|
||||
* @return 清除结果
|
||||
*/
|
||||
Result<String> clearCurrentTenant();
|
||||
|
||||
/**
|
||||
* 检查是否为 webApp 租户
|
||||
* @return 是否为 webApp 租户
|
||||
*/
|
||||
boolean isWebAppTenant();
|
||||
|
||||
/**
|
||||
* 获取租户信息
|
||||
* @return 租户信息
|
||||
*/
|
||||
Map<String, Object> getTenantInfo();
|
||||
|
||||
/**
|
||||
* 验证租户权限
|
||||
* @param tenantId 租户ID
|
||||
* @param operation 操作类型
|
||||
* @return 权限验证结果
|
||||
*/
|
||||
Result<Object> validateTenantPermission(String tenantId, String operation);
|
||||
|
||||
/**
|
||||
* 切换租户
|
||||
* @param targetTenantId 目标租户ID
|
||||
* @return 切换结果
|
||||
*/
|
||||
Result<Object> switchTenant(String targetTenantId);
|
||||
|
||||
/**
|
||||
* 获取租户状态
|
||||
* @return 租户状态
|
||||
*/
|
||||
Map<String, Object> getTenantStatus();
|
||||
|
||||
/**
|
||||
* 获取所有租户列表
|
||||
* @return 租户列表
|
||||
*/
|
||||
Result<List<Map<String, Object>>> getAllTenants();
|
||||
|
||||
/**
|
||||
* 获取租户统计信息
|
||||
* @return 统计信息
|
||||
*/
|
||||
Result<Map<String, Object>> getTenantStatistics();
|
||||
|
||||
/**
|
||||
* 检查租户是否存在
|
||||
* @param tenantId 租户ID
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean isTenantExists(String tenantId);
|
||||
|
||||
/**
|
||||
* 创建新租户
|
||||
* @param tenantInfo 租户信息
|
||||
* @return 创建结果
|
||||
*/
|
||||
Result<String> createTenant(Map<String, Object> tenantInfo);
|
||||
|
||||
/**
|
||||
* 删除租户
|
||||
* @param tenantId 租户ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
Result<String> deleteTenant(String tenantId);
|
||||
|
||||
/**
|
||||
* 更新租户信息
|
||||
* @param tenantId 租户ID
|
||||
* @param tenantInfo 租户信息
|
||||
* @return 更新结果
|
||||
*/
|
||||
Result<String> updateTenant(String tenantId, Map<String, Object> tenantInfo);
|
||||
}
|
||||
+122
-8
@@ -1,13 +1,22 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.lock.DistributedLock;
|
||||
import com.central.common.model.*;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.model.SysRole;
|
||||
import com.central.common.model.SysUser;
|
||||
import com.central.common.model.UserType;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import com.central.common.model.SysMenu;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.user.feign.DeviceCenterService;
|
||||
import com.central.user.feign.OrderCenterService;
|
||||
import com.central.user.mapper.SysRoleMenuMapper;
|
||||
import com.central.user.mapper.SysUserMapper;
|
||||
import com.central.user.model.SysRoleUser;
|
||||
@@ -16,7 +25,6 @@ import com.central.user.service.ISysRoleUserService;
|
||||
import com.central.user.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,13 +32,14 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 作者 owen E-mail: 624191343@qq.com
|
||||
* @author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -49,6 +58,12 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
@Autowired
|
||||
private DistributedLock lock;
|
||||
|
||||
@Resource
|
||||
private OrderCenterService orderCenterService;
|
||||
|
||||
@Resource
|
||||
private DeviceCenterService deviceCenterService;
|
||||
|
||||
@Override
|
||||
public SysUser findByUsername(String username) {
|
||||
SysUser sysUser = this.selectByUsername(username);
|
||||
@@ -76,7 +91,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
SysUser sysUser = this.selectByOpenId(wxOpenid);
|
||||
|
||||
// 如果用户存在,更新 unionId(无论是否为空都更新)
|
||||
if (ObjectUtils.isNotEmpty(sysUser)) {
|
||||
if (ObjectUtil.isNotEmpty(sysUser)) {
|
||||
if (StringUtils.isNotEmpty(unionId)) {
|
||||
sysUser.setUnionId(unionId);
|
||||
log.info("更新用户unionId: {}", unionId);
|
||||
@@ -132,7 +147,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
@Override
|
||||
public SysUser selectByUsername(String username) {
|
||||
List<SysUser> users = baseMapper.selectList(
|
||||
new QueryWrapper<SysUser>().eq("username", username)
|
||||
new QueryWrapper<SysUser>().eq("username", username).eq("is_del", 0)
|
||||
);
|
||||
return getUser(users);
|
||||
}
|
||||
@@ -145,7 +160,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
@Override
|
||||
public SysUser selectByMobile(String mobile) {
|
||||
List<SysUser> users = baseMapper.selectList(
|
||||
new QueryWrapper<SysUser>().eq("mobile", mobile)
|
||||
new QueryWrapper<SysUser>().eq("mobile", mobile).eq("is_del", 0)
|
||||
);
|
||||
return getUser(users);
|
||||
}
|
||||
@@ -158,7 +173,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
@Override
|
||||
public SysUser selectByOpenId(String openId) {
|
||||
List<SysUser> users = baseMapper.selectList(
|
||||
new QueryWrapper<SysUser>().eq("open_id", openId)
|
||||
new QueryWrapper<SysUser>().eq("open_id", openId).eq("is_del", 0)
|
||||
);
|
||||
return getUser(users);
|
||||
}
|
||||
@@ -218,7 +233,7 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
List<Long> userIds = list.stream().map(SysUser::getId).collect(Collectors.toList());
|
||||
|
||||
List<SysRole> sysRoles = roleUserService.findRolesByUserIds(userIds);
|
||||
list.forEach(u -> u.setRoles(sysRoles.stream().filter(r -> !ObjectUtils.notEqual(u.getId(), r.getUserId()))
|
||||
list.forEach(u -> u.setRoles(sysRoles.stream().filter(r -> !Objects.equals(u.getId(), r.getUserId()))
|
||||
.collect(Collectors.toList())));
|
||||
}
|
||||
return PageResult.<SysUser>builder().data(list).resp_code(0).count(total).build();
|
||||
@@ -282,6 +297,105 @@ public class SysUserServiceImpl extends SuperServiceImpl<SysUserMapper, SysUser>
|
||||
return baseMapper.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean completelyDeleteUser(Long userId) {
|
||||
try {
|
||||
log.info("开始彻底删除用户及其相关数据,用户ID: {}", userId);
|
||||
|
||||
// 1. 删除用户角色关联
|
||||
roleUserService.deleteUserRole(userId, null);
|
||||
log.info("已删除用户角色关联,用户ID: {}", userId);
|
||||
|
||||
// 2. 删除用户基本信息(物理删除,不使用逻辑删除)
|
||||
int userDeleteResult = baseMapper.deleteById(userId);
|
||||
log.info("已删除用户基本信息,用户ID: {}, 删除结果: {}", userId, userDeleteResult);
|
||||
|
||||
// 3. 清理订单中心相关数据 @TODO
|
||||
/*try {
|
||||
log.info("开始清理订单中心用户相关数据,用户ID: {}", userId);
|
||||
|
||||
// 删除用户订单
|
||||
Result<String> orderResult = orderCenterService.deleteUserOrders(userId);
|
||||
if (orderResult.getResp_code() == 0) {
|
||||
log.info("已删除用户订单数据,用户ID: {}", userId);
|
||||
} else {
|
||||
log.warn("删除用户订单数据失败,用户ID: {}, 错误: {}", userId, orderResult.getResp_msg());
|
||||
}
|
||||
|
||||
// 删除用户订单文件
|
||||
Result<String> orderFileResult = orderCenterService.deleteUserOrderFiles(userId);
|
||||
if (orderFileResult.getResp_code() == 0) {
|
||||
log.info("已删除用户订单文件,用户ID: {}", userId);
|
||||
} else {
|
||||
log.warn("删除用户订单文件失败,用户ID: {}, 错误: {}", userId, orderFileResult.getResp_msg());
|
||||
}
|
||||
|
||||
// 删除用户消息
|
||||
Result<String> messageResult = orderCenterService.deleteUserMessages(userId);
|
||||
if (messageResult.getResp_code() == 0) {
|
||||
log.info("已删除用户消息,用户ID: {}", userId);
|
||||
} else {
|
||||
log.warn("删除用户消息失败,用户ID: {}, 错误: {}", userId, messageResult.getResp_msg());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("清理订单中心数据失败,用户ID: {}", userId, e);
|
||||
}
|
||||
|
||||
// 4. 清理设备中心相关数据
|
||||
try {
|
||||
log.info("开始清理设备中心用户相关数据,用户ID: {}", userId);
|
||||
|
||||
String userIdStr = String.valueOf(userId);
|
||||
|
||||
// 删除用户设备
|
||||
Result<String> deviceResult = deviceCenterService.deleteUserDevices(userIdStr);
|
||||
if (deviceResult.getResp_code() == 0) {
|
||||
log.info("已删除用户设备数据,用户ID: {}", userId);
|
||||
} else {
|
||||
log.warn("删除用户设备数据失败,用户ID: {}, 错误: {}", userId, deviceResult.getResp_msg());
|
||||
}
|
||||
|
||||
// 删除用户航线文件
|
||||
Result<String> waylineFileResult = deviceCenterService.deleteUserWaylineFiles(userIdStr);
|
||||
if (waylineFileResult.getResp_code() == 0) {
|
||||
log.info("已删除用户航线文件,用户ID: {}", userId);
|
||||
} else {
|
||||
log.warn("删除用户航线文件失败,用户ID: {}, 错误: {}", userId, waylineFileResult.getResp_msg());
|
||||
}
|
||||
|
||||
// 删除用户任务记录
|
||||
Result<String> waylineJobResult = deviceCenterService.deleteUserWaylineJobs(userIdStr);
|
||||
if (waylineJobResult.getResp_code() == 0) {
|
||||
log.info("已删除用户任务记录,用户ID: {}", userId);
|
||||
} else {
|
||||
log.warn("删除用户任务记录失败,用户ID: {}, 错误: {}", userId, waylineJobResult.getResp_msg());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("清理设备中心数据失败,用户ID: {}", userId, e);
|
||||
}
|
||||
|
||||
// 5. 清理日志中心相关数据(通过数据库直接清理)
|
||||
try {
|
||||
log.info("开始清理日志中心用户相关数据,用户ID: {}", userId);
|
||||
// 这里可以通过JdbcTemplate直接清理日志数据
|
||||
// 由于日志中心可能没有提供清理接口,我们可以通过数据库直接清理
|
||||
// TODO: 添加日志中心数据清理逻辑
|
||||
} catch (Exception e) {
|
||||
log.error("清理日志中心数据失败,用户ID: {}", userId, e);
|
||||
}*/
|
||||
|
||||
log.info("用户彻底删除完成,用户ID: {}", userId);
|
||||
return userDeleteResult > 0;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("彻底删除用户失败,用户ID: {}", userId, e);
|
||||
throw new RuntimeException("彻底删除用户失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserExcel> findAllUsers(Map<String, Object> params) {
|
||||
List<SysUserExcel> sysUserExcels = new ArrayList<>();
|
||||
|
||||
+255
@@ -0,0 +1,255 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.user.service.ITenantService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 租户服务实现类
|
||||
* 统一管理系统中所有租户相关功能
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2024-12-19
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TenantServiceImpl implements ITenantService {
|
||||
|
||||
// 模拟租户数据存储(实际项目中应该使用数据库)
|
||||
private static final Map<String, Map<String, Object>> TENANT_STORE = new HashMap<>();
|
||||
|
||||
static {
|
||||
// 初始化默认租户
|
||||
Map<String, Object> webAppTenant = new HashMap<>();
|
||||
webAppTenant.put("tenantId", "webApp");
|
||||
webAppTenant.put("name", "系统管理租户");
|
||||
webAppTenant.put("description", "系统管理租户,可查询所有数据");
|
||||
webAppTenant.put("level", "admin");
|
||||
webAppTenant.put("canQueryAllData", true);
|
||||
webAppTenant.put("createTime", System.currentTimeMillis());
|
||||
TENANT_STORE.put("webApp", webAppTenant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> setCurrentTenant(String tenantId) {
|
||||
try {
|
||||
TenantContextHolder.setTenant(tenantId);
|
||||
log.info("设置当前租户: {}", tenantId);
|
||||
return Result.succeed(tenantId, "租户设置成功");
|
||||
} catch (Exception e) {
|
||||
log.error("设置租户失败", e);
|
||||
return Result.failed("设置租户失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentTenant() {
|
||||
return TenantContextHolder.getTenant();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> clearCurrentTenant() {
|
||||
try {
|
||||
TenantContextHolder.clear();
|
||||
log.info("清除当前租户");
|
||||
return Result.succeed("", "租户清除成功");
|
||||
} catch (Exception e) {
|
||||
log.error("清除租户失败", e);
|
||||
return Result.failed("清除租户失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWebAppTenant() {
|
||||
String tenant = TenantContextHolder.getTenant();
|
||||
return "webApp".equals(tenant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getTenantInfo() {
|
||||
String currentTenant = TenantContextHolder.getTenant();
|
||||
boolean isWebApp = "webApp".equals(currentTenant);
|
||||
|
||||
Map<String, Object> tenantInfo = new HashMap<>();
|
||||
tenantInfo.put("tenantId", currentTenant);
|
||||
tenantInfo.put("webAppTenant", isWebApp);
|
||||
tenantInfo.put("canQueryAllData", isWebApp);
|
||||
tenantInfo.put("description", isWebApp ? "系统管理租户,可查询所有数据" : "普通租户,只能查询自己的数据");
|
||||
tenantInfo.put("level", isWebApp ? "admin" : "user");
|
||||
|
||||
// 如果租户存在于存储中,添加额外信息
|
||||
if (TENANT_STORE.containsKey(currentTenant)) {
|
||||
tenantInfo.putAll(TENANT_STORE.get(currentTenant));
|
||||
}
|
||||
|
||||
return tenantInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Object> validateTenantPermission(String tenantId, String operation) {
|
||||
try {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("tenantId", tenantId);
|
||||
result.put("operation", operation);
|
||||
|
||||
// webApp 租户拥有所有权限
|
||||
if ("webApp".equals(tenantId)) {
|
||||
result.put("hasPermission", true);
|
||||
result.put("message", "webApp 租户拥有所有权限");
|
||||
result.put("level", "admin");
|
||||
} else {
|
||||
// 其他租户只能操作自己的数据
|
||||
result.put("hasPermission", true);
|
||||
result.put("message", "租户只能操作自己的数据");
|
||||
result.put("level", "user");
|
||||
}
|
||||
|
||||
log.info("验证租户权限: {}", result);
|
||||
return Result.succeed(result, "权限验证成功");
|
||||
} catch (Exception e) {
|
||||
log.error("验证租户权限失败", e);
|
||||
return Result.failed("权限验证失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Object> switchTenant(String targetTenantId) {
|
||||
try {
|
||||
String oldTenant = TenantContextHolder.getTenant();
|
||||
|
||||
// 设置新租户
|
||||
TenantContextHolder.setTenant(targetTenantId);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("oldTenant", oldTenant);
|
||||
result.put("newTenant", targetTenantId);
|
||||
result.put("switchTime", System.currentTimeMillis());
|
||||
|
||||
log.info("租户切换成功: {} -> {}", oldTenant, targetTenantId);
|
||||
return Result.succeed(result, "租户切换成功");
|
||||
} catch (Exception e) {
|
||||
log.error("租户切换失败", e);
|
||||
return Result.failed("租户切换失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getTenantStatus() {
|
||||
String currentTenant = TenantContextHolder.getTenant();
|
||||
boolean isWebApp = "webApp".equals(currentTenant);
|
||||
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
status.put("currentTenant", currentTenant);
|
||||
status.put("isWebApp", isWebApp);
|
||||
status.put("canQueryAllData", isWebApp);
|
||||
status.put("timestamp", System.currentTimeMillis());
|
||||
status.put("status", "active");
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<Map<String, Object>>> getAllTenants() {
|
||||
try {
|
||||
List<Map<String, Object>> tenants = new ArrayList<>(TENANT_STORE.values());
|
||||
log.info("获取所有租户,数量: {}", tenants.size());
|
||||
return Result.succeed(tenants, "获取租户列表成功");
|
||||
} catch (Exception e) {
|
||||
log.error("获取租户列表失败", e);
|
||||
return Result.failed("获取租户列表失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Map<String, Object>> getTenantStatistics() {
|
||||
try {
|
||||
Map<String, Object> statistics = new HashMap<>();
|
||||
statistics.put("totalTenants", TENANT_STORE.size());
|
||||
statistics.put("webAppTenants", TENANT_STORE.containsKey("webApp") ? 1 : 0);
|
||||
statistics.put("regularTenants", TENANT_STORE.size() - (TENANT_STORE.containsKey("webApp") ? 1 : 0));
|
||||
statistics.put("lastUpdateTime", System.currentTimeMillis());
|
||||
|
||||
log.info("获取租户统计信息: {}", statistics);
|
||||
return Result.succeed(statistics, "获取统计信息成功");
|
||||
} catch (Exception e) {
|
||||
log.error("获取租户统计信息失败", e);
|
||||
return Result.failed("获取统计信息失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTenantExists(String tenantId) {
|
||||
return TENANT_STORE.containsKey(tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> createTenant(Map<String, Object> tenantInfo) {
|
||||
try {
|
||||
String tenantId = (String) tenantInfo.get("tenantId");
|
||||
if (tenantId == null || tenantId.trim().isEmpty()) {
|
||||
return Result.failed("租户ID不能为空");
|
||||
}
|
||||
|
||||
if (isTenantExists(tenantId)) {
|
||||
return Result.failed("租户已存在");
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
tenantInfo.put("createTime", System.currentTimeMillis());
|
||||
tenantInfo.put("level", "user");
|
||||
tenantInfo.put("canQueryAllData", false);
|
||||
|
||||
TENANT_STORE.put(tenantId, new HashMap<>(tenantInfo));
|
||||
|
||||
log.info("创建新租户成功: {}", tenantId);
|
||||
return Result.succeed(tenantId, "租户创建成功");
|
||||
} catch (Exception e) {
|
||||
log.error("创建租户失败", e);
|
||||
return Result.failed("创建租户失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> deleteTenant(String tenantId) {
|
||||
try {
|
||||
if ("webApp".equals(tenantId)) {
|
||||
return Result.failed("不能删除系统管理租户");
|
||||
}
|
||||
|
||||
if (!isTenantExists(tenantId)) {
|
||||
return Result.failed("租户不存在");
|
||||
}
|
||||
|
||||
TENANT_STORE.remove(tenantId);
|
||||
|
||||
log.info("删除租户成功: {}", tenantId);
|
||||
return Result.succeed(tenantId, "租户删除成功");
|
||||
} catch (Exception e) {
|
||||
log.error("删除租户失败", e);
|
||||
return Result.failed("删除租户失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> updateTenant(String tenantId, Map<String, Object> tenantInfo) {
|
||||
try {
|
||||
if (!isTenantExists(tenantId)) {
|
||||
return Result.failed("租户不存在");
|
||||
}
|
||||
|
||||
Map<String, Object> existingTenant = TENANT_STORE.get(tenantId);
|
||||
existingTenant.putAll(tenantInfo);
|
||||
existingTenant.put("updateTime", System.currentTimeMillis());
|
||||
|
||||
log.info("更新租户信息成功: {}", tenantId);
|
||||
return Result.succeed(tenantId, "租户信息更新成功");
|
||||
} catch (Exception e) {
|
||||
log.error("更新租户信息失败", e);
|
||||
return Result.failed("更新租户信息失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -94,7 +94,9 @@ public class WechatConfigServiceImpl extends ServiceImpl<WechatConfigMapper, Wec
|
||||
return getOne(new LambdaQueryWrapper<WechatConfig>()
|
||||
.eq(WechatConfig::getSubMchId, subMchId)
|
||||
.eq(WechatConfig::getIsServiceMode, true)
|
||||
.eq(WechatConfig::getStatus, 1));
|
||||
.eq(WechatConfig::getStatus, 1)
|
||||
.orderByDesc(WechatConfig::getId) // 按ID倒序,取最新的
|
||||
.last("LIMIT 1")); // 明确限制只取第一条
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,7 +39,7 @@ zlt:
|
||||
- sys_user
|
||||
- sys_role_user
|
||||
- sys_role_menu
|
||||
- mini_app_config
|
||||
- wechat_config
|
||||
ignoreSqls:
|
||||
# 用户关联角色时,显示所有角色
|
||||
- com.central.user.mapper.SysRoleMapper.findAll
|
||||
|
||||
@@ -4,10 +4,10 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: user-center
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# ip: 124.222.128.40
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
ip: 124.222.128.40
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
|
||||
+12
-1
@@ -9,6 +9,7 @@ import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
@@ -20,6 +21,7 @@ import java.io.IOException;
|
||||
* @author zlt
|
||||
* @date 2019/9/15
|
||||
*/
|
||||
@Slf4j
|
||||
@ConditionalOnClass(Filter.class)
|
||||
public class TenantFilter extends OncePerRequestFilter {
|
||||
@Override
|
||||
@@ -31,13 +33,22 @@ public class TenantFilter extends OncePerRequestFilter {
|
||||
if (StrUtil.isEmpty(tenantId)) {
|
||||
tenantId = request.getHeader(SecurityConstants.TENANT_HEADER);
|
||||
}
|
||||
|
||||
log.debug("请求URL: {}, 租户ID: {}", request.getRequestURI(), tenantId);
|
||||
|
||||
//保存租户id
|
||||
if (StrUtil.isNotEmpty(tenantId)) {
|
||||
if (StrUtil.isNotEmpty(tenantId) && null != tenantId) {
|
||||
TenantContextHolder.setTenant(tenantId);
|
||||
log.debug("设置租户上下文: {}", tenantId);
|
||||
} else {
|
||||
TenantContextHolder.setTenant("webApp");
|
||||
log.debug("未找到租户ID,使用默认租户");
|
||||
}
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
} finally {
|
||||
String currentTenant = TenantContextHolder.getTenant();
|
||||
log.debug("清理租户上下文: {}", currentTenant);
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
+36
-5
@@ -5,8 +5,8 @@ import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.properties.TenantProperties;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.NullValue;
|
||||
import net.sf.jsqlparser.expression.StringValue;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -18,6 +18,7 @@ import org.springframework.context.annotation.Bean;
|
||||
* @author zlt
|
||||
* @date 2019/8/5
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableConfigurationProperties(TenantProperties.class)
|
||||
public class TenantAutoConfigure {
|
||||
@Autowired
|
||||
@@ -31,17 +32,29 @@ public class TenantAutoConfigure {
|
||||
*/
|
||||
@Override
|
||||
public Expression getTenantId() {
|
||||
log.debug("=== 开始处理租户过滤 ===");
|
||||
|
||||
// 判断当前用户是否为超级管理员
|
||||
if (isSuperAdmin()) {
|
||||
// 超级管理员返回Null,不加租户条件
|
||||
return new NullValue();
|
||||
log.debug("超级管理员用户,跳过租户过滤");
|
||||
return new StringValue(""); // 返回空字符串,避免NULL条件
|
||||
}
|
||||
|
||||
String tenant = TenantContextHolder.getTenant();
|
||||
log.debug("当前租户: {}", tenant);
|
||||
|
||||
if (tenant != null) {
|
||||
// webApp 租户可以查询所有数据,返回空字符串
|
||||
if ("webApp".equals(tenant)) {
|
||||
log.debug("webApp租户,跳过租户过滤,可以查询所有数据");
|
||||
return new StringValue(""); // 返回空字符串,避免NULL条件
|
||||
}
|
||||
log.debug("普通租户: {},添加租户过滤条件", tenant);
|
||||
return new StringValue(TenantContextHolder.getTenant());
|
||||
}
|
||||
return new NullValue();
|
||||
log.debug("无租户信息,跳过租户过滤");
|
||||
return new StringValue(""); // 返回空字符串,避免NULL条件
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,9 +63,23 @@ public class TenantAutoConfigure {
|
||||
*/
|
||||
@Override
|
||||
public boolean ignoreTable(String tableName) {
|
||||
return tenantProperties.getIgnoreTables().stream().anyMatch(
|
||||
// 获取当前租户
|
||||
String tenant = TenantContextHolder.getTenant();
|
||||
|
||||
// webApp 租户或超级管理员跳过所有表的租户过滤
|
||||
if ("webApp".equals(tenant) || isSuperAdmin()) {
|
||||
log.debug("webApp租户或超级管理员,表 {} 被忽略租户过滤", tableName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查配置的忽略表
|
||||
boolean ignore = tenantProperties.getIgnoreTables().stream().anyMatch(
|
||||
(e) -> e.equalsIgnoreCase(tableName)
|
||||
);
|
||||
if (ignore) {
|
||||
log.debug("表 {} 被忽略租户过滤", tableName);
|
||||
}
|
||||
return ignore;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -62,6 +89,10 @@ public class TenantAutoConfigure {
|
||||
// 例如:
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
//@TODO 暂定admin和mgnt为系统管理员
|
||||
return user != null && (user.getUsername().equals("admin") || user.getUsername().equals("mgnt"));
|
||||
boolean isAdmin = user != null && (user.getUsername().equals("admin") || user.getUsername().equals("mgnt"));
|
||||
if (isAdmin) {
|
||||
log.debug("当前用户为超级管理员: {}", user.getUsername());
|
||||
}
|
||||
return isAdmin;
|
||||
}
|
||||
}
|
||||
|
||||
+31
-3
@@ -2,6 +2,7 @@ package com.central.db.interceptor;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
@@ -21,6 +22,7 @@ import java.util.List;
|
||||
* Blog: http://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Slf4j
|
||||
public class CustomTenantInterceptor extends TenantLineInnerInterceptor {
|
||||
private List<String> ignoreSqls;
|
||||
private List<String> noIgnoreSqls;
|
||||
@@ -34,13 +36,34 @@ public class CustomTenantInterceptor extends TenantLineInnerInterceptor {
|
||||
@Override
|
||||
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds
|
||||
, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
|
||||
if (isIgnoreMappedStatement(ms.getId())) {
|
||||
String msId = ms.getId();
|
||||
log.debug("租户拦截器处理SQL: {}", msId);
|
||||
|
||||
// 获取当前租户
|
||||
String tenant = com.central.common.context.TenantContextHolder.getTenant();
|
||||
|
||||
// webApp 租户或超级管理员直接跳过租户过滤
|
||||
if ("webApp".equals(tenant) || isSuperAdmin()) {
|
||||
log.debug("webApp租户或超级管理员,SQL {} 跳过租户过滤", msId);
|
||||
return;
|
||||
}
|
||||
if (isNoIgnoreMappedStatement(ms.getId())) {
|
||||
super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
|
||||
|
||||
// 租户为null时跳过租户过滤
|
||||
log.debug("租户ID: {}", tenant);
|
||||
if (null == tenant ) {
|
||||
log.debug("租户为null,SQL {} 跳过租户过滤", msId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果在忽略列表中,直接返回,不执行租户过滤
|
||||
if (isIgnoreMappedStatement(msId)) {
|
||||
log.debug("SQL {} 在忽略列表中,跳过租户过滤", msId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 所有其他SQL都执行租户过滤处理
|
||||
log.debug("SQL {} 执行租户过滤", msId);
|
||||
super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
|
||||
}
|
||||
|
||||
private boolean isIgnoreMappedStatement(String msId) {
|
||||
@@ -50,4 +73,9 @@ public class CustomTenantInterceptor extends TenantLineInnerInterceptor {
|
||||
private boolean isNoIgnoreMappedStatement(String msId) {
|
||||
return noIgnoreSqls.stream().anyMatch((e) -> e.equalsIgnoreCase(msId));
|
||||
}
|
||||
|
||||
private boolean isSuperAdmin() {
|
||||
com.central.common.model.LoginAppUser user = com.central.common.context.LoginUserContextHolder.getUser();
|
||||
return user != null && (user.getUsername().equals("admin") || user.getUsername().equals("mgnt"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,8 @@ zlt:
|
||||
/api-order/user/temp,
|
||||
/api-file/file/expires,
|
||||
/api-order/refund/auto,
|
||||
/api-order/files/exists/**
|
||||
/api-order/files/exists/**,
|
||||
/api-order/coupon/ctrip/create
|
||||
auth:
|
||||
urlPermission:
|
||||
#是否开启url级别权限
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button } from 'antd';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button, Switch } from 'antd';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { dashboard } from '@/services/orders/api';
|
||||
import { dashboard, getQrcodeOptions } from '@/services/orders/api';
|
||||
import { Area, Column, Pie } from '@ant-design/plots';
|
||||
import {
|
||||
ShoppingCartOutlined,
|
||||
@@ -15,6 +15,28 @@ import styles from './Welcome.less';
|
||||
const { Title } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
// 平台分账比例选项
|
||||
const PLATFORM_RATE_OPTIONS = [
|
||||
{ label: '90% (平台90%)', value: 0.9 },
|
||||
{ label: '85% (平台85%)', value: 0.85 },
|
||||
{ label: '80% (平台80%)', value: 0.8 },
|
||||
{ label: '75% (平台75%)', value: 0.75 },
|
||||
{ label: '70% (平台70%)', value: 0.7 },
|
||||
{ label: '65% (平台65%)', value: 0.65 },
|
||||
{ label: '60% (平台60%)', value: 0.6 },
|
||||
{ label: '55% (平台55%)', value: 0.55 },
|
||||
{ label: '50% (平台50%)', value: 0.5 },
|
||||
{ label: '45% (平台45%)', value: 0.45 },
|
||||
{ label: '40% (平台40%)', value: 0.4 },
|
||||
{ label: '35% (平台35%)', value: 0.35 },
|
||||
{ label: '30% (平台30%)', value: 0.3 },
|
||||
{ label: '25% (平台25%)', value: 0.25 },
|
||||
{ label: '20% (平台20%)', value: 0.2 },
|
||||
{ label: '15% (平台15%)', value: 0.15 },
|
||||
{ label: '10% (平台10%)', value: 0.1 },
|
||||
{ label: '5% (平台5%)', value: 0.05 },
|
||||
];
|
||||
|
||||
interface Statistics {
|
||||
orderStats: {
|
||||
totalOrders: number;
|
||||
@@ -57,18 +79,24 @@ const Welcome: React.FC = () => {
|
||||
const [statistics, setStatistics] = useState<any>({});
|
||||
// 只保留景区筛选
|
||||
const [selectedTourism, setSelectedTourism] = useState<number | undefined>();
|
||||
// 新增二维码筛选
|
||||
const [selectedQrcode, setSelectedQrcode] = useState<string | undefined>();
|
||||
// 新增平台分账比例,默认70%
|
||||
const [platformRate, setPlatformRate] = useState<number>(0.7);
|
||||
// 新增时间区间筛选
|
||||
const [timeRange, setTimeRange] = useState<[string, string]>(['', '']);
|
||||
// 新增是否包含测试二维码筛选,默认不包含
|
||||
const [includeTestQrcodes, setIncludeTestQrcodes] = useState<boolean>(false);
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const params = {
|
||||
tourismId: selectedTourism,
|
||||
qrcodeId: selectedQrcode,
|
||||
startTime: timeRange[0],
|
||||
endTime: timeRange[1],
|
||||
includeTestQrcodes: includeTestQrcodes,
|
||||
};
|
||||
const result = await dashboard(params);
|
||||
if (result.resp_code === 0) {
|
||||
@@ -83,7 +111,47 @@ const Welcome: React.FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [selectedTourism, timeRange]);
|
||||
}, [selectedTourism, selectedQrcode, timeRange, includeTestQrcodes]);
|
||||
|
||||
// 处理景区选择变化
|
||||
const handleTourismChange = (tourismId: number | undefined) => {
|
||||
setSelectedTourism(tourismId);
|
||||
// 当景区变化时,清空二维码选择
|
||||
setSelectedQrcode(undefined);
|
||||
// 重新获取二维码选项
|
||||
fetchQrcodeOptions(tourismId);
|
||||
};
|
||||
|
||||
// 获取当前景区下的二维码选项
|
||||
const getCurrentTourismQrcodes = () => {
|
||||
if (!selectedTourism) return [];
|
||||
// 从筛选选项中获取当前景区的二维码
|
||||
return filterOptions.qrcodeList || [];
|
||||
};
|
||||
|
||||
// 获取二维码列表
|
||||
const fetchQrcodeOptions = async (tourismId: number | undefined) => {
|
||||
if (!tourismId) return;
|
||||
try {
|
||||
const params = {
|
||||
tourismId: tourismId,
|
||||
includeTestQrcodes: includeTestQrcodes,
|
||||
};
|
||||
const result = await getQrcodeOptions(params);
|
||||
if (result.resp_code === 0 && result.data?.qrcodeList) {
|
||||
// 更新二维码选项
|
||||
setStatistics((prev: any) => ({
|
||||
...prev,
|
||||
filterOptions: {
|
||||
...prev.filterOptions,
|
||||
qrcodeList: result.data.qrcodeList
|
||||
}
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取二维码列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 更新数据访问方式
|
||||
const orderStats = statistics.orderStats || {};
|
||||
@@ -153,20 +221,50 @@ const Welcome: React.FC = () => {
|
||||
allowClear
|
||||
options={filterOptions.tourismList || []}
|
||||
value={selectedTourism}
|
||||
onChange={setSelectedTourism}
|
||||
onChange={handleTourismChange}
|
||||
/>
|
||||
{/* 新增二维码选择器 */}
|
||||
<Select
|
||||
placeholder="选择二维码"
|
||||
style={{ width: 200 }}
|
||||
allowClear
|
||||
disabled={!selectedTourism}
|
||||
options={getCurrentTourismQrcodes()}
|
||||
value={selectedQrcode}
|
||||
onChange={setSelectedQrcode}
|
||||
/>
|
||||
{/* 新增平台分账比例选择 */}
|
||||
<span>平台分账比例:</span>
|
||||
<Select
|
||||
style={{ width: 120 }}
|
||||
style={{ width: 140 }}
|
||||
value={platformRate}
|
||||
onChange={setPlatformRate}
|
||||
options={[
|
||||
{ label: '70%', value: 0.7 },
|
||||
{ label: '60%', value: 0.6 },
|
||||
{ label: '50%', value: 0.5 },
|
||||
]}
|
||||
showSearch
|
||||
placeholder="选择分账比例"
|
||||
optionFilterProp="label"
|
||||
filterOption={(input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
||||
}
|
||||
options={PLATFORM_RATE_OPTIONS}
|
||||
/>
|
||||
<span style={{ color: '#666', fontSize: '12px' }}>
|
||||
(当前:平台{Math.round(platformRate * 100)}% | 景区{Math.round((1 - platformRate) * 100)}%)
|
||||
</span>
|
||||
{/* 快速选择常用分账比例 */}
|
||||
<Space size="small">
|
||||
<span style={{ color: '#666', fontSize: '12px' }}>快速选择:</span>
|
||||
{[0.7, 0.6, 0.5, 0.4, 0.3].map(rate => (
|
||||
<Button
|
||||
key={rate}
|
||||
size="small"
|
||||
type={platformRate === rate ? 'primary' : 'default'}
|
||||
onClick={() => setPlatformRate(rate)}
|
||||
style={{ fontSize: '11px', padding: '0 6px' }}
|
||||
>
|
||||
{Math.round(rate * 100)}%
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
{/* 新增时间区间筛选 */}
|
||||
<RangePicker
|
||||
placeholder={['开始时间', '结束时间']}
|
||||
@@ -190,6 +288,14 @@ const Welcome: React.FC = () => {
|
||||
>
|
||||
刷新
|
||||
</Button>
|
||||
{/* 新增测试二维码筛选开关 */}
|
||||
<span>包含测试二维码:</span>
|
||||
<Switch
|
||||
checked={includeTestQrcodes}
|
||||
onChange={setIncludeTestQrcodes}
|
||||
checkedChildren="是"
|
||||
unCheckedChildren="否"
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -9,6 +9,12 @@ import {
|
||||
import { Form } from 'antd';
|
||||
import { ENABLE_PROFIT_OPTIONS, PAYEE_TYPE_OPTIONS, ENABLE_VIDEO_EDIT_OPTIONS } from '../index';
|
||||
|
||||
// 添加测试二维码选项常量
|
||||
export const IS_TEST_OPTIONS = [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
];
|
||||
|
||||
interface CreateFormProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
@@ -184,6 +190,15 @@ const CreateForm: React.FC<CreateFormProps> = ({
|
||||
rules={[{ required: true, message: '请选择是否开启一键成片' }]}
|
||||
initialValue={0}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="isTest"
|
||||
label="是否为测试二维码"
|
||||
options={IS_TEST_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择是否为测试二维码' }]}
|
||||
initialValue={0}
|
||||
tooltip="测试二维码的数据不会计入正式统计"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
|
||||
@@ -10,6 +10,12 @@ import { STATUS_OPTIONS, PAYEE_TYPE_OPTIONS, ENABLE_PROFIT_OPTIONS, ENABLE_VIDEO
|
||||
import { Form, Space } from 'antd';
|
||||
import styles from './index.less';
|
||||
|
||||
// 添加测试二维码选项常量
|
||||
export const IS_TEST_OPTIONS = [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
];
|
||||
|
||||
interface UpdateFormProps {
|
||||
updateModalVisible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
@@ -184,6 +190,14 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
options={ENABLE_VIDEO_EDIT_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择是否开启一键成片' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="isTest"
|
||||
label="是否为测试二维码"
|
||||
options={IS_TEST_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择是否为测试二维码' }]}
|
||||
tooltip="测试二维码的数据不会计入正式统计"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
|
||||
@@ -55,6 +55,12 @@ export const ENABLE_VIDEO_EDIT_OPTIONS = [
|
||||
{ label: '是', value: 1 },
|
||||
] as const;
|
||||
|
||||
// 添加测试二维码选项常量
|
||||
export const IS_TEST_OPTIONS = [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
] as const;
|
||||
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
@@ -91,7 +97,7 @@ const TableList: React.FC = () => {
|
||||
|
||||
// 将 renderStatus 函数移到组件内部
|
||||
const renderStatus = (status: number) => {
|
||||
const statusColorMap = {
|
||||
const statusColorMap: Record<number, { color: string; text: string }> = {
|
||||
0: { color: 'green', text: '启用' },
|
||||
1: { color: 'red', text: '未启用' },
|
||||
};
|
||||
@@ -100,12 +106,12 @@ const TableList: React.FC = () => {
|
||||
};
|
||||
|
||||
// 处理添加
|
||||
const handleAdd = async (fields: ORDERS.Qrcode) => {
|
||||
const handleAdd = async (fields: Partial<ORDERS.Qrcode>) => {
|
||||
const template = templateOptions.find(item => item.value === fields.templateId);
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateQrcode({
|
||||
...fields,
|
||||
}),
|
||||
} as ORDERS.Qrcode),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
@@ -170,7 +176,7 @@ const TableList: React.FC = () => {
|
||||
});
|
||||
|
||||
if (result?.data) {
|
||||
const options = result.data.map(item => ({
|
||||
const options = result.data.map((item: any) => ({
|
||||
label: item.tourismName || item.name,
|
||||
value: item.id,
|
||||
info: item
|
||||
@@ -205,7 +211,7 @@ const TableList: React.FC = () => {
|
||||
});
|
||||
|
||||
if (result?.data) {
|
||||
const options = result.data.map((item: DEVICE.Device) => ({
|
||||
const options = result.data.map((item: any) => ({
|
||||
label: `${item.deviceName}(${item.deviceSn})`,
|
||||
value: item.deviceSn,
|
||||
info: item
|
||||
@@ -225,7 +231,7 @@ const TableList: React.FC = () => {
|
||||
status: 1, // 只获取启用的模板
|
||||
});
|
||||
if (result.data?.data) {
|
||||
const options = result.data.data.map(item => ({
|
||||
const options = result.data.data.map((item: any) => ({
|
||||
label: item.templateName,
|
||||
value: item.templateId,
|
||||
info: item,
|
||||
@@ -418,6 +424,20 @@ const TableList: React.FC = () => {
|
||||
1: { text: '是' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '是否为测试二维码',
|
||||
dataIndex: 'isTest',
|
||||
width: 140,
|
||||
render: (_, record) => {
|
||||
const status = record.isTest === 1 ? '是' : '否';
|
||||
const color = record.isTest === 1 ? 'blue' : 'default';
|
||||
return <Tag color={color}>{status}</Tag>;
|
||||
},
|
||||
valueEnum: {
|
||||
0: { text: '否' },
|
||||
1: { text: '是' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
@@ -480,6 +500,12 @@ const TableList: React.FC = () => {
|
||||
placeholder="请选择状态"
|
||||
options={STATUS_OPTIONS}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="isTest"
|
||||
label="是否为测试二维码"
|
||||
placeholder="请选择是否为测试二维码"
|
||||
options={IS_TEST_OPTIONS}
|
||||
/>
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.Qrcode>
|
||||
rowKey="id"
|
||||
|
||||
+38
@@ -4,6 +4,7 @@ import {
|
||||
ProFormText,
|
||||
ProFormSelect,
|
||||
ProFormTextArea,
|
||||
ProFormDigit,
|
||||
} from '@ant-design/pro-components';
|
||||
import React from 'react';
|
||||
|
||||
@@ -30,6 +31,14 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
const formRules = {
|
||||
required: { required: true, message: '此项为必填项' },
|
||||
phone: { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' },
|
||||
longitude: {
|
||||
pattern: /^-?((1[0-7][0-9]|[1-9]?[0-9])\.\d{1,6}|180\.0{1,6})$/,
|
||||
message: '经度范围应在-180到180之间,最多6位小数'
|
||||
},
|
||||
latitude: {
|
||||
pattern: /^-?([1-8]?[0-9]\.\d{1,6}|90\.0{1,6})$/,
|
||||
message: '纬度范围应在-90到90之间,最多6位小数'
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -79,6 +88,35 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
name="longitude"
|
||||
label="经度"
|
||||
width="md"
|
||||
rules={[formRules.longitude]}
|
||||
placeholder="请输入经度(-180到180)"
|
||||
fieldProps={{
|
||||
precision: 6,
|
||||
min: -180,
|
||||
max: 180,
|
||||
}}
|
||||
tooltip="经度范围:-180到180,用于附近景区查询功能"
|
||||
/>
|
||||
<ProFormDigit
|
||||
name="latitude"
|
||||
label="纬度"
|
||||
width="md"
|
||||
rules={[formRules.latitude]}
|
||||
placeholder="请输入纬度(-90到90)"
|
||||
fieldProps={{
|
||||
precision: 6,
|
||||
min: -90,
|
||||
max: 90,
|
||||
}}
|
||||
tooltip="纬度范围:-90到90,用于附近景区查询功能"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
name="tenantId"
|
||||
|
||||
@@ -10,8 +10,9 @@ import {
|
||||
ProFormSelect,
|
||||
ProFormTextArea,
|
||||
ProTable,
|
||||
ProFormDigit,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, message, Popconfirm, Button, Space } from 'antd';
|
||||
import { Typography, message, Popconfirm, Button, Space, Tag } from 'antd';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
@@ -142,6 +143,22 @@ const TableList: React.FC = () => {
|
||||
dataIndex: 'tourismPhone',
|
||||
copyable: true,
|
||||
},
|
||||
{
|
||||
title: '经纬度',
|
||||
dataIndex: 'location',
|
||||
hideInSearch: true,
|
||||
render: (_, record) => {
|
||||
const hasLocation = record.longitude && record.latitude;
|
||||
return hasLocation ? (
|
||||
<Space direction="vertical" size="small">
|
||||
<Tag color="blue">经度: {record.longitude}</Tag>
|
||||
<Tag color="green">纬度: {record.latitude}</Tag>
|
||||
</Space>
|
||||
) : (
|
||||
<Tag color="red">未设置</Tag>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '租户ID',
|
||||
dataIndex: 'tenantId',
|
||||
@@ -192,6 +209,14 @@ const TableList: React.FC = () => {
|
||||
const formRules = {
|
||||
required: { required: true, message: '此项为必填项' },
|
||||
phone: { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' },
|
||||
longitude: {
|
||||
pattern: /^-?((1[0-7][0-9]|[1-9]?[0-9])\.\d{1,6}|180\.0{1,6})$/,
|
||||
message: '经度范围应在-180到180之间,最多6位小数'
|
||||
},
|
||||
latitude: {
|
||||
pattern: /^-?([1-8]?[0-9]\.\d{1,6}|90\.0{1,6})$/,
|
||||
message: '纬度范围应在-90到90之间,最多6位小数'
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -265,6 +290,35 @@ const TableList: React.FC = () => {
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
name="longitude"
|
||||
label="经度"
|
||||
width="md"
|
||||
rules={[formRules.longitude]}
|
||||
placeholder="请输入经度(-180到180)"
|
||||
fieldProps={{
|
||||
precision: 6,
|
||||
min: -180,
|
||||
max: 180,
|
||||
}}
|
||||
tooltip="经度范围:-180到180,用于附近景区查询功能"
|
||||
/>
|
||||
<ProFormDigit
|
||||
name="latitude"
|
||||
label="纬度"
|
||||
width="md"
|
||||
rules={[formRules.latitude]}
|
||||
placeholder="请输入纬度(-90到90)"
|
||||
fieldProps={{
|
||||
precision: 6,
|
||||
min: -90,
|
||||
max: 90,
|
||||
}}
|
||||
tooltip="纬度范围:-90到90,用于附近景区查询功能"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
name="tenantId"
|
||||
|
||||
@@ -190,6 +190,7 @@ export async function dashboard(params?: {
|
||||
deviceSn?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
includeTestQrcodes?: boolean;
|
||||
}) {
|
||||
return request('/api-order/dashboard/statistics', {
|
||||
method: 'GET',
|
||||
@@ -197,6 +198,17 @@ export async function dashboard(params?: {
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取二维码列表 GET /api-order/qrcode/options */
|
||||
export async function getQrcodeOptions(params?: {
|
||||
tourismId?: number;
|
||||
includeTestQrcodes?: boolean;
|
||||
}) {
|
||||
return request('/api-order/dashboard/qrcode/options', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/** 分页查询分账记录 */
|
||||
export async function profitSharingList(params: {
|
||||
page: number;
|
||||
|
||||
@@ -33,12 +33,20 @@ declare namespace ORDERS {
|
||||
tourismNo: string;
|
||||
tourismAddress: string;
|
||||
tourismPhone: string;
|
||||
longitude?: number; // 经度
|
||||
latitude?: number; // 纬度
|
||||
createTime?: string;
|
||||
status: number;
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
type TourismWithDistance = Tourism & {
|
||||
distance?: number; // 距离(公里)
|
||||
distanceDesc?: string; // 距离描述
|
||||
orderShowImageUrl?: string; // 景区订单展示图片URL
|
||||
}
|
||||
|
||||
type TourismFile = {
|
||||
id: number;
|
||||
tourismId: string;
|
||||
@@ -55,9 +63,11 @@ declare namespace ORDERS {
|
||||
type Qrcode = {
|
||||
id: number;
|
||||
codeId: string;
|
||||
name?: string;
|
||||
tourismId: string;
|
||||
path: string;
|
||||
fileId: string;
|
||||
viewUrl?: string;
|
||||
price: string;
|
||||
deviceSn: string;
|
||||
createTime?: string;
|
||||
@@ -71,6 +81,10 @@ declare namespace ORDERS {
|
||||
payeeFailReason?: string;
|
||||
templateId: string;
|
||||
materialCount?: number;
|
||||
isTest?: number; // 是否为测试二维码(0:否,1:是)
|
||||
enableProfit?: number; // 是否开启分润(0:否,1:是)
|
||||
enableVideoEdit?: number; // 是否开启一键成片(0:否,1:是)
|
||||
waylineId?: string; // 航线ID
|
||||
}
|
||||
|
||||
type HomeCarousel = {
|
||||
|
||||
Reference in New Issue
Block a user