You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
package com.zh.project0512.utils;
|
|
|
|
|
|
|
|
|
|
import com.zh.project0512.mapper.AppMessageMapper;
|
|
|
|
|
import com.zh.project0512.model.AppMessage;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* app消息工具类
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
public class AppMessageUtil {
|
|
|
|
|
@Resource
|
|
|
|
|
AppMessageMapper appMessageMapper;
|
|
|
|
|
|
|
|
|
|
//解决工具类无法调用Dao层数据,数据为null
|
|
|
|
|
//静态初始化当前类
|
|
|
|
|
private static AppMessageUtil appMessageUtil;
|
|
|
|
|
//在方法上加上注解@PostConstruct,这样方法就会在bean初始化之后被spring容器执行
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void init(){
|
|
|
|
|
//声明的静态类=this
|
|
|
|
|
appMessageUtil=this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendMessage(Integer type,String title,String describe,String url,String sendOpenId,String receiverOpenId){
|
|
|
|
|
AppMessage appMessage = new AppMessage();
|
|
|
|
|
appMessage.setType(type);
|
|
|
|
|
appMessage.setTitle(title);
|
|
|
|
|
appMessage.setDescribe(describe);
|
|
|
|
|
appMessage.setUrl(url);
|
|
|
|
|
appMessage.setSendOpenId(sendOpenId);
|
|
|
|
|
appMessage.setReceiverOpenId(receiverOpenId);
|
|
|
|
|
return sendMessage(appMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendMessage(AppMessage appMessage){
|
|
|
|
|
appMessage.setId(null);
|
|
|
|
|
appMessage.setCreateDate(new Date());
|
|
|
|
|
appMessage.setReads(0);
|
|
|
|
|
int insert = appMessageUtil.appMessageMapper.insert(appMessage);
|
|
|
|
|
return insert > 0;
|
|
|
|
|
}
|
|
|
|
|
}
|