|
|
@@ -1,10 +1,18 @@
|
|
|
package com.xunmei.core.safetyCheck.controller;
|
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.xunmei.common.core.vo.IdNameVo;
|
|
|
import com.xunmei.core.resumption.dto.resumptionRecord.ResumptionRoleDto;
|
|
|
@@ -12,6 +20,8 @@ import com.xunmei.core.safetyCheck.domain.CoreSafecheckPlan;
|
|
|
import com.xunmei.core.safetyCheck.domain.CoreSafetyTask;
|
|
|
import com.xunmei.core.safetyCheck.service.ICoreSafecheckPlanService;
|
|
|
import com.xunmei.core.safetyCheck.service.ICoreSafetyTaskService;
|
|
|
+import com.xunmei.core.safetyCheck.vo.CoreSafetyTaskExport;
|
|
|
+import com.xunmei.system.api.domain.SysUser;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
@@ -123,4 +133,41 @@ public class CoreSafetyTaskController extends BaseController {
|
|
|
public AjaxResult getNfc(String taskId) {
|
|
|
return success(coreSafetyTaskService.selectNfc(taskId));
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 导出安全检查数据
|
|
|
+ */
|
|
|
+// @RequiresPermissions("core:task:export")
|
|
|
+ @PostMapping("/export")
|
|
|
+ public void export( CoreSafetyTask coreSafetyTask, HttpServletResponse response) {
|
|
|
+ List<CoreSafetyTaskExport> list = null;
|
|
|
+ Set<String> excludeColumnFiledNames = new HashSet<String>();
|
|
|
+ list = coreSafetyTaskService.down(coreSafetyTask);
|
|
|
+ if (ObjectUtil.isEmpty(list)) {
|
|
|
+ throw new RuntimeException("导出数据为空!");
|
|
|
+ }
|
|
|
+ AtomicInteger xh = new AtomicInteger();
|
|
|
+ xh.getAndIncrement();
|
|
|
+ list.forEach(e -> {
|
|
|
+ e.setIndex(xh.getAndIncrement());
|
|
|
+ });
|
|
|
+ if (list.size() > 10000) {
|
|
|
+ throw new RuntimeException("导出数据量过大(单次导出限量10000条数据),请填写条件分批导出");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 设置响应头
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("用户数据", "utf-8"));
|
|
|
+ response.setContentType("application/octet-stream;charset=UTF-8");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ // 数据导出
|
|
|
+ EasyExcel.write(response.getOutputStream(), CoreSafetyTaskExport.class).excludeColumnFiledNames(excludeColumnFiledNames)
|
|
|
+ .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("安全检查数据").doWrite(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 重置response
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/json");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|