package com.template.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.template.annotation.PassToken;
import com.template.api.LoginControllerAPI;
import com.template.common.utils.*;
import com.template.config.WxOpenidConfig;
import com.template.model.enumModel.eAccountType;
import com.template.model.enumModel.eApplyType;
import com.template.model.enumModel.eOrgType;
import com.template.model.enumModel.ePassType;
import com.template.model.pojo.*;
import com.template.model.request.changePasswordRequest;
import com.template.model.request.loginRequest;
import com.template.model.result.CommonResult;
import com.template.model.result.PageUtils;
import com.template.model.result.Wx_user;
import com.template.model.vo.*;
import com.template.services.*;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;

/**
 * @Author: xwt
 * @Date: 2023/7/5 星期三 9:28
 * @Description: com.template.controller
 * @Version: 1.0
 */
@RestController
public class LoginController implements LoginControllerAPI {
    @Autowired
    private WeiXiaoUtil weiXiaoUtil;
    @Autowired
    private WxOpenidConfig wxOpenidConfig;
    @Autowired
    private AlumniUserService alumniUserService;
    @Autowired
    private AlumniOrgService alumniOrgService;
    @Autowired
    private SysCaptchaService sysCaptchaService;
    @Autowired
    private AlumniClubApplyService alumniClubApplyService;
    @Autowired
    private AlumniActivityService alumniActivityService;
    @Autowired
    private AlumniEndorseService alumniEndorseService;
    @Autowired
    private AlumniImageService alumniImageService;
    @Autowired
    private ActivityImageService activityImageService;

    private static Logger logger = LoggerFactory.getLogger(LoginController.class);


    @Override
    @PassToken
    @Transactional(rollbackFor = {Exception.class})
    public CommonResult Openid(String wxcode, String state, HttpServletResponse response) throws Exception {
        logger.info("微校授权：" + wxcode + "H5：" + state);
        Gson gson = new Gson();
        String tokenUrl = "https://open.wecard.qq.com/connect/oauth2/token";
        Map<String, String> tokenParams = new HashMap<>();
        tokenParams.put("wxcode", wxcode);
        tokenParams.put("app_key", wxOpenidConfig.getAppid());
        tokenParams.put("app_secret", wxOpenidConfig.getAppkey());
        tokenParams.put("grant_type", wxOpenidConfig.getGranttype());
        tokenParams.put("redirect_uri", state); // H5
        logger.info("微校授权1：");
        // wecode换取token
        String respon = HttpsClient.post(tokenUrl, tokenParams);
        logger.info("微校授权2：" + respon);
        if (!StringUtils.hasText(respon)) {
            logger.info("微校授权异常信息：respon为空" + respon);
            return CommonResult.fail("微校授权异常信息");
        }
        HashMap<String, Object> tokenMap = gson.fromJson(respon, new TypeToken<HashMap<String, Object>>() {
        }.getType());
        logger.info("微校授权3");
        String accessToken = (String) tokenMap.get("access_token");
        logger.info("微校授权4");
        // token换取用户信息
        String userInfoUrl = "https://open.wecard.qq.com/connect/oauth/get-user-info";
        logger.info("微校授权5");
        Map<String, String> userInfoParam = new HashMap<>();
        logger.info("微校授权6");
        userInfoParam.put("access_token", accessToken);
        logger.info("微校授权7");
        String userinfo = HttpsClient.post(userInfoUrl, userInfoParam);
        logger.info("微校授权8");
        String card_number = null;
        String user_name = null;
        String phone = null;
        int identity_type = 0;
        String college = null;
        String grade = null;
        String profession = null;
        String campus = null;
        String classStr = null;
        Wx_user userinfos = gson.fromJson(userinfo, new TypeToken<Wx_user>() {
        }.getType());
        logger.info("微校授权9");
        logger.info("微校授权获取用户信息：" + userinfo);
        logger.info("微校授权获取用户信息类别：" + userinfos.getIdentity_type());
        try {
            card_number = userinfos.getCard_number();
            user_name = userinfos.getName();
            phone = userinfos.getTelephone();
            identity_type = userinfos.getIdentity_type();
            college = userinfos.getCollege();//学院
            grade = userinfos.getGrade();//学段 年级
            profession = userinfos.getProfession();//专业
            campus = userinfos.getCampus();
            classStr = userinfos.getClassStr();//班级
        } catch (Exception e) {
            logger.info("微校授权异常信息：" + e.getMessage());
            response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("获取用户信息失败", "UTF-8"));
            return CommonResult.fail(e.getMessage());
        }

        if (card_number == null || card_number.equals("")) {
            response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("获取用户信息失败", "UTF-8"));
            return CommonResult.fail("卡号为空，授权失败");
        }
        //根据卡号判断用户是否存在 根据卡号查询alumni_user表中的用户信息
        AlumniUser user = alumniUserService.queryDataByCardNumber(card_number);

        //region 学院 学段 专业 班级
        Integer collegeId = null;
        String collegeName = null;
        Integer gradeId = null;
        String gradeName = null;
        Integer professId = null;
        String professName = null;
        Integer classId = null;
        String className = null;
        //endregion

        //上下级关系  学院 -》 学段 -》 专业 -》 班级
        List<String> orgNames = new ArrayList<>();
        orgNames.add(college);//学院
        orgNames.add(grade);//学段 年级
        orgNames.add(profession);//专业
        orgNames.add(classStr);//班级
        List<AlumniOrg> aos = alumniOrgService.queryAlumniOrgsByName(orgNames);
        //region 原来的学院学段专业班级赋值
        //学段得拿父级做筛选 因为会有重名的
//        String collegeStr = college;
//        Optional<AlumniOrg> oCollege = aos.stream().filter(e -> e.getName().equals(collegeStr)).findFirst();
//        if (oCollege == null) {
//            CommonResult result = weiXiaoUtil.queryOrgs();
//            aos = new ArrayList<>();
//            aos = alumniOrgService.queryAlumniOrgsByName(orgNames);
//        }
//        Optional<AlumniOrg> fCollege = aos.stream().filter(e -> e.getName().equals(collegeStr)).findFirst();
//        if (fCollege != null && fCollege.isPresent()) {
//            collegeId = fCollege.get().getId();
//            collegeName = fCollege.get().getName();
//
//            Optional<AlumniOrg> oG = aos.stream().filter(e -> e.getParentId().intValue() == fCollege.get().getId().intValue()).findFirst();
//            if (oG != null && oG.isPresent()) {
//                gradeId = oG.get().getId();
//                gradeName = oG.get().getName();
//
//                Optional<AlumniOrg> pG = aos.stream().filter(e -> e.getParentId().intValue() == oG.get().getId().intValue()).findFirst();
//                if (pG != null && pG.isPresent()) {
//                    professId = pG.get().getId();
//                    professName = pG.get().getName();
//
//                    Optional<AlumniOrg> cG = aos.stream().filter(e -> e.getParentId().intValue() == pG.get().getId().intValue()).findFirst();
//                    if (cG != null && cG.isPresent()) {
//                        classId = cG.get().getId();
//                        className = cG.get().getName();
//                    }
//                }
//            }
//        }
        //endregion
        //region 学院学段专业班级赋值
        if (StringUtils.hasText(college)) {
            String collegeStr = college;
            Optional<AlumniOrg> oCollege = aos.stream().filter(e -> e.getName().equals(collegeStr)).findFirst();
            if (oCollege != null && oCollege.isPresent()) {
                collegeId = oCollege.get().getId();
                collegeName = college;
            } else  if(StringUtils.hasText(college)){
                AlumniOrg insertData = new AlumniOrg();
                insertData.setParentId(1);//父级是南昌交通学院
                insertData.setName(college);
                insertData.setTypeId(eOrgType.College.getValue());
                collegeId = alumniOrgService.insertOrg(insertData);
                collegeName = college;
            }
            if (collegeId != null && collegeId.intValue() != 0) {
                int cid = collegeId.intValue();
                Optional<AlumniOrg> oG = aos.stream().filter(e -> e.getParentId().intValue() == cid).findFirst();
                if (oG != null && oG.isPresent()) {
                    gradeId = oG.get().getId();
                    gradeName = oG.get().getName();
                } else if (StringUtils.hasText(grade)){
                    AlumniOrg insertData = new AlumniOrg();
                    insertData.setParentId(cid);
                    insertData.setName(grade);
                    insertData.setTypeId(eOrgType.Period.getValue());
                    gradeId = alumniOrgService.insertOrg(insertData);
                    gradeName = grade;
                }
                if (gradeId != null && gradeId.intValue() != 0) {
                    int gid = gradeId.intValue();
                    Optional<AlumniOrg> pG = aos.stream().filter(e -> e.getParentId().intValue() == gid).findFirst();
                    if (pG != null && pG.isPresent()) {
                        professId = pG.get().getId();
                        professName = pG.get().getName();

                    } else if (StringUtils.hasText(profession)){
                        AlumniOrg insertData = new AlumniOrg();
                        insertData.setParentId(gid);
                        insertData.setName(profession);
                        insertData.setTypeId(eOrgType.Major.getValue());
                        professId = alumniOrgService.insertOrg(insertData);
                        professName = profession;
                    }
                    if (professId != null && professId.intValue() != 0) {
                        int pid = professId.intValue();
                        Optional<AlumniOrg> cG = aos.stream().filter(e -> e.getParentId().intValue() == pid).findFirst();
                        if (cG != null && cG.isPresent()) {
                            classId = cG.get().getId();
                            className = cG.get().getName();
                        } else if(StringUtils.hasText(classStr)){
                            AlumniOrg insertData = new AlumniOrg();
                            insertData.setParentId(pid);
                            insertData.setName(classStr);
                            insertData.setTypeId(eOrgType.ClassStr.getValue());
                            classId = alumniOrgService.insertOrg(insertData);
                            className = classStr;
                        }
                    }
                }
            }
        }
        //endregion


        logger.info("微校授权校区：" + campus);
        if (user == null) {
            try {
                user = new AlumniUser();
                user.setName(user_name);
                user.setCardNumber(card_number);
                user.setCollegeId(collegeId);
                user.setCollegeName(collegeName);
                user.setPeriodId(gradeId);
                user.setPeriodName(gradeName);
                user.setMajorId(professId);
                user.setMajorName(professName);
                user.setClassId(classId);
                user.setClassName(className);
                user.setPhone(phone);
                user.setTypeId(eAccountType.User.getValue());
                int num = alumniUserService.insertAlumniUser(user);
                if (num <= 0) {
                    logger.info("微校授权失败，用户信息新增异常：" + user_name + "" + card_number);
                    response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("用户新增异常", "UTF-8"));
                    throw new Exception("微校授权失败！");
                }

                user.setId(num);

            } catch (Exception e) {
                logger.info("微校授权异常信息：" + e.getMessage());
                response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("获取用户信息失败", "UTF-8"));
                throw new Exception("微校授权失败！");
            }
        } else {
            //更新微校获取的学段（年级） 班级 学院 专业信息
            user.setCollegeId(collegeId);
            user.setCollegeName(collegeName);
            user.setPeriodId(gradeId);
            user.setPeriodName(gradeName);
            user.setMajorId(professId);
            user.setMajorName(professName);
            user.setClassId(classId);
            user.setClassName(className);
            user.setPhone(phone);

            int num = alumniUserService.updateAlumniUser(user);
            if (num <= 0) {
                logger.info("微校授权失败，用户信息更新异常：" + user_name + "" + card_number);
                response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/404/404/?message=" + URLEncoder.encode("用户更新异常", "UTF-8"));
                throw new Exception("微校授权失败！");
            }
        }

        wxLoginVo wlv = new wxLoginVo();
        wlv.setUserId(user.getId());
        wlv.setUserName(user.getName());
        wlv.setCardNumber(user.getCardNumber());
        wlv.setUserPhone(user.getPhone().replace("(+86)", ""));
        long expired = 1000 * 60 * 60 * 24 * 365;
        String token = JWTUtil.getToken(user, expired);
        wlv.setToken(token);
        logger.info("微校授权成功：" + user_name + "" + card_number);
        response.sendRedirect(wxOpenidConfig.getIp() + "/#/pages/index/index/?card_number=" + user.getCardNumber() + "&phone=" + wlv.getUserPhone() + "&userName=" + wlv.getUserName() + "&token=" + token);
        return CommonResult.ok(wlv);
    }

    @Override
    @PassToken
    public void captcha(HttpServletResponse response, String uuid) throws IOException {
        response.setHeader("Cache-Control", "no-store, no-cache");
        response.setContentType("image/jpeg");

        //获取图片验证码
        BufferedImage image = sysCaptchaService.getCaptcha(uuid);
        if (image == null) {
            logger.info("验证码图片生成失败：" + uuid);
        }

        ServletOutputStream out = response.getOutputStream();
        ImageIO.write(image, "jpg", out);
        IOUtils.closeQuietly(out);
    }

    /**
     * 查看系统版本号
     *
     * @return
     */
    @Override
    @PassToken
    public CommonResult queryReduce() {
        return CommonResult.ok("当前系统版本为：1V");
    }

    /**
     * 登录接口
     *
     * @param loginRequest
     * @return
     */
    /**
     * @param loginRequest  account 账号
     *                      password 密码
     *                      uuid 唯一标识
     *                      captcha 验证码
     * @param bindingResult
     * @return
     */
    @Override
    @PassToken
    public CommonResult Login(@RequestBody loginRequest loginRequest, BindingResult bindingResult) {
        if (loginRequest == null) {
            return CommonResult.fail("请传递参数");
        }
        if (bindingResult.hasErrors()) {
            String st = paramUtils.getParamError(bindingResult);
            return CommonResult.fail(st);
        }

        AlumniUser result = alumniUserService.queryDataByAccount(loginRequest.getAccount());
        if (result == null) {
            return CommonResult.fail("账号或密码错误");
        }

        String encPassword = AesUtils.encrypt(loginRequest.getPassword());
        if (!encPassword.equals(result.getPassword())) {
            return CommonResult.fail("密码错误");
        }

        String token = JWTUtil.getToken(result, null);
        LoginVO login = new LoginVO();
        login.setToken(token);
        login.setTokenTtl(JWTUtil.getExpired());
        login.setUserId(result.getId());
        login.setUserName(result.getName());
        login.setPhone(result.getPhone());

        return CommonResult.ok("登录成功", login);
    }

    /**
     * 修改密码
     *
     * @param cpr           oldPassword 旧密码
     *                      newPassword 新密码
     *                      confirmPassword 确认密码
     * @param userId
     * @param bindingResult
     * @return
     */
    @Override
    public CommonResult ChangePassword(Integer userId, changePasswordRequest cpr, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            String st = paramUtils.getParamError(bindingResult);
            return CommonResult.fail(st);
        }

        if (!cpr.getNewPassword().equals(cpr.getConfirmPassword())) {
            return CommonResult.fail("确认密码和新密码不一致！");
        }


        AlumniUser operateData = alumniUserService.getById(userId);
        if (operateData == null) {
            return CommonResult.fail("当前账号不合法！");
        }


        String encPassword = AesUtils.encrypt(cpr.getOldPassword());
        if (!encPassword.equals(operateData.getPassword())) {
            return CommonResult.fail("原密码错误！");
        }

        operateData.setPassword(cpr.getNewPassword());
        int result = alumniUserService.updateAlumniUser(operateData);

        return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
    }

    @Override
    public CommonResult queryTypes() {
        List<ListDataVO> result = new ArrayList<>();
        for (int i = 1; i <= eApplyType.values().length; i++) {
            ListDataVO data = new ListDataVO();
            data.setId(i);
            data.setName(ePassType.stringOf(i));
            result.add(data);
        }

        return CommonResult.ok(result);
    }

    //我发起的
    @Override
    public CommonResult queryIinitiatedApply(int currentPage, int pageCount, Integer userId, int typeId, String keyword) {
        AlumniUser au = alumniUserService.queryDataById(userId);
        if (au == null) {
            return CommonResult.fail("当前操作人已失效，无法查看数据");
        }

        IPage<InitiatedPageVo> accountData = new Page<>();
        PageUtils<InitiatedPageVo> finallResult = new PageUtils<InitiatedPageVo>(accountData);
        List<InitiatedPageVo> datas = new ArrayList<>();
        if (typeId == eApplyType.Org.getValue()) {//组织
            PageUtils<ApplyClubVo> pages = alumniClubApplyService.queryMyClubApplys(userId, currentPage, pageCount, keyword);
            for (ApplyClubVo pg : pages.getList()) {
                InitiatedPageVo data = new InitiatedPageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(pg.getName());
                data.setIsPass(pg.getIsPass());
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(pg.getCreateTime());
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());

        } else if (typeId == eApplyType.Activity.getValue()) {//活动
            PageUtils<AlumniMyActivityPageVo> pages = alumniActivityService.queryMyActivityApplyPages(currentPage, pageCount, userId, keyword);
            for (AlumniMyActivityPageVo pg : pages.getList()) {
                InitiatedPageVo data = new InitiatedPageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(pg.getOrgName());
                data.setIsPass(pg.getIsPass());
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(TimeExchange.DateToString(pg.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());
        } else if (typeId == eApplyType.Endorse.getValue()) {//母校代言
            PageUtils<ApplicationRecordPageVo> pages = alumniEndorseService.applicationMyRecordDatas(currentPage, pageCount, userId, keyword);
            for (ApplicationRecordPageVo pg : pages.getList()) {
                InitiatedPageVo data = new InitiatedPageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(au.getOrgName());
                data.setIsPass(pg.getIsPass());
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(pg.getCreateTime());
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());
        } else if (typeId == eApplyType.Image.getValue()) {//相册
            PageUtils<ImageMyPageVo> pages = alumniImageService.imageMyApplyPageDatas(currentPage, pageCount, userId, keyword);
            for (ImageMyPageVo pg : pages.getList()) {
                InitiatedPageVo data = new InitiatedPageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(au.getOrgName());
                data.setIsPass(pg.getIsPass());
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(TimeExchange.DateToString(pg.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());
        } else {//活动相册
            PageUtils<ActivityMyImageApplyVo> pages = activityImageService.activityMyImagePageDatas(currentPage, pageCount, userId, keyword);
            for (ActivityMyImageApplyVo pg : pages.getList()) {
                InitiatedPageVo data = new InitiatedPageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(au.getOrgName());
                data.setIsPass(pg.getIsPass());
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(pg.getCreateTime());
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());
        }

        return CommonResult.ok(finallResult);
    }

    //我审核的
    @Override
    public CommonResult queryIapproveApply(int currentPage, int pageCount, Integer userId, int typeId, String keyword) {
        AlumniUser au = alumniUserService.queryDataById(userId);
        if (au == null) {
            return CommonResult.fail("当前操作人已失效，无法查看数据");
        }
        IPage<ApprovePageVo> accountData = new Page<>();
        PageUtils<ApprovePageVo> finallResult = new PageUtils<ApprovePageVo>(accountData);
        List<ApprovePageVo> datas = new ArrayList<>();
        if (typeId == eApplyType.Org.getValue()) {//组织
            PageUtils<ApplyClubVo> pages = alumniClubApplyService.queryApproveClubApplys(currentPage, pageCount, userId, keyword);
            for (ApplyClubVo pg : pages.getList()) {
                ApprovePageVo data = new ApprovePageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(pg.getName());
                data.setIsPass(pg.getIsPass());
                String collegeName = au.getCollegeName() == null ? "" : au.getCollegeName();
                String periodName = au.getPeriodName() == null ? "" : "/" + au.getPeriodName();
                String majorName = au.getMajorName() == null ? "" : "/" + au.getMajorName();
                String className = au.getClassName() == null ? "" : "/" + au.getClassName();
                data.setCollegeName(collegeName + "" + periodName + "" + majorName + "" + className);
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(pg.getCreateTime());
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());

        } else if (typeId == eApplyType.Activity.getValue()) {//活动
            PageUtils<AlumniMyActivityPageVo> pages = alumniActivityService.queryApproveActivityApplyPages(currentPage, pageCount, userId, keyword);
            for (AlumniMyActivityPageVo pg : pages.getList()) {
                ApprovePageVo data = new ApprovePageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(pg.getOrgName());
                data.setTheme(pg.getTheme());
                data.setIsPass(pg.getIsPass());
                String collegeName = au.getCollegeName() == null ? "" : au.getCollegeName();
                String periodName = au.getPeriodName() == null ? "" : "/" + au.getPeriodName();
                String majorName = au.getMajorName() == null ? "" : "/" + au.getMajorName();
                String className = au.getClassName() == null ? "" : "/" + au.getClassName();
                data.setCollegeName(collegeName + "" + periodName + "" + majorName + "" + className);
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(TimeExchange.DateToString(pg.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());
        } else if (typeId == eApplyType.Endorse.getValue()) {//母校代言
            PageUtils<ApplicationRecordPageVo> pages = alumniEndorseService.applicationApproveRecordDatas(currentPage, pageCount, userId, keyword);
            for (ApplicationRecordPageVo pg : pages.getList()) {
                ApprovePageVo data = new ApprovePageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(au.getOrgName());
                data.setIsPass(pg.getIsPass());
                String collegeName = au.getCollegeName() == null ? "" : au.getCollegeName();
                String periodName = au.getPeriodName() == null ? "" : "/" + au.getPeriodName();
                String majorName = au.getMajorName() == null ? "" : "/" + au.getMajorName();
                String className = au.getClassName() == null ? "" : "/" + au.getClassName();
                data.setCollegeName(collegeName + "" + periodName + "" + majorName + "" + className);
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(pg.getCreateTime());
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());
        } else if (typeId == eApplyType.Image.getValue()) {//相册
            PageUtils<ImageMyPageVo> pages = alumniImageService.imageApproveApplyPageDatas(currentPage, pageCount, userId, keyword);
            for (ImageMyPageVo pg : pages.getList()) {
                ApprovePageVo data = new ApprovePageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(au.getOrgName());
                data.setIsPass(pg.getIsPass());
                String collegeName = au.getCollegeName() == null ? "" : au.getCollegeName();
                String periodName = au.getPeriodName() == null ? "" : "/" + au.getPeriodName();
                String majorName = au.getMajorName() == null ? "" : "/" + au.getMajorName();
                String className = au.getClassName() == null ? "" : "/" + au.getClassName();
                data.setCollegeName(collegeName + "" + periodName + "" + majorName + "" + className);
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(TimeExchange.DateToString(pg.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());
        } else {//活动相册
            PageUtils<ActivityMyImageApplyVo> pages = activityImageService.activityApproveImagePageDatas(currentPage, pageCount, userId, keyword);
            for (ActivityMyImageApplyVo pg : pages.getList()) {
                ApprovePageVo data = new ApprovePageVo();
                data.setId(pg.getId());
                data.setModelId(typeId);
                data.setModelName(eApplyType.stringOf(typeId));
                data.setUserName(au.getName());
                data.setPhone(au.getPhone());
                data.setOrgName(au.getOrgName());
                data.setTheme(pg.getTheme());
                data.setIsPass(pg.getIsPass());
                String collegeName = au.getCollegeName() == null ? "" : au.getCollegeName();
                String periodName = au.getPeriodName() == null ? "" : "/" + au.getPeriodName();
                String majorName = au.getMajorName() == null ? "" : "/" + au.getMajorName();
                String className = au.getClassName() == null ? "" : "/" + au.getClassName();
                data.setCollegeName(collegeName + "" + periodName + "" + majorName + "" + className);
                data.setPassName(ePassType.stringOf(pg.getIsPass()));
                data.setCreateTime(pg.getCreateTime());
                datas.add(data);
            }
            finallResult.setList(datas);
            finallResult.setTotalPage(pages.getTotalPage());
            finallResult.setPageSize(pages.getPageSize());
            finallResult.setCurrentPage(pages.getCurrentPage());
            finallResult.setTotalCount(pages.getTotalCount());
        }
        return CommonResult.ok(finallResult);
    }


}
