update:
add order detail
This commit is contained in:
@@ -93,7 +93,10 @@ CREATE TABLE `kiosk_order`
|
||||
`serial_number` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '订单编号',
|
||||
`user_phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '用户电话',
|
||||
`user_email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '用户邮箱',
|
||||
`sub_amount` decimal(10, 2) NOT NULL DEFAULT 0 COMMENT '小计',
|
||||
`total_amount` decimal(10, 2) NOT NULL DEFAULT 0 COMMENT '总金额',
|
||||
`tax_percent` decimal(10, 2) NOT NULL DEFAULT 0 COMMENT '税率',
|
||||
`tax_amount` decimal(10, 2) NOT NULL DEFAULT 0 COMMENT '税费',
|
||||
`create_user` bigint NULL DEFAULT NULL COMMENT '创建人',
|
||||
`create_dept` bigint NULL DEFAULT NULL COMMENT '创建部门',
|
||||
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
|
||||
|
||||
@@ -116,7 +116,7 @@ public class KioskApiController {
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@Operation(summary = "订单提交", description = "传入request")
|
||||
public R<String> submit(@Valid @RequestBody OrderApiRequest request) {
|
||||
public R<SubmitVO> submit(@Valid @RequestBody OrderApiRequest request) {
|
||||
return R.data(kioskApiService.submitOrder(request));
|
||||
}
|
||||
|
||||
|
||||
@@ -64,10 +64,25 @@ public class OrderEntity extends TenantEntity {
|
||||
*/
|
||||
@Schema(description = "用户邮箱")
|
||||
private String userEmail;
|
||||
/**
|
||||
* 小计
|
||||
*/
|
||||
@Schema(description = "小计")
|
||||
private BigDecimal subAmount;
|
||||
/**
|
||||
* 总金额
|
||||
*/
|
||||
@Schema(description = "总金额")
|
||||
private BigDecimal totalAmount;
|
||||
/**
|
||||
* 税率
|
||||
*/
|
||||
@Schema(description = "税率")
|
||||
private BigDecimal taxPercent;
|
||||
/**
|
||||
* 税费
|
||||
*/
|
||||
@Schema(description = "总金额")
|
||||
private BigDecimal taxAmount;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.springblade.modules.kiosk.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class SubmitVO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String serialNumber;
|
||||
|
||||
private String storeInfo;
|
||||
|
||||
private BigDecimal subAmount;
|
||||
|
||||
private BigDecimal TotalAmount;
|
||||
|
||||
private BigDecimal taxPercent;
|
||||
|
||||
private BigDecimal taxAmount;
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public interface IKioskApiService {
|
||||
|
||||
List<StickersApiVO> stickersList();
|
||||
|
||||
String submitOrder(OrderApiRequest request);
|
||||
SubmitVO submitOrder(OrderApiRequest request);
|
||||
|
||||
List<DictBizApiVO> materialList();
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springblade.modules.kiosk.pojo.entity.*;
|
||||
import org.springblade.modules.kiosk.pojo.vo.*;
|
||||
import org.springblade.modules.kiosk.service.*;
|
||||
import org.springblade.modules.system.pojo.entity.User;
|
||||
import org.springblade.modules.system.service.IDeptService;
|
||||
import org.springblade.modules.system.service.IDictBizService;
|
||||
import org.springblade.modules.system.service.IUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -24,8 +25,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -40,6 +41,8 @@ public class KioskServiceImpl implements IKioskApiService {
|
||||
|
||||
private final IUserService userService;
|
||||
|
||||
private final IDeptService deptService;
|
||||
|
||||
private final IDictBizService dictService;
|
||||
|
||||
private final ICategoryService categoryService;
|
||||
@@ -63,6 +66,8 @@ public class KioskServiceImpl implements IKioskApiService {
|
||||
|
||||
private static final String materialType = "material_type";
|
||||
|
||||
private static final Integer taxPercent = 15;
|
||||
|
||||
@Override
|
||||
public List<CategoryApiVO> categoryList() {
|
||||
return categoryService.list().stream().map(category -> {
|
||||
@@ -149,7 +154,7 @@ public class KioskServiceImpl implements IKioskApiService {
|
||||
|
||||
@Override
|
||||
@Transactional(timeout = 30, rollbackFor = Exception.class)
|
||||
public String submitOrder(OrderApiRequest request) {
|
||||
public SubmitVO submitOrder(OrderApiRequest request) {
|
||||
try {
|
||||
photoAttachmentService.update(Wrappers.<PhotoAttachmentEntity>lambdaUpdate().eq(PhotoAttachmentEntity::getCreateUser, AuthUtil.getUserId()).set(PhotoAttachmentEntity::getStatus, 2));
|
||||
|
||||
@@ -215,12 +220,21 @@ public class KioskServiceImpl implements IKioskApiService {
|
||||
|
||||
item.getPhotos().forEach(photo -> photoAttachmentService.createPhotoDetail(photo, orderDetail.getId()));
|
||||
});
|
||||
BigDecimal sum = totalAmount.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
order.setTotalAmount(sum);
|
||||
order.setSubAmount(totalAmount.stream().reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP));
|
||||
order.setTaxPercent(BigDecimal.valueOf(taxPercent).setScale(2, RoundingMode.HALF_UP));
|
||||
order.setTaxAmount(order.getSubAmount().multiply(BigDecimal.valueOf(taxPercent).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP));
|
||||
order.setTotalAmount(order.getSubAmount().add(order.getTaxAmount()).setScale(2, RoundingMode.HALF_UP));
|
||||
orderService.updateById(order);
|
||||
|
||||
log.info("Order submitted successfully: {}", order.getSerialNumber());
|
||||
return order.getSerialNumber();
|
||||
SubmitVO result = new SubmitVO();
|
||||
result.setStoreInfo(deptService.getDeptNames(AuthUtil.getDeptId()).stream().findFirst().orElse(""));
|
||||
result.setSubAmount(order.getTotalAmount());
|
||||
result.setSerialNumber(order.getSerialNumber());
|
||||
result.setTaxPercent(order.getTaxPercent());
|
||||
result.setTaxAmount(order.getTaxAmount());
|
||||
result.setTotalAmount(order.getTotalAmount());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to submit order", e);
|
||||
throw e; // Rethrow the exception to trigger a rollback
|
||||
|
||||
Reference in New Issue
Block a user