| | |
| | | public class BPushDeviceToken implements Serializable { |
| | | @Id |
| | | private String id; |
| | | /** |
| | | * 应用编码 |
| | | */ |
| | | @Indexed |
| | | private String appCode; |
| | | @Indexed |
| | |
| | | private PushPlatform type; |
| | | private String token; |
| | | |
| | | /** |
| | | * APP软件版本号 |
| | | */ |
| | | @Indexed |
| | | private Integer versionCode; |
| | | //手机型号 |
| | | /** |
| | | * 手机型号 |
| | | */ |
| | | @Indexed |
| | | private String buildModel; |
| | | //手机系统版本 |
| | | /** |
| | | * 手机系统版本 |
| | | */ |
| | | @Indexed |
| | | private String buildVersion; |
| | | @Indexed |
| | |
| | | import java.util.Map; |
| | | |
| | | public class BPushMessage implements Serializable { |
| | | /** |
| | | * 推送的标题 |
| | | */ |
| | | private String title; |
| | | /** |
| | | * 推送的内容 |
| | | */ |
| | | private String content; |
| | | /** |
| | | * Android落地页 |
| | | */ |
| | | private String androidActivity; |
| | | private String androidActivityScheme; |
| | | private String androidHostPath; |
| | | |
| | | private Map<String, String> extras; |
| | | |
| | | public String getTitle() { |
| | |
| | | public void setExtras(Map<String, String> extras) { |
| | | this.extras = extras; |
| | | } |
| | | |
| | | public String getAndroidActivity() { |
| | | return androidActivity; |
| | | } |
| | | |
| | | public void setAndroidActivity(String androidActivity) { |
| | | this.androidActivity = androidActivity; |
| | | } |
| | | |
| | | public String getAndroidActivityScheme() { |
| | | return androidActivityScheme; |
| | | } |
| | | |
| | | public void setAndroidActivityScheme(String androidActivityScheme) { |
| | | this.androidActivityScheme = androidActivityScheme; |
| | | } |
| | | |
| | | public String getAndroidHostPath() { |
| | | return androidHostPath; |
| | | } |
| | | |
| | | public void setAndroidHostPath(String androidHostPath) { |
| | | this.androidHostPath = androidHostPath; |
| | | } |
| | | } |
| | |
| | | private String id; |
| | | @NotEmpty(message = "应用标识不能为空") |
| | | private String appCode; |
| | | // 推送的状态 |
| | | /** |
| | | * 推送的状态 |
| | | */ |
| | | private Integer state; |
| | | private String stateDesc; |
| | | @NotNull(message = "推送条件不能为空") |
| | |
| | | @Column(name = "platform") |
| | | private PushPlatform pushPlatform; |
| | | |
| | | //总共的设备数量 |
| | | /** |
| | | * 总共的设备数量 |
| | | */ |
| | | @Column(name = "total_device_count") |
| | | private Long totalDeviceCount; |
| | | |
| | | //推送成功的设备数量 |
| | | /** |
| | | * 推送成功的设备数量 |
| | | */ |
| | | @Column(name = "push_success_device_count") |
| | | private Long pushSuccessDeviceCount; |
| | | |
| | | //是否推送完成 |
| | | /** |
| | | * 是否推送完成 |
| | | */ |
| | | @Column(name = "finish") |
| | | private Boolean finish; |
| | | |
| | | //推送完成时间 |
| | | /** |
| | | * 推送完成时间 |
| | | */ |
| | | @Column(name = "finish_time") |
| | | private Date finishTime; |
| | | |
| | | //创建时间 |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @Column(name = "create_time") |
| | | private Date createTime; |
| | | |
| | | //更新时间 |
| | | /** |
| | | * 更新时间 |
| | | */ |
| | | @Column(name = "update_time") |
| | | private Date updateTime; |
| | | |
| | |
| | | package com.ks.push.service; |
| | | |
| | | import com.ks.lib.common.exception.ParamsException; |
| | | import com.ks.push.exception.BPushDeviceTokenException; |
| | | import com.ks.push.pojo.DO.BPushDeviceToken; |
| | | |
| | |
| | | * @param deviceToken |
| | | * @throws BPushDeviceTokenException |
| | | */ |
| | | public void save(BPushDeviceToken deviceToken) throws BPushDeviceTokenException; |
| | | public void save(BPushDeviceToken deviceToken) throws BPushDeviceTokenException, ParamsException; |
| | | |
| | | |
| | | /** |
| | |
| | | import com.alibaba.druid.pool.DruidDataSource; |
| | | import io.seata.rm.datasource.DataSourceProxy; |
| | | import io.seata.spring.annotation.GlobalTransactionScanner; |
| | | import org.apache.ibatis.session.SqlSessionFactory; |
| | | import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; |
| | | import org.mybatis.spring.SqlSessionFactoryBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.context.annotation.Primary; |
| | | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
| | | |
| | | /** |
| | | * @Author: heshouyou |
| | |
| | | <artifactId>facade-push</artifactId> |
| | | <version>0.0.1-SNAPSHOT</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>io.seata</groupId> |
| | | <artifactId>seata-spring-boot-starter</artifactId> |
| | | <version>${seata.version}</version> |
| | | </dependency> |
| | | <!--<dependency>--> |
| | | <!--<groupId>io.seata</groupId>--> |
| | | <!--<artifactId>seata-spring-boot-starter</artifactId>--> |
| | | <!--<version>${seata.version}</version>--> |
| | | <!--</dependency>--> |
| | | |
| | | <dependency> |
| | | <groupId>org.springframework.security</groupId> |
| | |
| | | |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-freemarker</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-web</artifactId> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-tomcat</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | <!--<exclusions>--> |
| | | <!--<exclusion>--> |
| | | <!--<groupId>org.springframework.boot</groupId>--> |
| | | <!--<artifactId>spring-boot-starter-tomcat</artifactId>--> |
| | | <!--</exclusion>--> |
| | | <!--</exclusions>--> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | |
| | | <artifactId>spring-boot-starter-tomcat</artifactId> |
| | | <!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。 |
| | | 相当于compile,但是打包阶段做了exclude操作--> |
| | | <scope>provided</scope> |
| | | <!--<scope>provided</scope>--> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | |
| | | <dependency> |
| | | <groupId>com.yeshi</groupId> |
| | | <artifactId>utils</artifactId> |
| | | <version>0.0.4</version> |
| | | <version>0.0.5</version> |
| | | <scope>compile</scope> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.qcloud</groupId> |
| | | <artifactId>cmq-http-client</artifactId> |
| | | <version>1.0.7</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.apache.commons</groupId> |
| | | <artifactId>commons-pool2</artifactId> |
| | | <version>2.5.0</version> |
| | | </dependency> |
| | | |
| | | |
| | | </dependencies> |
| | | |
| | |
| | | package com.ks.push; |
| | | |
| | | import com.ks.push.consumer.mq.PushTaskConsumer; |
| | | import com.ks.push.pojo.DO.PushPlatform; |
| | | import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.slf4j.Logger; |
| | |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.builder.SpringApplicationBuilder; |
| | | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
| | | import org.springframework.context.ApplicationListener; |
| | | import org.springframework.context.event.ContextRefreshedEvent; |
| | | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| | | import org.yeshi.utils.mq.JobThreadExecutorServiceImpl; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @SpringBootApplication |
| | | @EnableTransactionManagement |
| | | @MapperScan(basePackages = "com.ks.push.mapper") |
| | | @EnableDubbo(scanBasePackages = "com.ks.push.service.remote") |
| | | public class PushApplication { |
| | | public class PushApplication implements ApplicationListener<ContextRefreshedEvent> { |
| | | private final static Logger logger = LoggerFactory.getLogger(PushApplication.class); |
| | | |
| | | @Resource |
| | | private PushTaskConsumer pushTaskConsumer; |
| | | |
| | | public static void main(String[] args) { |
| | | SpringApplication.run(PushApplication.class, args); |
| | | logger.info("应用启动成功"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { |
| | | logger.info("容器加载完毕"); |
| | | initMQMsgConsumer(); |
| | | } |
| | | |
| | | private void initMQMsgConsumer() { |
| | | final int THREAD_NUM = 3; |
| | | for (PushPlatform pushPlatform : PushPlatform.values()) { |
| | | //创建三条队列处理 |
| | | for (int i = 0; i < THREAD_NUM; i++) { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushTaskConsumer.consumeMsg(pushPlatform); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ks.push.consumer.mq; |
| | | |
| | | import com.ks.push.dto.BPushDeviceDataSet; |
| | | import com.ks.push.manager.BPushPlatformAppInfoManager; |
| | | import com.ks.push.manager.CMQManager; |
| | | import com.ks.push.manager.PushExcuteResultManager; |
| | | import com.ks.push.pojo.DO.BPushPlatformAppInfo; |
| | | import com.ks.push.pojo.DO.BPushTask; |
| | | import com.ks.push.pojo.DO.PushPlatform; |
| | | import com.ks.push.service.BPushTaskService; |
| | | import com.ks.push.utils.PushUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | public class PushTaskConsumer { |
| | | |
| | | Logger logger = LoggerFactory.getLogger(PushTaskConsumer.class); |
| | | |
| | | |
| | | @Resource |
| | | private BPushTaskService bPushTaskService; |
| | | |
| | | @Resource |
| | | private PushExcuteResultManager pushExcuteResultManager; |
| | | |
| | | @Resource |
| | | private BPushPlatformAppInfoManager bPushPlatformAppInfoManager; |
| | | |
| | | |
| | | /** |
| | | * 消费任务消息 |
| | | * |
| | | * @param platform |
| | | */ |
| | | public void consumeMsg(PushPlatform platform) { |
| | | |
| | | if (platform == null) { |
| | | return; |
| | | } |
| | | logger.info("消费消息开始:{} Thread:{}", platform.name(),Thread.currentThread().getId()); |
| | | List<CMQManager.MQMsgConsumeResult> resultList = null; |
| | | try { |
| | | resultList = CMQManager.getInstance().consumePushQueue(platform, 1); |
| | | } catch (Exception e) { |
| | | } |
| | | logger.info("消费消息结束:{} Thread:{}", platform.name(),Thread.currentThread().getId()); |
| | | if (resultList != null) { |
| | | for (CMQManager.MQMsgConsumeResult result : resultList) { |
| | | try { |
| | | BPushDeviceDataSet dataSet = (BPushDeviceDataSet) result.getData(); |
| | | BPushTask task = bPushTaskService.getTask(dataSet.getTaskId()); |
| | | if (task != null) { |
| | | if (task.getState() == BPushTask.STATE_PUSHING) { |
| | | BPushPlatformAppInfo platformAppInfo = bPushPlatformAppInfoManager.selectByAppCodeAndPlatform(task.getAppCode(), platform); |
| | | if (platformAppInfo != null) { |
| | | try { |
| | | PushUtil.pushNotifyCation(platform, platformAppInfo.getPushAppInfo(), task.getMessage(), dataSet.getDeviceTokenList()); |
| | | logger.info("推送任务执行成功,taskId-{},batchId-{}", dataSet.getTaskId(), dataSet.getBatchId()); |
| | | } catch (Exception e) { |
| | | logger.error("推送出错:ttaskId-{},batchId-{},错误原因:{}", task.getId(), dataSet.getBatchId(), e.getMessage()); |
| | | } |
| | | } |
| | | } else { |
| | | if (task.getState() == BPushTask.STATE_PAUSED) { |
| | | //任务暂停,不删除消息等待下次消费 |
| | | continue; |
| | | } else if (task.getState() == BPushTask.STATE_CANCELED) { |
| | | //任务取消,删除消息 |
| | | } |
| | | } |
| | | } else { |
| | | logger.error("任务为空,taskId-{},batchId-{}", dataSet.getTaskId(), dataSet.getBatchId()); |
| | | } |
| | | //删除消息 |
| | | logger.info("推送任务执行完成,taskId-{},batchId-{}", dataSet.getTaskId(), dataSet.getBatchId()); |
| | | CMQManager.getInstance().deleteMsg(result.getQueueName(), result.getReceiptHandle()); |
| | | pushExcuteResultManager.batchPushFinish(dataSet, platform); |
| | | } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ks.push.controller.admin; |
| | | |
| | | import com.ks.push.pojo.DO.BPushAppInfo; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.validation.constraints.NotEmpty; |
| | | |
| | | @Controller |
| | | @RequestMapping("/admin/api/app") |
| | | public class AdminAppController { |
| | | |
| | | @Resource |
| | | private BPushAppInfo adminUserManager; |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("list") |
| | | public String list(@NotEmpty(message = "账号不能为空") String account, @NotEmpty(message = "密码不能为空") String pwd, @NotEmpty(message = "验证码不能为空") String code, BindingResult bindingResult, HttpSession session) { |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.ks.push.controller.admin; |
| | | |
| | | import com.ks.push.entity.AdminUser; |
| | | import com.ks.push.manager.AdminUserManager; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.yeshi.utils.JsonUtil; |
| | | import org.yeshi.utils.StringUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.validation.constraints.NotEmpty; |
| | | |
| | | @Controller |
| | | @RequestMapping("/admin/api/user") |
| | | public class AdminUserController { |
| | | |
| | | @Resource |
| | | private AdminUserManager adminUserManager; |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("login") |
| | | public String login(@NotEmpty(message = "账号不能为空") String account, @NotEmpty(message = "密码不能为空") String pwd, @NotEmpty(message = "验证码不能为空") String code, BindingResult bindingResult, HttpSession session) { |
| | | if (bindingResult.hasErrors()) { |
| | | String msg = bindingResult.getFieldError().getDefaultMessage(); |
| | | return JsonUtil.loadFalseResult(msg); |
| | | } |
| | | |
| | | String captcha = session.getAttribute("captcha") + ""; |
| | | if (StringUtil.isNullOrEmpty(captcha) || !captcha.equalsIgnoreCase(code)) { |
| | | return JsonUtil.loadFalseResult("验证码错误"); |
| | | } |
| | | |
| | | AdminUser adminUser = adminUserManager.selectByAccount(account); |
| | | if (adminUser == null) { |
| | | return JsonUtil.loadFalseResult("账号不存在"); |
| | | } |
| | | |
| | | if (!StringUtil.Md5(pwd).equalsIgnoreCase(adminUser.getPwd())) { |
| | | return JsonUtil.loadFalseResult("密码错误"); |
| | | } |
| | | |
| | | session.setAttribute("ADMIN_USER", adminUser); |
| | | return JsonUtil.loadTrueResult("登录成功"); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.ks.push.controller.admin; |
| | | |
| | | import com.google.code.kaptcha.Producer; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | |
| | | @Controller |
| | | @RequestMapping("admin/api") |
| | | public class CaptchaController { |
| | | @Resource |
| | | private Producer captchaProducer; |
| | | |
| | | @GetMapping("captcha.jpg") |
| | | public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception { |
| | | response.setContentType("image/jpeg"); |
| | | String capText = captchaProducer.createText(); |
| | | request.getSession().setAttribute("captcha", capText); |
| | | BufferedImage bi = captchaProducer.createImage(capText); |
| | | ServletOutputStream out = response.getOutputStream(); |
| | | ImageIO.write(bi, "jpg", out); |
| | | try { |
| | | out.flush(); |
| | | } finally { |
| | | out.close(); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ks.push.entity; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | public class AdminUser implements Serializable { |
| | | |
| | | private Long id; |
| | | |
| | | private String account; |
| | | |
| | | private String pwd; |
| | | |
| | | private String name; |
| | | |
| | | private Date createTime; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getAccount() { |
| | | return account; |
| | | } |
| | | |
| | | public void setAccount(String account) { |
| | | this.account = account; |
| | | } |
| | | |
| | | public String getPwd() { |
| | | return pwd; |
| | | } |
| | | |
| | | public void setPwd(String pwd) { |
| | | this.pwd = pwd; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ks.push.manager; |
| | | |
| | | import com.ks.push.entity.AdminUser; |
| | | import com.ks.push.mapper.AdminUserMapper; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Component |
| | | public class AdminUserManager { |
| | | |
| | | @Resource |
| | | private AdminUserMapper adminUserMapper; |
| | | |
| | | public AdminUser selectByAccount(String account) { |
| | | return adminUserMapper.selectByAccount(account); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ks.push.manager; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Component |
| | | public class BPushAppInfoManager { |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | import com.ks.push.dao.BPushPlatformAppInfoDao; |
| | | import com.ks.push.pojo.DO.BPushPlatformAppInfo; |
| | | import com.ks.push.pojo.DO.PushPlatform; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | return bPushPlatformAppInfoDao.findList(query); |
| | | } |
| | | |
| | | /** |
| | | * 查询推送平台 |
| | | * |
| | | * @param appCode |
| | | * @param pushPlatform |
| | | * @return |
| | | */ |
| | | public BPushPlatformAppInfo selectByAppCodeAndPlatform(String appCode, PushPlatform pushPlatform) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("appCode").is(appCode).and("platform").is(pushPlatform)); |
| | | return bPushPlatformAppInfoDao.findOne(query); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | package com.ks.push.manager; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.ks.push.dto.BPushDeviceDataSet; |
| | | import com.ks.push.pojo.DO.PushPlatform; |
| | | import com.qcloud.cmq.Message; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | import org.yeshi.utils.CMQUtil; |
| | | |
| | | @Component |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class CMQManager { |
| | | static Logger logger = LoggerFactory.getLogger(CMQManager.class); |
| | | |
| | | private static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25"; |
| | | private static String secretKey = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo"; |
| | | |
| | | private static CMQManager cmqManager; |
| | | private static CMQUtil cmqUtil; |
| | | /** |
| | | * 小米推送队列 |
| | | */ |
| | | public static String PUSH_XM = "bpush-xm"; |
| | | /** |
| | | * 华为推送队列 |
| | | */ |
| | | public static String PUSH_HUAWEI = "bpush-huawei"; |
| | | /** |
| | | * oppo推送队列 |
| | | */ |
| | | public static String PUSH_OPPO = "bpush-oppo"; |
| | | /** |
| | | * vivo推送队列 |
| | | */ |
| | | public static String PUSH_VIVO = "bpush-vivo"; |
| | | /** |
| | | * 魅族推送队列 |
| | | */ |
| | | public static String PUSH_MZ = "bpush-mz"; |
| | | |
| | | static { |
| | | cmqUtil = CMQUtil.getInstance(secretId, secretKey); |
| | | // 最大消息为1M |
| | | cmqUtil.createQueue(PUSH_XM); |
| | | cmqUtil.createQueue(PUSH_HUAWEI); |
| | | cmqUtil.createQueue(PUSH_OPPO); |
| | | cmqUtil.createQueue(PUSH_VIVO); |
| | | cmqUtil.createQueue(PUSH_MZ); |
| | | logger.info("创建队列完毕"); |
| | | } |
| | | |
| | | |
| | | public static CMQManager getInstance() { |
| | | if (cmqManager == null) { |
| | | cmqManager = new CMQManager(); |
| | | } |
| | | return cmqManager; |
| | | } |
| | | |
| | | private String getQueueName(PushPlatform platform) { |
| | | String queueName = null; |
| | | if (platform == PushPlatform.xm) { |
| | | queueName = PUSH_XM; |
| | | } else if (platform == PushPlatform.hw) { |
| | | queueName = PUSH_HUAWEI; |
| | | } else if (platform == PushPlatform.oppo) { |
| | | queueName = PUSH_OPPO; |
| | | } else if (platform == PushPlatform.vivo) { |
| | | queueName = PUSH_VIVO; |
| | | } else if (platform == PushPlatform.mz) { |
| | | queueName = PUSH_MZ; |
| | | } |
| | | return queueName; |
| | | } |
| | | |
| | | /** |
| | | * 添加到推送队列 |
| | |
| | | * @param dataSet |
| | | */ |
| | | public void addToPushQueue(PushPlatform platform, BPushDeviceDataSet dataSet) { |
| | | //TODO 添加到推送队列 |
| | | String queueName = getQueueName(platform); |
| | | if (queueName == null) { |
| | | return; |
| | | } |
| | | cmqUtil.sendMsg(queueName, new Gson().toJson(dataSet)); |
| | | } |
| | | |
| | | /** |
| | | * 消费队列 |
| | | * |
| | | * @param platform |
| | | * @param count |
| | | * @return |
| | | */ |
| | | public List<MQMsgConsumeResult> consumePushQueue(PushPlatform platform, int count) throws Exception { |
| | | String queueName = getQueueName(platform); |
| | | if (queueName == null) { |
| | | return null; |
| | | } |
| | | |
| | | List<Message> list = cmqUtil.recieveMsg(count, queueName); |
| | | if (list != null) { |
| | | List<MQMsgConsumeResult> resultList = new ArrayList<>(); |
| | | for (Message msg : list) { |
| | | String result = msg.msgBody; |
| | | logger.info("队列名称:{} 消息内容:{}", queueName, result); |
| | | BPushDeviceDataSet dataSet = new Gson().fromJson(result, BPushDeviceDataSet.class); |
| | | resultList.add(new MQMsgConsumeResult(dataSet, queueName, msg.receiptHandle)); |
| | | } |
| | | return resultList; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 删除消息 |
| | | * |
| | | * @param queueName |
| | | * @param receiptHandle |
| | | */ |
| | | public void deleteMsg(String queueName, String receiptHandle) { |
| | | cmqUtil.deleteMsg(queueName, receiptHandle); |
| | | } |
| | | |
| | | |
| | | public static class MQMsgConsumeResult { |
| | | private String queueName; |
| | | private Object data; |
| | | private String receiptHandle; |
| | | |
| | | public MQMsgConsumeResult(Object data, String queueName, String receiptHandle) { |
| | | this.data = data; |
| | | this.queueName = queueName; |
| | | this.receiptHandle = receiptHandle; |
| | | } |
| | | |
| | | public Object getData() { |
| | | return data; |
| | | } |
| | | |
| | | public void setData(Object data) { |
| | | this.data = data; |
| | | } |
| | | |
| | | public String getReceiptHandle() { |
| | | return receiptHandle; |
| | | } |
| | | |
| | | public void setReceiptHandle(String receiptHandle) { |
| | | this.receiptHandle = receiptHandle; |
| | | } |
| | | |
| | | public String getQueueName() { |
| | | return queueName; |
| | | } |
| | | |
| | | public void setQueueName(String queueName) { |
| | | this.queueName = queueName; |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | package com.ks.push.manager; |
| | | |
| | | import com.ks.push.dao.BPushTaskDao; |
| | | import com.ks.push.dto.BPushDeviceDataSet; |
| | | import com.ks.push.mapper.BPushTaskExcuteResultMapper; |
| | | import com.ks.push.pojo.DO.BPushTask; |
| | | import com.ks.push.pojo.DO.BPushTaskExcuteResult; |
| | | import com.ks.push.pojo.DO.PushPlatform; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | public class PushExcuteResultManager { |
| | | @Resource |
| | | private BPushTaskExcuteResultMapper bPushTaskExcuteResultMapper; |
| | | |
| | | @Resource |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | @Resource |
| | | private BPushTaskDao bPushTaskDao; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void initPushExcuteResult(String taskId, PushPlatform pushPlatform, long deviceCount) { |
| | | public BPushTaskExcuteResult initPushExcuteResult(String taskId, PushPlatform pushPlatform, long deviceCount) { |
| | | BPushTaskExcuteResult result = new BPushTaskExcuteResult(); |
| | | result.setCreateTime(new Date()); |
| | | result.setFinish(false); |
| | |
| | | result.setId(BPushTaskExcuteResult.createId(taskId, pushPlatform)); |
| | | //初始化 |
| | | bPushTaskExcuteResultMapper.insertSelective(result); |
| | | |
| | | String key = getRedisKey(taskId, pushPlatform); |
| | | redisTemplate.delete(key); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 批量推送成功 |
| | | * |
| | | * @param dataSet |
| | | * @param pushPlatform |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void batchPushSuccess(BPushDeviceDataSet dataSet, PushPlatform pushPlatform) { |
| | | String id = BPushTaskExcuteResult.createId(dataSet.getTaskId(), pushPlatform); |
| | | BPushTaskExcuteResult result = bPushTaskExcuteResultMapper.selectByPrimaryKeyForUpdate(id); |
| | | if (result != null) { |
| | | BPushTaskExcuteResult update = new BPushTaskExcuteResult(); |
| | | update.setId(result.getId()); |
| | | update.setPushSuccessDeviceCount(dataSet.getDeviceTokenList().size() + (result.getPushSuccessDeviceCount() == null ? 0 : result.getPushSuccessDeviceCount())); |
| | | update.setUpdateTime(new Date()); |
| | | bPushTaskExcuteResultMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 批量推送完成 |
| | | * |
| | | * @param dataSet |
| | | * @param pushPlatform |
| | | */ |
| | | public void batchPushFinish(BPushDeviceDataSet dataSet, PushPlatform pushPlatform) { |
| | | String key = getRedisKey(dataSet.getTaskId(), pushPlatform); |
| | | redisTemplate.opsForSet().remove(key, dataSet.getBatchId()); |
| | | Long size = redisTemplate.opsForSet().size(key); |
| | | //判断是否推送完成 |
| | | if (size == null || size == 0L) { |
| | | //已经推送完了 |
| | | String id = BPushTaskExcuteResult.createId(dataSet.getTaskId(), pushPlatform); |
| | | BPushTaskExcuteResult update = new BPushTaskExcuteResult(); |
| | | update.setId(id); |
| | | update.setFinish(true); |
| | | update.setFinishTime(new Date()); |
| | | update.setUpdateTime(new Date()); |
| | | bPushTaskExcuteResultMapper.updateByPrimaryKeySelective(update); |
| | | redisTemplate.delete(key); |
| | | //判断整个推送任务是否已经完成了 |
| | | if (pushTaskFinish(dataSet.getTaskId())) { |
| | | //完成推送了 |
| | | BPushTask updateTask = new BPushTask(); |
| | | updateTask.setId(dataSet.getTaskId()); |
| | | updateTask.setState(BPushTask.STATE_FINSIH); |
| | | updateTask.setStateDesc("推送完成"); |
| | | updateTask.setUpdateTime(new Date()); |
| | | bPushTaskDao.updateSelective(updateTask); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 整个推送任务是否已经完成 |
| | | * |
| | | * @param taskId |
| | | * @return |
| | | */ |
| | | public boolean pushTaskFinish(String taskId) { |
| | | BPushTaskExcuteResultMapper.DaoQuery daoQuery = new BPushTaskExcuteResultMapper.DaoQuery(); |
| | | daoQuery.taskId = taskId; |
| | | long count = bPushTaskExcuteResultMapper.count(daoQuery); |
| | | daoQuery.count = (int) count; |
| | | List<BPushTaskExcuteResult> list = bPushTaskExcuteResultMapper.list(daoQuery); |
| | | int finishCount = 0; |
| | | for (BPushTaskExcuteResult result : list) { |
| | | if (result.getFinish() != null && result.getFinish()) { |
| | | finishCount++; |
| | | } |
| | | } |
| | | if (finishCount == list.size()) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 开始批量推送 |
| | | * |
| | | * @param taskId |
| | | * @param pushPlatform |
| | | * @param batchId |
| | | */ |
| | | public void startBatchPush(String taskId, PushPlatform pushPlatform, String batchId) { |
| | | String key = getRedisKey(taskId, pushPlatform); |
| | | redisTemplate.opsForSet().add(key, batchId); |
| | | } |
| | | |
| | | private String getRedisKey(String taskId, PushPlatform pushPlatform) { |
| | | return String.format("push-task-batch-%s-%s", taskId, pushPlatform.name()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置设备数量 |
| | | * |
| | | * @param id |
| | | * @param count |
| | | */ |
| | | public void setDeviceCount(String id, Long count) { |
| | | BPushTaskExcuteResult update = new BPushTaskExcuteResult(); |
| | | update.setId(id); |
| | | update.setTotalDeviceCount(count); |
| | | update.setUpdateTime(new Date()); |
| | | bPushTaskExcuteResultMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | |
| | | |
| | |
| | | import com.ks.push.pojo.DO.BPushDeviceToken; |
| | | import com.ks.push.pojo.DO.BPushPlatformAppInfo; |
| | | import com.ks.push.pojo.DO.BPushTask; |
| | | import com.ks.push.pojo.DO.BPushTaskExcuteResult; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.validation.Valid; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | |
| | | @Resource |
| | | private PushExcuteResultManager pushExcuteResultManager; |
| | | |
| | | @Resource |
| | | private CMQManager cmqManager; |
| | | |
| | | |
| | | /** |
| | |
| | | // 查询可推送的平台 |
| | | List<BPushPlatformAppInfo> list = bPushPlatformAppInfoManager.listByAppCode(task.getAppCode()); |
| | | |
| | | //先初始化推送结果数据数据 |
| | | List<BPushTaskExcuteResult> resultList = new ArrayList<>(); |
| | | Map<String, Long> resultCountMap = new HashMap<>(); |
| | | for (BPushPlatformAppInfo appInfo : list) { |
| | | long count = pushDeviceTokenManager.count(task.getAppCode(), appInfo.getPlatform(), task.getFilter()); |
| | | if (count > 0) { |
| | | hasDevice = true; |
| | | //初始化推送结果数据 |
| | | pushExcuteResultManager.initPushExcuteResult(taskId, appInfo.getPlatform(), count); |
| | | //将数据加入到cmq |
| | | int pageSize = 500; |
| | | int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); |
| | | for (int page = 0; page < totalPage; page++) { |
| | | List<BPushDeviceToken> deviceTokenList = pushDeviceTokenManager.list(task.getAppCode(), appInfo.getPlatform(), task.getFilter(), page + 1, pageSize); |
| | | List<String> tokenList = new ArrayList<>(); |
| | | for (BPushDeviceToken deviceToken : deviceTokenList) { |
| | | tokenList.add(deviceToken.getToken()); |
| | | } |
| | | BPushDeviceDataSet dataSet = new BPushDeviceDataSet(tokenList, page + "", taskId); |
| | | cmqManager.addToPushQueue(appInfo.getPlatform(), dataSet); |
| | | } |
| | | |
| | | logger.info("加入推送队列#任务Id:{}#平台:{}#推送数量:{}", task.getId(), appInfo.getPlatform().name(), count); |
| | | BPushTaskExcuteResult result = pushExcuteResultManager.initPushExcuteResult(taskId, appInfo.getPlatform(), count); |
| | | resultCountMap.put(result.getId(), count); |
| | | resultList.add(result); |
| | | } |
| | | } |
| | | |
| | | |
| | | for (BPushTaskExcuteResult result : resultList) { |
| | | long count = resultCountMap.get(result.getId()); |
| | | int pageSize = 500; |
| | | int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); |
| | | long totalValidCount = 0L; |
| | | |
| | | //初始化批量推送的计数 |
| | | for (int page = 0; page < totalPage; page++) { |
| | | pushExcuteResultManager.startBatchPush(taskId, result.getPushPlatform(), page + ""); |
| | | } |
| | | |
| | | for (int page = 0; page < totalPage; page++) { |
| | | List<BPushDeviceToken> deviceTokenList = pushDeviceTokenManager.list(task.getAppCode(), result.getPushPlatform(), task.getFilter(), page + 1, pageSize); |
| | | |
| | | List<String> tokenList = new ArrayList<>(); |
| | | for (BPushDeviceToken deviceToken : deviceTokenList) { |
| | | //TODO 时间判断 |
| | | tokenList.add(deviceToken.getToken()); |
| | | } |
| | | totalValidCount += tokenList.size(); |
| | | BPushDeviceDataSet dataSet = new BPushDeviceDataSet(tokenList, page + "", taskId); |
| | | //最后一页 |
| | | if (page == totalPage - 1 && totalValidCount != count) { |
| | | //修改总数 |
| | | pushExcuteResultManager.setDeviceCount(result.getId(), totalValidCount); |
| | | } |
| | | CMQManager.getInstance().addToPushQueue(result.getPushPlatform(), dataSet); |
| | | } |
| | | logger.info("加入推送队列#任务Id:{}#平台:{}#推送数量:{}", task.getId(), result.getPushPlatform().name(), count); |
| | | } |
| | | } finally { |
| | | redisTemplate.delete(key); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 暂停推送 |
| | | * |
| | | * @param taskId |
| | | * @throws BPushTaskException |
| | | */ |
| | | public void pausePush(String taskId) throws BPushTaskException { |
| | | //验证状态 |
| | | BPushTask task = bPushTaskDao.get(taskId); |
| | |
| | | if (task.getState() != BPushTask.STATE_PUSHING) { |
| | | throw new BPushTaskException(2, "处于推送中状态的推送才可暂停"); |
| | | } |
| | | |
| | | updateState(taskId, BPushTask.STATE_PAUSED, null); |
| | | |
| | | logger.info("暂停推送#taskId:{}", task.getId()); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 重新推送(处于暂停状态的数据才能重新推送) |
| | | * |
| | | * @param taskId |
| | | * @throws BPushTaskException |
| | | */ |
| | | public void reStartPush(String taskId) throws BPushTaskException { |
| | | //验证状态 |
| | | BPushTask task = bPushTaskDao.get(taskId); |
| | |
| | | if (task.getState() != BPushTask.STATE_PAUSED) { |
| | | throw new BPushTaskException(2, "处于暂停状态的推送才可重新开始推送"); |
| | | } |
| | | |
| | | updateState(taskId, BPushTask.STATE_PUSHING, "重新推送"); |
| | | |
| | | logger.info("重新推送#taskId:{}", task.getId()); |
| | | } |
| | | |
| | | /** |
| | | * 取消推送(处于暂停/推送中状态的推送才可取消) |
| | | * |
| | | * @param taskId |
| | | * @throws BPushTaskException |
| | | */ |
| | | public void cancelPush(String taskId) throws BPushTaskException { |
| | | //验证状态 |
| | | BPushTask task = bPushTaskDao.get(taskId); |
New file |
| | |
| | | package com.ks.push.mapper; |
| | | |
| | | import com.ks.lib.common.dao.BaseMapper; |
| | | import com.ks.push.entity.AdminUser; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | @Repository |
| | | public interface AdminUserMapper extends BaseMapper<AdminUser> { |
| | | /** |
| | | * 根据账号查询 |
| | | * |
| | | * @param account |
| | | * @return |
| | | */ |
| | | AdminUser selectByAccount(String account); |
| | | } |
| | |
| | | |
| | | import com.ks.lib.common.dao.BaseMapper; |
| | | import com.ks.push.pojo.DO.BPushTaskExcuteResult; |
| | | import com.ks.push.pojo.DO.PushPlatform; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface BPushTaskExcuteResultMapper extends BaseMapper<BPushTaskExcuteResult> { |
| | | |
| | | } |
| | | BPushTaskExcuteResult selectByPrimaryKeyForUpdate(String id); |
| | | |
| | | |
| | | List<BPushTaskExcuteResult> list(@Param("query") DaoQuery query); |
| | | |
| | | long count(@Param("query") DaoQuery query); |
| | | |
| | | |
| | | public static class DaoQuery { |
| | | public String taskId; |
| | | public PushPlatform pushPlatform; |
| | | public Boolean finish; |
| | | public int start; |
| | | public int count; |
| | | } |
| | | } |
| | |
| | | package com.ks.push.service.remote; |
| | | |
| | | import com.ks.lib.common.exception.ParamsException; |
| | | import com.ks.push.dao.BPushDeviceTokenDao; |
| | | import com.ks.push.exception.BPushDeviceTokenException; |
| | | import com.ks.push.pojo.DO.BPushDeviceToken; |
| | | import com.ks.push.service.BDeviceTokenService; |
| | | import org.apache.dubbo.config.annotation.Service; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.yeshi.utils.StringUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | |
| | | @Service(version = "1.0") |
| | | public class BDeviceTokenServiceImpl implements BDeviceTokenService { |
| | | @Override |
| | | public void save(BPushDeviceToken deviceToken) throws BPushDeviceTokenException { |
| | | |
| | | @Resource |
| | | private BPushDeviceTokenDao bPushDeviceTokenDao; |
| | | |
| | | @Override |
| | | public void save(BPushDeviceToken deviceToken) throws ParamsException, BPushDeviceTokenException { |
| | | if (deviceToken == null) { |
| | | throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "对象为空"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(deviceToken.getAppCode())) { |
| | | throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "appcode为空"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(deviceToken.getDeviceId())) { |
| | | throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "设备ID为空"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(deviceToken.getToken())) { |
| | | throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "token为空"); |
| | | } |
| | | String id = BPushDeviceToken.createId(deviceToken.getAppCode(), deviceToken.getDeviceId()); |
| | | if (bPushDeviceTokenDao.get(id) == null) { |
| | | //新增 |
| | | if (deviceToken.getCreateTime() == null) { |
| | | deviceToken.setCreateTime(new Date()); |
| | | } |
| | | deviceToken.setUpdateTime(new Date()); |
| | | bPushDeviceTokenDao.save(deviceToken); |
| | | } else { |
| | | //更新 |
| | | deviceToken.setId(id); |
| | | bPushDeviceTokenDao.updateSelective(deviceToken); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByDeviceId(String appCode, String deviceId) { |
| | | |
| | | String id = BPushDeviceToken.createId(appCode, deviceId); |
| | | bPushDeviceTokenDao.delete(id); |
| | | } |
| | | |
| | | @Override |
| | | public void unBindUid(String appCode, String deviceId) { |
| | | |
| | | String id = BPushDeviceToken.createId(appCode, deviceId); |
| | | Update update = new Update(); |
| | | update.set("uid", null); |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("_id").is(id)); |
| | | bPushDeviceTokenDao.update(query, update); |
| | | } |
| | | |
| | | @Override |
| | | public void bindUid(String appCode, String deviceId, String uid) { |
| | | |
| | | String id = BPushDeviceToken.createId(appCode, deviceId); |
| | | Update update = new Update(); |
| | | update.set("uid", uid); |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("_id").is(id)); |
| | | bPushDeviceTokenDao.update(query, update); |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void pausePush(String taskId) throws BPushTaskException { |
| | | |
| | | pushManager.pausePush(taskId); |
| | | } |
| | | |
| | | @Override |
| | | public void reStartPush(String taskId) throws BPushTaskException { |
| | | |
| | | pushManager.reStartPush(taskId); |
| | | } |
| | | |
| | | @Override |
| | | public void cancelPush(String taskId) throws BPushTaskException { |
| | | |
| | | pushManager.cancelPush(taskId); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ks.push.utils; |
| | | |
| | | import com.ks.push.pojo.DO.BPushMessage; |
| | | import com.ks.push.pojo.DO.PushPlatform; |
| | | import org.yeshi.utils.push.*; |
| | | import org.yeshi.utils.push.entity.PushAppInfo; |
| | | import org.yeshi.utils.push.entity.PushMessage; |
| | | |
| | | import java.util.List; |
| | | |
| | | public class PushUtil { |
| | | |
| | | /** |
| | | * 推送通知 |
| | | * |
| | | * @param platform |
| | | * @param appInfo |
| | | * @param pushMessage |
| | | * @param tokenList |
| | | * @throws Exception |
| | | */ |
| | | public static void pushNotifyCation(PushPlatform platform, PushAppInfo appInfo, BPushMessage pushMessage, List<String> tokenList) throws Exception { |
| | | if (appInfo == null) { |
| | | throw new Exception("应用参数为空"); |
| | | } |
| | | |
| | | if (pushMessage == null) { |
| | | throw new Exception("消息为空"); |
| | | } |
| | | |
| | | if (tokenList == null || tokenList.size() == 0) { |
| | | throw new Exception("token为空"); |
| | | } |
| | | PushMessage message = new PushMessage(pushMessage.getTitle(), pushMessage.getContent(), pushMessage.getAndroidActivity(), pushMessage.getAndroidActivityScheme(), pushMessage.getAndroidHostPath(), pushMessage.getExtras()); |
| | | |
| | | if (platform == PushPlatform.xm) { |
| | | pushXM(appInfo, message, tokenList); |
| | | } else if (platform == PushPlatform.hw) { |
| | | pushHW(appInfo, message, tokenList); |
| | | } else if (platform == PushPlatform.oppo) { |
| | | pushOPPO(appInfo, message, tokenList); |
| | | } else if (platform == PushPlatform.vivo) { |
| | | pushVIVO(appInfo, message, tokenList); |
| | | } else if (platform == PushPlatform.mz) { |
| | | pushMZ(appInfo, message, tokenList); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 小米推送 |
| | | * |
| | | * @param appInfo |
| | | * @param message |
| | | * @param tokenList |
| | | * @throws Exception |
| | | */ |
| | | private static void pushXM(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception { |
| | | XiaoMiPushUtil.pushNotificationByRegIds(appInfo, message, tokenList); |
| | | } |
| | | |
| | | /** |
| | | * 华为推送 |
| | | * |
| | | * @param appInfo |
| | | * @param message |
| | | * @param tokenList |
| | | * @throws Exception |
| | | */ |
| | | private static void pushHW(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception { |
| | | HuaWeiPushUtil.pushNotificationByTokens(appInfo, message, tokenList); |
| | | } |
| | | |
| | | /** |
| | | * OPPO推送 |
| | | * |
| | | * @param appInfo |
| | | * @param message |
| | | * @param tokenList |
| | | * @throws Exception |
| | | */ |
| | | private static void pushOPPO(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception { |
| | | OppoPushUtil.pushNotificationByRegIds(appInfo, message, tokenList); |
| | | } |
| | | |
| | | /** |
| | | * VIVO推送 |
| | | * |
| | | * @param appInfo |
| | | * @param message |
| | | * @param tokenList |
| | | * @throws Exception |
| | | */ |
| | | private static void pushVIVO(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception { |
| | | VIVOPushUtil.pushNotificationByRegIds(appInfo, message, tokenList); |
| | | } |
| | | |
| | | /** |
| | | * 魅族推送 |
| | | * |
| | | * @param appInfo |
| | | * @param message |
| | | * @param tokenList |
| | | * @throws Exception |
| | | */ |
| | | private static void pushMZ(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception { |
| | | MeiZuPushUtil.pushNotificationByPushId(appInfo, message, tokenList); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | #Yeshi2016@ |
| | | password: 'crs-43yhgz0i:Yeshi2016@' |
| | | timeout: 5000ms |
| | | jedis: |
| | | database: 10 |
| | | lettuce: |
| | | pool: |
| | | max-active: 1024 |
| | | max-wait: 10000ms |
| | | max-idle: 200 |
| | | max-active: 1024 |
| | | database: 6 |
| | | time-between-eviction-runs: 60000ms |
| | | min-idle: 8 |
| | | jedis: |
| | | pool: |
| | | max-active: 1024 |
| | | max-wait: 10000ms |
| | | max-idle: 200 |
| | | time-between-eviction-runs: 60000ms |
| | | min-idle: 8 |
| | | |
| | | |
| | | datasource: |
| | | #jdbc:mysql://gz-cdb-r13d0yi9.sql.tencentcdb.com:62929/ks_goldcorn?serverTimezone=GMT%2B8 |
| | | url: jdbc:mysql://gz-cdb-r13d0yi9.sql.tencentcdb.com:62929/push?serverTimezone=GMT%2B8 |
| | | url: jdbc:mysql://gz-cdb-r13d0yi9.sql.tencentcdb.com:62929/bpush?serverTimezone=GMT%2B8 |
| | | username: root |
| | | password: Yeshi2016@ |
| | | driver-class-name: com.mysql.jdbc.Driver |
| | |
| | | |
| | | dubbo: |
| | | application: |
| | | name: goldcorn-service |
| | | name: push-service |
| | | registry: |
| | | protocol: zookeeper |
| | | address: zookeeper://193.112.35.168:2181 # 134.175.68.214 134.175.68.214:2181 |
| | |
| | | #Yeshi2016@ |
| | | password: 'crs-43yhgz0i:Yeshi2016@' |
| | | timeout: 5000ms |
| | | database: 5 |
| | | database: 10 |
| | | lettuce: |
| | | pool: |
| | | max-active: 1024 |
| | |
| | | |
| | | datasource: |
| | | #jdbc:mysql://gz-cdb-r13d0yi9.sql.tencentcdb.com:62929/ks_goldcorn?serverTimezone=GMT%2B8 |
| | | url: jdbc:mysql://172.16.16.17:3306/ks_goldcorn?serverTimezone=GMT%2B8 |
| | | url: jdbc:mysql://172.16.16.17:3306/bpush?serverTimezone=GMT%2B8 |
| | | username: root |
| | | password: Yeshi2016@ |
| | | driver-class-name: com.mysql.jdbc.Driver |
| | |
| | | |
| | | dubbo: |
| | | application: |
| | | name: goldcorn-service |
| | | name: push-service |
| | | registry: |
| | | protocol: zookeeper |
| | | address: zookeeper://172.16.16.29:2181 # 134.175.68.214 134.175.68.214:2181 |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
| | | <mapper namespace="com.ks.goldcorn.mapper.AdminUserMapper" > |
| | | <resultMap id="BaseResultMap" type="com.ks.goldcorn.entity.AdminUser" > |
| | | <id column="id" property="id" jdbcType="BIGINT" /> |
| | | <result column="account" property="account" jdbcType="VARCHAR" /> |
| | | <result column="pwd" property="pwd" jdbcType="VARCHAR" /> |
| | | <result column="name" property="name" jdbcType="VARCHAR" /> |
| | | <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> |
| | | </resultMap> |
| | | <sql id="Base_Column_List" > |
| | | <mapper namespace="com.ks.push.mapper.AdminUserMapper"> |
| | | <resultMap id="BaseResultMap" type="com.ks.push.entity.AdminUser"> |
| | | <id column="id" property="id" jdbcType="BIGINT"/> |
| | | <result column="account" property="account" jdbcType="VARCHAR"/> |
| | | <result column="pwd" property="pwd" jdbcType="VARCHAR"/> |
| | | <result column="name" property="name" jdbcType="VARCHAR"/> |
| | | <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> |
| | | </resultMap> |
| | | <sql id="Base_Column_List"> |
| | | id, account, pwd, name, create_time |
| | | </sql> |
| | | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" > |
| | | select |
| | | <include refid="Base_Column_List" /> |
| | | from ks_admin |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </select> |
| | | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | from ks_admin |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </select> |
| | | |
| | | <select id="selectByAccount" resultMap="BaseResultMap" parameterType="java.lang.String"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | from ks_admin |
| | | where `account` = #{0} limit 1 |
| | | </select> |
| | | |
| | | |
| | | <select id="selectByAccount" resultMap="BaseResultMap" parameterType="java.lang.String" > |
| | | select |
| | | <include refid="Base_Column_List" /> |
| | | from ks_admin |
| | | where account = #{0} |
| | | </select> |
| | | <select id="selectByAccount" resultMap="BaseResultMap" parameterType="java.lang.String"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | from ks_admin |
| | | where account = #{0} |
| | | </select> |
| | | |
| | | <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" > |
| | | <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> |
| | | delete from ks_admin |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </delete> |
| | | <insert id="insert" parameterType="com.ks.goldcorn.entity.AdminUser" > |
| | | <insert id="insert" parameterType="com.ks.push.entity.AdminUser"> |
| | | insert into ks_admin (id, account, pwd, |
| | | name, create_time) |
| | | values (#{id,jdbcType=BIGINT}, #{account,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR}, |
| | | #{name,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}) |
| | | </insert> |
| | | <insert id="insertSelective" parameterType="com.ks.goldcorn.entity.AdminUser" > |
| | | insert into ks_admin |
| | | <trim prefix="(" suffix=")" suffixOverrides="," > |
| | | <if test="id != null" > |
| | | id, |
| | | </if> |
| | | <if test="account != null" > |
| | | account, |
| | | </if> |
| | | <if test="pwd != null" > |
| | | pwd, |
| | | </if> |
| | | <if test="name != null" > |
| | | name, |
| | | </if> |
| | | <if test="createTime != null" > |
| | | create_time, |
| | | </if> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides="," > |
| | | <if test="id != null" > |
| | | #{id,jdbcType=BIGINT}, |
| | | </if> |
| | | <if test="account != null" > |
| | | #{account,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="pwd != null" > |
| | | #{pwd,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="name != null" > |
| | | #{name,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="createTime != null" > |
| | | #{createTime,jdbcType=TIMESTAMP}, |
| | | </if> |
| | | </trim> |
| | | </insert> |
| | | <update id="updateByPrimaryKeySelective" parameterType="com.ks.goldcorn.entity.AdminUser" > |
| | | update ks_admin |
| | | <set > |
| | | <if test="account != null" > |
| | | account = #{account,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="pwd != null" > |
| | | pwd = #{pwd,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="name != null" > |
| | | name = #{name,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="createTime != null" > |
| | | create_time = #{createTime,jdbcType=TIMESTAMP}, |
| | | </if> |
| | | </set> |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | <update id="updateByPrimaryKey" parameterType="com.ks.goldcorn.entity.AdminUser" > |
| | | <insert id="insertSelective" parameterType="com.ks.push.entity.AdminUser"> |
| | | insert into ks_admin |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="id != null"> |
| | | id, |
| | | </if> |
| | | <if test="account != null"> |
| | | account, |
| | | </if> |
| | | <if test="pwd != null"> |
| | | pwd, |
| | | </if> |
| | | <if test="name != null"> |
| | | name, |
| | | </if> |
| | | <if test="createTime != null"> |
| | | create_time, |
| | | </if> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="id != null"> |
| | | #{id,jdbcType=BIGINT}, |
| | | </if> |
| | | <if test="account != null"> |
| | | #{account,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="pwd != null"> |
| | | #{pwd,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="name != null"> |
| | | #{name,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="createTime != null"> |
| | | #{createTime,jdbcType=TIMESTAMP}, |
| | | </if> |
| | | </trim> |
| | | </insert> |
| | | <update id="updateByPrimaryKeySelective" parameterType="com.ks.push.entity.AdminUser"> |
| | | update ks_admin |
| | | <set> |
| | | <if test="account != null"> |
| | | account = #{account,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="pwd != null"> |
| | | pwd = #{pwd,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="name != null"> |
| | | name = #{name,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="createTime != null"> |
| | | create_time = #{createTime,jdbcType=TIMESTAMP}, |
| | | </if> |
| | | </set> |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | <update id="updateByPrimaryKey" parameterType="com.ks.push.entity.AdminUser"> |
| | | update ks_admin |
| | | set account = #{account,jdbcType=VARCHAR}, |
| | | pwd = #{pwd,jdbcType=VARCHAR}, |
| | |
| | | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select |
| | | <include refid="Base_Column_List"/>from p_push_result where id = #{id,jdbcType=BIGINT} |
| | | </select> |
| | | |
| | | |
| | | <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap" parameterType="java.lang.Long">select |
| | | <include refid="Base_Column_List"/>from p_push_result where id = #{0} for update |
| | | </select> |
| | | <sql id="listWhere"> |
| | | |
| | | <if test="query.taskId!=null"> |
| | | AND task_id=#{query.taskId} |
| | | </if> |
| | | |
| | | <if test="query.pushPlatform!=null"> |
| | | AND platform=#{query.pushPlatform} |
| | | </if> |
| | | |
| | | <if test="query.finish!=null"> |
| | | AND finish=#{query.finish} |
| | | </if> |
| | | |
| | | |
| | | </sql> |
| | | |
| | | <select id="list" resultMap="BaseResultMap"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | from p_push_result where 1=1 |
| | | <include refid="listWhere"></include> |
| | | limit #{query.start},#{query.count} |
| | | </select> |
| | | |
| | | <select id="count" resultType="java.lang.Long"> |
| | | select |
| | | count(*) from p_push_result where 1=1 |
| | | <include refid="listWhere"></include> |
| | | </select> |
| | | |
| | | |
| | | <delete id="deleteByPrimaryKey" |
| | | parameterType="java.lang.Long">delete from p_push_result where id = #{id,jdbcType=BIGINT}</delete> |
| | | <insert id="insert" parameterType="com.ks.push.pojo.DO.BPushTaskExcuteResult" useGeneratedKeys="true" |
| | |
| | | |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <title>金币管理系统</title> |
| | | <title>推送系统管理系统</title> |
| | | <meta name="renderer" content="webkit"> |
| | | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| | | <meta name="viewport" |
| | |
| | | package com.ks; |
| | | |
| | | import com.ks.lib.common.dao.MongodbBaseDao; |
| | | import com.ks.push.pojo.DO.BPushAppInfo; |
| | | import com.ks.push.pojo.DO.BPushDeviceToken; |
| | | import com.ks.push.pojo.DO.BPushTaskExcuteResult; |
| | | import org.yeshi.utils.generater.SpringComponentGenerater; |
| | |
| | | @org.junit.Test |
| | | public void createDao() { |
| | | try { |
| | | SpringComponentGenerater.createMongoDao(new MongoDBDaoData.Builder().setBaseDaoClass(MongodbBaseDao.class).setDaoPackageName("com.ks.push.dao").setEntityClass(BPushDeviceToken.class).create(), "D:\\workspace\\DayBuy\\service-push\\src\\main\\java\\com\\ks\\push\\dao\\"); |
| | | SpringComponentGenerater.createMongoDao(new MongoDBDaoData.Builder().setBaseDaoClass(MongodbBaseDao.class).setDaoPackageName("com.ks.push.dao").setEntityClass(BPushAppInfo.class).create(), "D:\\workspace\\DayBuy\\service-push\\src\\main\\java\\com\\ks\\push\\dao\\"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |