TOrderMonthReportMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.goafanti.common.dao.TOrderMonthReportMapper">
  4. <resultMap id="BaseResultMap" type="com.goafanti.common.model.TOrderMonthReport">
  5. <!--
  6. WARNING - @mbggenerated
  7. This element is automatically generated by MyBatis Generator, do not modify.
  8. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  9. -->
  10. <id column="id" jdbcType="INTEGER" property="id" />
  11. <result column="type" jdbcType="INTEGER" property="type" />
  12. <result column="month" jdbcType="INTEGER" property="month" />
  13. <result column="amount" jdbcType="DECIMAL" property="amount" />
  14. <result column="proof_count" jdbcType="REAL" property="proofCount" />
  15. <result column="salemans_id" jdbcType="VARCHAR" property="salemansId" />
  16. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  17. </resultMap>
  18. <sql id="Example_Where_Clause">
  19. <!--
  20. WARNING - @mbggenerated
  21. This element is automatically generated by MyBatis Generator, do not modify.
  22. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  23. -->
  24. <where>
  25. <foreach collection="oredCriteria" item="criteria" separator="or">
  26. <if test="criteria.valid">
  27. <trim prefix="(" prefixOverrides="and" suffix=")">
  28. <foreach collection="criteria.criteria" item="criterion">
  29. <choose>
  30. <when test="criterion.noValue">
  31. and ${criterion.condition}
  32. </when>
  33. <when test="criterion.singleValue">
  34. and ${criterion.condition} #{criterion.value}
  35. </when>
  36. <when test="criterion.betweenValue">
  37. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  38. </when>
  39. <when test="criterion.listValue">
  40. and ${criterion.condition}
  41. <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
  42. #{listItem}
  43. </foreach>
  44. </when>
  45. </choose>
  46. </foreach>
  47. </trim>
  48. </if>
  49. </foreach>
  50. </where>
  51. </sql>
  52. <sql id="Update_By_Example_Where_Clause">
  53. <!--
  54. WARNING - @mbggenerated
  55. This element is automatically generated by MyBatis Generator, do not modify.
  56. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  57. -->
  58. <where>
  59. <foreach collection="example.oredCriteria" item="criteria" separator="or">
  60. <if test="criteria.valid">
  61. <trim prefix="(" prefixOverrides="and" suffix=")">
  62. <foreach collection="criteria.criteria" item="criterion">
  63. <choose>
  64. <when test="criterion.noValue">
  65. and ${criterion.condition}
  66. </when>
  67. <when test="criterion.singleValue">
  68. and ${criterion.condition} #{criterion.value}
  69. </when>
  70. <when test="criterion.betweenValue">
  71. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  72. </when>
  73. <when test="criterion.listValue">
  74. and ${criterion.condition}
  75. <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
  76. #{listItem}
  77. </foreach>
  78. </when>
  79. </choose>
  80. </foreach>
  81. </trim>
  82. </if>
  83. </foreach>
  84. </where>
  85. </sql>
  86. <sql id="Base_Column_List">
  87. <!--
  88. WARNING - @mbggenerated
  89. This element is automatically generated by MyBatis Generator, do not modify.
  90. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  91. -->
  92. id, type, month, amount, proof_count, salemans_id, update_time
  93. </sql>
  94. <select id="selectByExample" parameterType="com.goafanti.common.model.TOrderMonthReportExample" resultMap="BaseResultMap">
  95. <!--
  96. WARNING - @mbggenerated
  97. This element is automatically generated by MyBatis Generator, do not modify.
  98. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  99. -->
  100. select
  101. <if test="distinct">
  102. distinct
  103. </if>
  104. <include refid="Base_Column_List" />
  105. from t_order_month_report
  106. <if test="_parameter != null">
  107. <include refid="Example_Where_Clause" />
  108. </if>
  109. <if test="orderByClause != null">
  110. order by ${orderByClause}
  111. </if>
  112. </select>
  113. <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  114. <!--
  115. WARNING - @mbggenerated
  116. This element is automatically generated by MyBatis Generator, do not modify.
  117. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  118. -->
  119. select
  120. <include refid="Base_Column_List" />
  121. from t_order_month_report
  122. where id = #{id,jdbcType=INTEGER}
  123. </select>
  124. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  125. <!--
  126. WARNING - @mbggenerated
  127. This element is automatically generated by MyBatis Generator, do not modify.
  128. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  129. -->
  130. delete from t_order_month_report
  131. where id = #{id,jdbcType=INTEGER}
  132. </delete>
  133. <delete id="deleteByExample" parameterType="com.goafanti.common.model.TOrderMonthReportExample">
  134. <!--
  135. WARNING - @mbggenerated
  136. This element is automatically generated by MyBatis Generator, do not modify.
  137. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  138. -->
  139. delete from t_order_month_report
  140. <if test="_parameter != null">
  141. <include refid="Example_Where_Clause" />
  142. </if>
  143. </delete>
  144. <insert id="insert" parameterType="com.goafanti.common.model.TOrderMonthReport">
  145. <!--
  146. WARNING - @mbggenerated
  147. This element is automatically generated by MyBatis Generator, do not modify.
  148. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  149. -->
  150. insert into t_order_month_report (id, type, month,
  151. amount, proof_count, salemans_id,
  152. update_time)
  153. values (#{id,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{month,jdbcType=INTEGER},
  154. #{amount,jdbcType=DECIMAL}, #{proofCount,jdbcType=REAL}, #{salemansId,jdbcType=VARCHAR},
  155. #{updateTime,jdbcType=TIMESTAMP})
  156. </insert>
  157. <insert id="insertSelective" parameterType="com.goafanti.common.model.TOrderMonthReport">
  158. <!--
  159. WARNING - @mbggenerated
  160. This element is automatically generated by MyBatis Generator, do not modify.
  161. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  162. -->
  163. insert into t_order_month_report
  164. <trim prefix="(" suffix=")" suffixOverrides=",">
  165. <if test="id != null">
  166. id,
  167. </if>
  168. <if test="type != null">
  169. type,
  170. </if>
  171. <if test="month != null">
  172. month,
  173. </if>
  174. <if test="amount != null">
  175. amount,
  176. </if>
  177. <if test="proofCount != null">
  178. proof_count,
  179. </if>
  180. <if test="salemansId != null">
  181. salemans_id,
  182. </if>
  183. <if test="updateTime != null">
  184. update_time,
  185. </if>
  186. </trim>
  187. <trim prefix="values (" suffix=")" suffixOverrides=",">
  188. <if test="id != null">
  189. #{id,jdbcType=INTEGER},
  190. </if>
  191. <if test="type != null">
  192. #{type,jdbcType=INTEGER},
  193. </if>
  194. <if test="month != null">
  195. #{month,jdbcType=INTEGER},
  196. </if>
  197. <if test="amount != null">
  198. #{amount,jdbcType=DECIMAL},
  199. </if>
  200. <if test="proofCount != null">
  201. #{proofCount,jdbcType=REAL},
  202. </if>
  203. <if test="salemansId != null">
  204. #{salemansId,jdbcType=VARCHAR},
  205. </if>
  206. <if test="updateTime != null">
  207. #{updateTime,jdbcType=TIMESTAMP},
  208. </if>
  209. </trim>
  210. </insert>
  211. <select id="countByExample" parameterType="com.goafanti.common.model.TOrderMonthReportExample" resultType="java.lang.Integer">
  212. <!--
  213. WARNING - @mbggenerated
  214. This element is automatically generated by MyBatis Generator, do not modify.
  215. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  216. -->
  217. select count(*) from t_order_month_report
  218. <if test="_parameter != null">
  219. <include refid="Example_Where_Clause" />
  220. </if>
  221. </select>
  222. <update id="updateByExampleSelective" parameterType="map">
  223. <!--
  224. WARNING - @mbggenerated
  225. This element is automatically generated by MyBatis Generator, do not modify.
  226. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  227. -->
  228. update t_order_month_report
  229. <set>
  230. <if test="record.id != null">
  231. id = #{record.id,jdbcType=INTEGER},
  232. </if>
  233. <if test="record.type != null">
  234. type = #{record.type,jdbcType=INTEGER},
  235. </if>
  236. <if test="record.month != null">
  237. month = #{record.month,jdbcType=INTEGER},
  238. </if>
  239. <if test="record.amount != null">
  240. amount = #{record.amount,jdbcType=DECIMAL},
  241. </if>
  242. <if test="record.proofCount != null">
  243. proof_count = #{record.proofCount,jdbcType=REAL},
  244. </if>
  245. <if test="record.salemansId != null">
  246. salemans_id = #{record.salemansId,jdbcType=VARCHAR},
  247. </if>
  248. <if test="record.updateTime != null">
  249. update_time = #{record.updateTime,jdbcType=TIMESTAMP},
  250. </if>
  251. </set>
  252. <if test="_parameter != null">
  253. <include refid="Update_By_Example_Where_Clause" />
  254. </if>
  255. </update>
  256. <update id="updateByExample" parameterType="map">
  257. <!--
  258. WARNING - @mbggenerated
  259. This element is automatically generated by MyBatis Generator, do not modify.
  260. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  261. -->
  262. update t_order_month_report
  263. set id = #{record.id,jdbcType=INTEGER},
  264. type = #{record.type,jdbcType=INTEGER},
  265. month = #{record.month,jdbcType=INTEGER},
  266. amount = #{record.amount,jdbcType=DECIMAL},
  267. proof_count = #{record.proofCount,jdbcType=REAL},
  268. salemans_id = #{record.salemansId,jdbcType=VARCHAR},
  269. update_time = #{record.updateTime,jdbcType=TIMESTAMP}
  270. <if test="_parameter != null">
  271. <include refid="Update_By_Example_Where_Clause" />
  272. </if>
  273. </update>
  274. <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderMonthReport">
  275. <!--
  276. WARNING - @mbggenerated
  277. This element is automatically generated by MyBatis Generator, do not modify.
  278. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  279. -->
  280. update t_order_month_report
  281. <set>
  282. <if test="type != null">
  283. type = #{type,jdbcType=INTEGER},
  284. </if>
  285. <if test="month != null">
  286. month = #{month,jdbcType=INTEGER},
  287. </if>
  288. <if test="amount != null">
  289. amount = #{amount,jdbcType=DECIMAL},
  290. </if>
  291. <if test="proofCount != null">
  292. proof_count = #{proofCount,jdbcType=REAL},
  293. </if>
  294. <if test="salemansId != null">
  295. salemans_id = #{salemansId,jdbcType=VARCHAR},
  296. </if>
  297. <if test="updateTime != null">
  298. update_time = #{updateTime,jdbcType=TIMESTAMP},
  299. </if>
  300. </set>
  301. where id = #{id,jdbcType=INTEGER}
  302. </update>
  303. <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderMonthReport">
  304. <!--
  305. WARNING - @mbggenerated
  306. This element is automatically generated by MyBatis Generator, do not modify.
  307. This element was generated on Tue Nov 27 14:53:14 CST 2018.
  308. -->
  309. update t_order_month_report
  310. set type = #{type,jdbcType=INTEGER},
  311. month = #{month,jdbcType=INTEGER},
  312. amount = #{amount,jdbcType=DECIMAL},
  313. proof_count = #{proofCount,jdbcType=REAL},
  314. salemans_id = #{salemansId,jdbcType=VARCHAR},
  315. update_time = #{updateTime,jdbcType=TIMESTAMP}
  316. where id = #{id,jdbcType=INTEGER}
  317. </update>
  318. <!-- 定时插入上月的签单数据 -->
  319. <insert id="insertLastMonthOrderData" parameterType="java.lang.String">
  320. REPLACE INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id)
  321. 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
  322. from t_order_new o
  323. where 1 = 1
  324. and o.proof_status = 1 and o.delete_sign = 0 and o.order_status &lt;&gt; 7
  325. and PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( o.sign_time, '%Y%m' ) ) = 1
  326. group by o.salesman_id , o.order_type
  327. </insert>
  328. <!-- 定时插入上一年的数据 -->
  329. <insert id="insertLastYearOrderData" parameterType="java.lang.String">
  330. REPLACE INTO t_order_year_report(`type`,`year`,amount,proof_count,salemans_id)
  331. select m.`type`, year(date_sub(now(),interval 1 year)), sum(amount), sum(proof_count), salemans_id from t_order_month_report m
  332. where CAST(`month` as CHAR) like concat (year(date_sub(now(),interval 1 year)),'%')
  333. group by m.salemans_id , m.`type`
  334. </insert>
  335. <!-- 查看订单统计数据 -->
  336. <select id="getOrderReportDataList" parameterType="Map" resultType="com.goafanti.order.bo.OrderReportBo">
  337. 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,
  338. m.id as mid
  339. from t_order_month_report m
  340. left join admin a on m.salemans_id = a.id
  341. left join department d on d.id = a.department_id
  342. ,(select @rowno:=0)c
  343. where
  344. `month` between #{r.month,jdbcType=INTEGER} and #{r.month1,jdbcType=INTEGER}
  345. <if test='r.departmentId != null and r.departmentId != ""'>
  346. and a.department_id = #{r.departmentId,jdbcType=VARCHAR}
  347. </if>
  348. <if test='r.type != null and r.type != ""'><!-- 装数据是0变成null 加一处理后减一 -->
  349. and m.type= #{r.type,jdbcType=INTEGER} -1
  350. </if>
  351. <if test='r.saleName != null and r.saleName != ""'>
  352. <bind name="n" value=" '%' + r.saleName + '%'"/>
  353. and a.name like #{n,jdbcType=VARCHAR}
  354. </if>
  355. group by
  356. a.department_id, a.id, m.`type`
  357. <if test="page_sql != null">
  358. ${page_sql}
  359. </if>
  360. </select>
  361. <select id="getOrderReportDataCount" parameterType="Map" resultType="java.lang.Integer">
  362. select count(*) from (
  363. select count(*)
  364. from t_order_month_report m
  365. left join admin a on m.salemans_id = a.id
  366. left join department d on d.id = a.department_id
  367. where
  368. `month` between #{r.month,jdbcType=INTEGER} and #{r.month1,jdbcType=INTEGER}
  369. <if test='r.departmentId != null and r.departmentId != ""'>
  370. and a.department_id = #{r.departmentId,jdbcType=VARCHAR}
  371. </if>
  372. <if test='r.type != null and r.type != ""'>
  373. and m.type= #{r.type,jdbcType=INTEGER} -1
  374. </if>
  375. <if test='r.saleName != null and r.saleName != ""'>
  376. <bind name="n" value=" '%' + r.saleName + '%'"/>
  377. and a.name like #{n,jdbcType=VARCHAR}
  378. </if>
  379. group by
  380. a.department_id, a.id, m.`type`
  381. )ff
  382. </select>
  383. <!-- 导出月统计 -->
  384. <select id="exportMonthData" parameterType="com.goafanti.order.bo.OrderReportBo" resultType="com.goafanti.order.bo.OrderReportBo">
  385. 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
  386. from t_order_month_report m
  387. left join admin a on m.salemans_id = a.id
  388. left join department d on d.id = a.department_id
  389. ,(select @rowno:=0)c
  390. where
  391. `month` between #{month,jdbcType=INTEGER} and #{month1,jdbcType=INTEGER}
  392. <if test='departmentId != null and departmentId != ""'>
  393. and a.department_id = #{departmentId,jdbcType=VARCHAR}
  394. </if>
  395. <if test='type != null and type != ""'>
  396. and m.type= #{type,jdbcType=INTEGER} -1
  397. </if>
  398. <if test='saleName != null and saleName != ""'>
  399. <bind name="n" value=" '%' + saleName + '%'"/>
  400. and a.name like #{n,jdbcType=VARCHAR}
  401. </if>
  402. group by
  403. a.department_id, a.id, m.`type`
  404. </select>
  405. <!-- 查看某人某年某月某类型的数据是否存在 -->
  406. <select id="checkData" parameterType="com.goafanti.order.bo.OrderReportBo" resultType="java.lang.Integer">
  407. select count(*) from
  408. t_order_month_report
  409. where salemans_id = #{salemansId,jdbcType=VARCHAR} and `month` = #{month,jdbcType=INTEGER}
  410. and type = #{type,jdbcType=INTEGER}
  411. </select>
  412. <!-- 查看某时间范围内的月统计 -->
  413. <select id="getMonthReportByMonth" parameterType="com.goafanti.order.bo.OrderReportBo" resultType="com.goafanti.order.bo.OrderReportBo">
  414. 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
  415. from
  416. t_order_month_report
  417. where `month` between #{month,jdbcType=INTEGER} and #{month1,jdbcType=INTEGER}
  418. <if test="salemansId != null">
  419. and salemans_id = #{salemansId,jdbcType=VARCHAR}
  420. </if>
  421. <if test="salemansId == null">
  422. group by salemans_id
  423. </if>
  424. </select>
  425. <!-- 查看某时间范围内的年统计 -->
  426. <select id="getYearReportByYear" parameterType="com.goafanti.order.bo.OrderReportBo" resultType="com.goafanti.order.bo.OrderReportBo">
  427. 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
  428. from
  429. t_order_year_report
  430. where `year` between #{month,jdbcType=INTEGER} and #{month1,jdbcType=INTEGER}
  431. <if test="salemansId != null">
  432. and salemans_id = #{salemansId,jdbcType=VARCHAR}
  433. </if>
  434. <if test="salemansId == null">
  435. group by salemans_id
  436. </if>
  437. </select>
  438. <!-- 更新某人某月份某类型的数据 -->
  439. <update id="proofDataBySomeBody" parameterType="com.goafanti.common.model.TOrderNew">
  440. UPDATE t_order_month_report m,
  441. (select sum(proof_count) as proof_count, sum(total_amount) as amount , order_type, salesman_id from t_order_new
  442. where
  443. proof_status = 1
  444. and salesman_id = #{salesmanId,jdbcType=VARCHAR}
  445. and order_type = #{orderType,jdbcType=INTEGER}
  446. and date_format( sign_time , '%Y%m' ) = date_format( #{signTime,jdbcType=DATE}, '%Y%m' )) as o
  447. SET m.proof_count = o.proof_count, m.amount = o.amount
  448. WHERE m.type = o.order_type and m.salemans_id = o.salesman_id and m.month = date_format( #{signTime,jdbcType=DATE}, '%Y%m' )
  449. </update>
  450. <!-- 更新年数据 -->
  451. <update id="updateYearReportData" parameterType="java.lang.String">
  452. update t_order_year_report y,(
  453. SELECT salemans_id, `type`, sum(amount) amount, sum(proof_count) proof_count FROM t_order_month_report
  454. WHERE CAST(`month` as CHAR) like concat (date_format(now(),'%Y'),'%')
  455. GROUP BY salemans_id, type) m
  456. SET y.proof_count = m.proof_count, y.amount = m.amount
  457. WHERE y.salemans_id = m.salemans_id and y.type = m.type and year = date_format(now(),'%Y')
  458. </update>
  459. <!-- 新增某人某月某类型的统计数据 -->
  460. <insert id="insertBySome" parameterType="com.goafanti.common.model.TOrderNew">
  461. INSERT INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id)
  462. select order_type, date_format( sign_time , '%Y%m' ), sum(total_amount) as amount, sum(proof_count) as proof_count, salesman_id
  463. from t_order_new
  464. where
  465. proof_status = 1 and o.delete_sign = 0 and o.order_status &lt;&gt; 7
  466. and salesman_id = #{salesmanId,jdbcType=VARCHAR}
  467. and order_type = #{orderType,jdbcType=INTEGER}
  468. and date_format( sign_time , '%Y%m' ) = date_format( #{signTime,jdbcType=DATE}, '%Y%m' )
  469. </insert>
  470. <!-- 更新指定月份的统计数据 -->
  471. <insert id="updateByMonth" parameterType="java.lang.Integer">
  472. REPLACE INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id)
  473. select o.order_type, #{month,jdbcType=INTEGER},sum(o.total_amount), sum(o.proof_count), o.salesman_id
  474. from t_order_new o
  475. where 1 = 1
  476. and o.proof_status = 1 and o.delete_sign = 0 and o.order_status &lt;&gt; 7
  477. and date_format( o.sign_time, '%Y%m' ) = #{month,jdbcType=INTEGER}
  478. group by o.salesman_id , o.order_type
  479. </insert>
  480. <!-- 更新本年的年统计数据 -->
  481. <insert id="updateByYear">
  482. REPLACE INTO t_order_year_report(`type`,`year`,amount,proof_count,salemans_id)
  483. select m.`type`, year(now()), sum(amount), sum(proof_count), salemans_id from t_order_month_report m
  484. where CAST(`month` as CHAR) like concat (year(now()),'%')
  485. group by m.salemans_id , m.`type`
  486. </insert>
  487. </mapper>