Browse Source

将检查定时消息的任务由admin移到portal

master
lzh 2 years ago
parent
commit
856c88ecde
  1. 2
      mallplus-admin/src/main/java/com/zscat/mallplus/MallAdminApplication.java
  2. 4
      mallplus-admin/src/main/java/com/zscat/mallplus/task/SchedulingTaskComponent.java
  3. 12
      mallplus-portal/pom.xml
  4. 14
      mallplus-portal/src/main/java/com/zscat/mallplus/sms/service/ScheduledService.java
  5. 2
      mallplus-portal/src/main/java/com/zscat/mallplus/ums/service/ISysMessageService.java
  6. 28
      mallplus-portal/src/main/java/com/zscat/mallplus/ums/service/impl/SysMessageServiceImpl.java
  7. 40
      mallplus-portal/src/main/java/com/zscat/mallplus/unipush/SysMessageTaskService.java
  8. 329
      mallplus-portal/src/main/java/com/zscat/mallplus/unipush/UniPushService.java

2
mallplus-admin/src/main/java/com/zscat/mallplus/MallAdminApplication.java

@ -14,7 +14,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@MapperScan({"com.zscat.mallplus.mapper", "com.zscat.mallplus.ums.mapper", "com.zscat.mallplus.sms.mapper", "com.zscat.mallplus.cms.mapper", "com.zscat.mallplus.sys.mapper", "com.zscat.mallplus.oms.mapper", "com.zscat.mallplus.pms.mapper"})
@EnableTransactionManagement
@EnableScheduling
// @EnableScheduling
public class MallAdminApplication {
public static void main(String[] args) {
SpringApplication.run(MallAdminApplication.class, args);

4
mallplus-admin/src/main/java/com/zscat/mallplus/task/SchedulingTaskComponent.java

@ -47,13 +47,13 @@ import java.util.Date;
* @version 1.0
* @since 1.0
*/
@Component
// @Component
public class SchedulingTaskComponent {
@Autowired
private SysMessageTaskService sysMessageTaskService;
@Scheduled(cron = "0 */5 * * * ?")
// @Scheduled(cron = "0 */5 * * * ?")
public void remindVehicle() {
sysMessageTaskService.checkTask();
}

12
mallplus-portal/pom.xml

@ -204,12 +204,12 @@
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.getui.push</groupId>-->
<!-- <artifactId>restful-sdk</artifactId>-->
<!-- <version>1.0.0.11</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>com.getui.push</groupId>
<artifactId>restful-sdk</artifactId>
<version>1.0.0.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

14
mallplus-portal/src/main/java/com/zscat/mallplus/sms/service/ScheduledService.java

@ -1,5 +1,6 @@
package com.zscat.mallplus.sms.service;
import com.zscat.mallplus.unipush.SysMessageTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@ -19,7 +20,7 @@ public class ScheduledService {
@Autowired
private ISmsCouponHistoryService smsCouponHistoryService;
// @Scheduled(cron = "0 0 0 * * ?")
// @Scheduled(cron = "0 0 0 * * ?")
// @Scheduled(cron = "0 0/5 11 * * ?")
@Scheduled(cron = "*/5 * * * * ?")
public void remindVehicle() {
@ -31,6 +32,15 @@ public class ScheduledService {
calendar.setTime(now);
String tomorrow = sdf.format(calendar.getTime());
//查询优惠券历史记录中已超过endTime时间的
smsCouponHistoryService.updateUseStatus(2,tomorrow);
smsCouponHistoryService.updateUseStatus(2, tomorrow);
}
@Autowired
private SysMessageTaskService sysMessageTaskService;
@Scheduled(cron = "0 */5 * * * ?")
public void checkSysMessageTask() {
sysMessageTaskService.checkTask();
}
}

2
mallplus-portal/src/main/java/com/zscat/mallplus/ums/service/ISysMessageService.java

@ -23,4 +23,6 @@ public interface ISysMessageService extends IService<SysMessage> {
IPage<SysMessage> listPageByUserId(Long id, IPage<SysMessage> page);
IPage<SysMessage> listPageOfSys(IPage<SysMessage> page);
void sendToAll(SysMessage sm);
}

28
mallplus-portal/src/main/java/com/zscat/mallplus/ums/service/impl/SysMessageServiceImpl.java

@ -6,8 +6,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zscat.mallplus.ums.entity.SysMessage;
import com.zscat.mallplus.ums.mapper.SysMessageMapper;
import com.zscat.mallplus.ums.service.ISysMessageService;
import com.zscat.mallplus.unipush.UniPushService;
import com.zscat.mallplus.unipush.entity.PushCids;
import com.zscat.mallplus.unipush.mapper.PushCidsMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
@ -21,6 +26,11 @@ import java.util.List;
@Service
public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMessage> implements ISysMessageService {
@Resource
private PushCidsMapper pushCidsMapper;
@Resource
private UniPushService uniPushService;
@Override
public List<SysMessage> listByUserId(Long userId) {
QueryWrapper<SysMessage> qw = new QueryWrapper<>();
@ -53,4 +63,22 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
qw.orderByDesc("ctime");
return this.page(page, qw);
}
@Override
public void sendToAll(SysMessage sm) {
sendPushToAll(sm);
sm.setId(null);
sm.setUserId(1);
this.save(sm);
}
private void sendPushToAll(SysMessage sysMessage) {
List<String> cids = listPushCidAll();
uniPushService.sendPushAsync(sysMessage, cids);
}
private List<String> listPushCidAll() {
List<PushCids> list = pushCidsMapper.selectList(new QueryWrapper<>());
List<String> cids = new ArrayList<>();
list.forEach(ent -> cids.add(ent.getGetuiCid()));
return cids;
}
}

40
mallplus-portal/src/main/java/com/zscat/mallplus/unipush/SysMessageTaskService.java

@ -0,0 +1,40 @@
package com.zscat.mallplus.unipush;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zscat.mallplus.ums.entity.SysMessage;
import com.zscat.mallplus.ums.entity.SysMessageTask;
import com.zscat.mallplus.ums.mapper.SysMessageTaskMapper;
import com.zscat.mallplus.ums.service.ISysMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class SysMessageTaskService extends ServiceImpl<SysMessageTaskMapper, SysMessageTask> {
@Autowired
private ISysMessageService messageService;
public void checkTask() {
QueryWrapper<SysMessageTask> qw = new QueryWrapper<>();
qw.eq("status", 0);
qw.lt("sendtime", new Date());
List<SysMessageTask> list = baseMapper.selectList(qw);
for (SysMessageTask task : list) {
SysMessage sm = new SysMessage();
sm.setCode("系统消息");
sm.setUserId(1);
sm.setId(null);
sm.setContent(task.getContent());
sm.setParams(task.getParams());
sm.setCtime(System.currentTimeMillis());
messageService.sendToAll(sm);
task.setStatus(1);
baseMapper.updateById(task);
}
}
}

329
mallplus-portal/src/main/java/com/zscat/mallplus/unipush/UniPushService.java

@ -0,0 +1,329 @@
package com.zscat.mallplus.unipush;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.json.JSONUtil;
import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import com.getui.push.v2.sdk.common.ApiResult;
import com.getui.push.v2.sdk.dto.req.Audience;
import com.getui.push.v2.sdk.dto.req.AudienceDTO;
import com.getui.push.v2.sdk.dto.req.message.PushDTO;
import com.getui.push.v2.sdk.dto.req.message.PushMessage;
import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
import com.getui.push.v2.sdk.dto.res.TaskIdDTO;
import com.zscat.mallplus.ums.entity.SysMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class UniPushService {
private static final Logger L = LoggerFactory.getLogger(UniPushService.class);
// @Value("${unipush.appid:UBUIDJ8NQm50rGJsB6LYx1}")
// private String appid;
private static String apiurl = "https://restapi.getui.com/v2/";
private static String appid = "UBUIDJ8NQm50rGJsB6LYx1";
private static String appkey = "RS3UZfeS509hcNEkmfS6R";
private static String appsecret = "6QuFcPWFga8DQzSa03ruR7";
private static String mastersecret = "6fjUinwRfDA3BcEnDQvTl5";
private static String apppackage = "org.jbase.yxt.yyd.pyw";
private static PushApi pushApi = null;
private PushApi singlePushApi() {
if (pushApi == null) {
System.setProperty("http.maxConnections", "200");
GtApiConfiguration apiConfiguration = new GtApiConfiguration();
//填写应用配置
apiConfiguration.setAppId(appid);
apiConfiguration.setAppKey(appkey);
apiConfiguration.setMasterSecret(mastersecret);
// 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
apiConfiguration.setDomain(apiurl);
// 实例化ApiHelper对象,用于创建接口对象
ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
// 创建对象,建议复用。目前有PushApi、StatisticApi、UserApi
pushApi = apiHelper.creatApi(PushApi.class);
}
return pushApi;
}
public void test() {
// 设置httpClient最大连接数,当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
System.setProperty("http.maxConnections", "200");
GtApiConfiguration apiConfiguration = new GtApiConfiguration();
//填写应用配置
apiConfiguration.setAppId("UBUIDJ8NQm50rGJsB6LYx1");
apiConfiguration.setAppKey("RS3UZfeS509hcNEkmfS6R");
apiConfiguration.setMasterSecret("6fjUinwRfDA3BcEnDQvTl5");
// 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
apiConfiguration.setDomain("https://restapi.getui.com/v2/");
// 实例化ApiHelper对象,用于创建接口对象
ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
// 创建对象,建议复用。目前有PushApi、StatisticApi、UserApi
PushApi pushApi = apiHelper.creatApi(PushApi.class);
//根据cid进行单推
PushDTO<Audience> pushDTO = new PushDTO<Audience>();
// 设置推送参数
pushDTO.setRequestId(System.currentTimeMillis() + "");
/**** 设置个推通道参数 *****/
PushMessage pushMessage = new PushMessage();
pushDTO.setPushMessage(pushMessage);
GTNotification notification = new GTNotification();
pushMessage.setNotification(notification);
notification.setTitle("测试TitleXXX");
notification.setBody("测试BodyXXXXXX");
String payload = "{\"title\":\"liutitle\",\"body\":\"liubody\",\"name\":\"hao\",\"userid\":101,\"msgtitle\":\"haha\"}";
notification.setPayload(payload);
notification.setClickType("payload");
// notification.setClickType("url");
// notification.setUrl("https://www.getui.com");
/**** 设置个推通道参数,更多参数请查看文档或对象源码 *****/
// /**** 设置厂商相关参数 ****/
// PushChannel pushChannel = new PushChannel();
// pushDTO.setPushChannel(pushChannel);
// /*配置安卓厂商参数*/
// AndroidDTO androidDTO = new AndroidDTO();
// pushChannel.setAndroid(androidDTO);
// Ups ups = new Ups();
// androidDTO.setUps(ups);
// ThirdNotification thirdNotification = new ThirdNotification();
// ups.setNotification(thirdNotification);
// thirdNotification.setTitle("厂商title");
// thirdNotification.setBody("厂商body");
// thirdNotification.setClickType("url");
// thirdNotification.setUrl("https://www.getui.com");
// // 两条消息的notify_id相同,新的消息会覆盖老的消息,取值范围:0-2147483647
// // thirdNotification.setNotifyId("11177");
// /*配置安卓厂商参数结束,更多参数请查看文档或对象源码*/
// /*设置ios厂商参数*/
// IosDTO iosDTO = new IosDTO();
// pushChannel.setIos(iosDTO);
// // 相同的collapseId会覆盖之前的消息
// iosDTO.setApnsCollapseId("xxx");
// Aps aps = new Aps();
// iosDTO.setAps(aps);
// Alert alert = new Alert();
// aps.setAlert(alert);
// alert.setTitle("ios title");
// alert.setBody("ios body");
// /*设置ios厂商参数结束,更多参数请查看文档或对象源码*/
/*设置接收人信息*/
Audience audience = new Audience();
pushDTO.setAudience(audience);
audience.addCid("89e286aee78d38faf748a690e603b1a3");
/*设置接收人信息结束*/
/**** 设置厂商相关参数,更多参数请查看文档或对象源码 ****/
// 进行cid单推
ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushToSingleByCid(pushDTO);
if (apiResult.isSuccess()) {
// success
System.out.println(apiResult.getData());
} else {
// failed
System.out.println("code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
}
}
public void testlist() {
String taskid = createMessageTaskaa();
AudienceDTO pdto = new AudienceDTO();
Audience audience = new Audience();
audience.addCid("89e286aee78d38faf748a690e603b1a3");
audience.addCid("e4a96929cc5f40c886cb517853356bc2");
pdto.setAudience(audience);
pdto.setTaskid(taskid);
ApiResult<Map<String, Map<String, String>>> mapApiResult = singlePushApi().pushListByCid(pdto);
System.out.println(mapApiResult);
}
public String createMessageTaskaa() {
PushDTO<Audience> pdto = new PushDTO<>();
pdto.setGroupName("群发消息");
PushMessage pushMessage = new PushMessage();
GTNotification notification = new GTNotification();
notification.setTitle("测试Titleaa");
notification.setBody("测试BodyXaa");
SysMessage msg = new SysMessage();
msg.setId(11);
msg.setUserId(1);
msg.setCode("云链助手");
msg.setParams("欢迎");
msg.setContent("欢迎注册汇融云链~");
msg.setCtime(System.currentTimeMillis());
// String payload = "{\"title\":\"lzh\",\"body\":\"liubody\",\"name\":\"hao\",\"userid\":101,\"msgtitle\":\"haha\"}";
String payload = JSONUtil.toJsonStr(msg);
notification.setPayload(payload);
notification.setClickType("payload");
pushMessage.setNotification(notification);
pdto.setPushMessage(pushMessage);
ApiResult<TaskIdDTO> msgg = this.singlePushApi().createMsg(pdto);
System.out.println(msgg);
return msgg.getData().getTaskId();
}
public static void main(String[] args) {
List<String> clist = new ArrayList<>();
clist.add("079fb42d1f4f824a3defd471a432d0fe");
clist.add("89e286aee78d38faf748a690e603b1a3");
SysMessage msg = new SysMessage();
msg.setId(11);
msg.setUserId(1);
msg.setCode("交易物流");
msg.setParams("ABC");
msg.setContent("欢迎注册汇融云链~");
msg.setCtime(System.currentTimeMillis());
new UniPushService().sendPush(msg, clist);
// new UniPushService().testlist();
}
private static String imgUrltx = "http://mall.yyundong.com/tx.png";
private static String imgUrltz = "http://mall.yyundong.com/tz.png";
private static String imgUrlwl = "http://mall.yyundong.com/wl.png";
public void sendPush(SysMessage mess, List<String> cids) {
// String code = mess.getCode();
// if ("系统消息".equals(code)) {
// sendTzMsg(mess);
// } else {
// sendUserMsg(mess, cids);
// }
if (cids == null || cids.isEmpty())
return;
PushMessage pushMessage = createPushMessage(mess);
int size = cids.size();
for (int i = 0; i < size; i++) {
sendSingleMsg(pushMessage, cids.get(i), i);
}
}
public void sendPushAsync(SysMessage mess, List<String> cids) {
ThreadUtil.execute(() -> sendPush(mess, cids));
}
private void sendSingleMsg(PushMessage pushMessage, String cid, int index) {
PushDTO<Audience> pushDTO = new PushDTO<Audience>();
pushDTO.setRequestId("" + System.currentTimeMillis() + index);
pushDTO.setPushMessage(pushMessage);
Audience audience = new Audience();
audience.addCid(cid);
pushDTO.setAudience(audience);
ApiResult<Map<String, Map<String, String>>> apiResult = singlePushApi().pushToSingleByCid(pushDTO);
if (apiResult.isSuccess()) {
System.out.println(apiResult.getData());
} else {
L.warn("推送信息失败:code:{}, msg: {}", apiResult.getCode(), apiResult.getMsg());
}
}
private void sendUserMsg(SysMessage mess, List<String> cids) {
if (cids == null || cids.isEmpty())
return;
String taskid = createMessageTask(mess);
AudienceDTO pdto = new AudienceDTO();
Audience audience = new Audience();
cids.forEach(cid -> audience.addCid(cid));
pdto.setAudience(audience);
pdto.setTaskid(taskid);
ApiResult<Map<String, Map<String, String>>> mapApiResult = singlePushApi().pushListByCid(pdto);
}
private void sendTzMsg(SysMessage mess) {
PushDTO<String> pd = new PushDTO<>();
pd.setRequestId("all" + System.currentTimeMillis());
pd.setGroupName("system_notice");
pd.setAudience("all");
pd.setPushMessage(createPushMessage(mess));
ApiResult<TaskIdDTO> taskIdDTOApiResult = singlePushApi().pushAll(pd);
// System.out.println(taskIdDTOApiResult);
}
private PushMessage createPushMessage(SysMessage mess) {
String code = mess.getCode();
PushMessage pushMessage = new PushMessage();
GTNotification notification = new GTNotification();
// notification.setTitle(code);
// notification.setBody(mess.getParams());
notification.setTitle(mess.getParams());
notification.setBody(mess.getContent());
if ("交易物流".equals(code)) {
notification.setLogoUrl(imgUrlwl);
} else if ("云链助手".equals(code)) {
notification.setLogoUrl(imgUrltx);
} else {
notification.setLogoUrl(imgUrltz);
}
Map<String, Object> map = new HashMap<>();
map.put("code", mess.getCode());
map.put("params", mess.getParams());
map.put("content", mess.getContent());
map.put("cdate", mess.getCdate());
map.put("id", mess.getId());
map.put("ctime", mess.getCtime());
map.put("status", mess.getStatus());
map.put("userId", mess.getUserId());
String payload = JSONUtil.toJsonStr(map);
notification.setPayload(payload);
notification.setClickType("payload");
// notification.setClickType("payload_custom");
pushMessage.setNotification(notification);
return pushMessage;
}
private String createMessageTask(SysMessage mess) {
PushDTO<Audience> pdto = new PushDTO<>();
pdto.setGroupName("tolist");
pdto.setPushMessage(createPushMessage(mess));
ApiResult<TaskIdDTO> result = this.singlePushApi().createMsg(pdto);
// System.out.println(msgg);
return result.getData().getTaskId();
}
}
Loading…
Cancel
Save