| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- <?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.goafanti.common.dao.TOrderMonthReportMapper">
- <resultMap id="BaseResultMap" type="com.goafanti.common.model.TOrderMonthReport">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- <id column="id" jdbcType="INTEGER" property="id" />
- <result column="type" jdbcType="INTEGER" property="type" />
- <result column="month" jdbcType="INTEGER" property="month" />
- <result column="amount" jdbcType="DECIMAL" property="amount" />
- <result column="proof_count" jdbcType="REAL" property="proofCount" />
- <result column="salemans_id" jdbcType="VARCHAR" property="salemansId" />
- <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
- </resultMap>
- <sql id="Example_Where_Clause">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- <where>
- <foreach collection="oredCriteria" item="criteria" separator="or">
- <if test="criteria.valid">
- <trim prefix="(" prefixOverrides="and" suffix=")">
- <foreach collection="criteria.criteria" item="criterion">
- <choose>
- <when test="criterion.noValue">
- and ${criterion.condition}
- </when>
- <when test="criterion.singleValue">
- and ${criterion.condition} #{criterion.value}
- </when>
- <when test="criterion.betweenValue">
- and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
- </when>
- <when test="criterion.listValue">
- and ${criterion.condition}
- <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
- #{listItem}
- </foreach>
- </when>
- </choose>
- </foreach>
- </trim>
- </if>
- </foreach>
- </where>
- </sql>
- <sql id="Update_By_Example_Where_Clause">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- <where>
- <foreach collection="example.oredCriteria" item="criteria" separator="or">
- <if test="criteria.valid">
- <trim prefix="(" prefixOverrides="and" suffix=")">
- <foreach collection="criteria.criteria" item="criterion">
- <choose>
- <when test="criterion.noValue">
- and ${criterion.condition}
- </when>
- <when test="criterion.singleValue">
- and ${criterion.condition} #{criterion.value}
- </when>
- <when test="criterion.betweenValue">
- and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
- </when>
- <when test="criterion.listValue">
- and ${criterion.condition}
- <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
- #{listItem}
- </foreach>
- </when>
- </choose>
- </foreach>
- </trim>
- </if>
- </foreach>
- </where>
- </sql>
- <sql id="Base_Column_List">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- id, type, month, amount, proof_count, salemans_id, update_time
- </sql>
- <select id="selectByExample" parameterType="com.goafanti.common.model.TOrderMonthReportExample" resultMap="BaseResultMap">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- select
- <if test="distinct">
- distinct
- </if>
- <include refid="Base_Column_List" />
- from t_order_month_report
- <if test="_parameter != null">
- <include refid="Example_Where_Clause" />
- </if>
- <if test="orderByClause != null">
- order by ${orderByClause}
- </if>
- </select>
- <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- select
- <include refid="Base_Column_List" />
- from t_order_month_report
- where id = #{id,jdbcType=INTEGER}
- </select>
- <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- delete from t_order_month_report
- where id = #{id,jdbcType=INTEGER}
- </delete>
- <delete id="deleteByExample" parameterType="com.goafanti.common.model.TOrderMonthReportExample">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- delete from t_order_month_report
- <if test="_parameter != null">
- <include refid="Example_Where_Clause" />
- </if>
- </delete>
- <insert id="insert" parameterType="com.goafanti.common.model.TOrderMonthReport">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- insert into t_order_month_report (id, type, month,
- amount, proof_count, salemans_id,
- update_time)
- values (#{id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{month,jdbcType=INTEGER},
- #{amount,jdbcType=DECIMAL}, #{proofCount,jdbcType=REAL}, #{salemansId,jdbcType=VARCHAR},
- #{updateTime,jdbcType=TIMESTAMP})
- </insert>
- <insert id="insertSelective" parameterType="com.goafanti.common.model.TOrderMonthReport">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- insert into t_order_month_report
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="id != null">
- id,
- </if>
- <if test="type != null">
- type,
- </if>
- <if test="month != null">
- month,
- </if>
- <if test="amount != null">
- amount,
- </if>
- <if test="proofCount != null">
- proof_count,
- </if>
- <if test="salemansId != null">
- salemans_id,
- </if>
- <if test="updateTime != null">
- update_time,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="id != null">
- #{id,jdbcType=INTEGER},
- </if>
- <if test="type != null">
- #{type,jdbcType=INTEGER},
- </if>
- <if test="month != null">
- #{month,jdbcType=INTEGER},
- </if>
- <if test="amount != null">
- #{amount,jdbcType=DECIMAL},
- </if>
- <if test="proofCount != null">
- #{proofCount,jdbcType=REAL},
- </if>
- <if test="salemansId != null">
- #{salemansId,jdbcType=VARCHAR},
- </if>
- <if test="updateTime != null">
- #{updateTime,jdbcType=TIMESTAMP},
- </if>
- </trim>
- </insert>
- <select id="countByExample" parameterType="com.goafanti.common.model.TOrderMonthReportExample" resultType="java.lang.Integer">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- select count(*) from t_order_month_report
- <if test="_parameter != null">
- <include refid="Example_Where_Clause" />
- </if>
- </select>
- <update id="updateByExampleSelective" parameterType="map">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- update t_order_month_report
- <set>
- <if test="record.id != null">
- id = #{record.id,jdbcType=INTEGER},
- </if>
- <if test="record.type != null">
- type = #{record.type,jdbcType=INTEGER},
- </if>
- <if test="record.month != null">
- month = #{record.month,jdbcType=INTEGER},
- </if>
- <if test="record.amount != null">
- amount = #{record.amount,jdbcType=DECIMAL},
- </if>
- <if test="record.proofCount != null">
- proof_count = #{record.proofCount,jdbcType=REAL},
- </if>
- <if test="record.salemansId != null">
- salemans_id = #{record.salemansId,jdbcType=VARCHAR},
- </if>
- <if test="record.updateTime != null">
- update_time = #{record.updateTime,jdbcType=TIMESTAMP},
- </if>
- </set>
- <if test="_parameter != null">
- <include refid="Update_By_Example_Where_Clause" />
- </if>
- </update>
- <update id="updateByExample" parameterType="map">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- update t_order_month_report
- set id = #{record.id,jdbcType=INTEGER},
- type = #{record.type,jdbcType=INTEGER},
- month = #{record.month,jdbcType=INTEGER},
- amount = #{record.amount,jdbcType=DECIMAL},
- proof_count = #{record.proofCount,jdbcType=REAL},
- salemans_id = #{record.salemansId,jdbcType=VARCHAR},
- update_time = #{record.updateTime,jdbcType=TIMESTAMP}
- <if test="_parameter != null">
- <include refid="Update_By_Example_Where_Clause" />
- </if>
- </update>
- <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderMonthReport">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- update t_order_month_report
- <set>
- <if test="type != null">
- type = #{type,jdbcType=INTEGER},
- </if>
- <if test="month != null">
- month = #{month,jdbcType=INTEGER},
- </if>
- <if test="amount != null">
- amount = #{amount,jdbcType=DECIMAL},
- </if>
- <if test="proofCount != null">
- proof_count = #{proofCount,jdbcType=REAL},
- </if>
- <if test="salemansId != null">
- salemans_id = #{salemansId,jdbcType=VARCHAR},
- </if>
- <if test="updateTime != null">
- update_time = #{updateTime,jdbcType=TIMESTAMP},
- </if>
- </set>
- where id = #{id,jdbcType=INTEGER}
- </update>
- <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderMonthReport">
- <!--
- WARNING - @mbggenerated
- This element is automatically generated by MyBatis Generator, do not modify.
- This element was generated on Tue Nov 27 14:53:14 CST 2018.
- -->
- update t_order_month_report
- set type = #{type,jdbcType=INTEGER},
- month = #{month,jdbcType=INTEGER},
- amount = #{amount,jdbcType=DECIMAL},
- proof_count = #{proofCount,jdbcType=REAL},
- salemans_id = #{salemansId,jdbcType=VARCHAR},
- update_time = #{updateTime,jdbcType=TIMESTAMP}
- where id = #{id,jdbcType=INTEGER}
- </update>
- <!-- 定时插入上月的签单数据 -->
- <insert id="insertLastMonthOrderData" parameterType="java.lang.String">
- REPLACE INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id)
- select o.order_type, date_format(DATE_ADD(NOW(),INTERVAL -1 MONTH),'%Y%m'),sum(o.total_amount), sum(o.proof_count), o.salesman_id
- from t_order_new o
- where 1 = 1
- and o.proof_status = 1 and o.delete_sign = 0 and o.order_status <> 7
- and PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( o.sign_time, '%Y%m' ) ) = 1
- group by o.salesman_id , o.order_type
- </insert>
- <!-- 定时插入上一年的数据 -->
- <insert id="insertLastYearOrderData" parameterType="java.lang.String">
- REPLACE INTO t_order_year_report(`type`,`year`,amount,proof_count,salemans_id)
- select m.`type`, year(date_sub(now(),interval 1 year)), sum(amount), sum(proof_count), salemans_id from t_order_month_report m
- where CAST(`month` as CHAR) like concat (year(date_sub(now(),interval 1 year)),'%')
- group by m.salemans_id , m.`type`
- </insert>
- <!-- 查看订单统计数据 -->
- <select id="getOrderReportDataList" parameterType="Map" resultType="com.goafanti.order.bo.OrderReportBo">
- select @rowno:= @rowno+1 as id, d.name as deptName, a.name as saleName, m.`type`, sum(proof_count) as proofCount, sum(amount) as amount,
- m.id as mid
- from t_order_month_report m
- left join admin a on m.salemans_id = a.id
- left join department d on d.id = a.department_id
- ,(select @rowno:=0)c
- where
- `month` between #{r.month,jdbcType=INTEGER} and #{r.month1,jdbcType=INTEGER}
- <if test='r.departmentId != null and r.departmentId != ""'>
- and a.department_id = #{r.departmentId,jdbcType=VARCHAR}
- </if>
- <if test='r.type != null and r.type != ""'><!-- 装数据是0变成null 加一处理后减一 -->
- and m.type= #{r.type,jdbcType=INTEGER} -1
- </if>
- <if test='r.saleName != null and r.saleName != ""'>
- <bind name="n" value=" '%' + r.saleName + '%'"/>
- and a.name like #{n,jdbcType=VARCHAR}
- </if>
- group by
- a.department_id, a.id, m.`type`
- <if test="page_sql != null">
- ${page_sql}
- </if>
- </select>
- <select id="getOrderReportDataCount" parameterType="Map" resultType="java.lang.Integer">
- select count(*) from (
- select count(*)
- from t_order_month_report m
- left join admin a on m.salemans_id = a.id
- left join department d on d.id = a.department_id
- where
- `month` between #{r.month,jdbcType=INTEGER} and #{r.month1,jdbcType=INTEGER}
- <if test='r.departmentId != null and r.departmentId != ""'>
- and a.department_id = #{r.departmentId,jdbcType=VARCHAR}
- </if>
- <if test='r.type != null and r.type != ""'>
- and m.type= #{r.type,jdbcType=INTEGER} -1
- </if>
- <if test='r.saleName != null and r.saleName != ""'>
- <bind name="n" value=" '%' + r.saleName + '%'"/>
- and a.name like #{n,jdbcType=VARCHAR}
- </if>
- group by
- a.department_id, a.id, m.`type`
- )ff
- </select>
- <!-- 导出月统计 -->
- <select id="exportMonthData" parameterType="com.goafanti.order.bo.OrderReportBo" resultType="com.goafanti.order.bo.OrderReportBo">
- select @rowno:= @rowno+1 as id, d.name as deptName, a.name as saleName, m.`type`, sum(proof_count) as proofCount, sum(amount) as amount
- from t_order_month_report m
- left join admin a on m.salemans_id = a.id
- left join department d on d.id = a.department_id
- ,(select @rowno:=0)c
- where
- `month` between #{month,jdbcType=INTEGER} and #{month1,jdbcType=INTEGER}
- <if test='departmentId != null and departmentId != ""'>
- and a.department_id = #{departmentId,jdbcType=VARCHAR}
- </if>
- <if test='type != null and type != ""'>
- and m.type= #{type,jdbcType=INTEGER} -1
- </if>
- <if test='saleName != null and saleName != ""'>
- <bind name="n" value=" '%' + saleName + '%'"/>
- and a.name like #{n,jdbcType=VARCHAR}
- </if>
- group by
- a.department_id, a.id, m.`type`
- </select>
- <!-- 查看某人某年某月某类型的数据是否存在 -->
- <select id="checkData" parameterType="com.goafanti.order.bo.OrderReportBo" resultType="java.lang.Integer">
- select count(*) from
- t_order_month_report
- where salemans_id = #{salemansId,jdbcType=VARCHAR} and `month` = #{month,jdbcType=INTEGER}
- and type = #{type,jdbcType=INTEGER}
- </select>
- <!-- 查看某时间范围内的月统计 -->
- <select id="getMonthReportByMonth" parameterType="com.goafanti.order.bo.OrderReportBo" resultType="com.goafanti.order.bo.OrderReportBo">
- select salemans_id as salemansId, sum(case `type` when 0 then proof_count else 0 end) renzm ,sum(case `type` when 1 then proof_count else 0 end) kejim
- from
- t_order_month_report
- where `month` between #{month,jdbcType=INTEGER} and #{month1,jdbcType=INTEGER}
- <if test="salemansId != null">
- and salemans_id = #{salemansId,jdbcType=VARCHAR}
- </if>
- <if test="salemansId == null">
- group by salemans_id
- </if>
- </select>
- <!-- 查看某时间范围内的年统计 -->
- <select id="getYearReportByYear" parameterType="com.goafanti.order.bo.OrderReportBo" resultType="com.goafanti.order.bo.OrderReportBo">
- select sum(case `type` when 0 then proof_count else 0 end) renzy ,sum(case `type` when 1 then proof_count else 0 end) kejiy
- from
- t_order_year_report
- where `year` between #{month,jdbcType=INTEGER} and #{month1,jdbcType=INTEGER}
- <if test="salemansId != null">
- and salemans_id = #{salemansId,jdbcType=VARCHAR}
- </if>
- <if test="salemansId == null">
- group by salemans_id
- </if>
- </select>
- <!-- 更新某人某月份某类型的数据 -->
- <update id="proofDataBySomeBody" parameterType="com.goafanti.common.model.TOrderNew">
- UPDATE t_order_month_report m,
- (select sum(proof_count) as proof_count, sum(total_amount) as amount , order_type, salesman_id from t_order_new
- where
- proof_status = 1
- and salesman_id = #{salesmanId,jdbcType=VARCHAR}
- and order_type = #{orderType,jdbcType=INTEGER}
- and date_format( sign_time , '%Y%m' ) = date_format( #{signTime,jdbcType=DATE}, '%Y%m' )) as o
-
- SET m.proof_count = o.proof_count, m.amount = o.amount
-
- WHERE m.type = o.order_type and m.salemans_id = o.salesman_id and m.month = date_format( #{signTime,jdbcType=DATE}, '%Y%m' )
- </update>
-
- <!-- 更新年数据 -->
- <update id="updateYearReportData" parameterType="java.lang.String">
- update t_order_year_report y,(
- SELECT salemans_id, `type`, sum(amount) amount, sum(proof_count) proof_count FROM t_order_month_report
-
- WHERE CAST(`month` as CHAR) like concat (date_format(now(),'%Y'),'%')
-
- GROUP BY salemans_id, type) m
-
- SET y.proof_count = m.proof_count, y.amount = m.amount
-
- WHERE y.salemans_id = m.salemans_id and y.type = m.type and year = date_format(now(),'%Y')
- </update>
-
- <!-- 新增某人某月某类型的统计数据 -->
- <insert id="insertBySome" parameterType="com.goafanti.common.model.TOrderNew">
- INSERT INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id)
- select order_type, date_format( sign_time , '%Y%m' ), sum(total_amount) as amount, sum(proof_count) as proof_count, salesman_id
- from t_order_new
- where
- proof_status = 1 and o.delete_sign = 0 and o.order_status <> 7
- and salesman_id = #{salesmanId,jdbcType=VARCHAR}
- and order_type = #{orderType,jdbcType=INTEGER}
- and date_format( sign_time , '%Y%m' ) = date_format( #{signTime,jdbcType=DATE}, '%Y%m' )
- </insert>
- <!-- 更新指定月份的统计数据 -->
- <insert id="updateByMonth" parameterType="java.lang.Integer">
- REPLACE INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id)
- select o.order_type, #{month,jdbcType=INTEGER},sum(o.total_amount), sum(o.proof_count), o.salesman_id
- from t_order_new o
- where 1 = 1
- and o.proof_status = 1 and o.delete_sign = 0 and o.order_status <> 7
- and date_format( o.sign_time, '%Y%m' ) = #{month,jdbcType=INTEGER}
- group by o.salesman_id , o.order_type
- </insert>
- <!-- 更新本年的年统计数据 -->
- <insert id="updateByYear">
- REPLACE INTO t_order_year_report(`type`,`year`,amount,proof_count,salemans_id)
- select m.`type`, year(now()), sum(amount), sum(proof_count), salemans_id from t_order_month_report m
- where CAST(`month` as CHAR) like concat (year(now()),'%')
- group by m.salemans_id , m.`type`
- </insert>
- </mapper>
|