|
@@ -1,20 +1,23 @@
|
|
|
package com.ruixuan.salesLeads.controller;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.ruixuan.common.core.controller.BaseController;
|
|
|
import com.ruixuan.common.core.domain.AjaxResult;
|
|
|
import com.ruixuan.common.core.domain.ResultResponse;
|
|
|
+import com.ruixuan.common.utils.poi.ExcelUtil;
|
|
|
+import com.ruixuan.salesLeads.listener.ImportExcelListener;
|
|
|
+import com.ruixuan.salesLeads.pojo.SalesleadsInfoPojo;
|
|
|
import com.ruixuan.salesLeads.pojo.TestPojo;
|
|
|
import com.ruixuan.salesLeads.service.ITestService;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import io.swagger.annotations.ApiResponse;
|
|
|
-import io.swagger.annotations.ApiResponses;
|
|
|
+import io.swagger.annotations.*;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -49,4 +52,69 @@ public class DemoController extends BaseController {
|
|
|
return testServiceImpl.selectDemoList();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "导入",notes = "swagger不支持上传,请移步使用postman上传仅支持form-data。")
|
|
|
+ @PostMapping(value = "/importExcel")
|
|
|
+ public ResultResponse importExcel(@ModelAttribute
|
|
|
+ //@ApiParam("wenjianwenjian") @RequestParam("file") MultipartFile file,
|
|
|
+ //@ApiParam("aaa") @RequestParam("aa") String aa,
|
|
|
+ TestPojo testPojo) throws Exception{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //读取Excel
|
|
|
+ EasyExcel.read(testPojo.getFile().getInputStream(),null,
|
|
|
+ new ImportExcelListener()).sheet().headRowNumber(1).doRead();
|
|
|
+
|
|
|
+
|
|
|
+ // 从监听中获取结果集
|
|
|
+ List<Map<String,String>> dataList = ImportExcelListener.importDataList;
|
|
|
+ Map<Integer, String> headList = ImportExcelListener.importHeadList;
|
|
|
+
|
|
|
+ logger.info("--结果shuju---{}",dataList);
|
|
|
+ logger.info("--结果表头---{}",headList);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //System.out.println("--转化--"+SalesleadsInfoPojo.SalesleadsInfoPojoInit(dataList));
|
|
|
+
|
|
|
+ ImportExcelListener.importDataList.clear();
|
|
|
+ ImportExcelListener.importHeadList.clear();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// // 得到Class类对象
|
|
|
+// Class<?> clazz = Class.forName("com.ruixuan.salesLeads.pojo.SalesleadsInfoPojo");
|
|
|
+//
|
|
|
+// // 获取类的所有属性
|
|
|
+// Field[] fields = clazz.getDeclaredFields();
|
|
|
+//
|
|
|
+//
|
|
|
+// Map<String,String> map = new HashMap<>();
|
|
|
+//
|
|
|
+//
|
|
|
+// for (int i = 0; i < headList.size(); i++) {
|
|
|
+//
|
|
|
+//
|
|
|
+// for (Field field : fields) {
|
|
|
+// ApiModelProperty myField2 = field.getAnnotation(ApiModelProperty.class);
|
|
|
+//
|
|
|
+// System.out.println(myField2.value());
|
|
|
+// System.out.println(field.getName());
|
|
|
+//
|
|
|
+// if (headList.containsKey(myField2.value())){
|
|
|
+// System.out.println("包含属性---"+field.getName());
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ //startPage();
|
|
|
+ return ResultResponse.successMsg("cheng.",null);
|
|
|
+ }
|
|
|
+
|
|
|
}
|