<?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="shop.alien.mapper.second.SecondUserViolationMapper">
    <resultMap id="BaseResultMap" type="shop.alien.entity.second.vo.SecondUserViolationVo">
        <!--@mbggenerated-->
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="reported_user_name" property="reportedUserName" jdbcType="VARCHAR"/>
        <result column="reported_user_phone" property="reportedUserPhone" jdbcType="VARCHAR"/>
        <result column="reporting_user_name" property="reportingUserName" jdbcType="VARCHAR"/>
        <result column="reporting_user_phone" property="reportingUserPhone" jdbcType="VARCHAR"/>
        <result column="report_context" property="reportContext" jdbcType="VARCHAR"/>
        <result column="report_context_type" property="reportContextType" jdbcType="VARCHAR"/>
        <result column="dict_detail" property="dictDetail" jdbcType="VARCHAR"/>
        <result column="processing_context" property="processingContext" jdbcType="VARCHAR"/>
        <result column="processing_status" property="processingStatus" jdbcType="VARCHAR"/>
        <result column="business_id" property="businessId" jdbcType="INTEGER"/>
        <result column="created_time" property="reportingDate" jdbcType="TIMESTAMP"/>
        <result column="other_reason_content" property="otherReasonContent" jdbcType="VARCHAR"/>
        <result column="report_evidence_img" property="reportEvidenceImg" jdbcType="VARCHAR"/>
        <result column="processing_time" property="processingTime" jdbcType="TIMESTAMP"/>
        <result column="report_result" property="reportResult" jdbcType="VARCHAR"/>
        <result column="video_first_frame" property="videoFirstFrame" jdbcType="VARCHAR"/>
    </resultMap>

    <!-- 分页查询举报信息 -->
    <select id="getUserViolationByPage" resultType="shop.alien.entity.second.vo.SecondUserViolationVo">
        select
            v.id,
            u.user_name reporting_user_name,
            u.user_phone reporting_user_phone,
            case when v.report_context_type = 4 then '二手商品' else '二手用户' end report_context,
            v.report_context_type,
            d.dict_detail dict_detail,
            case when v.processing_status = 0 then '待处理'
                when v.processing_status = 1 then '已通过'
                else '已驳回' end processing_context,
            v.processing_status,
            v.created_time as reportingDate,
            v.business_id
        from
        life_user_violation v
        left join store_dictionary d on v.dict_type = d.type_name and v.dict_id = d.dict_id
        left join life_user u on u.id = v.reporting_user_id
        where 1 = 1
        <if test="reportingUserName != null and reportingUserName != ''">
            and u.user_name like concat('%',#{reportingUserName},'%')
        </if>
        <if test="reportingDate != null and reportingDate != ''">
            and DATE_FORMAT(v.created_time, '%Y-%m-%d') = #{reportingDate}
        </if>
        <if test="processingStatus != null and processingStatus != ''">
            and v.processing_status = #{processingStatus}
        </if>
        <if test="reportContextType != null and reportContextType != ''">
            and v.report_context_type = #{reportContextType}
        </if>
        <if test="reportContextType == null or reportContextType == ''">
            and (v.report_context_type = 4 or v.report_context_type = 5)
        </if>
        order by v.created_time desc
    </select>

    <!-- 分页查询举报信息 -->
    <select id="getUserViolationInfo" resultType="shop.alien.entity.second.vo.SecondUserViolationDetailVo">
        select
            v.id,
            case when v.report_context_type = 4 then lu1.user_name else u.user_name end reported_user_name,
            case when v.report_context_type = 4 then lu1.user_phone else u.user_phone end reported_user_phone,
            lu.user_name reporting_user_name,
            lu.user_phone reporting_user_phone,
            v.created_time,
            case when v.processing_status = 0 then '待处理' when v.processing_status = 1 then '已通过' else '已驳回' end processing_status,
            d.dict_detail,
            v.business_id,
            v.report_context_type,
            v.processing_status,
            v.other_reason_content,
            v.report_evidence_img,
            v.processing_time,
            v.report_result,
            v.video_first_frame
        from
        life_user_violation v
        left join life_user u on v.reported_user_id = u.id
        left join life_user lu on v.reporting_user_id = lu.id
        left join store_dictionary d on v.dict_type = d.type_name
            and v.dict_id = d.dict_id
        left join second_goods_record g on g.id = v.business_id
        left join life_user lu1 on g.user_id = lu1.id
        <if test="id != null and id != ''">
            where v.id = #{id}
        </if>
    </select>


    <!-- 分页查询举报信息 -->
    <select id="getUserViolationDetailInfo" resultType="shop.alien.entity.second.vo.SecondUserViolationDetailVo">
        select
            v.id,
            case when reported_user_type = 1 then s.nick_name else u.user_name end reported_user_name,
            case when reported_user_type = 1 then s.phone else u.user_phone end reported_user_phone,
            case when reporting_user_type = 1 then su.nick_name else lu.user_name end reporting_user_name,
            case when reporting_user_type = 1 then su.phone else lu.user_phone end reporting_user_phone,
            v.created_time,
            case when v.processing_status = 0 then '待处理' when v.processing_status = 1 then '已通过' else '已驳回' end processing_status,
            case when v.violation_type = 1 then '用户违规' when v.violation_type = 2 then '色情低俗' when v.violation_type = 3 then '违法违规' when v.violation_type = 4 then '谩骂嘲讽、煽动对立' when v.violation_type = 5 then '涉嫌诈骗'
            when v.violation_type = 6 then '人身攻击' when v.violation_type = 7 then '种族歧视' when v.violation_type = 8 then '政治敏感' when v.violation_type = 9 then '虚假、不实内容'
            when v.violation_type = 10 then '违反公德秩序' when v.violation_type = 11 then '危害人身安全' when v.violation_type = 12 then '网络暴力' else '其他原因' end dict_detail,
            v.business_id,
            v.report_context_type,
            v.processing_status,
            v.other_reason_content,
            v.report_evidence_img,
            v.processing_time,
            v.report_result,
            v.video_first_frame,
            v.comment_id,
            v.dynamics_id
        from
            life_user_violation v
            left join life_user u on v.reported_user_id = u.id
            left join store_user s on v.reported_user_id = s.id
            left join life_user lu on v.reporting_user_id = lu.id
            left join store_user su on v.reporting_user_id = su.id
        <if test="id != null and id != ''">
            where v.id = #{id}
        </if>
    </select>

</mapper>