库存汇总查询
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?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.search.StockSummary.mapper.StockSummaryMapper">
|
||||
|
||||
<resultMap type="StockSummary" id="StockSummaryResult">
|
||||
<result property="onlyIdentity" column="only_identity" />
|
||||
<result property="productId" column="product_id" />
|
||||
<result property="productName" column="product_name" />
|
||||
<result property="spec" column="spec" />
|
||||
<result property="unit" column="unit" />
|
||||
<result property="lotNo" column="lot_no" />
|
||||
<result property="warehouseId" column="warehouse_id" />
|
||||
<result property="roadwayId" column="roadway_id" />
|
||||
<result property="quantity" column="quantity" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectStockSummaryVo">
|
||||
SELECT
|
||||
<choose>
|
||||
<when test="groupByProductId != null and groupByProductId or groupByProductName != null and groupByProductName or groupBySpec != null and groupBySpec or groupByUnit != null and groupByUnit or groupByLotNo != null and groupByLotNo or groupByWarehouseId != null and groupByWarehouseId or groupByRoadwayId != null and groupByRoadwayId">
|
||||
<if test="groupByProductId != null and groupByProductId">p.product_id,</if>
|
||||
<if test="groupByProductName != null and groupByProductName">p.product_name,</if>
|
||||
<if test="groupBySpec != null and groupBySpec">p.spec,</if>
|
||||
<if test="groupByUnit != null and groupByUnit">p.unit,</if>
|
||||
<if test="groupByLotNo != null and groupByLotNo">s.lot_no,</if>
|
||||
<if test="groupByWarehouseId != null and groupByWarehouseId">s.warehouse_id,</if>
|
||||
<if test="groupByRoadwayId != null and groupByRoadwayId">s.cargo_space_id as roadway_id,</if>
|
||||
SUM(CAST(s.quantity AS DECIMAL(18,2))) as quantity
|
||||
FROM bas_stock s
|
||||
LEFT JOIN bas_product p ON s.product_guid = p.product_guid
|
||||
GROUP BY
|
||||
<trim prefixOverrides=",">
|
||||
<if test="groupByProductId != null and groupByProductId">,p.product_id</if>
|
||||
<if test="groupByProductName != null and groupByProductName">,p.product_name</if>
|
||||
<if test="groupBySpec != null and groupBySpec">,p.spec</if>
|
||||
<if test="groupByUnit != null and groupByUnit">,p.unit</if>
|
||||
<if test="groupByLotNo != null and groupByLotNo">,s.lot_no</if>
|
||||
<if test="groupByWarehouseId != null and groupByWarehouseId">,s.warehouse_id</if>
|
||||
<if test="groupByRoadwayId != null and groupByRoadwayId">,s.cargo_space_id</if>
|
||||
</trim>
|
||||
</when>
|
||||
<otherwise>
|
||||
1 as group_all,
|
||||
SUM(CAST(s.quantity AS DECIMAL(18,2))) as quantity
|
||||
FROM bas_stock s
|
||||
LEFT JOIN bas_product p ON s.product_guid = p.product_guid
|
||||
</otherwise>
|
||||
</choose>
|
||||
</sql>
|
||||
|
||||
<select id="selectStockSummaryList" parameterType="StockSummary" resultMap="StockSummaryResult">
|
||||
<include refid="selectStockSummaryVo"/>
|
||||
<where>
|
||||
<if test="productId != null and productId != ''"> AND p.product_id = #{productId}</if>
|
||||
<if test="productName != null and productName != ''"> AND p.product_name like concat('%', #{productName}, '%')</if>
|
||||
<if test="spec != null and spec != ''"> AND p.spec = #{spec}</if>
|
||||
<if test="unit != null and unit != ''"> AND p.unit = #{unit}</if>
|
||||
<if test="lotNo != null and lotNo != ''"> AND s.lot_no = #{lotNo}</if>
|
||||
<if test="warehouseId != null and warehouseId != ''"> AND s.warehouse_id = #{warehouseId}</if>
|
||||
<if test="roadwayId != null and roadwayId != ''"> AND s.cargo_space_id = #{roadwayId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectStockSummaryByOnlyIdentity" parameterType="Long" resultMap="StockSummaryResult">
|
||||
<include refid="selectStockSummaryVo"/>
|
||||
where only_identity = #{onlyIdentity}
|
||||
</select>
|
||||
|
||||
<insert id="insertStockSummary" parameterType="StockSummary">
|
||||
insert into stock_summary
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="onlyIdentity != null">only_identity,</if>
|
||||
<if test="productId != null and productId != ''">product_id,</if>
|
||||
<if test="productName != null">product_name,</if>
|
||||
<if test="spec != null">spec,</if>
|
||||
<if test="unit != null">unit,</if>
|
||||
<if test="lotNo != null">lot_no,</if>
|
||||
<if test="warehouseId != null">warehouse_id,</if>
|
||||
<if test="roadwayId != null">roadway_id,</if>
|
||||
<if test="quantity != null">quantity,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="onlyIdentity != null">#{onlyIdentity},</if>
|
||||
<if test="productId != null and productId != ''">#{productId},</if>
|
||||
<if test="productName != null">#{productName},</if>
|
||||
<if test="spec != null">#{spec},</if>
|
||||
<if test="unit != null">#{unit},</if>
|
||||
<if test="lotNo != null">#{lotNo},</if>
|
||||
<if test="warehouseId != null">#{warehouseId},</if>
|
||||
<if test="roadwayId != null">#{roadwayId},</if>
|
||||
<if test="quantity != null">#{quantity},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateStockSummary" parameterType="StockSummary">
|
||||
update stock_summary
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="productId != null and productId != ''">product_id = #{productId},</if>
|
||||
<if test="productName != null">product_name = #{productName},</if>
|
||||
<if test="spec != null">spec = #{spec},</if>
|
||||
<if test="unit != null">unit = #{unit},</if>
|
||||
<if test="lotNo != null">lot_no = #{lotNo},</if>
|
||||
<if test="warehouseId != null">warehouse_id = #{warehouseId},</if>
|
||||
<if test="roadwayId != null">roadway_id = #{roadwayId},</if>
|
||||
<if test="quantity != null">quantity = #{quantity},</if>
|
||||
</trim>
|
||||
where only_identity = #{onlyIdentity}
|
||||
</update>
|
||||
|
||||
<delete id="deleteStockSummaryByOnlyIdentity" parameterType="Long">
|
||||
delete from stock_summary where only_identity = #{onlyIdentity}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteStockSummaryByOnlyIdentitys" parameterType="String">
|
||||
delete from stock_summary where only_identity in
|
||||
<foreach item="onlyIdentity" collection="array" open="(" separator="," close=")">
|
||||
#{onlyIdentity}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user