XiaoyuanNoticeServiceImpl.java 5.6 KB

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