DzSchoolController.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 javax.validation.ValidationException;
  9. import cn.hutool.core.collection.CollectionUtil;
  10. import com.ruoyi.common.enums.BoolValues;
  11. import com.ruoyi.common.utils.SecurityUtils;
  12. import com.ruoyi.common.utils.StringUtils;
  13. import com.ruoyi.dz.domain.DzClasses;
  14. import com.ruoyi.dz.service.IDzClassesService;
  15. import com.ruoyi.dz.service.impl.DzClassesServiceImpl;
  16. import com.ruoyi.enums.UserTypeEnum;
  17. import com.ruoyi.system.domain.SysArea;
  18. import com.ruoyi.system.service.ISysAreaService;
  19. import org.springframework.security.access.prepost.PreAuthorize;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.GetMapping;
  22. import org.springframework.web.bind.annotation.PostMapping;
  23. import org.springframework.web.bind.annotation.PutMapping;
  24. import org.springframework.web.bind.annotation.DeleteMapping;
  25. import org.springframework.web.bind.annotation.PathVariable;
  26. import org.springframework.web.bind.annotation.RequestBody;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RestController;
  29. import com.ruoyi.common.annotation.Log;
  30. import com.ruoyi.common.core.controller.BaseController;
  31. import com.ruoyi.common.core.domain.AjaxResult;
  32. import com.ruoyi.common.enums.BusinessType;
  33. import com.ruoyi.dz.domain.DzSchool;
  34. import com.ruoyi.dz.service.IDzSchoolService;
  35. import com.ruoyi.common.utils.poi.ExcelUtil;
  36. import com.ruoyi.common.core.page.TableDataInfo;
  37. /**
  38. * 机构校区Controller
  39. *
  40. * @author ruoyi
  41. * @date 2025-09-12
  42. */
  43. @RestController
  44. @RequestMapping("/dz/school")
  45. public class DzSchoolController extends BaseController
  46. {
  47. @Autowired
  48. private IDzSchoolService dzSchoolService;
  49. @Autowired
  50. private ISysAreaService areaService;
  51. @Autowired
  52. private IDzClassesService classesService;
  53. /**
  54. * 查询机构校区列表
  55. */
  56. @PreAuthorize("@ss.hasPermi('dz:school:list')")
  57. @GetMapping("/list")
  58. public TableDataInfo list(DzSchool dzSchool)
  59. {
  60. // if (null==dzSchool.getDeptId()){
  61. // dzSchool.setDeptId(getLoginUser().getDeptId());
  62. // }
  63. // if(!UserTypeEnum.Sys.getVal().equals(SecurityUtils.getLoginUser().getUser().getUserType())) {
  64. // dzSchool.setCampus(true);
  65. // }else {
  66. // dzSchool.setCampus(false);
  67. // }
  68. startPage();
  69. List<DzSchool> list= dzSchoolService.selectDzSchoolList(dzSchool);
  70. //处理省市区
  71. List<Long> areaIds = list.stream()
  72. .flatMap(school -> Stream.of(
  73. school.getPro(),school.getCity(),school.getArea()
  74. ))
  75. .filter(Objects::nonNull).distinct().collect(Collectors.toList());
  76. if (CollectionUtil.isNotEmpty(areaIds)){
  77. Map<Long, SysArea> areaMap = areaService.selectSysAreaListByIds(areaIds)
  78. .stream().collect(Collectors.toMap(SysArea::getAreaId,area -> area));
  79. list.forEach(school -> {
  80. StringBuilder proCityAreaName = new StringBuilder();
  81. if (null!=school.getPro()&&areaMap.containsKey(school.getPro())){
  82. proCityAreaName.append(areaMap.get(school.getPro()).getAreaName());
  83. }
  84. if (null!=school.getCity()&&areaMap.containsKey(school.getCity())){
  85. proCityAreaName.append(areaMap.get(school.getCity()).getAreaName());
  86. }
  87. if (null!=school.getArea()&&areaMap.containsKey(school.getArea())){
  88. proCityAreaName.append(areaMap.get(school.getArea()).getAreaName());
  89. }
  90. if (StringUtils.isNotEmpty(proCityAreaName.toString())){
  91. school.setProCityAreaName(proCityAreaName.toString());
  92. }
  93. });
  94. }
  95. return getDataTable(list);
  96. }
  97. @GetMapping("/getCampusSchoolList")
  98. public AjaxResult getCampusSchoolList(DzSchool dzSchool)
  99. {
  100. if(null == dzSchool.getCampus() && !UserTypeEnum.isSys(SecurityUtils.getLoginUser().getUser().getUserType())) {
  101. dzSchool.setCampus(true);
  102. }
  103. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  104. return AjaxResult.success(list);
  105. }
  106. // @GetMapping("/getSchoolList")
  107. // public AjaxResult getSchoolList(DzSchool dzSchool)
  108. // {
  109. // if(!UserTypeEnum.Sys.getVal().equals(SecurityUtils.getLoginUser().getUser().getUserType())) {
  110. // dzSchool.setCampus(false);
  111. // }
  112. // List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  113. // return AjaxResult.success(list);
  114. // }
  115. @GetMapping("/getSchoolList")
  116. public AjaxResult getSchoolList(DzSchool dzSchool)
  117. {
  118. // if(!UserTypeEnum.Sys.getVal().equals(SecurityUtils.getLoginUser().getUser().getUserType())) {
  119. // dzSchool.setCampus(true);
  120. // }else {
  121. // dzSchool.setCampus(false);
  122. // }
  123. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  124. return AjaxResult.success(list);
  125. }
  126. /**
  127. * 导出机构校区列表
  128. */
  129. @PreAuthorize("@ss.hasPermi('dz:school:export')")
  130. @Log(title = "机构校区", businessType = BusinessType.EXPORT)
  131. @PostMapping("/export")
  132. public void export(HttpServletResponse response, DzSchool dzSchool)
  133. {
  134. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  135. ExcelUtil<DzSchool> util = new ExcelUtil<DzSchool>(DzSchool.class);
  136. util.exportExcel(response, list, "机构校区数据");
  137. }
  138. /**
  139. * 获取机构校区详细信息
  140. */
  141. @PreAuthorize("@ss.hasPermi('dz:school:query')")
  142. @GetMapping(value = "/{id}")
  143. public AjaxResult getInfo(@PathVariable("id") Long id)
  144. {
  145. return success(dzSchoolService.selectDzSchoolById(id));
  146. }
  147. /**
  148. * 新增机构校区
  149. */
  150. @PreAuthorize("@ss.hasPermi('dz:school:add')")
  151. @Log(title = "机构校区", businessType = BusinessType.INSERT)
  152. @PostMapping
  153. public AjaxResult add(@RequestBody DzSchool dzSchool)
  154. {
  155. int id = dzSchoolService.insertDzSchool(dzSchool);
  156. //创建学校时,如果没有班级则默认创建30个班级
  157. for (int i = 0; i < 30; i++) {
  158. DzClasses dzClass = new DzClasses();
  159. dzClass.setSchoolId(Long.valueOf(id));
  160. dzClass.setName( String.valueOf(i + 1));
  161. dzClass.setIsDefault(BoolValues.yes.getValue());
  162. dzClass.setOnline(BoolValues.yes.getValue());
  163. dzClass.setStatus(BoolValues.yes.getValue());
  164. classesService.insertDzClasses(dzClass);
  165. }
  166. return toAjax(id);
  167. }
  168. /**
  169. * 修改机构校区
  170. */
  171. @PreAuthorize("@ss.hasPermi('dz:school:edit')")
  172. @Log(title = "机构校区", businessType = BusinessType.UPDATE)
  173. @PutMapping
  174. public AjaxResult edit(@RequestBody DzSchool dzSchool)
  175. {
  176. return toAjax(dzSchoolService.updateDzSchool(dzSchool));
  177. }
  178. /**
  179. * 删除机构校区
  180. */
  181. @PreAuthorize("@ss.hasPermi('dz:school:remove')")
  182. @Log(title = "机构校区", businessType = BusinessType.DELETE)
  183. @DeleteMapping("/{ids}")
  184. public AjaxResult remove(@PathVariable Long[] ids)
  185. {
  186. return toAjax(dzSchoolService.deleteDzSchoolByIds(ids));
  187. }
  188. }