<?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.bonus.boot.manager.basic.dao.PhyCombinDao">
    <insert id="addInfo">
        insert into pm_base_project(project_name,type_id,project_content,price,is_active)
        values (#{combinName}, #{combinType}, #{combinContent},#{combinPrice},'1');
    </insert>
    <update id="updateInfo">
        update pm_base_project set
            project_name = #{combinName},
            type_id = #{combinType},
            project_content=#{combinContent},
            price = #{combinPrice}
        where id = #{id}
    </update>
    <update id="delById">
        update pm_base_project set is_active = '0' where id = #{id}
    </update>

    <select id="getList" resultType="com.bonus.boot.manager.basic.entity.PhyCombinBean">
        SELECT
            ppc.id,
            ppc.project_name as combinName,
            case when pbtp.type_name = '1' then '标准套餐' when pbtp.type_name = '2' then '个性化套餐' when pbtp.type_name = '3' then '职业健康套餐' end as combinType,
--             pbtp.type_name as combinType,
            ppc.type_id as combinTypeId,
            ppc.project_content as  combinContent,
            ppc.price as combinPrice
        FROM pm_base_project ppc
        left join pm_base_type_package pbtp on pbtp.id = ppc.type_id
        where ppc.is_active = '1' and pbtp.is_active = '1'
        <if test="combinName != null and combinName != ''">
            AND  ppc.project_name LIKE concat ('%',#{combinName},'%')
        </if>
        <if test="combinType != null and combinType != ''">
            AND ppc.type_id  = #{combinType}
        </if>
        <if test="combinContent != null and combinContent != ''">
            AND  ppc.project_content LIKE concat ('%',#{combinContent},'%')
        </if>
        <if test="keyWord != null and keyWord != '' ">
            and (
            ppc.project_name like concat ('%',#{keyWord},'%') or
            ppc.project_content like concat ('%',#{keyWord},'%')
            )
        </if>
    </select>
    <select id="getListById" resultType="com.bonus.boot.manager.basic.entity.PhyCombinBean">
        SELECT
            ppc.id,
            ppc.project_name as combinName,
            pbtp.type_name as combinType,
            ppc.type_id as combinTypeId,
            ppc.project_content as  combinContent,
            ppc.price as combinPrice
        FROM pm_base_project ppc
                 left join pm_base_type_package pbtp on pbtp.id = ppc.type_id
        where ppc.is_active = '1' and pbtp.is_active = '1' and ppc.id = #{id}
    </select>
    <select id="determineIfExists" resultType="java.lang.Integer">
        select count(1) from pm_base_project where is_active = '1' and project_name = #{combinName} and type_id = #{combinType}
        <if test="id != null and id != ''">
            and id != #{id}
        </if>
        limit 1
    </select>
</mapper>

