|
|
|
|
@@ -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
|
|
|
|
|
|