|
|
@@ -1,9 +1,12 @@
|
|
|
package org.dromara.product.controller.pc;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.common.excel.utils.ExcelUtil;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
@@ -15,10 +18,13 @@ import org.dromara.product.domain.bo.*;
|
|
|
import org.dromara.product.domain.vo.PcProductVo;
|
|
|
import org.dromara.product.domain.vo.ProcurementProgramVo;
|
|
|
import org.dromara.product.domain.vo.ProductFavoritesVo;
|
|
|
+import org.dromara.product.domain.vo.ProductShoppingCartExportVo;
|
|
|
import org.dromara.product.service.*;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -100,6 +106,7 @@ public class MyProductController {
|
|
|
*/
|
|
|
@GetMapping("/getProductFavoritesPage")
|
|
|
public TableDataInfo<ProductFavoritesVo> getProductFavoritesPage(ProductFavoritesBo bo, PageQuery pageQuery) {
|
|
|
+ bo.setUserId(LoginHelper.getUserId());
|
|
|
return productFavoritesService.queryPageList(bo, pageQuery);
|
|
|
}
|
|
|
/**
|
|
|
@@ -268,4 +275,46 @@ public class MyProductController {
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出购物车的商品
|
|
|
+ * */
|
|
|
+ @PostMapping("/exportProductShoppingCart")
|
|
|
+ public void exportProductShoppingCart( HttpServletResponse response) {
|
|
|
+ PageQuery pageQuery = new PageQuery();
|
|
|
+ pageQuery.setPageNum(1);
|
|
|
+ pageQuery.setPageSize(Integer.MAX_VALUE);
|
|
|
+ TableDataInfo<PcProductVo> tableDataInfo = productBaseService.getProductShoppingCartPage(null, LoginHelper.getUserId(),pageQuery);
|
|
|
+ // 转换为导出对象
|
|
|
+ List<ProductShoppingCartExportVo> exportList = new ArrayList<>();
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(tableDataInfo.getRows())) {
|
|
|
+ int index = 1;
|
|
|
+ for (PcProductVo vo : tableDataInfo.getRows()) {
|
|
|
+ ProductShoppingCartExportVo exportVo = new ProductShoppingCartExportVo();
|
|
|
+ exportVo.setSerialNumber(index++);
|
|
|
+ exportVo.setProductNo(vo.getProductNo());
|
|
|
+ exportVo.setItemName(vo.getItemName());
|
|
|
+ exportVo.setUnitName(vo.getUnitName());
|
|
|
+ exportVo.setProductNum(vo.getProductNum());
|
|
|
+
|
|
|
+ BigDecimal price = vo.getMemberPrice() != null ? vo.getMemberPrice() : BigDecimal.ZERO;
|
|
|
+ exportVo.setPrice(price);
|
|
|
+
|
|
|
+ BigDecimal subtotal = price.multiply(BigDecimal.valueOf(vo.getProductNum() != null ? vo.getProductNum() : 0L));
|
|
|
+ exportVo.setSubtotal(subtotal);
|
|
|
+
|
|
|
+ totalAmount = totalAmount.add(subtotal);
|
|
|
+ exportList.add(exportVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置合计值
|
|
|
+ for (ProductShoppingCartExportVo vo : exportList) {
|
|
|
+ vo.setTotal(totalAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ ExcelUtil.exportExcel(exportList, "购物车商品", ProductShoppingCartExportVo.class, response);
|
|
|
+ }
|
|
|
+
|
|
|
}
|