zoujiajian 3 년 전
부모
커밋
59b178a4f8

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/model/views/FormFieldsDataView.java

@@ -16,7 +16,7 @@ import java.util.Date;
 @Getter
 @Setter
 @SearchBean(tables = "form_fields_data fa",
-		where = "fa.deleted is true")
+		where = "fa.deleted is true :time_sql:")
 public class FormFieldsDataView {
 	@DbField("fa.id")
 	private Integer id;

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/model/views/FormSubmitDataView.java

@@ -16,7 +16,7 @@ import java.util.Date;
 @Getter
 @Setter
 @SearchBean(tables = "form_fields_data fd left join form_fields ff on ff.id = fd.fields_id",
-		where = "fd.deleted is true")
+		where = "fd.deleted is true :time_sql:")
 public class FormSubmitDataView {
 	@DbField("fd.id")
 	private Long id;

+ 2 - 1
netflix-service/src/main/java/com/cyksj/service/mange/form/FormService.java

@@ -4,6 +4,7 @@ import com.cyksj.model.dto.FormTemplateDataDto;
 import com.cyksj.model.entity.FormFieldsDefault;
 
 import javax.servlet.http.HttpServletResponse;
+import java.util.Date;
 import java.util.List;
 
 /*
@@ -16,7 +17,7 @@ public interface FormService {
 
 	void saveOrUpdateTemplateAndRelationFields(FormTemplateDataDto dataDto);
 
-	void exportQuestionInfo(Long promotionId, String start, String end, HttpServletResponse response) throws Exception;
+	void exportQuestionInfo(Long promotionId, Date start, Date end, HttpServletResponse response) throws Exception;
 
 	void saveOrUpdateTemplateFieldsValue(List<FormFieldsDefault> values);
 }

+ 24 - 5
netflix-service/src/main/java/com/cyksj/service/mange/form/impl/FormServiceImpl.java

@@ -10,10 +10,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.mapper.manage.form.*;
 import com.cyksj.model.dto.FormTemplateDataDto;
-import com.cyksj.model.entity.*;
+import com.cyksj.model.entity.FormFields;
+import com.cyksj.model.entity.FormFieldsDefault;
+import com.cyksj.model.entity.FormTemplate;
+import com.cyksj.model.entity.QuestionnairePromotion;
 import com.cyksj.model.views.FormSubmitDataView;
 import com.cyksj.service.mange.form.FormService;
 import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.util.MapBuilder;
 import com.ejlchina.searcher.util.MapUtils;
 import com.google.common.collect.Lists;
 import lombok.RequiredArgsConstructor;
@@ -23,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -58,7 +63,7 @@ public class FormServiceImpl implements FormService {
 	}
 
 	@Override
-	public void exportQuestionInfo(Long promotionId, String start, String end, HttpServletResponse response) throws Exception {
+	public void exportQuestionInfo(Long promotionId, Date start, Date end, HttpServletResponse response) throws Exception {
 		QuestionnairePromotion promotion = questionnairePromotionMapper.selectById(promotionId);
 		if (promotion == null) throw BusinessRuntimeException.getInstance("问卷活动不存在");
 		String fileName = promotion.getName();
@@ -68,11 +73,12 @@ public class FormServiceImpl implements FormService {
 		response.setHeader("Content-disposition",
 				"attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO-8859-1") + ExcelTypeEnum.XLS.getValue());
 		List<FormFields> formFields = formFieldsMapper.selectList(new LambdaQueryWrapper<FormFields>().eq(FormFields::getTemplateId, promotion.getTemplateId()).orderByAsc(FormFields::getSorted));
+		List<List<String>> data = data(promotionId, formFields, start, end);
 		EasyExcel.write(response.getOutputStream())
 				// 这里放入动态头
 				.head(head(formFields)).sheet("问卷信息")
 				// 当然这里数据也可以用 List<List<String>> 去传入
-				.doWrite(data(promotionId, formFields));
+				.doWrite(data);
 	}
 
 	@Override
@@ -133,9 +139,22 @@ public class FormServiceImpl implements FormService {
 		return headTitles;
 	}
 
-	private List<List<String>> data(Long promotionId, List<FormFields> formFields) {
+	private List<List<String>> data(Long promotionId, List<FormFields> formFields, Date start, Date end) {
 //		List<FormFieldsData> fieldsDataList = formFieldsDataMapper.selectList(new LambdaQueryWrapper<FormFieldsData>().eq(FormFieldsData::getPromotionId, promotionId).eq(FormFieldsData::getDeleted, true).orderByAsc(FormFieldsData::getSorted));
-		List<FormSubmitDataView> formSubmitDataViews = beanSearcher.searchAll(FormSubmitDataView.class, MapUtils.builder().field(FormSubmitDataView::getPromotionId, promotionId).orderBy(FormSubmitDataView::getSorted).asc().build());
+		String timeSql = StrUtil.EMPTY;
+		if (start != null) {
+			timeSql += String.format(" and fd.created_time >= '%s'", start);
+		}
+		if (end != null) {
+			timeSql += String.format(" and fd.created_time < '%s'", end);
+		}
+		MapBuilder builder = MapUtils.builder()
+				.field(FormSubmitDataView::getPromotionId, promotionId)
+				.orderBy(FormSubmitDataView::getSorted).asc();
+		if (StrUtil.isNotBlank(timeSql)) {
+			builder.put("time_sql", timeSql);
+		}
+		List<FormSubmitDataView> formSubmitDataViews = beanSearcher.searchAll(FormSubmitDataView.class, builder.build());
 		if (formSubmitDataViews.isEmpty()) {
 			throw BusinessRuntimeException.getInstance("暂无数据");
 		}

+ 41 - 15
netflix-web/src/main/java/com/cyksj/web/controller/manage/form/FormController.java

@@ -20,13 +20,13 @@ import com.cyksj.service.mange.form.FormService;
 import com.cyksj.service.mange.form.QuestionnairePromotionService;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.SearchResult;
+import com.ejlchina.searcher.util.MapBuilder;
 import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.util.Date;
 import java.util.List;
 
 /*
@@ -131,7 +131,21 @@ public class FormController {
 	 * 用户问卷回答列表
 	 */
 	@GetMapping("/get/question/resp/data")
-	public Result<SearchResult<FormFieldsDataView>> getData(Long promotionId, Long fieldsId) {
+	public Result<SearchResult<FormFieldsDataView>> getData(Long promotionId, Long fieldsId, Long startTime, Long endTime) {
+		DateTime startDate = null;
+		DateTime endDate = null;
+		if (startTime != null) {
+			startDate = DateUtil.date(startTime);
+		}
+		if (endTime != null) {
+			endDate = DateUtil.date(endTime);
+		}
+		if (startDate == null) {
+			startDate = DateUtil.beginOfDay(DateTime.now());
+		}
+		if (endDate == null) {
+			endDate = DateUtil.offsetDay(startDate, 1);
+		}
 		if (promotionId != null) {
 			QuestionnairePromotion byId = promotionService.getById(promotionId);
 			if (byId == null) throw BusinessRuntimeException.getInstance("问卷不存在");
@@ -143,9 +157,19 @@ public class FormController {
 				}
 			}
 		}
-		SearchResult<FormFieldsDataView> search = beanSearcher.search(FormFieldsDataView.class, MapUtils.flatBuilder(request.getParameterMap())
-				.field(FormFieldsDataView::getFieldsId, fieldsId)
-				.build());
+		String timeSql = StrUtil.EMPTY;
+		if (startDate != null) {
+			timeSql += String.format(" and fa.created_time >= '%s'", startDate);
+		}
+		if (endDate != null) {
+			timeSql += String.format(" and fa.created_time < '%s'", endDate);
+		}
+		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap())
+				.field(FormFieldsDataView::getFieldsId, fieldsId);
+		if (StrUtil.isNotBlank(timeSql)) {
+			builder.put("time_sql", timeSql);
+		}
+		SearchResult<FormFieldsDataView> search = beanSearcher.search(FormFieldsDataView.class, builder.build());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
 	}
 
@@ -153,19 +177,21 @@ public class FormController {
 	 * @param promotionId
 	 */
 	@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)) {
-			start = DateUtil.formatDate(new Date(Long.parseLong(start))) + " 00:00:00";
+	public void exportQuestionInfo(@RequestParam(required = false, defaultValue = "1") Long promotionId, Long startTime, Long endTime, String charset, HttpServletResponse response) throws Exception {
+		DateTime startDate = null;
+		DateTime endDate = null;
+		if (startTime != null) {
+			startDate = DateUtil.date(startTime);
 		}
-		if (StrUtil.isNotBlank(end)) {
-			end = DateUtil.formatDate(new Date(Long.parseLong(end))) + " 23:59:59";
+		if (endTime != null) {
+			endDate = DateUtil.date(endTime);
 		}
-		if (StrUtil.isBlank(start)) {
-			start = DateUtil.beginOfDay(DateTime.now()).toString();
+		if (startDate == null) {
+			startDate = DateUtil.beginOfDay(DateTime.now());
 		}
-		if (StrUtil.isBlank(end)) {
-			start = DateUtil.endOfDay(DateTime.now()).toString();
+		if (endDate == null) {
+			endDate = DateUtil.offsetDay(startDate, 1);
 		}
-		formService.exportQuestionInfo(promotionId, start, end, response);
+		formService.exportQuestionInfo(promotionId, startDate, endDate, response);
 	}
 }