GameAnswerMapper.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.api.games.dao.GameAnswerMapper">
  4. <resultMap id="BaseResultMap" type="com.api.games.model.GameAnswer">
  5. <!--
  6. WARNING - @mbg.generated
  7. -->
  8. <id column="id" jdbcType="BIGINT" property="id" />
  9. <result column="game_log_id" jdbcType="BIGINT" property="gameLogId" />
  10. <result column="answer" jdbcType="INTEGER" property="answer" />
  11. <result column="correct" jdbcType="INTEGER" property="correct" />
  12. <result column="reaction" jdbcType="DECIMAL" property="reaction" />
  13. <result column="show_num" jdbcType="INTEGER" property="showNum" />
  14. </resultMap>
  15. <select id="getAvgReaction" resultType="float">
  16. SELECT avg(reaction) FROM game_answer where game_log_id = #{id} and reaction > 0;
  17. </select>
  18. <select id="listByGameIdNew" resultMap="BaseResultMap">
  19. select * from game_answer where game_log_id =#{id}
  20. </select>
  21. <select id="listByGameId" resultType="com.api.common.mybatis.ResultMap">
  22. SELECT * fROM (select * from game_answer where game_log_id =#{id}) a
  23. left join game_log gl on (gl.id = a.game_log_id)
  24. left join sys_user sy on (sy.id = gl.user_id)
  25. left join user_config uc on (uc.user_id = gl.user_id)
  26. </select>
  27. <select id="statistics" resultType="com.api.common.mybatis.ResultMap">
  28. SELECT sum(case when answer=a.correct=show_num then 1 else 0 end)/count(*) as correctRate,avg(a.reaction) avg_reaction
  29. fROM game_answer as a
  30. left join game_log gl on (gl.id = a.game_log_id)
  31. left join sys_user sy on (sy.id = gl.user_id)
  32. left join user_config uc on (uc.user_id = gl.user_id)
  33. where 1=1
  34. <if test="gameId !=null">
  35. and game_log_id =#{gameId}
  36. </if>
  37. <if test="nickname!=null and nickname!=''">
  38. and sy.nickname = #{nickname}
  39. </if>
  40. <if test="startTime!=null and startTime!=''">
  41. and date(start_time) = #{startTime}
  42. </if>
  43. <if test="sign!=null and sign!=''">
  44. and sign = #{sign}
  45. </if>
  46. <if test="version!=null and version!=''">
  47. and version = #{version}
  48. </if>
  49. <if test="schedule!=null and schedule!=''">
  50. and schedule = #{schedule}
  51. </if>
  52. </select>
  53. <select id="list" resultType="com.api.common.mybatis.ResultMap">
  54. SELECT *,gl.id as gid fROM (select * from game_answer) a
  55. left join game_log gl on (gl.id = a.game_log_id)
  56. left join sys_user sy on (sy.id = gl.user_id)
  57. left join user_config uc on (uc.user_id = gl.user_id)
  58. where 1=1
  59. <if test="params.nickname!=null and params.nickname!=''">
  60. and sy.nickname = #{params.nickname}
  61. </if>
  62. <if test="params.gameId !=null">
  63. and game_log_id =#{gameId}
  64. </if>
  65. <if test="params.startTime!=null and params.startTime!=''">
  66. and date(start_time) = #{params.startTime}
  67. </if>
  68. <if test="params.sign!=null and params.sign!=''">
  69. and sign = #{params.sign}
  70. </if>
  71. <if test="params.version!=null and params.version!=''">
  72. and version = #{params.version}
  73. </if>
  74. <if test="params.schedule!=null and params.schedule!=''">
  75. and schedule = #{params.schedule}
  76. </if>
  77. order by 1
  78. <if test="order.nickname!=null and order.nickname!=''">
  79. ,sy.nickname ${order.nickname}
  80. </if>
  81. <if test="order.startTime!=null and order.startTime!=''">
  82. ,start_time ${order.startTime}
  83. </if>
  84. <if test="order.endTime!=null and order.endTime!=''">
  85. ,end_time ${order.endTime}
  86. </if>
  87. <if test="order.version!=null and order.version!=''">
  88. ,version ${order.version}
  89. </if>
  90. <if test="order.sign!=null and order.sign!=''">
  91. ,sign ${order.sign}
  92. </if>
  93. </select>
  94. </mapper>