linwei
2024-01-31 b3b566ebdfed4005aaa513da3d5d2fd3924903cc
src/main/java/org/springblade/modules/place/mapper/PlaceMapper.xml
@@ -2,16 +2,294 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.place.mapper.PlaceMapper">
    <!--详情map-->
    <resultMap id="detailMap" type="org.springblade.modules.place.vo.PlaceVO" autoMapping="true">
        <id property="id" column="id"/>
        <collection property="placePoiLabelVOList" javaType="java.util.List" ofType="org.springblade.modules.place.vo.PlacePoiLabelVO"
        autoMapping="true">
            <id property="id" column="plid"/>
            <result property="remark" column="cremark"/>
        </collection>
    </resultMap>
    <!--自定义分页查询-->
    <select id="selectPlacePage" resultType="org.springblade.modules.place.vo.PlaceVO">
        select * from jczz_place where is_deleted = 0
        select
        jp.*,
        jpe.id as placeExtId,
        bu.real_name as username,bu.phone as phone,
        br.town_name as townStreetName,br.name as neiName,
        jpe.confirm_flag confirmFlag,
        jg.grid_name as gridName
        from jczz_place jp
        left join blade_user bu on bu.id = jp.principal_user_id and bu.is_deleted = 0
        left join jczz_place_ext jpe on jpe.place_id=jp.id and jpe.is_deleted = 0
        left join jczz_grid jg on jg.grid_code = jp.grid_code and jg.is_deleted = 0
        left join blade_region br on br.code = jg.community_code
        left join (
        select a.* from jczz_place_poi_label a inner join
        (
        select place_id,max(id) as id from jczz_place_poi_label b group by place_id
        ) b on a.id = b.id
        ) jppl on jppl.place_id = jp.id
        where jp.is_deleted = 0 and jp.source!=3
        and jp.place_name != ''
        <if test="place.placeName!=null and place.placeName!=''">
            and jp.place_name like concat('%',#{place.placeName},'%')
        </if>
        <if test="place.principal!=null and place.principal!=''">
            and jp.principal like concat('%',#{place.principal},'%')
        </if>
        <if test="place.principalPhone!=null and place.principalPhone!=''">
            and jp.principal_phone like concat('%',#{place.principalPhone},'%')
        </if>
        <if test="place.houseCode!=null and place.houseCode!=''">
            and jp.house_code like concat('%',#{place.houseCode},'%')
        </if>
        <if test="place.townStreetName!=null and place.townStreetName!=''">
            and br.town_name like concat('%',#{place.townStreetName},'%')
        </if>
        <if test="place.neiName!=null and place.neiName!=''">
            and br.name like concat('%',#{place.neiName},'%')
        </if>
        <if test="place.id!=null">
            and jp.id = #{place.id}
        </if>
        <if test="place.source!=null">
            and jp.source = #{place.source}
        </if>
        <if test="place.isPerfect==1">
            and jp.status = 1
        </if>
        <if test="place.isPerfect==2">
            and jp.status = 2
        </if>
        <if test="houseCodeList != null and houseCodeList.size()>0">
            and jp.house_code in
            <foreach collection="houseCodeList" item="houseCode" separator ="," open="("  close=")">
                #{houseCode}
            </foreach>
        </if>
        <if test="isAdministrator==2">
            <choose>
                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                    and jg.grid_code in
                    <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                        #{code}
                    </foreach>
                </when>
                <otherwise>
                    and jg.grid_code in ('')
                </otherwise>
            </choose>
        </if>
        order by jp.create_time desc,jp.id desc
    </select>
    <!--查询场所集合信息-->
    <select id="selectPlaceNodeList" resultType="org.springblade.common.node.TreeNode" >
        select id,place_name as name,false as hasChildren from jczz_place
        where 1=1
        and principal = #{userId}
    <select id="selectPlaceNodeList" resultType="org.springblade.common.node.TreeStringNode" >
        SELECT jp.id,
               jp.house_code      houseCode,
               jp.place_name AS   NAME,
               jp.is_nine AS isNine,
               br.name neiName,
               FALSE         AS   hasChildren
        FROM jczz_place jp
                 LEFT JOIN jczz_grid jg on jp.grid_code = jg.grid_code and jg.is_deleted = 0
                 LEFT JOIN blade_region br on br.code = jg.community_code
        where 1 = 1
          and jp.is_deleted = 0
          and jp.principal_user_id = #{userId}
    </select>
    <!--插入用户标签-->
    <insert id="saveUserLabel">
        insert into jczz_user_house_label(user_id,label_id,lable_type)
        values(#{userId},#{labelId},1)
    </insert>
    <!--查询所有的场所(手机号不为空)-->
    <select id="getPlaceNotNullPhone" resultType="org.springblade.modules.place.vo.PlaceVO">
        select link_person as username,link_tel as phone,std_id as houseCode from wgccp_place
        WHERE link_person !='' and link_tel!=''
    </select>
    <!--查询所有的场所-->
    <select id="getAllHistoryPlace" resultType="org.springblade.modules.place.vo.PlaceVO">
        select place_id as id,third_level_id as label,std_id as houseCode from wgccp_place
    </select>
    <!--更新场所信息-->
    <update id="updatePlaceEntity">
        update jczz_place set principal_user_id = #{place.principalUserId}
        WHERE house_code = #{place.houseCode}
    </update>
    <!--查询场所详情数据-->
    <select id="getDetail" resultMap="detailMap">
        select
        jp.*,
        bu.real_name as username,bu.phone as phone,
        jppl.id as plid,
        jppl.place_id,
        jppl.poi_code,
        jppl.type,
        jppl.color,
        jppl.remark as cremark,
        jc.category_name as labelName,
        br.code as neiCode
        from jczz_place jp
        left join blade_user bu on bu.id = jp.principal_user_id and bu.is_deleted = 0
        left join jczz_place_poi_label jppl on jppl.place_id = jp.id
        left join jczz_category jc on jc.category_no = jppl.poi_code
        left join jczz_grid jg on jp.grid_code = jg.grid_code and jg.is_deleted = 0
        left join blade_region br on br.code = jg.community_code
        where jp.is_deleted = 0
        <if test="place.houseCode!=null and place.houseCode!=''">
            and jp.house_code like concat('%',#{place.houseCode},'%')
        </if>
        <if test="place.id!=null">
            and jp.id = #{place.id}
        </if>
    </select>
    <!--判断商超是否导入-->
    <select id="getPlaceAndRelInfo" resultType="org.springblade.modules.place.entity.PlaceEntity">
        select
        jp.*
        from jczz_place jp
        left join jczz_place_rel jpr on jpr.place_id = jp.id and jpr.is_deleted = 0
        where jp.is_deleted = 0
        <if test="place.buildingName!=null and place.buildingName!=''">
            and jpr.building_name = #{place.buildingName}
        </if>
        <if test="place.doorplateNum!=null and place.doorplateNum!=''">
            and jpr.doorplate_num = #{place.doorplateNum}
        </if>
        <if test="place.placeName!=null and place.placeName!=''">
            and jp.place_name = #{place.placeName}
        </if>
        limit 1
    </select>
    <!--查询出有用户id 的场所-->
    <select id="getHasUserIdPlaceList" resultType="org.springblade.modules.place.entity.PlaceEntity">
        select
        jp.*
        from jczz_place jp
        left join blade_user bu on bu.id = jp.principal_user_id and bu.is_deleted = 0
        where jp.is_deleted = 0 and jp.principal_user_id is not null
    </select>
    <!--查询所有的场所数据(除去详情表已有的)-->
    <select id="getPlaceListByNoExt" resultType="org.springblade.modules.place.entity.PlaceEntity">
        select
        jp.*
        from jczz_place jp
        LEFT JOIN jczz_place_ext jpe on jpe.place_id=jp.id and jpe.is_deleted = 0
        where jp.is_deleted = 0 and jpe.id is null
    </select>
    <!--商超数据处理-->
    <select id="placeAndRelHandle" resultType="org.springblade.modules.place.entity.PlaceEntity">
        select jp.* from jczz_place jp
        left join jczz_place_rel jpr on jp.id = jpr.place_id and jpr.is_deleted =0
        where jpr.id is not null
        and jp.is_deleted = 0
        and jp.source !=3
    </select>
    <!--根据标签编号集合查询对应的场所-->
    <select id="getPlaceListByParam" resultType="org.springblade.modules.place.vo.PlaceVO">
        select jp.*,jppl.poi_code as label from jczz_place jp
        left join jczz_place_poi_label jppl on jppl.place_id = jp.id
        where jp.is_deleted = 0 and jppl.type = 3
        and jppl.color = 'green'
        and jp.principal_user_id is not null
        and jp.house_code != ''
        and jp.id in (
            select place_id from ${tableName} where is_deleted = 0 and source = 2 and TIMESTAMPDIFF( day, now(), create_time )=30
        )
        <choose>
            <when test="list!=null and list.size()>0">
                and jppl.poi_code in
                <foreach collection="list" item="id" separator="," open="(" close=")">
                    #{id}
                </foreach>
            </when>
            <otherwise>
                and jppl.poi_code in ('')
            </otherwise>
        </choose>
        union all
        (
        select jp.*,jppl.poi_code as label from jczz_place jp
        left join jczz_place_poi_label jppl on jppl.place_id = jp.id
        where jp.is_deleted = 0 and jppl.type = 3
        and jppl.color = 'yellow'
        and jp.principal_user_id is not null
        and jp.house_code != ''
        and jp.id in (
            select place_id from ${tableName} where is_deleted = 0 and source = 2 and TIMESTAMPDIFF( day, now(), create_time )=14
        )
        <choose>
            <when test="list!=null and list.size()>0">
                and jppl.poi_code in
                <foreach collection="list" item="id" separator="," open="(" close=")">
                    #{id}
                </foreach>
            </when>
            <otherwise>
                and jppl.poi_code in ('')
            </otherwise>
        </choose>
        )
        union all
        (
        select jp.*,jppl.poi_code as label from jczz_place jp
        left join jczz_place_poi_label jppl on jppl.place_id = jp.id
        where jp.is_deleted = 0 and jppl.type = 3
        and jppl.color = 'red'
        and jp.principal_user_id is not null
        and jp.house_code != ''
        and jp.id in (
            select place_id from ${tableName} where is_deleted = 0 and source = 2 and TIMESTAMPDIFF( day, now(), create_time )=7
        )
        <choose>
            <when test="list!=null and list.size()>0">
                and jppl.poi_code in
                <foreach collection="list" item="id" separator="," open="(" close=")">
                    #{id}
                </foreach>
            </when>
            <otherwise>
                and jppl.poi_code in ('')
            </otherwise>
        </choose>
        )
        union all
        (
        select jp.*,jppl.poi_code as label from jczz_place jp
        left join jczz_place_poi_label jppl on jppl.place_id = jp.id
        where jp.is_deleted = 0 and jppl.type = 3
        and jp.principal_user_id is not null
        and jp.house_code != ''
        and (jppl.color = 'green' or jppl.color = 'yellow' or jppl.color = 'red')
        and jp.id not in (
            select place_id from ${tableName} where is_deleted = 0 and source = 2 and place_id is not null group by place_id
        )
        <choose>
            <when test="list!=null and list.size()>0">
                and jppl.poi_code in
                <foreach collection="list" item="id" separator="," open="(" close=")">
                    #{id}
                </foreach>
            </when>
            <otherwise>
                and jppl.poi_code in ('')
            </otherwise>
        </choose>
        )
    </select>
</mapper>