package com.ym.mec.web.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dao.*;
import com.ym.mec.biz.dal.dto.*;
import com.ym.mec.biz.dal.entity.*;
import com.ym.mec.biz.dal.enums.GroupType;
import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
import com.ym.mec.biz.dal.page.*;
import com.ym.mec.biz.service.*;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.util.collection.MapUtil;
import com.ym.mec.util.date.DateUtil;
import com.ym.mec.util.excel.POIUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@RequestMapping
@Api(tags = "数据导出服务")
@Controller
public class ExportController extends BaseController {

    @Autowired
    private StudentRegistrationService studentRegistrationService;
    @Autowired
    private StudentManageService studentManageService;
    @Autowired
    private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
    @Autowired
    private CourseScheduleTeacherSalaryService courseScheduleTeacherSalaryService;
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private EmployeeDao employeeDao;
    @Autowired
    private StudentPaymentOrderService studentPaymentOrderService;
    @Autowired
    private StudentRegistrationDao studentRegistrationDao;
    @Autowired
    private VipGroupDao vipGroupDao;
    @Autowired
    private MusicGroupDao musicGroupDao;
    @Autowired
    private VipGroupService vipGroupService;
    @Autowired
    private PracticeGroupService practiceGroupService;
    @Autowired
    private CourseScheduleService scheduleService;
    @Autowired
    private SporadicChargeInfoService sporadicChargeInfoService;

    @ApiOperation(value = "导出陪练课列表")
    @GetMapping("export/practiceGroupList")
    @PreAuthorize("@pcs.hasPermissions('export/practiceGroupList')")
    public void queryAll(HttpServletResponse response,PracticeGroupQueryInfo queryInfo) {
        queryInfo.setRows(999999999);
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            throw new BizException("用户信息获取失败");
        }
        if(!sysUser.getIsSuperAdmin()){
            Employee employee = employeeDao.get(sysUser.getId());
            if (StringUtils.isEmpty(queryInfo.getOrganId())) {
                queryInfo.setOrganId(employee.getOrganIdList());
            }else if(StringUtils.isEmpty(employee.getOrganIdList())){
                throw new BizException("用户所在分部异常");
            }else {
                List<String> list = Arrays.asList(employee.getOrganIdList().split(","));
                if(!list.containsAll(Arrays.asList(queryInfo.getOrganId().split(",")))){
                    throw new BizException("非法请求");
                }
            }
        }
        List<PracticeGroupDto> rows = practiceGroupService.findPracticeGroups(queryInfo).getRows();
        if(rows != null && rows.size() > 0){
            rows.forEach(e->{
                e.setSubClassTimes(e.getTotalClassTimes()==null?0:e.getTotalClassTimes() - (e.getCurrentClassTimes()==null?0:e.getCurrentClassTimes()));
            });
        }
        try {
            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"分部","陪练课编号", "课程名称", "指导老师", "班级人数", "先上课单价", "线下课单价",
                    "当前课次", "总课次", "剩余课次","开课时间", "结束时间"}, new String[]{
                    "organName","id", "name", "teacherName", "studentNum", "onlineClassesUnitPrice",
                    "offlineClassesUnitPrice", "currentClassTimes", "totalClassTimes", "subClassTimes","coursesStartDate", "coursesExpireDate"}, rows);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "导出VIP课管理")
    @GetMapping("export/vipGroupList")
    @PreAuthorize("@pcs.hasPermissions('export/vipGroupList')")
    public void queryAll(HttpServletResponse response,VipGroupQueryInfo queryInfo) {
        queryInfo.setRows(999999999);
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            throw new BizException("用户信息获取失败");
        }
        if(!sysUser.getIsSuperAdmin()){
            Employee employee = employeeDao.get(sysUser.getId());
            if (StringUtils.isEmpty(queryInfo.getOrganId())) {
                queryInfo.setOrganId(employee.getOrganIdList());
            }else if(StringUtils.isEmpty(employee.getOrganIdList())){
                throw new BizException("用户所在分部异常");
            }else {
                List<String> list = Arrays.asList(employee.getOrganIdList().split(","));
                if(!list.containsAll(Arrays.asList(queryInfo.getOrganId().split(",")))){
                    throw new BizException("非法请求");
                }
            }
        }
        List<VipGroup> rows = vipGroupService.findVipGroups(queryInfo).getRows();
        if(rows != null && rows.size() > 0){
            rows.forEach(e->{
                e.setSubClassTimes(e.getTotalClassTimes()==null?0:e.getTotalClassTimes() - (e.getCurrentClassTimes()==null?0:e.getCurrentClassTimes()));
            });
        }
        try {
            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"VIP编号", "课程名称", "课程状态", "指导老师", "班级人数", "先上课单价", "线下课单价",
                    "活动方案", "当前课次", "总课次", "剩余课次", "月消耗", "开课时间", "结束时间", "申请时间"}, new String[]{
                    "id", "name", "status.msg", "userName", "studentNum", "onlineClassesUnitPrice",
                    "offlineClassesUnitPrice", "vipGroupActivityName", "currentClassTimes", "totalClassTimes", "subClassTimes", "monthConsumeRate",
                    "courseStartDate", "coursesExpireDate", "registrationStartTime"}, rows);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "终课表列表导出")
    @GetMapping("export/superFindCourseSchedules")
    @PreAuthorize("@pcs.hasPermissions('export/superFindCourseSchedules')")
    public void superFindCourseSchedules(EndCourseScheduleQueryInfo queryInfo,HttpServletResponse response){
        queryInfo.setRows(999999999);
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            throw new BizException("用户信息获取失败");
        }
        if(!sysUser.getIsSuperAdmin()){
            Employee employee = employeeDao.get(sysUser.getId());
            if (org.apache.commons.lang3.StringUtils.isEmpty(queryInfo.getOrganIdList())) {
                queryInfo.setOrganIdList(employee.getOrganIdList());
            }else if(org.apache.commons.lang3.StringUtils.isEmpty(employee.getOrganIdList())){
                throw new BizException("用户所在分部异常");
            }else {
                List<String> list = Arrays.asList(employee.getOrganIdList().split(","));
                if(!list.containsAll(Arrays.asList(queryInfo.getOrganIdList().split(",")))){
                    throw new BizException("非法请求");
                }
            }
        }
        List<CourseScheduleEndDto> rows = scheduleService.endFindCourseSchedules(queryInfo).getRows();
        try {
            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"分部名称", "课程编号", "开始时间", "结束时间", "班级名称", "班级声部", "课程名称", "课程类型", "教学模式",
                    "教学点", "课程状态", "是否点名", "指导老师", "签到时间", "签退时间","签到备注"}, new String[]{
                    "organName", "id", "startClassTime", "endClassTime", "classGroupName","subjectName", "name",
                    "groupType.desc", "teachMode.msg", "schoolName", "status.msg", "isCallNames.msg", "teacherName", "signInTime",
                    "signOutTime","remark"}, rows);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @ApiOperation(value = "导出零星收费列表")
    @GetMapping("export/sporadicChargeInfo")
    @PreAuthorize("@pcs.hasPermissions('export/sporadicChargeInfo')")
    public void queryPage(SporadicChargeInfoQueryInfo queryInfo,HttpServletResponse response) {
        queryInfo.setRows(999999999);
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            throw new BizException("用户信息获取失败");
        }
        if(!sysUser.getIsSuperAdmin()){
            Employee employee = employeeDao.get(sysUser.getId());
            if (StringUtils.isEmpty(queryInfo.getOrganId())) {
                queryInfo.setOrganId(employee.getOrganIdList());
            }else if(StringUtils.isEmpty(employee.getOrganIdList())){
                throw new BizException("用户所在分部异常");
            }else {
                List<String> list = Arrays.asList(employee.getOrganIdList().split(","));
                if(!list.containsAll(Arrays.asList(queryInfo.getOrganId().split(",")))){
                    throw new BizException("非法请求");
                }
            }
        }
        List<SporadicChargeInfo> rows = sporadicChargeInfoService.queryDetailPage(queryInfo).getRows();
        try {
            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"分部", "收费类型", "标题", "金额", "时间", "学生姓名","创建人"}, new String[]{
                    "organName", "chargeType.msg", "title", "amount", "updateTime", "userName","operatorName"}, rows);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "导出学员是否有课")
    @PostMapping("export/studentHasCourse")
    @PreAuthorize("@pcs.hasPermissions('export/studentHasCourse')")
    public void studentHasCourse(HttpServletResponse response,String organId) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            throw new BizException("获取用户信息失败");
        }
        if(StringUtils.isEmpty(organId)){
            Employee employee = employeeDao.get(sysUser.getId());
            organId = employee.getOrganIdList();
        }
        List<StudentHasCourseDto> hasCourseDtos = studentManageService.queryHasCourseStudent(organId);
        try {
            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"学员编号", "姓名", "分部", "所在乐团", "乐团所属声部", "所在vip课","是否激活","是否预约"}, new String[]{
                    "userId", "userName", "organName", "musicGroupName", "subjectName", "vipGroupName","isActive.msg","isMake.msg"}, hasCourseDtos);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @ApiOperation(value = "导出乐器采购清单")
    @PostMapping("order/musicalListExport")
    @PreAuthorize("@pcs.hasPermissions('order/musicalListExport')")
    public void musicalListExport(HttpServletResponse response, String musicGroupId) {
        List<Goods> musicalList = studentPaymentOrderDetailService.getMusicalList(musicGroupId);
        try {
            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"分部", "乐团", "商品类型", "商品名称", "型号", "数量"}, new String[]{
                    "brief", "memo", "type.desc", "name", "specification", "sellCount"}, musicalList);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "导出学员采购清单明细")
    @PostMapping("order/musicalListDetailExport")
    @PreAuthorize("@pcs.hasPermissions('order/musicalListDetailExport')")
    public void musicalListDetailExport(HttpServletResponse response, String musicGroupId) {
        List<musicalListDetailDto> musicalList = studentPaymentOrderDetailService.getMusicalListDetail(musicGroupId);
        try {
            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"分部", "乐团", "学员编号", "学员姓名", "购买商品", "采购方式", "乐器金额", "教辅金额", "课程金额", "订单总价"}, new String[]{
                    "organName", "musicGroupName", "userId", "username", "goodsNames", "kitGroupPurchaseTypeEnum.msg", "musicalAmount", "accessoriesAmount", "courseAmount", "orderAmount"}, musicalList);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "乐团【报名中、缴费中】 学生详情列表导出")
    @PostMapping(value = "studentRegistration/queryStudentApplyDetailExport")
    @PreAuthorize("@pcs.hasPermissions('studentRegistration/queryStudentApplyDetailExport')")
    public void queryStudentApplyDetailExport(StudentRegistrationQueryInfo queryInfo, HttpServletResponse response) {
        List<StudentApplyDetailDto> studentApplyDetail = studentRegistrationService.queryStudentDetailPage(queryInfo).getRows();
        try {
            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"学生姓名", "家长姓名", "年级", "班级", "性别", "服从调剂", "报名专业", "实际专业", "联系电话", "学员缴费状态", "乐器购买方式"}, new String[]{
                    "studentName", "parentsName", "currentGrade", "currentClass", "gender.description", "isAllowAdjust.msg", "subjectName", "actualSubjectName", "parentsPhone", "paymentStatus.desc", "kitGroupPurchaseTypeEnum.msg"}, studentApplyDetail);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "分页导出教师薪酬列表")
    @RequestMapping("courseScheduleTeacherSalary/export")
    @PreAuthorize("@pcs.hasPermissions('courseScheduleTeacherSalary/export')")
    public void export(CourseScheduleTeacherSalaryQueryInfo queryInfo, HttpServletResponse response) {
        List<TeacherSalaryDto> teacherSalaries = courseScheduleTeacherSalaryService.querySalaries(queryInfo).getRows();
        try {
            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"用户编号", "用户名", "手机号", "课程类型", "实际薪水", "补助", "结算时间", "教师角色"}, new String[]{
                    "userId", "username", "phone", "type.msg", "name", "actualSalary", "subsidy", "settlementTime", "teacherRole.msg"}, teacherSalaries);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "订单列表导出")
    @RequestMapping("export/orderList")
    @PreAuthorize("@pcs.hasPermissions('export/orderList')")
    public void orderList(StudentPaymentOrderQueryInfo queryInfo, HttpServletResponse response) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (!sysUser.getIsSuperAdmin()) {
            Employee employee = employeeDao.get(sysUser.getId());
            if (StringUtils.isEmpty(queryInfo.getOrganId())) {
                queryInfo.setOrganId(employee.getOrganIdList());
            }
        }
        queryInfo.setRows(999999999);
        Map<String, Object> params = new HashMap<String, Object>();
        MapUtil.populateMap(params, queryInfo);
        List<StudentPaymentOrderExportDto> studentPaymentOrderExportDtos = studentPaymentOrderService.ExportQueryPage(params);

        long i = 1;
        for (StudentPaymentOrderExportDto row : studentPaymentOrderExportDtos) {
            if (queryInfo.getOrderType().equals("1")) {
                BigDecimal comAmount = row.getComAmount() == null ? BigDecimal.ZERO : row.getComAmount();
                row.setActualAmount(comAmount);
            } else if (queryInfo.getOrderType().equals("2")) {
                BigDecimal perAmount = row.getPerAmount() == null ? BigDecimal.ZERO : row.getPerAmount();
                row.setActualAmount(perAmount);
            }
            if (row.getActualAmount() == null) {
                row.setActualAmount(BigDecimal.ZERO);
            }
            BigDecimal transferFee = (row.getActualAmount().multiply(new BigDecimal("0.28")).divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_UP);
            row.setTransferFee(transferFee);
            BigDecimal musicalFee = BigDecimal.ZERO;
            BigDecimal teachingFee = BigDecimal.ZERO;
            BigDecimal courseFee = BigDecimal.ZERO;
            BigDecimal leaseFee = BigDecimal.ZERO;
            String goodsName = "";
            if (row.getOrderDetailList() != null) {
                for (StudentPaymentOrderDetail orderDetail : row.getOrderDetailList()) {
                    if (orderDetail.getType().equals(OrderDetailTypeEnum.MUSICAL)) {
                        if(orderDetail.getKitGroupPurchaseType() != null && orderDetail.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)){
                            leaseFee = orderDetail.getPrice();
                        }else {
                            musicalFee = orderDetail.getPrice();
                        }
                    } else if (orderDetail.getType().equals(OrderDetailTypeEnum.COURSE)) {
                        courseFee = courseFee.add(orderDetail.getPrice());
                    } else if (orderDetail.getType().equals(OrderDetailTypeEnum.ACCESSORIES) || orderDetail.getType().equals(OrderDetailTypeEnum.TEACHING) || orderDetail.getType().equals(OrderDetailTypeEnum.OTHER)) {
                        teachingFee = teachingFee.add(orderDetail.getPrice());
                    }
                }
            }
            if(row.getGoodsList() != null){
                goodsName = row.getGoodsList().stream().map(Goods::getName).collect(Collectors.joining("|"));
            }
            row.setCourseFee(courseFee);
            row.setMusicalFee(musicalFee);
            row.setTeachingFee(teachingFee);
            row.setLeaseFee(leaseFee);
            row.setMemo(goodsName);
            //专业
            if (row.getGroupType().equals(GroupType.MUSIC)) {
                StudentRegistration studentRegistration = studentRegistrationDao.findStudentByMusicGroupIdAndUserId(row.getMusicGroupId(), row.getUserId());
                if (studentRegistration != null) {
                    row.setSubjectName(studentRegistration.getSubjectName());
                    row.setSchoolName(studentRegistration.getSchoolName());
                    row.setCooperationOrganName(studentRegistration.getRemark());
                }
            } else if (row.getGroupType().equals(GroupType.VIP)) {
                row.setCourseFee(row.getActualAmount());
                VipGroup vipGroupInfo = vipGroupDao.findVipGroupInfo(Integer.parseInt(row.getMusicGroupId()), row.getClassGroupId());
                if (vipGroupInfo != null) {
                    row.setSchoolName(vipGroupInfo.getSchoolName());
                    row.setSubjectName(vipGroupInfo.getSubjectName());
                }

            } else if (row.getGroupType().equals(GroupType.SPORADIC)) {
                row.setSporadicAmount(row.getActualAmount());
                row.setMusicalFee(BigDecimal.ZERO);
                row.setTeachingFee(BigDecimal.ZERO);
                if (row.getChargeType() != null) {
                    if (row.getChargeType().equals(1)) {
                        row.setSporadicType("考级");
                    } else if (row.getChargeType().equals(2)) {
                        row.setSporadicType("声部更改");
                    } else if (row.getChargeType().equals(3)) {
                        row.setSporadicType("乐器更换");
                    } else if (row.getChargeType().equals(4)) {
                        row.setSporadicType("配件销售");
                    }else if (row.getChargeType().equals(5)) {
                        row.setSporadicType("维修费");
                    }else if (row.getChargeType().equals(6)) {
                        row.setSporadicType("福袋活动");
                    }else if (row.getChargeType().equals(7)) {
                        row.setSporadicType("上门费");
                    }
                }
                School userSchool = musicGroupDao.findUserSchool(row.getUserId());
                if(userSchool!= null){
                    row.setSchoolName(userSchool.getName());
                }
            }
            String paymentChannel = "";
            if (row.getPaymentChannel() == null) {
            } else if (row.getPaymentChannel().equals("YQPAY")) {
                paymentChannel = "双乾";
            } else if (row.getPaymentChannel().equals("ADAPAY")) {
                paymentChannel = "汇付";
            } else if (row.getPaymentChannel().equals("BALANCE")) {
                paymentChannel = "余额";
            }
            row.setPaymentChannel(paymentChannel);
            row.setId(i);
            i++;
        }

        try {
            String[] header = {"序号", "学生姓名", "交易流水号", "订单编号", "收款渠道", "收款账户", "支付金额", "到账时间",
                    "关联乐团ID/VIP课ID", "课程形态", "课程费用","减免费用","押金", "乐器", "教辅费用", "零星收款费用", "零星收款类别", "手续费", "专业", "分部", "单位/学校","合作机构","备注"};
            String[] body = {"id", "user.username", "transNo", "orderNo", "paymentChannel", "merNos", "actualAmount", "payTime", "musicGroupId",
                    "groupType.desc", "courseFee","remitFee", "leaseFee", "musicalFee", "teachingFee", "sporadicAmount", "sporadicType", "transferFee", "subjectName", "organName", "schoolName","cooperationOrganName", "memo"};
            HSSFWorkbook workbook = POIUtil.exportExcel(header, body, studentPaymentOrderExportDtos);
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @ApiOperation(value = "乐团管理--乐团详情-导出学员列表")
    @RequestMapping("export/musicGroupStudent")
    @PreAuthorize("@pcs.hasPermissions('export/musicGroupStudent')")
    public void queryMusicGroupStudent(MusicGroupStudentQueryInfo queryInfo, HttpServletResponse response) {
        queryInfo.setRows(99999);
        PageInfo<MusicGroupStudentsDto> musicGroupStudentsDtoPageInfo = studentManageService.queryMusicGroupStudent(queryInfo);
        try {
            for (MusicGroupStudentsDto row : musicGroupStudentsDtoPageInfo.getRows()) {
                if (row.getGender() != null) {
                    if (row.getGender().equals("1")) {
                        row.setGender("男");
                    } else {
                        row.setGender("女");
                    }
                }
                if (row.getPaymentStatus() != null) {
                    if (row.getPaymentStatus().equals("PAID_COMPLETED")) {
                        row.setPaymentStatus("完成缴费");
                    } else if (row.getPaymentStatus().equals("NON_PAYMENT")) {
                        row.setPaymentStatus("未缴费");
                    } else if (row.getPaymentStatus().equals("PROCESSING")) {
                        row.setPaymentStatus("缴费中");
                    }
                }
                if (row.getStudentStatus().equals("NORMAL")) {
                    row.setStudentStatus("在读");
                } else {
                    row.setStudentStatus("退团");
                }
                if (row.getIsActive()) {
                    row.setActiveName("是");
                } else {
                    row.setActiveName("否");
                }
                if (row.getIsNewStudent().equals(1)) {
                    row.setIsNewStudentStr("是");
                } else {
                    row.setIsNewStudentStr("否");
                }
                if (row.getNextPaymentDate() != null) {
                    row.setNextPaymentDateStr(DateUtil.format(row.getNextPaymentDate(), DateUtil.DEFAULT_PATTERN));
                }
            }
            String[] header = {"学员编号", "学员姓名", "性别", "联系电话", "年级", "班级", "专业", "学员状态", "新增学员", "缴费金额",
                    "下次缴费日期", "报名缴费", "是否激活"};
            String[] body = {"userId", "realName", "gender", "phone", "currentGrade", "currentClass", "subjectName", "studentStatus", "isNewStudentStr",
                    "courseFee", "nextPaymentDateStr", "paymentStatus", "activeName"};
            HSSFWorkbook workbook = POIUtil.exportExcel(header, body, musicGroupStudentsDtoPageInfo.getRows());
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
