SmartFamilyIndexController.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.template.controller;
  2. import com.template.api.SmartFamilyIndexControllerAPI;
  3. import com.template.model.pojo.SmartFamilyIndex;
  4. import com.template.model.result.CommonResult;
  5. import com.template.services.SmartFamilyIndexService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import java.util.Optional;
  12. import java.util.stream.Collectors;
  13. /**
  14. * <p>
  15. * 楼栋表 前端控制器
  16. * </p>
  17. *
  18. * @author ceshi
  19. * @since 2024-04-23
  20. */
  21. @RestController
  22. public class SmartFamilyIndexController implements SmartFamilyIndexControllerAPI {
  23. @Autowired
  24. private SmartFamilyIndexService smartFamilyIndexService;
  25. @Override
  26. public CommonResult exitsData() {
  27. List<SmartFamilyIndex> familys = smartFamilyIndexService.list(null);
  28. List<String> studentNos = familys.stream().map(SmartFamilyIndex::getStudentNo).distinct().collect(Collectors.toList());
  29. List<Integer> deleteIds = new ArrayList<>();
  30. for (String data : studentNos) {
  31. List<SmartFamilyIndex> datas = familys.stream().filter(e -> e.getStudentNo().equals(data)).collect(Collectors.toList());
  32. if (datas.size() > 1) {
  33. if (datas.get(0).getParentPhone().equals(datas.get(1).getParentPhone())) {
  34. Optional<SmartFamilyIndex> firstData = datas.stream().filter(e -> e.getIndexData().intValue() == 1).findFirst();
  35. if (firstData != null && firstData.isPresent()) {
  36. deleteIds.add(firstData.get().getId());
  37. }
  38. }
  39. }
  40. }
  41. if(deleteIds != null && deleteIds.size() > 0){
  42. int deleteDatas = smartFamilyIndexService.deleteSmartFamilyByIds(deleteIds);
  43. if(deleteDatas <= 0){
  44. return CommonResult.fail("操作失败");
  45. }
  46. }
  47. return CommonResult.ok("操作成功");
  48. }
  49. }