You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
4.9 KiB
114 lines
4.9 KiB
<?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.example.mapper.OrdersMapper">
|
|
|
|
<!-- 定义订单表基础字段列表 -->
|
|
<sql id="Base_Column_List">
|
|
id,user_id,business_id,goods_id,num,price,address_id,status,order_id
|
|
</sql>
|
|
|
|
<!-- 查询所有订单(关联查询商家、商品和地址信息) -->
|
|
<select id="selectAll" resultType="com.example.entity.Orders">
|
|
select orders.*,
|
|
business.name as businessName, <!-- 商家名称 -->
|
|
goods.img as goodsImg, <!-- 商品图片 -->
|
|
goods.name as goodsName, <!-- 商品名称 -->
|
|
goods.price as goodsPrice, <!-- 商品单价 -->
|
|
goods.unit as goodsUnit, <!-- 商品单位 -->
|
|
address.username as username, <!-- 收货人姓名 -->
|
|
address.useraddress as useraddress, <!-- 收货地址 -->
|
|
address.phone as phone <!-- 收货人电话 -->
|
|
from orders
|
|
left join business on orders.business_id = business.id <!-- 关联商家表 -->
|
|
left join goods on orders.goods_id = goods.id <!-- 关联商品表 -->
|
|
left join address on orders.address_id = address.id <!-- 关联地址表 -->
|
|
<where>
|
|
<if test="id != null"> and id= #{id}</if>
|
|
<if test="userId != null"> and orders.user_id = #{userId}</if>
|
|
<if test="businessId != null"> and orders.business_id = #{businessId}</if>
|
|
<if test="goodsId != null"> and goods_id = #{goodsId}</if>
|
|
<if test="num != null"> and num = #{num}</if> <!-- 购买数量 -->
|
|
<if test="price != null"> and price = #{price}</if> <!-- 订单金额 -->
|
|
<if test="addressId != null"> and address_id = #{addressId}</if>
|
|
<if test="status != null"> and status = #{status}</if> <!-- 订单状态 -->
|
|
<if test="orderId != null"> and order_id = #{orderId}</if> <!-- 订单编号 -->
|
|
</where>
|
|
</select>
|
|
|
|
<!-- 根据ID查询单个订单 -->
|
|
<select id="selectById" resultType="com.example.entity.Orders">
|
|
select
|
|
<include refid="Base_Column_List" />
|
|
from orders
|
|
where id = #{id}
|
|
</select>
|
|
|
|
<!-- 根据ID删除订单 -->
|
|
<delete id="deleteById">
|
|
delete from orders
|
|
where id = #{id}
|
|
</delete>
|
|
|
|
<!-- 新增订单 -->
|
|
<insert id="insert" parameterType="com.example.entity.Orders" useGeneratedKeys="true">
|
|
insert into orders
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
<if test="id != null">id,</if>
|
|
<if test="userId != null">user_id,</if>
|
|
<if test="businessId != null">business_id,</if>
|
|
<if test="goodsId != null">goods_id,</if>
|
|
<if test="num != null">num,</if>
|
|
<if test="price != null">price,</if>
|
|
<if test="addressId != null">address_id,</if>
|
|
<if test="status != null">status,</if>
|
|
<if test="orderId != null">order_id,</if>
|
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
<if test="id != null">#{id},</if>
|
|
<if test="userId != null">#{userId},</if>
|
|
<if test="businessId != null">#{businessId},</if>
|
|
<if test="goodsId != null">#{goodsId},</if>
|
|
<if test="num != null">#{num},</if>
|
|
<if test="price != null">#{price},</if>
|
|
<if test="addressId != null">#{addressId},</if>
|
|
<if test="status != null">#{status},</if>
|
|
<if test="orderId != null">#{orderId},</if>
|
|
</trim>
|
|
</insert>
|
|
|
|
<!-- 根据ID修改订单信息 -->
|
|
<update id="updateById" parameterType="com.example.entity.Orders">
|
|
update orders
|
|
<set>
|
|
<if test="userId != null">
|
|
user_id = #{userId}, <!-- 用户ID -->
|
|
</if>
|
|
<if test="businessId != null">
|
|
business_id = #{businessId}, <!-- 商家ID -->
|
|
</if>
|
|
<if test="goodsId != null">
|
|
goods_id = #{goodsId}, <!-- 商品ID -->
|
|
</if>
|
|
<if test="num != null">
|
|
num = #{num}, <!-- 购买数量 -->
|
|
</if>
|
|
<if test="price != null">
|
|
price = #{price}, <!-- 订单金额 -->
|
|
</if>
|
|
<if test="addressId != null">
|
|
address_id = #{addressId}, <!-- 地址ID -->
|
|
</if>
|
|
<if test="status != null">
|
|
status = #{status}, <!-- 订单状态 -->
|
|
</if>
|
|
<if test="orderId != null">
|
|
order_id = #{orderId}, <!-- 订单编号 -->
|
|
</if>
|
|
</set>
|
|
where id = #{id}
|
|
</update>
|
|
|
|
</mapper> |