1. add order
This commit is contained in:
2025-10-08 23:37:02 +08:00
parent 98e125508d
commit 7c73df2783
5 changed files with 131 additions and 12 deletions

View File

@@ -1,9 +1,11 @@
package org.springblade.modules.kiosk.controller;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.modules.kiosk.pojo.dto.OrderApiRequest;
import org.springblade.modules.kiosk.pojo.vo.CategoryApiVO;
import org.springblade.modules.kiosk.pojo.vo.PhotoAttachmentApiVO;
import org.springblade.modules.kiosk.pojo.vo.StickersApiVO;
@@ -48,7 +50,7 @@ public class KioskApiController {
/**
* 照片列表查询
*
* @return String
* @return List<PhotoAttachmentApiVO>
*/
@GetMapping("/photo-list")
@Operation(summary = "照片列表查询")
@@ -60,7 +62,7 @@ public class KioskApiController {
/**
* 照片列表查询
*
* @return String
* @return List<StickersApiVO>
*/
@GetMapping("/stickers-list")
@Operation(summary = "贴纸列表查询")
@@ -69,4 +71,15 @@ public class KioskApiController {
return R.data(list);
}
/**
* 订单提交
*
* @return String
*/
@PostMapping("/submit")
@Operation(summary = "订单提交", description = "传入request")
public R<String> submit(@Valid @RequestBody OrderApiRequest request) {
return R.data(kioskApiService.submitOrder(request));
}
}

View File

@@ -32,8 +32,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import jakarta.validation.Valid;
import org.springblade.core.datascope.annotation.DataAuth;
import org.springblade.core.datascope.enums.DataScopeEnum;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;

View File

@@ -0,0 +1,38 @@
package org.springblade.modules.kiosk.pojo.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class OrderApiRequest implements Serializable {
private String phone;
private String email;
private List<Item> data = List.of();
@Data
public static class Item {
private Long category;
private String snapshot;
private List<Long> photos = List.of();
private String size;
private String material;
private String shape;
private List<Text> text = List.of();
private List<Long> stickers = List.of();
private List<Long> accessories = List.of();
}
@Data
public static class Text {
private Integer size;
private String content;
private String font;
}
}

View File

@@ -1,5 +1,6 @@
package org.springblade.modules.kiosk.service;
import org.springblade.modules.kiosk.pojo.dto.OrderApiRequest;
import org.springblade.modules.kiosk.pojo.vo.CategoryApiVO;
import org.springblade.modules.kiosk.pojo.vo.PhotoAttachmentApiVO;
import org.springblade.modules.kiosk.pojo.vo.StickersApiVO;
@@ -20,4 +21,5 @@ public interface IKioskApiService {
List<StickersApiVO> stickersList();
String submitOrder(OrderApiRequest request);
}

View File

@@ -9,21 +9,19 @@ import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.*;
import org.springblade.modules.kiosk.pojo.entity.PhotoAttachmentEntity;
import org.springblade.modules.kiosk.pojo.entity.StickersEntity;
import org.springblade.modules.kiosk.pojo.dto.OrderApiRequest;
import org.springblade.modules.kiosk.pojo.entity.*;
import org.springblade.modules.kiosk.pojo.vo.CategoryApiVO;
import org.springblade.modules.kiosk.pojo.vo.PhotoAttachmentApiVO;
import org.springblade.modules.kiosk.pojo.vo.StickersApiVO;
import org.springblade.modules.kiosk.service.IKioskApiService;
import org.springblade.modules.kiosk.service.IPhotoAttachmentService;
import org.springblade.modules.kiosk.service.IStickersService;
import org.springblade.modules.kiosk.service.*;
import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;
@Service
@AllArgsConstructor
@@ -35,10 +33,22 @@ public class KioskServiceImpl implements IKioskApiService {
private final IUserService userService;
private final ICategoryService categoryService;
private final IPhotoAttachmentService photoAttachmentService;
private final IOrderDetailPhotoAttachmentRService orderDetailPhotoAttachmentRService;
private final IOrderService orderService;
private final IOrderDetailService orderDetailService;
private final ITextAttachmentRService textAttachmentRService;
private final IStickersService stickersService;
private final IStickersAttachmentRService stickersAttachmentRService;
private static final String codePrefix = "kiosk:code:";
@Override
@@ -99,7 +109,7 @@ public class KioskServiceImpl implements IKioskApiService {
vo.setLink(photo.getLink());
vo.setId(photo.getId());
return vo;
}).collect(Collectors.toList());
}).toList();
}
@Override
@@ -110,6 +120,63 @@ public class KioskServiceImpl implements IKioskApiService {
vo.setLink(stickers.getLink());
vo.setId(stickers.getId());
return vo;
}).collect(Collectors.toList());
}).toList();
}
@Override
public String submitOrder(OrderApiRequest request) {
BladeUser user = AuthUtil.getUser();
photoAttachmentService.update(Wrappers.<PhotoAttachmentEntity>lambdaUpdate()
.eq(PhotoAttachmentEntity::getCreateUser, user.getUserId())
.set(PhotoAttachmentEntity::getStatus, 2));
OrderEntity order = new OrderEntity();
order.setUserPhone(request.getPhone());
order.setUserEmail(request.getEmail());
order.setSerialNumber(StringUtil.random(8, RandomType.INT));
orderService.save(order);
BigDecimal totalAmount = BigDecimal.ZERO;
request.getData().forEach(item -> {
OrderDetailEntity orderDetail = new OrderDetailEntity();
orderDetail.setOrderId(order.getId());
CategoryEntity category = categoryService.getById(item.getCategory());
orderDetail.setCategoryId(item.getCategory());
orderDetail.setCategoryType(category.getType());
orderDetail.setMaterial(item.getMaterial());
orderDetail.setSize(item.getSize());
orderDetail.setShape(category.getType() == 1 ? item.getShape() : category.getShape());
orderDetail.setSnapshotLink(item.getSnapshot());
//todo: add amount!
orderDetailService.save(orderDetail);
List<OrderDetailPhotoAttachmentREntity> photoRList = item.getPhotos().stream().map(p -> {
OrderDetailPhotoAttachmentREntity r = new OrderDetailPhotoAttachmentREntity();
r.setPhotoId(p);
r.setDetailId(orderDetail.getId());
return r;
}).toList();
orderDetailPhotoAttachmentRService.saveBatch(photoRList);
List<StickersAttachmentREntity> stickerRList = item.getStickers().stream().map(s -> {
StickersAttachmentREntity r = new StickersAttachmentREntity();
r.setStickersId(s);
r.setDetailId(orderDetail.getId());
return r;
}).toList();
stickersAttachmentRService.saveBatch(stickerRList);
List<TextAttachmentREntity> textRList = item.getText().stream().map(t -> {
TextAttachmentREntity r = new TextAttachmentREntity();
r.setDetailId(orderDetail.getId());
r.setFontName(t.getFont());
r.setFontSize(t.getSize());
r.setTextContent(t.getContent());
return r;
}).toList();
textAttachmentRService.saveBatch(textRList);
});
order.setTotalAmount(totalAmount);
orderService.updateById(order);
return order.getSerialNumber();
}
}