InsureUserMapper.xml 20.9 KB
Newer Older
翁国栋 committed
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
<?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="cn.timer.api.dao.insure.InsureUserMapper">

    <!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="cn.timer.api.bean.insure.InsureUser" id="insureUserMap">
        <result property="id" column="id"/>
        <result property="transId" column="trans_id"/>
        <result property="price" column="price"/>
        <result property="insuredName" column="insured_name"/>
        <result property="batchNo" column="batch_no"/>
        <result property="premium" column="premium"/>
        <result property="insuredMobile" column="insured_mobile"/>
        <result property="insuredNo" column="insured_no"/>
        <result property="insuredEContact" column="insured_e_contact"/>
        <result property="benefitBasicPlan" column="benefit_basic_plan"/>
        <result property="benefitOccupationCategory" column="benefit_occupation_category"/>
        <result property="benefitElEmployeeNumberT" column="benefit_EL_employee_number_t"/>
        <result property="tricycleFrameNumber" column="Tricycle_frame_number"/>
        <result property="policyNo" column="policy_no"/>
        <result property="status" column="status"/>
        <result property="type" column="type"/>
        <result property="orgCode" column="org_code"/>
        <result property="userId" column="user_id"/>
        <result property="applicantEmployeeList" column="applicant_employee_list"/>
        <result property="policyDateStart" column="policy_date_start"/>
        <result property="policyDateEnd" column="policy_date_end"/>
翁国栋 committed
29 30 31
        <result property="insureStatus" column="insure_status"/>
        <result property="policyId" column="policy_id"/>
        <result property="replaceTransId" column="replace_trans_id"/>
翁国栋 committed
32
        <result property="applyType" column="apply_type"/>
33
        <result property="reason" column="reason"/>
翁国栋 committed
34
        <result property="createTime" column="create_time"/>
翁国栋 committed
35 36
        <result property="productPlanId" column="product_plan_id"/>

翁国栋 committed
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
    </resultMap>

    <select id="queryObject" resultType="cn.timer.api.bean.insure.InsureUser">
        select *
        from insure_user
        where id = #{value}
    </select>

    <select id="queryList" resultType="cn.timer.api.bean.insure.InsureUser">
        select * from insure_user
        <where>
            <if test="transId != null and transId != ''">AND `trans_id` = #{transId}</if>
            <if test="price != null and price != ''">AND `price` = #{price}</if>
            <if test="insuredName != null and insuredName != ''">AND `insured_name` = #{insuredName}</if>
            <if test="batchNo != null and batchNo != ''">AND `batch_no` = #{batchNo}</if>
            <if test="premium != null and premium != ''">AND `premium` = #{premium}</if>
            <if test="insuredMobile != null and insuredMobile != ''">AND `insured_mobile` = #{insuredMobile}</if>
            <if test="insuredNo != null and insuredNo != ''">AND `insured_no` = #{insuredNo}</if>
            <if test="insuredEContact != null and insuredEContact != ''">AND `insured_e_contact` = #{insuredEContact}
            </if>
            <if test="benefitBasicPlan != null and benefitBasicPlan != ''">AND `benefit_basic_plan` =
                #{benefitBasicPlan}
            </if>
            <if test="benefitOccupationCategory != null and benefitOccupationCategory != ''">AND
                `benefit_occupation_category` = #{benefitOccupationCategory}
            </if>
            <if test="benefitElEmployeeNumberT != null and benefitElEmployeeNumberT != ''">AND
                `benefit_EL_employee_number_t` = #{benefitElEmployeeNumberT}
            </if>
            <if test="tricycleFrameNumber != null and tricycleFrameNumber != ''">AND `Tricycle_frame_number` =
                #{tricycleFrameNumber}
            </if>
            <if test="policyNo != null and policyNo != ''">AND `policy_no` = #{policyNo}</if>
            <if test="status != null and status != ''">AND `status` = #{status}</if>
            <if test="type != null and type != ''">AND `type` = #{type}</if>
            <if test="orgCode != null and orgCode != ''">AND `org_code` = #{orgCode}</if>
            <if test="userId != null and userId != ''">AND `user_id` = #{userId}</if>
            <if test="applicantEmployeeList != null and applicantEmployeeList != ''">AND `applicant_employee_list` =
                #{applicantEmployeeList}
            </if>
翁国栋 committed
77 78
            <if test="insureStatus != null and insureStatus != ''">AND `insure_status` = #{insureStatus}</if>
            <if test="policyId != null and policyId != ''">AND `policy_id` = #{policyId}</if>
翁国栋 committed
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
        </where>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
        select count(*) from insure_user
        <where>
            <if test="transId != null and transId != ''">AND `trans_id` = #{transId}</if>
            <if test="price != null and price != ''">AND `price` = #{price}</if>
            <if test="insuredName != null and insuredName != ''">AND `insured_name` = #{insuredName}</if>
            <if test="batchNo != null and batchNo != ''">AND `batch_no` = #{batchNo}</if>
            <if test="premium != null and premium != ''">AND `premium` = #{premium}</if>
            <if test="insuredMobile != null and insuredMobile != ''">AND `insured_mobile` = #{insuredMobile}</if>
            <if test="insuredNo != null and insuredNo != ''">AND `insured_no` = #{insuredNo}</if>
            <if test="insuredEContact != null and insuredEContact != ''">AND `insured_e_contact` = #{insuredEContact}
            </if>
            <if test="benefitBasicPlan != null and benefitBasicPlan != ''">AND `benefit_basic_plan` =
                #{benefitBasicPlan}
            </if>
            <if test="benefitOccupationCategory != null and benefitOccupationCategory != ''">AND
                `benefit_occupation_category` = #{benefitOccupationCategory}
            </if>
            <if test="benefitElEmployeeNumberT != null and benefitElEmployeeNumberT != ''">AND
                `benefit_EL_employee_number_t` = #{benefitElEmployeeNumberT}
            </if>
            <if test="tricycleFrameNumber != null and tricycleFrameNumber != ''">AND `Tricycle_frame_number` =
                #{tricycleFrameNumber}
            </if>
            <if test="policyNo != null and policyNo != ''">AND `policy_no` = #{policyNo}</if>
            <if test="status != null and status != ''">AND `status` = #{status}</if>
            <if test="type != null and type != ''">AND `type` = #{type}</if>
            <if test="orgCode != null and orgCode != ''">AND `org_code` = #{orgCode}</if>
            <if test="userId != null and userId != ''">AND `user_id` = #{userId}</if>
            <if test="applicantEmployeeList != null and applicantEmployeeList != ''">AND `applicant_employee_list` =
                #{applicantEmployeeList}
            </if>
翁国栋 committed
125 126
            <if test="insureStatus != null and insureStatus != ''">AND `insure_status` = #{insureStatus}</if>
            <if test="policyId != null and policyId != ''">AND `policy_id` = #{policyId}</if>
翁国栋 committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
        </where>
    </select>

    <insert id="save" parameterType="cn.timer.api.bean.insure.InsureUser" useGeneratedKeys="true" keyProperty="id">
        insert into insure_user
        (`trans_id`,
         `price`,
         `insured_name`,
         `batch_no`,
         `premium`,
         `insured_mobile`,
         `insured_no`,
         `insured_e_contact`,
         `benefit_basic_plan`,
         `benefit_occupation_category`,
         `benefit_EL_employee_number_t`,
         `Tricycle_frame_number`,
         `policy_no`,
         `status`,
         `type`,
         `org_code`,
         `user_id`,
翁国栋 committed
149 150 151
         `applicant_employee_list`,
         `insure_status`,
         `policy_id`)
翁国栋 committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
        values (#{transId},
                #{price},
                #{insuredName},
                #{batchNo},
                #{premium},
                #{insuredMobile},
                #{insuredNo},
                #{insuredEContact},
                #{benefitBasicPlan},
                #{benefitOccupationCategory},
                #{benefitElEmployeeNumberT},
                #{tricycleFrameNumber},
                #{policyNo},
                #{status},
                #{type},
                #{orgCode},
                #{userId},
翁国栋 committed
169 170
                #{applicantEmployeeList},
                #{policyId})
翁国栋 committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    </insert>

    <insert id="saveSelective" parameterType="cn.timer.api.bean.insure.InsureUser" useGeneratedKeys="true"
            keyProperty="id">
        insert into insure_user
        (
        <if test="transId != null">,`trans_id`</if>
        <if test="price != null">,`price`</if>
        <if test="insuredName != null">,`insured_name`</if>
        <if test="batchNo != null">,`batch_no`</if>
        <if test="premium != null">,`premium`</if>
        <if test="insuredMobile != null">,`insured_mobile`</if>
        <if test="insuredNo != null">,`insured_no`</if>
        <if test="insuredEContact != null">,`insured_e_contact`</if>
        <if test="benefitBasicPlan != null">,`benefit_basic_plan`</if>
        <if test="benefitOccupationCategory != null">,`benefit_occupation_category`</if>
        <if test="benefitElEmployeeNumberT != null">,`benefit_EL_employee_number_t`</if>
        <if test="tricycleFrameNumber != null">,`Tricycle_frame_number`</if>
        <if test="policyNo != null">,`policy_no`</if>
        <if test="status != null">,`status`</if>
        <if test="type != null">,`type`</if>
        <if test="orgCode != null">,`org_code`</if>
        <if test="userId != null">,`user_id`</if>
        <if test="applicantEmployeeList != null">,`applicant_employee_list`</if>
翁国栋 committed
195 196
        <if test="insureStatus != null">,`insure_status`</if>
        <if test="policyId != null">,`policy_id`</if>
翁国栋 committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
        )
        values
        (
        <if test="transId != null">,#{transId}</if>
        <if test="price != null">,#{price}</if>
        <if test="insuredName != null">,#{insuredName}</if>
        <if test="batchNo != null">,#{batchNo}</if>
        <if test="premium != null">,#{premium}</if>
        <if test="insuredMobile != null">,#{insuredMobile}</if>
        <if test="insuredNo != null">,#{insuredNo}</if>
        <if test="insuredEContact != null">,#{insuredEContact}</if>
        <if test="benefitBasicPlan != null">,#{benefitBasicPlan}</if>
        <if test="benefitOccupationCategory != null">,#{benefitOccupationCategory}</if>
        <if test="benefitElEmployeeNumberT != null">,#{benefitElEmployeeNumberT}</if>
        <if test="tricycleFrameNumber != null">,#{tricycleFrameNumber}</if>
        <if test="policyNo != null">,#{policyNo}</if>
        <if test="status != null">,#{status}</if>
        <if test="type != null">,#{type}</if>
        <if test="orgCode != null">,#{orgCode}</if>
        <if test="userId != null">,#{userId}</if>
        <if test="applicantEmployeeList != null">,#{applicantEmployeeList}</if>
翁国栋 committed
218 219
        <if test="insureStatus != null">,#{insureStatus}</if>
        <if test="policyId != null">,#{policyId}</if>
翁国栋 committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
        )
    </insert>


    <insert id="saveList" parameterType="cn.timer.api.bean.insure.InsureUser" useGeneratedKeys="true" keyProperty="id">
        insert into insure_user
        (
        `trans_id`,
        `price`,
        `insured_name`,
        `batch_no`,
        `premium`,
        `insured_mobile`,
        `insured_no`,
        `insured_e_contact`,
        `benefit_basic_plan`,
        `benefit_occupation_category`,
        `benefit_EL_employee_number_t`,
        `Tricycle_frame_number`,
        `policy_no`,
        `status`,
        `type`,
        `org_code`,
        `user_id`,
翁国栋 committed
244 245 246
        `applicant_employee_list`,
        `insure_status`,
        `policy_id`
翁国栋 committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.transId},
            #{item.price},
            #{item.insuredName},
            #{item.batchNo},
            #{item.premium},
            #{item.insuredMobile},
            #{item.insuredNo},
            #{item.insuredEContact},
            #{item.benefitBasicPlan},
            #{item.benefitOccupationCategory},
            #{item.benefitElEmployeeNumberT},
            #{item.tricycleFrameNumber},
            #{item.policyNo},
            #{item.status},
            #{item.type},
            #{item.orgCode},
            #{item.userId},
翁国栋 committed
268 269 270
            #{item.applicantEmployeeList},
            #{item.insureStatus},
            #{item.policyId}
翁国栋 committed
271 272 273 274 275 276 277 278 279 280 281 282 283
            )
        </foreach>
    </insert>


    <delete id="deleteBatch">
        delete from insure_user where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectPolicyList" resultType="cn.timer.api.dto.insure.PolicyDto">
翁国栋 committed
284
        select
翁国栋 committed
285
        iu.id,yme.`name`,yme.zj_type,yme.zj_num,ip.policy_no,iu.`status`,io.name as schemeName,iu.policy_date_start,iu.insure_status,
翁国栋 committed
286
        iu.policy_date_end,iu.create_time,iu.insured_name,iu.benefit_basic_plan AS benefitBasicPlan,iu.price AS price,
翁国栋 committed
287 288
        iu.user_id as userId,iu.batch_no as batchNo,iu.benefit_occupation_category as benefitOccupationCategory,
        iu.policy_id as policyId,
翁国栋 committed
289 290
        iu.apply_type as applyType,
        ipp.name as planName
翁国栋 committed
291
        from insure_user iu
翁国栋 committed
292 293
        LEFT JOIN yggl_main_emp yme on yme.id=iu.user_id
        LEFT JOIN insure_policy ip on ip.id=iu.policy_id
翁国栋 committed
294
        LEFT JOIN insure_product io on io.id=ip.product_id
翁国栋 committed
295
        LEFT JOIN insure_product_plan ipp on ipp.id =iu.product_plan_id
翁国栋 committed
296
        <where>
翁国栋 committed
297 298 299
            <if test="policyDto.orgCode !=null and policyDto.orgCode !=''">
                and ip.org_code=#{policyDto.orgCode}
            </if>
翁国栋 committed
300 301 302 303 304 305
            <if test="policyDto.productId !=null and policyDto.productId !=''">
                and ip.product_id=#{policyDto.productId}
            </if>
            <if test="policyDto.policyNo !=null and policyDto.policyNo !=''">
                and ip.policy_no=#{policyDto.policyNo}
            </if>
翁国栋 committed
306 307 308 309
            <if test="policyDto.id !=null and policyDto.id !=''">
                and ip.id=#{policyDto.id}
            </if>
            <if test="policyDto.planId !=null and policyDto.planId !=''">
翁国栋 committed
310
                and iu.product_plan_id = #{policyDto.planId}
翁国栋 committed
311 312
            </if>
            <if test="policyDto.categoryId !=null and policyDto.categoryId !=''">
翁国栋 committed
313
                and iu.benefit_occupation_category = #{policyDto.categoryId}
翁国栋 committed
314 315 316 317
            </if>
            <if test="policyDto.name !=null and policyDto.name !=''">
                and iu.insured_e_contact like CONCAT('%',#{policyDto.name},'%')
            </if>
翁国栋 committed
318 319 320 321 322 323
<!--            <if test="policyDto.policyDateStart !=null and policyDto.policyDateStart !=''">-->
<!--                and iu.policy_date_start <![CDATA[<=]]> #{policyDto.policyDateStart}-->
<!--            </if>-->
<!--            <if test="policyDto.policyDateEnd !=null and policyDto.policyDateEnd !=''">-->
<!--                and iu.policy_date_start <![CDATA[>=]]> #{policyDto.policyDateEnd}-->
<!--            </if>-->
翁国栋 committed
324 325 326 327 328 329
            <if test="policyDto.status !=null and policyDto.status !=''">
                and iu.insure_status = #{policyDto.status}
            </if>
            <if test="policyDto.applyType !=null and policyDto.applyType !=''">
                and iu.apply_type = #{policyDto.applyType}
            </if>
翁国栋 committed
330 331 332 333 334 335
            <if test="policyDto.monthD !=null and policyDto.monthD !=''">
                AND DATE_FORMAT(iu.policy_date_start,'%Y-%m') = #{policyDto.monthD}
            </if>
            <if test="policyDto.policyDateStart !=null and policyDto.policyDateStart !='' and policyDto.policyDateEnd !=null and policyDto.policyDateEnd !=''">
                and  iu.create_time BETWEEN #{policyDto.policyDateStart} and #{policyDto.policyDateEnd}
            </if>
翁国栋 committed
336 337 338 339 340 341
            <if test="policyDto.userName !=null and policyDto.userName !='' ">
                and  yme.`name` like CONCAT('%',#{policyDto.userName},'%')
            </if>
            <if test="policyDto.zjNum !=null and policyDto.zjNum !='' ">
                and  yme.zj_num like CONCAT('%',#{policyDto.zjNum},'%')
            </if>
翁国栋 committed
342

翁国栋 committed
343
        </where>
翁国栋 committed
344
                order by iu.create_time desc
翁国栋 committed
345
        <if test="!policyDto.isAll">
翁国栋 committed
346 347
            LIMIT #{policyDto.page.offset},#{policyDto.page.totalPage}
        </if>
翁国栋 committed
348

翁国栋 committed
349 350
    </select>

翁国栋 committed
351 352 353 354
    <select id="totalUser" resultType="java.lang.Integer">
        select count(iu.id) from insure_user iu
        LEFT JOIN yggl_main_emp yme on yme.id=iu.user_id
        LEFT JOIN insure_policy ip on ip.id=iu.policy_id
翁国栋 committed
355 356 357 358
        <where>
            <if test="policyDto.orgCode !=null and policyDto.orgCode !=''">
                and ip.org_code=#{policyDto.orgCode}
            </if>
翁国栋 committed
359 360 361 362 363 364
            <if test="policyDto.productId !=null and policyDto.productId !=''">
                and ip.product_id=#{policyDto.productId}
            </if>
            <if test="policyDto.policyNo !=null and policyDto.policyNo !=''">
                and ip.policy_no=#{policyDto.policyNo}
            </if>
翁国栋 committed
365 366 367 368
            <if test="policyDto.id !=null and policyDto.id !=''">
                and ip.id=#{policyDto.id}
            </if>
            <if test="policyDto.planId !=null and policyDto.planId !=''">
翁国栋 committed
369
                and iu.product_plan_id = #{policyDto.planId}
翁国栋 committed
370 371 372 373 374 375 376 377 378 379
            </if>
            <if test="policyDto.categoryId !=null and policyDto.categoryId !=''">
                and iu.benefit_occupation_category = #{policyDto.categoryId}
            </if>
            <if test="policyDto.name !=null and policyDto.name !=''">
                and iu.insured_e_contact like CONCAT('%',#{policyDto.name},'%')
            </if>
            <if test="policyDto.policyDateStart !=null and policyDto.policyDateStart !=''">
                and iu.policy_date_start <![CDATA[>=]]> #{policyDto.policyDateStart}
            </if>
翁国栋 committed
380 381 382 383 384 385 386 387 388
            <if test="policyDto.policyDateEnd !=null and policyDto.policyDateEnd !=''">
                and iu.policy_date_end <![CDATA[<=]]> #{policyDto.policyDateEnd}
            </if>
            <if test="policyDto.status !=null and policyDto.status !=''">
                and iu.insure_status = #{policyDto.status}
            </if>
            <if test="policyDto.applyType !=null and policyDto.applyType !=''">
                and iu.apply_type = #{policyDto.applyType}
            </if>
翁国栋 committed
389
        </where>
翁国栋 committed
390 391 392
    </select>

    <!--根据id数组查询员工-->
翁国栋 committed
393
    <select id="selectListByIds" resultMap="insureUserMap">
翁国栋 committed
394 395 396
        SELECT
        *
        FROM insure_user
翁国栋 committed
397 398 399 400 401 402 403 404 405 406 407 408 409 410
        <where>
            <if test="policyId ==null or policyId ==0">
              user_id IN
                <foreach item="id" collection="array" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="policyId !=null and policyId > 0">
                id IN
                <foreach item="id" collection="array" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
          <if test="policyId!=null and policyId >0">
翁国栋 committed
411 412 413
            and policy_id =#{policyId}
          </if>
          <if test="createTime!=null and createTime !=''">
翁国栋 committed
414
            and date_format(policy_date_start,'%Y-%m') = #{createTime}
翁国栋 committed
415 416
          </if>
            and status = 1 and insure_status = 1
翁国栋 committed
417
        </where>
翁国栋 committed
418
    </select>
翁国栋 committed
419

翁国栋 committed
420 421 422 423
    <!--根据id数组查询员工-->
    <select id="selectPlansListByIds" resultType="cn.timer.api.dto.insure.InsureUserDto">
        SELECT
        policy_id as policyId,
翁国栋 committed
424
        product_plan_id as benefitBasicPlan,
翁国栋 committed
425 426 427 428 429 430 431
        benefit_occupation_category as benefitOccupationCategory,
        count(id) as totalUser
        FROM insure_user
        WHERE id IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
翁国栋 committed
432
        group by product_plan_id,benefit_occupation_category
翁国栋 committed
433 434 435
    </select>

    <select id="selectPlansListById" resultType="cn.timer.api.dto.insure.InsureUserDto">
翁国栋 committed
436 437 438 439 440 441 442 443
        SELECT iu.policy_id                   as policyId,
               iu.benefit_basic_plan          as benefitBasicPlan,
               iu.benefit_occupation_category as benefitOccupationCategory,/*废弃*/
               count(iu.id)                   as totalUser,
               iu.product_plan_id as productPlanId,
               ipp.name as name
        FROM insure_user iu
        left join insure_product_plan ipp on ipp.id=iu.product_plan_id
翁国栋 committed
444
        WHERE policy_id = #{policyId}
翁国栋 committed
445
        group by  iu.product_plan_id
翁国栋 committed
446
    </select>
翁国栋 committed
447

448 449 450 451 452 453 454 455 456 457 458
    <update id="updateInsure">
        UPDATE insure_user
        <set>
            status = 2,
            insure_status=2
        </set>
        WHERE policy_id IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
翁国栋 committed
459
</mapper>