邱宇豪
2023-11-13 990f794e91ddaae1d8ef6a71b5741c58dfed23ba
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?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.thhy.secure.modules.biz.regionWarranty.mapper.TRegionWarrantyMapper">
 
    <resultMap id="BaseResultMap"
               type="com.thhy.secure.modules.biz.regionWarranty.entity.TRegionWarrantyEntity">
        <result column="region" jdbcType="VARCHAR" property="region" />
        <result column="region_hazard_inform_id" jdbcType="VARCHAR" property="regionHazardInformId" />
        <result column="risk_source_situation" jdbcType="VARCHAR" property="riskSourceSituation" />
        <result column="countermeasures" jdbcType="VARCHAR" property="countermeasures" />
        <result column="company_id" jdbcType="VARCHAR" property="companyId" />
        <result column="create_user" jdbcType="VARCHAR" property="createUser" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    </resultMap>
 
  <insert id="insert" >
      insert into t_region_warranty
    <trim prefix="(" suffix=")" suffixOverrides=",">
          <if test="id != null">
              id,
          </if>
          <if test="regionHazardInformId != null">
              region_hazard_inform_id,
          </if>
          <if test="riskSourceSituation != null">
              risk_source_situation,
           </if>
          <if test="countermeasures != null">
              countermeasures,
          </if>
 
          <if test="createTime != null">
            create_time,
          </if>
          <if test="createUser != null">
            create_user,
          </if>
          <if test="companyId != null">
            company_id,
          </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
        <if test="id != null">
            #{id,jdbcType=VARCHAR},
        </if>
        <if test="regionHazardInformId != null">
            #{regionHazardInformId,jdbcType=VARCHAR},
        </if>
        <if test="riskSourceSituation != null">
            #{riskSourceSituation,jdbcType=VARCHAR},
        </if>
        <if test="countermeasures != null">
            #{countermeasures,jdbcType=VARCHAR},
        </if>
        <if test="createTime != null">
            #{createTime,jdbcType=TIMESTAMP},
        </if>
        <if test="createUser != null">
            #{createUser,jdbcType=VARCHAR},
        </if>
        <if test="companyId != null">
            #{companyId,jdbcType=VARCHAR},
        </if>
    </trim>
  </insert>
 
    <select id="findAll" parameterType="com.thhy.secure.modules.biz.regionWarranty.dto.TRegionWarrantyDto" resultType="com.thhy.secure.modules.biz.regionWarranty.entity.TRegionWarrantyEntity">
      SELECT
          a.id,
          a.region_hazard_inform_id  regionHazardInformId,
          a.risk_source_situation riskSourceSituation,
          a.countermeasures countermeasures,
          a.create_time createTime,
          a.create_user createUser,
          b.region
      FROM
      t_region_warranty a
      LEFT JOIN t_region_hazard_inform b ON b.id = a.region_hazard_inform_id
      WHERE a.is_use = 1
          <if test="companyId!=null and companyId!='' ">
              and a.company_id=#{companyId}
          </if>
          <if test="regionHazardInformId!=null and regionHazardInformId!='' ">
              and b.id = #{regionHazardInformId}
          </if>
        order by a.create_time desc
  </select>
  <select id="findEntity" parameterType="java.lang.String" resultType="com.thhy.secure.modules.biz.regionWarranty.entity.TRegionWarrantyEntity">
      SELECT
              a.id,
              a.region_hazard_inform_id  regionHazardInformId,
              a.risk_source_situation riskSourceSituation,
              a.countermeasures countermeasures,
              a.create_time createTime,
              a.create_user createUser,
              b.region
      FROM
      t_region_warranty a
      LEFT JOIN t_region_hazard_inform b ON b.id = a.region_hazard_inform_id
      WHERE is_use = 1  and a.id = #{id,jdbcType=VARCHAR}
  </select>
  <update id="update">
      update t_region_warranty
    <set>
        <if test="regionHazardInformId != null">
            region_hazard_inform_id = #{regionHazardInformId,jdbcType=VARCHAR},
        </if>
        <if test="riskSourceSituation != null">
            risk_source_situation = #{riskSourceSituation,jdbcType=VARCHAR},
        </if>
        <if test="countermeasures != null">
            countermeasures = #{countermeasures,jdbcType=VARCHAR},
        </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
    <delete id="delete">
        update t_region_warranty set is_use = 2 where id = #{id,jdbcType=VARCHAR}
    </delete>
 
    <insert id="insertMiddleTable" >
        insert into t_region_warranty_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="regionWarrantyId != null">
                region_warranty_id,
            </if>
            <if test="userType != null">
                user_type,
            </if>
            <if test="userId != null">
                user_id,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="regionWarrantyId != null">
                #{regionWarrantyId},
            </if>
            <if test="userType != null">
                #{userType},
            </if>
            <if test="userId != null">
                #{userId},
            </if>
        </trim>
    </insert>
 
    <delete id="deleteMiddleTable">
        delete from t_region_warranty_user where region_warranty_id = #{id,jdbcType=VARCHAR}
    </delete>
 
    <select id="findMiddleTable" resultType="com.thhy.secure.modules.biz.regionWarranty.entity.TRegionWarrantyUserEntity">
        SELECT
                a.id,
                a.region_warranty_id regionWarrantyId,
                a.user_id userId,
                a.user_type userType,
                b.real_name as realName
        FROM t_region_warranty_user a
        LEFT JOIN sys_plat_user b ON b.user_id = a.user_id
        WHERE a.region_warranty_id = #{regionWarrantyId} and a.user_type = #{userType}
    </select>
</mapper>