screen-api/src/main/java/com/moral/api/controller/GovMonitorPointController.java
@@ -1,18 +1,22 @@ package com.moral.api.controller; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.moral.api.entity.GovMonitorPoint; import com.moral.api.entity.Organization; import com.moral.api.mapper.OrganizationMapper; import com.moral.api.service.GovMonitorPointService; import com.moral.constant.ResponseCodeEnum; import com.moral.constant.ResultMessage; import com.moral.util.WebUtils; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; /** * @ClassName @@ -31,6 +35,9 @@ @Autowired GovMonitorPointService govMonitorPointService; @Resource private OrganizationMapper organizationMapper; /** * @Description: 查询国控站以及数据接口接口 @@ -46,4 +53,27 @@ return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(), govMonitorPoints); } /** *@Description: 通过组织id获取政府站点 *@Param: [request] *@return: com.moral.constant.ResultMessage *@Author: lizijie *@Date: 2021/9/26 9:42 **/ @RequestMapping(value = "getGovMonitorPointsByOrgId", method = RequestMethod.GET) @ResponseBody public ResultMessage getGovMonitorPointsByOrgId(HttpServletRequest request){ Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); Object orgid = parameters.get("organization_id"); if (ObjectUtils.isEmpty(orgid)){ return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } Organization organization = organizationMapper.selectById(Integer.parseInt(orgid.toString())); if (ObjectUtils.isEmpty(organization)){ return ResultMessage.fail(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode(), ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg()); } List<GovMonitorPoint> govMonitorPoints = govMonitorPointService.selectGovMonitorPointsByOrgid(parameters); return ResultMessage.ok(govMonitorPoints); } } screen-api/src/main/java/com/moral/api/entity/GovMonitorPoint.java
@@ -89,6 +89,7 @@ /** * 备注 */ @TableField("`desc`") private String desc; screen-api/src/main/java/com/moral/api/service/GovMonitorPointService.java
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; import java.util.Map; /** * <p> @@ -23,4 +24,13 @@ * @Date: 2021/9/24 */ List<GovMonitorPoint> queryGovMonitorPointAndDataByRegionCode(Integer regionCode,String sensorCode); /** *@Description: 通过组织id获取国控站点列表 *@Param: [map] *@return: java.util.List<java.util.Map<java.lang.String,java.lang.Object>> *@Author: lizijie *@Date: 2021/9/23 15:32 **/ List<GovMonitorPoint> selectGovMonitorPointsByOrgid(Map map); } screen-api/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java
@@ -2,10 +2,14 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.moral.api.entity.Device; import com.moral.api.entity.GovMonitorPoint; import com.moral.api.entity.Organization; import com.moral.api.mapper.DeviceMapper; import com.moral.api.mapper.GovMonitorPointMapper; import com.moral.api.service.GovMonitorPointService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.api.service.OrganizationService; import com.moral.constant.Constants; import com.moral.constant.RedisConstants; import com.moral.util.RegionCodeUtils; @@ -13,8 +17,11 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; /** * <p> @@ -32,6 +39,12 @@ @Autowired RedisTemplate redisTemplate; @Resource private OrganizationService organizationService; @Autowired(required = false) private DeviceMapper deviceMapper; @Override public List<GovMonitorPoint> queryGovMonitorPointAndDataByRegionCode(Integer regionCode,String sensorCode) { String regionCodeStr = RegionCodeUtils.regionCodeConvertToName(regionCode); @@ -48,4 +61,23 @@ } return govMonitorPoints; } @Override public List<GovMonitorPoint> selectGovMonitorPointsByOrgid(Map map) { //根据组织id获取子组织 List<Organization> organizations = organizationService.getChildrenOrganizationsById(Integer.parseInt(map.get("organization_id").toString())); Set<Integer> organization_ids = organizations.stream().map(organization -> organization.getId()).collect(Collectors.toSet()); organization_ids.add(Integer.parseInt(map.get("organization_id").toString())); //先获取组织下所有设备 QueryWrapper<Device> wrapper_device = new QueryWrapper<>(); wrapper_device.in("organization_id",organization_ids).eq("is_delete",Constants.NOT_DELETE); List<Device> devices = deviceMapper.selectList(wrapper_device); //用集合存放所有设备的id Set<String> guids = devices.stream().map(device -> device.getGuid()).collect(Collectors.toSet()); //获取所有政府站点信息 QueryWrapper<GovMonitorPoint> wrapper_govMonitorPoint = new QueryWrapper<>(); wrapper_govMonitorPoint.eq("is_delete",Constants.NOT_DELETE).in("guid",guids); List<GovMonitorPoint> govMonitorPointList = govMonitorPointMapper.selectList(wrapper_govMonitorPoint); return govMonitorPointList; } }