Эх сурвалжийг харах

fix 外卖订单新增订单状态字典、支付类型字典、退款状态字典

classic_blue 5 сар өмнө
parent
commit
1397a32c0d

+ 19 - 11
application-webadmin/src/main/java/com/tourism/webadmin/back/controller/DeliveryOrderController.java

@@ -5,16 +5,14 @@ import com.alibaba.fastjson.JSONObject;
 import com.tourism.common.log.annotation.OperationLog;
 import com.tourism.common.log.model.constant.SysOperationLogType;
 import com.github.pagehelper.page.PageMethod;
+import com.tourism.webadmin.back.vo.*;
+import com.tourism.webadmin.back.dto.*;
+import com.tourism.webadmin.back.model.*;
+import com.tourism.webadmin.back.service.*;
 import com.tourism.common.core.object.*;
 import com.tourism.common.core.util.*;
 import com.tourism.common.core.constant.*;
 import com.tourism.common.core.annotation.MyRequestBody;
-import com.tourism.webadmin.back.dto.DeliveryOrderDto;
-import com.tourism.webadmin.back.dto.DeliveryOrderItemsDto;
-import com.tourism.webadmin.back.model.DeliveryOrder;
-import com.tourism.webadmin.back.model.DeliveryOrderItems;
-import com.tourism.webadmin.back.service.DeliveryOrderService;
-import com.tourism.webadmin.back.vo.DeliveryOrderVo;
 import com.tourism.common.additional.config.ApplicationConfig;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -191,6 +189,11 @@ public class DeliveryOrderController {
         Set<String> translatedDictFieldSet = new HashSet<>();
         List<DeliveryOrder> dataList =
                 ImportUtil.doImport(headerInfos, skipHeader, filename, DeliveryOrder.class, translatedDictFieldSet);
+        CallResult result = deliveryOrderService.verifyImportList(dataList, translatedDictFieldSet);
+        if (!result.isSuccess()) {
+            // result中返回了具体的验证失败对象,如果需要返回更加详细的错误,可根据实际情况手动修改。
+            return ResponseResult.errorFrom(result);
+        }
         deliveryOrderService.saveNewBatch(dataList, -1);
         return ResponseResult.success();
     }
@@ -215,7 +218,7 @@ public class DeliveryOrderController {
         // 导出文件的标题数组
         // NOTE: 下面的代码中仅仅导出了主表数据,主表聚合计算数据和主表关联字典的数据。
         // 一对一从表数据的导出,可根据需要自行添加。如:headerMap.put("slaveFieldName.xxxField", "标题名称")
-        Map<String, String> headerMap = new LinkedHashMap<>(21);
+        Map<String, String> headerMap = new LinkedHashMap<>(22);
         headerMap.put("id", "主键");
         headerMap.put("deliveryTime", "配送时间");
         headerMap.put("deliveryAddress", "配送地址");
@@ -224,12 +227,12 @@ public class DeliveryOrderController {
         headerMap.put("tableware", "餐具数量");
         headerMap.put("orderNo", "订单号");
         headerMap.put("orderTime", "下单时间");
-        headerMap.put("payType", "支付方式");
+        headerMap.put("payTypeDictMap.name", "支付方式");
         headerMap.put("orderAmount", "订单金额");
         headerMap.put("payAmount", "实付金额");
-        headerMap.put("orderStatus", "订单状态");
+        headerMap.put("orderStatusDictMap.name", "订单状态");
         headerMap.put("customerId", "用户id");
-        headerMap.put("refundStatus", "退款状态");
+        headerMap.put("refundStatusDictMap.name", "退款状态");
         headerMap.put("packCharge", "打包费");
         headerMap.put("deliveryFee", "配送费");
         headerMap.put("createUserId", "创建用户");
@@ -237,6 +240,7 @@ public class DeliveryOrderController {
         headerMap.put("updateUserId", "更新用户");
         headerMap.put("updateTime", "更新时间");
         headerMap.put("dataState", "删除标记(1: 正常 -1: 已删除)");
+        headerMap.put("shopName", "店铺名称");
         ExportUtil.doExport(resultList, headerMap, "deliveryOrder.xlsx");
     }
 
@@ -276,7 +280,7 @@ public class DeliveryOrderController {
         CallResult verifyResult;
         // 下面是输入参数中,主表关联数据的验证。
         DeliveryOrder deliveryOrder = MyModelUtil.copyTo(deliveryOrderDto, DeliveryOrder.class);
-        DeliveryOrder originalData;
+        DeliveryOrder originalData = null;
         if (forUpdate && deliveryOrder != null) {
             originalData = deliveryOrderService.getById(deliveryOrder.getId());
             if (originalData == null) {
@@ -284,6 +288,10 @@ public class DeliveryOrderController {
             }
             relationData.put("originalData", originalData);
         }
+        verifyResult = deliveryOrderService.verifyRelatedData(deliveryOrder, originalData);
+        if (!verifyResult.isSuccess()) {
+            return ResponseResult.errorFrom(verifyResult);
+        }
         // 处理主表的一对多关联 [DeliveryOrderItems]
         List<DeliveryOrderItems> deliveryOrderItemsList =
                 MyModelUtil.copyCollectionTo(deliveryOrderItemsDtoList, DeliveryOrderItems.class);

+ 4 - 4
application-webadmin/src/main/java/com/tourism/webadmin/back/controller/DeliveryOrderItemsController.java

@@ -4,14 +4,14 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 import com.tourism.common.log.annotation.OperationLog;
 import com.tourism.common.log.model.constant.SysOperationLogType;
 import com.github.pagehelper.page.PageMethod;
+import com.tourism.webadmin.back.vo.*;
+import com.tourism.webadmin.back.dto.*;
+import com.tourism.webadmin.back.model.*;
+import com.tourism.webadmin.back.service.*;
 import com.tourism.common.core.object.*;
 import com.tourism.common.core.util.*;
 import com.tourism.common.core.constant.*;
 import com.tourism.common.core.annotation.MyRequestBody;
-import com.tourism.webadmin.back.dto.DeliveryOrderItemsDto;
-import com.tourism.webadmin.back.model.DeliveryOrderItems;
-import com.tourism.webadmin.back.service.DeliveryOrderItemsService;
-import com.tourism.webadmin.back.vo.DeliveryOrderItemsVo;
 import com.tourism.common.additional.config.ApplicationConfig;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.v3.oas.annotations.tags.Tag;

+ 4 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/dao/mapper/DeliveryOrderMapper.xml

@@ -87,6 +87,10 @@
     <!-- 这里仅包含调用接口输入的主表过滤条件 -->
     <sql id="inputFilterRef">
         <if test="deliveryOrderFilter != null">
+            <if test="deliveryOrderFilter.shopName != null and deliveryOrderFilter.shopName != ''">
+                <bind name = "safeDeliveryOrderShopName" value = "'%' + deliveryOrderFilter.shopName + '%'" />
+                AND tour_delivery_order.shop_name LIKE #{safeDeliveryOrderShopName}
+            </if>
             <if test="deliveryOrderFilter.deliveryPhone != null and deliveryOrderFilter.deliveryPhone != ''">
                 <bind name = "safeDeliveryOrderDeliveryPhone" value = "'%' + deliveryOrderFilter.deliveryPhone + '%'" />
                 AND tour_delivery_order.delivery_phone LIKE #{safeDeliveryOrderDeliveryPhone}

+ 21 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/model/DeliveryOrder.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.tourism.common.core.annotation.MaskField;
+import com.tourism.common.core.annotation.RelationGlobalDict;
 import com.tourism.common.core.base.model.BaseModel;
 import com.tourism.common.core.constant.MaskFieldTypeEnum;
 import lombok.Data;
@@ -13,6 +14,7 @@ import lombok.EqualsAndHashCode;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 外卖订单管理实体对象。
@@ -140,4 +142,23 @@ public class DeliveryOrder extends BaseModel {
      */
     @TableField(exist = false)
     private List<DeliveryOrderItems> itemList;
+
+
+    @RelationGlobalDict(
+            masterIdField = "payType",
+            dictCode = "DeliveryPayType")
+    @TableField(exist = false)
+    private Map<String, Object> payTypeDictMap;
+
+    @RelationGlobalDict(
+            masterIdField = "orderStatus",
+            dictCode = "DeliveryOrderStatus")
+    @TableField(exist = false)
+    private Map<String, Object> orderStatusDictMap;
+
+    @RelationGlobalDict(
+            masterIdField = "refundStatus",
+            dictCode = "DeliveryOrderRefundStatus")
+    @TableField(exist = false)
+    private Map<String, Object> refundStatusDictMap;
 }

+ 13 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/service/DeliveryOrderService.java

@@ -2,6 +2,7 @@ package com.tourism.webadmin.back.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.tourism.common.core.base.service.IBaseService;
+import com.tourism.common.core.object.CallResult;
 import com.tourism.webadmin.back.model.DeliveryOrder;
 
 import java.util.*;
@@ -93,4 +94,16 @@ public interface DeliveryOrderService extends IBaseService<DeliveryOrder, Long>
      * @return 查询结果集。
      */
     List<DeliveryOrder> getDeliveryOrderListWithRelation(DeliveryOrder filter, String orderBy);
+
+
+    /**
+     * 对批量导入数据列表进行数据合法性验证。
+     * 验证逻辑主要覆盖主表的常量字典字段、字典表字典字段、数据源字段和一对一关联数据是否存在。
+     *
+     * @param dataList 主表的数据列表。
+     * @param ignoreFieldSet 需要忽略校验的字典字段集合。通常对于字典反向翻译过来的字段适用,
+     *                       避免了二次验证,以提升效率。
+     * @return 验证结果。如果失败,包含具体的错误信息和导致错误的数据对象。
+     */
+    CallResult verifyImportList(List<DeliveryOrder> dataList, Set<String> ignoreFieldSet);
 }

+ 50 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/DeliveryOrderServiceImpl.java

@@ -9,6 +9,7 @@ import com.tourism.common.core.annotation.MyDataSource;
 import com.tourism.common.core.base.dao.BaseDaoMapper;
 import com.tourism.common.core.base.service.BaseService;
 import com.tourism.common.core.constant.GlobalDeletedFlag;
+import com.tourism.common.core.object.CallResult;
 import com.tourism.common.core.object.MyRelationParam;
 import com.tourism.common.core.util.MyModelUtil;
 import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
@@ -22,8 +23,10 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import com.tourism.common.dict.service.GlobalDictService;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * 外卖订单管理数据操作服务类。
@@ -42,6 +45,8 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrder, Long> i
     private DeliveryOrderMapper deliveryOrderMapper;
     @Autowired
     private DeliveryOrderItemsService deliveryOrderItemsService;
+    @Autowired
+    private GlobalDictService globalDictService;
 
     /**
      * 返回当前Service的主表Mapper对象。
@@ -172,4 +177,49 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrder, Long> i
         MyModelUtil.setDefaultValue(deliveryOrder, "shopName", "");
         return deliveryOrder;
     }
+
+    @Override
+    public CallResult verifyImportList(List<DeliveryOrder> dataList, Set<String> ignoreFieldSet) {
+        CallResult callResult;
+        if (!CollUtil.contains(ignoreFieldSet, "payType")) {
+            callResult = verifyImportForGlobalDict(dataList, "payTypeDictMap", DeliveryOrder::getPayType);
+            if (!callResult.isSuccess()) {
+                return callResult;
+            }
+        }
+        if (!CollUtil.contains(ignoreFieldSet, "orderStatus")) {
+            callResult = verifyImportForGlobalDict(dataList, "orderStatusDictMap", DeliveryOrder::getOrderStatus);
+            if (!callResult.isSuccess()) {
+                return callResult;
+            }
+        }
+        if (!CollUtil.contains(ignoreFieldSet, "refundStatus")) {
+            callResult = verifyImportForGlobalDict(dataList, "refundStatusDictMap", DeliveryOrder::getRefundStatus);
+            if (!callResult.isSuccess()) {
+                return callResult;
+            }
+        }
+        return CallResult.ok();
+    }
+
+    @Override
+    public CallResult verifyRelatedData(DeliveryOrder deliveryOrder, DeliveryOrder originalDeliveryOrder) {
+        String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
+        //这里是基于字典的验证。
+        if (this.needToVerify(deliveryOrder, originalDeliveryOrder, DeliveryOrder::getPayType)
+                && !globalDictService.existDictItemFromCache("DeliveryPayType", deliveryOrder.getPayType())) {
+            return CallResult.error(String.format(errorMessageFormat, "支付方式"));
+        }
+        //这里是基于字典的验证。
+        if (this.needToVerify(deliveryOrder, originalDeliveryOrder, DeliveryOrder::getOrderStatus)
+                && !globalDictService.existDictItemFromCache("DeliveryOrderStatus", deliveryOrder.getOrderStatus())) {
+            return CallResult.error(String.format(errorMessageFormat, "订单状态"));
+        }
+        //这里是基于字典的验证。
+        if (this.needToVerify(deliveryOrder, originalDeliveryOrder, DeliveryOrder::getRefundStatus)
+                && !globalDictService.existDictItemFromCache("DeliveryOrderRefundStatus", deliveryOrder.getRefundStatus())) {
+            return CallResult.error(String.format(errorMessageFormat, "退款状态"));
+        }
+        return CallResult.ok();
+    }
 }

+ 19 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/vo/DeliveryOrderVo.java

@@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 外卖订单管理VO视图对象。
@@ -126,4 +127,22 @@ public class DeliveryOrderVo extends BaseVo {
      * 订单明细。
      */
     private List<DeliveryOrderItemsVo> itemList;
+
+    /**
+     * payType 全局字典关联数据。
+     */
+    @Schema(description = "payType 全局字典关联数据")
+    private Map<String, Object> payTypeDictMap;
+
+    /**
+     * orderStatus 全局字典关联数据。
+     */
+    @Schema(description = "orderStatus 全局字典关联数据")
+    private Map<String, Object> orderStatusDictMap;
+
+    /**
+     * refundStatus 全局字典关联数据。
+     */
+    @Schema(description = "refundStatus 全局字典关联数据")
+    private Map<String, Object> refundStatusDictMap;
 }