ItemMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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 from item i left join department d on d.id = i.department_id left join user u on u.id = i.user_id where i.deleted = 0 and i.id =#{id}
  105. </select>
  106. <select id="selectItemUserId" parameterType="java.lang.Long" resultType="java.lang.Long">
  107. select user_id from item_user where item_id = #{id}
  108. </select>
  109. <select id="getPage" resultType="com.dayou.vo.ItemVO">
  110. <include refid="Common_query_item"/>
  111. <if test="item!=null and item.name!=null and item.name!='' ">
  112. and i.name like concat ('%',#{item.name},'%')
  113. </if>
  114. <if test="item!=null and item.cate!=null and item.cate!='' ">
  115. and i.cate =#{item.cate}
  116. </if>
  117. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  118. and i.business_no like concat (#{item.businessNo},'%')
  119. </if>
  120. <if test="item!=null and item.isCurYear!=null and item.isCurYear==true">
  121. AND i.sign_date &gt;= concat( YEAR ( now())- 1, '-12-23' )
  122. AND i.sign_date &lt;= concat( YEAR ( now()), '-12-22' )
  123. </if>
  124. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  125. and u.name like concat ('%',#{item.clientManager},'%')
  126. </if>
  127. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  128. and i.user_id in
  129. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  130. #{userId}
  131. </foreach>
  132. </if>
  133. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  134. and i.department_id in
  135. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  136. #{departmentId}
  137. </foreach>
  138. </if>
  139. <if test="item!=null and item.state!=null and item.state!='' ">
  140. GROUP BY i.id
  141. HAVING itemStatus =#{item.state}
  142. </if>
  143. </select>
  144. <select id="getXPage" resultType="com.dayou.vo.ItemVO">
  145. <include refid="Common_query_item"/>
  146. <if test="item!=null and item.name!=null and item.name!='' ">
  147. and i.name like concat ('%',#{item.name},'%')
  148. </if>
  149. <if test="item!=null and item.cate!=null and item.cate!='' ">
  150. and i.cate =#{item.cate}
  151. </if>
  152. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  153. and i.business_no like concat (#{item.businessNo},'%')
  154. </if>
  155. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  156. and u.name like concat ('%',#{item.clientManager},'%')
  157. </if>
  158. <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">
  159. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  160. and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  161. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  162. #{userId}
  163. </foreach>
  164. )
  165. </if>
  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.departmentIds!=null and item.departmentIds.size!=0">
  169. and i.department_id in
  170. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  171. #{departmentId}
  172. </foreach>
  173. </if>
  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. and (
  177. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  178. 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 test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  185. or i.department_id in
  186. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  187. #{departmentId}
  188. </foreach>
  189. </if>
  190. )
  191. </if>
  192. <if test="item!=null and item.state!=null and item.state!='' ">
  193. GROUP BY i.id
  194. HAVING itemStatus =#{item.state}
  195. </if>
  196. </select>
  197. <select id="xSelectList" parameterType="com.dayou.vo.ItemStageVO" resultType="com.dayou.vo.ItemVO">
  198. <include refid="Common_query_item"/>
  199. <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">
  200. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  201. and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  202. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  203. #{userId}
  204. </foreach>
  205. )
  206. </if>
  207. </if>
  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.departmentIds!=null and item.departmentIds.size!=0">
  210. and i.department_id in
  211. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  212. #{departmentId}
  213. </foreach>
  214. </if>
  215. </if>
  216. <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">
  217. and (
  218. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  219. EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  220. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  221. #{userId}
  222. </foreach>
  223. )
  224. </if>
  225. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  226. or i.department_id in
  227. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  228. #{departmentId}
  229. </foreach>
  230. </if>
  231. )
  232. </if>
  233. <if test="item!=null and item.state!=null and item.state!='' ">
  234. GROUP BY i.id
  235. HAVING itemStatus =#{item.state}
  236. </if>
  237. </select>
  238. <select id="getLastMonthItems" resultType="com.dayou.entity.ItemBrokerageGeneral">
  239. select ibg.*
  240. FROM
  241. item i
  242. left join item_brokerage_general ibg on ibg.item_id = i.id
  243. WHERE
  244. i.deleted = 0
  245. and i.upload_date is not null
  246. AND i.upload_date &gt;= #{lastMonth23}
  247. AND i.upload_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
  248. AND i.user_id = #{userId}
  249. and ibg.marketer_status=#{marketerStatus}
  250. </select>
  251. <select id="getLastMonthItemsInStatus" resultType="com.dayou.entity.ItemBrokerageGeneral">
  252. select ibg.*
  253. FROM
  254. item i
  255. left join item_brokerage_general ibg on ibg.item_id = i.id
  256. WHERE
  257. i.deleted = 0
  258. and i.upload_date is not null
  259. AND i.upload_date &gt;= #{lastMonth23}
  260. AND i.upload_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
  261. AND i.user_id = #{userId}
  262. and ibg.marketer_status in ('TO_PREDICTING','NOT_PAYMENT')
  263. </select>
  264. <select id="xList" resultType="com.dayou.vo.ItemVO">
  265. <include refid="Common_query_item"/>
  266. <if test="item!=null and item.name!=null and item.name!='' ">
  267. and i.name like concat ('%',#{item.name},'%')
  268. </if>
  269. <if test="item!=null and item.cate!=null and item.cate!='' ">
  270. and i.cate =#{item.cate}
  271. </if>
  272. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  273. and i.business_no like concat (#{item.businessNo},'%')
  274. </if>
  275. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  276. and u.name like concat ('%',#{item.clientManager},'%')
  277. </if>
  278. <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">
  279. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  280. and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  281. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  282. #{userId}
  283. </foreach>
  284. )
  285. </if>
  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.departmentIds!=null and item.departmentIds.size!=0">
  289. and i.department_id in
  290. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  291. #{departmentId}
  292. </foreach>
  293. </if>
  294. </if>
  295. <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">
  296. and (
  297. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  298. EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  299. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  300. #{userId}
  301. </foreach>
  302. )
  303. </if>
  304. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  305. or i.department_id in
  306. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  307. #{departmentId}
  308. </foreach>
  309. </if>
  310. )
  311. </if>
  312. <if test="item!=null and item.state!=null and item.state!='' ">
  313. GROUP BY i.id
  314. HAVING itemStatus =#{item.state}
  315. </if>
  316. order by i.id DESC
  317. </select>
  318. <select id="xMineList" resultType="com.dayou.vo.ItemVO">
  319. <include refid="Common_query_item"/>
  320. <if test="item!=null and item.name!=null and item.name!='' ">
  321. and i.name like concat ('%',#{item.name},'%')
  322. </if>
  323. <if test="item!=null and item.cate!=null and item.cate!='' ">
  324. and i.cate =#{item.cate}
  325. </if>
  326. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  327. and i.business_no like concat (#{item.businessNo},'%')
  328. </if>
  329. <if test="item!=null and item.isCurYear!=null and item.isCurYear==true">
  330. AND i.sign_date &gt;= concat( YEAR ( now())- 1, '-12-23' )
  331. AND i.sign_date &lt;= concat( YEAR ( now()), '-12-22' )
  332. </if>
  333. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  334. and u.name like concat ('%',#{item.clientManager},'%')
  335. </if>
  336. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  337. and i.user_id in
  338. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  339. #{userId}
  340. </foreach>
  341. </if>
  342. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  343. and i.department_id in
  344. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  345. #{departmentId}
  346. </foreach>
  347. </if>
  348. <if test="item!=null and item.state!=null and item.state!='' ">
  349. GROUP BY i.id
  350. HAVING itemStatus =#{item.state}
  351. </if>
  352. order by i.id DESC
  353. </select>
  354. <select id="getItemByBrokerageGeneralId" parameterType="java.lang.Long" resultType="com.dayou.dto.ItemDTO">
  355. select <include refid="Base_Column_List"/>,ibg.brokerage_rate as ratio from item_brokerage_general ibg left join item i on i.id = ibg.item_id where i.deleted = 0 and ibg.deleted = 0 and ibg.id = #{generalId}
  356. </select>
  357. <select id="getLastMonthTeamItems" resultType="com.dayou.dto.ItemBrokerageGeneralDTO">
  358. select ibg.*,i.amount,i.user_id
  359. FROM
  360. item i
  361. left join item_brokerage_general ibg on ibg.item_id = i.id
  362. WHERE
  363. i.deleted = 0
  364. and i.upload_date is not null
  365. AND i.upload_date &gt;= #{lastMonth23}
  366. AND i.upload_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
  367. AND i.user_id in (
  368. <foreach collection="juniorUserIds" index="index" item="item" separator=",">
  369. #{item}
  370. </foreach>
  371. )
  372. and ibg.marketer_status != 'CLOSED'
  373. </select>
  374. </mapper>