CanteenDao.xml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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.example.nngkxxdp.dao.CanteenDao">
  4. <resultMap type="com.example.nngkxxdp.entity.CanteenDO" id="CanteenMap">
  5. <result property="id" column="id" jdbcType="VARCHAR"/>
  6. <result property="canteenName" column="canteen_name" jdbcType="VARCHAR"/>
  7. <result property="canteenPhotoPath" column="canteen_photo_path" jdbcType="VARCHAR"/>
  8. <result property="supplyTimeId" column="supply_time_id" jdbcType="VARCHAR"/>
  9. <result property="founder" column="founder" jdbcType="INTEGER"/>
  10. <result property="principal" column="principal" jdbcType="VARCHAR"/>
  11. <result property="complaintPhone" column="complaint_phone" jdbcType="VARCHAR"/>
  12. <result property="takeoutPhone" column="takeout_phone" jdbcType="VARCHAR"/>
  13. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  14. <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
  15. <result property="isdel" column="isdel" jdbcType="INTEGER"/>
  16. </resultMap>
  17. <!--查询单个-->
  18. <select id="queryById" resultMap="CanteenMap">
  19. SELECT id,
  20. canteen_name,
  21. canteen_photo_path,
  22. supply_time_id,
  23. founder,
  24. principal,
  25. complaint_phone,
  26. takeout_phone,
  27. worker_id,
  28. create_time,
  29. update_time,
  30. isdel
  31. FROM s_canteen
  32. WHERE id = #{id}
  33. </select>
  34. <!--分页计数-->
  35. <select id="pageCount" resultType="java.lang.Long">
  36. SELECT COUNT(*)
  37. FROM s_canteen
  38. <where>
  39. s_canteen.isdel = 0
  40. <if test="canteenName != null and canteenName != ''">
  41. AND canteen_name LIKE CONCAT('%', #{canteenName}, '%')
  42. </if>
  43. </where>
  44. </select>
  45. <!--分页列表-->
  46. <select id="pageList" resultType="java.util.Map">
  47. SELECT
  48. s_canteen.id, canteen_name, canteen_photo_path, supply_time_id, u.user_name founder, s_canteen.principal,
  49. complaint_phone complaintPhone, takeout_phone takeoutPhone, s_canteen.create_time, s_canteen.update_time,worker_id,
  50. s_canteen.isdel
  51. FROM s_canteen
  52. LEFT JOIN p_user u
  53. ON u.id = s_canteen.founder
  54. <where>
  55. s_canteen.isdel = 0
  56. <if test="canteenName != null and canteenName != ''">
  57. AND canteen_name LIKE CONCAT('%', #{canteenName}, '%')
  58. </if>
  59. </where>
  60. ORDER BY s_canteen.create_time DESC
  61. LIMIT #{startRows}, #{limit}
  62. </select>
  63. <select id="detail" resultType="java.util.Map">
  64. select id,
  65. canteen_name,
  66. canteen_photo_path,
  67. supply_time_id
  68. from s_canteen
  69. where isdel = 0
  70. and id = #{canteenId}
  71. </select>
  72. <!--新增所有列-->
  73. <insert id="addSCanteen">
  74. INSERT INTO s_canteen(id, canteen_name, canteen_photo_path, supply_time_id, founder, principal,
  75. complaint_phone, takeout_phone, create_time, update_time, isdel,worker_id)
  76. VALUES (#{id}, #{canteenName}, #{canteenPhotoPath}, #{supplyTimeId}, #{founder}, #{principal},
  77. #{complaintPhone}, #{takeoutPhone}, #{createTime}, #{updateTime}, #{isdel},#{workerId})
  78. </insert>
  79. <!--通过主键修改数据-->
  80. <update id="updateSCanteen">
  81. UPDATE s_canteen
  82. <set>
  83. <if test="canteenName != null and canteenName != ''">
  84. canteen_name = #{canteenName},
  85. </if>
  86. canteen_photo_path = #{canteenPhotoPath},
  87. supply_time_id = #{supplyTimeId},
  88. takeout_phone = #{takeoutPhone},
  89. <if test="founder != null">
  90. founder = #{founder},
  91. </if>
  92. <if test="principal != null">
  93. principal = #{principal},
  94. </if>
  95. <if test="complaintPhone != null">
  96. complaint_phone = #{complaintPhone},
  97. </if>
  98. <if test="createTime != null">
  99. create_time = #{createTime},
  100. </if>
  101. <if test="updateTime != null">
  102. update_time = #{updateTime},
  103. </if>
  104. <if test="workerId !=null and workerId !=''">
  105. worker_id = #{workerId},
  106. </if>
  107. <if test="isdel != null">
  108. isdel = #{isdel},
  109. </if>
  110. </set>
  111. WHERE id = #{id}
  112. </update>
  113. <!--食堂是否存在菜单,菜品的计数-->
  114. <select id="deleteCount" resultType="java.lang.Long">
  115. SELECT SUM(a.b) num
  116. FROM (
  117. (SELECT COUNT(*) b
  118. FROM (SELECT 1
  119. FROM s_canteen
  120. INNER JOIN s_food sf ON sf.canteen_id = s_canteen.id
  121. WHERE s_canteen.id = #{id}
  122. LIMIT 1) food_num)
  123. UNION ALL
  124. (SELECT COUNT(*) b
  125. FROM (SELECT 1
  126. FROM s_canteen
  127. INNER JOIN s_menu sm ON sm.canteen_id = s_canteen.id
  128. WHERE s_canteen.id = #{id}
  129. LIMIT 1) menu_num)
  130. ) a
  131. </select>
  132. <!--通过主键删除-->
  133. <delete id="deleteSCanteenById">
  134. UPDATE s_canteen
  135. SET s_canteen.isdel = 1
  136. WHERE id = #{id}
  137. </delete>
  138. <select id="getAllCanteen" resultType="com.example.nngkxxdp.entity.CanteenNeDO">
  139. SELECT canteen_name,
  140. sc.id,
  141. sc.supply_time_id,
  142. sc.founder,
  143. sc.principal,
  144. sc.complaint_phone,
  145. sc.takeout_phone,
  146. sc.canteen_photo_path,
  147. sc.worker_id
  148. FROM s_canteen sc
  149. left join s_worker sw on sc.worker_id = sw.id
  150. WHERE sc.isdel = 0
  151. <if test="userId != null and userId != ''">
  152. AND sw.wx_user_id = #{userId}
  153. </if>
  154. </select>
  155. <select id="getAllDeliciousByDishesId" resultType="java.util.Map">
  156. SELECT se.id commentId,
  157. se.dishesId,
  158. ROUND(AVG(se.score), 0) score,
  159. COUNT(*) commentCount
  160. FROM `s_evaluation` se
  161. WHERE se.isdel = 0
  162. and se.isviolations = 0
  163. and se.canteenId = #{id}
  164. and YEARWEEK(date_format(se.create_time, '%Y-%m-%d'), 1) = YEARWEEK(DATE_SUB(now(),INTERVAL 7 DAY), 1)
  165. GROUP BY se.dishesId
  166. ORDER BY se.score DESC, commentCount DESC
  167. limit 3
  168. </select>
  169. <select id="getLatestComment" resultType="java.util.Map">
  170. select se.evaluation,
  171. sf.dishes_name,
  172. se.dishesId,
  173. sf.dishes_photo_path
  174. from s_evaluation se
  175. left join s_food sf on sf.id = se.dishesId
  176. where se.isdel = 0
  177. and se.isviolations = 0
  178. and se.dishesId = #{dishesId}
  179. and se.canteenId = #{canteenId}
  180. order by se.create_time DESC
  181. limit 1
  182. </select>
  183. </mapper>