<?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.zhongzheng.modules.exam.mapper.ExamNumberGoodsMapper">

    <resultMap type="com.zhongzheng.modules.exam.domain.ExamNumberGoods" id="ExamNumberGoodsResult">
        <result property="id" column="id"/>
        <result property="examNumberId" column="exam_number_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="goodsId" column="goods_id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.exam.vo.ExamNumberGoodsVo" id="ExamNumberGoodsVoResult">
        <result property="id" column="id"/>
        <result property="examNumberId" column="exam_number_id"/>
        <result property="goodsId" column="goods_id"/>
        <result property="goodsName" column="goods_name"/>
        <result property="code" column="code"/>
        <result property="standPrice" column="stand_price"/>
        <result property="goodsStatus" column="goods_status"/>
    </resultMap>



    <select id="ListExamNumber" parameterType="com.zhongzheng.modules.exam.bo.ExamNumberQueryBo" resultMap="ExamNumberGoodsVoResult">
        SELECT
        *,
        (SELECT goods_name FROM goods g where eng.goods_id = g.goods_id) as goods_name,
        (SELECT code FROM goods g where eng.goods_id = g.goods_id) as code,
        (SELECT stand_price FROM goods g where eng.goods_id = g.goods_id) as stand_price
        FROM
        exam_number_goods eng
        WHERE
            1=1
        <if test="examNumberId != null and examNumberId != ''">
            AND eng.exam_number_id = #{examNumberId}
        </if>
    </select>

    <select id="listGoods" parameterType="com.zhongzheng.modules.exam.bo.ExamNumberQueryBo" resultMap="ExamNumberGoodsVoResult">
        SELECT
            goods_id,
            goods_name,
            CODE,
            stand_price,
            (case WHEN (SELECT COUNT(en.exam_number_id) FROM exam_number en LEFT JOIN exam_number_goods eng on en.exam_number_id =eng.exam_number_id where 1=1 and eng.goods_id = g.goods_id  ) >0 then 0 ELSE 1 end) as goods_status
        FROM
            goods g
        WHERE
            1 = 1
        and g.status in(1)
        <if test="businessId != null and businessId != ''">
          and g.business_id = #{businessId}
        </if>
        <if test="projectId != null and projectId != ''">
          and g.project_id = #{projectId}
        </if>
        <if test="goodsType != null and goodsType != ''">
          and g.goods_type = #{goodsType}
        </if>
    </select>

</mapper>
