完成订单提交相关接口
This commit is contained in:
parent
f592d3f457
commit
c56befe516
@ -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<Order> 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<Order> list = orderService.selectOrderList(order);
|
||||||
|
ExcelUtil<Order> util = new ExcelUtil<Order>(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<CartItem> items = cartItemService.selectCartItemListById(SecurityUtils.getUserId());
|
||||||
|
List<OrderItem> 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));
|
||||||
|
}
|
||||||
|
}
|
237
ruoyi-core/src/main/java/com/ruoyi/system/domain/Order.java
Normal file
237
ruoyi-core/src/main/java/com/ruoyi/system/domain/Order.java
Normal file
@ -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<OrderItem> 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<OrderItem> getOrderItemList()
|
||||||
|
{
|
||||||
|
return orderItemList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrderItemList(List<OrderItem> 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();
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -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<Order> 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<OrderItem> orderItemList);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过订单列表主键删除订单商品列表信息
|
||||||
|
*
|
||||||
|
* @param id 订单列表ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteOrderItemByOrderId(Long id);
|
||||||
|
}
|
@ -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<Order> 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);
|
||||||
|
}
|
@ -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<Order> 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<OrderItem> orderItemList = order.getOrderItemList();
|
||||||
|
Long id = order.getId();
|
||||||
|
if (StringUtils.isNotNull(orderItemList))
|
||||||
|
{
|
||||||
|
List<OrderItem> list = new ArrayList<OrderItem>();
|
||||||
|
for (OrderItem orderItem : orderItemList)
|
||||||
|
{
|
||||||
|
orderItem.setOrderId(id);
|
||||||
|
list.add(orderItem);
|
||||||
|
}
|
||||||
|
if (list.size() > 0)
|
||||||
|
{
|
||||||
|
orderMapper.batchOrderItem(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
153
ruoyi-core/src/main/resources/mapper/system/OrderMapper.xml
Normal file
153
ruoyi-core/src/main/resources/mapper/system/OrderMapper.xml
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ruoyi.system.mapper.OrderMapper">
|
||||||
|
|
||||||
|
<resultMap type="Order" id="OrderResult">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="uid" column="uid" />
|
||||||
|
<result property="time" column="time" />
|
||||||
|
<result property="pirce" column="pirce" />
|
||||||
|
<result property="name" column="name" />
|
||||||
|
<result property="company" column="company" />
|
||||||
|
<result property="country" column="country" />
|
||||||
|
<result property="city" column="city" />
|
||||||
|
<result property="steet1" column="steet1" />
|
||||||
|
<result property="steet2" column="steet2" />
|
||||||
|
<result property="postal" column="postal" />
|
||||||
|
<result property="phone" column="phone" />
|
||||||
|
<result property="email" column="email" />
|
||||||
|
<result property="note" column="note" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<resultMap id="OrderOrderItemResult" type="Order" extends="OrderResult">
|
||||||
|
<collection property="orderItemList" ofType="OrderItem" column="id" select="selectOrderItemList" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<resultMap type="OrderItem" id="OrderItemResult">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="orderId" column="order_id" />
|
||||||
|
<result property="title" column="title" />
|
||||||
|
<result property="price" column="price" />
|
||||||
|
<result property="count" column="count" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectOrderVo">
|
||||||
|
select id, uid, time, pirce, name, company, country, city, steet1, steet2, postal, phone, email, note from db_order
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectOrderList" parameterType="Order" resultMap="OrderResult">
|
||||||
|
<include refid="selectOrderVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="uid != null "> and uid = #{uid}</if>
|
||||||
|
<if test="time != null "> and time = #{time}</if>
|
||||||
|
<if test="pirce != null "> and pirce = #{pirce}</if>
|
||||||
|
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
||||||
|
<if test="company != null and company != ''"> and company = #{company}</if>
|
||||||
|
<if test="country != null and country != ''"> and country = #{country}</if>
|
||||||
|
<if test="city != null and city != ''"> and city = #{city}</if>
|
||||||
|
<if test="steet1 != null and steet1 != ''"> and steet1 = #{steet1}</if>
|
||||||
|
<if test="steet2 != null and steet2 != ''"> and steet2 = #{steet2}</if>
|
||||||
|
<if test="postal != null and postal != ''"> and postal = #{postal}</if>
|
||||||
|
<if test="phone != null and phone != ''"> and phone = #{phone}</if>
|
||||||
|
<if test="email != null and email != ''"> and email = #{email}</if>
|
||||||
|
<if test="note != null and note != ''"> and note = #{note}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectOrderById" parameterType="Long" resultMap="OrderOrderItemResult">
|
||||||
|
select id, uid, time, pirce, name, company, country, city, steet1, steet2, postal, phone, email, note
|
||||||
|
from db_order
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectOrderItemList" resultMap="OrderItemResult">
|
||||||
|
select id, order_id, title, price, count
|
||||||
|
from db_order_item
|
||||||
|
where order_id = #{order_id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertOrder" parameterType="Order" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into db_order
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="uid != null">uid,</if>
|
||||||
|
<if test="time != null">time,</if>
|
||||||
|
<if test="pirce != null">pirce,</if>
|
||||||
|
<if test="name != null">name,</if>
|
||||||
|
<if test="company != null">company,</if>
|
||||||
|
<if test="country != null">country,</if>
|
||||||
|
<if test="city != null">city,</if>
|
||||||
|
<if test="steet1 != null">steet1,</if>
|
||||||
|
<if test="steet2 != null">steet2,</if>
|
||||||
|
<if test="postal != null">postal,</if>
|
||||||
|
<if test="phone != null">phone,</if>
|
||||||
|
<if test="email != null">email,</if>
|
||||||
|
<if test="note != null">note,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="uid != null">#{uid},</if>
|
||||||
|
<if test="time != null">#{time},</if>
|
||||||
|
<if test="pirce != null">#{pirce},</if>
|
||||||
|
<if test="name != null">#{name},</if>
|
||||||
|
<if test="company != null">#{company},</if>
|
||||||
|
<if test="country != null">#{country},</if>
|
||||||
|
<if test="city != null">#{city},</if>
|
||||||
|
<if test="steet1 != null">#{steet1},</if>
|
||||||
|
<if test="steet2 != null">#{steet2},</if>
|
||||||
|
<if test="postal != null">#{postal},</if>
|
||||||
|
<if test="phone != null">#{phone},</if>
|
||||||
|
<if test="email != null">#{email},</if>
|
||||||
|
<if test="note != null">#{note},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateOrder" parameterType="Order">
|
||||||
|
update db_order
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="uid != null">uid = #{uid},</if>
|
||||||
|
<if test="time != null">time = #{time},</if>
|
||||||
|
<if test="pirce != null">pirce = #{pirce},</if>
|
||||||
|
<if test="name != null">name = #{name},</if>
|
||||||
|
<if test="company != null">company = #{company},</if>
|
||||||
|
<if test="country != null">country = #{country},</if>
|
||||||
|
<if test="city != null">city = #{city},</if>
|
||||||
|
<if test="steet1 != null">steet1 = #{steet1},</if>
|
||||||
|
<if test="steet2 != null">steet2 = #{steet2},</if>
|
||||||
|
<if test="postal != null">postal = #{postal},</if>
|
||||||
|
<if test="phone != null">phone = #{phone},</if>
|
||||||
|
<if test="email != null">email = #{email},</if>
|
||||||
|
<if test="note != null">note = #{note},</if>
|
||||||
|
</trim>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteOrderById" parameterType="Long">
|
||||||
|
delete from db_order where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteOrderByIds" parameterType="String">
|
||||||
|
delete from db_order where id in
|
||||||
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteOrderItemByOrderIds" parameterType="String">
|
||||||
|
delete from db_order_item where order_id in
|
||||||
|
<foreach item="orderId" collection="array" open="(" separator="," close=")">
|
||||||
|
#{orderId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteOrderItemByOrderId" parameterType="Long">
|
||||||
|
delete from db_order_item where order_id = #{orderId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<insert id="batchOrderItem">
|
||||||
|
insert into db_order_item( id, order_id, title, price, count) values
|
||||||
|
<foreach item="item" index="index" collection="list" separator=",">
|
||||||
|
( #{item.id}, #{item.orderId}, #{item.title}, #{item.price}, #{item.count})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user