<?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.property.mapper.PropertyMapper">

    <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.property.entity.Property">
        <id property="id" column="cp_id" jdbcType="VARCHAR"/>
        <result property="corpId" column="cp_corp_id" jdbcType="VARCHAR"/>
        <result property="deptId" column="cp_dept_id" jdbcType="BIGINT"/>
        <result property="posId" column="cp_pos_id" jdbcType="VARCHAR"/>
        <result property="userId" column="cp_user_id" jdbcType="VARCHAR"/>
        <result property="propNo" column="cp_prop_no" jdbcType="VARCHAR"/>
        <result property="propName" column="cp_prop_name" jdbcType="VARCHAR"/>
        <result property="propCatg" column="cp_prop_catg" jdbcType="VARCHAR"/>
        <result property="useYear" column="cp_use_year" jdbcType="INTEGER"/>
        <result property="costType" column="cp_cost_type" jdbcType="VARCHAR"/>
        <result property="propNum" column="cp_prop_num" jdbcType="INTEGER"/>
        <result property="costTotal" column="cp_cost_total" jdbcType="DECIMAL"/>
        <result property="propStatus" column="cp_prop_status" jdbcType="VARCHAR"/>
        <result property="brand" column="cp_brand" jdbcType="VARCHAR"/>
        <result property="spec" column="cp_spec" jdbcType="VARCHAR"/>
        <result property="factory" column="cp_factory" jdbcType="VARCHAR"/>
        <result property="serialNo" column="cp_serial_no" jdbcType="VARCHAR"/>
        <result property="unit" column="cp_unit" jdbcType="VARCHAR"/>
        <result property="getDate" column="cp_get_date" jdbcType="DATE"/>
        <result property="prodDate" column="cp_prod_date" jdbcType="DATE"/>
        <result property="supplier" column="cp_supplier" jdbcType="VARCHAR"/>
        <result property="openDate" column="cp_open_date" jdbcType="DATE"/>
        <result property="netValue" column="cp_net_value" jdbcType="DECIMAL"/>
        <result property="voucherNo" column="cp_voucher_no" jdbcType="VARCHAR"/>
        <result property="keepCycleType" column="cp_keep_cycle_type" jdbcType="VARCHAR"/>
        <result property="keepCycle" column="cp_keep_cycle" jdbcType="INTEGER"/>
        <result property="lastKeepDate" column="cp_last_keep_date" jdbcType="DATE"/>
        <result property="nextKeepDate" column="cp_next_keep_date" jdbcType="DATE"/>
        <result property="fileUrls" column="cp_file_urls" jdbcType="VARCHAR"/>
        <result property="staffName" column="staff_name" jdbcType="VARCHAR" />
        <result property="posName" column="pos_name" jdbcType="VARCHAR" />
    </resultMap>

    <sql id="Base_SQL">
        SELECT cp.id              AS cp_id,
               cp.corp_id         AS cp_corp_id,
               cp.dept_id         AS cp_dept_id,
               cp.pos_id          AS cp_pos_id,
               cp.user_id         AS cp_user_id,
               cp.prop_no         AS cp_prop_no,
               cp.prop_name       AS cp_prop_name,
               cp.prop_catg       AS cp_prop_catg,
               cp.use_year        AS cp_use_year,
               cp.cost_type       AS cp_cost_type,
               cp.prop_num        AS cp_prop_num,
               cp.cost_total      AS cp_cost_total,
               cp.prop_status     AS cp_prop_status,
               cp.brand           AS cp_brand,
               cp.spec            AS cp_spec,
               cp.factory         AS cp_factory,
               cp.serial_no       AS cp_serial_no,
               cp.unit            AS cp_unit,
               cp.get_date        AS cp_get_date,
               cp.prod_date       AS cp_prod_date,
               cp.supplier        AS cp_supplier,
               cp.open_date       AS cp_open_date,
               cp.net_value       AS cp_net_value,
               cp.voucher_no      AS cp_voucher_no,
               cp.keep_cycle_type AS cp_keep_cycle_type,
               cp.keep_cycle      AS cp_keep_cycle,
               cp.last_keep_date  AS cp_last_keep_date,
               cp.next_keep_date  AS cp_next_keep_date,
               cp.file_urls       AS cp_file_urls,
               cs.name            AS staff_name,
               cpp.pos_name       AS pos_name
        FROM company_property cp
                 LEFT JOIN company_staff cs ON cp.user_id = cs.user_id
                 LEFT JOIN company_property_pos cpp ON cp.pos_id = cpp.id
        WHERE cp.deleted = '0'
    </sql>

    <select id="getPropertyPage" resultMap="BaseResultMap">
        <include refid="Base_SQL"/>
        <if test="map.propNo != null and  map.propNo != ''">
            ANd (cp.prop_no like concat('%', #{map.propNo}, '%'))
        </if>
        <if test="map.propName != null and map.propName != ''">
            AND (cp.prop_name like concat('%', #{map.propName}, '%'))
        </if>
        <if test="map.brand != null and map.brand != ''">
            AND (cp.brand like concat('%', #{map.brand}, '%'))
        </if>
        <if test="map.supplier != null and map.supplier != ''">
            AND (cp.supplier like concat('%', #{map.supplier}, '%'))
        </if>
        <if test="map.propCatg != null and map.propCatg != ''">
            AND (cp.prop_catg = #{map.propCatg})
        </if>
        <if test="map.costType != null and map.costType != ''">
            AND (cp.cost_type = #{map.costType})
        </if>
        <if test="map.propStatus != null and map.propStatus != ''">
            AND (cp.prop_status = #{map.propStatus})
        </if>
        <if test="map.voucherNo != null and map.voucherNo != ''">
            AND (cp.voucher_no like concat('%', #{map.voucherNo}, '%'))
        </if>
        <if test="map.factory != null and map.factory != ''">
            AND (cp.factory like concat('%', #{map.factory}, '%'))
        </if>
        <if test="map.posId != null and map.posId != ''">
            AND (cp.pos_id = #{map.posId})
        </if>
        <if test="map.userId != null and map.userId != ''">
            AND (cp.user_id = #{map.userId})
        </if>
        <if test="map.getDateArray != null and map.getDateArray.length > 0">
            AND (cp.get_date BETWEEN #{map.getDateArray[0]} AND #{map.getDateArray[1]})
        </if>
        <if test="map.openDateArray != null and map.openDateArray != ''">
            AND (cp.open_date BETWEEN #{map.openDateArray[0]} AND #{map.openDateArray[1]})
        </if>
        order by cp.create_time desc
    </select>
</mapper>