Переглянути джерело

fix: 完善航次价格和价格模板

luofeiyun 1 місяць тому
батько
коміт
2a68f92175

+ 1 - 1
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/controller/admin/pricetemplate/vo/PriceAreaRespVO.java

@@ -27,7 +27,7 @@ public class PriceAreaRespVO {
 
     @Schema(description = "父级区域ID", example = "25276")
     @ExcelProperty("父级区域ID")
-    private Long parentAreaID;
+    private Long parentAreaId;
 
     @Schema(description = "父级区域名称", example = "张三")
     private String parentAreaName;

+ 13 - 3
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/controller/admin/pricevoyage/PriceVoyageController.java

@@ -5,6 +5,7 @@ import com.yc.ship.framework.common.pojo.CommonResult;
 import com.yc.ship.framework.common.pojo.PageParam;
 import com.yc.ship.framework.common.pojo.PageResult;
 import com.yc.ship.framework.common.util.collection.CollectionUtils;
+import com.yc.ship.framework.common.util.collection.MapUtils;
 import com.yc.ship.framework.common.util.object.BeanUtils;
 import com.yc.ship.framework.excel.core.util.ExcelUtils;
 import com.yc.ship.module.product.controller.admin.pricetemplate.vo.PriceAreaRespVO;
@@ -163,9 +164,18 @@ public class PriceVoyageController {
         Map<Long, RouteRespDTO> routeMap = routeApi.queryRoute(routeIds);
 
         list.stream().forEach(item -> {
-            item.setShipName(shipMap.get(item.getShipId()).getName());
-            item.setVoyageName(voyageMap.get(item.getVoyageId()).getName());
-            item.setRouteName(routeMap.get(item.getRouteId()).getName());
+            ShipRespDTO shipRespDTO = shipMap.get(item.getShipId());
+            if(shipRespDTO != null) {
+                item.setShipName(shipRespDTO.getName());
+            }
+            VoyageDO voyageDO = voyageMap.get(item.getVoyageId());
+            if(voyageDO != null) {
+                item.setVoyageName(voyageDO.getName());
+            }
+            RouteRespDTO routeRespDTO = routeMap.get(item.getRouteId());
+            if(routeRespDTO != null) {
+                item.setRouteName(routeRespDTO.getName());
+            }
         });
         return success(page);
     }

+ 11 - 3
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/dal/mysql/pricearea/PriceAreaMapper.java

@@ -7,6 +7,7 @@ import com.yc.ship.module.product.dal.dataobject.pricearea.PriceAreaDO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -26,7 +27,14 @@ public interface PriceAreaMapper extends BaseMapperX<PriceAreaDO> {
         return selectList(new LambdaQueryWrapperX<PriceAreaDO>().eq(PriceAreaDO::getObjectId, id));
     }
 
-    @Select("select t1.price, t2.country_id from product_price_area t1 LEFT JOIN system_area_country t2 on t1.area_id = t2.area_id\n" +
-            "where t1.object_id = #{id} and t1.deleted = 0 and t2.deleted = 0")
-    List<PriceCountryRespVO> selectCountryPriceByObjectId(Long id);
+    default List<PriceCountryRespVO> selectCountryPriceByObjectId(Long id) {
+        List<PriceCountryRespVO> list = new ArrayList<>();
+        List<PriceAreaDO> priceAreaDOS = selectList(new LambdaQueryWrapperX<PriceAreaDO>().eq(PriceAreaDO::getObjectId, id).isNotNull(PriceAreaDO::getParentAreaId));
+        priceAreaDOS.stream().forEach(priceAreaDO -> {
+            PriceCountryRespVO priceCountryRespVO = new PriceCountryRespVO();
+            priceCountryRespVO.setPrice(priceAreaDO.getPrice());
+            priceCountryRespVO.setCountryId(priceAreaDO.getAreaId().intValue());
+        });
+        return list;
+    }
 }

+ 7 - 4
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/service/pricetemplate/PriceTemplateServiceImpl.java

@@ -1,6 +1,7 @@
 package com.yc.ship.module.product.service.pricetemplate;
 
 import com.yc.ship.framework.common.pojo.PageResult;
+import com.yc.ship.framework.common.util.collection.CollectionUtils;
 import com.yc.ship.framework.common.util.object.BeanUtils;
 import com.yc.ship.module.product.controller.admin.pricetemplate.vo.PriceTemplatePageReqVO;
 import com.yc.ship.module.product.controller.admin.pricetemplate.vo.PriceTemplateReqVO;
@@ -150,10 +151,12 @@ public class PriceTemplateServiceImpl implements PriceTemplateService {
 
         // 插入附加产品
         List<PriceSpuDO> spuList = vo.getSpuList();
-        spuList.stream().forEach(spu -> {
-            spu.setObjectId(objectId);
-        });
-        priceSpuMapper.insertBatch(spuList);
+        if(!CollectionUtils.isAnyEmpty(spuList)) {
+            spuList.stream().forEach(spu -> {
+                spu.setObjectId(objectId);
+            });
+            priceSpuMapper.insertBatch(spuList);
+        }
 
     }
 

+ 13 - 1
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/service/pricevoyage/PriceVoyageServiceImpl.java

@@ -19,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 
 import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -128,10 +129,21 @@ public class PriceVoyageServiceImpl implements PriceVoyageService {
 
         //插入区域加价
         List<PriceAreaDO> areaList = vo.getAreaList();
+        List<PriceAreaDO> insertAreaList = new ArrayList<>();
         areaList.stream().forEach(area -> {
             area.setObjectId(objectId);
+            insertAreaList.add(area);
+            List<PriceAreaDO> children = area.getChildren();
+            if (children != null) {
+                children.stream().forEach(child -> {
+                    child.setObjectId(objectId);
+                    child.setParentAreaId(area.getAreaId());
+                    child.setParentAreaName(area.getAreaName());
+                    insertAreaList.add(child);
+                });
+            }
         });
-        priceAreaMapper.insertBatch(areaList);
+        priceAreaMapper.insertBatch(insertAreaList);
     }
 
     private void deleteRelation(Long objectId) {