/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ifish.helper;

import com.ifish.dto.JsonResult;
import com.ifish.dto.PageingDto;
import com.ifish.entity.Grade;
import com.ifish.mapper.Tbl_User_Activity_Mapper;
import com.ifish.service.CacheService;
import com.ifish.util.IfishUtil;
import com.ifish.util.ResultUtil;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户动态所有接口方法
 *
 * @author Administrator
 */
@Component
public class UserActivityHelper implements UserActivityHelperI {

    @Autowired
    private Tbl_User_Activity_Mapper tbl_User_Activity_Mapper;

    @Autowired
    private CacheService cacheService;

    @Override
    public PageingDto<?> getUserActivityByPage(Integer pageSize, Integer firstResult) {
        //分页获取数据
        List<Map> list = tbl_User_Activity_Mapper.getUserActivityByPage(firstResult, pageSize);
        firstResult += list.size();
        try {
            for (Map map : list) {
                Integer gradeValue = (Integer) map.get("grade_value");
                for (Grade grade : cacheService.getGradeList()) {
                    if (gradeValue >= grade.getMinValue() && gradeValue < grade.getMaxValue()) {
                        map.remove("grade_value");
                        map.put("gradeNum", grade.getGradeNum());
                        break;
                    }
                }
            }
        } catch (Exception e) {
        }

        //分页数据封装
        return ResultUtil.success(firstResult, tbl_User_Activity_Mapper.getUserActivityCount(), list);
    }

    @Override
    public JsonResult<?> getUserActivityMaxCount() {
        try {
            int count = tbl_User_Activity_Mapper.getUserActivityCount();
            return new JsonResult<>("100", count);
        } catch (Exception e) {
            return new JsonResult<>("101", "");
        }
    }
}
