xkrs_ms/stdiet-custom/src/main/resources/mapper/custom/SysServicesQuestionMapper.xml
2021-05-24 11:18:19 +08:00

83 lines
3.6 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.SysServicesQuestionMapper">
<resultMap type="SysServicesQuestion" id="SysServicesQuestionResult">
<result column="id" property="id"/>
<result column="que_id" property="queId"/>
<result column="content" property="content"/>
<result column="role" property="role"/>
<result column="name" property="name"/>
<result column="type" property="type"/>
<result column="read" property="read"/>
<result column="img" property="img" typeHandler="com.stdiet.custom.typehandler.ArrayJsonHandler"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<!-- 根据userId和角色查询问题列表-->
<select id="selectSysServicesQuestionByUserIdAndRole" parameterType="SysServicesQuestion"
resultMap="SysServicesQuestionResult">
SELECT * FROM (
SELECT * FROM sys_services_question_status WHERE role = #{role} AND user_id = #{userId}
) AS status
LEFT JOIN sys_services_question USING(que_id)
<choose>
<when test="role == 'customer'">
LEFT JOIN (
SELECT name, id AS user_id FROM sys_customer WHERE id = #{userId}
) AS customer USING(user_id)
</when>
<otherwise>
LEFT JOIN (
SELECT role_key, sys_role.role_id, sys_user_role.user_id, sys_user.nick_name AS name FROM sys_role
INNER JOIN sys_user_role USING(role_id)
INNER JOIN sys_user USING(user_id)
WHERE role_key = #{role} AND user_id = #{userId}
) AS user USING(user_id)
</otherwise>
</choose>
ORDER BY type ASC, update_time DESC
</select>
<!-- 插入问题-->
<insert id="insertSysServicesQuestion" parameterType="SysServicesQuestion" useGeneratedKeys="true" keyProperty="id">
insert into sys_services_question
<trim prefix="(" suffix=")" suffixOverrides=",">
id,
<if test="cusId != null">cus_id,</if>
<if test="content != null">content,</if>
<if test="type != null">type,</if>
<if test="cusId != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
replace(uuid(), '-', ''),
<if test="cusId != null">#{cusId},</if>
<if test="content != null">#{content},</if>
<if test="type != null">#{type},</if>
<if test="cusId != null">now(),</if>
</trim>
</insert>
<!-- 插入问题的四个角色1用户 2营养师 3售后 4助理-->
<insert id="insertSysServicesQuestionStatus" parameterType="java.util.List">
insert into sys_services_question (que_id, user_id, role, create_time, update_time) values
<foreach collection="list" item="status" index="index" separator=",">
(#{status.queId}, #{status.userId}, #{status.role}, now(), now())
</foreach>
</insert>
<!-- 根据状态id更新-->
<update id="updateSysServicesQuestionStatus" parameterType="SysServicesQuestion">
update sys_services_question_status
<trim prefix="SET" suffixOverrides=",">
<if test="read !== null">read = #{read}</if>
<if test="read !== null">update_time = now()</if>
</trim>
where id = ${id}
</update>
</mapper>