123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.example.nngkxxdp.dao.CanteenDao">
- <resultMap type="com.example.nngkxxdp.entity.CanteenDO" id="CanteenMap">
- <result property="id" column="id" jdbcType="VARCHAR"/>
- <result property="canteenName" column="canteen_name" jdbcType="VARCHAR"/>
- <result property="canteenPhotoPath" column="canteen_photo_path" jdbcType="VARCHAR"/>
- <result property="supplyTimeId" column="supply_time_id" jdbcType="VARCHAR"/>
- <result property="founder" column="founder" jdbcType="INTEGER"/>
- <result property="principal" column="principal" jdbcType="VARCHAR"/>
- <result property="complaintPhone" column="complaint_phone" jdbcType="VARCHAR"/>
- <result property="takeoutPhone" column="takeout_phone" jdbcType="VARCHAR"/>
- <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
- <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
- <result property="isdel" column="isdel" jdbcType="INTEGER"/>
- </resultMap>
- <!--查询单个-->
- <select id="queryById" resultMap="CanteenMap">
- SELECT id,
- canteen_name,
- canteen_photo_path,
- supply_time_id,
- founder,
- principal,
- complaint_phone,
- takeout_phone,
- worker_id,
- create_time,
- update_time,
- isdel
- FROM s_canteen
- WHERE id = #{id}
- </select>
- <!--分页计数-->
- <select id="pageCount" resultType="java.lang.Long">
- SELECT COUNT(*)
- FROM s_canteen
- <where>
- s_canteen.isdel = 0
- <if test="canteenName != null and canteenName != ''">
- AND canteen_name LIKE CONCAT('%', #{canteenName}, '%')
- </if>
- </where>
- </select>
- <!--分页列表-->
- <select id="pageList" resultType="java.util.Map">
- SELECT
- s_canteen.id, canteen_name, canteen_photo_path, supply_time_id, u.user_name founder, s_canteen.principal,
- complaint_phone complaintPhone, takeout_phone takeoutPhone, s_canteen.create_time, s_canteen.update_time,worker_id,
- s_canteen.isdel
- FROM s_canteen
- LEFT JOIN p_user u
- ON u.id = s_canteen.founder
- <where>
- s_canteen.isdel = 0
- <if test="canteenName != null and canteenName != ''">
- AND canteen_name LIKE CONCAT('%', #{canteenName}, '%')
- </if>
- </where>
- ORDER BY s_canteen.create_time DESC
- LIMIT #{startRows}, #{limit}
- </select>
- <select id="detail" resultType="java.util.Map">
- select id,
- canteen_name,
- canteen_photo_path,
- supply_time_id
- from s_canteen
- where isdel = 0
- and id = #{canteenId}
- </select>
- <!--新增所有列-->
- <insert id="addSCanteen">
- INSERT INTO s_canteen(id, canteen_name, canteen_photo_path, supply_time_id, founder, principal,
- complaint_phone, takeout_phone, create_time, update_time, isdel,worker_id)
- VALUES (#{id}, #{canteenName}, #{canteenPhotoPath}, #{supplyTimeId}, #{founder}, #{principal},
- #{complaintPhone}, #{takeoutPhone}, #{createTime}, #{updateTime}, #{isdel},#{workerId})
- </insert>
- <!--通过主键修改数据-->
- <update id="updateSCanteen">
- UPDATE s_canteen
- <set>
- <if test="canteenName != null and canteenName != ''">
- canteen_name = #{canteenName},
- </if>
- canteen_photo_path = #{canteenPhotoPath},
- supply_time_id = #{supplyTimeId},
- takeout_phone = #{takeoutPhone},
- <if test="founder != null">
- founder = #{founder},
- </if>
- <if test="principal != null">
- principal = #{principal},
- </if>
- <if test="complaintPhone != null">
- complaint_phone = #{complaintPhone},
- </if>
- <if test="createTime != null">
- create_time = #{createTime},
- </if>
- <if test="updateTime != null">
- update_time = #{updateTime},
- </if>
- <if test="workerId !=null and workerId !=''">
- worker_id = #{workerId},
- </if>
- <if test="isdel != null">
- isdel = #{isdel},
- </if>
- </set>
- WHERE id = #{id}
- </update>
- <!--食堂是否存在菜单,菜品的计数-->
- <select id="deleteCount" resultType="java.lang.Long">
- SELECT SUM(a.b) num
- FROM (
- (SELECT COUNT(*) b
- FROM (SELECT 1
- FROM s_canteen
- INNER JOIN s_food sf ON sf.canteen_id = s_canteen.id
- WHERE s_canteen.id = #{id}
- LIMIT 1) food_num)
- UNION ALL
- (SELECT COUNT(*) b
- FROM (SELECT 1
- FROM s_canteen
- INNER JOIN s_menu sm ON sm.canteen_id = s_canteen.id
- WHERE s_canteen.id = #{id}
- LIMIT 1) menu_num)
- ) a
- </select>
- <!--通过主键删除-->
- <delete id="deleteSCanteenById">
- UPDATE s_canteen
- SET s_canteen.isdel = 1
- WHERE id = #{id}
- </delete>
- <select id="getAllCanteen" resultType="com.example.nngkxxdp.entity.CanteenNeDO">
- SELECT canteen_name,
- sc.id,
- sc.supply_time_id,
- sc.founder,
- sc.principal,
- sc.complaint_phone,
- sc.takeout_phone,
- sc.canteen_photo_path,
- sc.worker_id
- FROM s_canteen sc
- left join s_worker sw on sc.worker_id = sw.id
- WHERE sc.isdel = 0
- <if test="userId != null and userId != ''">
- AND sw.wx_user_id = #{userId}
- </if>
- </select>
- <select id="getAllDeliciousByDishesId" resultType="java.util.Map">
- SELECT se.id commentId,
- se.dishesId,
- ROUND(AVG(se.score), 0) score,
- COUNT(*) commentCount
- FROM `s_evaluation` se
- WHERE se.isdel = 0
- and se.isviolations = 0
- and se.canteenId = #{id}
- and YEARWEEK(date_format(se.create_time, '%Y-%m-%d'), 1) = YEARWEEK(DATE_SUB(now(),INTERVAL 7 DAY), 1)
- GROUP BY se.dishesId
- ORDER BY se.score DESC, commentCount DESC
- limit 3
- </select>
- <select id="getLatestComment" resultType="java.util.Map">
- select se.evaluation,
- sf.dishes_name,
- se.dishesId,
- sf.dishes_photo_path
- from s_evaluation se
- left join s_food sf on sf.id = se.dishesId
- where se.isdel = 0
- and se.isviolations = 0
- and se.dishesId = #{dishesId}
- and se.canteenId = #{canteenId}
- order by se.create_time DESC
- limit 1
- </select>
- </mapper>
|