All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rexsheng.springboot.faster.system.notice.domain.SysNotice Maven / Gradle / Ivy

The newest version!
package com.github.rexsheng.springboot.faster.system.notice.domain;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.rexsheng.springboot.faster.common.constant.CommonConstant;
import com.github.rexsheng.springboot.faster.system.file.application.dto.FileDetailResponse;
import com.github.rexsheng.springboot.faster.system.utils.AuthenticationUtil;
import com.github.rexsheng.springboot.faster.util.DateUtil;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

public class SysNotice {

    private Long noticeId;

    private Long messageId;

    private String noticeTitle;

    private String noticeContent;

    private String noticeType;

    private LocalDateTime endTime;

    private Integer status;

    private Boolean isDel;

    private LocalDateTime createTime;

    private Long createUserId;

    private LocalDateTime updateTime;

    private Long updateUserId;

    private LocalDateTime readTime;

    private List noticeUsers;

    private List noticeFiles;

    public static Integer STATUS_NORMAL = CommonConstant.STATUS_RUNNING;

    public String getBroadcastContent(){
        List> list=new ArrayList<>();
        Map data=new HashMap<>();
        if(this.getNoticeId()!=null){
            data.put("id",this.getNoticeId());
        }
        if(this.getMessageId()!=null){
            data.put("relationId",this.getMessageId());
        }
        data.put("title",this.getNoticeTitle()==null?"通知":this.getNoticeTitle());
        if(this.getNoticeUsers()!=null && this.getNoticeUsers().size()>0){
            for(SysNoticeUser sysNoticeUser:this.getNoticeUsers()){
                Map newMap=new HashMap<>();
                newMap.putAll(data);
                newMap.put("user",sysNoticeUser.getUserId());
                if(sysNoticeUser.getId()!=null){
                    newMap.put("relationId",sysNoticeUser.getId());
                }
                list.add(newMap);
            }
        }
        else{
            list.add(data);
        }
        try {
            return new ObjectMapper().writeValueAsString(list);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static List> parseBroadcastContent(String broadcastContent){
        try {
            return new ObjectMapper().readValue(broadcastContent,new TypeReference>>(){});
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static List of(List ids, Boolean isDel){
        return ids.stream().map(a->{
            SysNotice domain=new SysNotice();
            domain.setNoticeId(a);
            domain.setDel(isDel);
            domain.setUpdateTime(DateUtil.currentDateTime());
            domain.setUpdateUserId(AuthenticationUtil.currentUserId());
            return domain;
        }).collect(Collectors.toList());
    }

    public static SysNotice ofReadEntity(Long userId, Long noticeId, Long messageId){
        SysNotice domain=new SysNotice();
        domain.setNoticeId(noticeId);
        domain.setMessageId(messageId);
        domain.setCreateTime(DateUtil.currentDateTime());
        domain.setCreateUserId(userId);
        domain.setUpdateTime(DateUtil.currentDateTime());
        domain.setUpdateUserId(userId);
        return domain;
    }

    public Long getNoticeId() {
        return noticeId;
    }

    public void setNoticeId(Long noticeId) {
        this.noticeId = noticeId;
    }

    public Long getMessageId() {
        return messageId;
    }

    public void setMessageId(Long messageId) {
        this.messageId = messageId;
    }

    public String getNoticeTitle() {
        return noticeTitle;
    }

    public void setNoticeTitle(String noticeTitle) {
        this.noticeTitle = noticeTitle;
    }

    public String getNoticeContent() {
        return noticeContent;
    }

    public void setNoticeContent(String noticeContent) {
        this.noticeContent = noticeContent;
    }

    public String getNoticeType() {
        return noticeType;
    }

    public void setNoticeType(String noticeType) {
        this.noticeType = noticeType;
    }

    public LocalDateTime getEndTime() {
        return endTime;
    }

    public void setEndTime(LocalDateTime endTime) {
        this.endTime = endTime;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Boolean getDel() {
        return isDel;
    }

    public void setDel(Boolean del) {
        isDel = del;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public Long getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(Long createUserId) {
        this.createUserId = createUserId;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public Long getUpdateUserId() {
        return updateUserId;
    }

    public void setUpdateUserId(Long updateUserId) {
        this.updateUserId = updateUserId;
    }

    public LocalDateTime getReadTime() {
        return readTime;
    }

    public void setReadTime(LocalDateTime readTime) {
        this.readTime = readTime;
    }

    public List getNoticeUsers() {
        return noticeUsers;
    }

    public void setNoticeUsers(List noticeUsers) {
        this.noticeUsers = noticeUsers;
    }

    public List getNoticeFiles() {
        return noticeFiles;
    }

    public void setNoticeFiles(List noticeFiles) {
        this.noticeFiles = noticeFiles;
    }

    public void addNoticeUser(Long[] userIds){
        if(userIds!=null){
            Arrays.stream(userIds).filter(userId->userId!=null).distinct().forEach(userId->{
                SysNoticeUser user=new SysNoticeUser();
                user.setUserId(userId);
                user.setReadState(false);
                user.setCreateTime(DateUtil.currentDateTime());
                user.setCreateUserId(AuthenticationUtil.currentUserId());
                if(this.noticeUsers==null){
                    this.noticeUsers=new ArrayList<>();
                }
                this.noticeUsers.add(user);
            });
        }
    }

    public static class SysNoticeUser{

        private Long id;

        private Long userId;

        private Boolean readState;

        private LocalDateTime createTime;

        private Long createUserId;

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public Long getUserId() {
            return userId;
        }

        public void setUserId(Long userId) {
            this.userId = userId;
        }

        public Boolean getReadState() {
            return readState;
        }

        public void setReadState(Boolean readState) {
            this.readState = readState;
        }

        public LocalDateTime getCreateTime() {
            return createTime;
        }

        public void setCreateTime(LocalDateTime createTime) {
            this.createTime = createTime;
        }

        public Long getCreateUserId() {
            return createUserId;
        }

        public void setCreateUserId(Long createUserId) {
            this.createUserId = createUserId;
        }
    }

    public static class SysNoticeFile{

        private String fileId;

        private String fileName;

        private String originalFileName;

        private Long fileSize;

        private byte[] fileContent;

        public static SysNoticeFile of(FileDetailResponse fileDetailResponse){
            SysNoticeFile file=new SysNoticeFile();
            file.setFileId(fileDetailResponse.getId());
            file.setFileName(fileDetailResponse.getName());
            file.setOriginalFileName(fileDetailResponse.getOriginalName());
            file.setFileSize(fileDetailResponse.getSize());
            return file;
        }

        public String generateObjectKey(){
            LocalDateTime now=DateUtil.currentDateTime();
            return DateUtil.format(now,"yyyyMMdd")+"/"+fileName;
        }

        public String getFileId() {
            return fileId;
        }

        public void setFileId(String fileId) {
            this.fileId = fileId;
        }

        public String getFileName() {
            return fileName;
        }

        public void setFileName(String fileName) {
            this.fileName = fileName;
        }

        public String getOriginalFileName() {
            return originalFileName;
        }

        public void setOriginalFileName(String originalFileName) {
            this.originalFileName = originalFileName;
        }

        public Long getFileSize() {
            return fileSize;
        }

        public void setFileSize(Long fileSize) {
            this.fileSize = fileSize;
        }

        public byte[] getFileContent() {
            return fileContent;
        }

        public void setFileContent(byte[] fileContent) {
            this.fileContent = fileContent;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy