Parcourir la source

求购导出接口

yzc il y a 2 ans
Parent
commit
1cca242409

+ 24 - 0
sckw-modules/sckw-order/src/main/java/com/sckw/order/controller/KwpWantBuyController.java

@@ -1,14 +1,21 @@
 package com.sckw.order.controller;
 
 import com.sckw.core.annotation.Log;
+import com.sckw.core.exception.BusinessException;
+import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.excel.utils.ExcelUtil;
+import com.sckw.order.model.dto.WantBuyExport;
 import com.sckw.order.model.vo.req.*;
 import com.sckw.order.serivce.KwpWantBuyService;
+import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
 import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 /**
  * @desc: 求购controller
  * @author: yzc
@@ -142,4 +149,21 @@ public class KwpWantBuyController {
     public HttpResult statistic(@RequestBody WantBuySelectParam params) {
         return HttpResult.ok(kwpWantBuyService.statistic(params));
     }
+
+    /**
+     * @desc: 求购导出
+     * @author: yzc
+     * @date: 2023-08-16 16:09
+     * @Param param:
+     * @Param response:
+     * @return: void
+     */
+    @PostMapping(value = "/export", produces = MediaType.APPLICATION_JSON_VALUE)
+    public void export(@RequestBody WantBuySelectParam param, HttpServletResponse response) {
+        List<WantBuyExport> list = kwpWantBuyService.export(param);
+        if (CollectionUtils.isEmpty(list)) {
+            throw new BusinessException("导出数据为空!");
+        }
+        ExcelUtil.downData(response, WantBuyExport.class, list);
+    }
 }

+ 15 - 12
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/dto/TransportDemandExport.java

@@ -20,40 +20,43 @@ public class TransportDemandExport implements Serializable {
     @Serial
     private static final long serialVersionUID = -7951209824419422786L;
 
-    @ExcelProperty(value = "状态", index = 0)
+    @ExcelProperty(value = "序号" )
+    private String serialNumber;
+
+    @ExcelProperty(value = "状态")
     private String statusLabel;
 
-    @ExcelProperty(value = "商品名称", index = 1)
+    @ExcelProperty(value = "商品名称")
     private String name;
 
-    @ExcelProperty(value = "分类", index = 2)
+    @ExcelProperty(value = "分类")
     private String goodsTypeLabel;
 
-    @ExcelProperty(value = "运需单价", index = 3)
+    @ExcelProperty(value = "运需单价")
     private String price;
 
-    @ExcelProperty(value = "总计划量", index = 4)
+    @ExcelProperty(value = "总计划量")
     private String amount;
 
-    @ExcelProperty(value = "商品规格", index = 5)
+    @ExcelProperty(value = "商品规格")
     private String spec;
 
-    @ExcelProperty(value = "装货地址", index = 6)
+    @ExcelProperty(value = "装货地址")
     private String loadAddress;
 
-    @ExcelProperty(value = "卸货地址", index = 7)
+    @ExcelProperty(value = "卸货地址")
     private String unloadAddress;
 
-    @ExcelProperty(value = "截止时间", index = 8)
+    @ExcelProperty(value = "截止时间")
     private String deadline;
 
-    @ExcelProperty(value = "创建时间", index = 9)
+    @ExcelProperty(value = "创建时间")
     private String createTime;
 
-    @ExcelProperty(value = "更新时间", index = 10)
+    @ExcelProperty(value = "更新时间")
     private String updateTime;
 
-    @ExcelProperty(value = "备注", index = 11)
+    @ExcelProperty(value = "备注")
     private String remark;
 
 }

+ 56 - 0
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/dto/WantBuyExport.java

@@ -0,0 +1,56 @@
+package com.sckw.order.model.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.sckw.excel.annotation.ExcelContext;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * @desc: 求购列表导出
+ * @author: yzc
+ * @date: 2023-08-16 15:36
+ */
+@Data
+@Accessors(chain = true)
+@ExcelContext(fileName = "求购列表信息", sheetName = "求购列表信息")
+public class WantBuyExport implements Serializable {
+    @Serial
+    private static final long serialVersionUID = 7225805024416842861L;
+
+
+    @ExcelProperty(value = "序号" )
+    private String serialNumber;
+
+    @ExcelProperty(value = "状态")
+    private String statusLabel;
+
+    @ExcelProperty(value = "商品名称")
+    private String name;
+
+    @ExcelProperty(value = "分类")
+    private String goodsTypeLabel;
+
+    @ExcelProperty(value = "规格尺寸")
+    private String spec;
+
+    @ExcelProperty(value = "支付方式")
+    private String tradings;
+
+    @ExcelProperty(value = "求购单价")
+    private String price;
+
+    @ExcelProperty(value = "求购总量")
+    private String amount;
+
+    @ExcelProperty(value = "创建时间")
+    private String createTime;
+
+    @ExcelProperty(value = "更新时间")
+    private String updateTime;
+
+    @ExcelProperty(value = "备注")
+    private String remark;
+}

+ 7 - 0
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/vo/req/WantBuySelectParam.java

@@ -73,4 +73,11 @@ public class WantBuySelectParam extends PageRequest {
     private Long entId;
     private List<Long> entIds;
 
+    /**
+     * 指定求购id集合导出
+     */
+    private String ids;
+
+    private List<Long> wantBuyIds;
+
 }

+ 3 - 1
sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwoTransportDemandService.java

@@ -34,6 +34,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 /**
@@ -286,11 +287,12 @@ public class KwoTransportDemandService {
             return Collections.emptyList();
         }
         List<TransportDemandExport> result = Lists.newArrayList();
+        AtomicInteger i = new AtomicInteger(1);
         demands.forEach(e -> {
             TransportDemandExport export = BeanUtils.copyProperties(e, TransportDemandExport.class);
             export.setGoodsTypeLabel(DictEnum.getLabel(DictTypeEnum.PRODUCT_NAME_TYPE.getType(), e.getGoodsType()))
                     .setStatusLabel(DictEnum.getLabel(DictTypeEnum.TRANSPORT_DEMAND_STATUS.getType(), String.valueOf(e.getStatus())))
-                    .setLoadAddress(e.getLoadAreaName() + e.getLoadDetailAddress())
+                    .setLoadAddress(e.getLoadAreaName() + e.getLoadDetailAddress()).setSerialNumber(String.valueOf(i.getAndIncrement()))
                     .setUnloadAddress(e.getUnloadAreaName() + e.getUnloadDetailAddress())
                     .setDeadline(Objects.isNull(e.getDeadline()) ? null : DateUtil.dateToStr(e.getDeadline()))
                     .setCreateTime(Objects.isNull(e.getCreateTime()) ? null : DateUtil.getDateTime(e.getCreateTime()))

+ 45 - 3
sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwpWantBuyService.java

@@ -16,12 +16,14 @@ import com.sckw.core.utils.BeanUtils;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.context.LoginUserHolder;
+import com.sckw.excel.utils.DateUtil;
 import com.sckw.order.dao.KwpWantBuyAddressMapper;
 import com.sckw.order.dao.KwpWantBuyMapper;
 import com.sckw.order.dao.KwpWantBuyTradingMapper;
 import com.sckw.order.model.KwoWantBuy;
 import com.sckw.order.model.KwoWantBuyAddress;
 import com.sckw.order.model.KwoWantBuyTrading;
+import com.sckw.order.model.dto.WantBuyExport;
 import com.sckw.order.model.vo.req.*;
 import com.sckw.order.model.vo.res.WantBuyAddressDetailRes;
 import com.sckw.order.model.vo.res.WantBuyDetailRes;
@@ -36,6 +38,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 /**
@@ -446,9 +449,7 @@ public class KwpWantBuyService {
             List<String> longList = stringToLongList(params.getTrading());
             params.setTradings(longList);
         }
-        if (StringUtils.isNotBlank(params.getStatus())) {
-            params.setStatus(params.getStatus());
-        }
+        params.setStatus(null);
         //商品分类筛选处理
         if (StringUtils.isNotBlank(params.getGoodsType()) && StringUtils.isNotBlank(params.getGoodsTypeValue())) {
             List<String> goodsTypes = goodsTypeHandle(params);
@@ -475,4 +476,45 @@ public class KwpWantBuyService {
         res.setTableTops(tableTops).setTableBottom(tableBottom);
         return res;
     }
+
+    public List<WantBuyExport> export(WantBuySelectParam param) {
+        WantBuySelectParam selectParam = new WantBuySelectParam();
+        if (StringUtils.isNotBlank(param.getIds())) {
+            List<Long> ids = StringUtils.splitStrToList(param.getIds(), Long.class);
+            selectParam.setWantBuyIds(ids);
+        } else {
+            BeanUtils.copyProperties(param, selectParam);
+            if (StringUtils.isNotBlank(selectParam.getTrading())) {
+                List<String> longList = stringToLongList(selectParam.getTrading());
+                selectParam.setTradings(longList);
+            }
+            if (StringUtils.isNotBlank(selectParam.getStatus())) {
+                selectParam.setStatus(selectParam.getStatus());
+            }
+            //商品分类筛选处理
+            if (StringUtils.isNotBlank(selectParam.getGoodsType()) && StringUtils.isNotBlank(selectParam.getGoodsTypeValue())) {
+                List<String> goodsTypes = goodsTypeHandle(selectParam);
+                selectParam.setGoodsTypeValueSearch(goodsTypes);
+            }
+        }
+        selectParam.setEntId(LoginUserHolder.getEntId());
+        List<WantBuySelectRes> wantBuyDto = kwpWantBuyMapper.pageSelect(selectParam);
+        if (CollectionUtils.isEmpty(wantBuyDto)) {
+            return Collections.emptyList();
+        }
+        List<WantBuyExport> result = new ArrayList<>();
+        AtomicInteger i = new AtomicInteger(1);
+        wantBuyDto.forEach(e -> {
+            WantBuyExport export = BeanUtils.copyProperties(e, WantBuyExport.class);
+            List<String> tradings = e.getWantBuyTradings().stream()
+                    .map(wantBuyTradingRes -> DictEnum.getLabel(DictTypeEnum.TRADE_TYPE.getType(), wantBuyTradingRes.getTrading()))
+                    .collect(Collectors.toList());
+            export.setSerialNumber(String.valueOf(i.getAndIncrement())).setTradings(String.join(Global.COMMA, tradings))
+                    .setGoodsTypeLabel(DictEnum.getLabel(DictTypeEnum.PRODUCT_NAME_TYPE.getType(), e.getGoodsType()))
+                    .setCreateTime(Objects.isNull(e.getCreateTime()) ? null : DateUtil.getDateTime(e.getCreateTime()))
+                    .setUpdateTime(Objects.isNull(e.getUpdateTime()) ? null : DateUtil.getDateTime(e.getUpdateTime()));
+            result.add(export);
+        });
+        return result;
+    }
 }

+ 6 - 0
sckw-modules/sckw-order/src/main/resources/mapper/KwoWantBuyMapper.xml

@@ -55,6 +55,12 @@
                 #{item,jdbcType=VARCHAR}
             </foreach>
         </if>
+        <if test="wantBuyReq.wantBuyIds != null and wantBuyReq.wantBuyIds.size() > 0">
+            and kb.id in
+            <foreach collection="wantBuyReq.wantBuyIds" item="item" open="(" close=")" separator=",">
+                #{item,jdbcType=BIGINT}
+            </foreach>
+        </if>
         <if test="wantBuyReq.status != null and wantBuyReq.status != ''">
             and kb.status = #{wantBuyReq.status}
         </if>