LiveApplyJob.java
6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.cnlive.shenhe.job;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.entity.ShyChannel;
import com.cnlive.shenhe.entity.ShyComments;
import com.cnlive.shenhe.entity.ShyLiveapply;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.mapper.ShyLiveapplyMapper;
import com.cnlive.shenhe.serviceImpl.ChannelServiceImpl;
import com.cnlive.shenhe.serviceImpl.CommentsServiceImpl;
import com.cnlive.shenhe.serviceImpl.LiveApplyServiceImpl;
import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.cnlive.shenhe.utils.HttpUtil;
import com.cnlive.shenhe.utils.InfoUtil;
import com.cnlive.shenhe.utils.OpenUtil;
import tk.mybatis.mapper.entity.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class LiveApplyJob {
private static Logger logger = LoggerFactory.getLogger(LiveApplyJob.class);
@Value("${spring.localhost.url}")
private String localhost_url;//本机地址
@Autowired
SitesServiceImpl sitesService;
@Autowired
AuditPass Pass;
@Autowired
InfoUtil infoUtil;
@Autowired
LiveApplyServiceImpl liveApplyServiceImpl;
@Autowired
ShyLiveapplyMapper shyLiveApplyMapper;
@Autowired
UsersServiceImpl usersService;
@Scheduled(fixedRate = 60 * 1000)
public void updateLiveApply() {
//遍历免审的spid去更改状态值
ShyLiveapply shyLiveApply = new ShyLiveapply();
shyLiveApply.setShenhe_type(CommonConst.AUDIT_TYPE_FREE);// 审核类型为免审
shyLiveApply.setShenhe_state(CommonConst.AUDIT_INTT);
List<ShyLiveapply> liveApplyList = liveApplyServiceImpl.findshyLiveApply(shyLiveApply);
if (liveApplyList.size() > 0) {
for (ShyLiveapply liveApply : liveApplyList) {
liveApplyServiceImpl.updateLiveApply(liveApply.getId(), "","白名单", CommonConst.AUDIT_SUCCESS,"白名单通过");
}
}
}
/**
* 直播申请邮件通知
*/
@Scheduled(fixedRate = 60 * 1000)
public void liveApplyNotice() {
Example example = new Example(ShyLiveapply.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("shenhe_state", CommonConst.AUDIT_SUCCESS);
criteria.andNotEqualTo("notice_jishu", CommonConst.NOTICE_SUCCESS);
List<ShyLiveapply> shyLiveApplyList = shyLiveApplyMapper.selectByExample(example);
if (shyLiveApplyList.size() > 0) {
logger.info("直播申请邮件通知开始,共"+shyLiveApplyList.size()+"个");
String app_id = "769_jetja50p18"; //开发者对应的id,与app_key相对应
String app_key = "ad101b9152817a79b5c33c3617b96ff91385096ff3b4ba"; //开发者帐号对应的key. 请开发者谨慎保管此值。
String URL = "http://sms.cnlive.com/CnliveM3/email/sendMoreVarEmail.action";//调用邮件发送服务器的地址
for(ShyLiveapply liveApply : shyLiveApplyList){
String startTime=CommonUtils.formatDate(liveApply.getPre_start_time(), "yyyy-MM-dd HH:mm:ss");
String endTime=CommonUtils.isNotNull(liveApply.getPre_end_time())?CommonUtils.formatDate(liveApply.getPre_end_time(), "yyyy-MM-dd HH:mm:ss"):"待定";
String content = liveApply.getSender()+"__"+liveApply.getMobile()+"__"+liveApply.getOrganization()+"__"+liveApply.getTheme()+"__"+startTime+"__"+endTime+"__"+liveApply.getLive_place()+"__"+liveApply.getPush_url()+"__"+liveApply.getPull_url();
String emailAddr = "642522156@qq.com";
String title = "新直播开播申请";
String templateId = "4017";
Integer notice_jishu = CommonConst.NOTICE_INTT;//初始化通知状态
String notice_msg = "";//初始化通知消息
Map<String, String> params = new HashMap<>();
params.put("appId", app_id);
params.put("emailAddr", emailAddr);
params.put("title",title );
params.put("content", content);
params.put("templateId", templateId);
params.put("sign", OpenUtil.sign(params,app_key));
HttpUtil httpUtil = HttpUtil.init();
httpUtil.setParamMap(params);
try {
Map<String, String> post = httpUtil.post(URL);
logger.info(post.get("result"));
JSONObject result=JSONObject.parseObject(post.get("result"));
if (result == null) {
notice_jishu=CommonConst.NOTICE_FAIL;
notice_msg="邮件服务器调用失败,result为空";
}
Integer code = result.getInteger("errorCode");
if (code != 0) {
notice_jishu=CommonConst.NOTICE_FAIL;
notice_msg="邮件服务器调用失败,result返回消息为:"+result.getString("errorMessage");
}else{
notice_jishu=CommonConst.NOTICE_SUCCESS;
notice_msg="邮件发送成功";
}
} catch (Exception e) {
notice_jishu=CommonConst.NOTICE_FAIL;
notice_msg="邮件服务器调用失败,服务器报错了";
}
liveApply.setNotice_jishu(notice_jishu);
liveApply.setNotice_msg(notice_msg);
liveApplyServiceImpl.updateshyLiveApply(liveApply);
}
}
}
/**
* 自动退领
*/
@Scheduled(cron="0 0 0 * * ? ")//每天0点执行
public void autoRetReceive() {
logger.info("直播申请自动退领的进入.....");
ShyLiveapply liveApply = new ShyLiveapply();
liveApply.setShenhe_state(CommonConst.AUDIT_INTT);//审核状态:未审核
liveApply.setReceive(CommonConst.RECEIVE_AFTER);//已领取
List<ShyLiveapply> shyLiveapplyList = liveApplyServiceImpl.findshyLiveApply(liveApply);
if(shyLiveapplyList.size()>0){
for (ShyLiveapply liveapply : shyLiveapplyList) {
logger.info("自动退领的liveApply_id:"+liveapply.getId());
liveapply.setReceive(CommonConst.RECEIVE_BEFORE);//未领取
liveapply.setAuditor(null);
liveApplyServiceImpl.updateshyLiveApply(liveApply);
}
}
}
}