ItemMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. i.client_name, i.mobile, i.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. <select id="stat" resultType="com.dayou.vo.ItemStatVO">
  41. SELECT
  42. ( SELECT count(*) FROM item WHERE state = '已完成' AND deleted = 0 ) AS doneNum,
  43. ( SELECT count(*) FROM item WHERE state = '进行中' AND deleted = 0 ) AS pendingNum,
  44. ( SELECT count(*) FROM item WHERE state = '未开始' AND deleted = 0 ) AS unplayedNum
  45. FROM
  46. item
  47. WHERE
  48. deleted =0
  49. </select>
  50. <select id="xDetail" parameterType="java.lang.Long" resultMap="BaseResultMap">
  51. select <include refid="Base_Column_List"/>, d.name as departmentName from item i left join department d on d.id = i.department_id where i.deleted = 0 and i.id =#{id}
  52. </select>
  53. <select id="selectItemUserId" parameterType="java.lang.Long" resultType="java.lang.Long">
  54. select user_id from item_user where item_id = #{id}
  55. </select>
  56. <select id="getPage" resultType="com.dayou.vo.ItemVO">
  57. SELECT
  58. <include refid="Base_Column_List"/> , d.name as departmentName,dd1.name as cateName,dd2.name as businessSourceName,
  59. (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,
  60. (select id from item_stage s where curDate() &gt;= s.start_date and curDate() &lt;= s.end_date and s.item_id and s.item_id = i.id) as stageId
  61. FROM
  62. item i left join department d on i.department_id = d.id left join dict_data dd1 on i.cate = dd1.id
  63. left join dict_data dd2 on i.business_source = dd2.id
  64. WHERE
  65. i.deleted = 0 and dd1.deleted =0 and dd2.deleted = 0
  66. <if test="item!=null and item.name!=null and item.name!='' ">
  67. and i.name like concat ('%',#{item.name},'%')
  68. </if>
  69. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  70. and i.business_no like concat (#{item.businessNo},'%')
  71. </if>
  72. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  73. and i.client_manager like concat ('%',#{item.clientManager},'%')
  74. </if>
  75. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  76. and i.user_id in
  77. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  78. #{userId}
  79. </foreach>
  80. </if>
  81. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  82. and i.department_id in
  83. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  84. #{departmentId}
  85. </foreach>
  86. </if>
  87. </select>
  88. <select id="getXPage" resultType="com.dayou.vo.ItemVO">
  89. SELECT
  90. <include refid="Base_Column_List"/> , d.name as departmentName,dd1.name as cateName,dd2.name as businessSourceName,
  91. (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,
  92. (select id from item_stage s where curDate() &gt;= s.start_date and curDate() &lt;= s.end_date and s.item_id and s.item_id = i.id) as stageId
  93. FROM
  94. item i left join department d on i.department_id = d.id
  95. left join dict_data dd1 on i.cate = dd1.id
  96. left join dict_data dd2 on i.business_source = dd2.id
  97. WHERE
  98. i.deleted = 0 and dd1.deleted =0 and dd2.deleted = 0
  99. <if test="item!=null and item.name!=null and item.name!='' ">
  100. and i.name like concat ('%',#{item.name},'%')
  101. </if>
  102. <if test="item!=null and item.businessNo!=null and item.businessNo!='' ">
  103. and i.business_no like concat (#{item.businessNo},'%')
  104. </if>
  105. <if test="item!=null and item.clientManager!=null and item.clientManager!='' ">
  106. and i.client_manager like concat ('%',#{item.clientManager},'%')
  107. </if>
  108. <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">
  109. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  110. and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  111. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  112. #{userId}
  113. </foreach>
  114. )
  115. </if>
  116. </if>
  117. <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">
  118. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  119. and i.department_id in
  120. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  121. #{departmentId}
  122. </foreach>
  123. </if>
  124. </if>
  125. <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">
  126. and (
  127. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  128. EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  129. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  130. #{userId}
  131. </foreach>
  132. )
  133. </if>
  134. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  135. or i.department_id in
  136. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  137. #{departmentId}
  138. </foreach>
  139. </if>
  140. )
  141. </if>
  142. </select>
  143. <select id="xSelectList" parameterType="com.dayou.vo.ItemStageVO" resultType="com.dayou.entity.Item">
  144. select <include refid="Base_Column_List"/> ,dd1.name as cateName,dd2.name as businessSourceName from item i left join dict_data dd1 on i.cate = dd1.id
  145. left join dict_data dd2 on i.business_source = dd2.id
  146. where i.deleted = 0 and dd1.deleted =0 and dd2.deleted = 0
  147. <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">
  148. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  149. and EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  150. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  151. #{userId}
  152. </foreach>
  153. )
  154. </if>
  155. </if>
  156. <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">
  157. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  158. and i.department_id in
  159. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  160. #{departmentId}
  161. </foreach>
  162. </if>
  163. </if>
  164. <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">
  165. and (
  166. <if test="item!=null and item.userIds!=null and item.userIds.size!=0">
  167. EXISTS ( SELECT item_id FROM item_user iu WHERE iu.item_id = i.id AND iu.user_id in
  168. <foreach collection="item.userIds" open="(" close=")" separator="," item="userId">
  169. #{userId}
  170. </foreach>
  171. )
  172. </if>
  173. <if test="item!=null and item.departmentIds!=null and item.departmentIds.size!=0">
  174. or i.department_id in
  175. <foreach collection="item.departmentIds" open="(" close=")" separator="," item="departmentId">
  176. #{departmentId}
  177. </foreach>
  178. </if>
  179. )
  180. </if>
  181. </select>
  182. </mapper>