| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.entity.MonitorPoint; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.entity.Supervision; |
| | | import com.moral.api.entity.SysArea; |
| | | import com.moral.api.mapper.SupervisionMapper; |
| | | import com.moral.api.service.MonitorPointService; |
| | | import com.moral.api.service.OrganizationService; |
| | | import com.moral.api.service.SupervisionService; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.service.SysAreaService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.DateUtils; |
| | | import com.moral.util.FileUtils; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | private SupervisionMapper supervisionMapper; |
| | | |
| | | @Autowired |
| | | private SysAreaService sysAreaService; |
| | | private OrganizationService organizationService; |
| | | |
| | | @Autowired |
| | | private MonitorPointService monitorPointService; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | @Override |
| | | public Map<String, Object> selectSupervisions(Map<String, Object> params) { |
| | | //获取查询参数 |
| | | int cityCode = Integer.parseInt(params.get("cityCode").toString()); |
| | | int page = Integer.parseInt(params.get("page").toString()); |
| | | int size = Integer.parseInt(params.get("size").toString()); |
| | | Object start = params.get("start"); |
| | | Object end = params.get("end"); |
| | | |
| | | QueryWrapper<Supervision> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("city_code", cityCode) |
| | | .eq("is_delete", Constants.NOT_DELETE); |
| | | |
| | | QueryWrapper<Supervision> supervisionQueryWrapper = new QueryWrapper<>(); |
| | | supervisionQueryWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | if (params.get("organizationId") != null) { |
| | | Integer orgId = Integer.parseInt(params.get("organizationId").toString()); |
| | | //获取组织下所有子组织 |
| | | List<Organization> organizations = organizationService.getChildrenOrganizationsById(orgId); |
| | | List<Integer> orgIds = organizations.stream().map(Organization::getId).collect(Collectors.toList()); |
| | | orgIds.add(orgId); |
| | | QueryWrapper<MonitorPoint> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select("city_code") |
| | | .eq("is_delete", Constants.NOT_DELETE) |
| | | .in("organization_id", orgIds); |
| | | |
| | | //根据组织id查询所有站点市级code |
| | | List<Object> cityCodes = monitorPointService.listObjs(queryWrapper); |
| | | |
| | | cityCodes = cityCodes.stream() |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | supervisionQueryWrapper.in("CONCAT(LEFT(city_code,4),'00')", cityCodes); |
| | | } else { |
| | | String cityCode = params.get("cityCode").toString(); |
| | | //如果是市级,就查询该市下所有县市区的,否则只查询该县市区的 |
| | | if (cityCode.endsWith("00")) { |
| | | supervisionQueryWrapper.eq("CONCAT(LEFT(city_code,4),'00')", cityCode); |
| | | } else { |
| | | supervisionQueryWrapper.eq("city_code", cityCode); |
| | | } |
| | | } |
| | | |
| | | |
| | | if (start != null) { |
| | | queryWrapper.ge("time", start); |
| | | supervisionQueryWrapper.ge("time", start); |
| | | } |
| | | if (start != null) { |
| | | queryWrapper.le("time", end); |
| | | supervisionQueryWrapper.le("time", end); |
| | | } |
| | | |
| | | //按time倒序 |
| | | queryWrapper.orderByDesc("time"); |
| | | supervisionQueryWrapper.orderByDesc("time"); |
| | | |
| | | //分页 |
| | | Page<Supervision> supervisionPage = new Page<>(page, size); |
| | | supervisionMapper.selectPage(supervisionPage, queryWrapper); |
| | | supervisionMapper.selectPage(supervisionPage, supervisionQueryWrapper); |
| | | List<Supervision> supervisions = supervisionPage.getRecords(); |
| | | |
| | | //获取区域名字 |
| | | List<Map<String, Object>> item = new ArrayList<>(); |
| | | QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>(); |
| | | sysAreaQueryWrapper.eq("area_code", cityCode); |
| | | SysArea one = sysAreaService.getOne(sysAreaQueryWrapper); |
| | | String cityName = one.getAreaName(); |
| | | for (Supervision supervision : supervisions) { |
| | | Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(supervision), Map.class); |
| | | map.remove("isDelete"); |
| | | map.remove("createTime"); |
| | | map.remove("updateTime"); |
| | | map.put("cityName", cityName); |
| | | map.put("time", DateUtils.getLongToStr((Long) map.remove("time"), DateUtils.yyyy_MM_dd_EN)); |
| | | item.add(map); |
| | | } |
| | | |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("total", supervisionPage.getTotal()); |
| | | result.put("totalPage", supervisionPage.getPages()); |
| | | result.put("current", supervisionPage.getCurrent()); |
| | | result.put("pageSize", supervisionPage.getSize()); |
| | | result.put("item", item); |
| | | result.put("item", supervisions); |
| | | |
| | | return result; |
| | | } |