ManagementTeacherController.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package com.ruoyi.web.controller.info;
  2. import java.net.MalformedURLException;
  3. import java.net.URL;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6. import java.util.Collections;
  7. import java.util.List;
  8. import java.util.Set;
  9. import java.util.stream.Collectors;
  10. import javax.annotation.Resource;
  11. import javax.servlet.http.HttpServletResponse;
  12. import javax.validation.constraints.NotEmpty;
  13. import javax.validation.constraints.NotNull;
  14. import org.springframework.validation.annotation.Validated;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.PathVariable;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.RequestBody;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import com.ruoyi.common.annotation.Log;
  22. import com.ruoyi.common.annotation.RepeatSubmit;
  23. import com.ruoyi.common.core.controller.BaseController;
  24. import com.ruoyi.common.core.domain.PageQuery;
  25. import com.ruoyi.common.core.domain.R;
  26. import com.ruoyi.common.core.page.TableDataInfo;
  27. import com.ruoyi.common.core.validate.AddGroup;
  28. import com.ruoyi.common.core.validate.EditGroup;
  29. import com.ruoyi.common.core.validate.QueryGroup;
  30. import com.ruoyi.common.enums.BusinessType;
  31. import com.ruoyi.common.enums.FilePathSplicingType;
  32. import com.ruoyi.common.filepathsplicing.FilePathSplicing;
  33. import com.ruoyi.common.filepathsplicing.FilePathSplicingUtil;
  34. import com.ruoyi.common.utils.BeanCopyUtils;
  35. import com.ruoyi.common.utils.CollectionUtils;
  36. import com.ruoyi.common.utils.poi.ExcelUtil;
  37. import com.ruoyi.info.hospital.domain.vo.HospitalDepartmentVo;
  38. import com.ruoyi.info.hospital.domain.vo.HospitalVo;
  39. import com.ruoyi.info.hospital.service.IHospitalDepartmentService;
  40. import com.ruoyi.info.hospital.service.IHospitalService;
  41. import com.ruoyi.info.management.domain.TeacherDepartmentRel;
  42. import com.ruoyi.info.management.domain.bo.ManagementTeacherBo;
  43. import com.ruoyi.info.management.domain.bo.ManagementTeacherPageReqBo;
  44. import com.ruoyi.info.management.domain.vo.ManagementTeacherVo;
  45. import com.ruoyi.info.management.service.IManagementTeacherService;
  46. import com.ruoyi.info.management.service.ITeacherDepartmentRelService;
  47. import com.ruoyi.info.nursing.domain.bo.EnableStatusBo;
  48. import cn.dev33.satoken.annotation.SaCheckPermission;
  49. import cn.hutool.core.collection.CollUtil;
  50. import cn.hutool.core.util.StrUtil;
  51. import io.swagger.annotations.Api;
  52. import io.swagger.annotations.ApiOperation;
  53. import io.swagger.annotations.ApiParam;
  54. import lombok.RequiredArgsConstructor;
  55. import static com.ruoyi.common.utils.CollectionUtils.*;
  56. /**
  57. * 管理老师信息Controller
  58. *
  59. * @author baifc
  60. * @date 2025-09-30
  61. */
  62. @Validated
  63. @Api(value = "管理老师信息控制器", tags = {"管理老师信息管理"})
  64. @RequiredArgsConstructor
  65. @RestController
  66. @RequestMapping("/info/managementTeacher")
  67. public class ManagementTeacherController extends BaseController {
  68. private final IManagementTeacherService iManagementTeacherService;
  69. private final FilePathSplicingUtil filePathSplicingUtil;
  70. private final ITeacherDepartmentRelService iTeacherDepartmentRelService;
  71. private final IHospitalService iHospitalService;
  72. private final IHospitalDepartmentService iHospitalDepartmentService;
  73. /**
  74. * 分页查询管理老师信息列表
  75. */
  76. @FilePathSplicing(type = FilePathSplicingType.RESPONSE)
  77. @ApiOperation("查询管理老师信息列表")
  78. @SaCheckPermission("info:managementTeacher:list")
  79. @GetMapping("/page")
  80. public TableDataInfo<ManagementTeacherVo> page(ManagementTeacherPageReqBo bo, PageQuery pageQuery) {
  81. return iManagementTeacherService.queryPageList(bo, pageQuery);
  82. }
  83. /**
  84. * 获取管理老师信息详细信息
  85. */
  86. @FilePathSplicing(type = FilePathSplicingType.RESPONSE)
  87. @ApiOperation("获取管理老师信息详细信息")
  88. @SaCheckPermission("info:managementTeacher:query")
  89. @GetMapping("/info/{id}")
  90. public R<ManagementTeacherVo> getInfo(@ApiParam("主键")
  91. @NotNull(message = "主键不能为空")
  92. @PathVariable("id") Long id) {
  93. ManagementTeacherVo managementTeacherVo = iManagementTeacherService.queryById(id);
  94. // 获取管理老师关联的医院和科室信息
  95. List<TeacherDepartmentRel> teacherDepartmentRelList = iTeacherDepartmentRelService.queryByTeacherId(id);
  96. if (CollUtil.isEmpty(teacherDepartmentRelList)) {
  97. return R.ok(managementTeacherVo);
  98. }
  99. // 处理老师关联的医院和科室信息
  100. Set<Long> hospitalIds = convertSet(teacherDepartmentRelList, TeacherDepartmentRel::getHospitalId);
  101. List<HospitalVo> hospitalList = iHospitalService.queryListByIds(hospitalIds);
  102. List<ManagementTeacherVo.HospitalSimpleInfo> hospitalSimpleInfoList = BeanCopyUtils.copyList(hospitalList, ManagementTeacherVo.HospitalSimpleInfo.class);
  103. // 科室信息
  104. for (ManagementTeacherVo.HospitalSimpleInfo hospitalSimpleInfo : hospitalSimpleInfoList) {
  105. Set<Long> departmentIds = teacherDepartmentRelList.stream()
  106. .filter(rel -> rel.getHospitalId().equals(hospitalSimpleInfo.getId()))
  107. .map(TeacherDepartmentRel::getDepartmentId)
  108. .collect(Collectors.toSet());
  109. // 获取关联部门详情
  110. List<ManagementTeacherVo.DepartmentSimpleInfo> departmentSimpleInfoList =
  111. BeanCopyUtils.copyList(iHospitalDepartmentService.queryListByIds(departmentIds), ManagementTeacherVo.DepartmentSimpleInfo.class);
  112. hospitalSimpleInfo.setDepartmentList(departmentSimpleInfoList);
  113. }
  114. managementTeacherVo.setHospitalRelList(hospitalSimpleInfoList);
  115. return R.ok(managementTeacherVo);
  116. }
  117. /**
  118. * 新增管理老师信息
  119. */
  120. @FilePathSplicing(type = FilePathSplicingType.REQUEST)
  121. @ApiOperation("新增管理老师信息")
  122. @SaCheckPermission("info:managementTeacher:add")
  123. @Log(title = "管理老师信息", businessType = BusinessType.INSERT)
  124. @RepeatSubmit()
  125. @PostMapping("/add")
  126. public R<Void> add(@Validated(AddGroup.class) @RequestBody ManagementTeacherBo bo) {
  127. return toAjax(iManagementTeacherService.insertByBo(bo) ? 1 : 0);
  128. }
  129. /**
  130. * 修改管理老师信息
  131. */
  132. @FilePathSplicing(type = FilePathSplicingType.REQUEST)
  133. @ApiOperation("修改管理老师信息")
  134. @SaCheckPermission("info:managementTeacher:edit")
  135. @Log(title = "管理老师信息", businessType = BusinessType.UPDATE)
  136. @RepeatSubmit()
  137. @PostMapping("/edit")
  138. public R<Void> edit(@Validated(EditGroup.class) @RequestBody ManagementTeacherBo bo) {
  139. return toAjax(iManagementTeacherService.updateByBo(bo) ? 1 : 0);
  140. }
  141. /**
  142. * 启用/禁用 管理老师
  143. */
  144. @ApiOperation("启用/禁用 管理老师")
  145. @SaCheckPermission("info:managementTeacher:edit")
  146. @Log(title = "管理老师信息", businessType = BusinessType.UPDATE)
  147. @RepeatSubmit()
  148. @PostMapping("/update-status")
  149. public R<Void> updateStatus(@Validated @RequestBody EnableStatusBo bo) {
  150. iManagementTeacherService.updateStatus(bo);
  151. return R.ok();
  152. }
  153. /**
  154. * 删除管理老师信息
  155. */
  156. @ApiOperation("删除管理老师信息")
  157. @SaCheckPermission("info:managementTeacher:remove")
  158. @Log(title = "管理老师信息", businessType = BusinessType.DELETE)
  159. @PostMapping("/del/{ids}")
  160. public R<Void> remove(@ApiParam("主键串")
  161. @NotEmpty(message = "主键不能为空")
  162. @PathVariable Long[] ids) {
  163. return toAjax(iManagementTeacherService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
  164. }
  165. /**
  166. * 导出管理老师信息列表
  167. */
  168. @ApiOperation("导出管理老师信息列表")
  169. @SaCheckPermission("info:managementTeacher:export")
  170. @Log(title = "管理老师信息", businessType = BusinessType.EXPORT)
  171. @PostMapping("/export")
  172. public void export(ManagementTeacherPageReqBo bo, HttpServletResponse response) throws MalformedURLException {
  173. List<ManagementTeacherVo> list = iManagementTeacherService.queryList(bo);
  174. // 处理图片
  175. for (ManagementTeacherVo managementTeacherVo : list) {
  176. String url = managementTeacherVo.getPhotographUrl();
  177. if (StrUtil.isNotEmpty(url) && !url.startsWith("http")) {
  178. managementTeacherVo.setPhotograph(new URL(filePathSplicingUtil.getPrefix() + url));
  179. }
  180. }
  181. ExcelUtil.exportExcel(list, "管理老师信息", ManagementTeacherVo.class, response);
  182. }
  183. }