package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.shiro.SecurityUtils;
import org.jeecg.modules.system.entity.SysAnnouncement;
import org.jeecg.modules.system.entity.SysAnnouncementSend;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysAnnouncementMapper;
import org.jeecg.modules.system.service.ISysAnnouncementSendService;
import org.jeecg.modules.system.service.ISysAnnouncementService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 系统通告表
 * @author： jeecg-boot
 * @date：   2019-01-02
 * @version： V1.0
 */
@Service
public class SysAnnouncementServiceImpl extends ServiceImpl<SysAnnouncementMapper, SysAnnouncement> implements ISysAnnouncementService {

    @Resource
    ISysAnnouncementSendService sysAnnouncementSendService;

    @Override
    public SysAnnouncement addAll(SysAnnouncement sysAnnouncement) {
        //获取发布人名称
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        sysAnnouncement.setSender(user.getRealname());
        save(sysAnnouncement);
        if (!sysAnnouncement.getSysAnnouncementSendList().isEmpty()){
           for (SysAnnouncementSend sysAnnouncementSend:sysAnnouncement.getSysAnnouncementSendList()){
               sysAnnouncementSend.setAnntId(sysAnnouncement.getId());
           }
           sysAnnouncementSendService.saveBatch(sysAnnouncement.getSysAnnouncementSendList());
        }
         return null;
    }
}
