ItemMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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.dayou.mapper.ItemMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.vo.ItemVO">
  6. <result column="id" property="id" />
  7. <result column="deleted" property="deleted" />
  8. <result column="created" property="created" />
  9. <result column="modified" property="modified" />
  10. <result column="business_no" property="businessNo" />
  11. <result column="oa_no" property="oaNo" />
  12. <result column="name" property="name" />
  13. <result column="cate" property="cate" />
  14. <result column="business_source" property="businessSource" />
  15. <result column="belong_to" property="belongTo" />
  16. <result column="client_unit" property="clientUnit" />
  17. <result column="client_name" property="clientName" />
  18. <result column="mobile" property="mobile" />
  19. <result column="client_manager" property="clientManager" />
  20. <result column="skiller" property="skiller" />
  21. <result column="sign_date" property="signDate" />
  22. <result column="payment_method" property="paymentMethod" />
  23. <result column="amount" property="amount" />
  24. <result column="state" property="state" />
  25. <result column="department_id" property="departmentId" />
  26. <result column="contract_url" property="contractUrl" />
  27. <result column="user_id" property="userId" />
  28. <result column="customer_id" property="customerId" />
  29. <collection property="userIds" ofType="java.lang.Long" select="selectItemUserId" column="id"/>
  30. </resultMap>
  31. <!-- 通用查询结果列 -->
  32. <sql id="Base_Column_List">
  33. i.id,
  34. i.deleted,
  35. i.created,
  36. i.modified,
  37. i.business_no, i.oa_no, i.name,i.cate, i.business_source,i.belong_to,i.client_unit,
  38. c.name as client_name, i.mobile, u.name as client_manager, i.skiller, i.sign_date,
  39. i.payment_method, i.amount, i.state,i.department_id,i.contract_url,i.user_id,i.customer_id , i.upload_date
  40. </sql>
  41. <sql id="Common_query_item">
  42. SELECT
  43. <include refid="Base_Column_List"/>
  44. , d.name as departmentName,dd1.name as cateName,dd2.name as businessSourceName,
  45. (select name from item_stage s where curDate() &gt;= s.start_date and curDate() &lt;= s.end_date and s.item_id = i.id) as stageName,
  46. ( SELECT
  47. s.id
  48. FROM
  49. item_stage s
  50. WHERE
  51. curDate() &gt;= s.start_date
  52. AND curDate() &lt;= s.end_date
  53. AND s.item_id = i.id
  54. ) AS stageId,
  55. ( CASE when (
  56. i.state = '暂停'
  57. ) then '暂停'
  58. when (
  59. i.state = '终止'
  60. ) then '终止'
  61. when ((SELECT count(*) FROM item_stage s
  62. WHERE
  63. s.item_id = i.id
  64. AND curDate() &gt;= ( SELECT min( start_date ) FROM item_stage WHERE item_id = i.id )
  65. AND curDate() &lt;= ( SELECT max( end_date ) FROM item_stage WHERE item_id = i.id )
  66. )=0
  67. AND
  68. ( SELECT count(*) FROM item_stage s WHERE s.item_id = i.id ) !=0 )
  69. THEN
  70. '已完成'
  71. WHEN
  72. (SELECT
  73. count(*)
  74. FROM
  75. item_stage s
  76. WHERE
  77. s.item_id = i.id
  78. AND curDate() &gt;= ( SELECT min( start_date ) FROM item_stage WHERE item_id = i.id )
  79. AND curDate() &lt;= ( SELECT max( end_date ) FROM item_stage WHERE item_id = i.id ) )
  80. !=0
  81. THEN
  82. '进行中'
  83. WHEN
  84. (SELECT
  85. count(*)
  86. FROM
  87. item_stage s
  88. WHERE
  89. s.item_id = i.id)= 0
  90. THEN
  91. '未开始'
  92. ELSE ''
  93. END
  94. ) AS itemStatus
  95. FROM
  96. item i left join department d on i.department_id = d.id left join dict_data dd1 on i.cate = dd1.id and dd1.deleted =0
  97. left join dict_data dd2 on i.business_source = dd2.id and dd2.deleted = 0 left join user u on u.id = i.user_id left join customer c on c.id = i.customer_id
  98. where i.deleted = 0
  99. </sql>
  100. <select id="stat" resultType="com.dayou.vo.ItemStatVO">
  101. SELECT
  102. ( SELECT count(*) FROM item WHERE state = '已完成' AND deleted = 0 ) AS doneNum,
  103. ( SELECT count(*) FROM item WHERE state = '进行中' AND deleted = 0 ) AS pendingNum,
  104. ( SELECT count(*) FROM item WHERE state = '未开始' AND deleted = 0 ) AS unplayedNum
  105. FROM
  106. item
  107. WHERE
  108. deleted =0
  109. </select>
  110. <select id="xDetail" parameterType="java.lang.Long" resultMap="BaseResultMap">
  111. select <include refid="Base_Column_List"/>, d.name as departmentName
  112. from item i left join department d on d.id = i.department_id left join user u on u.id = i.user_id
  113. left join customer c on c.id = i.customer_id
  114. where i.deleted = 0 and i.id =#{id}
  115. </select>
  116. <select id="selectItemUserId" parameterType="java.lang.Long" resultType="java.lang.Long">
  117. select user_id from item_user where item_id = #{id}
  118. </select>
  119. <select id="getPage" resultType="com.dayou.vo.ItemVO">
  120. <include refid="Common_query_item"/>
  121. <if test="item!=null and item.name!=null and item.name!='' ">
  122. and i.name like concat ('%',#{item.name},'%')
  123. </if>
  124. <if test="item!=null and item.cate!=null and item.cate!='' ">
  125. and i.cate =#{item.cate}
  126. </if>
  127. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  128. and i.business_no like concat (#{item.businessNo},'%')
  129. </if>
  130. <if test="item!=null and item.isCurYear!=null and item.isCurYear==true">
  131. AND i.upload_date &gt;= concat( YEAR ( now())- 1, '-12-23' )
  132. AND i.upload_date &lt;= concat( YEAR ( now()), '-12-22' )
  133. </if>
  134. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  135. and u.name like concat ('%',#{item.clientManager},'%')
  136. </if>
  137. <if test="item!=null and item.skiller!=null and item.skiller!='' ">
  138. and i.skiller =#{item.skiller}
  139. </if>
  140. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  141. and i.user_id in
  142. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  143. #{userId}
  144. </foreach>
  145. </if>
  146. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  147. and i.department_id in
  148. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  149. #{departmentId}
  150. </foreach>
  151. </if>
  152. <if test="item!=null and item.state!=null and item.state!='' ">
  153. GROUP BY i.id
  154. HAVING itemStatus =#{item.state}
  155. </if>
  156. order by i.upload_date desc ,i.id DESC
  157. </select>
  158. <select id="getXPage" resultType="com.dayou.vo.ItemVO">
  159. <include refid="Common_query_item"/>
  160. <if test="item!=null and item.name!=null and item.name!='' ">
  161. and i.name like concat ('%',#{item.name},'%')
  162. </if>
  163. <if test="item!=null and item.cate!=null and item.cate!='' ">
  164. and i.cate =#{item.cate}
  165. </if>
  166. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  167. and i.business_no like concat (#{item.businessNo},'%')
  168. </if>
  169. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  170. and u.name like concat ('%',#{item.clientManager},'%')
  171. </if>
  172. <if test="item!=null and item.skiller!=null and item.skiller!='' ">
  173. and i.skiller =#{item.skiller}
  174. </if>
  175. <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size==0">
  176. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  177. and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  178. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  179. #{userId}
  180. </foreach>
  181. )
  182. </if>
  183. </if>
  184. <if test="item!=null and item.userIds!=null and item.userIds.size==0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  185. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  186. and i.department_id in
  187. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  188. #{departmentId}
  189. </foreach>
  190. </if>
  191. </if>
  192. <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  193. and (
  194. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  195. EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  196. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  197. #{userId}
  198. </foreach>
  199. )
  200. </if>
  201. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  202. or i.department_id in
  203. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  204. #{departmentId}
  205. </foreach>
  206. </if>
  207. )
  208. </if>
  209. <if test="item!=null and item.state!=null and item.state!='' ">
  210. GROUP BY i.id
  211. HAVING itemStatus =#{item.state}
  212. </if>
  213. order by i.upload_date desc ,i.id DESC
  214. </select>
  215. <select id="xSelectList" parameterType="com.dayou.vo.ItemStageVO" resultType="com.dayou.vo.ItemVO">
  216. <include refid="Common_query_item"/>
  217. and i.state is null
  218. <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size==0">
  219. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  220. and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  221. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  222. #{userId}
  223. </foreach>
  224. )
  225. </if>
  226. </if>
  227. <if test="item!=null and item.userIds!=null and item.userIds.size==0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  228. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  229. and i.department_id in
  230. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  231. #{departmentId}
  232. </foreach>
  233. </if>
  234. </if>
  235. <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  236. and (
  237. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  238. EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  239. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  240. #{userId}
  241. </foreach>
  242. )
  243. </if>
  244. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  245. or i.department_id in
  246. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  247. #{departmentId}
  248. </foreach>
  249. </if>
  250. )
  251. </if>
  252. <if test="item!=null and item.state!=null and item.state!='' ">
  253. GROUP BY i.id
  254. HAVING itemStatus =#{item.state}
  255. </if>
  256. order by i.upload_date desc ,i.id DESC
  257. </select>
  258. <select id="getLastMonthItems" resultType="com.dayou.entity.ItemBrokerageGeneral">
  259. select ibg.*
  260. FROM
  261. item i
  262. left join item_brokerage_general ibg on ibg.item_id = i.id
  263. WHERE
  264. i.deleted = 0
  265. and i.upload_date is not null
  266. AND i.upload_date &gt;= #{lastMonth23}
  267. AND i.upload_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
  268. AND i.user_id = #{userId}
  269. and ibg.marketer_status=#{marketerStatus}
  270. </select>
  271. <select id="getLastMonthItemsInStatus" resultType="com.dayou.entity.ItemBrokerageGeneral">
  272. select ibg.*
  273. FROM
  274. item i
  275. left join item_brokerage_general ibg on ibg.item_id = i.id
  276. WHERE
  277. i.deleted = 0
  278. and i.upload_date is not null
  279. AND i.upload_date &gt;= #{lastMonth23}
  280. AND i.upload_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
  281. AND i.user_id = #{userId}
  282. and ibg.marketer_status in ('TO_PREDICTING','NOT_PAYMENT')
  283. </select>
  284. <select id="xList" resultType="com.dayou.vo.ItemVO">
  285. <include refid="Common_query_item"/>
  286. <if test="item!=null and item.name!=null and item.name!='' ">
  287. and i.name like concat ('%',#{item.name},'%')
  288. </if>
  289. <if test="item!=null and item.cate!=null and item.cate!='' ">
  290. and i.cate =#{item.cate}
  291. </if>
  292. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  293. and i.business_no like concat (#{item.businessNo},'%')
  294. </if>
  295. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  296. and u.name like concat ('%',#{item.clientManager},'%')
  297. </if>
  298. <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size==0">
  299. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  300. and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  301. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  302. #{userId}
  303. </foreach>
  304. )
  305. </if>
  306. </if>
  307. <if test="item!=null and item.userIds!=null and item.userIds.size==0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  308. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  309. and i.department_id in
  310. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  311. #{departmentId}
  312. </foreach>
  313. </if>
  314. </if>
  315. <if test="item!=null and item.userIds!=null and item.userIds.size!=0 and item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  316. and (
  317. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  318. EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  319. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  320. #{userId}
  321. </foreach>
  322. )
  323. </if>
  324. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  325. or i.department_id in
  326. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  327. #{departmentId}
  328. </foreach>
  329. </if>
  330. )
  331. </if>
  332. <if test="item!=null and item.state!=null and item.state!='' ">
  333. GROUP BY i.id
  334. HAVING itemStatus =#{item.state}
  335. </if>
  336. order by i.upload_date desc ,i.id DESC
  337. </select>
  338. <select id="xMineList" resultType="com.dayou.vo.ItemVO">
  339. <include refid="Common_query_item"/>
  340. <if test="item!=null and item.name!=null and item.name!='' ">
  341. and i.name like concat ('%',#{item.name},'%')
  342. </if>
  343. <if test="item!=null and item.cate!=null and item.cate!='' ">
  344. and i.cate =#{item.cate}
  345. </if>
  346. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  347. and i.business_no like concat (#{item.businessNo},'%')
  348. </if>
  349. <if test="item!=null and item.isCurYear!=null and item.isCurYear==true">
  350. AND i.upload_date &gt;= concat( YEAR ( now())- 1, '-12-23' )
  351. AND i.upload_date &lt;= concat( YEAR ( now()), '-12-22' )
  352. </if>
  353. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  354. and u.name like concat ('%',#{item.clientManager},'%')
  355. </if>
  356. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  357. and i.user_id in
  358. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  359. #{userId}
  360. </foreach>
  361. </if>
  362. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  363. and i.department_id in
  364. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  365. #{departmentId}
  366. </foreach>
  367. </if>
  368. <if test="item!=null and item.state!=null and item.state!='' ">
  369. GROUP BY i.id
  370. HAVING itemStatus =#{item.state}
  371. </if>
  372. order by i.upload_date desc ,i.id DESC
  373. </select>
  374. <select id="getItemByBrokerageGeneralId" parameterType="java.lang.Long" resultType="com.dayou.dto.ItemDTO">
  375. select <include refid="Base_Column_List"/>,ibg.brokerage_rate as ratio
  376. from item_brokerage_general ibg left join item i on i.id = ibg.item_id
  377. left join customer c on c.id = i.customer_id left join user u on u.id = i.user_id
  378. where i.deleted = 0 and ibg.deleted = 0 and ibg.id = #{generalId}
  379. </select>
  380. <select id="getLastMonthTeamItems" resultType="com.dayou.dto.ItemBrokerageGeneralDTO">
  381. select ibg.*,i.amount,i.user_id
  382. FROM
  383. item i
  384. left join item_brokerage_general ibg on ibg.item_id = i.id
  385. WHERE
  386. i.deleted = 0
  387. and i.upload_date is not null
  388. AND i.upload_date &gt;= #{lastMonth23}
  389. AND i.upload_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
  390. AND i.user_id in (
  391. <foreach collection="juniorUserIds" index="index" item="item" separator=",">
  392. #{item}
  393. </foreach>
  394. )
  395. and ibg.marketer_status != 'CLOSED'
  396. </select>
  397. <select id="getCompletedNotEvaluateItem" resultType="com.dayou.vo.ItemVO">
  398. SELECT
  399. i.id,
  400. i.user_id,
  401. i.name,
  402. ( CASE when ((SELECT count(*) FROM item_stage s
  403. WHERE
  404. s.item_id = i.id
  405. AND curDate() &gt;= ( SELECT min( start_date ) FROM item_stage WHERE item_id = i.id )
  406. AND curDate() &lt;= ( SELECT max( end_date ) FROM item_stage WHERE item_id = i.id )
  407. )=0
  408. AND
  409. ( SELECT count(*) FROM item_stage s WHERE s.item_id = i.id ) !=0 )
  410. THEN
  411. '已完成'
  412. WHEN
  413. (SELECT
  414. count(*)
  415. FROM
  416. item_stage s
  417. WHERE
  418. s.item_id = i.id
  419. AND curDate() &gt;= ( SELECT min( start_date ) FROM item_stage WHERE item_id = i.id )
  420. AND curDate() &lt;= ( SELECT max( end_date ) FROM item_stage WHERE item_id = i.id ) )
  421. !=0
  422. THEN
  423. '进行中'
  424. WHEN
  425. (SELECT
  426. count(*)
  427. FROM
  428. item_stage s
  429. WHERE
  430. s.item_id = i.id)= 0
  431. THEN
  432. '未开始'
  433. ELSE ''
  434. END
  435. ) AS itemStatus
  436. FROM
  437. item i
  438. WHERE
  439. i.deleted = 0 and i.state is null
  440. GROUP BY
  441. i.id
  442. HAVING
  443. itemStatus = '已完成'
  444. AND NOT EXISTS ( SELECT id FROM item_evaluate WHERE item_id = i.id AND deleted = 0 )
  445. </select>
  446. </mapper>