2021-07-31 15:22:06 +08:00

418 lines
24 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.stdiet.custom.mapper.SysWxUserLogMapper">
<resultMap type="SysWxUserLog" id="SysWxUserLogResult">
<result property="id" column="id"/>
<result property="openid" column="openid"/>
<result property="weight" column="weight"/>
<result property="appid" column="appid"/>
<result property="phone" column="phone"/>
<result property="phone" column="phone"/>
<result property="logTime" column="log_time"/>
<result property="wakeupTime" column="wakeup_time"/>
<result property="sleepTime" column="sleep_time"/>
<result property="sport" column="sport"/>
<result property="sportDesc" column="sport_desc"/>
<result property="avatarUrl" column="avatar_url"/>
<result property="diet" column="diet"/>
<result property="insomnia" column="insomnia"/>
<result property="defecation" column="defecation"/>
<result property="defecationDesc" column="defecation_desc"/>
<result property="water" column="water"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
<result property="emotion" column="emotion"/>
<result property="emotionDesc" column="emotion_desc"/>
<result property="slyEatFood" column="sly_eat_food"/>
<result property="constipation" column="constipation"/>
<result property="ingredientDesc" column="ingredient_desc"/>
<result property="breakfastImages" column="breakfast_images"/>
<result property="lunchImages" column="lunch_images"/>
<result property="dinnerImages" column="dinner_images"/>
<result property="extraMealImages" column="extra_meal_images"/>
<result property="bodyImages" column="body_images"/>
<result property="suggest" column="suggest"/>
<result property="targetWeight" column="target_weight"/>
<result property="executionScore" column="execution_score"/>
<result property="comment" column="comment"/>
<result property="thumbsupNum" column="thumbsup_num"/>
<result property="healthManifesto" column="health_manifesto"/>
<result property="delFlag" column="del_flag"/>
<!-- 非持久字段 -->
<result property="customerName" column="customer_name"></result>
<!-- 营养师 -->
<result property="nutritionist" column="nutritionist"></result>
<result property="afterNutritionist" column="after_nutritionist"></result>
</resultMap>
<resultMap type="com.stdiet.custom.page.WxLogInfo" id="WxLogInfo">
<result property="id" column="id"/>
<result property="weight" column="weight"/>
<result property="sleepTime" column="sleep_time"/>
<result property="wakeupTime" column="wakeup_time"/>
<result property="sport" column="sport"/>
<result property="sportDesc" column="sport_desc"/>
<result property="diet" column="diet"/>
<result property="insomnia" column="insomnia"/>
<result property="defecation" column="defecation"/>
<result property="defecationDesc" column="defecation_desc"/>
<result property="water" column="water"/>
<result property="date" column="log_time"/>
<result property="emotion" column="emotion"/>
<result property="emotionDesc" column="emotion_desc"/>
<result property="slyEatFood" column="sly_eat_food"/>
<result property="constipation" column="constipation"/>
<result property="remark" column="remark"/>
<result property="ingredientDesc" column="ingredient_desc"/>
<!-- <result property="breakfastImages" column="breakfast_images"/>-->
<result property="breakfastImagesUrl" column="breakfast_images" typeHandler="com.stdiet.custom.typehandler.ImagesHandler"/>
<!-- <result property="lunchImages" column="lunch_images"/>-->
<result property="lunchImagesUrl" column="lunch_images" typeHandler="com.stdiet.custom.typehandler.ImagesHandler"/>
<!-- <result property="dinnerImages" column="dinner_images"/>-->
<result property="dinnerImagesUrl" column="dinner_images" typeHandler="com.stdiet.custom.typehandler.ImagesHandler"/>
<!-- <result property="extraMealImages" column="extra_meal_images"/>-->
<result property="extraMealImagesUrl" column="extra_meal_images" typeHandler="com.stdiet.custom.typehandler.ImagesHandler"/>
<!-- <result property="bodyImages" column="body_images"/>-->
<result property="bodyImagesUrl" column="body_images" typeHandler="com.stdiet.custom.typehandler.ImagesHandler"/>
<result property="suggest" column="suggest"/>
<result property="targetWeight" column="target_weight"/>
<result property="executionScore" column="execution_score"/>
<result property="comment" column="comment"/>
<result property="thumbsupNum" column="thumbsup_num"/>
<result property="healthManifesto" column="health_manifesto"/>
</resultMap>
<sql id="selectSysWxUserLogVo">
select id,openid, weight, appid, phone, log_time, sleep_time, wakeup_time, sport, sport_desc, avatar_url, diet, insomnia, defecation, defecation_desc, water, create_by, create_time, update_by, update_time, remark,
emotion, emotion_desc,sly_eat_food,constipation,ingredient_desc,breakfast_images,lunch_images,dinner_images,extra_meal_images,body_images,suggest,execution_score,comment,health_manifesto
from sys_wx_user_log
</sql>
<select id="checkWxLogInfoCount" parameterType="SysWxUserLog" resultType="Integer">
select count(*) from sys_wx_user_log where to_days(log_time) = to_days(#{logTime}) and openid = #{openid} and del_flag = 0
</select>
<!-- 后台查询 -->
<select id="selectSysWxUserLogList" parameterType="SysWxUserLog" resultMap="SysWxUserLogResult">
SELECT
wxlog.id,wxinfo.appid,wxinfo.openid,wxinfo.avatar_url,wxinfo.phone,wxlog.weight,wxlog.log_time,wxlog.sleep_time,
wxlog.wakeup_time,wxlog.defecation, wxlog.defecation_desc, wxlog.water, wxlog.insomnia,wxlog.sport, wxlog.sport_desc,wxlog.diet,wxlog.remark,
wxlog.emotion, wxlog.emotion_desc,wxlog.sly_eat_food,wxlog.constipation,wxlog.ingredient_desc,wxlog.breakfast_images,
wxlog.lunch_images,wxlog.dinner_images,wxlog.extra_meal_images,wxlog.body_images,
wxlog.suggest,wxlog.execution_score,wxlog.comment,sc.name as customer_name, su.nick_name as nutritionist,
su_atferSale.nick_name as after_nutritionist, wxlog.health_manifesto, wxlog.log_time
FROM sys_wx_user_log wxlog
left join sys_wx_user_info wxinfo on wxinfo.openid = wxlog.openid
left join sys_customer sc on sc.phone = wxinfo.phone and sc.del_flag = 0
left join sys_user su on su.user_id = sc.main_dietitian and su.del_flag = '0'
left join sys_user su_atferSale on su_atferSale.user_id = sc.after_dietitian and su_atferSale.del_flag = '0'
where wxlog.del_flag = 0 and wxinfo.phone is not null
<if test="id != null">
and wxlog.id = #{id}
</if>
<if test="customerId != null">
and sc.id = #{customerId}
</if>
<if test="phone != null and phone != ''">and (sc.name like concat('%',#{phone},'%') or wxinfo.phone like
concat('%',#{phone},'%') )
</if>
<if test="appid != null">
and wxinfo.appid = #{appid}
</if>
<if test="nutritionistId != null">
and su.user_id = #{nutritionistId}
</if>
<if test="afterNutritionistId != null">
and su_atferSale.user_id = #{afterNutritionistId}
</if>
<if test="beginTime != null and beginTime != ''">and date_format(wxlog.log_time,'%y%m%d') &gt;=
date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''">and date_format(wxlog.log_time,'%y%m%d') &lt;=
date_format(#{endTime},'%y%m%d')
</if>
order by wxlog.log_time desc
</select>
<select id="selectWxLogInfoList" parameterType="SysWxUserLog" resultMap="WxLogInfo">
SELECT * FROM sys_wx_user_log log where log.del_flag = 0
<choose>
<when test="phone == null or phone == ''">
(SELECT phone FROM sys_wx_user_info WHERE openid = #{openid}) = log.phone
</when>
<otherwise>
<if test="openid != null and openid != ''">and openid = #{openid}</if>
<if test="phone != null and phone != ''">or phone = #{phone}</if>
</otherwise>
</choose>
order by log_time asc
</select>
<select id="selectSysWxUserLogById" parameterType="String" resultMap="SysWxUserLogResult">
<include refid="selectSysWxUserLogVo"/>
where id = #{id} and del_flag = 0
</select>
<insert id="insertSysWxUserLog" parameterType="SysWxUserLog">
insert into sys_wx_user_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="openid != null">openid,</if>
<if test="weight != null">weight,</if>
<if test="appid != null">appid,</if>
<if test="phone != null">phone,</if>
<if test="true">log_time,</if>
<if test="sleepTime != null">sleep_time,</if>
<if test="wakeupTime != null">wakeup_time,</if>
<if test="sport != null">sport,</if>
<if test="sportDesc != null">sport_desc,</if>
<if test="avatarUrl != null">avatar_url,</if>
<if test="diet != null">diet,</if>
<if test="insomnia != null">insomnia,</if>
<if test="defecation != null">defecation,</if>
<if test="defecationDesc != null">defecation_desc,</if>
<if test="water != null">water,</if>
<if test="createBy != null">create_by,</if>
<if test="true">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="true">update_time,</if>
<if test="remark != null">remark,</if>
<if test="emotion != null">emotion,</if>
<if test="emotionDesc != null">emotion_desc,</if>
<if test="slyEatFood != null">sly_eat_food,</if>
<if test="constipation != null">constipation,</if>
<if test="ingredientDesc != null">ingredient_desc,</if>
<if test="breakfastImages != null">breakfast_images,</if>
<if test="lunchImages != null">lunch_images,</if>
<if test="dinnerImages != null">dinner_images,</if>
<if test="extraMealImages != null">extra_meal_images,</if>
<if test="bodyImages != null">body_images,</if>
<if test="suggest != null">suggest,</if>
<if test="targetWeight != null">target_weight,</if>
<if test="executionScore != null">execution_score,</if>
<if test="comment != null">comment,</if>
<if test="thumbsupNum != null">thumbsup_num,</if>
<if test="healthManifesto != null">health_manifesto,</if>
<if test="delFlag != null">del_flag,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="openid != null">#{openid},</if>
<if test="weight != null">#{weight},</if>
<if test="appid != null">#{appid},</if>
<if test="phone != null">#{phone},</if>
<if test="true">now(),</if>
<if test="sleepTime != null">#{sleepTime},</if>
<if test="wakeupTime != null">#{wakeupTime},</if>
<if test="sport != null">#{sport},</if>
<if test="sportDesc != null">#{sportDesc},</if>
<if test="avatarUrl != null">#{avatarUrl},</if>
<if test="diet != null">#{diet},</if>
<if test="insomnia != null">#{insomnia},</if>
<if test="defecation != null">#{defecation},</if>
<if test="defecationDesc != null">#{defecationDesc},</if>
<if test="water != null">#{water},</if>
<if test="createBy != null">#{createBy},</if>
<if test="true">now(),</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="true">now(),</if>
<if test="remark != null">#{remark},</if>
<if test="emotion != null">#{emotion},</if>
<if test="emotionDesc != null">#{emotionDesc},</if>
<if test="slyEatFood != null">#{slyEatFood},</if>
<if test="constipation != null">#{constipation},</if>
<if test="ingredientDesc != null">#{ingredientDesc},</if>
<if test="breakfastImages != null">#{breakfastImages},</if>
<if test="lunchImages != null">#{lunchImages},</if>
<if test="dinnerImages != null">#{dinnerImages},</if>
<if test="extraMealImages != null">#{extraMealImages},</if>
<if test="bodyImages != null">#{bodyImages},</if>
<if test="suggest != null">suggest = #{suggest},</if>
<if test="targetWeight != null">target_weight = #{targetWeight},</if>
<if test="executionScore != null">execution_score = #{executionScore},</if>
<if test="comment != null">comment = #{comment},</if>
<if test="thumbsupNum != null">#{thumbsupNum},</if>
<if test="healthManifesto != null">#{healthManifesto},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
</trim>
</insert>
<update id="updateSysWxUserLog" parameterType="SysWxUserLog">
update sys_wx_user_log
<trim prefix="SET" suffixOverrides=",">
<if test="openid != null">openid = #{openid},</if>
<if test="weight != null">weight = #{weight},</if>
<if test="appid != null">appid = #{appid},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="sleepTime != null">sleep_time = #{sleepTime},</if>
<if test="wakeupTime != null">wakeup_time = #{wakeupTime},</if>
<if test="sport != null">sport = #{sport},</if>
<if test="sportDesc != null">sport_desc = #{sportDesc},</if>
<if test="avatarUrl != null">avatar_url = #{avatarUrl},</if>
<if test="diet != null">diet = #{diet},</if>
<if test="insomnia != null">insomnia = #{insomnia},</if>
<if test="defecation != null">defecation = #{defecation},</if>
<if test="defecationDesc != null">defecation_desc = #{defecationDesc},</if>
<if test="water != null">water = #{water},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = now(),</if>
<if test="remark != null">remark = #{remark},</if>
<if test="emotion != null">emotion = #{emotion},</if>
<if test="emotionDesc != null">emotion_desc = #{emotionDesc},</if>
<if test="slyEatFood != null">sly_eat_food = #{slyEatFood},</if>
<if test="constipation != null">constipation = #{constipation},</if>
<if test="ingredientDesc != null">ingredient_desc = #{ingredientDesc},</if>
<if test="breakfastImages != null">breakfast_images = #{breakfastImages},</if>
<if test="lunchImages != null">lunch_images = #{lunchImages},</if>
<if test="dinnerImages != null">dinner_images = #{dinnerImages},</if>
<if test="extraMealImages != null">extra_meal_images = #{extraMealImages},</if>
<if test="bodyImages != null">body_images = #{bodyImages},</if>
<if test="suggest != null">suggest = #{suggest},</if>
<if test="targetWeight != null">target_weight = #{targetWeight},</if>
<if test="executionScore != null">execution_score = #{executionScore},</if>
<if test="comment != null">comment = #{comment},</if>
<if test="thumbsupNum != null">thumbsup_num = #{thumbsupNum},</if>
<if test="healthManifesto != null">health_manifesto = #{healthManifesto},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
</trim>
where id = #{id}
</update>
<update id="deleteSysWxUserLogById" parameterType="Long">
update sys_wx_user_log set del_flag = 1 where id = #{id}
</update>
<update id="deleteSysWxUserLogByIds" parameterType="String">
update sys_wx_user_log set del_flag = 1 where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<!-- 根据openid和手机号查询对应打卡记录 -->
<select id="getWxLogInfoList" parameterType="SysWxUserLog" resultMap="WxLogInfo">
SELECT wxlog.id,wxlog.weight,wxlog.log_time,wxlog.sleep_time, wxlog.wakeup_time,wxlog.defecation, wxlog.defecation_desc, wxlog.water, wxlog.insomnia,wxlog.sport, wxlog.sport_desc,wxlog.diet,
wxlog.emotion, wxlog.emotion_desc,wxlog.sly_eat_food,wxlog.constipation,wxlog.ingredient_desc,wxlog.breakfast_images,wxlog.lunch_images,wxlog.dinner_images,wxlog.extra_meal_images,wxlog.body_images
,wxlog.remark,wxlog.execution_score,wxlog.comment, wxlog.health_manifesto
FROM sys_wx_user_log wxlog
where wxlog.del_flag = 0 and wxlog.openid = #{openid}
order by wxlog.log_time asc
</select>
<select id="selectSysWxUserLogByDateAndOpenId" parameterType="SysWxUserLog" resultMap="SysWxUserLogResult">
select id from sys_wx_user_log where del_flag = 0 and to_days(log_time) = to_days(#{logTime}) and openid = #{openid} limit 1
</select>
<!-- 根据手机号和openid查询打卡连续天数只查询前两条 -->
<select id="getContinuity" parameterType="SysWxUserLog" resultType="Map">
SELECT yearMonth,MIN(log_time) AS minLogTime,MAX(log_time) AS maxLogTime,COUNT(*) AS continuityDayCount FROM
(
SELECT log_time,yearMonth,(days-date_rank) AS day_cha FROM
(
SELECT *,row_number() over(PARTITION BY yearMonth ORDER BY log_time) date_rank FROM
(
SELECT log_time,CONCAT(YEAR(log_time),'-',MONTH(log_time)) AS yearMonth,DAY(log_time) AS days
FROM sys_wx_user_log wxlog left join sys_wx_user_info wxinfo on wxinfo.openid = wxlog.openid
where wxlog.del_flag = 0 and wxinfo.openid = #{openid} or wxinfo.phone = #{phone}
) AS s ORDER BY s.log_time DESC
) ss
) sss GROUP BY yearMonth,day_cha LIMIT 2
</select>
<!-- 后台根据用户ID查询该用户的打卡体重 -->
<select id="getWxUserLogListByCustomerId" parameterType="SysWxUserLog" resultMap="SysWxUserLogResult">
SELECT wxlog.id,wxlog.log_time,wxlog.weight FROM sys_wx_user_log wxlog
left join sys_wx_user_info wxinfo on wxinfo.openid = wxlog.openid
left join sys_customer sc on sc.phone = wxinfo.phone and sc.del_flag = 0
where wxlog.del_flag = 0 and wxinfo.phone is not null and sc.id = #{customerId}
<if test="beginTime != null and beginTime != ''">and date_format(wxlog.log_time,'%y%m%d') &gt;=
date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''">and date_format(wxlog.log_time,'%y%m%d') &lt;=
date_format(#{endTime},'%y%m%d')
</if>
order by wxlog.log_time asc
</select>
<!-- 根据openid和手机号查询对应打卡记录 -->
<select id="getWxLogInfoDetailById" parameterType="SysWxUserLog" resultMap="WxLogInfo">
SELECT wxlog.id,wxlog.weight,wxlog.log_time,wxlog.sleep_time, wxlog.wakeup_time,wxlog.defecation, wxlog.defecation_desc, wxlog.water, wxlog.insomnia,wxlog.sport, wxlog.sport_desc,wxlog.diet,
wxlog.emotion, wxlog.emotion_desc,wxlog.sly_eat_food,wxlog.constipation,wxlog.ingredient_desc,wxlog.breakfast_images,wxlog.lunch_images,wxlog.dinner_images,wxlog.extra_meal_images,wxlog.body_images
,wxlog.remark,wxlog.execution_score,wxlog.comment
FROM sys_wx_user_log wxlog left join sys_wx_user_info wxinfo on wxinfo.openid = wxlog.openid
where wxlog.del_flag = 0 and wxlog.id = #{id}
order by wxlog.log_time desc
</select>
<resultMap id="punchReponseMap" type="com.stdiet.custom.dto.response.CommunityPunchReponse">
<result property="id" column="id" typeHandler="com.stdiet.custom.typehandler.EncryptedIdHandler"/>
<result property="openid" column="openid"/>
<result property="nickName" column="nick_name"/>
<result property="avatarUrl" column="avatar_url"/>
<result property="logTime" column="log_time"/>
<result property="weight" column="weight"/>
<result property="comment" column="comment"/>
<result property="healthManifesto" column="health_manifesto"/>
<association property="thumbsupNum" column="id" select="getPunchThumbsupCount"/>
<!-- 查询最近五天体重 -->
<association property="weightData" column="{id=openid}" select="getRecentWeight"/>
<!-- 查询点赞的openid -->
<association property="thumbsupUser" column="id" select="getPunchThumbsupList"/>
</resultMap>
<!-- 查询打卡社区内容 -->
<select id="getCommunityPunch" resultMap="punchReponseMap" parameterType="SysWxUserLog">
SELECT * FROM
(SELECT id, openid, `comment`, health_manifesto, log_time FROM sys_wx_user_log WHERE TO_DAYS(log_time) = TO_DAYS(NOW()) AND del_flag = 0) AS wxlog
LEFT JOIN (SELECT openid, nick_name, avatar_url FROM sys_wx_user_info) AS wxinfo
USING(openid)
ORDER BY log_time DESC
</select>
<!-- 查询打卡社区中点赞的openid -->
<!-- <select id="getPunchThumbsupList" parameterType="Long" resultType="Map">-->
<!-- select * from-->
<!-- (select id, cus_openid as openid, DATE_FORMAT(create_time,'%Y-%m-%d %H:%i') as `time` from sys_punch_thumbsup where punch_id = #{id} and del_flag = 0 order by create_time asc) as tu-->
<!-- left join (SELECT openid, nick_name as nickName, avatar_url as avatarUrl FROM sys_wx_user_info) AS wxinfo-->
<!-- using(openid)-->
<!-- </select>-->
<resultMap id="thumbupUserResultMap" type="Map">
<result property="id" column="id" typeHandler="com.stdiet.custom.typehandler.EncryptedIdHandler"/>
<result property="openid" column="cus_openid"/>
</resultMap>
<select id="getPunchThumbsupList" parameterType="Long" resultMap="thumbupUserResultMap">
select id, cus_openid from sys_punch_thumbsup where punch_id = #{id} and del_flag = 0
</select>
<select id="getPunchThumbsupCount" parameterType="Long" resultType="Integer">
select count(*) from sys_punch_thumbsup where punch_id = #{id} and del_flag = 0
</select>
<!-- 查询所有打卡体重 -->
<select id="getRecentWeight" resultType="Map">
select DATE_FORMAT(log_time,'%Y-%m-%d') as name, weight as `value` from sys_wx_user_log
where del_flag = 0 and openid = #{id}
order by log_time desc
</select>
<!-- 根据客户ID查询总共打卡次数 -->
<select id="getPunchTotalNum" parameterType="SysWxUserLog" resultType="int">
select count(1) from sys_wx_user_log wxlog
left join sys_wx_user_info wxinfo on wxinfo.openid = wxlog.openid
where wxlog.del_flag = 0 and wxinfo.cus_id = #{customerId}
</select>
<!-- 查询当天打卡社区总共几个人在打卡 -->
<select id="getPunchCustomerTotalNum" resultType="int">
select count(wxlog.openid) from sys_wx_user_log wxlog where wxlog.del_flag = 0 and to_days(log_time) = to_days(now())
</select>
</mapper>