src/org/wdl/hotelSysTest/sys/service/OrderDetailServiceImpl.java
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package org.wdl.hotelSysTest.sys.service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.wdl.hotelSysTest.sys.dao.OrderDao;
import org.wdl.hotelSysTest.sys.dao.OrderDaoImpl;
import org.wdl.hotelSysTest.sys.dao.OrderDetailDao;
import org.wdl.hotelSysTest.sys.dao.OrderDetailDaoImpl;
import org.wdl.hotelTest.bean.Order;
import org.wdl.hotelTest.bean.OrderDetail;
import org.wdl.hotelTest.util.ConnectionFactory;
public class OrderDetailServiceImpl implements OrderDetailService {
OrderDetailDao orderDetailDao = new OrderDetailDaoImpl();
OrderDao orderDao = new OrderDaoImpl();
@Override
public OrderDetail findById(int id) {
return orderDetailDao.findById(id);
}
@Override
public void update(OrderDetail orderDetail, Integer flag) {
Connection connection = ConnectionFactory.getConnection();
try {
connection.setAutoCommit(false);
orderDetailDao.update(orderDetail, connection);
Order order = orderDao.findById(orderDetail.getOrderId());
if (flag == 1) {
//删除
order.setTotalPrice(order.getTotalPrice() - orderDetail.getFood().getPrice() * orderDetail.getFood().getDiscount() * orderDetail.getBuyNum());
} else if (flag == 2) {
//修改数量
List<OrderDetail> details = orderDao.findByOrderId(order.getId());
System.out.println("details:" + details);
Double totalPrice = orderDetail.getFood().getPrice() * orderDetail.getFood().getDiscount() * orderDetail.getBuyNum();
for (OrderDetail orderDetail2 : details) {
if ((orderDetail2.getId() != orderDetail.getId()) && (orderDetail2.getDisabled() != 1)) {
totalPrice = totalPrice + orderDetail2.getFood().getPrice() * orderDetail2.getFood().getDiscount() * orderDetail2.getBuyNum();
}
}
order.setTotalPrice(totalPrice);
}
orderDao.update(order);
connection.commit();
} catch (SQLException e) {
e.printStackTrace();
} finally {
ConnectionFactory.close(connection, null, null);
}
}
后面还有 6 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
