1
0
DingXiaoYu 2 лет назад
Родитель
Сommit
39e6fca6fb

+ 4 - 1
src/main/java/com/seecoder/BlueWhale/configure/AlipayTools.java

@@ -36,13 +36,16 @@ public class AlipayTools {
      * @Author: DingXiaoyu
      * @Date: 11:25 2024/1/31
      * 使用支付宝沙箱
+     * 使用时可以根据自己的需要做修改,包括参数名、返回值、具体实现
+     * 在bizContent中放入关键的信息:tradeName、price、name
+     * 返回的form是一个String类型的html页面
     */
     public String pay(String tradeName, String name , Double price){
         AlipayClient alipayClient = new DefaultAlipayClient(serverUrl,appId,appPrivateKey,format,charset,alipayPublicKey,signType);
         AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
         request.setNotifyUrl(notifyUrl);
         JSONObject bizContent = new JSONObject();
-        bizContent.put("out_trade_no", tradeName); //订单id-优惠券id
+        bizContent.put("out_trade_no", tradeName);
         bizContent.put("total_amount", price);
         bizContent.put("subject", name);
         bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");

+ 1 - 22
src/main/java/com/seecoder/BlueWhale/controller/AliPayController.java

@@ -1,11 +1,5 @@
 package com.seecoder.BlueWhale.controller;
 
-import com.seecoder.BlueWhale.enums.OrderStatusEnum;
-import com.seecoder.BlueWhale.po.Coupon;
-import com.seecoder.BlueWhale.po.Order;
-import com.seecoder.BlueWhale.repository.CouponRepository;
-import com.seecoder.BlueWhale.repository.OrderRepository;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -18,12 +12,6 @@ import java.util.Map;
 @RequestMapping("/api/ali")
 public class AliPayController {
 
-    @Autowired
-    OrderRepository orderRepository;
-
-    @Autowired
-    CouponRepository couponRepository;
-
     @PostMapping("/notify")
     public void notify(HttpServletRequest httpServletRequest){
         if (httpServletRequest.getParameter("trade_status").equals("TRADE_SUCCESS")) {
@@ -34,17 +22,8 @@ public class AliPayController {
                 params.put(name, httpServletRequest.getParameter(name));
             }
             String tradeName = params.get("out_trade_no");
-            String[] args=tradeName.split("-");
             Double paid = Double.parseDouble(params.get("total_amount"));
-            Order order = orderRepository.findById(Integer.parseInt(args[0])).get();
-            order.setPaid(paid);
-            order.setStatus(OrderStatusEnum.UNSEND);
-            orderRepository.save(order);
-            if (!args[1].equals("$")){
-                Coupon coupon=couponRepository.findById(Integer.parseInt(args[1])).get();
-                coupon.setUsed(true);
-                couponRepository.save(coupon);
-            }
+            //todo: 在这里完成回调接口
         }
     }
 

+ 1 - 1
src/main/java/com/seecoder/BlueWhale/controller/OrderController.java

@@ -32,7 +32,7 @@ public class OrderController {
     }
 
     @PostMapping("/pay")
-    public ResultVO<String> pay(@RequestParam("orderId") Integer orderId,@RequestParam("couponId")Integer couponId){
+    public ResultVO<Boolean> pay(@RequestParam("orderId") Integer orderId,@RequestParam("couponId")Integer couponId){
         return ResultVO.buildSuccess(orderService.pay(orderId,couponId));
     }
 

+ 0 - 5
src/main/java/com/seecoder/BlueWhale/controller/ProductController.java

@@ -36,11 +36,6 @@ public class ProductController {
         return ResultVO.buildSuccess(productService.getProduct(id));
     }
 
-    @GetMapping("/condition")
-    public ResultVO<List<ProductVO>> getProductsWithCondition(@RequestBody ProductVO productVO){
-        return ResultVO.buildSuccess(productService.getProductsWithCondition(productVO.getName(),productVO.getCategory(),productVO.getPrice()));
-    }
-
     @GetMapping("/comment")
     public ResultVO<List<CommentVO>> getComments(@RequestParam("productId")Integer productId){
         return ResultVO.buildSuccess(productService.getComments(productId));

+ 0 - 8
src/main/java/com/seecoder/BlueWhale/controller/ToolsController.java

@@ -1,6 +1,5 @@
 package com.seecoder.BlueWhale.controller;
 
-import com.seecoder.BlueWhale.service.ExcelService;
 import com.seecoder.BlueWhale.service.ImageService;
 import com.seecoder.BlueWhale.vo.ResultVO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,16 +12,9 @@ public class ToolsController {
     @Autowired
     ImageService imageService;
 
-    @Autowired
-    ExcelService excelService;
-
     @PostMapping("/images")
     public ResultVO<String> upload(@RequestParam MultipartFile file){
         return ResultVO.buildSuccess(imageService.upload(file));
     }
 
-    @GetMapping("/excel")
-    public ResultVO<String> export(){
-        return ResultVO.buildSuccess(excelService.export());
-    }
 }

+ 0 - 5
src/main/java/com/seecoder/BlueWhale/service/ExcelService.java

@@ -1,5 +0,0 @@
-package com.seecoder.BlueWhale.service;
-
-public interface ExcelService {
-    public String export();
-}

+ 1 - 1
src/main/java/com/seecoder/BlueWhale/service/OrderService.java

@@ -11,7 +11,7 @@ public interface OrderService {
 
     OrderVO getOrder(Integer id);
 
-    String pay(Integer orderId,Integer couponId);
+    Boolean pay(Integer orderId,Integer couponId);
 
     Boolean deliver(Integer orderId);
 

+ 0 - 2
src/main/java/com/seecoder/BlueWhale/service/ProductService.java

@@ -15,7 +15,5 @@ public interface ProductService {
 
     ProductVO getProduct(Integer id);
 
-    List<ProductVO> getProductsWithCondition(String name, CategoryEnum category, Double price);
-
     List<CommentVO> getComments(Integer productId);
 }

+ 0 - 32
src/main/java/com/seecoder/BlueWhale/serviceImpl/ExcelServiceImpl.java

@@ -1,32 +0,0 @@
-package com.seecoder.BlueWhale.serviceImpl;
-
-import java.io.InputStream;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import com.seecoder.BlueWhale.service.ExcelService;
-import com.seecoder.BlueWhale.service.OrderService;
-import com.seecoder.BlueWhale.util.ExcelUtil;
-import com.seecoder.BlueWhale.util.OssUtil;
-
-@Service
-public class ExcelServiceImpl implements ExcelService{
-
-    @Autowired
-    ExcelUtil excelUtil;
-
-    @Autowired
-    OssUtil ossUtil;
-
-    @Autowired
-    OrderService orderService;
-
-    @Override
-    public String export() {
-        InputStream inputStream = excelUtil.exportExcel(orderService.getAllOrders());
-        String url = ossUtil.upload("order.xlsx", inputStream);
-        return url;
-    }
-    
-}

+ 7 - 7
src/main/java/com/seecoder/BlueWhale/serviceImpl/OrderServiceImpl.java

@@ -78,7 +78,7 @@ public class OrderServiceImpl implements OrderService {
     }
 
     @Override
-    public String pay(Integer orderId,Integer couponId) {
+    public Boolean pay(Integer orderId,Integer couponId) {
         User user=securityUtil.getCurrentUser();
         Order order = orderRepository.findById(orderId).orElse(null);
         if(order == null){
@@ -87,7 +87,9 @@ public class OrderServiceImpl implements OrderService {
         if(order.getStatus() != OrderStatusEnum.UNPAID){
             throw BlueWhaleException.orderStatusError();
         }
-        String tradeName=String.valueOf(order.getId()).concat("-");
+        order.setPaid(calculate(orderId,couponId));
+        order.setStatus(OrderStatusEnum.UNSEND);
+        orderRepository.save(order);
         if (couponId!=0){
             Coupon coupon = couponRepository.findById(couponId).get();
             CouponGroup couponGroup=couponGroupRepository.findById(coupon.getGroupId()).get();
@@ -96,12 +98,10 @@ public class OrderServiceImpl implements OrderService {
             couponGroup.getStoreId()>0 && !couponGroup.getStoreId().equals(product.getStoreId())){
                 throw BlueWhaleException.couponNotAllowed();
             }
-            tradeName=tradeName.concat(String.valueOf(coupon.getId()));
-        }else {
-            tradeName=tradeName.concat("$");
+            coupon.setUsed(true);
+            couponRepository.save(coupon);
         }
-        String name=productRepository.findById(order.getProductId()).get().getName();
-        return alipayTools.pay(tradeName,name,calculate(orderId,couponId));
+        return true;
     }
 
     @Override

+ 0 - 28
src/main/java/com/seecoder/BlueWhale/serviceImpl/ProductServiceImpl.java

@@ -1,6 +1,5 @@
 package com.seecoder.BlueWhale.serviceImpl;
 
-import com.seecoder.BlueWhale.enums.CategoryEnum;
 import com.seecoder.BlueWhale.exception.BlueWhaleException;
 import com.seecoder.BlueWhale.po.Order;
 import com.seecoder.BlueWhale.po.Product;
@@ -16,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.persistence.EntityManager;
-import javax.persistence.Query;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -81,32 +79,6 @@ public class ProductServiceImpl implements ProductService {
         return product.toVO();
     }
 
-    @Override
-    public List<ProductVO> getProductsWithCondition(String name, CategoryEnum category, Double price) {
-        String condition="SELECT p FROM Product p WHERE 1=1";
-        if (name!=null && name.length()>0){
-            condition=condition.concat(" AND name = :name");
-        }
-        if (category!=null){
-            condition=condition.concat(" AND category = :category");
-        }
-        if (price!=null && price>0){
-            condition=condition.concat(" AND price <= :price");
-        }
-        Query query=entityManager.createQuery(condition);
-        if (name!=null && name.length()>0){
-            query.setParameter("name",name);
-        }
-        if (category!=null){
-            query.setParameter("category",category);
-        }
-        if (price!=null && price>0){
-            query.setParameter("price",price);
-        }
-        List<Product> products=query.getResultList();
-        return products.stream().map(Product::toVO).collect(Collectors.toList());
-    }
-
     @Override
     public List<CommentVO> getComments(Integer productId) {
         List<Order> orders=orderRepository.findByProductIdAndFinishTimeNotNull(productId);

+ 0 - 128
src/main/java/com/seecoder/BlueWhale/util/ExcelUtil.java

@@ -1,128 +0,0 @@
-package com.seecoder.BlueWhale.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-
-import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.ss.usermodel.BorderStyle;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.FillPatternType;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
-import org.apache.poi.ss.usermodel.VerticalAlignment;
-import org.apache.poi.xssf.streaming.SXSSFCell;
-import org.apache.poi.xssf.streaming.SXSSFRow;
-import org.apache.poi.xssf.streaming.SXSSFSheet;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-import org.springframework.stereotype.Component;
-import com.seecoder.BlueWhale.vo.OrderVO;
-
-@Component
-public class ExcelUtil {
-
-    public CellStyle headSytle(SXSSFWorkbook workbook) {
-        // 设置style1的样式,此样式运用在第二行
-        CellStyle style1 = workbook.createCellStyle();// cell样式
-        // 设置单元格背景色,设置单元格背景色以下两句必须同时设置
-        style1.setFillPattern(FillPatternType.SOLID_FOREGROUND);// 设置填充样式
-        style1.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);// 设置填充色
-        // 设置单元格上、下、左、右的边框线
-        style1.setBorderBottom(BorderStyle.THIN);
-        style1.setBorderLeft(BorderStyle.THIN);
-        style1.setBorderRight(BorderStyle.THIN);
-        style1.setBorderTop(BorderStyle.THIN);
-        Font font1 = workbook.createFont();// 创建一个字体对象
-//        font1.setBoldweight((short) 10);// 设置字体的宽度
-        font1.setFontHeightInPoints((short) 10);// 设置字体的高度
-        font1.setBold(true);// 粗体显示
-        style1.setFont(font1);// 设置style1的字体
-        style1.setWrapText(true);// 设置自动换行
-        style1.setAlignment(HorizontalAlignment.CENTER);// 设置单元格字体显示居中(左右方向)
-        style1.setVerticalAlignment(VerticalAlignment.CENTER);// 设置单元格字体显示居中(上下方向)
-        return style1;
-    }
-
-    public CellStyle contentStyle(SXSSFWorkbook wb) {
-        // 设置style1的样式,此样式运用在第二行
-        CellStyle style1 = wb.createCellStyle();// cell样式
-        // 设置单元格上、下、左、右的边框线
-        style1.setBorderBottom(BorderStyle.THIN);
-        style1.setBorderLeft(BorderStyle.THIN);
-        style1.setBorderRight(BorderStyle.THIN);
-        style1.setBorderTop(BorderStyle.THIN);
-        style1.setWrapText(true);// 设置自动换行
-        style1.setAlignment(HorizontalAlignment.CENTER);// 设置单元格字体显示居中(左右方向)
-        style1.setVerticalAlignment(VerticalAlignment.CENTER);// 设置单元格字体显示居中(上下方向)
-        return style1;
-    }
-
-    public void initTitleEX(SXSSFSheet sheet, CellStyle header, List<String> attributeList, int titleLength[]) {
-        SXSSFRow row0 = sheet.createRow(0);
-        row0.setHeight((short) 800);
-        for (int j = 0; j < attributeList.size(); j++) {
-            SXSSFCell cell = row0.createCell(j);
-            //设置每一列的字段名
-            cell.setCellValue(attributeList.get(j));
-            cell.setCellStyle(header);
-            sheet.setColumnWidth(j, titleLength[j]);
-        }
-    }
-
-    public InputStream exportExcel(List<OrderVO> orders) {
-
-        ByteArrayOutputStream output = null;
-        InputStream inputStream = null;
-        SXSSFWorkbook wb = new SXSSFWorkbook(1000);// 保留1000条数据在内存中
-        SXSSFSheet sheet = wb.createSheet();
-        // 设置报表头样式
-        CellStyle header = headSytle(wb);
-        // 报表体样式 cell样式
-        CellStyle content = contentStyle(wb);
-        // 每一列字段名
-        List<String> attributeList = orders.get(0).getHeaderList();
-        // 字段名所在表格的宽度
-        int[] ints = new int[attributeList.size()];
-        for (int i = 0; i < ints.length; i++) {
-            ints[i] = 5000;
-        }
-
-        // 设置表头样式
-        initTitleEX(sheet, header, attributeList, ints);
-        //写入表格
-        for (OrderVO orderVO : orders) {
-            SXSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
-            List<Object> cellContent = orderVO.getCellContent();
-            int columnNumber = 0;
-            for (Object item : cellContent) {
-                SXSSFCell cell = row.createCell(columnNumber++);
-                cell.setCellValue(String.valueOf(item));
-            }
-        }
-        
-        try {
-            //将wb中的数据以字节形式存到inputStream1中
-            output = new ByteArrayOutputStream();
-            wb.write(output);
-            inputStream = new ByteArrayInputStream(output.toByteArray());
-            output.flush();
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            try {
-                if (output != null) {
-                    output.close();
-                    if (inputStream != null) {
-                        inputStream.close();
-                    }
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-        return inputStream;
-
-    }
-}