<?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.hxhq.business.mapper.MjyMapper">

    <select id="queryInfo" resultType="com.hxhq.business.dto.mjy.DetailDto">
        select t.*,s.name as studyMc,sf.bdmc as bdMc,sf.user_mc as bdgsrMc,
        (select GROUP_CONCAT(s.name) from t_study s where find_in_set(s.id, t.`md_ids`)) as mdMcs
        FROM `t_mjy` t
        left join  `t_study` s on s.id=t.study_id
        left join  `t_study_form_fill` sf on sf.id=t.bd_id
        where t.id=#{id}
    </select>

    <select id="queryList" resultType="com.hxhq.business.dto.mjy.ListDto">
        select t.id,t.mc,t.bh,t.nd,t.nddw,t.kc,t.kcdw,t.sxrq,t.zjzt,t.jyzt,t.cctj,t.ccwz,t.create_time,t.bjzt,t.kcbjzt,t.rqzt,t.ghzt
        ,t.ckl,t.ckldw,t.ffzytj,t.ckmz,t.ckmzdw,t.lqr1_mc,t.lqr2_mc,t.ffr1_mc,t.ffr2_mc,t.ffbz,t.gdsqr_id
        ,z.mc as zcgMc
        FROM `t_mjy` t
        left join  `t_zcg` z on z.id=t.zcg_id
        <if test="ew.sqlSegment != '' and ew.sqlSegment != null">
            <where>
                ${ew.sqlSegment}
            </where>
        </if>
    </select>

    <select id="queryStudyList" resultType="com.hxhq.business.dto.mjy.ListDto">
        select t.id,t.mc,t.bh,t.nd,t.nddw,t.kc,t.kcdw,t.sxrq,t.zjzt,t.cczt,ts.resource_id
        FROM `t_study_mjy` ts
        join  `t_mjy` t on t.id=ts.resource_id
        <if test="ew.sqlSegment != '' and ew.sqlSegment != null">
            <where>
                ${ew.sqlSegment}
            </where>
        </if>
    </select>

    <update id="updateKcBatch">
        UPDATE t_mjy SET kc = #{kc} WHERE bh in
        <foreach item="item" index="index" collection="bhList" separator=",">
            (#{item})
        </foreach>
    </update>
    <update id="updateCc">
        UPDATE t_mjy SET cctj = #{cctj}, ccwz = #{ccwz} WHERE bh in
        <foreach item="item" index="index" collection="bhList" separator=",">
            (#{item})
        </foreach>
    </update>
    <update id="updateKc">
        UPDATE t_mjy SET kc = #{kc} WHERE id = #{id}
    </update>

</mapper>