<?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="cn.iocoder.yudao.module.chain.dal.mysql.blockcertificate.BlockCertificateMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->

    <resultMap id="queryBlockCertificateListMap" type="cn.iocoder.yudao.module.chain.controller.admin.blockcertificate.vo.BlockCertificateRespVO">
        <result column="chain_operate_id" property="chainOperateId"></result>
        <collection property="operateDetails" column="chainOperateId=chain_operate_id" select="queryOperateDetails"></collection>
    </resultMap>

    <select id="getBlockCertificateList" resultMap="queryBlockCertificateListMap" parameterType="cn.iocoder.yudao.module.chain.controller.admin.blockcertificate.vo.BlockCertificateReqVO">
        SELECT
            *
        FROM
            chain_block_certificate
        <where>
            deleted = false
            <if test="blockCertificate.id != null and blockCertificate.id > 0">and id = #{blockCertificate.id}</if>
            <if test="blockCertificate.chainOperateId != null and blockCertificate.id != ''">and chain_operate_id = #{blockCertificate.chainOperateId}</if>
            <if test="blockCertificate.operateType != null">and operate_type = #{blockCertificate.operateType}</if>
            <if test="blockCertificate.operateTypes != null">
                and operate_type in
                <foreach collection="blockCertificate.operateTypes" item="operateType" separator="," open="(" close=")">
                    #{operateType}
                </foreach>
            </if>
            <if test="blockCertificate.batchType != null">and batch_type = #{blockCertificate.batchType}</if>
            <if test="blockCertificate.batchId != null and blockCertificate.batchId != ''">and batch_id = #{blockCertificate.batchId}</if>
            <if test="blockCertificate.chainState != null">and chain_state = #{blockCertificate.chainState}</if>
            <if test="blockCertificate.chainStatus != null">and chain_status = #{blockCertificate.chainStatus}</if>
            <if test="blockCertificate.languageTypeId != null">and language_type_id = #{blockCertificate.languageTypeId}</if>
            <if test="blockCertificate.parentOperateId != null and blockCertificate.parentOperateId != ''">and parent_operate_id = #{blockCertificate.parentOperateId}</if>
        </where>
        ORDER BY sort asc
    </select>
    <select id="queryOperateDetails" resultType="cn.iocoder.yudao.module.chain.controller.admin.operatedetail.vo.OperateDetailRespVO">
        SELECT * FROM chain_operate_detail where chain_operate_id = #{chainOperateId} and deleted = false ORDER BY sort asc
    </select>

</mapper>
