Files
wb-java-nc-shop/target/classes/mapper/InventoryMapper.xml
2026-01-11 18:14:42 +08:00

56 lines
2.3 KiB
XML

<?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.nlshop.mapper.InventoryMapper">
<resultMap id="BaseResultMap" type="com.nlshop.entity.Inventory">
<id column="id" property="id"/>
<result column="merchant_id" property="merchantId"/>
<result column="material_name" property="materialName"/>
<result column="quantity" property="quantity"/>
<result column="unit" property="unit"/>
<result column="min_threshold" property="minThreshold"/>
<result column="last_in_time" property="lastInTime"/>
<result column="last_out_time" property="lastOutTime"/>
</resultMap>
<insert id="insert" parameterType="com.nlshop.entity.Inventory" useGeneratedKeys="true" keyProperty="id">
INSERT INTO inventory (merchant_id, material_name, quantity, unit, min_threshold)
VALUES (#{merchantId}, #{materialName}, #{quantity}, #{unit}, #{minThreshold})
</insert>
<select id="selectByMerchantId" resultMap="BaseResultMap">
SELECT * FROM inventory WHERE merchant_id = #{merchantId} ORDER BY material_name
</select>
<select id="selectById" resultMap="BaseResultMap">
SELECT * FROM inventory WHERE id = #{id}
</select>
<select id="selectByMerchantAndMaterial" resultMap="BaseResultMap">
SELECT * FROM inventory
WHERE merchant_id = #{merchantId} AND material_name = #{materialName}
LIMIT 1
</select>
<select id="selectLowStock" resultMap="BaseResultMap">
SELECT * FROM inventory
WHERE merchant_id = #{merchantId} AND quantity &lt;= min_threshold
ORDER BY quantity ASC
</select>
<update id="update" parameterType="com.nlshop.entity.Inventory">
UPDATE inventory
<set>
<if test="quantity != null">quantity = #{quantity},</if>
<if test="unit != null">unit = #{unit},</if>
<if test="minThreshold != null">min_threshold = #{minThreshold},</if>
<if test="lastInTime != null">last_in_time = #{lastInTime},</if>
<if test="lastOutTime != null">last_out_time = #{lastOutTime},</if>
</set>
WHERE id = #{id}
</update>
<delete id="delete">
DELETE FROM inventory WHERE id = #{id}
</delete>
</mapper>