ItemUserLogMapper.xml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.ItemUserLogMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.ItemUserLog">
  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="item_id" property="itemId" />
  11. <result column="user_id" property="userId" />
  12. <result column="log_date" property="logDate" />
  13. <result column="task_situation" property="taskSituation" />
  14. </resultMap>
  15. <!-- 通用查询结果列 -->
  16. <sql id="Base_Column_List">
  17. iul.id,
  18. iul.deleted,
  19. iul.created,
  20. iul.modified,
  21. iul.item_id,
  22. iul.user_id,
  23. iul.log_date,
  24. iul.task_situation
  25. </sql>
  26. <sql id="log_collect">
  27. i.NAME AS itemName,
  28. u.NAME AS userName,
  29. iul.id,
  30. iul.deleted,
  31. iul.created,
  32. iul.modified,
  33. iul.item_id,
  34. iul.user_id,
  35. iul.log_date,
  36. iul.task_situation
  37. </sql>
  38. <select id="logListByUserId" parameterType="java.lang.Long" resultType="com.dayou.vo.ItemUserLogVO">
  39. SELECT
  40. <include refid="log_collect"/>,s.name as stageName
  41. FROM
  42. item_user_log iul
  43. INNER JOIN (
  44. SELECT
  45. distinct iu1.item_id,
  46. iu1.user_id
  47. FROM
  48. item_user iu1
  49. WHERE
  50. EXISTS ( SELECT item_id FROM item_user iu2 WHERE iu2.user_id = #{userId} AND iu1.item_id = iu2.item_id )) temp ON iul.item_id = temp.item_id
  51. AND iul.user_id = temp.user_id
  52. INNER JOIN item i ON i.id = temp.item_id
  53. INNER JOIN user u ON u.id = temp.user_id
  54. left join item_stage s on s.id = iul.stage_id
  55. WHERE
  56. u.deleted = 0
  57. AND i.deleted = 0
  58. AND iul.deleted = 0
  59. <choose>
  60. <when test="startDate!=null">
  61. and log_date &gt;= #{startDate}
  62. </when>
  63. <otherwise>
  64. and log_date &gt;= date_add(curDate(),INTERVAL -10 DAY)
  65. </otherwise>
  66. </choose>
  67. <choose>
  68. <when test="endDate!=null">
  69. and log_date &lt;= #{endDate}
  70. </when>
  71. <otherwise>
  72. and log_date &lt;= curDate()
  73. </otherwise>
  74. </choose>
  75. AND iul.item_id = #{itemId}
  76. </select>
  77. <select id="logListByDepartmentId" parameterType="java.lang.Long" resultType="com.dayou.vo.ItemUserLogVO">
  78. SELECT
  79. <include refid="log_collect"/>,s.name as stageName
  80. FROM
  81. item_user_log iul
  82. INNER JOIN
  83. ( select distinct up.user_id from user_post up where EXISTS
  84. ( select id from post where post.deleted=0
  85. and up.post_id =post.id
  86. <if test="departmentId!=null">
  87. and department_id = #{departmentId}
  88. </if>
  89. ) and up.deleted = 0) temp on temp.user_id = iul.user_id
  90. INNER JOIN item i ON i.id = iul.item_id
  91. INNER JOIN user u ON u.id = temp.user_id
  92. left join item_stage s on s.id = iul.stage_id
  93. WHERE
  94. u.deleted = 0
  95. AND i.deleted = 0
  96. AND iul.deleted = 0
  97. <choose>
  98. <when test="startDate!=null">
  99. and log_date &gt;= #{startDate}
  100. </when>
  101. <otherwise>
  102. and log_date &gt;= date_add(curDate(),INTERVAL -10 DAY)
  103. </otherwise>
  104. </choose>
  105. <choose>
  106. <when test="endDate!=null">
  107. and log_date &lt;= #{endDate}
  108. </when>
  109. <otherwise>
  110. and log_date &lt;= curDate()
  111. </otherwise>
  112. </choose>
  113. <if test="itemId!=null">
  114. and iul.item_id = #{itemId}
  115. </if>
  116. </select>
  117. <select id="page" parameterType="com.dayou.vo.ItemUserLogVO" resultType="com.dayou.vo.ItemUserLogVO">
  118. SELECT
  119. iul.id,iul.log_date as logDate,i.name as itemName ,iul.created,s.name as stageName
  120. FROM
  121. item_user_log iul left join item i on iul.item_id = i.id
  122. left join item_stage s on s.id = iul.stage_id
  123. where iul.deleted = 0 and i.deleted = 0 and iul.user_id = #{userId}
  124. <if test="itemUserLogVO!=null and itemUserLogVO.itemName!=null and itemUserLogVO.itemName!='' ">
  125. and i.name like concat ('%',#{itemUserLogVO.itemName},'%')
  126. </if>
  127. order by iul.log_date DESC
  128. </select>
  129. <select id="detail" parameterType="java.lang.Long" resultType="com.dayou.vo.ItemUserLogVO">
  130. SELECT
  131. <include refid="Base_Column_List"/> , i.name as itemName,s.name as stageName
  132. FROM
  133. item_user_log iul left join item i on iul.item_id = i.id left join item_stage s on s.id = iul.stage_id
  134. where iul.deleted = 0 and i.deleted = 0 and iul.id = #{logId}
  135. </select>
  136. <select id="getLogs" resultType="com.dayou.vo.ItemUserLogVO">
  137. SELECT
  138. iul.id,
  139. iul.item_id,
  140. iul.log_date,
  141. i.NAME AS itemName
  142. FROM
  143. item_user_log iul
  144. LEFT JOIN item i ON i.id = iul.item_id
  145. WHERE
  146. DATE_SUB( curDate(), INTERVAL 10 DAY ) &lt;= date( iul.log_date )
  147. AND iul.deleted = 0
  148. AND i.deleted = 0
  149. order by iul.log_date ASC
  150. </select>
  151. <select id="logStat" resultType="com.dayou.vo.LogStatVO">
  152. SELECT
  153. (select count(*) from item_user_log where log_date = curDate() and deleted = 0) as currentDayNum,
  154. (select count(*) from item_user_log where deleted = 0) as totalNum,
  155. (select u.name from item_user_log iul left join user u on u.id = iul.user_id where iul.deleted =0 and u.deleted = 0 order by iul.created DESC LIMIT 1) as userName,
  156. (select log_date from item_user_log where deleted =0 order by created DESC LIMIT 1) as logDate
  157. </select>
  158. </mapper>