IMProductStatMapper.xml
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?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.sibu.orderHelper.integral.web.dao.IMWebProductStatDao">
<resultMap type="com.sibu.orderHelper.vo.ProductSaleBean" id="productSaleBean">
<result column="name" property="productName"></result>
<result column="erp_code" property="erpCode"></result>
<result column="cost1" property="cost1"></result>
<result column="cost2" property="cost2"></result>
<result column="num" property="num"></result>
<result column="integral" property="integral" jdbcType="INTEGER"></result>
<result column="price" property="price" jdbcType="DOUBLE"></result>
</resultMap>
<!-- 查询erpCodo数据 -->
<select id="selectProductErpCodes" resultType="java.lang.String" parameterType="java.util.Map">
select erp_code from im_product imp left join im_product_inventory inventory
on imp.im_product_id =inventory.im_product_id
where imp.delete_flag = 1 and imp.erp_code !='0' and imp.erp_code is not null
<if test="categoryId !=null and categoryId!=''">
and (imp.im_category_id =#{categoryId} or
imp.im_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId}))
</if>
<if test="keyword != null and keyword !=''">
and imp.name like concat('%',#{keyword},'%')
</if>
<if test="erpCode != null and erpCode !=''">
and imp.erp_code like concat('%',#{erpCode},'%')
</if>
<if test="isShow != null and isShow !=''">
and imp.is_show = ${isShow}
</if>
<if test="isHot != null and isHot !=''">
and imp.is_hot = ${isHot}
</if>
group by
imp.erp_code
order by sum(inventory.cost) desc
LIMIT
${pageNow}, ${pageSize}
</select>
<select id="totalIMProduct" resultType="int" parameterType="map">
select count(1) from (
select count(1) as num from im_product imp where imp.delete_flag = 1 and imp.erp_code !='0' and imp.erp_code is not null
<if test="categoryId !=null and categoryId!=''">
and (imp.im_category_id =#{categoryId} or
imp.im_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId}))
</if>
<if test="keyword != null and keyword !=''">
and imp.name like concat('%',#{keyword},'%')
</if>
<if test="erpCode != null and erpCode !=''">
and imp.erp_code like concat('%',#{erpCode},'%')
</if>
<if test="isShow != null and isShow !=''">
and imp.is_show = ${isShow}
</if>
<if test="isHot != null and isHot !=''">
and imp.is_hot = ${isHot}
</if>
group by erp_code
) as temp
</select>
<!-- 查询商品的积分销售,现金销售,总销售量 -->
<select id="selectProductSale" resultMap="productSaleBean" parameterType="java.util.Map">
<foreach collection="erpCodes" separator="union all" item="erpCode">
SELECT n.erp_code ,n.name ,integral.cost AS 'cost1',cash.cost AS 'cost2',integral.cost+cash.cost AS 'num' , product1.integral,product2.price FROM
(SELECT erp_code ,NAME FROM im_product WHERE erp_code =#{erpCode} GROUP BY erp_code) n,
(SELECT IFNULL(SUM(inventory.cost),0) AS 'cost' FROM im_product imp
left join im_product_inventory inventory on imp.im_product_id =inventory.im_product_id
WHERE imp.product_type =0 AND imp.erp_code =#{erpCode} ) integral,
(SELECT IFNULL(SUM(inventory.cost),0) AS 'cost' FROM im_product imp
left join im_product_inventory inventory on imp.im_product_id =inventory.im_product_id
WHERE imp.product_type =1 AND imp.erp_code =#{erpCode}) cash,
(SELECT IFNULL (SUM(xws_exchange_integral),0) AS integral FROM im_product WHERE erp_code =#{erpCode} AND product_type =0) AS product1,
(SELECT IFNULL (SUM(retail_price),0) AS price FROM im_product WHERE erp_code =#{erpCode} AND product_type =1 ) AS product2
</foreach>
</select>
</mapper>