<?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.matrix.system.hive.dao.SysBusinessDataDao">
|
<!-- 定义SysBusinessData 的复杂关联map -->
|
<resultMap type="com.matrix.system.hive.bean.SysBusinessData" id="SysBusinessDataMap">
|
<id property="id" column="id"/>
|
<result property="createBy" column="create_by"/>
|
<result property="createTime" column="create_time"/>
|
<result property="updateBy" column="update_by"/>
|
<result property="updateTime" column="update_time"/>
|
<result property="time" column="time"/>
|
<result property="companyId" column="company_id"/>
|
<result property="shopId" column="shop_id"/>
|
<result property="name" column="name"/>
|
<result property="value" column="value"/>
|
<result property="code" column="code"/>
|
<result property="sequence" column="sequence"/>
|
<result property="dataType" column="data_type"/>
|
<result property="t1" column="t1"/>
|
<result property="t2" column="t2"/>
|
<result property="t3" column="t3"/>
|
<result property="t4" column="t4"/>
|
<result property="t5" column="t5"/>
|
<result property="t6" column="t6"/>
|
<result property="t7" column="t7"/>
|
<result property="t8" column="t8"/>
|
<result property="t9" column="t9"/>
|
<result property="t10" column="t10"/>
|
<result property="t11" column="t11"/>
|
<result property="t12" column="t12"/>
|
<result property="t13" column="t13"/>
|
<result property="t14" column="t14"/>
|
<result property="t15" column="t15"/>
|
</resultMap>
|
|
|
<!-- 定义SysBusinessData 的简单map ,本map不添加其他的关联属性 -->
|
<resultMap type="com.matrix.system.hive.bean.SysBusinessData" id="SysBusinessDataSimpleMap">
|
<id property="id" column="id"/>
|
<result property="createBy" column="create_by"/>
|
<result property="createTime" column="create_time"/>
|
<result property="updateBy" column="update_by"/>
|
<result property="updateTime" column="update_time"/>
|
<result property="time" column="time"/>
|
<result property="companyId" column="company_id"/>
|
<result property="shopId" column="shop_id"/>
|
<result property="name" column="name"/>
|
<result property="value" column="value"/>
|
<result property="code" column="code"/>
|
<result property="sequence" column="sequence"/>
|
<result property="dataType" column="data_type"/>
|
<result property="t1" column="t1"/>
|
<result property="t2" column="t2"/>
|
<result property="t3" column="t3"/>
|
<result property="t4" column="t4"/>
|
<result property="t5" column="t5"/>
|
<result property="t6" column="t6"/>
|
<result property="t7" column="t7"/>
|
<result property="t8" column="t8"/>
|
<result property="t9" column="t9"/>
|
<result property="t10" column="t10"/>
|
<result property="t11" column="t11"/>
|
<result property="t12" column="t12"/>
|
<result property="t13" column="t13"/>
|
<result property="t14" column="t14"/>
|
<result property="t15" column="t15"/>
|
</resultMap>
|
|
<!-- 字段sql -->
|
<sql id="columns">
|
create_by,
|
create_time,
|
update_by,
|
update_time,
|
id,
|
time,
|
company_id,
|
shop_id,
|
name,
|
value,
|
code,
|
sequence,
|
data_type,
|
t1,
|
t2,
|
t3,
|
t4,
|
t5,
|
t6,
|
t7,
|
t8,
|
t9,
|
t10,
|
t11,
|
t12,
|
t13,
|
t14,
|
t15
|
</sql>
|
|
<!-- 属性sql -->
|
<sql id="propertys">
|
#{item.createBy},
|
now(),
|
#{item.updateBy},
|
now(),
|
#{item.id},
|
#{item.time},
|
#{item.companyId},
|
#{item.shopId},
|
#{item.name},
|
#{item.value},
|
#{item.code},
|
#{item.sequence},
|
#{item.dataType},
|
#{item.t1},
|
#{item.t2},
|
#{item.t3},
|
#{item.t4},
|
#{item.t5},
|
#{item.t6},
|
#{item.t7},
|
#{item.t8},
|
#{item.t9},
|
#{item.t10},
|
#{item.t11},
|
#{item.t12},
|
#{item.t13},
|
#{item.t14},
|
#{item.t15}
|
</sql>
|
|
<!-- where sql -->
|
<sql id="where_sql">
|
|
<if test="record!=null">
|
<if test="(record.id!=null and record.id!='') or (record.id!='' and record.id==0) ">
|
and id = #{record.id}
|
</if>
|
<if test="record.time!=null ">
|
and to_days(time) = to_days(#{record.time})
|
</if>
|
<if test="(record.companyId!=null and record.companyId!='') or (record.companyId!='' and record.companyId==0) ">
|
and company_id = #{record.companyId}
|
</if>
|
<if test="(record.shopId!=null and record.shopId!='') or (record.shopId!='' and record.shopId==0) ">
|
and shop_id = #{record.shopId}
|
</if>
|
<if test="(record.name!=null and record.name!='') or (record.name!='' and record.name==0) ">
|
and name = #{record.name}
|
</if>
|
<if test="(record.value!=null and record.value!='') or (record.value!='' and record.value==0) ">
|
and value = #{record.value}
|
</if>
|
<if test="(record.code!=null and record.code!='') or (record.code!='' and record.code==0) ">
|
and code = #{record.code}
|
</if>
|
<if test="(record.sequence!=null and record.sequence!='') or (record.sequence!='' and record.sequence==0) ">
|
and sequence = #{record.sequence}
|
</if>
|
<if test="(record.dataType!=null and record.dataType!='') or (record.dataType!='' and record.dataType==0) ">
|
and data_type = #{record.dataType}
|
</if>
|
<if test="(record.t1!=null and record.t1!='') or (record.t1!='' and record.t1==0) ">
|
and t1 = #{record.t1}
|
</if>
|
<if test="(record.t2!=null and record.t2!='') or (record.t2!='' and record.t2==0) ">
|
and t2 = #{record.t2}
|
</if>
|
<if test="(record.t3!=null and record.t3!='') or (record.t3!='' and record.t3==0) ">
|
and t3 = #{record.t3}
|
</if>
|
<if test="(record.t4!=null and record.t4!='') or (record.t4!='' and record.t4==0) ">
|
and t4 = #{record.t4}
|
</if>
|
<if test="(record.t5!=null and record.t5!='') or (record.t5!='' and record.t5==0) ">
|
and t5 = #{record.t5}
|
</if>
|
<if test="(record.t6!=null and record.t6!='') or (record.t6!='' and record.t6==0) ">
|
and t6 = #{record.t6}
|
</if>
|
<if test="(record.t7!=null and record.t7!='') or (record.t7!='' and record.t7==0) ">
|
and t7 = #{record.t7}
|
</if>
|
<if test="(record.t8!=null and record.t8!='') or (record.t8!='' and record.t8==0) ">
|
and t8 = #{record.t8}
|
</if>
|
<if test="(record.t9!=null and record.t9!='') or (record.t9!='' and record.t9==0) ">
|
and t9 = #{record.t9}
|
</if>
|
<if test="(record.t10!=null and record.t10!='') or (record.t10!='' and record.t10==0) ">
|
and t10 = #{record.t10}
|
</if>
|
<if test="(record.t11!=null and record.t11!='') or (record.t11!='' and record.t11==0) ">
|
and t11 = #{record.t11}
|
</if>
|
<if test="(record.t12!=null and record.t12!='') or (record.t12!='' and record.t12==0) ">
|
and t12 = #{record.t12}
|
</if>
|
<if test="(record.t13!=null and record.t13!='') or (record.t13!='' and record.t13==0) ">
|
and t13 = #{record.t13}
|
</if>
|
<if test="(record.t14!=null and record.t14!='') or (record.t14!='' and record.t14==0) ">
|
and t14 = #{record.t14}
|
</if>
|
<if test="(record.t15!=null and record.t15!='') or (record.t15!='' and record.t15==0) ">
|
and t15 = #{record.t15}
|
</if>
|
</if>
|
|
</sql>
|
|
<!-- 插入方法 -->
|
<insert id="insert" parameterType="com.matrix.system.hive.bean.SysBusinessData"
|
useGeneratedKeys="true" keyProperty="item.id">
|
INSERT INTO sys_business_data (
|
<include refid="columns"></include>
|
)
|
VALUES (
|
<include refid="propertys"></include>
|
)
|
</insert>
|
|
|
<!-- 批量插入 -->
|
<insert id="batchInsert" parameterType="java.util.List">
|
INSERT INTO sys_business_data (
|
<include refid="columns"></include>
|
)
|
VALUES
|
<foreach collection="list" item="item" index="index" separator=",">(
|
<include refid="propertys"></include>
|
)
|
</foreach>
|
</insert>
|
|
|
<!-- 根据Map更新 部分更新 -->
|
<update id="updateByMap" parameterType="java.util.HashMap">
|
UPDATE sys_business_data
|
<set>
|
<if test="_parameter.containsKey('time')">
|
time = #{time},
|
</if>
|
<if test="_parameter.containsKey('companyId')">
|
company_id = #{companyId},
|
</if>
|
<if test="_parameter.containsKey('shopId')">
|
shop_id = #{shopId},
|
</if>
|
<if test="_parameter.containsKey('name')">
|
name = #{name},
|
</if>
|
<if test="_parameter.containsKey('value')">
|
value = #{value},
|
</if>
|
<if test="_parameter.containsKey('code')">
|
code = #{code},
|
</if>
|
<if test="_parameter.containsKey('sequence')">
|
sequence = #{sequence},
|
</if>
|
<if test="_parameter.containsKey('dataType')">
|
data_type = #{dataType},
|
</if>
|
<if test="_parameter.containsKey('t1')">
|
t1 = #{t1},
|
</if>
|
<if test="_parameter.containsKey('t2')">
|
t2 = #{t2},
|
</if>
|
<if test="_parameter.containsKey('t3')">
|
t3 = #{t3},
|
</if>
|
<if test="_parameter.containsKey('t4')">
|
t4 = #{t4},
|
</if>
|
<if test="_parameter.containsKey('t5')">
|
t5 = #{t5},
|
</if>
|
<if test="_parameter.containsKey('t6')">
|
t6 = #{t6},
|
</if>
|
<if test="_parameter.containsKey('t7')">
|
t7 = #{t7},
|
</if>
|
<if test="_parameter.containsKey('t8')">
|
t8 = #{t8},
|
</if>
|
<if test="_parameter.containsKey('t9')">
|
t9 = #{t9},
|
</if>
|
<if test="_parameter.containsKey('t10')">
|
t10 = #{t10},
|
</if>
|
<if test="_parameter.containsKey('t11')">
|
t11 = #{t11},
|
</if>
|
<if test="_parameter.containsKey('t12')">
|
t12 = #{t12},
|
</if>
|
<if test="_parameter.containsKey('t13')">
|
t13 = #{t13},
|
</if>
|
<if test="_parameter.containsKey('t14')">
|
t14 = #{t14},
|
</if>
|
<if test="_parameter.containsKey('t15')">
|
t15 = #{t15},
|
</if>
|
</set>
|
WHERE id=#{id}
|
</update>
|
|
|
<!-- 根据对象更新 部分更新 -->
|
<update id="updateByModel" parameterType="Integer">
|
UPDATE sys_business_data
|
<set>
|
<if test="record.time != null ">
|
time = #{record.time},
|
</if>
|
<if test="record.companyId != null ">
|
company_id = #{record.companyId},
|
</if>
|
<if test="record.shopId != null ">
|
shop_id = #{record.shopId},
|
</if>
|
<if test="record.name != null and record.name != '' ">
|
name = #{record.name},
|
</if>
|
<if test="record.value != null and record.value != '' ">
|
value = #{record.value},
|
</if>
|
<if test="record.code != null and record.code != '' ">
|
code = #{record.code},
|
</if>
|
<if test="record.sequence != null ">
|
sequence = #{record.sequence},
|
</if>
|
<if test="record.dataType != null ">
|
data_type = #{record.dataType},
|
</if>
|
<if test="record.t1 != null and record.t1 != '' ">
|
t1 = #{record.t1},
|
</if>
|
<if test="record.t2 != null and record.t2 != '' ">
|
t2 = #{record.t2},
|
</if>
|
<if test="record.t3 != null and record.t3 != '' ">
|
t3 = #{record.t3},
|
</if>
|
<if test="record.t4 != null and record.t4 != '' ">
|
t4 = #{record.t4},
|
</if>
|
<if test="record.t5 != null and record.t5 != '' ">
|
t5 = #{record.t5},
|
</if>
|
<if test="record.t6 != null and record.t6 != '' ">
|
t6 = #{record.t6},
|
</if>
|
<if test="record.t7 != null and record.t7 != '' ">
|
t7 = #{record.t7},
|
</if>
|
<if test="record.t8 != null and record.t8 != '' ">
|
t8 = #{record.t8},
|
</if>
|
<if test="record.t9 != null and record.t9 != '' ">
|
t9 = #{record.t9},
|
</if>
|
<if test="record.t10 != null and record.t10 != '' ">
|
t10 = #{record.t10},
|
</if>
|
<if test="record.t11 != null and record.t11 != '' ">
|
t11 = #{record.t11},
|
</if>
|
<if test="record.t12 != null and record.t12 != '' ">
|
t12 = #{record.t12},
|
</if>
|
<if test="record.t13 != null and record.t13 != '' ">
|
t13 = #{record.t13},
|
</if>
|
<if test="record.t14 != null and record.t14 != '' ">
|
t14 = #{record.t14},
|
</if>
|
<if test="record.t15 != null and record.t15 != '' ">
|
t15 = #{record.t15},
|
</if>
|
</set>
|
WHERE id=#{record.id}
|
</update>
|
|
|
<!-- 批量删除 -->
|
<delete id="deleteByIds" parameterType="java.util.List">
|
delete from sys_business_data where id in
|
<foreach collection="list" index="index" item="item" open="("
|
separator="," close=")">
|
#{item}
|
</foreach>
|
</delete>
|
|
<!-- 根据id删除-->
|
<delete id="deleteById" parameterType="Integer">
|
DELETE FROM sys_business_data
|
where id=#{id}
|
</delete>
|
|
<!-- 根据对象删除-->
|
<delete id="deleteByModel" parameterType="com.matrix.system.hive.bean.SysBusinessData">
|
DELETE FROM sys_business_data
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</delete>
|
|
|
<!-- 分页查询 -->
|
<select id="selectInPage" resultMap="SysBusinessDataMap">
|
select
|
<include refid="columns"></include>
|
from sys_business_data
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
<if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
|
<if test="pageVo.sort !=null and pageVo.order !=null">
|
order by
|
${pageVo.sort} ${pageVo.order}
|
</if>
|
<if test="pageVo.offset >=0 and pageVo.limit >0">
|
limit
|
#{pageVo.offset},#{pageVo.limit}
|
</if>
|
</if>
|
</select>
|
|
<!-- 查询总条数 -->
|
<select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer">
|
select count(*)
|
from sys_business_data
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</select>
|
|
<!-- 根据id查询-->
|
<select id="selectById" resultMap="SysBusinessDataMap">
|
select
|
<include refid="columns"></include>
|
from sys_business_data
|
where id=#{id}
|
</select>
|
|
|
<!-- 根据id 锁表查询-->
|
<select id="selectForUpdate" resultMap="SysBusinessDataMap">
|
select
|
<include refid="columns"></include>
|
from sys_business_data
|
where id=#{id}
|
for update
|
</select>
|
|
|
<!-- 根据对象查询-->
|
<select id="selectByModel" resultMap="SysBusinessDataMap">
|
select
|
<include refid="columns"></include>
|
from sys_business_data
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</select>
|
|
<select id="selectShowList" resultType="com.matrix.system.hive.statistics.BusinessDataShowVo">
|
SELECT shop_id ,
|
a.time,
|
b.SHOP_NAME as shopName,
|
MAX(CASE code WHEN 'cashPay' THEN value ELSE 0 END ) cashPay,
|
MAX(CASE code WHEN 'cardPay' THEN value ELSE 0 END ) cardPay,
|
MAX(CASE code WHEN 'arrearsPay' THEN value ELSE 0 END ) arrearsPay,
|
MAX(CASE code WHEN 'freeConsumePay' THEN value ELSE 0 END ) freeConsumePay,
|
MAX(CASE code WHEN 'consumePay' THEN value ELSE 0 END ) consumePay,
|
MAX(CASE code WHEN 'refundCashPay' THEN ABS(value) ELSE 0 END) refundCashPay,
|
MAX(CASE code WHEN 'refundCardPay' THEN ABS(value) ELSE 0 END) refundCardPay
|
FROM sys_business_data a
|
left join sys_shop_info b on a.shop_id=b.ID
|
<where>
|
<if test="record.beginTime !=null">
|
and to_days(a.time) >= to_days(#{record.beginTime})
|
</if>
|
<if test="record.endTime !=null">
|
<![CDATA[ and to_days(a.time) <= to_days(#{record.endTime}) ]]>
|
</if>
|
<if test="record.shopId !=null and record.shopId != ''">
|
and a.shop_Id = #{record.shopId}
|
</if>
|
</where>
|
GROUP BY a.time ,a.shop_id
|
<if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
|
<if test="pageVo.sort !=null and pageVo.order !=null">
|
order by
|
${pageVo.sort} ${pageVo.order}
|
</if>
|
<if test="pageVo.offset >=0 and pageVo.limit >0">
|
limit
|
#{pageVo.offset},#{pageVo.limit}
|
</if>
|
</if>
|
</select>
|
|
|
<select id="selectShowListTotal" resultType="java.lang.Integer" >
|
select count(1) from (
|
SELECT shop_id ,
|
a.time
|
FROM sys_business_data a
|
<where>
|
<if test="record.beginTime !=null">
|
and to_days(a.time) >= to_days(#{record.beginTime})
|
</if>
|
<if test="record.endTime !=null">
|
<![CDATA[ and to_days(a.time) <= to_days(#{record.endTime}) ]]>
|
</if>
|
<if test="record.shopId !=null and record.shopId != ''">
|
and a.shop_Id = #{record.shopId}
|
</if>
|
</where>
|
GROUP BY a.time ,a.shop_id
|
) t
|
</select>
|
|
<select id="selectApiBusinessDataInPage" resultType="com.matrix.system.app.vo.BusinessesDataShowVo">
|
select
|
date_format(a.time, #{record.t1}) dataTime,
|
sum(cashPay + cardPay + arrearsPay) totalPay,
|
sum(cashPay) cashPay,
|
sum(cardPay) cardPay,
|
sum(arrearsPay) arrearsPay,
|
sum(freeConsumePay) freeConsumePay,
|
sum(consumePay) consumePay,
|
sum(refundCardPay) refundCardPay,
|
sum(refundCashPay) refundCashPay
|
from (
|
select
|
company_id,
|
shop_id,
|
a.time,
|
MAX(CASE code WHEN 'cashPay' THEN value ELSE 0 END) cashPay,
|
MAX(CASE code WHEN 'cardPay' THEN value ELSE 0 END) cardPay,
|
MAX(CASE code WHEN 'arrearsPay' THEN value ELSE 0 END) arrearsPay,
|
MAX(CASE code WHEN 'freeConsumePay' THEN value ELSE 0 END) freeConsumePay,
|
MAX(CASE code WHEN 'consumePay' THEN value ELSE 0 END) consumePay,
|
MAX(CASE code WHEN 'refundCashPay' THEN ABS(value) ELSE 0 END) refundCashPay,
|
MAX(CASE code WHEN 'refundCardPay' THEN ABS(value) ELSE 0 END) refundCardPay
|
from sys_business_data a
|
group by a.time, company_id, shop_id
|
) a
|
<where>
|
<if test="record.companyId != null">
|
and a.company_id=#{record.companyId}
|
</if>
|
<if test="record.shopId != null">
|
and a.shop_id=#{record.shopId}
|
</if>
|
</where>
|
group by date_format(a.time, #{record.t1})
|
order by a.time desc
|
<if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
|
<if test="pageVo.offset >=0 and pageVo.limit >0">
|
limit
|
#{pageVo.offset},#{pageVo.limit}
|
</if>
|
</if>
|
</select>
|
|
<select id="selectApiBusinessDataTotal" resultType="java.lang.Integer">
|
select
|
count(1)
|
from (
|
select
|
date_format(a.time, #{record.t1}) dataTime,
|
sum(cashPay + cardPay + arrearsPay) totalPay,
|
sum(cashPay) cashPay,
|
sum(cardPay) cardPay,
|
sum(arrearsPay) arrearsPay,
|
sum(freeConsumePay) freeConsumePay,
|
sum(consumePay) consumePay,
|
sum(refundCardPay) refundCardPay,
|
sum(refundCashPay) refundCashPay
|
from (
|
select
|
company_id,
|
shop_id,
|
a.time,
|
MAX(CASE code WHEN 'cashPay' THEN value ELSE 0 END) cashPay,
|
MAX(CASE code WHEN 'cardPay' THEN value ELSE 0 END) cardPay,
|
MAX(CASE code WHEN 'arrearsPay' THEN value ELSE 0 END) arrearsPay,
|
MAX(CASE code WHEN 'freeConsumePay' THEN value ELSE 0 END) freeConsumePay,
|
MAX(CASE code WHEN 'consumePay' THEN value ELSE 0 END) consumePay,
|
MAX(CASE code WHEN 'refundCashPay' THEN ABS(value) ELSE 0 END) refundCashPay,
|
MAX(CASE code WHEN 'refundCardPay' THEN ABS(value) ELSE 0 END) refundCardPay
|
from sys_business_data a
|
group by a.time, company_id, shop_id
|
) a
|
<where>
|
<if test="record.companyId != null">
|
and a.company_id=#{record.companyId}
|
</if>
|
<if test="record.shopId != null">
|
and a.shop_id=#{record.shopId}
|
</if>
|
</where>
|
group by date_format(a.time, #{record.t1})
|
order by a.time desc
|
) a
|
</select>
|
|
<select id="selectApiBusinessData" resultType="com.matrix.system.app.vo.BusinessesDataShowVo">
|
<foreach collection="list" index="index" item="item" separator="union all" >
|
select
|
#{item.beginTime} dataTime,
|
(select shop_short_name from sys_shop_info where id=#{shopId}) shopName,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]> and pay_method!='欠款'
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
)totalPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method not in ('储值卡', '欠款') and flow_type != '退款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) cashPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method = '储值卡' and flow_type != '退款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) cardPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method = '欠款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) arrearsPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method not in ('储值卡', '欠款') and flow_type = '退款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) refundCashPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method in ('储值卡') and flow_type = '退款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) refundCardPay,
|
(select IFNULL(sum(zk_price*count),0) from sys_order_item a
|
inner join shopping_goods b on a.goods_id=b.id
|
inner join sys_order c on a.ORDER_ID=c.id
|
where b.good_type='家居产品' and <![CDATA[ a.create_time > #{item.beginTime} and a.create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and c.shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and c.company_id=#{companyId}
|
</if>
|
) productAchieve,
|
(select IFNULL(sum(zk_price*count),0) from sys_order_item a
|
inner join shopping_goods b on a.goods_id=b.id
|
inner join sys_order c on a.ORDER_ID=c.id
|
where b.good_type!='家居产品' and <![CDATA[ a.create_time > #{item.beginTime} and a.create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and c.shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and c.company_id=#{companyId}
|
</if>
|
) cardAchieve,
|
(select IFNULL(sum(amount),0) from sys_order_flow where flow_type = '还款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) refund,
|
(select IFNULL(count(1),0) from sys_order
|
where STATU in ('已付款', '欠款') and orderType=1 and <![CDATA[ ORDER_TIME > #{item.beginTime} and ORDER_TIME < #{item.endTime} ]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) perCustomCnt,
|
(select IFNULL(sum(b.COUNT),0) from sys_order a inner join sys_order_item b on a.ID=b.ORDER_ID
|
where a.STATU in ('已付款', '欠款') and a.orderType=1 and <![CDATA[ ORDER_TIME > #{item.beginTime} and ORDER_TIME < #{item.endTime} ]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) totalSaleCnt,
|
(select IFNULL(sum(e.count * d.GOODS_PRICE),0) from sys_order a
|
inner join sys_out_store b on a.id=b.ORDER_ID
|
inner join sys_out_store_item c on b.id=c.OUT_STORE_ID
|
inner join sys_store_info d on c.store_id = d.ID
|
inner join sys_order_item e on a.ID=e.ORDER_ID
|
inner join shopping_goods f on e.goods_id=f.id and f.good_type='家居产品'
|
where a.STATU in ('已付款', '欠款') and a.orderType=1 and <![CDATA[ ORDER_TIME > #{item.beginTime} and ORDER_TIME < #{item.endTime} ]]>
|
<if test="shopId != null">
|
and a.shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and a.company_id=#{companyId}
|
</if>
|
) goodsCost,
|
(select IFNULL(sum(b.COUNT * IFNULL(c.price, 0)),0) from sys_order a
|
inner join sys_order_item b on a.ID=b.ORDER_ID
|
inner join shopping_goods c on c.good_type != '家居产品' and b.goods_id=c.id
|
where a.STATU in ('已付款', '欠款') and a.orderType=1 and <![CDATA[ ORDER_TIME > #{item.beginTime} and ORDER_TIME < #{item.endTime} ]]>
|
<if test="shopId != null">
|
and a.shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and a.company_id=#{companyId}
|
</if>
|
) otherCost,
|
(select IFNULL(sum(IFNULL(his_consume, 0)),0) from achieve_new
|
where <![CDATA[datatime > #{item.beginTime} and datatime < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) consumePay,
|
(select IFNULL(sum(IFNULL(free_consume, 0)),0) from achieve_new
|
where <![CDATA[datatime > #{item.beginTime} and datatime < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) freeConsumePay,
|
(select IFNULL(sum(IFNULL(number_of_people, 0)),0) from achieve_new
|
where <![CDATA[datatime > #{item.beginTime} and datatime < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) peopleCnt,
|
(select IFNULL(sum(IFNULL(proj_num, 0)),0) from achieve_new
|
where <![CDATA[datatime > #{item.beginTime} and datatime < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) projConsumeCnt,
|
(select IFNULL(sum(IFNULL(proj_time, 0)),0) from achieve_new
|
where <![CDATA[datatime > #{item.beginTime} and datatime < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
<if test="companyId != null">
|
and company_id=#{companyId}
|
</if>
|
) timeLength
|
from dual
|
</foreach>
|
</select>
|
|
<select id="selectDailySaleData" resultType="com.matrix.system.hive.statistics.DailySaleVo">
|
<foreach collection="list" index="index" item="item" separator="union all" >
|
select
|
#{item.beginTime} dataTime,
|
(select shop_short_name from sys_shop_info where id=#{shopId}) shopName,
|
(select sum(total) shouldPay from sys_order
|
where STATU in ('已付款', '欠款') and orderType=1 and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
) shouldPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]> and pay_method!='欠款'
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
)totalPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method not in ('储值卡', '欠款') and flow_type != '退款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
) cashPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method = '储值卡' and flow_type != '退款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
) cardPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method = '欠款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
) arrearsPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method not in ('储值卡', '欠款') and flow_type = '退款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
) refundCashPay,
|
(select IFNULL(sum(amount),0) from sys_order_flow
|
where pay_method in ('储值卡') and flow_type = '退款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
) refundCardPay,
|
(select IFNULL(sum(zk_price*count),0) from sys_order_item a
|
inner join shopping_goods b on a.goods_id=b.id
|
inner join sys_order c on a.ORDER_ID=c.id
|
where b.good_type='家居产品' and <![CDATA[ a.create_time > #{item.beginTime} and a.create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and c.shop_id=#{shopId}
|
</if>
|
) productAchieve,
|
(select IFNULL(sum(zk_price*count),0) from sys_order_item a
|
inner join shopping_goods b on a.goods_id=b.id
|
inner join sys_order c on a.ORDER_ID=c.id
|
where b.good_type!='家居产品' and <![CDATA[ a.create_time > #{item.beginTime} and a.create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and c.shop_id=#{shopId}
|
</if>
|
) cardAchieve,
|
(select IFNULL(sum(amount),0) from sys_order_flow where flow_type = '退款' and <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime}]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
) refund,
|
(select IFNULL(count(1),0) from sys_order
|
where STATU in ('已付款', '欠款') and orderType=1 and <![CDATA[ ORDER_TIME > #{item.beginTime} and ORDER_TIME < #{item.endTime} ]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
) perCustomCnt,
|
(select IFNULL(sum(b.COUNT),0) from sys_order a inner join sys_order_item b on a.ID=b.ORDER_ID
|
where a.STATU in ('已付款', '欠款') and a.orderType=1 and <![CDATA[ ORDER_TIME > #{item.beginTime} and ORDER_TIME < #{item.endTime} ]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
) totalSaleCnt,
|
(select IFNULL(sum(e.count * d.GOODS_PRICE),0) from sys_order a
|
inner join sys_out_store b on a.id=b.ORDER_ID
|
inner join sys_out_store_item c on b.id=c.OUT_STORE_ID
|
inner join sys_store_info d on c.store_id = d.ID
|
inner join sys_order_item e on a.ID=e.ORDER_ID
|
inner join shopping_goods f on e.goods_id=f.id and f.good_type='家居产品'
|
where a.STATU in ('已付款', '欠款') and a.orderType=1 and <![CDATA[ ORDER_TIME > #{item.beginTime} and ORDER_TIME < #{item.endTime} ]]>
|
<if test="shopId != null">
|
and a.shop_id=#{shopId}
|
</if>
|
) goodsCost,
|
(select IFNULL(sum(b.COUNT * IFNULL(c.price, 0)),0) from sys_order a
|
inner join sys_order_item b on a.ID=b.ORDER_ID
|
inner join shopping_goods c on c.good_type != '家居产品' and b.goods_id=c.id
|
where a.STATU in ('已付款', '欠款') and a.orderType=1 and <![CDATA[ ORDER_TIME > #{item.beginTime} and ORDER_TIME < #{item.endTime} ]]>
|
<if test="shopId != null">
|
and a.shop_id=#{shopId}
|
</if>
|
) otherCost,
|
(select sum(case a.paymethod when '微信' then amount else 0 end) wechat
|
from (<include refid="dailySaleFlow"></include>) a
|
) wechat,
|
(select
|
sum(case a.paymethod when '支付宝' then amount else 0 end) alipay
|
from (<include refid="dailySaleFlow"></include>) a
|
) alipay,
|
(select
|
sum(case a.paymethod when '现金支付' then amount else 0 end) cash
|
from (<include refid="dailySaleFlow"></include>) a
|
) cash,
|
(select
|
sum(case a.paymethod when '银行卡' then amount else 0 end) bankCard
|
from (<include refid="dailySaleFlow"></include>) a
|
) bankCard,
|
(select
|
sum(case a.paymethod when '团购' then amount else 0 end) tuan
|
from (<include refid="dailySaleFlow"></include>) a
|
) tuan,
|
(select
|
sum(case a.paymethod when '本金收款' then amount else 0 end) cardBj
|
from (<include refid="dailySaleFlow"></include>) a
|
) cardBj,
|
(select
|
sum(case a.paymethod when '赠金收款' then amount else 0 end) cardFree
|
from (<include refid="dailySaleFlow"></include>) a
|
) cardFree,
|
(select
|
sum(case a.paymethod when '欠款' then amount else 0 end) arrears
|
from (<include refid="dailySaleFlow"></include>) a
|
) arrears
|
from dual
|
</foreach>
|
</select>
|
|
<sql id="dailySaleFlow">
|
select sum(amount) amount, case when is_gift = 'Y' then '赠金收款' when is_gift='N' then '本金收款' else pay_method end paymethod
|
from sys_order_flow
|
where <![CDATA[ create_time > #{item.beginTime} and create_time < #{item.endTime} ]]>
|
<if test="shopId != null">
|
and shop_id=#{shopId}
|
</if>
|
group by paymethod
|
</sql>
|
</mapper>
|