|
|
<?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="cn.iocoder.yudao.module.product.dal.mysql.inputsbuy.InputsBuyMapper">
|
|
|
|
|
|
<!--
|
|
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
|
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
|
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
|
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
|
|
-->
|
|
|
|
|
|
<resultMap id="queryInputsBuyPageMap" type="cn.iocoder.yudao.module.product.controller.admin.inputsbuy.vo.InputsBuyRespVO">
|
|
|
<association property="blockState" column="inputsBuyId=inputs_buy_id" select="queryBlockState"></association>
|
|
|
</resultMap>
|
|
|
<select id="selectInputsBuyPage" resultMap="queryInputsBuyPageMap">
|
|
|
SELECT * FROM product_inputs_buy
|
|
|
<where>
|
|
|
deleted = 0
|
|
|
<if test="pageReqVO.inputsBuyId != null and pageReqVO.inputsBuyId != ''">
|
|
|
and inputs_buy_id like concat('%',#{pageReqVO.inputsBuyId},'%') ESCAPE '/'
|
|
|
</if>
|
|
|
<if test="pageReqVO.relateOutboundId != null and pageReqVO.relateOutboundId != ''">
|
|
|
and relate_outbound_id like concat('%',#{pageReqVO.relateOutboundId},'%') ESCAPE '/'
|
|
|
</if>
|
|
|
<if test="pageReqVO.vendorName != null and pageReqVO.vendorName != ''">
|
|
|
and vendor_name like concat('%',#{pageReqVO.vendorName},'%') ESCAPE '/'
|
|
|
</if>
|
|
|
<if test="pageReqVO.inputsBuyTime != null and pageReqVO.inputsBuyTime.length == 2">
|
|
|
and unix_timestamp(inputs_buy_time) between unix_timestamp(#{pageReqVO.inputsBuyTime[0]}) and unix_timestamp(#{pageReqVO.inputsBuyTime[1]})
|
|
|
</if>
|
|
|
<if test="pageReqVO.belongBusinessName != null and pageReqVO.belongBusinessName != ''">
|
|
|
and belong_business_name like concat('%',#{pageReqVO.belongBusinessName},'%') ESCAPE '/'
|
|
|
</if>
|
|
|
<if test="pageReqVO.blockState != null">
|
|
|
and block_state = #{pageReqVO.blockState}
|
|
|
</if>
|
|
|
</where>
|
|
|
</select>
|
|
|
<select id="queryBlockState" resultType="Integer">
|
|
|
SELECT block_state FROM product_inputs_batch WHERE inputs_buy_id = #{inputsBuyId} AND deleted = 0 limit 0, 1
|
|
|
</select>
|
|
|
|
|
|
<select id="getMonthYOYDatas" resultType="cn.iocoder.yudao.module.product.controller.admin.statistics.vo.MonthYOYRespVO">
|
|
|
SELECT
|
|
|
YEAR ( pib.inputs_buy_time ) year,
|
|
|
MONTH ( pib.inputs_buy_time ) month,
|
|
|
SUM( pibh.inputs_num * bii.conversion_value ) sumNum,
|
|
|
CONCAT(ifnull(round((sum( pibh.inputs_num * bii.conversion_value ) - ss )/ ss * 100, 2 ), 0 ), '%') rateData
|
|
|
FROM
|
|
|
product_inputs_buy pib
|
|
|
LEFT JOIN product_inputs_batch pibh ON pibh.inputs_buy_id = pib.inputs_buy_id
|
|
|
LEFT JOIN basic_inputs_info bii ON bii.inputs_id = pibh.inputs_id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
MONTH( pib.inputs_buy_time ) mm,
|
|
|
YEAR( pib.inputs_buy_time ) yy,
|
|
|
SUM( pibh.inputs_num * bii.conversion_value ) ss
|
|
|
FROM
|
|
|
product_inputs_buy pib
|
|
|
LEFT JOIN product_inputs_batch pibh ON pibh.inputs_buy_id = pib.inputs_buy_id
|
|
|
LEFT JOIN basic_inputs_info bii ON bii.inputs_id = pibh.inputs_id
|
|
|
WHERE pib.deleted = 0 AND pibh.deleted = 0
|
|
|
GROUP BY
|
|
|
mm, yy
|
|
|
) tongbi
|
|
|
ON MONTH ( pib.inputs_buy_time ) = tongbi.mm
|
|
|
AND tongbi.yy = YEAR ( pib.inputs_buy_time ) - 1
|
|
|
WHERE
|
|
|
YEAR(pib.inputs_buy_time) = YEAR(now()) AND pib.deleted = 0 AND pibh.deleted = 0
|
|
|
GROUP BY
|
|
|
year, month
|
|
|
ORDER BY
|
|
|
year DESC, month DESC
|
|
|
</select>
|
|
|
|
|
|
<select id="getWeekYOYDatas" resultType="cn.iocoder.yudao.module.product.controller.admin.statistics.vo.WeekYOYRespVO">
|
|
|
SELECT
|
|
|
YEAR ( pib.inputs_buy_time ) year,
|
|
|
MONTH ( pib.inputs_buy_time ) month,
|
|
|
WEEK ( pib.inputs_buy_time ) week,
|
|
|
sum( pibh.inputs_num * bii.conversion_value ) sumNum,
|
|
|
concat(ifnull( round(( sum( pibh.inputs_num * bii.conversion_value ) - ss )/ ss * 100, 2 ), 0 ), '%') rateData
|
|
|
FROM
|
|
|
product_inputs_buy pib
|
|
|
LEFT JOIN product_inputs_batch pibh ON pibh.inputs_buy_id = pib.inputs_buy_id
|
|
|
LEFT JOIN basic_inputs_info bii ON bii.inputs_id = pibh.inputs_id
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
MONTH( pib.inputs_buy_time ) mm,
|
|
|
YEAR( pib.inputs_buy_time ) yy,
|
|
|
WEEK( pib.inputs_buy_time ) ww,
|
|
|
sum( pibh.inputs_num * bii.conversion_value ) ss
|
|
|
FROM
|
|
|
product_inputs_buy pib
|
|
|
LEFT JOIN product_inputs_batch pibh ON pibh.inputs_buy_id = pib.inputs_buy_id
|
|
|
LEFT JOIN basic_inputs_info bii ON bii.inputs_id = pibh.inputs_id
|
|
|
WHERE pib.deleted = 0 AND pibh.deleted = 0
|
|
|
GROUP BY
|
|
|
mm,
|
|
|
yy,
|
|
|
ww
|
|
|
) tongbi ON MONTH ( pib.inputs_buy_time ) = tongbi.mm
|
|
|
AND WEEK ( pib.inputs_buy_time ) = tongbi.ww
|
|
|
AND tongbi.yy = YEAR ( pib.inputs_buy_time ) - 1
|
|
|
WHERE
|
|
|
YEAR(pib.inputs_buy_time) = YEAR(now()) AND pib.deleted = 0 AND pibh.deleted = 0
|
|
|
GROUP BY
|
|
|
year, month, week
|
|
|
ORDER BY
|
|
|
year DESC, month DESC, week DESC
|
|
|
</select>
|
|
|
|
|
|
<select id="getDatasGroupByGoodsId" resultType="cn.iocoder.yudao.module.product.controller.admin.statistics.vo.InputsStatisticsDataRespVO">
|
|
|
SELECT
|
|
|
pibh.inputs_id,
|
|
|
bii.inputs_name,
|
|
|
SUM( pibh.inputs_num ) sumNum
|
|
|
FROM
|
|
|
product_inputs_buy pib
|
|
|
LEFT JOIN product_inputs_batch pibh ON pibh.inputs_buy_id = pib.inputs_buy_id
|
|
|
LEFT JOIN basic_inputs_info bii ON bii.inputs_id = pibh.inputs_id
|
|
|
WHERE
|
|
|
pib.deleted = 0 AND pibh.deleted = 0
|
|
|
<if test="type = 'month'">
|
|
|
AND MONTH ( pib.inputs_buy_time ) = MONTH (NOW())
|
|
|
</if>
|
|
|
<if test="type = 'month'">
|
|
|
AND WEEK ( pib.inputs_buy_time ) = WEEK (NOW())
|
|
|
</if>
|
|
|
GROUP BY
|
|
|
pibh.inputs_id
|
|
|
</select>
|
|
|
|
|
|
<select id="getTodayInputBuyCount" resultType="BigDecimal">
|
|
|
SELECT
|
|
|
IFNULL(SUM( inputs_num ), 0)
|
|
|
FROM
|
|
|
product_inputs_buy pib
|
|
|
LEFT JOIN product_inputs_batch pibh ON pibh.inputs_buy_id = pib.inputs_buy_id
|
|
|
WHERE
|
|
|
pib.deleted = 0
|
|
|
AND pibh.deleted = 0
|
|
|
AND TO_DAYS(pib.inputs_buy_time) = TO_DAYS(NOW())
|
|
|
</select>
|
|
|
</mapper>
|