Przeglądaj źródła

订单列表导出

zouxuan 2 lat temu
rodzic
commit
31ca5ae003

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SellOrderDao.java

@@ -230,4 +230,15 @@ public interface SellOrderDao extends BaseDAO<Integer, SellOrder> {
     List<Map<Long, String>> sumOutOrderAmount(@Param("outOrderList") List<Long> outOrderList);
 
     List<SellOrder> querySellOrderByOrderIds(@Param("orderIds") Set<Long> paymentOrderIds);
+
+    /**
+    * @description: 获取商城商品分类
+     * @param productIdList
+    * @return java.util.Map<java.lang.Integer,java.lang.String>
+    * @author zx
+    * @date 2022/11/7 11:15
+    */
+    List<Map<Long, String>> getMallProductMap(@Param("productIdList") Set<String> productIdList, @Param("database") String database);
+
+    List<String> getMallProductCategory(@Param("database") String database);
 }

+ 122 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/StudentPaymentOrderMallExportDto.java

@@ -3,6 +3,7 @@ package com.ym.mec.biz.dal.dto;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.math.BigDecimal;
+import java.util.Map;
 
 public class StudentPaymentOrderMallExportDto extends StudentPaymentOrderRouteDto {
     @ApiModelProperty(value = "分部",required = true)
@@ -23,6 +24,127 @@ public class StudentPaymentOrderMallExportDto extends StudentPaymentOrderRouteDt
     @ApiModelProperty(value = "购买商品列表",required = true)
     private String goodsJson;
 
+    @ApiModelProperty(value = "购买的商品汇总金额",required = true)
+    private Map<String, BigDecimal> categoryAmount;
+
+    @ApiModelProperty(value = "商品分类1",required = true)
+    private BigDecimal category1 = BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品分类2",required = true)
+    private BigDecimal category2 = BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品分类3",required = true)
+    private BigDecimal category3 = BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品分类4",required = true)
+    private BigDecimal category4 = BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品分类5",required = true)
+    private BigDecimal category5 = BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品分类6",required = true)
+    private BigDecimal category6 = BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品分类7",required = true)
+    private BigDecimal category7 = BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品分类8",required = true)
+    private BigDecimal category8 = BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品分类9",required = true)
+    private BigDecimal category9 = BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品分类10",required = true)
+    private BigDecimal category10 = BigDecimal.ZERO;
+
+    public Map<String, BigDecimal> getCategoryAmount() {
+        return categoryAmount;
+    }
+
+    public void setCategoryAmount(Map<String, BigDecimal> categoryAmount) {
+        this.categoryAmount = categoryAmount;
+    }
+
+    public BigDecimal getCategory1() {
+        return category1;
+    }
+
+    public void setCategory1(BigDecimal category1) {
+        this.category1 = category1;
+    }
+
+    public BigDecimal getCategory2() {
+        return category2;
+    }
+
+    public void setCategory2(BigDecimal category2) {
+        this.category2 = category2;
+    }
+
+    public BigDecimal getCategory3() {
+        return category3;
+    }
+
+    public void setCategory3(BigDecimal category3) {
+        this.category3 = category3;
+    }
+
+    public BigDecimal getCategory4() {
+        return category4;
+    }
+
+    public void setCategory4(BigDecimal category4) {
+        this.category4 = category4;
+    }
+
+    public BigDecimal getCategory5() {
+        return category5;
+    }
+
+    public void setCategory5(BigDecimal category5) {
+        this.category5 = category5;
+    }
+
+    public BigDecimal getCategory6() {
+        return category6;
+    }
+
+    public void setCategory6(BigDecimal category6) {
+        this.category6 = category6;
+    }
+
+    public BigDecimal getCategory7() {
+        return category7;
+    }
+
+    public void setCategory7(BigDecimal category7) {
+        this.category7 = category7;
+    }
+
+    public BigDecimal getCategory8() {
+        return category8;
+    }
+
+    public void setCategory8(BigDecimal category8) {
+        this.category8 = category8;
+    }
+
+    public BigDecimal getCategory9() {
+        return category9;
+    }
+
+    public void setCategory9(BigDecimal category9) {
+        this.category9 = category9;
+    }
+
+    public BigDecimal getCategory10() {
+        return category10;
+    }
+
+    public void setCategory10(BigDecimal category10) {
+        this.category10 = category10;
+    }
+
     public String getOrganName() {
         return organName;
     }

+ 37 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ExportServiceImpl.java

@@ -38,6 +38,7 @@ import org.springframework.util.CollectionUtils;
 import javax.annotation.PostConstruct;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
+import java.lang.reflect.Method;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
@@ -1685,14 +1686,23 @@ public class ExportServiceImpl implements ExportService {
         return BigDecimal.ZERO;
     }
 
-
     @Override
-    public void mallOrderList(Map<String, Object> params, ManagerDownload managerDownload) {
+    public void mallOrderList(Map<String, Object> params, ManagerDownload managerDownload){
         List<StudentPaymentOrderMallExportDto> studentPaymentOrderExportDtos = studentPaymentOrderDao.exportMallQueryPage(params);
         long i = 1;
         //获取机构费率
         Integer tenantId = (Integer) params.get("tenantId");
         TenantConfig tenantConfig = tenantConfigService.queryByTenantId(tenantId);
+        //获取商城订单商品信息
+        List<String> goodsJsonList = studentPaymentOrderExportDtos.stream().map(e -> e.getGoodsJson()).collect(Collectors.toList());
+        goodsJsonList.removeAll(Collections.singleton(null));
+        Set<String> productIdList = new HashSet<>();
+        for (String goodsJson : goodsJsonList) {
+            List<JSONObject> orderItemList = JSONObject.parseArray(JSONObject.parseObject(goodsJson).getString("orderItemList"), JSONObject.class);
+            productIdList.addAll(orderItemList.stream().map(e -> e.get("productId").toString()).collect(Collectors.toSet()));
+        }
+        List<String> categoryNames = sellOrderDao.getMallProductCategory("mall_dev");
+        Map<Long,String> productCategoryMap = MapUtil.convertMybatisMap(sellOrderDao.getMallProductMap(productIdList,"mall_dev"));
         for (StudentPaymentOrderMallExportDto row : studentPaymentOrderExportDtos) {
             if (row.getActualAmount() == null) {
                 row.setActualAmount(BigDecimal.ZERO);
@@ -1708,8 +1718,23 @@ public class ExportServiceImpl implements ExportService {
             row.setPlatformFee(row.getActualAmount().multiply(tenantConfig.getChargeRate()).divide(new BigDecimal(1000), 2, BigDecimal.ROUND_HALF_UP));
             if(StringUtils.isNotEmpty(row.getGoodsJson())){
                 List<JSONObject> orderItemList = JSONObject.parseArray(JSONObject.parseObject(row.getGoodsJson()).getString("orderItemList"), JSONObject.class);
-                String productName = orderItemList.stream().map(e -> e.get("productName").toString()).collect(Collectors.joining(","));
-                row.setGoodsNames(productName);
+                for (JSONObject json : orderItemList) {
+                    try {
+                        String category = productCategoryMap.get(Long.parseLong(json.get("productId").toString()));
+                        BigDecimal realAmount = new BigDecimal(json.get("realAmount").toString());
+                        int index = categoryNames.indexOf(category) + 1;
+                        if(index == 0){
+                            continue;
+                        }
+                        Method method = row.getClass().getMethod("getCategory" + index, null);
+                        BigDecimal invoke = (BigDecimal)method.invoke(row);
+                        invoke = invoke.add(realAmount);
+                        Method method1 = row.getClass().getMethod("setCategory" + index, BigDecimal.class);
+                        method1.invoke(row,invoke);
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
             }
             //活动购买的商品列表
             String paymentChannel = "";
@@ -1726,7 +1751,14 @@ public class ExportServiceImpl implements ExportService {
             row.setOrderAmount(row.getExpectAmount().add(row.getCouponRemitFee()));
             i++;
         }
-        HSSFWorkbook workbook = getHSSFWorkbook(studentPaymentOrderExportDtos, ExportEnum.MALL_ORDER_LIST);
+        Map<String, String> headMap = getExportMap(new ExportDto(ExportEnum.MALL_ORDER_LIST));
+        for (int j = 0; j < categoryNames.size(); j++) {
+            int num = j + 1;
+            headMap.put(categoryNames.get(j),"category"+ num);
+        }
+        String[] header = headMap.keySet().toArray(new String[headMap.keySet().size()]);
+        String[] body = headMap.values().toArray(new String[headMap.keySet().size()]);
+        HSSFWorkbook workbook = POIUtil.exportExcel(header, body, studentPaymentOrderExportDtos);
         exportManagerDownload(workbook, managerDownload);
     }
     @Override

+ 12 - 0
mec-biz/src/main/resources/config/mybatis/SellOrderMapper.xml

@@ -657,5 +657,17 @@
             #{orderId}
         </foreach>
     </select>
+    <select id="getMallProductMap" resultType="java.util.Map">
+        select pp.id 'key',ppc.name 'value' from mall_dev.pms_product_category ppc
+        left join mall_dev.pms_product_category ppcc ON ppcc.parent_id = ppc.id
+        left join mall_dev.pms_product pp ON pp.product_category_id = ppcc.id
+        where pp.id IN
+        <foreach collection="productIdList" item="id" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+    </select>
+    <select id="getMallProductCategory" resultType="java.lang.String">
+        select name from mall_dev.pms_product_category where parent_id = 0
+    </select>
 
 </mapper>