<?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="org.agt.module.license.dal.mysql.customer.CustomerMapper">

    <select id="selectMaxCode" resultType="Integer">
        SELECT max(`code` + 0) from crm_customer;
    </select>

    <select id="selectUserCount" resultType="Long">
        select count(*) from system_users WHERE deleted = 0 and username != 'agtuser';
    </select>

    <select id="getUserByName" resultType="Long">
        select id from system_users where deleted = 0 and nickname = #{nickname} limit 1;
    </select>

    <select id="selectOldMaxCode" resultType="Integer">
        SELECT max(`code` + 0) from crm_customer where `code` + 0 &lt; 2000
    </select>

    <select id="getLicenseCustomers" resultType="org.agt.module.license.controller.admin.customer.vo.CustomerRespVO">
        SELECT
        	c.*
        FROM
        	`crm_project` p
        	LEFT JOIN `crm_license_server` l ON p.id = l.project_id
        	AND l.deleted = 0
        	LEFT JOIN `crm_customer` c ON c.id = p.customer_id
        	AND c.deleted = 0
        WHERE
        	p.deleted = 0
        	AND l.id IS NULL
        	AND c.id IS NOT NULL
    </select>
</mapper>