fuliqi
2024-08-16 2a12d6d43b6f7abc0ef594ee9b992f34ee00b7a1
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
<?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.ycl.platform.mapper.YwUnitMapper">
 
    <resultMap type="YwUnitVo" id="YwUnitResult">
        <result property="id"    column="id"    />
        <result property="unitCode"    column="unit_code"    />
        <result property="unitName"    column="unit_name"    />
        <result property="unitContact"    column="unit_contact"    />
        <result property="unitContactPhone"    column="unit_contact_phone"    />
        <result property="unitAdminAccount"    column="unit_admin_account"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>
 
    <sql id="selectYwUnitVo">
        select id, unit_code, unit_name, unit_contact, unit_contact_phone, unit_admin_account, remark, create_time, update_time, deleted from t_yw_unit
    </sql>
 
    <select id="selectYwUnitList" parameterType="YwUnit" resultMap="YwUnitResult">
        <include refid="selectYwUnitVo"/>
        <where>
            <if test="unitCode != null  and unitCode != ''"> and unit_code = #{unitCode}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
        </where>
    </select>
 
    <select id="selectYwUnitById" parameterType="Long" resultMap="YwUnitResult">
        <include refid="selectYwUnitVo"/>
        where id = #{id}
    </select>
 
    <select id="workList" resultType="com.ycl.platform.domain.vo.YwUnitVO">
        SELECT
            a.*,
            COUNT(b.id) AS work_order_count
        FROM
            t_yw_unit a
                LEFT JOIN
            t_work_order b ON a.id = b.unit_id AND b.deleted = 0 AND b.status = 'WAIT_DISTRIBUTE'
        WHERE
            a.deleted = 0
        GROUP BY
            a.id;
    </select>
 
    <insert id="insertYwUnit" parameterType="YwUnit" useGeneratedKeys="true" keyProperty="id">
        insert into t_yw_unit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="unitCode != null and unitCode != ''">unit_code,</if>
            <if test="unitName != null and unitName != ''">unit_name,</if>
            <if test="unitContact != null and unitContact != ''">unit_contact,</if>
            <if test="unitContactPhone != null and unitContactPhone != ''">unit_contact_phone,</if>
            <if test="unitAdminAccount != null and unitAdminAccount != ''">unit_admin_account,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deleted != null">deleted,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="unitCode != null and unitCode != ''">#{unitCode},</if>
            <if test="unitName != null and unitName != ''">#{unitName},</if>
            <if test="unitContact != null and unitContact != ''">#{unitContact},</if>
            <if test="unitContactPhone != null and unitContactPhone != ''">#{unitContactPhone},</if>
            <if test="unitAdminAccount != null and unitAdminAccount != ''">#{unitAdminAccount},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deleted != null">#{deleted},</if>
         </trim>
    </insert>
 
    <update id="updateYwUnit" parameterType="YwUnit">
        update t_yw_unit
        <trim prefix="SET" suffixOverrides=",">
            <if test="unitCode != null and unitCode != ''">unit_code = #{unitCode},</if>
            <if test="unitName != null and unitName != ''">unit_name = #{unitName},</if>
            <if test="unitContact != null and unitContact != ''">unit_contact = #{unitContact},</if>
            <if test="unitContactPhone != null and unitContactPhone != ''">unit_contact_phone = #{unitContactPhone},</if>
            <if test="unitAdminAccount != null and unitAdminAccount != ''">unit_admin_account = #{unitAdminAccount},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteYwUnitById" parameterType="Long">
        delete from t_yw_unit where id = #{id}
    </delete>
 
    <delete id="deleteYwUnitByIds" parameterType="String">
        delete from t_yw_unit where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
    <select id="getByUserId" resultMap="YwUnitResult">
        SELECT
             tyw.*
        FROM
             t_yw_unit tyw
                 INNER JOIN t_unit_people tup ON tup.unit_id = tyw.id and tyw.deleted = 0
                 INNER JOIN t_yw_people typ ON tup.yw_people_id = typ.id AND typ.user_id = #{userId} AND typ.deleted = 0
    </select>
 
    <select id="ywUnitCount" resultType="java.util.Map">
        SELECT
            u.unit_name AS name,
            COUNT(tcs.id) AS num,
            100 - SUM(score) AS score
        FROM
            t_contract_score tcs
                LEFT JOIN t_yw_unit u ON tcs.unit_id = u.id
        WHERE tcs.deleted = 0
        GROUP BY tcs.unit_id
        ORDER BY score DESC
    </select>
</mapper>