ItemMapper.xml 20 KB

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