DzSchoolController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package com.ruoyi.web.controller.dz;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Map;
  5. import java.util.Objects;
  6. import java.util.stream.Collectors;
  7. import java.util.stream.Stream;
  8. import javax.servlet.http.HttpServletResponse;
  9. import cn.hutool.core.collection.CollectionUtil;
  10. import com.ruoyi.common.core.domain.entity.SysUser;
  11. import com.ruoyi.common.enums.BoolValues;
  12. import com.ruoyi.common.utils.SecurityUtils;
  13. import com.ruoyi.common.utils.StringUtils;
  14. import com.ruoyi.dz.domain.DzClasses;
  15. import com.ruoyi.dz.service.IDzClassesService;
  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.RequestParam;
  29. import org.springframework.web.bind.annotation.RestController;
  30. import com.ruoyi.common.annotation.Log;
  31. import com.ruoyi.common.core.controller.BaseController;
  32. import com.ruoyi.common.core.domain.AjaxResult;
  33. import com.ruoyi.common.enums.BusinessType;
  34. import com.ruoyi.dz.domain.DzSchool;
  35. import com.ruoyi.dz.service.IDzSchoolService;
  36. import com.ruoyi.common.utils.poi.ExcelUtil;
  37. import com.ruoyi.common.core.page.TableDataInfo;
  38. /**
  39. * 机构校区Controller
  40. *
  41. * @author ruoyi
  42. * @date 2025-09-12
  43. */
  44. @RestController
  45. @RequestMapping("/dz/school")
  46. public class DzSchoolController extends BaseController
  47. {
  48. @Autowired
  49. private IDzSchoolService dzSchoolService;
  50. @Autowired
  51. private ISysAreaService areaService;
  52. @Autowired
  53. private IDzClassesService classesService;
  54. /**
  55. * 查询机构校区列表
  56. */
  57. @PreAuthorize("@ss.hasPermi('dz:school:list')")
  58. @GetMapping("/list")
  59. public TableDataInfo list(DzSchool dzSchool)
  60. {
  61. // if (null==dzSchool.getDeptId()){
  62. // dzSchool.setDeptId(getLoginUser().getDeptId());
  63. // }
  64. // if(!UserTypeEnum.Sys.getVal().equals(SecurityUtils.getLoginUser().getUser().getUserType())) {
  65. // dzSchool.setCampus(true);
  66. // }else {
  67. // dzSchool.setCampus(false);
  68. // }
  69. dzSchool.setCampus(false);
  70. if (StringUtils.isNotBlank(dzSchool.getAreaCode())) {
  71. if (dzSchool.getAreaCode().endsWith("0000")) {
  72. dzSchool.setPro(Long.parseLong(dzSchool.getAreaCode()));
  73. } else if (dzSchool.getAreaCode().endsWith("00")) {
  74. dzSchool.setCity(Long.parseLong(dzSchool.getAreaCode()));
  75. } else {
  76. dzSchool.setArea(Long.parseLong(dzSchool.getAreaCode()));
  77. }
  78. }
  79. startPage();
  80. List<DzSchool> list= dzSchoolService.selectDzSchoolList(dzSchool);
  81. //处理省市区
  82. List<Long> areaIds = list.stream()
  83. .flatMap(school -> Stream.of(
  84. school.getPro(),school.getCity(),school.getArea()
  85. ))
  86. .filter(Objects::nonNull).distinct().collect(Collectors.toList());
  87. if (CollectionUtil.isNotEmpty(areaIds)){
  88. Map<Long, SysArea> areaMap = areaService.selectSysAreaListByIds(areaIds)
  89. .stream().collect(Collectors.toMap(SysArea::getAreaId,area -> area));
  90. list.forEach(school -> {
  91. StringBuilder proCityAreaName = new StringBuilder();
  92. if (null!=school.getPro()&&areaMap.containsKey(school.getPro())){
  93. proCityAreaName.append(areaMap.get(school.getPro()).getAreaName());
  94. }
  95. if (null!=school.getCity()&&areaMap.containsKey(school.getCity())){
  96. proCityAreaName.append(areaMap.get(school.getCity()).getAreaName());
  97. }
  98. if (null!=school.getArea()&&areaMap.containsKey(school.getArea())){
  99. proCityAreaName.append(areaMap.get(school.getArea()).getAreaName());
  100. }
  101. if (StringUtils.isNotEmpty(proCityAreaName.toString())){
  102. school.setProCityAreaName(proCityAreaName.toString());
  103. }
  104. });
  105. }
  106. return getDataTable(list);
  107. }
  108. @GetMapping("/getCampusSchoolList")
  109. public AjaxResult getCampusSchoolList(DzSchool dzSchool)
  110. {
  111. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  112. if(null == dzSchool.getCampus() && !UserTypeEnum.isSys(sysUser.getUserType())) {
  113. dzSchool.setCampus(true);
  114. }
  115. if (UserTypeEnum.isSchool(sysUser.getUserType())) {
  116. dzSchool.setId(sysUser.getUserTypeId());
  117. }
  118. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  119. return AjaxResult.success(list);
  120. }
  121. // @GetMapping("/getSchoolList")
  122. // public AjaxResult getSchoolList(DzSchool dzSchool)
  123. // {
  124. // if(!UserTypeEnum.Sys.getVal().equals(SecurityUtils.getLoginUser().getUser().getUserType())) {
  125. // dzSchool.setCampus(false);
  126. // }
  127. // List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  128. // return AjaxResult.success(list);
  129. // }
  130. @GetMapping("/getSchoolList")
  131. public AjaxResult getSchoolList(DzSchool dzSchool)
  132. {
  133. // if(!UserTypeEnum.Sys.getVal().equals(SecurityUtils.getLoginUser().getUser().getUserType())) {
  134. // dzSchool.setCampus(true);
  135. // }else {
  136. // dzSchool.setCampus(false);
  137. // }
  138. dzSchool.setCampus(false);
  139. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  140. return AjaxResult.success(list);
  141. }
  142. /**
  143. * 获取所有学校列表(不分页)
  144. */
  145. @GetMapping("/getAllSchool")
  146. public AjaxResult getAllSchool()
  147. {
  148. DzSchool dzSchool = new DzSchool();
  149. dzSchool.setCampus(false);
  150. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  151. return AjaxResult.success(list);
  152. }
  153. /**
  154. * 导出机构校区列表
  155. */
  156. @PreAuthorize("@ss.hasPermi('dz:school:export')")
  157. @Log(title = "机构校区", businessType = BusinessType.EXPORT)
  158. @PostMapping("/export")
  159. public void export(HttpServletResponse response, DzSchool dzSchool)
  160. {
  161. dzSchool.setCampus(false);
  162. List<DzSchool> list = dzSchoolService.selectDzSchoolList(dzSchool);
  163. ExcelUtil<DzSchool> util = new ExcelUtil<DzSchool>(DzSchool.class);
  164. util.exportExcel(response, list, "机构校区数据");
  165. }
  166. /**
  167. * 获取机构校区详细信息
  168. */
  169. @PreAuthorize("@ss.hasPermi('dz:school:query')")
  170. @GetMapping(value = "/{id}")
  171. public AjaxResult getInfo(@PathVariable("id") Long id)
  172. {
  173. return success(dzSchoolService.selectDzSchoolById(id));
  174. }
  175. /**
  176. * 新增机构校区
  177. */
  178. @PreAuthorize("@ss.hasPermi('dz:school:add')")
  179. @Log(title = "机构校区", businessType = BusinessType.INSERT)
  180. @PostMapping
  181. public AjaxResult add(@RequestBody DzSchool dzSchool)
  182. {
  183. int id = dzSchoolService.insertDzSchool(dzSchool);
  184. //创建学校时,如果没有班级则默认创建30个班级
  185. for (int i = 0; i < 30; i++) {
  186. DzClasses dzClass = new DzClasses();
  187. dzClass.setSchoolId(Long.valueOf(id));
  188. dzClass.setName( String.valueOf(i + 1));
  189. dzClass.setIsDefault(BoolValues.yes.getValue());
  190. dzClass.setOnline(BoolValues.yes.getValue());
  191. dzClass.setStatus(BoolValues.yes.getValue());
  192. classesService.insertDzClasses(dzClass);
  193. }
  194. // generate();
  195. return toAjax(id);
  196. }
  197. private void generate(){
  198. List<Integer> schoolList = Arrays.asList(2,4,8,14,29,30,31,32,33,34,42,43,45,51,54,55,56,66,70,71,73,74,76,77,79,80,86,87,89,91,
  199. 92,93,94,95,97,98,108,110,111,112,114,115,117,118,119,121,122,124,126,127,130,131,132,133,134,135,136,137,138,139,140,142,143,145,146,149,151,153,173,174,175,176,182,183,184,185,186,187,188,189,204,205,206,207,250,251,252,253,254,255,257,262,263,264,265,266,273,274,275,284,358,359,360,361,362,363,364,365,366,376,377,427,428,440,441,452,453,454,455,456,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,480,481,482,483,484,485,486,487,488,489,527,528,555,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,591,592,593,594,595,596,
  200. 597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,668,669,670,671,672,673,674,675,679,680,681,682,683,688,689,690,691,692,723,724,725,726,727,728,732,733,734,735,736,747,748,749,760,761,762,763,764,765,766,784,785,786,787,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,832,833,834,835,836,837,838,839,840,
  201. 841,842,843,847,848,856,857,865,866,867,868,877,878,879,880,881,882,883,884,889,890,906,907,908,909,910,911,920,921,922,923,924,929,930,931,932,933,934,935,936,937,938,939,1000,1001,1002,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1071,1072,1073,1074,1075,1076,1077,1078,1083,1084,1085,1086,1087,1114,1115,1116,1117,1118,1119,1120,1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,1131,1132,1133,1134,1135,1136,1137,1138,1139,1140,1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,1151,1152,1153,1154,1155,1156,1157,1158,1159,1160,1161,1162,1163,1164,1165,
  202. 1166,1167,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1208,1209,1210,1211,1212,1247,1248,1267,1268,1269,1270,1271,1272,1273,1274,1275,1276,1277,1278,1279,1280,1281,1285,1286,1287,1288,1289,1299,1300,1301,1302,1303,1304,1305,1306,1307,1317,1318,1319,1320,1326,1327,1328,1329,1330,1331,1332,1333,1343,1344,1345,1349,1350,1351,1361,1362,1366,1367,1368,1369,1370,1371,1372,1373,1374,1375,1376,1377,1378,1379,1380,1381,1382,1383,1384,1385,1386,
  203. 1387,1388,1389,1390,1391,1392,1393,1394,1395,1396,1397,1398,1399,1400,1401,1402,1417,1430,1439,1440,1447,1448,1452,1453,1454,1455,1473,1474,1475,1476,1477,1478,1479,1480,1481,1482,1483,1484,1485,1486,1487,1488,1489,1490,1491,1492,1493,1494,1495,1595,1596,1597,1598,1599,1600,1601,1602,1603,1620,1621,1622,1623,1624,1625,1639,1640,1641,1642,1643,1644,1645,1646,1647,1648,1649,1650,1651,1652,1653,1654,1655,1656,1657,1658,1659,1660,1661,1662,1663,1664,1665,1666,1667,1668,1669,1670,1671,1672,1673,1674,1675,1683,1684,1685,1686,1687,1688,1689,1723,1724,1725,1727,1728
  204. );
  205. for (Integer id : schoolList) {
  206. for (int i = 0; i < 30; i++) {
  207. DzClasses dzClass = new DzClasses();
  208. dzClass.setSchoolId(Long.valueOf(id));
  209. dzClass.setName( String.valueOf(i + 1));
  210. dzClass.setIsDefault(BoolValues.yes.getValue());
  211. dzClass.setOnline(BoolValues.yes.getValue());
  212. dzClass.setStatus(BoolValues.yes.getValue());
  213. classesService.insertDzClasses(dzClass);
  214. }
  215. }
  216. }
  217. /**
  218. * 修改机构校区
  219. */
  220. @PreAuthorize("@ss.hasPermi('dz:school:edit')")
  221. @Log(title = "机构校区", businessType = BusinessType.UPDATE)
  222. @PutMapping
  223. public AjaxResult edit(@RequestBody DzSchool dzSchool)
  224. {
  225. return toAjax(dzSchoolService.updateDzSchool(dzSchool));
  226. }
  227. /**
  228. * 删除机构校区
  229. */
  230. @PreAuthorize("@ss.hasPermi('dz:school:remove')")
  231. @Log(title = "机构校区", businessType = BusinessType.DELETE)
  232. @DeleteMapping("/{ids}")
  233. public AjaxResult remove(@PathVariable Long[] ids)
  234. {
  235. return toAjax(dzSchoolService.deleteDzSchoolByIds(ids));
  236. }
  237. /**
  238. * 校验学校名称是否唯一
  239. */
  240. @GetMapping("/checkSchoolName")
  241. public AjaxResult checkSchoolName(@RequestParam("name") String name, @RequestParam(value = "id", required = false) Long id)
  242. {
  243. boolean isUnique = dzSchoolService.checkSchoolName(name, id);
  244. return AjaxResult.success(isUnique);
  245. }
  246. }