liujie
昨天 c983a0a398504697a777ffae48e59961b5ee2bd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?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.ruoyi.user.mapper.AccountCancelApplyMapper">
 
    <resultMap type="AccountCancelApply" id="AccountCancelApplyResult">
        <id     property="id"                 column="id"                   />
        <result property="userId"             column="user_id"              />
        <result property="subjectType"        column="subject_type"         />
        <result property="realName"           column="real_name"            />
        <result property="idCard"             column="id_card"              />
        <result property="companyName"        column="company_name"         />
        <result property="creditCode"         column="credit_code"          />
        <result property="legalPerson"        column="legal_person"         />
        <result property="registeredRegion"   column="registered_region"    />
        <result property="companyAddress"     column="company_address"      />
        <result property="registerDate"       column="register_date"        />
        <result property="licenseValidPeriod" column="license_valid_period" />
        <result property="licenseImage"       column="license_image"        />
        <result property="auditStatus"        column="audit_status"         />
        <result property="auditBy"            column="audit_by"             />
        <result property="auditTime"          column="audit_time"           />
        <result property="auditRemark"        column="audit_remark"         />
        <result property="delFlag"            column="del_flag"             />
        <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"               />
    </resultMap>
 
    <resultMap type="AccountCancelApplyVo" id="AccountCancelApplyVoResult" extends="AccountCancelApplyResult">
        <result property="phone"       column="phone"        />
        <result property="systemLevel" column="system_level" />
    </resultMap>
 
    <sql id="selectCancelApplyVo">
        select id, user_id, subject_type, real_name, id_card, company_name, credit_code, legal_person,
               registered_region, company_address, register_date, license_valid_period, license_image,
               audit_status, audit_by, audit_time, audit_remark,
               del_flag, create_by, create_time, update_by, update_time, remark
        from account_cancel_apply
    </sql>
 
    <!--
        列表:left join 会员表取手机号与系统等级。
        join 条件里带 u.del_flag = '0':会员被逻辑删除后,他遗留的申请仍要能被审核
        (申请自身有自己的 del_flag),只是这两列取不到值显示为空,比整行消失合理。
    -->
    <select id="selectCancelApplyList" parameterType="AccountCancelApplyVo" resultMap="AccountCancelApplyVoResult">
        select a.id, a.user_id, a.subject_type, a.real_name, a.id_card, a.company_name, a.credit_code,
               a.legal_person, a.registered_region, a.company_address, a.register_date,
               a.license_valid_period, a.license_image,
               a.audit_status, a.audit_by, a.audit_time, a.audit_remark,
               a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
               u.phone, u.system_level
        from account_cancel_apply a
        left join account_user u on u.user_id = a.user_id and u.del_flag = '0'
        <where>
            a.del_flag = '0'
            <if test="subjectType != null and subjectType != ''"> and a.subject_type = #{subjectType}</if>
            <if test="auditStatus != null and auditStatus != ''"> and a.audit_status = #{auditStatus}</if>
            <if test="systemLevel != null and systemLevel != ''"> and u.system_level = #{systemLevel}</if>
            <!-- 筛选框是「申请人」单个输入框(原型占位符写的是手机号/用户编号):文本按姓名/手机号/
                 企业名模糊匹配。keywordId 由 Controller 在输入为纯数字时补上,用来等值匹配用户编号
                 与申请号(与主体认证审核的口径一致);写成 a.id = #{keywordId} 而不是
                 cast(a.id as char) like ...,后者把列包进函数,主键索引直接失效。 -->
            <if test="params.keyword != null and params.keyword != ''">
                and (u.phone         like concat('%', #{params.keyword}, '%')
                     or a.real_name  like concat('%', #{params.keyword}, '%')
                     or a.company_name like concat('%', #{params.keyword}, '%')
                     <if test="params.keywordId != null">
                     or a.id = #{params.keywordId} or a.user_id = #{params.keywordId}
                     </if>)
            </if>
            <!-- sargable 写法:不能用 date_format(create_time,'%y%m%d') 把列包进函数 -->
            <if test="params.beginTime != null and params.beginTime != ''">
                and a.create_time &gt;= #{params.beginTime}
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                and a.create_time &lt; date_add(#{params.endTime}, interval 1 day)
            </if>
        </where>
        <!-- 待审核排最前(审核队列的首要诉求),同状态内新的在前 -->
        order by a.audit_status asc, a.id desc
    </select>
 
    <!--
        详情只取申请快照本身。用户信息/关系、云仓由服务层另查——
        real_name、company_name 两表与 account_user 同名,塞进一个扁平结果里会互相覆盖。
    -->
    <select id="selectCancelApplyById" parameterType="Long" resultMap="AccountCancelApplyResult">
        <include refid="selectCancelApplyVo"/>
        where id = #{id} and del_flag = '0'
    </select>
 
    <!--
        审核:where 带 audit_status = '0' 作并发闸门。
        两个管理员同时点「通过」时后一个只能更新 0 行,服务层据此抛异常回滚,
        避免同一份申请被审两次、把账户状态覆盖成与最终审核人意图不符的值。
        audit_remark 直接赋值不加 &lt;if&gt;:通过时要把上一次驳回的意见清空。
    -->
    <update id="auditCancelApply" parameterType="AccountCancelApply">
        update account_cancel_apply
        set audit_status = #{auditStatus},
            audit_by     = #{auditBy},
            audit_time   = sysdate(),
            audit_remark = #{auditRemark},
            update_by    = #{updateBy},
            update_time  = sysdate()
        where id = #{id} and del_flag = '0' and audit_status = '0'
    </update>
 
</mapper>