|
|
@@ -0,0 +1,154 @@
|
|
|
+package com.cyksj.web.controller.manage.form;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.mapper.manage.form.FormFieldsDataMapper;
|
|
|
+import com.cyksj.mapper.manage.form.FormFieldsMapper;
|
|
|
+import com.cyksj.model.entity.FormFields;
|
|
|
+import com.cyksj.model.entity.FormFieldsData;
|
|
|
+import com.cyksj.model.entity.FormTemplate;
|
|
|
+import com.cyksj.model.excel.ExcelOrderDonInfo;
|
|
|
+import com.cyksj.model.views.FormFieldsDataView;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/*
|
|
|
+ *项目名: netflix
|
|
|
+ *文件名: FormController
|
|
|
+ *创建者: JavaZou
|
|
|
+ *创建时间:2023/6/12 9:58
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/manage/form")
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class FormController {
|
|
|
+
|
|
|
+ private final FormFieldsMapper formFieldsMapper;
|
|
|
+
|
|
|
+ private final FormFieldsDataMapper formFieldsDataMapper;
|
|
|
+
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
+ private final HttpServletRequest request;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 问卷表单模板
|
|
|
+ */
|
|
|
+ @GetMapping("/get/template")
|
|
|
+ public Result<SearchResult<FormTemplate>> getTemplate() {
|
|
|
+ SearchResult<FormTemplate> search = beanSearcher.search(FormTemplate.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 问卷回答列表
|
|
|
+ */
|
|
|
+ @GetMapping("/get/data")
|
|
|
+ public Result<SearchResult<FormFieldsDataView>> getData() {
|
|
|
+ SearchResult<FormFieldsDataView> search = beanSearcher.search(FormFieldsDataView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param promotionId
|
|
|
+ */
|
|
|
+
|
|
|
+ public void exportOrderInfo(@PathVariable Long promotionId, String start, String end, String charset, HttpServletResponse response) throws IOException {
|
|
|
+ if (StrUtil.isNotBlank(start)) {
|
|
|
+ start = DateUtil.formatDate(new Date(Long.parseLong(start))) + " 00:00:00";
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(end)) {
|
|
|
+ end = DateUtil.formatDate(new Date(Long.parseLong(end))) + " 23:59:59";
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ExcelOrderDonInfo> list = cmsOrderDonService.exportOrderInfo(promotionId, start, end);
|
|
|
+
|
|
|
+ String fileName = "报名信息";
|
|
|
+ response.setContentType("application/x-download");
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ response.setHeader("Content-disposition",
|
|
|
+ "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO-8859-1") + ExcelTypeEnum.XLS.getValue());
|
|
|
+
|
|
|
+ EasyExcel.write(response.getOutputStream())
|
|
|
+ // 这里放入动态头
|
|
|
+ .head(head(4l)).sheet("商务合作问卷")
|
|
|
+ // 当然这里数据也可以用 List<List<String>> 去传入
|
|
|
+ .doWrite(data(list));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<List<String>> head(Long templateId) {
|
|
|
+
|
|
|
+ List<FormFields> formFields = formFieldsMapper.selectList(new LambdaQueryWrapper<FormFields>().eq(FormFields::getTemplateId, templateId).orderByAsc(FormFields::getSorted));
|
|
|
+ List<List<String>> headTitles = new ArrayList<>();
|
|
|
+// String orderInfo = "订单基本信息";
|
|
|
+ String formInfo = "表单信息";
|
|
|
+// String lottery = "中奖信息";
|
|
|
+// //第一列,1/2/3行
|
|
|
+// headTitles.add( Lists.newArrayList(orderInfo,orderInfo,"订单号" ));
|
|
|
+// headTitles.add( Lists.newArrayList(orderInfo,orderInfo,"微信名称" ));
|
|
|
+// headTitles.add( Lists.newArrayList(orderInfo,orderInfo,"推荐人微信名称" ));
|
|
|
+// headTitles.add( Lists.newArrayList(orderInfo,orderInfo,"金额" ));
|
|
|
+// headTitles.add( Lists.newArrayList(orderInfo,orderInfo,"支付时间" ));
|
|
|
+//
|
|
|
+// headTitles.add( Lists.newArrayList(lottery,lottery,"奖品名称" ));
|
|
|
+// headTitles.add( Lists.newArrayList(lottery,lottery,"奖品描述" ));
|
|
|
+
|
|
|
+ formFields.forEach((field) -> {
|
|
|
+ headTitles.add(Lists.newArrayList(formInfo, formInfo, field.getFieldsName()));
|
|
|
+ });
|
|
|
+ return headTitles;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<List<String>> data(List<ExcelOrderDonInfo> list) {
|
|
|
+ List<List<String>> contentList = Lists.newArrayList();
|
|
|
+ list.forEach((donInfo) -> {
|
|
|
+ ArrayList<String> dataList = Lists.newArrayList(donInfo.getOrderNo(), donInfo.getNickName(), donInfo.getSharedName(), donInfo.getPrice().toString(), DateUtil.format(donInfo.getPayTime(), "yyyy年MM月dd日HH时mm分ss秒"));
|
|
|
+
|
|
|
+// OrderDon orderDon = cmsOrderDonService.getById(donInfo.getOrderId());
|
|
|
+// LotteryRecord lotteryRecord = Optional.ofNullable(
|
|
|
+// lotteryRecordMapper.selectOne(new LambdaQueryWrapper<LotteryRecord>()
|
|
|
+// .eq(LotteryRecord::getUserId, orderDon.getUserId())
|
|
|
+// .eq(LotteryRecord::getPromotionId, orderDon.getPromotionId())
|
|
|
+// .last("limit 1")))
|
|
|
+// .orElseGet(() -> {
|
|
|
+// LotteryRecord record = new LotteryRecord();
|
|
|
+// record.setGiftName(StringUtil.EMPTY);
|
|
|
+// record.setGiftDesc(StringUtil.EMPTY);
|
|
|
+// return record;
|
|
|
+// });
|
|
|
+//
|
|
|
+// dataList.add(lotteryRecord.getGiftName());
|
|
|
+// dataList.add(lotteryRecord.getGiftDesc());
|
|
|
+
|
|
|
+ List<FormFieldsData> fieldsDataList = formFieldsDataMapper.selectList(new LambdaQueryWrapper<FormFieldsData>().eq(FormFieldsData::getOrderId, donInfo.getOrderId()).orderByAsc(FormFieldsData::getSorted));
|
|
|
+ fieldsDataList.forEach((formFieldsData) -> {
|
|
|
+ dataList.add(formFieldsData.getContent());
|
|
|
+ });
|
|
|
+
|
|
|
+ contentList.add(dataList);
|
|
|
+ });
|
|
|
+
|
|
|
+ return contentList;
|
|
|
+ }
|
|
|
+}
|