lin 4 سال پیش
والد
کامیت
e8392cdbe1

+ 2 - 1
src/main/java/com/zoniot/ccrc/controller/system/WarningLogController.java

@@ -32,6 +32,7 @@ public class WarningLogController {
     @GetMapping("getList")
     @ApiOperation(value = "查询预警记录列表")
     public AjaxMessage<Pagination<WarningLogDto>> getList(
+            @ApiParam(value = "设备ID", required = false) @RequestParam(required = false) Long deviceId,
             @ApiParam(value = "场景ID", required = false) @RequestParam(required = false) Integer channelId,
             @ApiParam(value = "设备编号/电子号", required = false) @RequestParam(required = false) String deviceNo,
             @ApiParam(value = "预警类型 1:较上日用水量激增30% 2:连续无用水量超过7天", required = false) @RequestParam(required = false) Integer warningType,
@@ -48,7 +49,7 @@ public class WarningLogController {
             @ApiParam(value = "条数,非必传,默认15条", required = false, defaultValue = "15") @RequestParam(required = false, defaultValue = "15") int pageSize
     ){
         Pagination<WarningLogDto> pageInfo = warningLogService.getList(
-                channelId,deviceNo,warningType,clientName,feedbackStatus,provinceId,cityId,regionId,communityId,buildingId,
+                deviceId,channelId,deviceNo,warningType,clientName,feedbackStatus,provinceId,cityId,regionId,communityId,buildingId,
                 startDate,endDate, pageNum, pageSize);
         return new AjaxMessage<>(ResultStatus.OK, pageInfo);
     }

+ 5 - 1
src/main/java/com/zoniot/ccrc/dao/OrganizationMapper.java

@@ -35,7 +35,11 @@ public interface OrganizationMapper {
 
     String findOrginName(@Param("id") String id, @Param("siteId") Integer siteId, @Param("customerId") Integer customerId);
 
-    void updateCommutity(@Param("communityIds")List<Integer> communityId, @Param("id")Integer id);
+    void updateCommutity(@Param("communityIds") List<Integer> communityId, @Param("id") Integer id);
 
     void deleteCommutityRations(@Param("id") Integer id);
+
+    List<Integer> findCommunityIds(@Param("orgId") Integer orgId);
+
+    Integer findSiteId(@Param("customerId") Integer customerId);
 }

+ 3 - 0
src/main/java/com/zoniot/ccrc/dao/WarningLogMapper.java

@@ -18,6 +18,8 @@ public interface WarningLogMapper {
 
     List<WarningLogDto> getList(
             @Param("siteId") Integer siteId,
+            @Param("deviceId") Long deviceId,
+            @Param("userId") Integer userId,
             @Param("channelId") Integer channelId,
             @Param("deviceNo") String deviceNo,
             @Param("warningType") Integer warningType,
@@ -33,6 +35,7 @@ public interface WarningLogMapper {
 
     List<BuildingSelectInfoDto> getAreaList(
             @Param("siteId") Integer siteId,
+            @Param("userId") Integer userId,
             @Param("channelId") Integer channelId,
             @Param("deviceNo") String deviceNo,
             @Param("warningType") Integer warningType,

+ 1 - 1
src/main/java/com/zoniot/ccrc/dto/LoginUser.java

@@ -22,7 +22,7 @@ public class LoginUser extends User implements UserDetails {
 
     private static final long serialVersionUID = -549522926597325135L;
 
-    //用户类型 0:无 1:超级管理员 2:站点管理员 3:站点用户
+    //用户类型 0:无 1:超级管理员 2:站点管理员 3:站点用户 4:网格管理员 5:社区管理员
     private Integer type;
 
     //站点id

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

@@ -16,7 +16,7 @@ public interface WarningLogService{
 
     int updateByPrimaryKeySelective(WarningLog record);
 
-    Pagination<WarningLogDto> getList(Integer channelId, String deviceNo, Integer warningType, String clientName, Integer feedbackStatus, Integer provinceId, Integer cityId, Integer regionId, Integer communityId, Integer buildingId, LocalDateTime startDate, LocalDateTime endDate, int pageNum, int pageSize);
+    Pagination<WarningLogDto> getList(Long deviceId,Integer channelId, String deviceNo, Integer warningType, String clientName, Integer feedbackStatus, Integer provinceId, Integer cityId, Integer regionId, Integer communityId, Integer buildingId, LocalDateTime startDate, LocalDateTime endDate, int pageNum, int pageSize);
 
     List<BuildingSelectDto> getAreaList(Integer channelId, String deviceNo, Integer warningType, String clientName, Integer feedbackStatus, LocalDateTime startDate, LocalDateTime endDate);
 

+ 6 - 2
src/main/java/com/zoniot/ccrc/service/impl/BuildingServiceImpl.java

@@ -10,6 +10,7 @@ import com.zoniot.ccrc.commom.utils.UserUtil;
 import com.zoniot.ccrc.dao.AreaMapper;
 import com.zoniot.ccrc.dao.BuildingMapper;
 import com.zoniot.ccrc.dao.CommunityMapper;
+import com.zoniot.ccrc.dao.OrganizationMapper;
 import com.zoniot.ccrc.dto.BuildingDto;
 import com.zoniot.ccrc.dto.BuildingSelectDto;
 import com.zoniot.ccrc.dto.BuildingSelectInfoDto;
@@ -52,6 +53,8 @@ public class BuildingServiceImpl implements BuildingService {
     private String filesPath;
     @Autowired
     private CommunityService communityService;
+    @Resource
+    private OrganizationMapper organizationMapper;
 
 
     @Override
@@ -323,7 +326,8 @@ public class BuildingServiceImpl implements BuildingService {
     @Override
     public void syncBuilding(BuildingData buildingData) {
 
-        Integer siteId = 1;
+        Integer siteId =  organizationMapper.findSiteId(buildingData.getCustomerId());
+        //Integer siteId = 1;
 
         Building building = new Building();
         building.setId(buildingData.getId());
@@ -341,7 +345,7 @@ public class BuildingServiceImpl implements BuildingService {
         building.setCreateBy("system");
         building.setUpdateDate(buildingData.getUpdateDate());
         building.setUpdateBy("system");
-        log.info("building {}", JSON.toJSONString(building));
+        log.info("syncBuilding building {}", JSON.toJSONString(building));
         buildingMapper.replaceSelective(building);
     }
 }

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

@@ -11,6 +11,7 @@ import com.zoniot.ccrc.commom.utils.Util;
 import com.zoniot.ccrc.dao.AreaMapper;
 import com.zoniot.ccrc.dao.BuildingMapper;
 import com.zoniot.ccrc.dao.CommunityMapper;
+import com.zoniot.ccrc.dao.OrganizationMapper;
 import com.zoniot.ccrc.dto.BuildingSelectDto;
 import com.zoniot.ccrc.dto.CommunityDto;
 import com.zoniot.ccrc.dto.LoginUser;
@@ -40,6 +41,8 @@ public class CommunityServiceImpl implements CommunityService {
 
     @Resource
     private AreaMapper areaMapper;
+    @Resource
+    private OrganizationMapper organizationMapper;
 
     @Override
 	public List<BuildingSelectDto> regionSearch(Integer siteId , String name) {
@@ -288,7 +291,7 @@ public class CommunityServiceImpl implements CommunityService {
 
     @Override
     public void syncCommunity(CommunityData communityData) {
-        Integer siteId = 1;
+        Integer siteId =  organizationMapper.findSiteId(communityData.getCustomerId());
         Community community = new Community();
         community.setId(communityData.getId());
         community.setSiteId(siteId);
@@ -308,7 +311,7 @@ public class CommunityServiceImpl implements CommunityService {
         community.setDateUpdate(communityData.getDateUpdate());
         community.setCreateBy("system");
         community.setUpdateBy("system");
-        log.info("community {}", JSON.toJSONString(community));
+        log.info("syncCommunity community {}", JSON.toJSONString(community));
         communityMapper.replaceSelective(community);
 
     }

+ 28 - 8
src/main/java/com/zoniot/ccrc/service/impl/DeviceServiceImpl.java

@@ -7,6 +7,7 @@ import com.zoniot.ccrc.commom.model.DeviceData;
 import com.zoniot.ccrc.commom.model.Pagination;
 import com.zoniot.ccrc.commom.utils.ExcelUtil;
 import com.zoniot.ccrc.commom.utils.UserUtil;
+import com.zoniot.ccrc.dao.OrganizationMapper;
 import com.zoniot.ccrc.dto.BuildingSelectDto;
 import com.zoniot.ccrc.dto.BuildingSelectInfoDto;
 import com.zoniot.ccrc.dto.DeviceDto;
@@ -33,6 +34,10 @@ public class DeviceServiceImpl implements DeviceService{
     private DeviceMapper deviceMapper;
     @Autowired
     private BuildingService buildingService;
+    @Resource
+    private OrganizationMapper organizationMapper;
+
+
 
     @Override
     public int insertSelective(Device record) {
@@ -56,17 +61,28 @@ public class DeviceServiceImpl implements DeviceService{
 
     @Override
     public Pagination<DeviceDto> pageList(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus, String sortColumn, String sortOrder, int pageNum, int pageSize) {
+
         LoginUser loginUser = UserUtil.getCurrentUser();
+        Integer userId = null;
+        List<Integer> communityIds = null;
+        if (loginUser.getType() == 4) userId = loginUser.getId();
+        if (orgId != null) communityIds = organizationMapper.findCommunityIds(orgId);
+
+
         PageHelper.startPage(pageNum,pageSize);
-        List<DeviceDto> list = deviceMapper.getList(loginUser.getSiteId(),null,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,null,sortColumn,sortOrder);
+        List<DeviceDto> list = deviceMapper.getList(loginUser.getSiteId(),userId,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,communityIds,sortColumn,sortOrder);
         return new Pagination<>(list);
     }
 
     @Override
     public void getDeviceListExcel(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus, String sortColumn, String sortOrder, HttpServletResponse httpServletResponse) {
-        String title = "历史数据";
+        String title = "设备列表";
         LoginUser loginUser = UserUtil.getCurrentUser();
-        List<DeviceDto> list = deviceMapper.getList(loginUser.getSiteId(),null,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,null,sortColumn,sortOrder);
+        Integer userId = null;
+        List<Integer> communityIds = null;
+        if (loginUser.getType() == 4) userId = loginUser.getId();
+        if (orgId != null) communityIds = organizationMapper.findCommunityIds(orgId);
+        List<DeviceDto> list = deviceMapper.getList(loginUser.getSiteId(),userId,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,communityIds,sortColumn,sortOrder);
 
         //水表档案号、水表电子号、设备状态、当前读数、机构、客户编号、客户名称、手机号、标签、建筑、安装地址、网格员
         SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -116,15 +132,19 @@ public class DeviceServiceImpl implements DeviceService{
     @Override
     public List<BuildingSelectDto> deviceAreaList(Integer sysId, Integer deviceTypeId, Integer orgId, Integer province, Integer city, Integer region, Integer communityId, Integer buildingId, String deviceNo, String clientName, String locDesc, Integer status, Integer valveStatus) {
         LoginUser loginUser = UserUtil.getCurrentUser();
-        //查询用户数据项下的建筑列表
-        List<BuildingSelectInfoDto> list = deviceMapper.deviceAreaList(loginUser.getSiteId(),null,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,null);
+        Integer userId = null;
+        List<Integer> communityIds = null;
+        if (loginUser.getType() == 4) userId = loginUser.getId();
+        if (orgId != null) communityIds = organizationMapper.findCommunityIds(orgId);
+        List<BuildingSelectInfoDto> list = deviceMapper.deviceAreaList(loginUser.getSiteId(),userId,sysId,deviceTypeId,orgId,province,city,region,communityId,buildingId,deviceNo,clientName,locDesc,status,valveStatus,communityIds);
         return buildingService.areaList(list);
     }
 
     @Override
     public void syncDevice(DeviceData deviceData) {
-        // TODO: 2021/3/18  查询站点
-        Integer siteId = 1;
+
+        Integer siteId =  organizationMapper.findSiteId(deviceData.getCustomerId());
+        //Integer siteId = 1;
 
         Device device = new Device();
         device.setId(deviceData.getId());
@@ -148,7 +168,7 @@ public class DeviceServiceImpl implements DeviceService{
         device.setDateCreate(deviceData.getDateCreate());
         device.setUpdateBy("system");
         device.setDateUpdate(deviceData.getDateUpdate());
-        log.info("device {}", JSON.toJSONString(device));
+        log.info("syncDevice device {}", JSON.toJSONString(device));
         deviceMapper.replaceSelective(device);
     }
 }

+ 3 - 3
src/main/java/com/zoniot/ccrc/service/impl/StatAndAnalysisServiceImpl.java

@@ -46,10 +46,10 @@ public class StatAndAnalysisServiceImpl implements StatAndAnalysisService {
             latitudeMin = Double.valueOf(southWestStr[1]);
             latitudeMax = Double.valueOf(northEastStr[1]);
         }
-        //设置当前站点
-        List<Integer> siteList = UserUtil.getUserCurrentSiteIds();
+        Integer userId = null;
+        if (loginUser.getType() == 4) userId = loginUser.getId();
 
-        List<BuildingInfoListDto> buildingInfoListDtoList = deviceMapper.getBuildingStatistics(loginUser.getSiteId(),sysId, null, null, province, city, region,  community, type, longitudeMin, longitudeMax, latitudeMin, latitudeMax);
+        List<BuildingInfoListDto> buildingInfoListDtoList = deviceMapper.getBuildingStatistics(loginUser.getSiteId(),sysId, userId, null, province, city, region,  community, type, longitudeMin, longitudeMax, latitudeMin, latitudeMax);
         return this.mapStatistical(type, buildingInfoListDtoList);
     }
 

+ 7 - 3
src/main/java/com/zoniot/ccrc/service/impl/WarningLogServiceImpl.java

@@ -51,10 +51,12 @@ public class WarningLogServiceImpl implements WarningLogService {
     }
 
     @Override
-    public Pagination<WarningLogDto> getList(Integer channelId, String deviceNo, Integer warningType, String clientName, Integer feedbackStatus, Integer provinceId, Integer cityId, Integer regionId, Integer communityId, Integer buildingId, LocalDateTime startDate, LocalDateTime endDate, int pageNum, int pageSize) {
+    public Pagination<WarningLogDto> getList(Long deviceId,Integer channelId, String deviceNo, Integer warningType, String clientName, Integer feedbackStatus, Integer provinceId, Integer cityId, Integer regionId, Integer communityId, Integer buildingId, LocalDateTime startDate, LocalDateTime endDate, int pageNum, int pageSize) {
         LoginUser loginUser = UserUtil.getCurrentUser();
+        Integer userId = null;
+        if (loginUser.getType() == 4) userId = loginUser.getId();
         PageHelper.startPage(pageNum,pageSize);
-        List<WarningLogDto> list =  warningLogMapper.getList(loginUser.getSiteId(),channelId,deviceNo,warningType,clientName,feedbackStatus,provinceId,cityId,regionId,communityId,buildingId,startDate,endDate);
+        List<WarningLogDto> list =  warningLogMapper.getList(loginUser.getSiteId(),deviceId,userId,channelId,deviceNo,warningType,clientName,feedbackStatus,provinceId,cityId,regionId,communityId,buildingId,startDate,endDate);
 
         return new Pagination<>(list);
     }
@@ -77,7 +79,9 @@ public class WarningLogServiceImpl implements WarningLogService {
     @Override
     public List<BuildingSelectDto> getAreaList(Integer channelId, String deviceNo, Integer warningType, String clientName, Integer feedbackStatus, LocalDateTime startDate, LocalDateTime endDate) {
         LoginUser loginUser = UserUtil.getCurrentUser();
-        List<BuildingSelectInfoDto> buildingList = warningLogMapper.getAreaList(loginUser.getSiteId(),channelId,deviceNo,warningType,clientName,feedbackStatus,startDate,endDate);
+        Integer userId = null;
+        if (loginUser.getType() == 4) userId = loginUser.getId();
+        List<BuildingSelectInfoDto> buildingList = warningLogMapper.getAreaList(loginUser.getSiteId(),userId,channelId,deviceNo,warningType,clientName,feedbackStatus,startDate,endDate);
         return buildingService.areaList(buildingList);
     }
 }

+ 22 - 0
src/main/resources/mapper/OrganizationMapper.xml

@@ -255,5 +255,27 @@
             and id=#{id}
         </if>
     </select>
+
+    <select id="findCommunityIds" resultType="java.lang.Integer">
+        SELECT id FROM sc_community WHERE `status` = 1 and org_id in(
+                SELECT  DATA.id FROM(
+                        SELECT
+                                @ids as _ids,
+                                (   SELECT @ids := GROUP_CONCAT(id)
+                                    FROM sc_organization
+                                    WHERE FIND_IN_SET(parent_id, @ids)
+                                        ) as cids,
+                                @l := @l+1 as level
+                        FROM sc_customer,
+                             (SELECT @ids :=#{orgId}, @l := 0 ) b
+                        WHERE @ids IS NOT NULL
+                        ) id, sc_organization DATA
+                WHERE FIND_IN_SET(DATA.id, ID._ids)
+        )
+    </select>
+
+    <select id="findSiteId" resultType="java.lang.Integer">
+        select site_id from sc_customer where status = 1 and id = #{customerId}
+    </select>
 </mapper>
 

+ 5 - 2
src/main/resources/mapper/WarningLogMapper.xml

@@ -142,8 +142,10 @@
     left join sc_device_type sdt1 on(sdt1.id = sd.device_type_id)
     left join sc_device_manufacturer sdm1 on(sdm1.id = sdt1.manufacturer_id)
     left join sc_grid_management sgm on(sgm.device_id = sd.id)
-    where swl.status = 1 and sd.status = 1
+    where swl.status = 1 and sd.status = 1 and sgm.status = 1
     <if test="siteId != null"> and sd.site_id = #{siteId}</if>
+    <if test="deviceId != null"> and sd.id = #{deviceId}</if>
+    <if test="userId != null"> and sgm.user_id = #{userId}</if>
     <if test="channelId != null"> and sd.sys_id = #{channelId}</if>
     <if test="deviceNo != null and deviceNo != ''"> and (
       sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.meter_no LIKE concat('%',#{deviceNo},'%')
@@ -180,8 +182,9 @@
     from sc_warning_log swl
     left join sc_device sd on(sd.id = swl.device_id)
     left join sc_grid_management sgm on(sgm.device_id = sd.id)
-    where swl.status = 1 and sd.status = 1
+    where swl.status = 1 and sd.status = 1 and sgm.status = 1
     <if test="siteId != null"> and sd.site_id = #{siteId}</if>
+    <if test="userId != null"> and sgm.user_id = #{userId}</if>
     <if test="channelId != null"> and sd.sys_id = #{channelId}</if>
     <if test="deviceNo != null and deviceNo != ''"> and (
       sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.meter_no LIKE concat('%',#{deviceNo},'%')