RepairConsumeController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. package com.repair.controller;
  2. import com.repair.api.RepairConsumeControllerAPI;
  3. import com.repair.common.utils.ExcelExportUtil;
  4. import com.repair.common.utils.ExcelUtils;
  5. import com.repair.common.utils.TimeExchange;
  6. import com.repair.common.utils.paramUtils;
  7. import com.repair.model.enumModel.eFileType;
  8. import com.repair.model.pojo.RepairArticleType;
  9. import com.repair.model.pojo.RepairConsume;
  10. import com.repair.model.request.insertRepairAssociationRequest;
  11. import com.repair.model.request.insertRepairConsumeRequest;
  12. import com.repair.model.request.updateRepairConsumeRequest;
  13. import com.repair.model.result.CommonResult;
  14. import com.repair.model.result.PageUtils;
  15. import com.repair.model.vo.*;
  16. import com.repair.services.RepairAreaService;
  17. import com.repair.services.RepairArticleTypeService;
  18. import com.repair.services.RepairConsumeService;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.apache.poi.hssf.usermodel.HSSFRow;
  21. import org.apache.poi.hssf.usermodel.HSSFSheet;
  22. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  23. import org.apache.poi.ss.usermodel.DataFormatter;
  24. import org.apache.poi.ss.usermodel.Workbook;
  25. import org.apache.poi.xssf.usermodel.XSSFRow;
  26. import org.apache.poi.xssf.usermodel.XSSFSheet;
  27. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.validation.BindingResult;
  30. import org.springframework.web.bind.annotation.RestController;
  31. import org.springframework.web.multipart.MultipartFile;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.io.IOException;
  34. import java.io.InputStream;
  35. import java.lang.reflect.InvocationTargetException;
  36. import java.math.BigDecimal;
  37. import java.util.*;
  38. import java.util.stream.Collectors;
  39. /**
  40. * <p>
  41. * 前端控制器
  42. * </p>
  43. *
  44. * @author ceshi
  45. * @since 2023-07-18
  46. */
  47. @RestController
  48. public class RepairConsumeController implements RepairConsumeControllerAPI {
  49. @Autowired
  50. private RepairAreaService repairAreaService;
  51. @Autowired
  52. private RepairConsumeService repairConsumeService;
  53. @Autowired
  54. private RepairArticleTypeService repairArticleTypeService;
  55. /**
  56. * 关联耗材中添加耗材
  57. * @param irc 耗材数据
  58. * @param bindingResult 是否为空判断
  59. * @return
  60. */
  61. @Override
  62. public CommonResult InsertRepairAssociation(insertRepairAssociationRequest irc, BindingResult bindingResult) {
  63. if (bindingResult.hasErrors()) {
  64. String st = paramUtils.getParamError(bindingResult);
  65. return CommonResult.fail(st);
  66. }
  67. RepairConsume data = repairConsumeService.queryConsumeByName(irc.getName(), irc.getSchoolId());
  68. if (data != null) {
  69. return CommonResult.fail("该报修耗材已存在!");
  70. }
  71. RepairConsume rc = new RepairConsume()
  72. .setName(irc.getName())
  73. .setSchoolId(irc.getSchoolId())
  74. .setArticleId(irc.getArticleId())
  75. .setPrice(new BigDecimal(0));
  76. int result = repairConsumeService.insertRepairConsume(rc);
  77. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  78. }
  79. /**
  80. * 新增耗材数据
  81. * @param ircr 耗材数据
  82. * @param bindingResult 是否为空判断
  83. * @return
  84. */
  85. @Override
  86. public CommonResult InsertRepairConsume(insertRepairConsumeRequest ircr, BindingResult bindingResult) {
  87. if (bindingResult.hasErrors()) {
  88. String st = paramUtils.getParamError(bindingResult);
  89. return CommonResult.fail(st);
  90. }
  91. RepairConsume data = repairConsumeService.queryConsumeByName(ircr.getName(), ircr.getSchoolId());
  92. if (data != null) {
  93. return CommonResult.fail("该报修耗材已存在!");
  94. }
  95. RepairConsume rc = new RepairConsume()
  96. .setName(ircr.getName())
  97. .setSchoolId(ircr.getSchoolId())
  98. .setArticleId(StringUtils.join(ircr.getArticleIds(), ','))
  99. .setPrice(ircr.getPrice())
  100. .setContent(ircr.getContent());
  101. int result = repairConsumeService.insertRepairConsume(rc);
  102. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  103. }
  104. /**
  105. * 根据数据ID修改耗材数据
  106. * @param urcr 耗材数据
  107. * @param bindingResult 是否为空判断
  108. * @return
  109. */
  110. @Override
  111. public CommonResult updateRepairConsumeById(updateRepairConsumeRequest urcr, BindingResult bindingResult) {
  112. if (bindingResult.hasErrors()) {
  113. String st = paramUtils.getParamError(bindingResult);
  114. return CommonResult.fail(st);
  115. }
  116. RepairConsume data = repairConsumeService.queryConsumeByName(urcr.getName(), urcr.getSchoolId());
  117. if (data != null && !data.getId().equals(urcr.getId())) {
  118. return CommonResult.fail("该报修耗材已存在!");
  119. }
  120. RepairConsume rc = new RepairConsume()
  121. .setId(urcr.getId())
  122. .setSchoolId(urcr.getSchoolId())
  123. .setName(urcr.getName())
  124. .setArticleId(StringUtils.join(urcr.getArticleIds(), ','))
  125. .setPrice(urcr.getPrice())
  126. .setContent(urcr.getContent());
  127. int result = repairConsumeService.updateRepairConsume(rc);
  128. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  129. }
  130. /**
  131. * 耗材管理分页数据查询
  132. * @param currentPage 当前页数
  133. * @param pageCount 一页数据条数
  134. * @param name 耗材名称
  135. * @param startTime 起始时间
  136. * @param endTime 结束时间
  137. * @return
  138. */
  139. @Override
  140. public CommonResult queryPageRepairConsumes(int currentPage, int pageCount, String name, String startTime, String endTime) {
  141. if (startTime != null && endTime != null) {
  142. try {
  143. startTime = TimeExchange.getStartOfDayStr(TimeExchange.StringToDate(startTime, "yyyy-MM-dd"));
  144. endTime = TimeExchange.getEndOfDayStr(TimeExchange.StringToDate(endTime, "yyyy-MM-dd"));
  145. } catch (Exception e) {
  146. }
  147. }
  148. PageUtils<RepairConsumeVo> result = repairConsumeService.queryPageRepairConsumes(currentPage, pageCount, name, startTime, endTime);
  149. for (RepairConsumeVo r : result.getList()) {
  150. if (r.getArticleId() != null) {
  151. r.setArticleIds(Arrays.asList(r.getArticleId().split(",")));
  152. }
  153. if (r.getArticleName() != null) {
  154. r.setArticleNames(Arrays.asList(r.getArticleName().split(",")));
  155. }
  156. }
  157. return CommonResult.ok(result);
  158. }
  159. /**
  160. * 根据数据ID删除耗材数据
  161. * @param id 数据ID
  162. * @return
  163. */
  164. @Override
  165. public CommonResult deleteRepairConsumeById(int id) {
  166. RepairConsume data = repairConsumeService.getRepairById(id);
  167. if (data == null) {
  168. return CommonResult.fail("当前数据不存在,删除失败!");
  169. }
  170. int result = repairConsumeService.deleteRepairConsumeById(id);
  171. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  172. }
  173. /**
  174. * 耗材数据导出
  175. * @param name 耗材名称
  176. * @param startTime 起始时间
  177. * @param endTime 结束时间
  178. * @param response 文件响应流
  179. * @throws NoSuchMethodException
  180. * @throws InstantiationException
  181. * @throws IllegalAccessException
  182. * @throws InvocationTargetException
  183. */
  184. @Override
  185. public void downloadRepairConsumeExcel(String name, String startTime, String endTime, HttpServletResponse response) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
  186. Map<String, String> map = new HashMap<>();
  187. //表头与键值对的映射关系
  188. map.put("id", "数据ID");
  189. map.put("name", "耗材名称");
  190. map.put("schoolName", "校区名称");
  191. map.put("price", "耗材单价");
  192. map.put("artileName", "物品类型");
  193. map.put("entryName", "录入人员");
  194. map.put("updateTimeStr", "录入时间");
  195. if (startTime != null && endTime != null) {
  196. try {
  197. startTime = TimeExchange.getStartOfDayStr(TimeExchange.StringToDate(startTime, "yyyy-MM-dd"));
  198. endTime = TimeExchange.getEndOfDayStr(TimeExchange.StringToDate(endTime, "yyyy-MM-dd"));
  199. } catch (Exception e) {
  200. }
  201. }
  202. List<ConsumeVo> datas = repairConsumeService.queryConsumeList(name, startTime, endTime);
  203. List<String> orderList = new ArrayList<>();
  204. orderList.add("id");
  205. orderList.add("name");
  206. orderList.add("schoolName");
  207. orderList.add("price");
  208. orderList.add("artileName");
  209. orderList.add("entryName");
  210. orderList.add("updateTimeStr");
  211. //导出逻辑 这里的list是从导入里面哪来的 map1与map不一样 orderList这里为空
  212. Workbook workbook = ExcelExportUtil.createWorkbook(datas, map, 1, "耗材管理表", orderList);
  213. ExcelUtils.excelDownload(workbook, "耗材管理.xlsx", response);
  214. }
  215. /**
  216. * 耗材模板数据导出
  217. * @param response 文件响应流
  218. */
  219. @Override
  220. public void downloadRepairConsumeModelExcel(HttpServletResponse response) {
  221. ExcelUtils.fileDownload("/耗材管理模板.xlsx", response);
  222. }
  223. /**
  224. * 耗材数据导入
  225. * @param file 导入文件
  226. * @return
  227. * @throws IOException
  228. */
  229. @Override
  230. public CommonResult importRepairConsumeExcel(MultipartFile file) throws IOException {
  231. if (file.isEmpty() || file.getSize() == 0) {
  232. return CommonResult.fail("导入文件不能为空");
  233. }
  234. String ContentType = file.getContentType();
  235. InputStream inputStream = file.getInputStream();
  236. List<RepairConsume> result = new ArrayList<>();
  237. //xls格式文件
  238. if (ContentType.equals(eFileType.Xls.getValue())) {
  239. CommonResult<List<RepairConsume>> resultData = readXls(inputStream);
  240. if (!resultData.isSuccess()) {
  241. return resultData;
  242. }
  243. result = resultData.getData();
  244. } else if (ContentType.equals(eFileType.Xlsx.getValue())) {
  245. CommonResult<List<RepairConsume>> resultData = readXlsx(inputStream);
  246. if (!resultData.isSuccess()) {
  247. return resultData;
  248. }
  249. result = resultData.getData();
  250. } else {
  251. return CommonResult.fail("耗材数据导入只支持Xls、Xlsx");
  252. }
  253. boolean resultBool = repairConsumeService.saveBatch(result);
  254. return resultBool ? CommonResult.ok("导入成功") : CommonResult.fail("导入失败");
  255. }
  256. /**
  257. * 导入Xls文件方法
  258. * @param inputStream
  259. * @return
  260. * @throws IOException
  261. */
  262. private CommonResult<List<RepairConsume>> readXls(InputStream inputStream) throws IOException {
  263. HSSFWorkbook sheets = new HSSFWorkbook(inputStream);
  264. List<RepairConsume> result = new ArrayList<>();
  265. List<String> ConsumeNames = new ArrayList<>();
  266. //读取第一张sheet
  267. HSSFSheet sheetAt = sheets.getSheetAt(0);
  268. //获取校区数据
  269. List<RepairSchoolVo> schools = repairAreaService.queryRepairSchools();
  270. //报修物品
  271. List<RepairArticleType> articles = repairArticleTypeService.getRepairArticleTypes();
  272. //耗材数据
  273. List<RepairConsume> consumes = repairConsumeService.getConsumes();
  274. DataFormatter dataFormatter = new DataFormatter();
  275. try {
  276. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  277. for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  278. HSSFRow row = sheetAt.getRow(rowNum);
  279. if (rowNum == 1) {
  280. String name = dataFormatter.formatCellValue(row.getCell(0));//耗材名称
  281. if (!name.equals("名称")) {
  282. return CommonResult.fail("导入数据第一列为名称");
  283. }
  284. String schoolName = dataFormatter.formatCellValue(row.getCell(1));//校区名称
  285. if (!schoolName.equals("校区")) {
  286. return CommonResult.fail("导入数据第二列为校区");
  287. }
  288. String ArticleName = dataFormatter.formatCellValue(row.getCell(2));//报修物品类别
  289. if (!ArticleName.equals("类别")) {
  290. return CommonResult.fail("导入数据第三列为类别");
  291. }
  292. String price = dataFormatter.formatCellValue(row.getCell(3));//耗材单价
  293. if (!price.equals("价格(元)")) {
  294. return CommonResult.fail("导入数据第四列为价格");
  295. }
  296. } else {
  297. RepairConsume data = new RepairConsume();
  298. //耗材名称
  299. String name = dataFormatter.formatCellValue(row.getCell(0));
  300. ConsumeNames.add(name);
  301. if (ConsumeNames.stream().distinct().count() != ConsumeNames.size()) {
  302. return CommonResult.fail("导入的Excel中" + name + "存在重复数据");
  303. }
  304. data.setName(name);
  305. //校区
  306. String schoolName = dataFormatter.formatCellValue(row.getCell(1));
  307. Optional<RepairSchoolVo> school = schools.stream().filter(e -> e.getName().equals(schoolName)).findFirst();
  308. if (school != null && school.isPresent()) {
  309. data.setSchoolId(school.get().getId());
  310. } else {
  311. return CommonResult.fail(name + "的" + schoolName + "校区数据在数据库中不存在");
  312. }
  313. //重复数据提示
  314. long exist = consumes.stream().filter(e -> e.getSchoolId().equals(school.get().getId()) && e.getName().equals(name)).count();
  315. if (exist > 0) {
  316. return CommonResult.fail(schoolName + "的" + name + "耗材数据在系统中已存在,请勿重复导入");
  317. }
  318. //报修物品(类别)
  319. String article = dataFormatter.formatCellValue(row.getCell(2));
  320. String[] articleStrs = null;
  321. if (article.contains("、")) {
  322. articleStrs = article.split("、");
  323. } else if (article.contains(",")) {
  324. articleStrs = article.split(",");
  325. } else {
  326. articleStrs = new String[1];
  327. articleStrs[0] = article;
  328. }
  329. List<String> ass = new ArrayList<>();
  330. for (String as : articleStrs) {
  331. if (!as.equals("")) {
  332. Optional<RepairArticleType> shiftData = articles.stream().filter(e -> e.getName().equals(as) && data.getSchoolId().equals(e.getSchoolId())).findFirst();
  333. if (shiftData != null && shiftData.isPresent()) {
  334. ass.add(shiftData.get().getId().toString());
  335. } else {
  336. return CommonResult.fail(name + "的" + as + "数据不存在");
  337. }
  338. }
  339. data.setArticleId(StringUtils.join(ass, ','));
  340. result.add(data);
  341. }
  342. //价格
  343. BigDecimal price = new BigDecimal(String.valueOf(row.getCell(3))).stripTrailingZeros();
  344. data.setPrice(price);
  345. }
  346. }
  347. } catch (Exception e) {
  348. return CommonResult.fail("请按模板格式导入数据");
  349. }
  350. return CommonResult.ok(result);
  351. }
  352. /**
  353. * 导入Xlsx文件方法
  354. * @param inputStream
  355. * @return
  356. * @throws IOException
  357. */
  358. private CommonResult<List<RepairConsume>> readXlsx(InputStream inputStream) throws IOException {
  359. XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
  360. List<RepairConsume> result = new ArrayList<>();
  361. List<String> ConsumeNames = new ArrayList<>();
  362. //读取第一张sheet
  363. XSSFSheet sheetAt = sheets.getSheetAt(0);
  364. //获取校区数据
  365. List<RepairSchoolVo> schools = repairAreaService.queryRepairSchools();
  366. //报修物品
  367. List<RepairArticleType> articles = repairArticleTypeService.getRepairArticleTypes();
  368. //耗材数据
  369. List<RepairConsume> consumes = repairConsumeService.getConsumes();
  370. DataFormatter dataFormatter = new DataFormatter();
  371. try {
  372. //sheetAt.getLastRowNum():从0开始统计数量 所以得+1
  373. for (int rowNum = 1; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
  374. XSSFRow row = sheetAt.getRow(rowNum);
  375. if (rowNum == 1) {
  376. String name = dataFormatter.formatCellValue(row.getCell(0));//耗材名称
  377. if (!name.equals("名称")) {
  378. return CommonResult.fail("导入数据第一列为名称");
  379. }
  380. String schoolName = dataFormatter.formatCellValue(row.getCell(1));//校区名称
  381. if (!schoolName.equals("校区")) {
  382. return CommonResult.fail("导入数据第二列为校区");
  383. }
  384. String ArticleName = dataFormatter.formatCellValue(row.getCell(2));//报修物品类别
  385. if (!ArticleName.equals("类别")) {
  386. return CommonResult.fail("导入数据第三列为类别");
  387. }
  388. String price = dataFormatter.formatCellValue(row.getCell(3));//耗材单价
  389. if (!price.equals("价格(元)")) {
  390. return CommonResult.fail("导入数据第四列为价格");
  391. }
  392. } else {
  393. RepairConsume data = new RepairConsume();
  394. //耗材名称
  395. String name = dataFormatter.formatCellValue(row.getCell(0));
  396. ConsumeNames.add(name);
  397. if (ConsumeNames.stream().distinct().count() != ConsumeNames.size()) {
  398. return CommonResult.fail("导入的Excel中" + name + "存在重复数据");
  399. }
  400. data.setName(name);
  401. //校区
  402. String schoolName = dataFormatter.formatCellValue(row.getCell(1));
  403. Optional<RepairSchoolVo> school = schools.stream().filter(e -> e.getName().equals(schoolName)).findFirst();
  404. if (school != null && school.isPresent()) {
  405. data.setSchoolId(school.get().getId());
  406. } else {
  407. return CommonResult.fail(name + "的" + schoolName + "校区数据在数据库中不存在");
  408. }
  409. //重复数据提示
  410. long exist = consumes.stream().filter(e -> e.getSchoolId().equals(school.get().getId()) && e.getName().equals(name)).count();
  411. if (exist > 0) {
  412. return CommonResult.fail(schoolName + "的" + name + "耗材数据在系统中已存在,请勿重复导入");
  413. }
  414. //报修物品(类别)
  415. String article = dataFormatter.formatCellValue(row.getCell(2));
  416. String[] articleStrs = null;
  417. if (article.contains("、")) {
  418. articleStrs = article.split("、");
  419. } else if (article.contains(",")) {
  420. articleStrs = article.split(",");
  421. } else {
  422. articleStrs = new String[1];
  423. articleStrs[0] = article;
  424. }
  425. List<String> ass = new ArrayList<>();
  426. for (String as : articleStrs) {
  427. if (!as.equals("")) {
  428. Optional<RepairArticleType> shiftData = articles.stream().filter(e -> e.getName().equals(as) && data.getSchoolId().equals(e.getSchoolId())).findFirst();
  429. if (shiftData != null && shiftData.isPresent()) {
  430. ass.add(shiftData.get().getId().toString());
  431. } else {
  432. return CommonResult.fail(name + "的" + as + "数据不存在");
  433. }
  434. }
  435. data.setArticleId(StringUtils.join(ass, ','));
  436. result.add(data);
  437. }
  438. //价格
  439. BigDecimal price = new BigDecimal(dataFormatter.formatCellValue(row.getCell(3)));
  440. data.setPrice(price);
  441. }
  442. }
  443. } catch (Exception e) {
  444. return CommonResult.fail("请按模板格式导入数据");
  445. }
  446. return CommonResult.ok(result);
  447. }
  448. /**
  449. * 根据校区ID和关键字查询耗材二级数据
  450. * @param schoolId 校区ID
  451. * @return
  452. */
  453. @Override
  454. public CommonResult queryRepairConsumesBykey(int schoolId, String keyWord) {
  455. List<RepairArticleType> result = repairArticleTypeService.getRepairArticlesBySchoolId(schoolId);
  456. List<RepairConsume> consumeLists = repairConsumeService.getConsumesByKeyword(schoolId, keyWord);
  457. List<RepairConsumeTreeVo> datas = new ArrayList<>();
  458. for (RepairConsume data:consumeLists) {
  459. RepairConsumeTreeVo treeData = new RepairConsumeTreeVo();
  460. treeData.setName(data.getName());
  461. treeData.setId(data.getId());
  462. treeData.setParentId(Integer.valueOf(data.getArticleId()));
  463. treeData.setPrice(data.getPrice());
  464. treeData.setNumber(1);
  465. treeData.setSchoolId(data.getSchoolId());
  466. Optional<RepairArticleType> article = result.stream().filter(e -> e.getId().toString().equals(data.getArticleId())).findFirst();
  467. if(article != null && article.isPresent()){
  468. treeData.setParentName(article.get().getName());
  469. }
  470. datas.add(treeData);
  471. }
  472. return CommonResult.ok(datas);
  473. }
  474. /**
  475. * 根据校区ID查询耗材树形图结构数据
  476. * @param schoolId 校区ID
  477. * @return
  478. */
  479. @Override
  480. public CommonResult queryRepairConsumeTypeTree(int schoolId) {
  481. List<RepairArticleType> result = repairArticleTypeService.getRepairArticlesBySchoolId(schoolId);
  482. List<RepairConsume> consumeLists = repairConsumeService.getConsumesByKeyword(schoolId, null);
  483. List<RepairConsumeypeTreeVo> datas = new ArrayList<>();
  484. for (RepairArticleType data:result) {
  485. RepairConsumeypeTreeVo newData = new RepairConsumeypeTreeVo().builder()
  486. .id(data.getId())
  487. .schoolId(data.getSchoolId())
  488. .parentId(0)
  489. .price(null)
  490. .name(data.getName())
  491. .build();
  492. List<RepairConsumeypeTreeVo> consumes = QueryArticleTypeTreeRecords(newData.getId(), newData.getName(), consumeLists);
  493. newData.setChildren(consumes);
  494. datas.add(newData);
  495. }
  496. return CommonResult.ok(datas);
  497. }
  498. /**
  499. * 根据父级ID获取树形菜单数据
  500. * @param parentID 父级ID
  501. * @param lists 数据集合
  502. * @return
  503. */
  504. private List<RepairConsumeypeTreeVo> QueryArticleTypeTreeRecords(Integer parentID, String parentName, List<RepairConsume> lists) {
  505. List<RepairConsumeypeTreeVo> newTrees = new ArrayList<>();
  506. List<RepairConsume> datas = lists.stream().filter(e -> e.getArticleId().equals(parentID.toString())).collect(Collectors.toList());
  507. for (RepairConsume data : datas) {
  508. RepairConsumeypeTreeVo item = RepairConsumeypeTreeVo.builder()
  509. .id(data.getId())
  510. .schoolId(data.getSchoolId())
  511. .parentId(Integer.valueOf(data.getArticleId()))
  512. .parentName(parentName)
  513. .price(data.getPrice())
  514. .name(data.getName())
  515. .number(1)
  516. .build();
  517. List<RepairConsumeypeTreeVo> news = QueryArticleTypeTreeRecords(item.getId(), item.getName(), lists);
  518. if (news == null || news.size() == 0) {
  519. newTrees.add(item);
  520. continue;
  521. } else {
  522. item.setChildren(news);
  523. newTrees.add(item);
  524. }
  525. }
  526. return newTrees;
  527. }
  528. }