XiaoyuanNoticeServiceImpl.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package com.ruoyi.system.service.impl;
  2. import java.util.List;
  3. import java.util.Set;
  4. import com.ruoyi.common.core.domain.entity.FormalParentsStudent;
  5. import com.ruoyi.common.core.domain.entity.FormalTeacherClass;
  6. import com.ruoyi.common.core.domain.entity.SysRole;
  7. import com.ruoyi.common.core.domain.entity.SysUser;
  8. import com.ruoyi.common.core.domain.model.LoginUser;
  9. import com.ruoyi.common.utils.DateUtils;
  10. import com.ruoyi.common.utils.SecurityUtils;
  11. import com.ruoyi.common.utils.ServletUtils;
  12. import com.ruoyi.common.utils.StringUtils;
  13. import com.ruoyi.system.mapper.FormalParentsStudentMapper;
  14. import com.ruoyi.system.mapper.FormalTeacherClassMapper;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import com.ruoyi.system.mapper.XiaoyuanNoticeMapper;
  18. import com.ruoyi.system.domain.XiaoyuanNotice;
  19. import com.ruoyi.system.service.IXiaoyuanNoticeService;
  20. import javax.annotation.Resource;
  21. import static com.ruoyi.common.utils.PageUtils.startPage;
  22. /**
  23. * 校园新闻Service业务层处理
  24. *
  25. * @author boman
  26. * @date 2023-06-05
  27. */
  28. @Service
  29. public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
  30. @Autowired
  31. private XiaoyuanNoticeMapper xiaoyuanNoticeMapper;
  32. @Autowired
  33. private FormalTeacherClassMapper formalTeacherClassMapper;
  34. @Autowired
  35. private FormalParentsStudentMapper formalParentsStudentMapper;
  36. /**
  37. * 查询校园新闻
  38. *
  39. * @param noticeId 校园新闻主键
  40. * @return 校园新闻
  41. */
  42. @Override
  43. public XiaoyuanNotice selectXiaoyuanNoticeByNoticeId(Integer noticeId) {
  44. return xiaoyuanNoticeMapper.selectXiaoyuanNoticeByNoticeId(noticeId);
  45. }
  46. /**
  47. * 查询校园新闻列表
  48. *
  49. * @param xiaoyuanNotice 校园新闻
  50. * @return 校园新闻
  51. */
  52. @Override
  53. public List<XiaoyuanNotice> selectXiaoyuanNoticeList(XiaoyuanNotice xiaoyuanNotice) {
  54. SysUser user = SecurityUtils.getLoginUser().getUser();
  55. xiaoyuanNotice.setSenderId(user.getUserId().toString());
  56. List<SysRole> roles = user.getRoles();
  57. String classId = "0,";
  58. for (SysRole role : roles) {
  59. if ("teacher".equals(role.getRoleKey())) {
  60. FormalTeacherClass formalTeacherClass = new FormalTeacherClass();
  61. formalTeacherClass.setTeacherId(user.getUserId());
  62. List<FormalTeacherClass> formalTeacherClasses = formalTeacherClassMapper.selectFormalTeacherClassList(formalTeacherClass);
  63. if (formalTeacherClasses != null && formalTeacherClasses.size() > 0) {
  64. for (FormalTeacherClass teacherClass : formalTeacherClasses) {
  65. classId = teacherClass.getClassId() + ",";
  66. }
  67. }
  68. }
  69. if ("parents".equals(role.getRoleKey())){
  70. FormalParentsStudent formalParentsStudent = new FormalParentsStudent();
  71. formalParentsStudent.setParentsId(user.getUserId());
  72. List<FormalParentsStudent> formalParentsStudents = formalParentsStudentMapper.selectFormalParentsStudentList(formalParentsStudent);
  73. for (FormalParentsStudent parentsStudent : formalParentsStudents) {
  74. classId = parentsStudent.getClassId() + ",";
  75. }
  76. }
  77. }
  78. if (StringUtils.isNotBlank(classId)){
  79. classId = classId.substring(0, classId.length() - 1);
  80. }
  81. //查询出所有班级id
  82. xiaoyuanNotice.setSenderDept(classId);
  83. startPage();
  84. return xiaoyuanNoticeMapper.selectXiaoyuanNoticeList(xiaoyuanNotice);
  85. }
  86. @Override
  87. public List<XiaoyuanNotice> selectXiaoyuanNoticeMyList(XiaoyuanNotice xiaoyuanNotice) {
  88. SysUser user = SecurityUtils.getLoginUser().getUser();
  89. xiaoyuanNotice.setSenderId(String.valueOf(user.getUserId()));
  90. return xiaoyuanNoticeMapper.selectXiaoyuanNoticeMyList(xiaoyuanNotice);
  91. }
  92. /**
  93. * 新增校园新闻
  94. *
  95. * @param xiaoyuanNotice 校园新闻
  96. * @return 结果
  97. */
  98. @Override
  99. public int insertXiaoyuanNotice(XiaoyuanNotice xiaoyuanNotice) {
  100. xiaoyuanNotice.setCreateTime(DateUtils.getNowDate());
  101. SysUser user = SecurityUtils.getLoginUser().getUser();
  102. xiaoyuanNotice.setSenderId(String.valueOf(user.getUserId()));
  103. xiaoyuanNotice.setSenderName(user.getUserName());
  104. String senderDept = xiaoyuanNotice.getSenderDept();
  105. xiaoyuanNotice.setAvatar(user.getAvatar());
  106. int result = 0;
  107. if (StringUtils.isNotBlank(senderDept)){
  108. String[] split = senderDept.split(",");
  109. for (String deptId : split) {
  110. xiaoyuanNotice.setSenderDept(deptId);
  111. result = result + xiaoyuanNoticeMapper.insertXiaoyuanNotice(xiaoyuanNotice);
  112. }
  113. }
  114. return result;
  115. }
  116. /**
  117. * 修改校园新闻
  118. *
  119. * @param xiaoyuanNotice 校园新闻
  120. * @return 结果
  121. */
  122. @Override
  123. public int updateXiaoyuanNotice(XiaoyuanNotice xiaoyuanNotice) {
  124. xiaoyuanNotice.setUpdateTime(DateUtils.getNowDate());
  125. return xiaoyuanNoticeMapper.updateXiaoyuanNotice(xiaoyuanNotice);
  126. }
  127. /**
  128. * 批量删除校园新闻
  129. *
  130. * @param noticeIds 需要删除的校园新闻主键
  131. * @return 结果
  132. */
  133. @Override
  134. public int deleteXiaoyuanNoticeByNoticeIds(Integer[] noticeIds) {
  135. return xiaoyuanNoticeMapper.deleteXiaoyuanNoticeByNoticeIds(noticeIds);
  136. }
  137. /**
  138. * 删除校园新闻信息
  139. *
  140. * @param noticeId 校园新闻主键
  141. * @return 结果
  142. */
  143. @Override
  144. public int deleteXiaoyuanNoticeByNoticeId(Integer noticeId) {
  145. return xiaoyuanNoticeMapper.deleteXiaoyuanNoticeByNoticeId(noticeId);
  146. }
  147. }