Files
foton-slrs-system-rest/adc-da-slrs/src/main/resources/mybatis/mapper/askQuestions/AskQuestionsMapper.xml
T

253 lines
12 KiB
XML

<?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.adc.da.slrs.StandardQA.dao.AskQuestionsDao">
<select id="getAskQuestions" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT
DISTINCT
aq.STANDARD_ID,aq.CLASSIFICATION,aq.STANDARD_ENCDOING,
aq.STANDARD_NAME,
MAX(aq.QUESTION_TIME) as questionTime
FROM ask_questions aq
LEFT JOIN (SELECT DISTINCT re.ANSWERER,re.ASK_ID FROM reply re) reply ON aq.ID = reply.ASK_ID
LEFT JOIN ts_user t1 ON t1.USID = aq.QUESTIONER
LEFT JOIN ts_user t2 ON t2.USID = reply.ANSWERER
<where>
<if test="askQuestions.questioner != null and askQuestions.questioner != ''">
AND aq.QUESTIONER =#{askQuestions.questioner}
</if>
<if test="askQuestions.id != null and askQuestions.id != ''">
AND aq.ID = #{askQuestions.id}
</if>
<if test="askQuestions.standardId !=null and askQuestions.standardId !=''">
AND aq.STANDARD_ID = #{askQuestions.standardId}
</if>
<if test="askQuestions.classification != null and askQuestions.classification != ''">
AND aq.CLASSIFICATION = #{askQuestions.classification}
</if>
<if test="askQuestions.standardEncdoing != null and askQuestions.standardEncdoing != ''">
AND aq.STANDARD_ENCDOING LIKE concat(concat('%',#{askQuestions.standardEncdoing}),'%')
</if>
<if test="askQuestions.standardName != null and askQuestions.standardName !=''">
AND aq.STANDARD_NAME LIKE concat(concat('%',#{askQuestions.standardName}),'%')
</if>
<if test="askQuestions.problemDescription != null and askQuestions.problemDescription != ''">
AND aq.PROBLEM_DESCRIPTION LIKE concat(concat('%',#{askQuestions.problemDescription}),'%')
</if>
<if test="askQuestions.answerer !=null and askQuestions.answerer !=''">
AND reply.ANSWERER = #{askQuestions.answerer}
</if>
</where>
GROUP BY
aq.STANDARD_ID,
aq.CLASSIFICATION,
aq.STANDARD_ENCDOING,
aq.STANDARD_NAME
ORDER BY
questionTime DESC
</select>
<select id="getAskQuestionsByStandardId" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT aq.ID,aq.CLASSIFICATION,aq.PROBLEM_DESCRIPTION,t1.UNAME QUESTIONER,aq.QUESTION_TIME,aq.STANDARD_ENCDOING,
aq.STANDARD_NAME,aq.STANDARD_ID
FROM ask_questions aq
LEFT JOIN ts_user t1 ON t1.USID = aq.QUESTIONER
<where>
<if test="standardId !=null and standardId !=''">
AND aq.STANDARD_ID = #{standardId}
</if>
</where>
order by QUESTION_TIME desc
</select>
<select id="getArchiveAskQuestions" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT reply.REPLY,reply.REPLY_TIME,t2.UNAME ANSWERER,
reply.APPENDIX,reply.APPENDIX_ID,reply.APPENDIX_NAME
FROM reply
LEFT JOIN ts_user t2 ON t2.USID = reply.ANSWERER
<where>
reply.STATE = 'yes'
<if test="id != nll and id !=''">
AND reply.ASK_ID = #{id}
</if>
</where>
</select>
<select id="getAskQuestionsByakId" resultType="com.adc.da.slrs.StandardQA.entity.Reply">
SELECT reply.ID, reply.REPLY,reply.REPLY_TIME,t2.UNAME ANSWERER,reply.APPENDIX_ID,APPENDIX_NAME,reply.state
FROM reply
LEFT JOIN ts_user t2 ON t2.USID = reply.ANSWERER
<where>
<if test="id !=null and id !=''">
AND reply.ASK_ID = #{id}
</if>
<if test="state !=null and state !=''">
AND reply.state = #{state}
</if>
</where>
order by reply.REPLY_TIME
</select>
<select id="getReplyDetails" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT
DISTINCT
aq.STANDARD_ID,aq.CLASSIFICATION,aq.STANDARD_ENCDOING,
aq.STANDARD_NAME
FROM ask_questions aq
LEFT JOIN reply ON aq.ID = reply.ASK_ID AND reply.STATE = '0'
LEFT JOIN ts_user t1 ON t1.USID = aq.QUESTIONER
LEFT JOIN ts_user t2 ON t2.USID = reply.ANSWERER
LEFT JOIN ask_user au ON au.ASK_ID = aq.ID
<where>
<if test="askQuestions.answerer != null and askQuestions.answerer != ''">
AND au.USID = #{askQuestions.answerer}
</if>
<if test="askQuestions.classification !=null and askQuestions.classification !=''">
AND aq.CLASSIFICATION = #{askQuestions.classification}
</if>
</where>
</select>
<select id="getReplyDetailsByStandId" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT aq.ID,aq.CLASSIFICATION,aq.PROBLEM_DESCRIPTION,t1.UNAME QUESTIONER,aq.QUESTION_TIME,aq.STANDARD_ENCDOING,
aq.STANDARD_NAME,aq.STANDARD_ID,reply.REPLY,reply.REPLY_TIME,t2.UNAME ANSWERER,
reply.APPENDIX,reply.APPENDIX_ID,reply.APPENDIX_NAME
FROM ask_questions aq
LEFT JOIN reply ON aq.ID = reply.ASK_ID AND reply.STATE = '0'
LEFT JOIN ts_user t1 ON t1.USID = aq.QUESTIONER
LEFT JOIN ts_user t2 ON t2.USID = reply.ANSWERER
LEFT JOIN ask_user au ON au.ASK_ID = aq.ID
<where>
<if test="askQuestions.standardId !=null and askQuestions.standardId !=''">
AND aq.STANDARD_ID = #{askQuestions.standardId}
</if>
</where>
</select>
<select id="getAskQuestionsBySubscription" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT
DISTINCT
aq.STANDARD_ID,aq.CLASSIFICATION,aq.STANDARD_ENCDOING,aq.STANDARD_NAME
FROM ask_questions aq
LEFT JOIN reply ON aq.ID = reply.ASK_ID
LEFT JOIN ts_user t1 ON t1.USID = aq.QUESTIONER
LEFT JOIN ts_user t2 ON t2.USID = reply.ANSWERER
LEFT JOIN subscription su ON su.ASK_ID = aq.ID
<where>
<if test="askQuestions.answerer !=null and askQuestions.answerer !=''">
AND su.USID = #{askQuestions.answerer}
</if>
<if test="askQuestions.classification !=null and askQuestions.classification !=''">
AND aq.CLASSIFICATION = #{askQuestions.classification}
</if>
</where>
</select>
<select id="retrieve" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT
DISTINCT
aq.STANDARD_ID,aq.CLASSIFICATION,aq.STANDARD_ENCDOING,aq.STANDARD_NAME
FROM ask_questions aq
LEFT JOIN reply ON aq.ID = reply.ASK_ID
LEFT JOIN ts_user t1 ON t1.USID = aq.QUESTIONER
LEFT JOIN ts_user t2 ON t2.USID = reply.ANSWERER
<if test="askQuestions.type == 'myAns'">
LEFT JOIN ask_user au ON au.ASK_ID = aq.ID
</if>
<if test="askQuestions.type == 'mySub'">
LEFT JOIN subscription su ON su.ASK_ID = aq.ID
</if>
<where>
<if test="askQuestions.questioner != null and askQuestions.questioner != ''">
AND aq.QUESTIONER =#{askQuestions.questioner}
</if>
<if test="askQuestions.id != null and askQuestions.id != ''">
AND aq.ID = #{askQuestions.id}
</if>
<if test="askQuestions.standardId !=null and askQuestions.standardId !=''">
AND aq.STANDARD_ID = #{askQuestions.standardId}
</if>
<if test="askQuestions.classification != null and askQuestions.classification != ''">
AND aq.CLASSIFICATION = #{askQuestions.classification}
</if>
<if test="askQuestions.standardEncdoing != null and askQuestions.standardEncdoing != ''">
AND aq.STANDARD_ENCDOING LIKE concat(concat('%',#{askQuestions.standardEncdoing}),'%')
</if>
<if test="askQuestions.standardName != null and askQuestions.standardName !=''">
AND aq.STANDARD_NAME LIKE concat(concat('%',#{askQuestions.standardName}),'%')
</if>
<if test="askQuestions.subscription !=null and askQuestions.subscription !=''">
AND su.USID = #{askQuestions.subscription}
</if>
<if test="askQuestions.answerer != null and askQuestions.answerer != ''">
AND au.USID = #{askQuestions.answerer}
</if>
<if test="askQuestions.problemDescription != null and askQuestions.problemDescription != ''">
AND aq.PROBLEM_DESCRIPTION LIKE concat(concat('%',#{askQuestions.problemDescription}),'%')
</if>
<if test="askQuestions.answerer !=null and askQuestions.answerer !=''">
AND reply.ANSWERER = #{askQuestions.answerer}
</if>
</where>
</select>
<select id="getSubscriptionByStandId" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT aq.ID,aq.CLASSIFICATION,aq.PROBLEM_DESCRIPTION,t1.UNAME QUESTIONER,aq.QUESTION_TIME,aq.STANDARD_ENCDOING,
aq.STANDARD_NAME,aq.STANDARD_ID,reply.REPLY,reply.REPLY_TIME,t2.UNAME ANSWERER,
reply.APPENDIX,reply.APPENDIX_ID,reply.APPENDIX_NAME
FROM ask_questions aq
LEFT JOIN reply ON aq.ID = reply.ASK_ID AND reply.STATE = '0'
LEFT JOIN ts_user t1 ON t1.USID = aq.QUESTIONER
LEFT JOIN ts_user t2 ON t2.USID = reply.ANSWERER
LEFT JOIN subscription su ON su.ASK_ID = aq.ID
<where>
<if test="askQuestions.answerer !=null and askQuestions.answerer !=''">
AND su.USID = #{askQuestions.answerer}
</if>
<if test="askQuestions.classification !=null and askQuestions.classification !=''">
AND aq.CLASSIFICATION = #{askQuestions.classification}
</if>
<if test="askQuestions.standardId !=null and askQuestions.standardId !=''">
AND aq.STANDARD_ID = #{askQuestions.standardId}
</if>
</where>
</select>
<select id="resemblance" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT DISTINCT *,
<foreach item="item" collection="chars" separator="+" open="(" close=")" index="">
(case when PROBLEM_DESCRIPTION like CONCAT('%',#{item},'%') then 1 else 0 end)
</foreach>
as num from ask_questions having num >1 order by num DESC
</select>
<select id="getUId" resultType="java.lang.String">
SELECT tu.USID
FROM ts_user tu
LEFT JOIN ts_institution ti ON ti.id = tu.INSTITUTION_ID
WHERE
ti.`name`='标准法规部'
</select>
<select id="getAskQuestionsNew" resultType="com.adc.da.slrs.StandardQA.entity.AskQuestions">
SELECT aq.ID,aq.CLASSIFICATION,aq.PROBLEM_DESCRIPTION,t1.UNAME QUESTIONER,aq.QUESTION_TIME,aq.STANDARD_ENCDOING,
aq.STANDARD_NAME,aq.STANDARD_ID
FROM ask_questions aq
LEFT JOIN ts_user t1 ON t1.USID = aq.QUESTIONER
<where>
<if test="ask.standardId !=null and ask.standardId !=''">
AND aq.STANDARD_ID = #{ask.standardId}
</if>
<if test="ask.problemDescription !=null and ask.problemDescription !=''">
AND aq.PROBLEM_DESCRIPTION LIKE concat(concat('%',#{ask.problemDescription}),'%')
</if>
<if test="ask.classification !=null and ask.classification !=''">
AND aq.CLASSIFICATION LIKE concat(concat('%',#{ask.classification}),'%')
</if>
</where>
order by QUESTION_TIME desc
</select>
</mapper>