123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package com.ruoyi.system.service.impl;
- import java.util.List;
- import java.util.Set;
- import com.ruoyi.common.core.domain.entity.FormalParentsStudent;
- import com.ruoyi.common.core.domain.entity.FormalTeacherClass;
- import com.ruoyi.common.core.domain.entity.SysRole;
- import com.ruoyi.common.core.domain.entity.SysUser;
- import com.ruoyi.common.core.domain.model.LoginUser;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.SecurityUtils;
- import com.ruoyi.common.utils.ServletUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.system.mapper.FormalParentsStudentMapper;
- import com.ruoyi.system.mapper.FormalTeacherClassMapper;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.ruoyi.system.mapper.XiaoyuanNoticeMapper;
- import com.ruoyi.system.domain.XiaoyuanNotice;
- import com.ruoyi.system.service.IXiaoyuanNoticeService;
- import javax.annotation.Resource;
- import static com.ruoyi.common.utils.PageUtils.startPage;
- /**
- * 校园新闻Service业务层处理
- *
- * @author boman
- * @date 2023-06-05
- */
- @Service
- public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
- @Autowired
- private XiaoyuanNoticeMapper xiaoyuanNoticeMapper;
- @Autowired
- private FormalTeacherClassMapper formalTeacherClassMapper;
- @Autowired
- private FormalParentsStudentMapper formalParentsStudentMapper;
- /**
- * 查询校园新闻
- *
- * @param noticeId 校园新闻主键
- * @return 校园新闻
- */
- @Override
- public XiaoyuanNotice selectXiaoyuanNoticeByNoticeId(Integer noticeId) {
- return xiaoyuanNoticeMapper.selectXiaoyuanNoticeByNoticeId(noticeId);
- }
- /**
- * 查询校园新闻列表
- *
- * @param xiaoyuanNotice 校园新闻
- * @return 校园新闻
- */
- @Override
- public List<XiaoyuanNotice> selectXiaoyuanNoticeList(XiaoyuanNotice xiaoyuanNotice) {
- SysUser user = SecurityUtils.getLoginUser().getUser();
- xiaoyuanNotice.setSenderId(user.getUserId().toString());
- List<SysRole> roles = user.getRoles();
- String classId = "0,";
- for (SysRole role : roles) {
- if ("teacher".equals(role.getRoleKey())) {
- FormalTeacherClass formalTeacherClass = new FormalTeacherClass();
- formalTeacherClass.setTeacherId(user.getUserId());
- List<FormalTeacherClass> formalTeacherClasses = formalTeacherClassMapper.selectFormalTeacherClassList(formalTeacherClass);
- if (formalTeacherClasses != null && formalTeacherClasses.size() > 0) {
- for (FormalTeacherClass teacherClass : formalTeacherClasses) {
- classId = teacherClass.getClassId() + ",";
- }
- }
- }
- if ("parents".equals(role.getRoleKey())){
- FormalParentsStudent formalParentsStudent = new FormalParentsStudent();
- formalParentsStudent.setParentsId(user.getUserId());
- List<FormalParentsStudent> formalParentsStudents = formalParentsStudentMapper.selectFormalParentsStudentList(formalParentsStudent);
- for (FormalParentsStudent parentsStudent : formalParentsStudents) {
- classId = parentsStudent.getClassId() + ",";
- }
- }
- }
- if (StringUtils.isNotBlank(classId)){
- classId = classId.substring(0, classId.length() - 1);
- }
- //查询出所有班级id
- xiaoyuanNotice.setSenderDept(classId);
- startPage();
- return xiaoyuanNoticeMapper.selectXiaoyuanNoticeList(xiaoyuanNotice);
- }
- @Override
- public List<XiaoyuanNotice> selectXiaoyuanNoticeMyList(XiaoyuanNotice xiaoyuanNotice) {
- SysUser user = SecurityUtils.getLoginUser().getUser();
- xiaoyuanNotice.setSenderId(String.valueOf(user.getUserId()));
- return xiaoyuanNoticeMapper.selectXiaoyuanNoticeMyList(xiaoyuanNotice);
- }
- /**
- * 新增校园新闻
- *
- * @param xiaoyuanNotice 校园新闻
- * @return 结果
- */
- @Override
- public int insertXiaoyuanNotice(XiaoyuanNotice xiaoyuanNotice) {
- xiaoyuanNotice.setCreateTime(DateUtils.getNowDate());
- SysUser user = SecurityUtils.getLoginUser().getUser();
- xiaoyuanNotice.setSenderId(String.valueOf(user.getUserId()));
- xiaoyuanNotice.setSenderName(user.getUserName());
- String senderDept = xiaoyuanNotice.getSenderDept();
- xiaoyuanNotice.setAvatar(user.getAvatar());
- int result = 0;
- if (StringUtils.isNotBlank(senderDept)){
- String[] split = senderDept.split(",");
- for (String deptId : split) {
- xiaoyuanNotice.setSenderDept(deptId);
- result = result + xiaoyuanNoticeMapper.insertXiaoyuanNotice(xiaoyuanNotice);
- }
- }
- return result;
- }
- /**
- * 修改校园新闻
- *
- * @param xiaoyuanNotice 校园新闻
- * @return 结果
- */
- @Override
- public int updateXiaoyuanNotice(XiaoyuanNotice xiaoyuanNotice) {
- xiaoyuanNotice.setUpdateTime(DateUtils.getNowDate());
- return xiaoyuanNoticeMapper.updateXiaoyuanNotice(xiaoyuanNotice);
- }
- /**
- * 批量删除校园新闻
- *
- * @param noticeIds 需要删除的校园新闻主键
- * @return 结果
- */
- @Override
- public int deleteXiaoyuanNoticeByNoticeIds(Integer[] noticeIds) {
- return xiaoyuanNoticeMapper.deleteXiaoyuanNoticeByNoticeIds(noticeIds);
- }
- /**
- * 删除校园新闻信息
- *
- * @param noticeId 校园新闻主键
- * @return 结果
- */
- @Override
- public int deleteXiaoyuanNoticeByNoticeId(Integer noticeId) {
- return xiaoyuanNoticeMapper.deleteXiaoyuanNoticeByNoticeId(noticeId);
- }
- }
|