<?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.system.dal.mysql.assets.AssetsMapper">

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

    <select id="selectAssetsChangeByIds"
            resultType="cn.iocoder.yudao.module.system.controller.admin.assets.dto.AssetsChangeDTO">
        SELECT
            a.id as assetsId,
            a.name,
            a.assets_no,
            a.stock,
            a.type_id,
            a.status,
            b.type
        FROM zc_assets a
        LEFT JOIN zc_assets_type b ON a.type_id = b.id
        <where>
            a.deleted = 0
            <if test="ids != null and ids.size() > 0">
                and a.id IN
                <foreach collection="ids" item="id" separator="," open="(" close=")">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>
    <select id="selectPageList" resultType="cn.iocoder.yudao.module.system.dal.dataobject.assets.AssetsDO">
        SELECT
        a.id,
        a.util,
        a.assets_no,
        a.item_json,
        a.name,
        a.amount,
        a.stock,
        a.type_id,
        a.status,
        a.create_time,
        a.creator,
        a.update_time,
        a.updater,
        a.deleted,
        b.type as type
        FROM zc_assets a
        left join zc_assets_type as b on a.type_id = b.id
        <where>
            a.deleted = 0
            <if test="reqVO.distributeFlag != null and reqVO.distributeFlag == 1">
                and a.stock > 0
            </if>
            <if test="reqVO.businessType != null">
                and b.business_type = #{reqVO.businessType}
            </if>
            <if test="reqVO.name != null and reqVO.name != ''">
                and a.name like concat('%', #{reqVO.name}, '%')
            </if>
            <if test="reqVO.assetsNo != null and reqVO.assetsNo != ''">
                and a.assets_no like concat('%', #{reqVO.keyWord}, '%')
            </if>
            <if test="reqVO.typeId != null">
                and a.type_id = #{reqVO.typeId}
            </if>
            <if test="reqVO.keyWord != null and reqVO.keyWord != ''">
                and (
                a.name like concat('%', #{reqVO.keyWord}, '%')
                or a.assets_no like concat('%', #{reqVO.keyWord}, '%')
                )
            </if>
        </where>
        order by a.create_time desc
    </select>
</mapper>
