From c56befe5161c0588999c5d548ef892cd394c297c Mon Sep 17 00:00:00 2001 From: nagocoler Date: Sun, 10 Nov 2024 17:53:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=AE=A2=E5=8D=95=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/OrderController.java | 134 ++++++++++ .../java/com/ruoyi/system/domain/Order.java | 237 ++++++++++++++++++ .../com/ruoyi/system/domain/OrderItem.java | 94 +++++++ .../com/ruoyi/system/mapper/OrderMapper.java | 87 +++++++ .../ruoyi/system/service/IOrderService.java | 61 +++++ .../system/service/impl/OrderServiceImpl.java | 131 ++++++++++ .../resources/mapper/system/OrderMapper.xml | 153 +++++++++++ 7 files changed, 897 insertions(+) create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/controller/OrderController.java create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/domain/Order.java create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/domain/OrderItem.java create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/mapper/OrderMapper.java create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/service/IOrderService.java create mode 100644 ruoyi-core/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java create mode 100644 ruoyi-core/src/main/resources/mapper/system/OrderMapper.xml diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/controller/OrderController.java b/ruoyi-core/src/main/java/com/ruoyi/system/controller/OrderController.java new file mode 100644 index 0000000..38fcac7 --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/controller/OrderController.java @@ -0,0 +1,134 @@ +package com.ruoyi.system.controller; + +import java.util.Date; +import java.util.List; +import java.util.Optional; + +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.system.domain.CartItem; +import com.ruoyi.system.domain.OrderItem; +import com.ruoyi.system.service.ICartItemService; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.beans.BeanUtils; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.Order; +import com.ruoyi.system.service.IOrderService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 订单列表Controller + * + * @author ruoyi + * @date 2024-11-10 + */ +@RestController +@RequestMapping("/system/order") +public class OrderController extends BaseController +{ + @Autowired + private IOrderService orderService; + + @Autowired + private ICartItemService cartItemService; + + /** + * 查询订单列表列表 + */ + @PreAuthorize("@ss.hasPermi('system:order:list')") + @GetMapping("/list") + public TableDataInfo list(Order order) + { + startPage(); + List list = orderService.selectOrderList(order); + return getDataTable(list); + } + + /** + * 导出订单列表列表 + */ + @PreAuthorize("@ss.hasPermi('system:order:export')") + @Log(title = "订单列表", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, Order order) + { + List list = orderService.selectOrderList(order); + ExcelUtil util = new ExcelUtil(Order.class); + util.exportExcel(response, list, "订单列表数据"); + } + + /** + * 获取订单列表详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:order:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(orderService.selectOrderById(id)); + } + + /** + * 新增订单列表 + */ + @PreAuthorize("@ss.hasPermi('system:order:add')") + @Log(title = "订单列表", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody Order order) + { + return toAjax(orderService.insertOrder(order)); + } + + /** + * 修改订单列表 + */ + @PreAuthorize("@ss.hasPermi('system:order:edit')") + @Log(title = "订单列表", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody Order order) + { + return toAjax(orderService.updateOrder(order)); + } + + /** + * 删除订单列表 + */ + @PreAuthorize("@ss.hasPermi('system:order:remove')") + @Log(title = "订单列表", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(orderService.deleteOrderByIds(ids)); + } + + @PostMapping("/create") + public AjaxResult createUserOrder(@RequestBody Order order) { + List items = cartItemService.selectCartItemListById(SecurityUtils.getUserId()); + List orderItemList = items.stream().map(item -> { + OrderItem orderItem = new OrderItem(); + BeanUtils.copyProperties(item, orderItem, "id"); + return orderItem; + }).toList(); + Long totalPrice = orderItemList.stream() + .map(item -> item.getCount() * item.getPrice().longValue()) + .reduce(Long::sum) + .orElse(0L); + order.setUid(SecurityUtils.getUserId()); + order.setTime(new Date()); + order.setPirce(totalPrice.doubleValue()); + order.setOrderItemList(orderItemList); + return toAjax(orderService.insertOrder(order)); + } +} diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/domain/Order.java b/ruoyi-core/src/main/java/com/ruoyi/system/domain/Order.java new file mode 100644 index 0000000..8006367 --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/domain/Order.java @@ -0,0 +1,237 @@ +package com.ruoyi.system.domain; + +import java.util.List; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 订单列表对象 db_order + * + * @author ruoyi + * @date 2024-11-10 + */ +public class Order extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 订单号 */ + private Long id; + + /** 用户ID */ + @Excel(name = "用户ID") + private Long uid; + + /** 时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date time; + + /** 合计金额 */ + @Excel(name = "合计金额") + private Double pirce; + + /** 收件人名称 */ + @Excel(name = "收件人名称") + private String name; + + /** 收件公司 */ + @Excel(name = "收件公司") + private String company; + + /** 国家 */ + @Excel(name = "国家") + private String country; + + /** 城市 */ + @Excel(name = "城市") + private String city; + + /** 街道地址1 */ + @Excel(name = "街道地址1") + private String steet1; + + /** 街道地址2 */ + @Excel(name = "街道地址2") + private String steet2; + + /** 邮政编码 */ + @Excel(name = "邮政编码") + private String postal; + + /** 手机号码 */ + @Excel(name = "手机号码") + private String phone; + + /** 电子邮件 */ + @Excel(name = "电子邮件") + private String email; + + /** 订单备注 */ + @Excel(name = "订单备注") + private String note; + + /** 订单商品列表信息 */ + private List orderItemList; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setUid(Long uid) + { + this.uid = uid; + } + + public Long getUid() + { + return uid; + } + public void setTime(Date time) + { + this.time = time; + } + + public Date getTime() + { + return time; + } + public void setPirce(Double pirce) + { + this.pirce = pirce; + } + + public Double getPirce() + { + return pirce; + } + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + public void setCompany(String company) + { + this.company = company; + } + + public String getCompany() + { + return company; + } + public void setCountry(String country) + { + this.country = country; + } + + public String getCountry() + { + return country; + } + public void setCity(String city) + { + this.city = city; + } + + public String getCity() + { + return city; + } + public void setSteet1(String steet1) + { + this.steet1 = steet1; + } + + public String getSteet1() + { + return steet1; + } + public void setSteet2(String steet2) + { + this.steet2 = steet2; + } + + public String getSteet2() + { + return steet2; + } + public void setPostal(String postal) + { + this.postal = postal; + } + + public String getPostal() + { + return postal; + } + public void setPhone(String phone) + { + this.phone = phone; + } + + public String getPhone() + { + return phone; + } + public void setEmail(String email) + { + this.email = email; + } + + public String getEmail() + { + return email; + } + public void setNote(String note) + { + this.note = note; + } + + public String getNote() + { + return note; + } + + public List getOrderItemList() + { + return orderItemList; + } + + public void setOrderItemList(List orderItemList) + { + this.orderItemList = orderItemList; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("uid", getUid()) + .append("time", getTime()) + .append("pirce", getPirce()) + .append("name", getName()) + .append("company", getCompany()) + .append("country", getCountry()) + .append("city", getCity()) + .append("steet1", getSteet1()) + .append("steet2", getSteet2()) + .append("postal", getPostal()) + .append("phone", getPhone()) + .append("email", getEmail()) + .append("note", getNote()) + .append("orderItemList", getOrderItemList()) + .toString(); + } +} diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/domain/OrderItem.java b/ruoyi-core/src/main/java/com/ruoyi/system/domain/OrderItem.java new file mode 100644 index 0000000..35153d6 --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/domain/OrderItem.java @@ -0,0 +1,94 @@ +package com.ruoyi.system.domain; + +import java.math.BigDecimal; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 订单商品列表对象 db_order_item + * + * @author ruoyi + * @date 2024-11-10 + */ +public class OrderItem extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** */ + private Long id; + + /** */ + @Excel(name = "") + private Long orderId; + + /** */ + @Excel(name = "") + private String title; + + /** */ + @Excel(name = "") + private BigDecimal price; + + /** */ + @Excel(name = "") + private Long count; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setOrderId(Long orderId) + { + this.orderId = orderId; + } + + public Long getOrderId() + { + return orderId; + } + public void setTitle(String title) + { + this.title = title; + } + + public String getTitle() + { + return title; + } + public void setPrice(BigDecimal price) + { + this.price = price; + } + + public BigDecimal getPrice() + { + return price; + } + public void setCount(Long count) + { + this.count = count; + } + + public Long getCount() + { + return count; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("orderId", getOrderId()) + .append("title", getTitle()) + .append("price", getPrice()) + .append("count", getCount()) + .toString(); + } +} diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/mapper/OrderMapper.java b/ruoyi-core/src/main/java/com/ruoyi/system/mapper/OrderMapper.java new file mode 100644 index 0000000..ada6a02 --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/mapper/OrderMapper.java @@ -0,0 +1,87 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.Order; +import com.ruoyi.system.domain.OrderItem; + +/** + * 订单列表Mapper接口 + * + * @author ruoyi + * @date 2024-11-10 + */ +public interface OrderMapper +{ + /** + * 查询订单列表 + * + * @param id 订单列表主键 + * @return 订单列表 + */ + public Order selectOrderById(Long id); + + /** + * 查询订单列表列表 + * + * @param order 订单列表 + * @return 订单列表集合 + */ + public List selectOrderList(Order order); + + /** + * 新增订单列表 + * + * @param order 订单列表 + * @return 结果 + */ + public int insertOrder(Order order); + + /** + * 修改订单列表 + * + * @param order 订单列表 + * @return 结果 + */ + public int updateOrder(Order order); + + /** + * 删除订单列表 + * + * @param id 订单列表主键 + * @return 结果 + */ + public int deleteOrderById(Long id); + + /** + * 批量删除订单列表 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteOrderByIds(Long[] ids); + + /** + * 批量删除订单商品列表 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteOrderItemByOrderIds(Long[] ids); + + /** + * 批量新增订单商品列表 + * + * @param orderItemList 订单商品列表列表 + * @return 结果 + */ + public int batchOrderItem(List orderItemList); + + + /** + * 通过订单列表主键删除订单商品列表信息 + * + * @param id 订单列表ID + * @return 结果 + */ + public int deleteOrderItemByOrderId(Long id); +} diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/service/IOrderService.java b/ruoyi-core/src/main/java/com/ruoyi/system/service/IOrderService.java new file mode 100644 index 0000000..313496d --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/service/IOrderService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.Order; + +/** + * 订单列表Service接口 + * + * @author ruoyi + * @date 2024-11-10 + */ +public interface IOrderService +{ + /** + * 查询订单列表 + * + * @param id 订单列表主键 + * @return 订单列表 + */ + public Order selectOrderById(Long id); + + /** + * 查询订单列表列表 + * + * @param order 订单列表 + * @return 订单列表集合 + */ + public List selectOrderList(Order order); + + /** + * 新增订单列表 + * + * @param order 订单列表 + * @return 结果 + */ + public int insertOrder(Order order); + + /** + * 修改订单列表 + * + * @param order 订单列表 + * @return 结果 + */ + public int updateOrder(Order order); + + /** + * 批量删除订单列表 + * + * @param ids 需要删除的订单列表主键集合 + * @return 结果 + */ + public int deleteOrderByIds(Long[] ids); + + /** + * 删除订单列表信息 + * + * @param id 订单列表主键 + * @return 结果 + */ + public int deleteOrderById(Long id); +} diff --git a/ruoyi-core/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java b/ruoyi-core/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java new file mode 100644 index 0000000..110028e --- /dev/null +++ b/ruoyi-core/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java @@ -0,0 +1,131 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import java.util.ArrayList; +import com.ruoyi.common.utils.StringUtils; +import org.springframework.transaction.annotation.Transactional; +import com.ruoyi.system.domain.OrderItem; +import com.ruoyi.system.mapper.OrderMapper; +import com.ruoyi.system.domain.Order; +import com.ruoyi.system.service.IOrderService; + +/** + * 订单列表Service业务层处理 + * + * @author ruoyi + * @date 2024-11-10 + */ +@Service +public class OrderServiceImpl implements IOrderService +{ + @Autowired + private OrderMapper orderMapper; + + /** + * 查询订单列表 + * + * @param id 订单列表主键 + * @return 订单列表 + */ + @Override + public Order selectOrderById(Long id) + { + return orderMapper.selectOrderById(id); + } + + /** + * 查询订单列表列表 + * + * @param order 订单列表 + * @return 订单列表 + */ + @Override + public List selectOrderList(Order order) + { + return orderMapper.selectOrderList(order); + } + + /** + * 新增订单列表 + * + * @param order 订单列表 + * @return 结果 + */ + @Transactional + @Override + public int insertOrder(Order order) + { + int rows = orderMapper.insertOrder(order); + insertOrderItem(order); + return rows; + } + + /** + * 修改订单列表 + * + * @param order 订单列表 + * @return 结果 + */ + @Transactional + @Override + public int updateOrder(Order order) + { + orderMapper.deleteOrderItemByOrderId(order.getId()); + insertOrderItem(order); + return orderMapper.updateOrder(order); + } + + /** + * 批量删除订单列表 + * + * @param ids 需要删除的订单列表主键 + * @return 结果 + */ + @Transactional + @Override + public int deleteOrderByIds(Long[] ids) + { + orderMapper.deleteOrderItemByOrderIds(ids); + return orderMapper.deleteOrderByIds(ids); + } + + /** + * 删除订单列表信息 + * + * @param id 订单列表主键 + * @return 结果 + */ + @Transactional + @Override + public int deleteOrderById(Long id) + { + orderMapper.deleteOrderItemByOrderId(id); + return orderMapper.deleteOrderById(id); + } + + /** + * 新增订单商品列表信息 + * + * @param order 订单列表对象 + */ + public void insertOrderItem(Order order) + { + List orderItemList = order.getOrderItemList(); + Long id = order.getId(); + if (StringUtils.isNotNull(orderItemList)) + { + List list = new ArrayList(); + for (OrderItem orderItem : orderItemList) + { + orderItem.setOrderId(id); + list.add(orderItem); + } + if (list.size() > 0) + { + orderMapper.batchOrderItem(list); + } + } + } +} diff --git a/ruoyi-core/src/main/resources/mapper/system/OrderMapper.xml b/ruoyi-core/src/main/resources/mapper/system/OrderMapper.xml new file mode 100644 index 0000000..d887e83 --- /dev/null +++ b/ruoyi-core/src/main/resources/mapper/system/OrderMapper.xml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select id, uid, time, pirce, name, company, country, city, steet1, steet2, postal, phone, email, note from db_order + + + + + + + + + + insert into db_order + + uid, + time, + pirce, + name, + company, + country, + city, + steet1, + steet2, + postal, + phone, + email, + note, + + + #{uid}, + #{time}, + #{pirce}, + #{name}, + #{company}, + #{country}, + #{city}, + #{steet1}, + #{steet2}, + #{postal}, + #{phone}, + #{email}, + #{note}, + + + + + update db_order + + uid = #{uid}, + time = #{time}, + pirce = #{pirce}, + name = #{name}, + company = #{company}, + country = #{country}, + city = #{city}, + steet1 = #{steet1}, + steet2 = #{steet2}, + postal = #{postal}, + phone = #{phone}, + email = #{email}, + note = #{note}, + + where id = #{id} + + + + delete from db_order where id = #{id} + + + + delete from db_order where id in + + #{id} + + + + + delete from db_order_item where order_id in + + #{orderId} + + + + + delete from db_order_item where order_id = #{orderId} + + + + insert into db_order_item( id, order_id, title, price, count) values + + ( #{item.id}, #{item.orderId}, #{item.title}, #{item.price}, #{item.count}) + + + \ No newline at end of file