<?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.health.dao.SpecialJobDao">
    <insert id="insert">
        insert into pm_special_job_relate(special_job_id,comb_id)
        values (#{specialId},#{id})
    </insert>
    <delete id="deleteSpecialJob">
        delete from pm_special_job_relate where special_job_id = #{specialId}
    </delete>

    <select id="getSpecialJobTree" resultType="com.bonus.boot.manager.health.entity.SpecialJobBean">
        select  id,`job_name` as name,0 AS parentId
        FROM  pm_base_special_job
        where is_active = 1
    </select>
    <select id="getList" resultType="com.bonus.boot.manager.health.entity.SpecialJobBean">
        SELECT
            pbc.id,
            pbc.comb_name as combinName,
            GROUP_CONCAT(pbp.combin_name) as combinContent,
            sum(pbp.combin_price) as combinPrice,
            psjr.special_job_id,
            if(psjr.special_job_id = #{specialId},'1','0') as status
            FROM pm_base_combination pbc
            left join pm_phy_combin pbp on pbp.id = pbc.id  and pbp.is_active = '1'
            left join pm_special_job_relate psjr on psjr.comb_id =  pbc.id
            where pbc.is_active = '1'
        GROUP BY pbc.id
        <if test="keyWord != null and keyWord != '' ">
            and (
                pbc.comb_name like concat ('%',#{keyWord},'%')
            )
        </if>
    </select>
</mapper>

