瀏覽代碼

Merge remote-tracking branch 'origin/master'

lin 4 年之前
父節點
當前提交
79da4fc2af

+ 2 - 1
src/main/java/com/zoniot/ccrc/dao/CommunityMapper.java

@@ -47,5 +47,6 @@ public interface CommunityMapper {
 
     List<CommunityDto> getListByCustomerIds(@Param("siteId") Integer siteId, @Param("customerIds") List<Integer> customerIds, @Param("communityName") String communityName, @Param("province") Integer province, @Param("city") Integer city, @Param("region") Integer region);
 
-    List<Community> getOrgCommunity(@Param("orgId") Integer orgId,@Param("areaId") Integer areaId);
+    List<Community> getOrgCommunity(@Param("orgId") Integer orgId, @Param("areaId") Integer areaId
+            , @Param("siteId") Integer siteId);
 }

+ 84 - 0
src/main/java/com/zoniot/ccrc/dao/CommunityOrgMapper.java

@@ -0,0 +1,84 @@
+package com.zoniot.ccrc.dao;
+
+
+import com.zoniot.ccrc.entity.CommunityOrg;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * (CommunityOrg)表数据库访问层
+ *
+ * @author hym
+ * @since 2021-03-26 15:05:15
+ */
+@Mapper
+public interface CommunityOrgMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    CommunityOrg selectById(Integer id);
+
+
+    /**
+     * 查询全部
+     *
+     * @return 对象列表
+     */
+    List<CommunityOrg> selectAll();
+
+    /**
+     * 通过实体作为筛选条件查询
+     *
+     * @param communityOrg 实例对象
+     * @return 对象列表
+     */
+    List<CommunityOrg> selectList(CommunityOrg communityOrg);
+
+    /**
+     * 新增数据
+     *
+     * @param communityOrg 实例对象
+     * @return 影响行数
+     */
+    int insert(CommunityOrg communityOrg);
+
+    /**
+     * 批量新增
+     *
+     * @param communityOrgs 实例对象的集合
+     * @return 影响行数
+     */
+    int batchInsert(@Param("communityOrgs") List<CommunityOrg> communityOrgs);
+
+    /**
+     * 修改数据
+     *
+     * @param communityOrg 实例对象
+     * @return 影响行数
+     */
+    int update(CommunityOrg communityOrg);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    /**
+     * 查询总数据数
+     *
+     * @return 数据总数
+     */
+    int count();
+
+   // IPage<CommunityOrg> selectPage(IPage<CommunityOrg> page, CommunityOrg communityOrg);
+
+}

+ 47 - 0
src/main/java/com/zoniot/ccrc/entity/CommunityOrg.java

@@ -0,0 +1,47 @@
+package com.zoniot.ccrc.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * (CommunityOrg)实体类
+ *
+ * @author hym
+ * @since 2021-03-26 15:22:52
+ */
+@Data
+@ApiModel
+public class CommunityOrg implements Serializable {
+    private static final long serialVersionUID = 575881793709690103L;
+    @ApiModelProperty(value = "")
+    private Integer id;
+    /**
+     * 机构id
+     */
+    @ApiModelProperty(value = "机构id")
+    private Integer orgId;
+    /**
+     * 小区id
+     */
+    @ApiModelProperty(value = "小区id")
+    private Integer communityId;
+    @ApiModelProperty(value = "")
+    private Date createDate;
+    @ApiModelProperty(value = "")
+    private Date updateDate;
+    @ApiModelProperty(value = "")
+    private String createBy;
+    @ApiModelProperty(value = "")
+    private String updateBy;
+    @ApiModelProperty(value = "")
+    private Integer status;
+    /**
+     * 站点id
+     */
+    @ApiModelProperty(value = "站点id")
+    private Integer siteId;
+}

+ 1 - 1
src/main/java/com/zoniot/ccrc/service/impl/CommunityServiceImpl.java

@@ -283,7 +283,7 @@ public class CommunityServiceImpl implements CommunityService {
     @Override
     public List<Community> getOrgCommunity(Integer orgId, Integer areaId) {
 
-        return communityMapper.getOrgCommunity(orgId,areaId);
+        return communityMapper.getOrgCommunity(orgId,areaId,UserUtil.getCurrentUser().getSiteId());
     }
 
     @Override

+ 18 - 4
src/main/java/com/zoniot/ccrc/service/impl/OrganizationServiceImpl.java

@@ -4,10 +4,12 @@ import com.alibaba.fastjson.JSON;
 import com.zoniot.ccrc.commom.exception.ServiceException;
 import com.zoniot.ccrc.commom.utils.TreeUtil;
 import com.zoniot.ccrc.commom.utils.UserUtil;
+import com.zoniot.ccrc.dao.CommunityOrgMapper;
 import com.zoniot.ccrc.dao.OrganizationMapper;
 import com.zoniot.ccrc.dao.UserMapper;
 import com.zoniot.ccrc.dto.LoginUser;
 import com.zoniot.ccrc.dto.OrganizationDto;
+import com.zoniot.ccrc.entity.CommunityOrg;
 import com.zoniot.ccrc.entity.Organization;
 import com.zoniot.ccrc.service.OrganizationService;
 import lombok.extern.slf4j.Slf4j;
@@ -16,9 +18,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.math.BigInteger;
 import java.time.LocalDateTime;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @Slf4j
 @Service
@@ -28,6 +28,8 @@ public class OrganizationServiceImpl implements OrganizationService {
     private OrganizationMapper organizationMapper;
     @Resource
     private UserMapper userMapper;
+    @Resource
+    private CommunityOrgMapper communityOrgMapper;
 
     @Override
     public int insert(Organization organization) {
@@ -99,7 +101,19 @@ public class OrganizationServiceImpl implements OrganizationService {
     private void updateOrgCommunity(Organization organization){
         List<Integer>communityIds=organization.getCommunityId();
         if(communityIds!=null&&communityIds.size()>0){
-            organizationMapper.updateCommutity(organization.getCommunityId(),organization.getId());
+            List<CommunityOrg>communityOrgs=new ArrayList<>();
+            communityIds.forEach(id->{
+                CommunityOrg communityOrg=new CommunityOrg();
+                communityOrg.setCommunityId(id);
+                communityOrg.setOrgId(organization.getId());
+                communityOrg.setSiteId(organization.getSiteId());
+                communityOrg.setStatus(1);
+                communityOrg.setCreateDate(new Date());
+                communityOrgs.add(communityOrg);
+            });
+            communityOrgMapper.batchInsert(communityOrgs);
+            //communityOrgMapper.updateCommutityRelations(organization.getCommunityId(),organization.getId());
+            //organizationMapper.updateCommutity(organization.getCommunityId(),organization.getId());
         }
     }
     @Override

+ 1 - 1
src/main/java/com/zoniot/ccrc/service/impl/SiteServiceImpl.java

@@ -123,7 +123,7 @@ public class SiteServiceImpl implements SiteService {
         role2.setName("水司管理员");
         role2.setDescription("");
         role2.setStatus(1);
-        role2.setType(1);
+        role2.setType(5);
         role2.setCreateBy(UserUtil.getUsername());
         role2.setCreateDate(LocalDateTime.now());
         role2.setUpdateBy(UserUtil.getUsername());

+ 13 - 6
src/main/resources/mapper/CommunityMapper.xml

@@ -408,8 +408,9 @@
         left join sc_area sa1 on sa1.id = sc.province
         left join sc_area sa2 on sa2.id = sc.city
         left join sc_area sa3 on sa3.id = sc.region
-        left join sc_organization so on sc.org_id=so.id
-        where sc.status = 1
+        left join sc_community_org sco on sc.id=sco.community_id
+        left join sc_organization so on sco.org_id=so.id
+        where sc.status = 1 and sco.status=1
         <if test="siteId != null"> and sc.site_id = #{siteId} </if>
         <if test="customerId != null"> and sc.customer_id = #{customerId} </if>
         <if test="communityName != null and communityName != ''"> and sc.name like concat('%',#{communityName} ,'%')</if>
@@ -480,14 +481,20 @@
         order by sc.date_create desc
     </select>
     <select id="getOrgCommunity" resultType="com.zoniot.ccrc.entity.Community">
-        select * from sc_community
+        select a.* from sc_community a left join sc_community_org b
+        on a.id=b.community_id
         <where>
+            a.customer_id in (select id from sc_customer where site_id=#{siteId})
             <if test="orgId!=null">
-                and org_id=#{orgId}
+                and b.org_id=#{orgId}
             </if>
             <if test="orgId==null">
-                and org_id is null
-                and region=#{areaId}
+                and a.region=#{areaId}
+                and not exists(
+                select 1 from sc_community_org sco where sco.community_id = a.id and sco.`STATUS` = 1
+                and sco.site_id=#{siteId}
+                    )
+
             </if>
         </where>
     </select>

+ 138 - 0
src/main/resources/mapper/CommunityOrgMapper.xml

@@ -0,0 +1,138 @@
+<?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.zoniot.ccrc.dao.CommunityOrgMapper">
+    <!-- 结果集 -->
+    <resultMap type="com.zoniot.ccrc.entity.CommunityOrg" id="CommunityOrgMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="orgId" column="org_id" jdbcType="INTEGER"/>
+        <result property="communityId" column="community_id" jdbcType="INTEGER"/>
+        <result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
+        <result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
+        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
+        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="siteId" column="site_id" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <!-- 基本字段 -->
+    <sql id="Base_Column_List">
+        id, org_id, community_id, create_date, update_date, create_by, update_by, status, site_id    </sql>
+
+    <!-- 查询单个 -->
+    <select id="selectById" resultMap="CommunityOrgMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sc_community_org
+        where id = #{id}
+    </select>
+
+
+    <!-- 查询全部 -->
+    <select id="selectAll" resultMap="CommunityOrgMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sc_community_org
+    </select>
+
+    <!--通过实体作为筛选条件查询-->
+    <select id="selectList" resultMap="CommunityOrgMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sc_community_org
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="orgId != null">
+                and org_id = #{orgId}
+            </if>
+            <if test="communityId != null">
+                and community_id = #{communityId}
+            </if>
+            <if test="createDate != null">
+                and create_date = #{createDate}
+            </if>
+            <if test="updateDate != null">
+                and update_date = #{updateDate}
+            </if>
+            <if test="createBy != null and createBy != ''">
+                and create_by = #{createBy}
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                and update_by = #{updateBy}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+            <if test="siteId != null">
+                and site_id = #{siteId}
+            </if>
+        </where>
+    </select>
+
+    <!-- 新增所有列 -->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into sc_community_org(id, org_id, community_id, create_date, update_date, create_by, update_by, status,
+                                     site_id)
+        values (#{id}, #{orgId}, #{communityId}, #{createDate}, #{updateDate}, #{createBy}, #{updateBy}, #{status},
+                #{siteId})
+    </insert>
+
+    <!-- 批量新增 -->
+    <insert id="batchInsert">
+        insert into sc_community_org(id, org_id, community_id, create_date, update_date, create_by, update_by, status,
+        site_id)
+        values
+        <foreach collection="communityOrgs" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.orgId}, #{item.communityId}, #{item.createDate}, #{item.updateDate}, #{item.createBy},
+            #{item.updateBy}, #{item.status}, #{item.siteId} )
+        </foreach>
+    </insert>
+
+    <!-- 通过主键修改数据 -->
+    <update id="update">
+        update sc_community_org
+        <set>
+            <if test="orgId != null">
+                org_id = #{orgId},
+            </if>
+            <if test="communityId != null">
+                community_id = #{communityId},
+            </if>
+            <if test="createDate != null">
+                create_date = #{createDate},
+            </if>
+            <if test="updateDate != null">
+                update_date = #{updateDate},
+            </if>
+            <if test="createBy != null and createBy != ''">
+                create_by = #{createBy},
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                update_by = #{updateBy},
+            </if>
+            <if test="status != null">
+                status = #{status},
+            </if>
+            <if test="siteId != null">
+                site_id = #{siteId},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete
+        from sc_community_org
+        where id = #{id}
+    </delete>
+
+    <!-- 总数 -->
+    <select id="count" resultType="int">
+        select count(*)
+        from sc_community_org
+    </select>
+
+</mapper>

+ 12 - 7
src/main/resources/mapper/GridManagementMapper.xml

@@ -38,10 +38,12 @@
     <select id="selectList" resultMap="GridManagementMap">
         select
          a.*,b.meter_no,b.loc_desc address,c.name bulidingName,
-         e.name orgName
+         e.name orgName,b.file_no
         from sc_grid_management a join sc_device b on a.device_id=b.id
         join sc_building c on b.building_id=c.id join sc_community d on c.community_id =d.id
-        left join sc_organization e on d.org_id=e.id
+        left join sc_community_org sco on sco.community_id=d.id
+
+        left join sc_organization e on sco.org_id=e.id
         <where>
              a.status=1
             <if test="id != null">
@@ -190,16 +192,18 @@
         select  b.id orgId,a.id,username,mobile_phone,a.name,b.name org_name,b.address,ifnull(c.peoples,0) peoples from
          sc_site_user ssu   join    sc_user a on ssu.user_id=a.id
          join sc_organization b on ssu.organ_id=b.id
+        join sc_user_role d on d.uid=a.id join sc_role e on e.id=d.rid
          left join (select count(*)peoples,user_id from sc_grid_management group by user_id)c
          on a.id=c.user_id
         <where>
+            a.status=1 and d.status=1
             <if test="type == 4 ">
                 and a.id=#{userId}
             </if>
             <if test="type != 4 ">
-                and ssu.type=4
+                and e.type=4
             </if>
-                a.status=1
+
             <if test="username != null and username!='' ">
                 and username LIKE concat('%',#{username},'%')
             </if>
@@ -214,12 +218,13 @@
         order by ssu.create_date desc
     </select>
     <select id="getCommutityByOrg" resultType="com.zoniot.ccrc.entity.Community">
-        select * from sc_community a
-        where  a.org_id in
+        select * from sc_community a join sc_community_org b
+        on a.id=b.community_id
+        where  b.org_id in
         <foreach collection="ids" item="id" open="(" separator="," close=")">
             #{id}
         </foreach>
-             and status=1
+             and b.status=1
     </select>
     <select id="getBuildingByCommutity" resultType="com.zoniot.ccrc.entity.Building">
         select * from sc_building where community_id=#{commutityId} and status=1

+ 1 - 1
src/main/resources/mapper/OrganizationMapper.xml

@@ -182,7 +182,7 @@
         </foreach>
     </update>
     <delete id="deleteCommutityRations">
-        update sc_community set org_id=null where org_id=#{id}
+        update sc_community_org set status=0 where org_id=#{id}
     </delete>
 
     <select id="findList" resultType="com.zoniot.ccrc.dto.OrganizationDto">

+ 1 - 1
src/main/resources/mapper/RoleMapper.xml

@@ -152,7 +152,7 @@ type
         select <include refid="Base_Column_List"/> from sc_role
         where site_id=#{siteId} and status = 1
         <if test="name != null"> AND name LIKE concat('%',#{name},'%')</if>
-        <if test="type != null"> and type = #{type}</if>
+        <if test="type != null"> and type in (4,5) </if>
         order by create_date desc
     </select>
     <select id="findByType" resultMap="BaseResultMap">

+ 3 - 0
src/main/resources/mapper/SiteMapper.xml

@@ -190,6 +190,9 @@
         </foreach>
         )
     </update>
+    <update id="updateOrgId">
+        update sc_site_user set organ_id=#{orgId} where user_id=#{userId}
+    </update>
 
 
     <select id="findByNameUnique" resultType="int">

+ 5 - 3
src/main/resources/mapper/SiteUserMapper.xml

@@ -230,10 +230,12 @@
         left join sc_site ss on (ss.id = ssu.site_id and ss.status = 1)
         where ssu.status = 1 and ssu.user_id = #{userId}
     </select>
-    <select id="findBySiteIdAndUserId" resultMap="BaseResultMap">
+    <select id="findBySiteIdAndUserId" resultType="com.zoniot.ccrc.entity.SiteUser">
         select
-        <include refid="Base_Column_List"/>
-        from sc_site_user where site_id = #{siteId} and user_id = #{userId} and status = 1 limit 1
+        a.organ_id,a.site_id,a.is_admin,a.type,c.type roleType
+        from sc_site_user a
+        left join sc_user_role b on a.user_id=b.uid left join sc_role  c on b.rid=c.id
+        where a.site_id = #{siteId} and a.user_id = #{userId} and a.status = 1 and b.status=1 limit 1
     </select>
 
     <update id="deleteBySiteIdAndUserIds">

+ 2 - 0
src/main/resources/mapper/UserMapper.xml

@@ -199,11 +199,13 @@
         sr.id as role_id,
         sr.name as role_name,
         ssu.organ_id,
+        so.name organName,
         ssu.type
         from sc_site_user ssu
         LEFT JOIN sc_user su on su.id = ssu.user_id
         LEFT JOIN sc_user_role sur on sur.uid = su.id and sur.status = 1
         LEFT JOIN sc_role sr on sr.id = sur.rid and sr.status = 1
+        left join sc_organization so on ssu.organ_id =so.id
         WHERE ssu.status=1 and ssu.site_id = #{siteId} and sr.site_id = #{siteId}
         <if test="username != null and username != ''"> AND su.username LIKE concat('%',#{username},'%')</if>
         <if test="name != null and name != ''"> AND su.`name` LIKE concat('%',#{name},'%')</if>