13693261870
2025-07-02 7c7cb1855b7f18802f55a70fa14ed70cbdb11bab
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?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.terra.system.mapper.show.ApplyMapper">
    <select id="selectCount" resultType="java.lang.Integer">
        select count(*) from lf.sys_apply a inner join lf.sys_user b on a.userid = b.id
        <where>
            1 = 1
            <if test="uname != null">
                and upper(b.uname) like #{uname}
            </if>
            <if test="status != null">
                <if test="status == 0">
                    and a.status between 0 and 9
                </if>
                <if test="status != 0">
                    and a.status = #{status}
                </if>
            </if>
            <if test="start != null">
                and a.create_time &gt;= #{start}
            </if>
            <if test="end != null">
                and a.create_time &lt;= #{end}
            </if>
        </where>
    </select>
 
    <select id="selectByPage" resultType="com.terra.system.entity.show.ApplyEntity">
        select
            case a.userid when #{userid} then guid else null end "guid", a.*, b.uname,
            (select count(*) from lf.sys_flow c where c.applyid = a.id and c.status = 0 and c.userid = #{userid}) isVerify
        from lf.sys_apply a inner join lf.sys_user b on a.userid = b.id
        <where>
            1 = 1
            <if test="uname != null">
                and upper(b.uname) like #{uname}
            </if>
            <if test="status != null">
                <if test="status == 0">
                    and a.status between 0 and 9
                </if>
                <if test="status != 0">
                    and a.status = #{status}
                </if>
            </if>
            <if test="start != null">
                and a.create_time &gt;= #{start}
            </if>
            <if test="end != null">
                and a.create_time &lt;= #{end}
            </if>
        </where>
        order by a.id desc
        limit #{limit} offset #{offset}
    </select>
 
    <select id="selectAll" resultType="com.terra.system.entity.show.ApplyEntity">
        select * from lf.sys_apply order by id desc
    </select>
 
    <select id="selectById" resultType="com.terra.system.entity.show.ApplyEntity">
        select * from lf.sys_apply where id = #{id}
    </select>
 
    <select id="selectUserByDepcode" resultType="com.terra.system.entity.sys.UserEntity">
        select c.* from lf.sys_role a inner join lf.sys_role_user b on a.id = b.roleid
        inner join lf.sys_user c on b.userid = c.id
        where a.is_admin = 2 and c.depcode = #{depcode}
        order by c.id limit 1
    </select>
    
    <select id="selectSubmits" resultType="java.lang.Integer">
        select count(*) from lf.sys_apply a inner join lf.sys_flow b on a.id = b.applyid
        where a.status between 0 and 9 and b.status = 0 and b.userid = #{userid}
    </select>
 
    <select id="selectFlows" resultType="com.terra.system.entity.show.FlowEntity">
        select a.*, b.uname, fn_get_fullname(a.depcode, 1) depName
        from lf.sys_flow a inner join lf.sys_user b on a.userid = b.id
        where a.applyid = #{applyid}
    </select>
 
    <insert id="insert" parameterType="com.terra.system.entity.show.ApplyEntity">
        <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
            select currval('lf.sys_apply_id_seq'::regclass) as id
        </selectKey>
 
        insert into lf.sys_apply
        (userid,depids,tabs,entities,wkt,pwd,status,count,descr,create_user,create_time,depcode,dircodes,gids,filters,guid)
        values
        (#{userid},#{depids},#{tabs},#{entities},#{wkt},#{pwd},#{status},#{count},#{descr},#{createUser},now(),#{depcode},#{dircodes},#{gids},#{filters},#{guid})
    </insert>
 
    <insert id="inserts">
        insert into lf.sys_apply
        (userid,depids,tabs,entities,wkt,pwd,status,count,descr,create_user,create_time,depcode,dircodes,gids,filters,guid)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.userid},#{item.depids},#{item.tabs},#{item.entities},#{item.wkt},#{item.pwd},#{item.status},#{item.count},#{item.descr},#{item.createUser},now(),#{item.depcode},#{item.dircodes},#{item.gids},#{item.filters},#{item.guid})
        </foreach>
    </insert>
 
    <delete id="delete">
        delete from lf.sys_apply where id = #{id}
    </delete>
 
    <delete id="deletes">
        delete from lf.sys_apply where id in
        <foreach item="id" collection="ids" index="index" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
    <update id="update">
        update lf.sys_apply
        set userid=#{userid},depids=#{depids},tabs=#{tabs},entities=#{entities},wkt=#{wkt},pwd=#{pwd},status=#{status},count=#{count},descr=#{descr},update_user=#{updateUser},update_time=now(),depcode=#{depcode},dircodes=#{dircodes},gids=#{gids},filters=#{filters},guid=#{guid}
        where id=#{id}
    </update>
 
    <update id="updates">
        <foreach collection="list" item="item" index="index" separator=";">
            update lf.sys_apply
            <set>
                userid=#{item.userid},depids=#{item.depids},tabs=#{item.tabs},entities=#{item.entities},wkt=#{item.wkt},pwd=#{item.pwd},status=#{item.status},count=#{item.count},descr=#{item.descr},update_user=#{item.updateUser},update_time=now(),depcode=#{item.depcode},dircodes=#{item.dircodes},gids=#{item.gids},filters=#{item.filters},guid=#{item.guid}
            </set>
            where id = #{item.id}
        </foreach>
    </update>
 
    <update id="updateForDiscard">
        update lf.sys_apply set status = -10, update_user = #{userid}, update_time = now() where status between -1 and 9 and id = #{id}
    </update>
 
    <update id="updateForResubmit">
        update lf.sys_flow set status = 0, update_user = #{userid}, update_time = now() where status = -1 and applyid = #{id};
        update lf.sys_apply a set status = (select count(*) from lf.sys_flow b where b.status = 1 and b.applyid = a.id), update_user = #{userid}, update_time = now() where status = -1 and id = #{id};
    </update>
 
    <update id="updateForSubmit">
        update lf.sys_flow set status = 1, update_user = #{userid}, update_time = now() where id = #{flowId};
        update lf.sys_apply a set status = (select count(*) from lf.sys_flow b where b.status = 1 and b.applyid = a.id), update_user = #{userid}, update_time = now() where id = #{applyid};
        update lf.sys_apply set status = 10 where status = count and id = #{applyid};
    </update>
 
    <update id="updateForReject">
        update lf.sys_flow set status = -1, update_user = #{userid}, update_time = now() where status = 0 and id = #{flowId};
        update lf.sys_apply set status = -1, update_user = #{userid}, update_time = now() where status between 0 and 9 and id = #{applyid};
    </update>
</mapper>