<?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.yeejoin.amos.boot.module.common.api.mapper.MaintenanceCompanyMapper">
    <select id="selectOrgUsrList" resultType="com.yeejoin.amos.boot.module.common.api.dto.OrgUsrDto">
    SELECT DISTINCT
	sequence_nbr,
	biz_org_name,
	biz_org_code,
	amos_org_id,
	amos_org_code,
	biz_org_type,
	build_name,
	build_id,
	parent_id
FROM
	cb_org_usr
WHERE
	sequence_nbr IN ( SELECT DISTINCT signed_company_id FROM cb_contract WHERE company_id = #{seq} )
	AND biz_org_type = "COMPANY"
	AND is_delete = 0
    </select>
    <select id="selectOrgUsrPageList" resultType="com.yeejoin.amos.boot.module.common.api.dto.OrgUsrDto">
    SELECT DISTINCT
	sequence_nbr,
	biz_org_name,
	biz_org_code,
	amos_org_id,
	amos_org_code,
	biz_org_type,
	build_name,
	build_id,
	parent_id
FROM
	cb_org_usr
WHERE
	sequence_nbr IN ( SELECT DISTINCT signed_company_id FROM cb_contract WHERE company_id = #{seq} )
	AND biz_org_type = "COMPANY"
	AND is_delete = 0
    </select>
	<select id="findByInstanceIdAndType" resultType="com.yeejoin.amos.boot.module.common.api.entity.MaintenanceCompany">
		SELECT
			m.sequence_nbr,
			m.`name`,
			m.`code`,
			m.type,
			m.instance_id
		FROM
			cb_maintenance_company m
		<where>
			<if test="instanceId != null">
				m.instance_id = #{instanceId}
			</if>
			<if test="type != null and type != ''">
				AND m.type = #{type}
			</if>
		</where>
	</select>
	<select id="findByCodeAndType" resultType="com.yeejoin.amos.boot.module.common.api.entity.MaintenanceCompany">
		SELECT
			m.sequence_nbr,
			m.`name`,
			m.`code`,
			m.type,
			m.instance_id
		FROM
			cb_maintenance_company m
		<where>
			<if test="code != null and code != ''">
				m.code LIKE CONCAT(#{code}, '%')
			</if>
			<if test="type != null and type != ''">
				AND m.type = #{type}
			</if>
		</where>
		ORDER BY
			m.sequence_nbr DESC
	</select>
</mapper>
