Newer
Older
huludao / src / main / java / com / newfiber / api / pc / service / impl / HomePageDataServiceImpl.java
package com.newfiber.api.pc.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.commons.ResultCode;
import com.newfiber.api.core.commons.ResultObj;
import com.newfiber.api.pc.dao.HomePageDataMapper;
import com.newfiber.api.pc.model.entity.HomePageData;
import com.newfiber.api.pc.service.HomePageDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 任务
 * @Author:zhz
 * @CreateDate:2020/12/1 14:50
 * @Description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class HomePageDataServiceImpl extends ServiceImpl<HomePageDataMapper, HomePageData> implements HomePageDataService {

    @Autowired
    private HomePageDataMapper homePageDataMapper;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public List<Object> getData(Integer classify) {
        EntityWrapper<HomePageData> wrapper = new EntityWrapper<>();
        wrapper.eq("classify",classify);
        List<HomePageData> homePageData = homePageDataMapper.selectList(wrapper);
        List<Object> list = new ArrayList<>();
        if(!homePageData.isEmpty()){
            Map<String, List<HomePageData>> collect = homePageData.stream().collect(Collectors.groupingBy(HomePageData::getClassifyName));
            for (Map.Entry<String, List<HomePageData>> obj : collect.entrySet()) {
                Map<String,Object> result = new HashMap<>();
                result.put(obj.getKey(),obj.getValue());
                list.add(result);
            }
        }
        return list;
    }

    @Override
    public PageInfo<HomePageData> list(Integer pageNo,Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        EntityWrapper<HomePageData> wrapper = new EntityWrapper<>();
        List<HomePageData> result =  homePageDataMapper.selectList(wrapper);
        PageInfo<HomePageData> pageInfo = new PageInfo<>();
        if(!result.isEmpty()){
            pageInfo = new PageInfo<HomePageData>(result);
        }
        return pageInfo;
    }

    @Override
    public ResultObj updatePage(ReqBodyObj<HomePageData> param) {
        Integer integer = homePageDataMapper.updateById(param.getData());
        if(integer>0){
            return new ResultObj(ResultCode.OK);
        }
        return new ResultObj(ResultCode.ERROR);
    }

    @Override
    public Map<String, String> newOneMapData() {
        HashMap<String, String> map = new HashMap<>();
        //查询一张图静态数据
        List<HomePageData> homePageData = homePageDataMapper.selectList(null);
       // List<SewerageTotal> sewerageTotals = homePageDataMapper.selectPointData();
       // sewerageTotals.forEach(s ->  map.put(s.getIsKeyPoint().compareTo(0) == 0 ? "noPoint" : "keyPoint",s.getCount()+""));
        Set<String> keys = stringRedisTemplate.keys("patrol*");
        for (HomePageData homePageDatum : homePageData) {
            if("排水管网长度".equals(homePageDatum.getName())){
                map.put("pipeTotalLength",homePageDatum.getNumerical());
            }
            if("雨水管网长度(km)".equals(homePageDatum.getName())){
                map.put("rainPipeTotalLength",homePageDatum.getNumerical());
            }
            if("污水管网长度(km)".equals(homePageDatum.getName())){
                map.put("seweragePipeTotalLength",homePageDatum.getNumerical());
            }
            if("河流(条)".equals(homePageDatum.getName())){
                map.put("riverCount",homePageDatum.getNumerical());
            }
            if("年均降水量(mm)".equals(homePageDatum.getName())){
                map.put("yearAvgRainfall",homePageDatum.getNumerical());
            }
            if("雨污合流管长度(km)".equals(homePageDatum.getName())){
                map.put("rainSewerageInterflow",homePageDatum.getNumerical());
            }

        }
        map.put("onlineCount", keys == null ? "0" : keys.size()+"");
        return map;
    }
}