<?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.gxwebsoft.pwl.mapper.PwlProjectMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*, u.real_name as realName, u.phone, u.avatar, dt.dict_data_name as invoiceTypeName
        FROM pwl_project a
        LEFT JOIN gxwebsoft_core.sys_user u ON a.user_id = u.user_id
        LEFT JOIN gxwebsoft_core.sys_dict_data dt ON a.invoice_type = dt.dict_data_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.companyId != null">
                AND a.company_id = #{param.companyId}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.code != null">
                AND a.code LIKE CONCAT('%', #{param.code}, '%')
            </if>
            <if test="param.caseIndex != null">
                AND a.case_index LIKE CONCAT('%', #{param.caseIndex}, '%')
            </if>
            <if test="param.parentId != null">
                AND a.parent_id = #{param.parentId}
            </if>
            <if test="param.type != null">
                AND a.type = #{param.type}
            </if>
            <if test="param.avatar != null">
                AND a.avatar LIKE CONCAT('%', #{param.avatar}, '%')
            </if>
            <if test="param.qrcode != null">
                AND a.qrcode LIKE CONCAT('%', #{param.qrcode}, '%')
            </if>
            <if test="param.url != null">
                AND a.url LIKE CONCAT('%', #{param.url}, '%')
            </if>
            <if test="param.images != null">
                AND a.images LIKE CONCAT('%', #{param.images}, '%')
            </if>
            <if test="param.files != null">
                AND a.files LIKE CONCAT('%', #{param.files}, '%')
            </if>
            <if test="param.content != null">
                AND a.content LIKE CONCAT('%', #{param.content}, '%')
            </if>
            <if test="param.totalAssets != null">
                AND a.total_assets = #{param.totalAssets}
            </if>
            <if test="param.contractPrice != null">
                AND a.contract_price = #{param.contractPrice}
            </if>
            <if test="param.payPrice != null">
                AND a.pay_price = #{param.payPrice}
            </if>
            <if test="param.price != null">
                AND a.price = #{param.price}
            </if>
            <if test="param.recommend != null">
                AND a.recommend = #{param.recommend}
            </if>
            <if test="param.expirationTime != null">
                AND a.expiration_time LIKE CONCAT('%', #{param.expirationTime}, '%')
            </if>
            <if test="param.itemName != null">
                AND a.item_name LIKE CONCAT('%', #{param.itemName}, '%')
            </if>
            <if test="param.itemYear != null">
                AND a.expiration_time LIKE CONCAT('%', #{param.itemYear}, '%')
            </if>
            <if test="param.itemType != null">
                AND a.item_type LIKE CONCAT('%', #{param.itemType}, '%')
            </if>
            <if test="param.itemOpinion != null">
                AND a.item_opinion LIKE CONCAT('%', #{param.itemOpinion}, '%')
            </if>
            <if test="param.bankName != null">
                AND a.bank_name LIKE CONCAT('%', #{param.bankName}, '%')
            </if>
            <if test="param.bankPayTime != null">
                AND a.bank_pay_time LIKE CONCAT('%', #{param.bankPayTime}, '%')
            </if>
            <if test="param.bankPrice != null">
                AND a.bank_price = #{param.bankPrice}
            </if>
            <if test="param.invoiceType != null">
                AND a.invoice_type LIKE CONCAT('%', #{param.invoiceType}, '%')
            </if>
            <if test="param.invoiceTime != null">
                AND a.invoice_time LIKE CONCAT('%', #{param.invoiceTime}, '%')
            </if>
            <if test="param.invoicePrice != null">
                AND a.invoice_price = #{param.invoicePrice}
            </if>
            <if test="param.reportNum != null">
                AND a.report_num = #{param.reportNum}
            </if>
            <if test="param.draftUserId != null">
                AND a.draft_user_id = #{param.draftUserId}
            </if>
            <if test="param.userIds != null">
                AND a.user_ids LIKE CONCAT('%', #{param.userIds}, '%')
            </if>
            <if test="param.signUserId != null">
                AND a.sign_user_id = #{param.signUserId}
            </if>
            <if test="param.saleUserId != null">
                AND a.sale_user_id = #{param.saleUserId}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.projectIds != null">
              AND a.id IN
              <foreach collection="param.projectIds" item="item" separator="," open="(" close=")">
                #{item}
              </foreach>
            </if>
            <if test="param.keywords != null">
              AND (a.name LIKE CONCAT('%', #{param.keywords}, '%')
              OR a.id = #{param.keywords}
              OR a.code = #{param.keywords}
              )
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.pwl.entity.PwlProject">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.pwl.entity.PwlProject">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="listByCount" resultType="com.gxwebsoft.common.system.entity.User">
      SELECT * FROM gxwebsoft_core.sys_user WHERE deleted = 0
    </select>


</mapper>
