(开发技巧)编写包含service层的工具类

36 篇文章 0 订阅
package com.jeesite.modules.util;

import BP.Tools.DateUtils;
import BP.Tools.StringUtils;
import com.jeesite.modules.msg.entity.MsgPush;
import com.jeesite.modules.msg.service.MsgPushService1;
import com.jeesite.modules.msg.utils.MsgPcPoolUtils;
import com.jeesite.modules.sys.entity.Employee;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.utils.UserUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Optional;

/**
 * @description:
 * @author: yangkai
 * @date: 2019/12/6
 */
@Component
public class MsgUtils {
    @Resource()
    private MsgPushService1 msgPushService1;
    private static MsgUtils msgUtils;
    @PostConstruct
    public void init(){
        msgUtils = this;
    }

    /**
     * 发送消息
     * @param entity 消息实体类
     */
    public static void sendMsg(MsgPush entity){
        User user=UserUtils.getUser();
        Employee employee=(Employee) user.getRefObj();
        entity.setId(IDUtil.getID());
        entity.setReadStatus(1);
        entity.setSendDate(DateUtils.currentDate());
        entity.setIsNewRecord(true);
        if (employee != null){
            entity.setSendDeptId(Optional.ofNullable(employee.getOffice().getOfficeCode()).orElse(""));
            entity.setSendDeptName(Optional.ofNullable(employee.getOffice().getOfficeName()).orElse(""));
        }
        entity.setSendUserCode(user.getUserCode());
        entity.setSendUserName(user.getUserName());
        //发送消息
        msgUtils.msgPushService1.save(entity);
        //添加新消息到消息池
        MsgPcPoolUtils.putPool(entity.getReceiveUserCode(),entity);
    }
    /**
     * 消息回执
     * @param where 定位,bizKey业务主键,bizType业务类型,msgType消息类型,receiveUserCode接受人id;
     * @param msgContent 回执消息主体
     * @param BizUrl 回执消息详情地址
     */
    public static void dealMsg(MsgPush where,String msgContent,String BizUrl){
        //获取当前用户信息
        User user=UserUtils.getUser();
        Employee employee=(Employee) user.getRefObj();
        //定位当前消息
        MsgPush entity=msgUtils.msgPushService1.findOneByBizKeyAndBizType(where);
        //消息回执
        MsgPush msgPush1=new MsgPush(entity);
        if(StringUtils.isNotBlank(BizUrl)){
            msgPush1.setBizUrl(BizUrl);
        }
        if(StringUtils.isNotBlank(msgContent)){
            msgPush1.setMsgContent(msgContent);
        }
        msgPush1.setReceiveUserCode(entity.getSendUserCode());
        msgPush1.setReceiveUserName(entity.getSendUserName());
        msgPush1.setSendDate(DateUtils.currentDate());
        if (employee != null)
        {
            msgPush1.setSendDeptId(employee.getOffice().getOfficeCode());
            msgPush1.setSendDeptName(employee.getOffice().getOfficeName());
        }
        msgPush1.setSendUserCode(UserUtils.getUser().getUserCode());
        msgPush1.setSendUserName(UserUtils.getUser().getUserName());
        msgPush1.setReadStatus(1);
        msgPush1.setId(IDUtil.getID());
        msgPush1.setIsNewRecord(true);
        msgUtils.msgPushService1.save(msgPush1);
        //添加消息到消息池
        MsgPcPoolUtils.putPool(msgPush1.getReceiveUserCode(),msgPush1);
        //消息处理
        if(StringUtils.isNotBlank(BizUrl)){
            entity.setBizUrl(BizUrl);
        }
        entity.setReadStatus(2);
        entity.setIsNewRecord(false);
        entity.setDealTime(DateUtils.currentDate());
        entity.setDealUserId(user.getUserCode());
        entity.setDealUserName(user.getUserName());
        msgUtils.msgPushService1.update(entity);
    }
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值