FileService.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by FernFlower decompiler)
  4. //
  5. package ieven.server.webapp.domain.file;
  6. import cn.hutool.core.date.DateUtil;
  7. import cn.hutool.core.io.FileUtil;
  8. import cn.hutool.core.io.IoUtil;
  9. import cn.hutool.core.util.IdUtil;
  10. import cn.hutool.poi.excel.ExcelReader;
  11. import cn.hutool.poi.excel.ExcelUtil;
  12. import com.mongodb.client.gridfs.model.GridFSFile;
  13. import com.mongodb.client.result.DeleteResult;
  14. import com.opencsv.CSVReader;
  15. import ieven.server.webapp.domain.IdInput;
  16. import ieven.server.webapp.domain.data.DataMap;
  17. import ieven.server.webapp.domain.data.Fields;
  18. import ieven.server.webapp.domain.model.Model;
  19. import ieven.server.webapp.infrastructure.wrapper.Mapped;
  20. import ieven.server.webapp.service.MongoExcelService;
  21. import ieven.server.webapp.util.EncodeDetector;
  22. import ieven.server.webapp.util.FileUtils;
  23. import ieven.server.webapp.util.excel.ExcelXlsReader;
  24. import ieven.server.webapp.util.excel.ExcelXlsxReader;
  25. import ieven.server.webapp.util.excel.PublicStatic;
  26. import info.monitorenter.cpdetector.io.*;
  27. import lombok.extern.slf4j.Slf4j;
  28. import org.apache.commons.csv.CSVFormat;
  29. import org.apache.commons.csv.CSVParser;
  30. import org.apache.commons.csv.CSVRecord;
  31. import org.apache.commons.lang3.StringUtils;
  32. import org.apache.poi.ss.usermodel.Sheet;
  33. import org.bson.types.ObjectId;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.beans.factory.annotation.Value;
  36. import org.springframework.context.annotation.Lazy;
  37. import org.springframework.data.domain.Sort;
  38. import org.springframework.data.domain.Sort.Order;
  39. import org.springframework.data.mongodb.core.MongoTemplate;
  40. import org.springframework.data.mongodb.core.query.Criteria;
  41. import org.springframework.data.mongodb.core.query.Query;
  42. import org.springframework.data.mongodb.core.query.Update;
  43. import org.springframework.data.mongodb.gridfs.GridFsOperations;
  44. import org.springframework.data.mongodb.gridfs.GridFsResource;
  45. import org.springframework.data.mongodb.gridfs.GridFsTemplate;
  46. import org.springframework.scheduling.annotation.Async;
  47. import org.springframework.scheduling.annotation.AsyncResult;
  48. import org.springframework.scheduling.annotation.EnableAsync;
  49. import org.springframework.stereotype.Service;
  50. import org.springframework.web.multipart.MultipartFile;
  51. import java.io.*;
  52. import java.nio.charset.Charset;
  53. import java.util.ArrayList;
  54. import java.util.Arrays;
  55. import java.util.List;
  56. import java.util.concurrent.*;
  57. import java.util.regex.Pattern;
  58. import java.util.stream.Collectors;
  59. @Service
  60. @EnableAsync
  61. @Slf4j
  62. public class FileService {
  63. @Value("${spring.data.fileExportPath}")
  64. private String fileUploadPath;
  65. String[] order1 = {"反诈数据-订单明细", "反诈数据-订单明细2", "治安数据-订单明细", "经侦数据-订单明细", "网黑数据-订单明细", "反诈治安-交易明细", "反诈治安-账户透视", "反诈治安-对手透视"};
  66. String[] order2 = {
  67. "五联单-注册信息",
  68. "经侦云-注册信息",
  69. "五联单-登录日志",
  70. "五联单-交易记录",
  71. "五联单-账户明细",
  72. "经侦云-账户明细",
  73. "五联单-转账明细",
  74. "五联单-转账分析",
  75. "五联单-账户透视",
  76. "五联单-对手透视",
  77. "五联单-IP地址分析",
  78. "五联单-收货地址分析"
  79. };
  80. String[] order3 = {"财付通-注册信息", "财付通-订单明细1", "财付通-订单明细2","财付通-商户订单", "财付通-交易明细", "财付通-账户透视", "财付通-对手透视", "财付通-手机明细"};
  81. String[] order4 = {"数据分析-主体信息汇总", "数据分析-账户透视", "数据分析-对手透视", "数据分析-共同关系网络"};
  82. @Autowired
  83. private GridFsTemplate gridFsTemplate;
  84. @Autowired
  85. private MongoTemplate mongoTemplate;
  86. @Autowired
  87. private GridFsOperations fsOperations;
  88. @Autowired
  89. @Lazy
  90. private FileService fileService;
  91. public FileService() {
  92. }
  93. public static String getCharsetName(File file) throws IOException {
  94. String charsetName = "UTF-8";
  95. // 获取 CodepageDetectorProxy 实例
  96. CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
  97. // 添加解析器,会使用到添加的后 2 个 ext 里的 jar 包
  98. detector.add(new ParsingDetector(false));
  99. detector.add(JChardetFacade.getInstance());
  100. detector.add(ASCIIDetector.getInstance());
  101. detector.add(UnicodeDetector.getInstance());
  102. Charset charset = detector.detectCodepage(file.toURI().toURL());
  103. if (charset != null) {
  104. charsetName = charset.name();
  105. }
  106. return charsetName;
  107. }
  108. public static void main(String[] args) throws IOException {
  109. File file =
  110. new File(
  111. "C:\\Users\\Administrator\\Desktop\\楼\\支付宝五联单数据格式\\20120303组织卖淫案_OR222713D2400411_注册信息_20210913100124.csv");
  112. String charsetName = getCharsetName(file);
  113. CSVParser csvParser =
  114. CSVFormat.EXCEL.parse(new InputStreamReader(new FileInputStream(file), charsetName));
  115. for (CSVRecord strings : csvParser) {
  116. System.out.println(strings);
  117. }
  118. file = new File("C:\\Users\\Administrator\\Desktop\\楼\\微信支付账单(2).csv");
  119. charsetName = getCharsetName(file);
  120. csvParser =
  121. CSVFormat.EXCEL.parse(new InputStreamReader(new FileInputStream(file), charsetName));
  122. for (CSVRecord strings : csvParser) {
  123. System.out.println(strings);
  124. }
  125. }
  126. public Mapped storeUploaded(
  127. InputStream inputStream, String encoding, String filename, String contentType, String modelId) {
  128. ObjectId objectId;
  129. objectId = this.gridFsTemplate.store(inputStream, filename, contentType);
  130. Query query =
  131. new Query(
  132. Criteria.where("modelId")
  133. .is(modelId)
  134. .and("filename")
  135. .is(filename));
  136. List<LogicalFile> existsFileList = this.mongoTemplate.find(query, LogicalFile.class);
  137. if (existsFileList != null && existsFileList.size() > 0) {
  138. return Mapped.OK();
  139. }
  140. LogicalFile logicalFile = new LogicalFile();
  141. logicalFile.setFilename(filename);
  142. logicalFile.setUploadDate(DateUtil.now());
  143. logicalFile.setModelId(modelId);
  144. logicalFile.setGridId(objectId);
  145. logicalFile.setGenerated(Boolean.FALSE);
  146. logicalFile.setStatus("LOADING");
  147. logicalFile = this.mongoTemplate.insert(logicalFile);
  148. this.readFile(logicalFile, encoding);
  149. return Mapped.OK();
  150. }
  151. @Async
  152. public void readFile(LogicalFile uploaded, String encoding) {
  153. GridFSFile fsFile =
  154. this.fsOperations.findOne(new Query(Criteria.where("_id").is(uploaded.getGridId())));
  155. if (fsFile == null) {
  156. this.modifyStatus(uploaded.getId(), "ERROR");
  157. } else {
  158. GridFsResource resource = this.fsOperations.getResource(fsFile);
  159. String filename = resource.getFilename();
  160. if (StringUtils.isBlank(filename)) {
  161. this.modifyStatus(uploaded.getId(), "ERROR");
  162. } else {
  163. try {
  164. InputStream inputStream = resource.getInputStream();
  165. MongoExcelService mongoExcelService;
  166. if (filename.endsWith(".xlsx")) {
  167. mongoExcelService = new MongoExcelService(this.mongoTemplate, uploaded.getId());
  168. ExcelXlsxReader reader = new ExcelXlsxReader(mongoExcelService);
  169. reader.processStream(inputStream);
  170. mongoExcelService.insertRest();
  171. } else if (filename.endsWith(".xls")) {
  172. mongoExcelService = new MongoExcelService(this.mongoTemplate, uploaded.getId());
  173. ExcelXlsReader reader = new ExcelXlsReader(mongoExcelService);
  174. reader.processStream(inputStream);
  175. mongoExcelService.insertRest();
  176. } else if (filename.endsWith(".csv")) {
  177. mongoExcelService = new MongoExcelService(this.mongoTemplate, uploaded.getId());
  178. log.info("encoding2:{}", encoding);
  179. /*CSVParser csvParser = null;
  180. if (encoding.equalsIgnoreCase("UTF-8")) {
  181. csvParser = CSVFormat.EXCEL.parse(new InputStreamReader(inputStream, "utf-8"));
  182. } else {
  183. csvParser = CSVFormat.EXCEL.parse(new InputStreamReader(inputStream));
  184. }*/
  185. int curRow = 0;
  186. int curRowWxFile = 0;
  187. boolean wxFile = false;
  188. String nickname = ""; // 微信手机账单文件 添加一列 微信昵称 需要单独处理
  189. try (CSVReader reader = new CSVReader(new InputStreamReader(inputStream))) {
  190. List<String[]> lines = reader.readAll();
  191. for (String[] line : lines) {
  192. log.info("record,{}", line);
  193. List<String> strings = Arrays.asList(line);
  194. List<String> strings2 = new ArrayList<>();
  195. strings2.addAll(strings);
  196. /************* 此处内容一下均为处理微信账单表头 ****************/
  197. String join = String.join("", strings);
  198. join = PublicStatic.removeAllSpecial(join);
  199. if (join.equals("微信支付账单明细")) {
  200. wxFile = true;
  201. }
  202. if (wxFile && curRowWxFile < 16) {
  203. if (curRowWxFile == 1) {
  204. String temp = strings.get(0);
  205. if (StringUtils.isNotBlank(temp)) {
  206. nickname = temp.replace("微信昵称:[", "").replace("]", "");
  207. }
  208. }
  209. curRowWxFile++;
  210. continue;
  211. }
  212. if (wxFile && curRowWxFile > 16) {
  213. strings2.add(0, nickname);
  214. curRowWxFile++;
  215. }
  216. if (wxFile && curRowWxFile == 16) {
  217. strings2.add(0, "微信昵称");
  218. curRowWxFile++;
  219. }
  220. /************* 此处内容以上均为处理微信账单表头 ****************/
  221. mongoExcelService.getRows(
  222. 0,
  223. curRow,
  224. strings2.stream()
  225. .map(PublicStatic::removeAllSpecial)
  226. .collect(Collectors.toList())
  227. );
  228. curRow++;
  229. }
  230. } catch (Exception e) {
  231. e.printStackTrace();
  232. }
  233. mongoExcelService.insertRest();
  234. } else if (filename.endsWith(".txt")) {
  235. mongoExcelService = new MongoExcelService(this.mongoTemplate, uploaded.getId());
  236. List<String> lines = new ArrayList<>();
  237. IoUtil.readLines(new InputStreamReader(inputStream, "utf-8"), lines);
  238. int curRow = 0;
  239. for (String string : lines) {
  240. if (string.equals("注销信息")) {
  241. break;
  242. }
  243. List<String> values = Arrays.asList(string.split("\t"));
  244. if (values.size() <= 1) {
  245. continue;
  246. }
  247. mongoExcelService.getRows(
  248. 0,
  249. curRow,
  250. values.stream().map(PublicStatic::removeAllSpecial).collect(Collectors.toList())
  251. );
  252. curRow++;
  253. }
  254. mongoExcelService.insertRest();
  255. }
  256. } catch (Exception var11) {
  257. this.modifyStatus(uploaded.getId(), "ERROR");
  258. var11.printStackTrace();
  259. }
  260. this.modifyStatus(uploaded.getId(), "FINISHED");
  261. }
  262. }
  263. }
  264. private void modifyStatus(String id, String status) {
  265. Query query = new Query();
  266. query.addCriteria(Criteria.where("_id").is(id));
  267. Update update = new Update();
  268. update.set("status", status);
  269. this.mongoTemplate.updateFirst(query, update, "logical_file");
  270. }
  271. public Mapped listGroupUploaded(FileListInput fileListInput) {
  272. String modelId = fileListInput.getModelId();
  273. if (modelId == null) {
  274. return Mapped.ERROR("没有选择任何分组");
  275. } else {
  276. Query query =
  277. new Query(Criteria.where("modelId").is(modelId).and("generated").is(Boolean.TRUE));
  278. query.with(Sort.by(Order.desc("uploadDate")));
  279. List<LogicalFile> resultList = this.mongoTemplate.find(query, LogicalFile.class);
  280. // 将文件 按照 反诈 财付通 五联单 进行分类
  281. List<GroupLogincalFile> groupLogincalFiles = new ArrayList<>();
  282. groupLogicalFile("反诈治安数据分析", new String[]{"反诈", "治安", "经侦数据", "网黑"}, resultList, groupLogincalFiles);
  283. groupLogicalFile("支付宝数据分析", new String[]{"五联单", "经侦云"}, resultList, groupLogincalFiles);
  284. groupLogicalFile("财付通数据分析", new String[]{"财付通"}, resultList, groupLogincalFiles);
  285. groupLogicalFile("数据综合分析", new String[]{"数据分析"}, resultList, groupLogincalFiles);
  286. Mapped res = Mapped.OK();
  287. res.put("code", 200);
  288. res.put("result", groupLogincalFiles);
  289. return res;
  290. }
  291. }
  292. public void groupLogicalFile(
  293. String groupName,
  294. String[] group,
  295. List<LogicalFile> logicalFileList,
  296. List<GroupLogincalFile> groupLogincalFiles) {
  297. List<LogicalFile> children = new ArrayList<>();
  298. for (String s : group) {
  299. children.addAll(
  300. logicalFileList.stream()
  301. .filter(t -> t.getFilename().startsWith(s))
  302. .collect(Collectors.toList()));
  303. }
  304. if (children != null && children.size() > 0) {
  305. GroupLogincalFile groupLogincalFile = new GroupLogincalFile();
  306. groupLogincalFile.setGroupName(groupName);
  307. groupLogincalFile.setId(IdUtil.randomUUID());
  308. groupLogincalFile.setChildren(orderGroupLogicalFile(groupName, children));
  309. groupLogincalFiles.add(groupLogincalFile);
  310. }
  311. }
  312. public List<LogicalFile> orderGroupLogicalFile(String groupName, List<LogicalFile> list) {
  313. if (groupName.equals("反诈治安数据分析")) {
  314. return orderGroupLogicalFileChild(order1, list);
  315. }
  316. if (groupName.equals("支付宝数据分析")) {
  317. return orderGroupLogicalFileChild(order2, list);
  318. }
  319. if (groupName.equals("财付通数据分析")) {
  320. return orderGroupLogicalFileChild(order3, list);
  321. }
  322. if (groupName.equals("数据综合分析")) {
  323. return orderGroupLogicalFileChild(order4, list);
  324. }
  325. return null;
  326. }
  327. public List<LogicalFile> orderGroupLogicalFileChild(String[] orders, List<LogicalFile> list) {
  328. List<LogicalFile> child = new ArrayList<>();
  329. for (String s : orders) {
  330. for (LogicalFile logicalFile : list) {
  331. if (logicalFile.getFilename().equals(s)) {
  332. if ("数据分析-共同关系网络".equals(logicalFile.getFilename())) {
  333. logicalFile.setFileType("map");
  334. }
  335. child.add(logicalFile);
  336. break;
  337. }
  338. }
  339. }
  340. return child;
  341. }
  342. public Mapped listUploaded(FileListInput fileListInput) {
  343. String modelId = fileListInput.getModelId();
  344. if (modelId == null) {
  345. return Mapped.ERROR("没有选择任何分组");
  346. } else {
  347. String generated = fileListInput.getGenerated();
  348. String fileName = fileListInput.getFileName();
  349. Future<Long> longFuture = this.fileService.countTotalByModelId(modelId, generated);
  350. Future<String> modelNameFuture = this.fileService.retrieveModelname(modelId);
  351. int page = fileListInput.getPage();
  352. int pageSize = fileListInput.getPageSize();
  353. int skip = (page - 1) * pageSize;
  354. Criteria criteria = Criteria.where("modelId").is(modelId);
  355. if ("true".equals(generated)) {
  356. criteria.and("generated").is(Boolean.TRUE);
  357. } else if ("false".equals(generated)) {
  358. criteria.and("generated").is(Boolean.FALSE);
  359. }
  360. if (fileName != null && !fileName.isEmpty()) {
  361. // 使用正则表达式进行模糊匹配,i 表示不区分大小写
  362. Pattern pattern = Pattern.compile(".*" + Pattern.quote(fileName) + ".*", Pattern.CASE_INSENSITIVE);
  363. criteria.and("filename").regex(pattern);
  364. }
  365. // 创建查询对象并执行查询
  366. Query query = new Query(criteria)
  367. .with(Sort.by(Sort.Direction.DESC, "uploadDate")) // 保留排序逻辑
  368. .skip(skip)
  369. .limit(pageSize);
  370. List<LogicalFile> resultList =
  371. this.mongoTemplate.find(query, LogicalFile.class);
  372. Long total;
  373. try {
  374. total = longFuture.get();
  375. } catch (ExecutionException | InterruptedException var17) {
  376. return Mapped.ERROR("查询出错");
  377. }
  378. String modelName;
  379. try {
  380. modelName = modelNameFuture.get();
  381. } catch (ExecutionException | InterruptedException var17) {
  382. return Mapped.ERROR("查询出错");
  383. }
  384. int i = skip;
  385. for (LogicalFile file : resultList) {
  386. ++i;
  387. file.setCount(i);
  388. file.setModelName(modelName);
  389. }
  390. Mapped res = Mapped.OK();
  391. res.put("code", 200);
  392. res.put("result", resultList);
  393. res.put("total", total);
  394. res.put("page", page);
  395. res.put("pageSize", pageSize);
  396. return res;
  397. }
  398. }
  399. public Mapped deleteById(IdInput idInput) {
  400. String id = idInput.getId();
  401. Query query = new Query(Criteria.where("id").is(id));
  402. LogicalFile file = this.mongoTemplate.findOne(query, LogicalFile.class);
  403. if (file != null && file.getGridId() != null) {
  404. String physicalId = file.getGridId().toHexString();
  405. this.fileService.removePhysicalFile(physicalId);
  406. }
  407. this.fileService.removeDataByFileId(id);
  408. this.fileService.removeFieldsByFileId(id);
  409. DeleteResult result = this.mongoTemplate.remove(query, LogicalFile.class);
  410. return result.getDeletedCount() > 0L ? Mapped.OK() : Mapped.ERROR("删除失败");
  411. }
  412. @Async
  413. Future<Long> countTotalByModelId(String modelId, String generated) {
  414. Criteria criteria = Criteria.where("modelId").is(modelId);
  415. if ("true".equals(generated)) {
  416. criteria.and("generated").is(Boolean.TRUE);
  417. } else if ("false".equals(generated)) {
  418. criteria.and("generated").is(Boolean.FALSE);
  419. }
  420. Long total = this.mongoTemplate.count(new Query(criteria), LogicalFile.class);
  421. return new AsyncResult(total);
  422. }
  423. @Async
  424. public void removePhysicalFile(String id) {
  425. this.fsOperations.delete(new Query(Criteria.where("_id").is(id)));
  426. }
  427. @Async
  428. public void removeLogicalFile(String fileId) {
  429. this.mongoTemplate.remove(new Query(Criteria.where("id").is(fileId)), LogicalFile.class);
  430. }
  431. @Async
  432. public void removeDataByFileId(String fileId) {
  433. this.mongoTemplate.remove(new Query(Criteria.where("fileId").is(fileId)), DataMap.class);
  434. }
  435. @Async
  436. public void removeFieldsByFileId(String fileId) {
  437. this.mongoTemplate.remove(new Query(Criteria.where("fileId").is(fileId)), Fields.class);
  438. }
  439. @Async
  440. Future<String> retrieveModelname(String modelId) {
  441. Query query = new Query(Criteria.where("id").is(modelId));
  442. query.fields().include("modelName");
  443. Model model = this.mongoTemplate.findOne(query, Model.class, "model");
  444. return new AsyncResult(model != null ? model.getModelName() : "");
  445. }
  446. public Mapped uploadFilesAndSave(List<MultipartFile> multipartFiles, String modelId) {
  447. List<String> failNameList = new ArrayList<>();
  448. for (int i = 0; i < multipartFiles.size(); i++) {
  449. MultipartFile multipartFile = multipartFiles.get(i);
  450. String originName = multipartFile.getOriginalFilename();
  451. String suffix = originName.substring(originName.lastIndexOf(".") + 1);
  452. String prefix = originName.substring(0, originName.lastIndexOf("."));
  453. String savedName = prefix + "(" + (i + 1) + ")." + suffix;
  454. String filepath = fileUploadPath + File.separator + modelId + File.separator + savedName;
  455. FileUtils.uploadFile(multipartFile, filepath);
  456. MultipartFile multipartFile1 = FileUtils.getMultipartFile(new File(filepath));
  457. try {
  458. ExecutorService executor = Executors.newSingleThreadExecutor();
  459. Future<Mapped> future = executor.submit(new Callable<Mapped>() {
  460. @Override
  461. public Mapped call() throws Exception {
  462. return uploadSingle(multipartFile1, modelId);
  463. }
  464. });
  465. // 在这里,主线程会等待 future 的结果
  466. Mapped mapped = future.get(); // 这将会阻塞,直到Callable任务完成
  467. if (200 != Integer.valueOf(String.valueOf(mapped.get("code")))) {
  468. failNameList.add(savedName + ":" + String.valueOf(mapped.get("message")));
  469. }
  470. //删除文件
  471. FileUtils.deleteFile(filepath);
  472. } catch (Exception e) {
  473. e.printStackTrace();
  474. }
  475. }
  476. Mapped mapped = Mapped.OK();
  477. mapped.put("failNameList", failNameList);
  478. return mapped;
  479. }
  480. public Mapped uploadSingle(MultipartFile file, String modelId)
  481. throws Exception {
  482. String filename = file.getOriginalFilename();
  483. String extName = FileUtil.extName(filename);
  484. String contentType = file.getContentType();
  485. ByteArrayOutputStream baos = FileUtils.cloneInputStream(file.getInputStream());
  486. if (extName.equalsIgnoreCase("xls") || extName.equalsIgnoreCase("xlsx")) {
  487. ExcelReader reader = ExcelUtil.getReader(new ByteArrayInputStream(baos.toByteArray()));
  488. List<Sheet> sheets = reader.getSheets();
  489. List<String> headers = new ArrayList<>();
  490. for (Sheet sheet : sheets) {
  491. reader.setSheet(sheet);
  492. List<Object> objects = reader.readRow(0);
  493. if (objects.size() > 1) { // 至少大于1
  494. StringBuilder stringBuilder = new StringBuilder();
  495. for (Object object : objects) {
  496. stringBuilder.append(object);
  497. }
  498. headers.add(stringBuilder.toString());
  499. }
  500. }
  501. if (headers.size() > 1) {
  502. // 判断sheet第一行内容是否一致
  503. StringBuilder errorHeaders = new StringBuilder();
  504. String baseHeader = headers.get(0);
  505. for (int i = 0; i < headers.size(); i++) {
  506. //
  507. if (i == 0) {
  508. continue;
  509. }
  510. if (!headers.get(i).equals(baseHeader)) {
  511. errorHeaders.append("sheet").append(i).append("标题列与第一个sheet不一致!");
  512. }
  513. }
  514. if (errorHeaders.length() > 0) {
  515. return Mapped.ERROR(errorHeaders.toString());
  516. }
  517. }
  518. reader.close();
  519. }
  520. String encoding = EncodeDetector.getEncoding(baos.toByteArray());
  521. baos.close();
  522. return this.fileService.storeUploaded(
  523. new ByteArrayInputStream(baos.toByteArray()), encoding, filename, contentType, modelId);
  524. }
  525. }