LuckDrawLogMapper.xml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.ym.mec.biz.dal.dao.LuckDrawLogDao">
  4. <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.LuckDrawLog">
  5. <id column="id_" property="id" jdbcType="BIGINT" />
  6. <result column="group_id_" property="groupId" jdbcType="INTEGER" />
  7. <result column="prize_id_" property="prizeId" jdbcType="INTEGER" />
  8. <result column="user_id_" property="userId" jdbcType="BIGINT" />
  9. <result column="create_on_" property="createOn" jdbcType="TIMESTAMP" />
  10. <result column="name_" property="luckDrawPrize.name" jdbcType="VARCHAR" />
  11. <result column="reward_type_" property="luckDrawPrize.rewardType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
  12. <result column="tenant_id_" property="tenantId" />
  13. </resultMap>
  14. <resultMap id="BaseResultMapExt" type="com.ym.mec.biz.dal.entity.LuckDrawLog" extends="BaseResultMap">
  15. <result column="username_" property="user.username" jdbcType="VARCHAR" />
  16. <result column="phone_" property="user.phone" jdbcType="VARCHAR" />
  17. <result column="organ_name_" property="user.organName" jdbcType="VARCHAR" />
  18. </resultMap>
  19. <sql id="Base_Column_List">
  20. l.id_,l.group_id_, l.prize_id_,d.name_,d.reward_type_, l.user_id_, l.create_on_,l.tenant_id_
  21. </sql>
  22. <select id="get" resultMap="BaseResultMap" parameterType="java.lang.Long">
  23. select
  24. <include refid="Base_Column_List" />
  25. from luck_draw_log l left join luck_draw_prize d on
  26. l.prize_id_ = d.id_
  27. where l.id_ = #{id,jdbcType=BIGINT}
  28. </select>
  29. <delete id="delete" parameterType="java.lang.Long">
  30. delete from
  31. luck_draw_log
  32. where id_ = #{id,jdbcType=BIGINT}
  33. </delete>
  34. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.LuckDrawLog">
  35. insert into
  36. luck_draw_log (id_,group_id_, prize_id_, user_id_,
  37. create_on_,tenant_id_)
  38. values
  39. (#{id,jdbcType=BIGINT}, #{groupId,jdbcType=INTEGER}, #{prizeId,jdbcType=INTEGER},
  40. #{userId,jdbcType=BIGINT},
  41. #{createOn,jdbcType=TIMESTAMP},#{tenantId})
  42. </insert>
  43. <update id="update" parameterType="com.ym.mec.biz.dal.entity.LuckDrawLog">
  44. update luck_draw_log
  45. <set>
  46. <if test="groupId != null">
  47. group_id_ = #{groupId,jdbcType=INTEGER},
  48. </if>
  49. <if test="prizeId != null">
  50. prize_id_ = #{prizeId,jdbcType=INTEGER},
  51. </if>
  52. <if test="userId != null">
  53. user_id_ = #{userId,jdbcType=BIGINT},
  54. </if>
  55. <if test="createOn != null">
  56. create_on_ = #{createOn,jdbcType=TIMESTAMP},
  57. </if>
  58. </set>
  59. where id_ = #{id,jdbcType=BIGINT} and tenant_id_ = #{tenantId}
  60. </update>
  61. <select id="queryCount" parameterType="map" resultType="int">
  62. SELECT COUNT(*) FROM luck_draw_log l
  63. LEFT JOIN luck_draw_prize d ON l.prize_id_ = d.id_
  64. LEFT JOIN sys_user u ON u.id_=l.user_id_
  65. <include refid="queryCondition" />
  66. </select>
  67. <select id="queryPage" parameterType="map" resultMap="BaseResultMapExt">
  68. SELECT <include refid="Base_Column_List" />,u.username_,u.phone_,o.name_ organ_name_ FROM luck_draw_log l
  69. LEFT JOIN luck_draw_prize d ON l.prize_id_ = d.id_
  70. LEFT JOIN sys_user u ON u.id_=l.user_id_
  71. LEFT JOIN organization o ON o.id_ = u.organ_id_
  72. <include refid="queryCondition" />
  73. ORDER BY l.create_on_ DESC
  74. <include refid="global.limit" />
  75. </select>
  76. <select id="countUseNumByIds" resultType="java.lang.String">
  77. SELECT GROUP_CONCAT(DISTINCT ldp.name_) FROM luck_draw_log ldl
  78. LEFT JOIN luck_draw_prize ldp ON ldl.prize_id_ = ldp.id_
  79. WHERE ldl.prize_id_ IN
  80. <foreach collection="prizeIds" open="(" close=")" item="id" separator=",">
  81. #{id}
  82. </foreach>
  83. </select>
  84. <sql id="queryCondition">
  85. <where>
  86. l.tenant_id_ = #{tenantId}
  87. <if test="prizeId != null">
  88. AND l.prize_id_ = #{id}
  89. </if>
  90. <if test="userId != null">
  91. AND l.user_id_ = #{userId}
  92. </if>
  93. <if test="rewardType != null">
  94. AND d.reward_type_ LIKE CONCAT('%',#{rewardType},'%')
  95. </if>
  96. <if test="groupId != null">
  97. AND l.group_id_ = #{groupId}
  98. </if>
  99. <if test="name != null and name != ''">
  100. AND d.name_ = #{name}
  101. </if>
  102. <if test="startDate != null">
  103. AND l.create_on_ &gt;= #{startDate}
  104. </if>
  105. <if test="endDate != null">
  106. AND l.create_on_ &lt;= #{endDate}
  107. </if>
  108. <if test="organId != null">
  109. AND u.organ_id_ = #{organId}
  110. </if>
  111. <if test="defaultFlag != null">
  112. AND d.is_default_ = #{defaultFlag}
  113. </if>
  114. <if test="search != null and search != ''">
  115. AND (u.username_ LIKE CONCAT('%',#{search},'%') OR u.id_ = #{search})
  116. </if>
  117. </where>
  118. </sql>
  119. </mapper>