|
@@ -1,33 +1,29 @@
|
|
|
package com.cyksj.web.controller.manage.form;
|
|
package com.cyksj.web.controller.manage.form;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
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.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.dto.Result;
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.manage.form.FormFieldsDataMapper;
|
|
import com.cyksj.mapper.manage.form.FormFieldsDataMapper;
|
|
|
import com.cyksj.mapper.manage.form.FormFieldsMapper;
|
|
import com.cyksj.mapper.manage.form.FormFieldsMapper;
|
|
|
|
|
+import com.cyksj.mapper.manage.form.FormTemplateMapper;
|
|
|
|
|
+import com.cyksj.model.dto.FormFieldsView;
|
|
|
|
|
+import com.cyksj.model.dto.FormTemplateDataDto;
|
|
|
import com.cyksj.model.entity.FormFields;
|
|
import com.cyksj.model.entity.FormFields;
|
|
|
-import com.cyksj.model.entity.FormFieldsData;
|
|
|
|
|
|
|
+import com.cyksj.model.entity.FormFieldsDefault;
|
|
|
import com.cyksj.model.entity.FormTemplate;
|
|
import com.cyksj.model.entity.FormTemplate;
|
|
|
-import com.cyksj.model.excel.ExcelOrderDonInfo;
|
|
|
|
|
import com.cyksj.model.views.FormFieldsDataView;
|
|
import com.cyksj.model.views.FormFieldsDataView;
|
|
|
|
|
+import com.cyksj.service.mange.form.FormService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
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 org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
@@ -46,24 +42,97 @@ public class FormController {
|
|
|
|
|
|
|
|
private final FormFieldsDataMapper formFieldsDataMapper;
|
|
private final FormFieldsDataMapper formFieldsDataMapper;
|
|
|
|
|
|
|
|
|
|
+ private final FormTemplateMapper formTemplateMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final FormService formService;
|
|
|
|
|
+
|
|
|
private final BeanSearcher beanSearcher;
|
|
private final BeanSearcher beanSearcher;
|
|
|
|
|
|
|
|
private final HttpServletRequest request;
|
|
private final HttpServletRequest request;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 问卷表单模板
|
|
|
|
|
|
|
+ * 新增模板 以及对应模板字段
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/template/post")
|
|
|
|
|
+ public Result<String> insertTemplateAndRelationFields(@RequestBody FormTemplateDataDto dataDto) {
|
|
|
|
|
+ formService.saveOrUpdateTemplateAndRelationFields(dataDto);
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 编辑模板以及对应模板字段
|
|
|
|
|
+ */
|
|
|
|
|
+ @PutMapping("/template/put")
|
|
|
|
|
+ public Result<String> updateTemplateAndRelationFields(@RequestBody FormTemplateDataDto dataDto) {
|
|
|
|
|
+ formService.saveOrUpdateTemplateAndRelationFields(dataDto);
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 选择模板 生成对应问题
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/template/fields/value")
|
|
|
|
|
+ public Result<String> postTemplateFieldsValue(@RequestBody List<FormFieldsDefault> values) {
|
|
|
|
|
+ formService.saveOrUpdateTemplateFieldsValue(values);
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 选择模板 修改对应问题
|
|
|
|
|
+ */
|
|
|
|
|
+ @PutMapping("/template/fields/value")
|
|
|
|
|
+ public Result<String> updateTemplateFieldsValue(@RequestBody List<FormFieldsDefault> values) {
|
|
|
|
|
+ formService.saveOrUpdateTemplateFieldsValue(values);
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除模板
|
|
|
|
|
+ */
|
|
|
|
|
+ @PutMapping("/template/del/{id}")
|
|
|
|
|
+ public Result<String> delTid(@PathVariable Long id) {
|
|
|
|
|
+ formTemplateMapper.update(null, Wrappers.lambdaUpdate(FormTemplate.class)
|
|
|
|
|
+ .set(FormTemplate::getIsDeleted, false)
|
|
|
|
|
+ .eq(FormTemplate::getId, id));
|
|
|
|
|
+
|
|
|
|
|
+ formFieldsMapper.update(null, Wrappers.lambdaUpdate(FormFields.class)
|
|
|
|
|
+ .set(FormFields::getIsDeleted, false)
|
|
|
|
|
+ .eq(FormFields::getTemplateId, id));
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 问卷表单模板列表
|
|
|
*/
|
|
*/
|
|
|
- @GetMapping("/get/template")
|
|
|
|
|
|
|
+ @GetMapping("/template/get")
|
|
|
public Result<SearchResult<FormTemplate>> getTemplate() {
|
|
public Result<SearchResult<FormTemplate>> getTemplate() {
|
|
|
SearchResult<FormTemplate> search = beanSearcher.search(FormTemplate.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
SearchResult<FormTemplate> search = beanSearcher.search(FormTemplate.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 模板详情 问卷字段列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/template/get/detail/{id}")
|
|
|
|
|
+ public Result<SearchResult<FormFieldsView>> getFieldsView(@PathVariable Long id) {
|
|
|
|
|
+ SearchResult<FormFieldsView> search = beanSearcher.search(FormFieldsView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
|
|
+ .field(FormFieldsView::getTemplateId, id)
|
|
|
|
|
+ .orderBy(FormFieldsView::getSorted).asc()
|
|
|
|
|
+ .build());
|
|
|
|
|
+ search.getDataList().forEach(data->{
|
|
|
|
|
+ List<FormFieldsDefault> formFieldsDefaults = beanSearcher.searchAll(FormFieldsDefault.class, MapUtils.builder().field(FormFieldsDefault::getFieldsId, data.getId()).orderBy(FormFieldsDefault::getId).asc().build());
|
|
|
|
|
+ data.setFieldsDefaults(formFieldsDefaults);
|
|
|
|
|
+ });
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 问卷回答列表
|
|
* 问卷回答列表
|
|
|
*/
|
|
*/
|
|
|
- @GetMapping("/get/data")
|
|
|
|
|
- public Result<SearchResult<FormFieldsDataView>> getData() {
|
|
|
|
|
|
|
+ @GetMapping("/get/question/resp/data")
|
|
|
|
|
+ public Result<SearchResult<FormFieldsDataView>> getData(Long fieldsId) {
|
|
|
|
|
+ if (fieldsId == null) fieldsId = 3l;
|
|
|
SearchResult<FormFieldsDataView> search = beanSearcher.search(FormFieldsDataView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
SearchResult<FormFieldsDataView> search = beanSearcher.search(FormFieldsDataView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
}
|
|
@@ -71,84 +140,20 @@ public class FormController {
|
|
|
/**
|
|
/**
|
|
|
* @param promotionId
|
|
* @param promotionId
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
- public void exportOrderInfo(@PathVariable Long promotionId, String start, String end, String charset, HttpServletResponse response) throws IOException {
|
|
|
|
|
|
|
+ @GetMapping("/export/question/resp/data")
|
|
|
|
|
+ public void exportQuestionInfo(@RequestParam(required = false, defaultValue = "1") Long promotionId, String start, String end, String charset, HttpServletResponse response) throws Exception {
|
|
|
if (StrUtil.isNotBlank(start)) {
|
|
if (StrUtil.isNotBlank(start)) {
|
|
|
start = DateUtil.formatDate(new Date(Long.parseLong(start))) + " 00:00:00";
|
|
start = DateUtil.formatDate(new Date(Long.parseLong(start))) + " 00:00:00";
|
|
|
}
|
|
}
|
|
|
if (StrUtil.isNotBlank(end)) {
|
|
if (StrUtil.isNotBlank(end)) {
|
|
|
end = DateUtil.formatDate(new Date(Long.parseLong(end))) + " 23:59:59";
|
|
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;
|
|
|
|
|
|
|
+ if (StrUtil.isBlank(start)) {
|
|
|
|
|
+ start = DateUtil.beginOfDay(DateTime.now()).toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isBlank(end)) {
|
|
|
|
|
+ start = DateUtil.endOfDay(DateTime.now()).toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ formService.exportQuestionInfo(promotionId, start, end, response);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|