|  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.common.controller.BaseController; | 
|---|
|  |  |  | import cc.mrbird.febs.common.entity.FebsResponse; | 
|---|
|  |  |  | import cc.mrbird.febs.common.entity.QueryRequest; | 
|---|
|  |  |  | import cc.mrbird.febs.common.exception.FebsException; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.RedisUtils; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.excl.ExcelSheetPO; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.excl.ExcelUtil; | 
|---|
|  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.mall.dto.activity.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.HappyActivity; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.HappyActivityOption; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.HappyActivityOrder; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IAdminHappyActivityService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.activity.AdminHappyActivityOrderCheckVo; | 
|---|
|  |  |  | import cn.hutool.core.date.DatePattern; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.ObjectUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.StrUtil; | 
|---|
|  |  |  | import lombok.RequiredArgsConstructor; | 
|---|
|  |  |  | import lombok.SneakyThrows; | 
|---|
|  |  |  | 
|---|
|  |  |  | ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SneakyThrows | 
|---|
|  |  |  | @GetMapping("/exportOrderList") | 
|---|
|  |  |  | public void exportOrderList(@RequestParam Map<String, String> params, HttpServletResponse response) { | 
|---|
|  |  |  | //获取查询参数 | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(params.get("activityId"))){ | 
|---|
|  |  |  | throw new FebsException("请选择活动"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String activityId = params.get("activityId"); | 
|---|
|  |  |  | HappyActivity happyActivity = adminHappyActivityService.getBaseMapper().selectById(activityId); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(happyActivity)){ | 
|---|
|  |  |  | throw new FebsException("活动不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<ExcelSheetPO> res = new ArrayList<>(); | 
|---|
|  |  |  | ExcelSheetPO orderSheet = new ExcelSheetPO(); | 
|---|
|  |  |  | String title = happyActivity.getName() + "的订单"; | 
|---|
|  |  |  | orderSheet.setTitle(title); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String[] header = {"序号","用户", "编号", "单价", "数量","总价","使用状态", "支付方式"}; | 
|---|
|  |  |  | orderSheet.setHeaders(header); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<HappyActivityOrder> orderListForExport = adminHappyActivityService.getOrderListForExport(params); | 
|---|
|  |  |  | List<List<Object>> list = new ArrayList<>(); | 
|---|
|  |  |  | if (orderListForExport.size() > 0) { | 
|---|
|  |  |  | int i = 0; | 
|---|
|  |  |  | for (HappyActivityOrder item : orderListForExport) { | 
|---|
|  |  |  | i++; | 
|---|
|  |  |  | List<Object> temp = new ArrayList<>(); | 
|---|
|  |  |  | temp.add(i); | 
|---|
|  |  |  | temp.add(item.getName()); | 
|---|
|  |  |  | temp.add(item.getOrderNo()); | 
|---|
|  |  |  | temp.add(item.getPrice()); | 
|---|
|  |  |  | temp.add(item.getNumCnt()); | 
|---|
|  |  |  | temp.add(item.getAmount()); | 
|---|
|  |  |  | temp.add(item.getState() == 2 ? "待使用" : "已使用"); | 
|---|
|  |  |  | temp.add(item.getPayType() == 0 ?"免费":"微信支付"); | 
|---|
|  |  |  | list.add(temp); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderSheet.setDataList(list); | 
|---|
|  |  |  | res.add(orderSheet); | 
|---|
|  |  |  | response = ResponseHeadUtil.setExcelHead(response); | 
|---|
|  |  |  | response.setHeader("Content-Disposition", | 
|---|
|  |  |  | "attachment;filename=" + URLEncoder.encode(title + DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) + ".xlsx".trim(), "UTF-8")); | 
|---|
|  |  |  | OutputStream os = null; | 
|---|
|  |  |  | os = response.getOutputStream(); | 
|---|
|  |  |  | ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 核销记录列表 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping("activityOrderCheckList") | 
|---|
|  |  |  | public FebsResponse activityOrderCheckList(AdminHappyActivityOrderCheckDto dto, QueryRequest request) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> data = getDataTable(adminHappyActivityService.activityOrderCheckList(dto, request)); | 
|---|
|  |  |  | return new FebsResponse().success().data(data); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 核销记录-手动核销 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("checkOrderItem") | 
|---|
|  |  |  | @ControllerEndpoint(operation = "核销记录-手动核销", exceptionMessage = "操作失败") | 
|---|
|  |  |  | public FebsResponse checkOrderItem(@RequestBody List<Long> dto) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return adminHappyActivityService.checkOrderItem(dto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SneakyThrows | 
|---|
|  |  |  | @GetMapping("/exportOrderCheckList") | 
|---|
|  |  |  | public void exportOrderCheckList(@RequestParam Map<String, String> params, HttpServletResponse response) { | 
|---|
|  |  |  | //获取查询参数 | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(params.get("activityId"))){ | 
|---|
|  |  |  | throw new FebsException("请选择活动"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String activityId = params.get("activityId"); | 
|---|
|  |  |  | HappyActivity happyActivity = adminHappyActivityService.getBaseMapper().selectById(activityId); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(happyActivity)){ | 
|---|
|  |  |  | throw new FebsException("活动不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<ExcelSheetPO> res = new ArrayList<>(); | 
|---|
|  |  |  | ExcelSheetPO orderSheet = new ExcelSheetPO(); | 
|---|
|  |  |  | String title = happyActivity.getName() + "的核销记录"; | 
|---|
|  |  |  | orderSheet.setTitle(title); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String[] header = {"序号", "票号","参与人","电话", "地址","使用状态","核销时间","核销员", "姓名", "联系方式"}; | 
|---|
|  |  |  | orderSheet.setHeaders(header); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<AdminHappyActivityOrderCheckVo> orderListForExport = adminHappyActivityService.getOrderCheckListForExport(params); | 
|---|
|  |  |  | List<List<Object>> list = new ArrayList<>(); | 
|---|
|  |  |  | if (orderListForExport.size() > 0) { | 
|---|
|  |  |  | int i = 0; | 
|---|
|  |  |  | for (AdminHappyActivityOrderCheckVo item : orderListForExport) { | 
|---|
|  |  |  | i++; | 
|---|
|  |  |  | List<Object> temp = new ArrayList<>(); | 
|---|
|  |  |  | temp.add(i); | 
|---|
|  |  |  | temp.add(item.getCode()); | 
|---|
|  |  |  | temp.add(item.getName()); | 
|---|
|  |  |  | temp.add(item.getPhone()); | 
|---|
|  |  |  | temp.add(item.getAddress()); | 
|---|
|  |  |  | temp.add(item.getState() == 1 ? "已使用" : "待使用"); | 
|---|
|  |  |  | temp.add(item.getState() == 1 ? item.getUpdatedTime() : ""); | 
|---|
|  |  |  | temp.add(item.getCheckName()); | 
|---|
|  |  |  | temp.add(item.getCheckRealName()); | 
|---|
|  |  |  | temp.add(item.getCheckPhone()); | 
|---|
|  |  |  | list.add(temp); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderSheet.setDataList(list); | 
|---|
|  |  |  | res.add(orderSheet); | 
|---|
|  |  |  | response = ResponseHeadUtil.setExcelHead(response); | 
|---|
|  |  |  | response.setHeader("Content-Disposition", | 
|---|
|  |  |  | "attachment;filename=" + URLEncoder.encode(title + DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) + ".xlsx".trim(), "UTF-8")); | 
|---|
|  |  |  | OutputStream os = null; | 
|---|
|  |  |  | os = response.getOutputStream(); | 
|---|
|  |  |  | ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|