package com.gxyan.service.impl;
import com.github.pagehelper.PageHelper;
import com.gxyan.common.Const;
import com.gxyan.common.ServerResponse;
import com.gxyan.dao.CarMapper;
import com.gxyan.dao.OrderDetailsMapper;
import com.gxyan.dao.OrderMapper;
import com.gxyan.pojo.Order;
import com.gxyan.pojo.OrderDetails;
import com.gxyan.service.IOrderService;
import com.gxyan.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.UUID;
/**
* @author gxyan
* @date 2019/1/3 13:05
*/
@Slf4j
@Service
public class OrderServiceImpl implements IOrderService {
@Autowired
private CarMapper carMapper;
@Autowired
private OrderMapper orderMapper;
@Autowired
private OrderDetailsMapper detailsMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public ServerResponse addOrder(OrderVo orderVo) {
log.info(orderVo.toString());
Order order = new Order();
Long orderId = createOrderId();
order.setId(orderId);
order.setCustomerId(orderVo.getCustomerId());
order.setEmployeeId(orderVo.getEmployeeId());
order.setStatus(orderVo.getStatus());
order.setTotalPrice(orderVo.getTotalPrice());
int result = orderMapper.insert(order);
if (result == 0) {
// 手动回滚
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("添加订单失败");
}
if (orderVo.getStatus().equals(Const.Number.ONE)) {
result = orderMapper.updatePayTimeByPrimaryKey(orderId);
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("添加订单失败");
}
}
for (OrderDetailVo detailVo: orderVo.getDetailVos()) {
OrderDetails orderDetails = new OrderDetails();
orderDetails.setId(createOrderDetailsId());
orderDetails.setCarId(detailVo.getCarId());
int num = detailVo.getCarNumber();
orderDetails.setCarNumber(num);
orderDetails.setOrderId(orderId);
result = detailsMapper.insert(orderDetails);
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("添加订单失败");
}
int repertory = carMapper.selectRepertoryByPrimaryKey(detailVo.getCarId());
num = repertory - num;
if (num >= 0){
result = carMapper.updateRepertoryByPrimaryKey(detailVo.getCarId(), num);
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("添加订单失败");
}
} else {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("库存不足,添加订单失败");
}
}
return ServerResponse.createBySuccess();
}
@Override
public ServerResponse getList(OrderQuery orderQuery) {
List<OrderList> list = PageHelper.startPage(orderQuery.getPage(), orderQuery.getLimit()).doSelectPage(()-> orderMapper.selectSale(orderQuery));
if (list != null) {
for (OrderList orderList: list) {
List<Details> details = detailsMapper.selectDetailsByOrderId(orderList.getOrderId());
orderList.setDetails(details);
}
ListVo listVo = new ListVo();
listVo.setItems(list);
listVo.setTotal(PageHelper.count(()->orderMapper.selectSale(orderQuery)));
return ServerResponse.createBySuccess(listVo);
}
return ServerResponse.createByErrorMessage("获取订单列表失败");
}
@Override
@Transactional(rollbackFor = Exception.class)
public ServerResponse update(Long orderId, String status) {
int result = orderMapper.updateStatusByPrimaryKey(orderId, status);
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("更新订单失败");
}
if (status.equals(Const.Number.ONE)) {
// status=1,支付订单,更新支付时间
result = orderMapper.updatePayTimeByPrimaryKey(orderId);
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("更新订单失败");
}
} else if (status.equals(Const.Number.TWO)) {
// status=2,取消订单,车辆回库
List <OrderDetails> details = detailsMapper.selectByOrderId(orderId);
for (OrderDetails orderDetails: details) {
result = carMapper.addRepertoryByPrimaryKey(orderDetails.getCarId(), orderDetails.getCarNumber());
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("更新订单失败");
}
}
}
return ServerResponse.createBySuccess();
}
@Override
@Transactional(rollbackFor = Exception.class)
public ServerResponse updateDetail(OrderDetails orderDetails) {
OrderDetails oldDetails = detailsMapper.selectByPrimaryKey(orderDetails.getId());
int result = carMapper.addRepertoryByPrimaryKey(oldDetails.getCarId(), oldDetails.getCarNumber());
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("更新失败");
}
int num = carMapper.selectRepertoryByPrimaryKey(orderDetails.getCarId()) - orderDetails.getCarNumber();
if (num >= 0){
result = carMapper.updateRepertoryByPrimaryKey(orderDetails.getCarId(), num);
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("添加订单失败");
}
} else {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("库存不足,添加订单失败");
}
result = detailsMapper.updateByPrimaryKey(orderDetails);
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("更新失败");
}
BigDecimal oldPrice = carMapper.selectSalePriceByPrimaryKey(oldDetails.getCarId()).multiply(BigDecimal.valueOf(oldDetails.getCarNumber()));
BigDecimal newPrice = carMapper.selectSalePriceByPrimaryKey(orderDetails.getCarId()).multiply(BigDecimal.valueOf(orderDetails.getCarNumber()));
result = orderMapper.addTotalPriceByPrimaryKey(orderDetails.getOrderId(), newPrice.subtract(oldPrice));
if (result == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ServerResponse.createByErrorMessage("更新失败");
}
return ServerResponse.createBySuccess();
}
@Overri
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
SpringBoot+Vue实现汽车销售管理系统前后端分离项目.zip使用教程如下: 导入carsale.sql到数据库中 修改src/resources/application.yml的数据库连接信息 启动CarsaleApplication,访问localhost:8080 食用指南PLUS(Vue项目启动) 安装好node环境 在front目录下运行npm install安装所需要的包 在front目录下运行npm run dev,访问localhost:9527 SpringBoot+Vue实现汽车销售管理系统前后端分离项目.zip使用教程如下: 导入carsale.sql到数据库中 修改src/resources/application.yml的数据库连接信息 启动CarsaleApplication,访问localhost:8080 食用指南PLUS(Vue项目启动) 安装好node环境 在front目录下运行npm install安装所需要的包 在front目录下运行npm run dev,访问localhost:9527
资源推荐
资源详情
资源评论
收起资源包目录
SpringBoot+Vue实现汽车销售管理系统前后端分离项目.zip (382个子文件)
.babelrc 313B
index.css 414KB
chunk-libs.9adc5ec3.css 205KB
skin.min.css 42KB
skin.min.css 42KB
app.6448790f.css 13KB
visualblocks.css 5KB
visualblocks.css 5KB
chunk-343b.4102efdc.css 5KB
chunk-cdc7.a00cce64.css 4KB
content.min.css 4KB
content.min.css 4KB
content.inline.min.css 3KB
content.inline.min.css 3KB
prism.css 2KB
prism.css 2KB
chunk-04bd.4df66e48.css 2KB
waves.css 825B
chunk-10c4.c3874ac2.css 763B
chunk-7ac7.c3874ac2.css 763B
chunk-720a.784534d9.css 763B
chunk-1e34.784534d9.css 763B
chunk-30e8.784534d9.css 763B
chunk-4de4.65ff90d7.css 745B
chunk-9ce9.a1efc4f6.css 492B
chunk-719c.d257adca.css 264B
chunk-324d.ab5ceba3.css 184B
chunk-cb25.8cf903bf.css 154B
chunk-dbc2.c23b3304.css 154B
.editorconfig 243B
tinymce.eot 18KB
tinymce.eot 18KB
tinymce-small.eot 9KB
tinymce-small.eot 9KB
.eslintignore 34B
401.089007e.gif 160KB
401.gif 160KB
loader.gif 3KB
loader.gif 3KB
smiley-cool.gif 354B
smiley-cool.gif 354B
smiley-wink.gif 350B
smiley-wink.gif 350B
smiley-smile.gif 344B
smiley-smile.gif 344B
smiley-laughing.gif 343B
smiley-laughing.gif 343B
smiley-foot-in-mouth.gif 342B
smiley-foot-in-mouth.gif 342B
smiley-frown.gif 340B
smiley-frown.gif 340B
smiley-kiss.gif 338B
smiley-surprised.gif 338B
smiley-kiss.gif 338B
smiley-surprised.gif 338B
smiley-undecided.gif 337B
smiley-undecided.gif 337B
smiley-innocent.gif 336B
smiley-yell.gif 336B
smiley-innocent.gif 336B
smiley-yell.gif 336B
smiley-embarassed.gif 331B
smiley-embarassed.gif 331B
smiley-cry.gif 329B
smiley-cry.gif 329B
smiley-tongue-out.gif 328B
smiley-tongue-out.gif 328B
smiley-sealed.gif 323B
smiley-sealed.gif 323B
smiley-money-mouth.gif 321B
smiley-money-mouth.gif 321B
object.gif 152B
object.gif 152B
anchor.gif 53B
anchor.gif 53B
trans.gif 43B
trans.gif 43B
.gitignore 1KB
index.html 8KB
index.html 494B
favicon.ico 66KB
favicon.ico 66KB
OrderServiceImpl.java 10KB
StoreServiceImpl.java 6KB
EmployeeServiceImpl.java 3KB
InitServiceImpl.java 3KB
UserController.java 3KB
Employee.java 3KB
ServerResponse.java 3KB
CustomerServiceImpl.java 2KB
ChartServiceImpl.java 2KB
ChartController.java 2KB
Car.java 2KB
Order.java 2KB
OrderController.java 2KB
StoreController.java 2KB
OrderMapperTest.java 1KB
Customer.java 1KB
InitController.java 1KB
CustomerController.java 1KB
共 382 条
- 1
- 2
- 3
- 4
资源评论
程序员张小妍
- 粉丝: 1w+
- 资源: 3474
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 【创新无忧】基于鸽群优化算法PIO优化广义神经网络GRNN实现光伏预测附matlab代码.rar
- 【创新无忧】基于鸽群优化算法PIO优化相关向量机RVM实现北半球光伏数据预测附matlab代码.rar
- 【创新无忧】基于鸽群优化算法PIO优化极限学习机KELM实现故障诊断附matlab代码.rar
- 【创新无忧】基于哈里斯鹰优化算法HHO优化广义神经网络GRNN实现数据回归预测附matlab代码.rar
- 【创新无忧】基于哈里斯鹰优化算法HHO优化广义神经网络GRNN实现电机故障诊断附matlab代码.rar
- 【创新无忧】基于哈里斯鹰优化算法HHO优化广义神经网络GRNN实现光伏预测附matlab代码.rar
- 【创新无忧】基于哈里斯鹰优化算法HHO优化相关向量机RVM实现北半球光伏数据预测附matlab代码.rar
- 【创新无忧】基于哈里斯鹰优化算法HHO优化极限学习机ELM实现乳腺肿瘤诊断附matlab代码.rar
- 【创新无忧】基于哈里斯鹰优化算法HHO优化极限学习机KELM实现故障诊断附matlab代码.rar
- 【创新无忧】基于哈里斯鹰优化算法HHO优化相关向量机RVM实现数据多输入单输出回归预测附matlab代码.rar
- 【创新无忧】基于海鸥优化算法SOA优化广义神经网络GRNN实现光伏预测附matlab代码.rar
- 【创新无忧】基于海鸥优化算法SOA优化广义神经网络GRNN实现电机故障诊断附matlab代码.rar
- 【创新无忧】基于海鸥优化算法SOA优化极限学习机ELM实现乳腺肿瘤诊断附matlab代码.rar
- 【创新无忧】基于海鸥优化算法SOA优化极限学习机KELM实现故障诊断附matlab代码.rar
- 【创新无忧】基于海鸥优化算法SOA优化广义神经网络GRNN实现数据回归预测附matlab代码.rar
- 【创新无忧】基于海洋捕食者优化算法MPA优化广义神经网络GRNN实现电机故障诊断附matlab代码.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功