<?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.zsElectric.boot.business.mapper.FirmInfoMapper">

    <!-- 获取企业信息分页列表 -->
    <select id="getFirmInfoPage" resultType="com.zsElectric.boot.business.model.vo.FirmInfoVO">
        SELECT
            a.id,
            a.dept_id,
            a.firm_type,
            a.NAME,
            COUNT( b.id ) AS empNum,
            a.STATUS,
            IFNULL(a.balance, 0.00) AS balance,
            IFNULL(a.total_recharge, 0.00) AS totalRecharge,
            IFNULL(a.current_profit, 0.00) AS currentProfit,
            IFNULL(a.total_profit, 0.00) AS totalProfit,
            a.create_time,
            a.create_by,
            a.update_time,
            a.update_by,
            a.is_deleted
        FROM
        c_firm_info a
        LEFT JOIN c_user_firm b ON a.id = b.firm_id AND b.is_deleted = 0
        <where>
            a.is_deleted = 0
            <if test="queryParams.deptId != null">
                AND a.dept_id = #{queryParams.deptId}
            </if>
            <if test="queryParams.firmType != null">
                AND a.firm_type = #{queryParams.firmType}
            </if>
            <if test="queryParams.name != null">
                AND a.name LIKE CONCAT('%', #{queryParams.name}, '%')
            </if>
         <if test="queryParams.status != null">
                AND a.status = #{queryParams.status}
            </if>
        </where>
        GROUP BY
        a.id
        ORDER BY a.create_time DESC
    </select>

</mapper>
