ItemMapper.xml 20 KB

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