无关风月
8 小时以前 16207f06b1aae069c05657c178855388a2bcf5b2
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TVipDetailController.java
@@ -1,10 +1,12 @@
package com.dsh.guns.modular.system.controller.code;
import cn.hutool.core.collection.CollUtil;
import com.dsh.course.feignClient.account.AppUserClient;
import com.dsh.course.feignClient.account.VipPaymentClient;
import com.dsh.course.feignClient.account.model.QueryByNamePhone;
import com.dsh.course.feignClient.account.model.TAppUser;
import com.dsh.course.feignClient.activity.CouponClient;
import com.dsh.course.feignClient.activity.model.HuiminPayQuery;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.core.base.tips.SuccessTip;
import com.dsh.guns.modular.system.model.*;
@@ -12,13 +14,19 @@
import com.dsh.guns.modular.system.model.dto.VipRefundDto;
import com.dsh.guns.modular.system.model.vo.VipPaymentListVO;
import com.dsh.guns.modular.system.service.*;
import com.dsh.guns.modular.system.util.DateUtil;
import com.dsh.guns.modular.system.util.ExcelUtil;
import com.dsh.guns.modular.system.util.ResultUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.util.stream.Collectors;
@@ -142,6 +150,116 @@
        return res;
    }
    /**
     * 导出会员卡订单
     * @param
     */
    @GetMapping("/export")
    public void exportData(String appUserName
            , String phone, String vipName
            , Integer isRefund
            , String time, HttpServletResponse response) {
        VipPaymentDto vipPaymentDto = new VipPaymentDto();
        if (StringUtils.hasLength(vipName)){
            List<Integer> vipIds = vipService.lambdaQuery().like(Vip::getVipName, vipName)
                    .list().stream().map(Vip::getId).collect(Collectors.toList());
            if (vipIds.isEmpty()){
                vipIds.add(-1);
            }
            vipPaymentDto.setVipIds(vipIds);
        }
        if (StringUtils.hasLength(phone)){
            QueryByNamePhone queryByNamePhone = new QueryByNamePhone();
            queryByNamePhone.setPhone( phone);
            List<Integer> userIds = appUserClient.queryByNamePhone(queryByNamePhone).stream().map(TAppUser::getId)
                    .collect(Collectors.toList());
            vipPaymentDto.setUserIds(userIds);
        }
        if (StringUtils.hasLength(appUserName)){
            QueryByNamePhone queryByNamePhone = new QueryByNamePhone();
            queryByNamePhone.setName( appUserName);
            List<Integer> userIds = appUserClient.queryByNamePhone(queryByNamePhone).stream().map(TAppUser::getId)
                    .collect(Collectors.toList());
            if (vipPaymentDto.getUserIds()!=null){
                // 取交集
                vipPaymentDto.setUserIds(vipPaymentDto.getUserIds().stream().filter(userIds::contains).collect(Collectors.toList()));
            }else{
                vipPaymentDto.setUserIds(userIds);
            }
        }
        if (StringUtils.hasLength(appUserName)|| StringUtils.hasLength(phone)){
            if (vipPaymentDto.getUserIds().isEmpty()){
                List<Integer> userIds = vipPaymentDto.getUserIds();
                userIds.add(-1);
                vipPaymentDto.setUserIds(userIds);
            }
        }
        vipPaymentDto.setIsRefund(isRefund);
        if (StringUtils.hasLength(time)){
            String stareTime = null;
            String endTime = null;
            stareTime = time.split(" - ")[0] + " 00:00:00";
            endTime = time.split(" - ")[1] + " 23:59:59";
            vipPaymentDto.setStartTime(stareTime);
            vipPaymentDto.setEndTime(endTime);
        }
        QueryByNamePhone queryByNamePhone = new QueryByNamePhone();
        List<TAppUser> tAppUsers = appUserClient.queryByNamePhone(queryByNamePhone);
        List<Vip> vipList = vipService.list();
        List<VipPaymentListVO> res =vipPaymentClient.vipPayment(vipPaymentDto);
        for (VipPaymentListVO re : res) {
            Vip vip = vipList.stream().filter(e -> e.getId().equals(re.getVipId())).findFirst().orElse(null);
            if (vip!=null){
                re.setVipName(vip.getVipName());
                Integer timeType = vip.getTimeType();
                Integer time1 = vip.getTime();
                switch (timeType){
                    case 1:
                        re.setVipTime(time1 + "天");
                        break;
                    case 2:
                        re.setVipTime(time1 + "月");
                        break;
                    case 3:
                        re.setVipTime(time1 + "年");
                        break;
                }
            }
            re.setAmountValue("¥"+re.getAmount().toString());
            TAppUser appUser = tAppUsers.stream().filter(e -> e.getId().equals(re.getAppUserId())).findFirst().orElse(null);
            if (appUser!=null){
                re.setAppUserName(appUser.getName());
                re.setAppUserPhone(appUser.getName());
            }
        }
        String[] titleArr = {"订单编号", "用户姓名", "联系电话", "会员卡名称", "时长", "金额", "下单时间", "是否退费", "备注"};
        String[][] values = new String[res.size()][];
        for (int i = 0; i < res.size(); i++) {
            VipPaymentListVO vipPaymentListVO = res.get(i);
            values[i] = new String[titleArr.length];
            values[i][0] = vipPaymentListVO.getCode();
            values[i][1] = vipPaymentListVO.getAppUserName();
            values[i][2] = vipPaymentListVO.getAppUserPhone();
            values[i][3] = vipPaymentListVO.getVipName();
            values[i][4] = vipPaymentListVO.getVipTime();
            values[i][5] = vipPaymentListVO.getAmountValue();
            values[i][6] = DateUtil.format(vipPaymentListVO.getInsertTime(), "yyyy-MM-dd HH:mm:ss");
            values[i][7] = vipPaymentListVO.getIsRefund() == 1 ? "是" : "否";
            values[i][8] = vipPaymentListVO.getRemark().toString();
        }
        try {
            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("会员卡订单", titleArr, values, null);
            ExcelUtil.setResponseHeader(response, "会员卡订单.xls");
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 退费
     */
    @RequestMapping(value = "/refund")