<?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.bonus.canteen.core.drp.mapper.DrpUnitMapper">
    <!-- 分页获取计量单位 -->
    <select id="selectAllList" resultType="com.bonus.canteen.core.drp.vo.DrpUnitPageVO">
        select du.unit_id    unitId,
               du.unit_name  unitName,
               du.rate,
               du.weigh_type weighType,
               du.crby,
               du.crtime,
               du.upby,
               du.uptime,
               du.area_id,
               aa.area_name
        from drp_unit du
                 left join alloc_area aa on du.area_id = aa.area_id
        where du.del_flag = #{delFlag}
        <if test="content.unitId != null">
            and du.unit_id = #{content.unitId}
        </if>
        <if test="content.areaId != null">
            and (du.area_id = #{content.areaId} or du.area_id is null)
        </if>
        <if test="content.ifListUse == 1 and content.areaId == null">
            and du.area_id is null
        </if>
        <!--区域权限-->
        <if test="content.areaAuth != null and content.areaAuth.size() > 0">
            and (du.area_id in
            <foreach collection="content.areaAuth" item="areaId" separator="," open="(" close=")">
                #{areaId}
            </foreach>
            or du.area_id is null )
        </if>
        <if test="content.unitName != null and content.unitName != ''">
            and du.unit_name like concat(concat('%', #{content.unitName}), '%')
        </if>
        order by du.id desc
    </select>
    <select id="listUnitAll" resultType="com.bonus.canteen.core.drp.vo.DrpUnitListVO">
        SELECT du.unit_id,
               du.unit_name,
               du.rate,
               du.weigh_type,
               du.area_id,
               aa.area_name
        FROM drp_unit du
                 LEFT JOIN alloc_area aa ON aa.area_id = du.area_id
        WHERE du.del_flag = #{delFlag}
        <if test="content.areaId != null">
            and (du.area_id = #{content.areaId} or du.area_id is null)
        </if>
        <if test="content.areaAuth != null and content.areaAuth.size() > 0">
            and (aa.area_id in
            <foreach collection="content.areaAuth" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
            or aa.area_id is null)
        </if>
        <if test="content.weighType != null">
            and du.weigh_type = #{content.weighType}
        </if>
    </select>

    <select id="getUnitIdByNameAndArea" resultType="java.lang.Long">
        select unit_id
        from drp_unit
        where unit_name = #{unitName}
          and del_flag = 2
        <if test="areaId != null">
            and (area_id = #{areaId} or area_id is null)
        </if>
        <if test="areaId == null">
            and area_id is null
        </if>
    </select>
</mapper>















































