DzSchoolController.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package com.ruoyi.web.controller.dz;
  2. import java.util.List;
  3. import java.util.Map;
  4. import java.util.Objects;
  5. import java.util.stream.Collectors;
  6. import java.util.stream.Stream;
  7. import javax.servlet.http.HttpServletResponse;
  8. import cn.hutool.core.collection.CollectionUtil;
  9. import com.ruoyi.common.utils.StringUtils;
  10. import com.ruoyi.system.domain.SysArea;
  11. import com.ruoyi.system.service.ISysAreaService;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.PutMapping;
  17. import org.springframework.web.bind.annotation.DeleteMapping;
  18. import org.springframework.web.bind.annotation.PathVariable;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import com.ruoyi.common.annotation.Log;
  23. import com.ruoyi.common.core.controller.BaseController;
  24. import com.ruoyi.common.core.domain.AjaxResult;
  25. import com.ruoyi.common.enums.BusinessType;
  26. import com.ruoyi.dz.domain.DzSchool;
  27. import com.ruoyi.dz.service.IDzSchoolService;
  28. import com.ruoyi.common.utils.poi.ExcelUtil;
  29. import com.ruoyi.common.core.page.TableDataInfo;
  30. /**
  31. * 机构校区Controller
  32. *
  33. * @author ruoyi
  34. * @date 2025-09-12
  35. */
  36. @RestController
  37. @RequestMapping("/dz/school")
  38. public class DzSchoolController extends BaseController
  39. {
  40. @Autowired
  41. private IDzSchoolService dzSchoolService;
  42. @Autowired
  43. private ISysAreaService areaService;
  44. /**
  45. * 查询机构校区列表
  46. */
  47. @PreAuthorize("@ss.hasPermi('dz:school:list')")
  48. @GetMapping("/list")
  49. public TableDataInfo list(DzSchool dzSchool)
  50. {
  51. startPage();
  52. List<DzSchool> list= dzSchoolService.selectDzSchoolList(dzSchool);
  53. //处理省市区
  54. List<Long> areaIds = list.stream()
  55. .flatMap(school -> Stream.of(
  56. school.getPro(),school.getCity(),school.getArea()
  57. ))
  58. .filter(Objects::nonNull).distinct().collect(Collectors.toList());
  59. if (CollectionUtil.isNotEmpty(areaIds)){
  60. Map<Long, SysArea> areaMap = areaService.selectSysAreaListByIds(areaIds)
  61. .stream().collect(Collectors.toMap(SysArea::getAreaId,area -> area));
  62. list.forEach(school -> {
  63. StringBuilder proCityAreaName = new StringBuilder();
  64. if (null!=school.getPro()&&areaMap.containsKey(school.getPro())){
  65. proCityAreaName.append(areaMap.get(school.getPro()).getAreaName());
  66. }
  67. if (null!=school.getCity()&&areaMap.containsKey(school.getCity())){
  68. proCityAreaName.append(areaMap.get(school.getCity()).getAreaName());
  69. }
  70. if (null!=school.getArea()&&areaMap.containsKey(school.getArea())){
  71. proCityAreaName.append(areaMap.get(school.getArea()).getAreaName());
  72. }
  73. if (StringUtils.isNotEmpty(proCityAreaName.toString())){
  74. school.setProCityAreaName(proCityAreaName.toString());
  75. }
  76. });
  77. }
  78. return getDataTable(list);
  79. }
  80. @GetMapping("/getCampusList")
  81. public AjaxResult getCampusList(DzSchool dzSchool)
  82. {
  83. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  84. return AjaxResult.success(list);
  85. }
  86. @GetMapping("/getSchoolList")
  87. public AjaxResult getSchoolList(DzSchool dzSchool)
  88. {
  89. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  90. return AjaxResult.success(list);
  91. }
  92. /**
  93. * 导出机构校区列表
  94. */
  95. @PreAuthorize("@ss.hasPermi('dz:school:export')")
  96. @Log(title = "机构校区", businessType = BusinessType.EXPORT)
  97. @PostMapping("/export")
  98. public void export(HttpServletResponse response, DzSchool dzSchool)
  99. {
  100. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  101. ExcelUtil<DzSchool> util = new ExcelUtil<DzSchool>(DzSchool.class);
  102. util.exportExcel(response, list, "机构校区数据");
  103. }
  104. /**
  105. * 获取机构校区详细信息
  106. */
  107. @PreAuthorize("@ss.hasPermi('dz:school:query')")
  108. @GetMapping(value = "/{id}")
  109. public AjaxResult getInfo(@PathVariable("id") Long id)
  110. {
  111. return success(dzSchoolService.selectDzSchoolById(id));
  112. }
  113. /**
  114. * 新增机构校区
  115. */
  116. @PreAuthorize("@ss.hasPermi('dz:school:add')")
  117. @Log(title = "机构校区", businessType = BusinessType.INSERT)
  118. @PostMapping
  119. public AjaxResult add(@RequestBody DzSchool dzSchool)
  120. {
  121. return toAjax(dzSchoolService.insertDzSchool(dzSchool));
  122. }
  123. /**
  124. * 修改机构校区
  125. */
  126. @PreAuthorize("@ss.hasPermi('dz:school:edit')")
  127. @Log(title = "机构校区", businessType = BusinessType.UPDATE)
  128. @PutMapping
  129. public AjaxResult edit(@RequestBody DzSchool dzSchool)
  130. {
  131. return toAjax(dzSchoolService.updateDzSchool(dzSchool));
  132. }
  133. /**
  134. * 删除机构校区
  135. */
  136. @PreAuthorize("@ss.hasPermi('dz:school:remove')")
  137. @Log(title = "机构校区", businessType = BusinessType.DELETE)
  138. @DeleteMapping("/{ids}")
  139. public AjaxResult remove(@PathVariable Long[] ids)
  140. {
  141. return toAjax(dzSchoolService.deleteDzSchoolByIds(ids));
  142. }
  143. }