<?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="org.sky.scientific.mapper.A107_1Mapper">

    <select id="qyyjkfxmqk" resultType="org.sky.scientific.pojo.vo.A107_1VO">
        SELECT
        xm.*, tmp.xm_stage,tmp.gov_bonus,
        IFNULL((SELECT COUNT(DISTINCT unicode) FROM kd_xm_technician xt where xt.xm_id = xm.xm_id GROUP BY xt.year_and_month ORDER BY xt.year_and_month desc  limit 1),0) as technicianCount
        FROM
        (
            SELECT
                xm.id as xm_id,xm.tenant_id,
                xm.yjlx,
                COALESCE(get_xm_info(xm.id,'XMMC', #{year}),XMMC) AS XMMC,
                xm.XMLY,xm.XMKZXS as kzxs,xm.YQCGXS as cgxs,xm.XMJSJJMB as jsjjmb,
                xm.XMKSSJ as kssj,
                COALESCE(get_xm_info(xm.id,'XMJSSJ', #{year}) ,XMJSSJ) AS jssj
            FROM kd_xm xm
        ) xm
        LEFT JOIN kd_107_1 tmp on tmp.xm_id = xm.xm_id and tmp.year_and_month = #{year} and tmp.tenant_id = #{tenantId}
        WHERE xm.tenant_id = #{tenantId} and left(xm.jssj,4) >= #{year}
    </select>

</mapper>
