ysh 3 年之前
父节点
当前提交
674fd6e02b

+ 49 - 12
jeecg-boot-module-demo/src/main/java/org/jeecg/modules/geke/userShift/controller/UserShiftController.java

@@ -13,6 +13,7 @@ import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.geke.userShift.entity.UserShift;
+import org.jeecg.modules.geke.userShift.entity.UserShiftExcel;
 import org.jeecg.modules.geke.userShift.entity.UserShiftVo;
 import org.jeecg.modules.geke.userShift.service.IUserShiftService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -173,18 +174,54 @@ public class UserShiftController extends JeecgController<UserShift, IUserShiftSe
       return super.exportXls(request, userShift, UserShift.class, "员工排班");
   }
 
-  /**
-   * 通过excel导入数据
-   *
-   * @param request
-   * @param response
-   * @return
-   */
-  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
-  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
-      return super.importExcel(request, response, UserShift.class);
-  }
-
+	  /**
+	   * 通过excel导入数据
+	   *
+	   * @param request
+	   * @param response
+	   * @return
+	   */
+	  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+	  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+		  MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+		  Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+		  for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+			  MultipartFile file = entity.getValue();// 获取上传文件对象
+			  ImportParams params = new ImportParams();
+			  params.setTitleRows(2);
+			  params.setHeadRows(1);
+			  params.setNeedSave(true);
+			  try {
+				  List<UserShiftExcel> list = ExcelImportUtil.importExcel(file.getInputStream(), UserShiftExcel.class, params);
+				  for(UserShiftExcel o:list){
+					  System.out.println(o.getWorkNo());
+					  System.out.println(o.getName());
+					  System.out.println(o.getA1());
+					  System.out.println(o.getA2());
+					  System.out.println(o.getA3());
+					  System.out.println(o.getA4());
+					  System.out.println(o.getA5());
+				  }
+				  //update-begin-author:taoyan date:20190528 for:批量插入数据
+				  long start = System.currentTimeMillis();
+				  //400条 saveBatch消耗时间1592毫秒  循环插入消耗时间1947毫秒
+				  //1200条  saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
+				  log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
+				  //update-end-author:taoyan date:20190528 for:批量插入数据
+				  return Result.ok("文件导入成功!数据行数:" + list.size());
+			  } catch (Exception e) {
+				  log.error(e.getMessage(), e);
+				  return Result.error("文件导入失败:" + e.getMessage());
+			  } finally {
+				  try {
+					  file.getInputStream().close();
+				  } catch (IOException e) {
+					  e.printStackTrace();
+				  }
+			  }
+		  }
+		  return Result.error("文件导入失败!");
+	  }
 
 
 	 @GetMapping(value = "/UserShiftType")

+ 45 - 0
jeecg-boot-module-demo/src/main/java/org/jeecg/modules/geke/userShift/entity/UserShiftExcel.java

@@ -0,0 +1,45 @@
+package org.jeecg.modules.geke.userShift.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.jeecgframework.poi.excel.annotation.ExcelTarget;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ExcelTarget("userShiftExcel")
+public class UserShiftExcel implements java.io.Serializable {
+
+	@Excel(name = "工号", width = 15)
+	private String workNo;
+
+	@Excel(name = "姓名", width = 15)
+	private String name;
+
+	@Excel(name = "1号", width = 15)
+	private String a1;
+
+	@Excel(name = "2号", width = 15)
+	private String a2;
+
+	@Excel(name = "3号", width = 15)
+	private String a3;
+
+	@Excel(name = "4号", width = 15)
+	private String a4;
+
+	@Excel(name = "5号", width = 15)
+	private String a5;
+
+}