GeneraterMybatis所生成model查询的serviceimpl应用

@Service("nRService")
public class NRServiceImpl implements NRWuhanService {

    @Autowired
    private SelfAddMapper selfAddMapper;

    @Autowired
    private DiyNewsresultWuhanMapper newsresultWuhanMapper;

    @Autowired
    private DiyNewsresultWuhanHotMapper diyNewsresultWuhanHotMapper;

    @Autowired
    private DiyUserKeywordMapper diyUserKeywordMapper;

    /**
     * 查询关系图谱
     */
    @Override
    public Map<String,Integer> countWordByAreaId(Map<String, Object> paramMap) {
        int keywordId = Integer.parseInt(paramMap.get("keywordId").toString());
        Map<String,Integer> countMap = new HashMap<String,Integer>();

        DiyNewsresultWuhanExample example = new DiyNewsresultWuhanExample();
        example.createCriteria().andKeywordidEqualTo(keywordId);
        // 查询需要统计的数据
        List<DiyNewsresultWuhan> dataList = newsresultWuhanMapper.selectByExample(example);

        Map<String,Integer> areaMap = Constants.WUHAN_AREAS;

        for(DiyNewsresultWuhan bean : dataList){
            // 相同的文章数
            int sameNum = bean.getSamenum();
            // 分割关键词
            String[] wordAry = bean.getRelatedwords().split(",");
            // 遍历关键词,并统计
            for(String word : wordAry){
                // 如果关键词包含则不统计
                if(areaMap.containsKey(word))break;

                if(countMap.containsKey(word)){
                    int newCount = countMap.get(word)+sameNum+1;
                    countMap.put(word, newCount);
                } else {
                    countMap.put(word, sameNum==0?1:sameNum);
                }
            }
        }
        countMap = sortMap(countMap,20);
        return countMap;
    }

    /**
     * 查询指定关键词的关系图谱
     */
    @Override
    public Map<String,Integer> countWordByKeywordId(Map<String,Object> paramMap){

        int keywordId = Integer.parseInt(paramMap.get("keywordId").toString());

        Map<String,Integer> countMap = new HashMap<String,Integer>();

        DiyNewsresultWuhanHotExample example = new DiyNewsresultWuhanHotExample();
        example.createCriteria().andKeywordidEqualTo(keywordId);
        // 查询需要统计的数据
        List<DiyNewsresultWuhanHot> dataList = diyNewsresultWuhanHotMapper.selectByExample(example);

        Map<String,Integer> hotMap = Constants.HOT_CI;

        for(DiyNewsresultWuhanHot bean : dataList){
            // 相同的文章数
            int sameNum = bean.getSamenum();
            // 分割关键词
            String[] wordAry = bean.getRelatedwords().split(",");
            // 遍历关键词,并统计
            for(String word : wordAry){
                // 如果关键词包含在则不统计
                if(hotMap.containsKey(word))break;
                if(countMap.containsKey(word)){
                    int newCount = countMap.get(word)+sameNum+1;
                    countMap.put(word, newCount);
                } else {
                    countMap.put(word, sameNum==0?1:sameNum);
                }
            }
        }
        countMap = sortMap(countMap,20);
        return countMap;
    }

    private static Set<String> fmtStr(String str){
        Set<String> wordSet = new HashSet<String>();

        String[] strAry = str.split(",");
        for(String s : strAry){
            wordSet.add(s);
        }
        return wordSet;
    }

    /**
     * 根据map排序,并倒叙取前几个
     * @param oldMap 需要排序的map
     * @param many   取的个数
     * @return
     */
    public static Map<String,Integer> sortMap(Map<String,Integer> oldMap,int many) {  
        ArrayList<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(oldMap.entrySet());  
        Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {  

            @Override  
            public int compare(Entry<java.lang.String, Integer> arg0,  
                    Entry<java.lang.String, Integer> arg1) {  
                return arg0.getValue() - arg1.getValue();  
            }  
        });  
        Map<String,Integer> newMap = new LinkedHashMap<String,Integer>();
        int count = list.size()>many?many:list.size();
        for (int i = count; i > 0; i--) {
            newMap.put(list.get(list.size()-i).getKey(), list.get(list.size()-i).getValue());  
        }  
        return newMap;
    }  


    /**
     * 查询13区折线图
     */
    @Override
    public List<Map<String,Object>> countWordByAreaIdLine(Map<String, Object> paramMap) {
        List<Map<String,Object>> dataMap = selfAddMapper.get13ByAreaIdLine(paramMap);
        return dataMap;
    }

    /**
     * 查询指定关键字的折线图
     */
    @Override
    public List<Map<String,Object>> countWordByKeywordIdLine(Map<String, Object> paramMap) {
        List<Map<String,Object>> dataMap = selfAddMapper.getKeywordIdLine(paramMap);
        return dataMap;

    }

    /**
     * 保存用户输入的关键词
     */
    @Override
    public void addUserKeyword(DiyUserKeyword diyUserKeyword) {
        diyUserKeywordMapper.insertSelective(diyUserKeyword);
    }

    /**
     * 根据地区id获取文章
     */
    @Override
    public Page getArticleByAreaId(Map<String, Object> paramMap, Page p) {
        Date beginDate = DateUtil.parse(paramMap.get("beginDate").toString(), "yyyy-MM-dd");
        Date endDate = DateUtil.parse(paramMap.get("endDate").toString(), "yyyy-MM-dd");
        int keywordId = Integer.parseInt(paramMap.get("keywordId").toString());
        int offset = (p.getCurrentPage()-1)*p.getPageSize();
        DiyNewsresultWuhanExample example = new DiyNewsresultWuhanExample();

        example.createCriteria().andKeywordidEqualTo(keywordId).andPubtimeBetween(beginDate, endDate);
        int count = newsresultWuhanMapper.countByExample(example);
        example.setOrderByClause(" samenum desc, pubtime desc limit " + offset + "," + p.getPageSize());
        List<DiyNewsresultWuhan> dataList = newsresultWuhanMapper.selectByExample(example);

        p = PageUtil.getPage(p.getCurrentPage(), p.getPageSize(), count, dataList);
        return p;
    }


    @Override
    public Page getArticleByKeywordId(Map<String, Object> paramMap, Page p) {

        int keywordId = Integer.parseInt(paramMap.get("keywordId").toString());
        Date beginDate = DateUtil.parse(paramMap.get("beginDate").toString(), "yyyy-MM-dd");
        Date endDate = DateUtil.parse(paramMap.get("endDate").toString(), "yyyy-MM-dd");

        int offset = (p.getCurrentPage()-1)*p.getPageSize();
        DiyNewsresultWuhanHotExample example = new DiyNewsresultWuhanHotExample();

        example.createCriteria().andKeywordidEqualTo(keywordId).andPubtimeBetween(beginDate, endDate);
        int count = diyNewsresultWuhanHotMapper.countByExample(example);
        example.setOrderByClause(" samenum desc, pubtime desc limit " + offset + "," + p.getPageSize());
        List<DiyNewsresultWuhanHot> dataList = diyNewsresultWuhanHotMapper.selectByExample(example);

        p = PageUtil.getPage(p.getCurrentPage(), p.getPageSize(), count, dataList);
        return p;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值