<?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.project.mapper.ProjectMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*, b.real_name as nickname, b.avatar,c.website_type as appType, u.real_name as companyName, u.phone as superAdminPhone
        FROM project a
        LEFT JOIN gxwebsoft_core.sys_user b ON a.user_id = b.user_id
        LEFT JOIN cms_website c ON a.website_id = c.website_id
        LEFT JOIN gxwebsoft_core.sys_user u ON a.company_id = u.user_id
        <where>
            <if test="param.appId != null">
                AND a.app_id = #{param.appId}
            </if>
            <if test="param.appName != null">
                AND a.app_name LIKE CONCAT('%', #{param.appName}, '%')
            </if>
            <if test="param.appCode != null">
                AND a.app_code LIKE CONCAT('%', #{param.appCode}, '%')
            </if>
            <if test="param.appSecret != null">
                AND a.app_secret LIKE CONCAT('%', #{param.appSecret}, '%')
            </if>
            <if test="param.parentId != null">
                AND a.parent_id = #{param.parentId}
            </if>
            <if test="param.websiteId != null">
              AND a.website_id = #{param.websiteId}
            </if>
            <if test="param.appType != null">
                AND a.app_type LIKE CONCAT('%', #{param.appType}, '%')
            </if>
            <if test="param.appTypeMultiple != null">
                AND a.app_type_multiple LIKE CONCAT('%', #{param.appTypeMultiple}, '%')
            </if>
            <if test="param.menuType != null">
                AND a.menu_type = #{param.menuType}
            </if>
            <if test="param.companyId != null">
                AND a.company_id = #{param.companyId}
            </if>
            <if test="param.companyName != null">
                AND a.company_name LIKE CONCAT('%', #{param.companyName}, '%')
            </if>
            <if test="param.loginPhone != null">
              AND u.phone = #{param.loginPhone}
            </if>
            <if test="param.appIcon != null">
                AND a.app_icon LIKE CONCAT('%', #{param.appIcon}, '%')
            </if>
            <if test="param.appQrcode != null">
                AND a.app_qrcode LIKE CONCAT('%', #{param.appQrcode}, '%')
            </if>
            <if test="param.appUrl != null">
                AND a.app_url LIKE CONCAT('%', #{param.appUrl}, '%')
            </if>
            <if test="param.adminUrl != null">
                AND a.admin_url LIKE CONCAT('%', #{param.adminUrl}, '%')
            </if>
            <if test="param.downUrl != null">
                AND a.down_url LIKE CONCAT('%', #{param.downUrl}, '%')
            </if>
            <if test="param.serverUrl != null">
                AND a.server_url LIKE CONCAT('%', #{param.serverUrl}, '%')
            </if>
            <if test="param.fileUrl != null">
                AND a.file_url LIKE CONCAT('%', #{param.fileUrl}, '%')
            </if>
            <if test="param.callbackUrl != null">
                AND a.callback_url LIKE CONCAT('%', #{param.callbackUrl}, '%')
            </if>
            <if test="param.docsUrl != null">
                AND a.docs_url LIKE CONCAT('%', #{param.docsUrl}, '%')
            </if>
            <if test="param.gitUrl != null">
                AND a.git_url LIKE CONCAT('%', #{param.gitUrl}, '%')
            </if>
            <if test="param.prototypeUrl != null">
                AND a.prototype_url LIKE CONCAT('%', #{param.prototypeUrl}, '%')
            </if>
            <if test="param.ipAddress != null">
                AND a.ip_address LIKE CONCAT('%', #{param.ipAddress}, '%')
            </if>
            <if test="param.images != null">
                AND a.images LIKE CONCAT('%', #{param.images}, '%')
            </if>
            <if test="param.packageName != null">
                AND a.package_name LIKE CONCAT('%', #{param.packageName}, '%')
            </if>
            <if test="param.clicks != null">
                AND a.clicks = #{param.clicks}
            </if>
            <if test="param.installs != null">
                AND a.installs = #{param.installs}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.content != null">
                AND a.content LIKE CONCAT('%', #{param.content}, '%')
            </if>
            <if test="param.requirement != null">
                AND a.requirement LIKE CONCAT('%', #{param.requirement}, '%')
            </if>
            <if test="param.developer != null">
                AND a.developer LIKE CONCAT('%', #{param.developer}, '%')
            </if>
            <if test="param.director != null">
                AND a.director LIKE CONCAT('%', #{param.director}, '%')
            </if>
            <if test="param.projectDirector != null">
                AND a.project_director LIKE CONCAT('%', #{param.projectDirector}, '%')
            </if>
            <if test="param.salesman != null">
                AND a.salesman LIKE CONCAT('%', #{param.salesman}, '%')
            </if>
            <if test="param.price != null">
                AND a.price = #{param.price}
            </if>
            <if test="param.linePrice != null">
                AND a.line_price = #{param.linePrice}
            </if>
            <if test="param.score != null">
                AND a.score LIKE CONCAT('%', #{param.score}, '%')
            </if>
            <if test="param.star != null">
                AND a.star LIKE CONCAT('%', #{param.star}, '%')
            </if>
            <if test="param.year != null">
              AND a.year = #{param.year}
            </if>
            <if test="param.month != null">
              AND a.month = #{param.month}
            </if>
            <if test="param.day != null">
              AND a.day = #{param.day}
            </if>
            <if test="param.path != null">
                AND a.path LIKE CONCAT('%', #{param.path}, '%')
            </if>
            <if test="param.component != null">
                AND a.component LIKE CONCAT('%', #{param.component}, '%')
            </if>
            <if test="param.authority != null">
                AND a.authority LIKE CONCAT('%', #{param.authority}, '%')
            </if>
            <if test="param.target != null">
                AND a.target LIKE CONCAT('%', #{param.target}, '%')
            </if>
            <if test="param.hide != null">
                AND a.hide = #{param.hide}
            </if>
            <if test="param.search != null">
                AND a.search = #{param.search}
            </if>
            <if test="param.active != null">
                AND a.active LIKE CONCAT('%', #{param.active}, '%')
            </if>
            <if test="param.meta != null">
                AND a.meta LIKE CONCAT('%', #{param.meta}, '%')
            </if>
            <if test="param.edition != null">
                AND a.edition LIKE CONCAT('%', #{param.edition}, '%')
            </if>
            <if test="param.version != null">
                AND a.version LIKE CONCAT('%', #{param.version}, '%')
            </if>
            <if test="param.isUse != null">
                AND a.is_use = #{param.isUse}
            </if>
            <if test="param.file1 != null">
                AND a.file1 LIKE CONCAT('%', #{param.file1}, '%')
            </if>
            <if test="param.file2 != null">
                AND a.file2 LIKE CONCAT('%', #{param.file2}, '%')
            </if>
            <if test="param.file3 != null">
                AND a.file3 LIKE CONCAT('%', #{param.file3}, '%')
            </if>
            <if test="param.showExpiration != null">
                AND a.show_expiration = #{param.showExpiration}
            </if>
            <if test="param.showCase != null">
                AND a.show_case = #{param.showCase}
            </if>
            <if test="param.showIndex != null">
                AND a.show_index = #{param.showIndex}
            </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.soon != null">
                AND a.soon = #{param.soon}
            </if>
            <if test="param.renewMoney != null">
                AND a.renew_money = #{param.renewMoney}
            </if>
            <if test="param.appStatus != null">
                AND a.app_status LIKE CONCAT('%', #{param.appStatus}, '%')
            </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.organizationId != null">
                AND a.organization_id = #{param.organizationId}
            </if>
            <if test="param.tenantCode != null">
                AND a.tenant_code LIKE CONCAT('%', #{param.tenantCode}, '%')
            </if>
          <if test="param.expirationTimeStart != null">
            AND a.expiration_time &gt;= #{param.expirationTimeStart}
          </if>
          <if test="param.expirationTimeEnd != null">
            AND a.expiration_time &lt;= #{param.expirationTimeEnd}
          </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.appIds != null">
              AND a.app_id IN
              <foreach collection="param.appIds" item="item" separator="," open="(" close=")">
                #{item}
              </foreach>
            </if>
            <if test="param.keywords != null">
                AND (a.app_name LIKE CONCAT('%', #{param.keywords}, '%')
                  OR a.app_id = #{param.keywords}
                  OR a.app_code = #{param.keywords}
                  OR a.app_name LIKE CONCAT('%', #{param.keywords}, '%')
                )
              </if>
        </where>
    </sql>

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

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


    <!-- 统计金额总和 -->
    <select id="selectSumMoney" resultType="java.math.BigDecimal">
      SELECT COALESCE(SUM(renew_money), 0) as total_money
      FROM project
      <if test="ew != null">
        ${ew.customSqlSegment}
      </if>
    </select>


</mapper>
