InsureUserMapper.xml 20.9 KB
Newer Older
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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
<?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"/>
        <result property="insureStatus" column="insure_status"/>
        <result property="policyId" column="policy_id"/>
        <result property="replaceTransId" column="replace_trans_id"/>
        <result property="applyType" column="apply_type"/>
        <result property="reason" column="reason"/>
        <result property="createTime" column="create_time"/>
        <result property="productPlanId" column="product_plan_id"/>

    </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>
            <if test="insureStatus != null and insureStatus != ''">AND `insure_status` = #{insureStatus}</if>
            <if test="policyId != null and policyId != ''">AND `policy_id` = #{policyId}</if>
        </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>
            <if test="insureStatus != null and insureStatus != ''">AND `insure_status` = #{insureStatus}</if>
            <if test="policyId != null and policyId != ''">AND `policy_id` = #{policyId}</if>
        </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`,
         `applicant_employee_list`,
         `insure_status`,
         `policy_id`)
        values (#{transId},
                #{price},
                #{insuredName},
                #{batchNo},
                #{premium},
                #{insuredMobile},
                #{insuredNo},
                #{insuredEContact},
                #{benefitBasicPlan},
                #{benefitOccupationCategory},
                #{benefitElEmployeeNumberT},
                #{tricycleFrameNumber},
                #{policyNo},
                #{status},
                #{type},
                #{orgCode},
                #{userId},
                #{applicantEmployeeList},
                #{policyId})
    </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>
        <if test="insureStatus != null">,`insure_status`</if>
        <if test="policyId != null">,`policy_id`</if>
        )
        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>
        <if test="insureStatus != null">,#{insureStatus}</if>
        <if test="policyId != null">,#{policyId}</if>
        )
    </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`,
        `applicant_employee_list`,
        `insure_status`,
        `policy_id`
        )
        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},
            #{item.applicantEmployeeList},
            #{item.insureStatus},
            #{item.policyId}
            )
        </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">
        select
        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,
        iu.policy_date_end,iu.create_time,iu.insured_name,iu.benefit_basic_plan AS benefitBasicPlan,iu.price AS price,
        iu.user_id as userId,iu.batch_no as batchNo,iu.benefit_occupation_category as benefitOccupationCategory,
        iu.policy_id as policyId,
        iu.apply_type as applyType,
        ipp.name as planName
        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
        LEFT JOIN insure_product io on io.id=ip.product_id
        LEFT JOIN insure_product_plan ipp on ipp.id =iu.product_plan_id
        <where>
            <if test="policyDto.orgCode !=null and policyDto.orgCode !=''">
                and ip.org_code=#{policyDto.orgCode}
            </if>
            <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>
            <if test="policyDto.id !=null and policyDto.id !=''">
                and ip.id=#{policyDto.id}
            </if>
            <if test="policyDto.planId !=null and policyDto.planId !=''">
                and iu.product_plan_id = #{policyDto.planId}
            </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>-->
<!--            <if test="policyDto.policyDateEnd !=null and policyDto.policyDateEnd !=''">-->
<!--                and iu.policy_date_start <![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>
            <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>
            <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>

        </where>
                order by iu.create_time desc
        <if test="!policyDto.isAll">
            LIMIT #{policyDto.page.offset},#{policyDto.page.totalPage}
        </if>

    </select>

    <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
        <where>
            <if test="policyDto.orgCode !=null and policyDto.orgCode !=''">
                and ip.org_code=#{policyDto.orgCode}
            </if>
            <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>
            <if test="policyDto.id !=null and policyDto.id !=''">
                and ip.id=#{policyDto.id}
            </if>
            <if test="policyDto.planId !=null and policyDto.planId !=''">
                and iu.product_plan_id = #{policyDto.planId}
            </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>
            <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>
        </where>
    </select>

    <!--根据id数组查询员工-->
    <select id="selectListByIds" resultMap="insureUserMap">
        SELECT
        *
        FROM insure_user
        <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">
            and policy_id =#{policyId}
          </if>
          <if test="createTime!=null and createTime !=''">
            and date_format(policy_date_start,'%Y-%m') = #{createTime}
          </if>
            and status = 1 and insure_status = 1
        </where>
    </select>

    <!--根据id数组查询员工-->
    <select id="selectPlansListByIds" resultType="cn.timer.api.dto.insure.InsureUserDto">
        SELECT
        policy_id as policyId,
        product_plan_id as benefitBasicPlan,
        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>
        group by product_plan_id,benefit_occupation_category
    </select>

    <select id="selectPlansListById" resultType="cn.timer.api.dto.insure.InsureUserDto">
        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
        WHERE policy_id = #{policyId}
        group by  iu.product_plan_id
    </select>

    <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>
</mapper>