|
|
|
|
@@ -2,6 +2,7 @@ package org.springblade.modules.kiosk.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
|
|
import org.springblade.core.oss.OssTemplate;
|
|
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
|
|
@@ -12,17 +13,21 @@ import org.springblade.core.tool.utils.*;
|
|
|
|
|
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.DictBizApiVO;
|
|
|
|
|
import org.springblade.modules.kiosk.pojo.vo.PhotoAttachmentApiVO;
|
|
|
|
|
import org.springblade.modules.kiosk.pojo.vo.StickersApiVO;
|
|
|
|
|
import org.springblade.modules.kiosk.service.*;
|
|
|
|
|
import org.springblade.modules.system.pojo.entity.User;
|
|
|
|
|
import org.springblade.modules.system.service.IDictBizService;
|
|
|
|
|
import org.springblade.modules.system.service.IUserService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
public class KioskServiceImpl implements IKioskApiService {
|
|
|
|
|
@@ -33,6 +38,8 @@ public class KioskServiceImpl implements IKioskApiService {
|
|
|
|
|
|
|
|
|
|
private final IUserService userService;
|
|
|
|
|
|
|
|
|
|
private final IDictBizService dictService;
|
|
|
|
|
|
|
|
|
|
private final ICategoryService categoryService;
|
|
|
|
|
|
|
|
|
|
private final IPhotoAttachmentService photoAttachmentService;
|
|
|
|
|
@@ -51,6 +58,12 @@ public class KioskServiceImpl implements IKioskApiService {
|
|
|
|
|
|
|
|
|
|
private static final String codePrefix = "kiosk:code:";
|
|
|
|
|
|
|
|
|
|
private static final String shapeType = "shape_type";
|
|
|
|
|
|
|
|
|
|
private static final String sizeType = "size_type";
|
|
|
|
|
|
|
|
|
|
private static final String materialType = "material_type";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<CategoryApiVO> categoryList() {
|
|
|
|
|
return List.of();
|
|
|
|
|
@@ -124,59 +137,110 @@ public class KioskServiceImpl implements IKioskApiService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(timeout = 30, rollbackFor = Exception.class)
|
|
|
|
|
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);
|
|
|
|
|
try {
|
|
|
|
|
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());
|
|
|
|
|
if (category == null) {
|
|
|
|
|
throw new ServiceException("Invalid category.");
|
|
|
|
|
}
|
|
|
|
|
if (category.getType() == 1 && StringUtil.isBlank(item.getShape())) {
|
|
|
|
|
throw new ServiceException("Invalid shape.");
|
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
PhotoAttachmentEntity snapshotPhoto = photoAttachmentService.getById(item.getSnapshot());
|
|
|
|
|
if (snapshotPhoto == null) {
|
|
|
|
|
throw new ServiceException("Invalid snapshot.");
|
|
|
|
|
}
|
|
|
|
|
orderDetail.setSnapshotLink(snapshotPhoto.getLink());
|
|
|
|
|
//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<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);
|
|
|
|
|
if (!item.getStickers().isEmpty()) {
|
|
|
|
|
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);
|
|
|
|
|
if (!item.getText().isEmpty()) {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
order.setTotalAmount(totalAmount);
|
|
|
|
|
orderService.updateById(order);
|
|
|
|
|
return order.getSerialNumber();
|
|
|
|
|
log.info("Order submitted successfully: {}", order.getSerialNumber());
|
|
|
|
|
return order.getSerialNumber();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("Failed to submit order", e);
|
|
|
|
|
throw e; // Rethrow the exception to trigger a rollback
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DictBizApiVO> materialList() {
|
|
|
|
|
return dictService.getList(materialType).stream().map(dictBiz -> {
|
|
|
|
|
DictBizApiVO vo = new DictBizApiVO();
|
|
|
|
|
vo.setKey(dictBiz.getDictKey());
|
|
|
|
|
vo.setValue(dictBiz.getDictValue());
|
|
|
|
|
return vo;
|
|
|
|
|
}).toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DictBizApiVO> sizeList() {
|
|
|
|
|
return dictService.getList(sizeType).stream().map(dictBiz -> {
|
|
|
|
|
DictBizApiVO vo = new DictBizApiVO();
|
|
|
|
|
vo.setKey(dictBiz.getDictKey());
|
|
|
|
|
vo.setValue(dictBiz.getDictValue());
|
|
|
|
|
return vo;
|
|
|
|
|
}).toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DictBizApiVO> shapeList() {
|
|
|
|
|
return dictService.getList(shapeType).stream().map(dictBiz -> {
|
|
|
|
|
DictBizApiVO vo = new DictBizApiVO();
|
|
|
|
|
vo.setKey(dictBiz.getDictKey());
|
|
|
|
|
vo.setValue(dictBiz.getDictValue());
|
|
|
|
|
return vo;
|
|
|
|
|
}).toList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|