LiveApplyJob.java
8.01 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
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.ShyEmail;
import com.cnlive.shenhe.entity.ShyLiveapply;
import com.cnlive.shenhe.entity.ShySites;
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.EmailServiceImpl;
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 tk.mybatis.mapper.entity.Example.Criteria;
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;//本机地址
@Value("${email_app_id}")
private String email_app_id;//开发者对应的id,与app_key相对应
@Value("${email_app_key}")
private String email_app_key;//开发者帐号对应的key. 请开发者谨慎保管此值。
@Value("${email_send_URL}")
private String email_send_URL;//调用邮件发送服务器的地址
@Autowired
SitesServiceImpl sitesService;
@Autowired
AuditPass Pass;
@Autowired
InfoUtil infoUtil;
@Autowired
LiveApplyServiceImpl liveApplyServiceImpl;
@Autowired
ShyLiveapplyMapper shyLiveApplyMapper;
@Autowired
UsersServiceImpl usersService;
@Autowired
EmailServiceImpl emailServiceImpl;
@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);
Criteria criteria = example.createCriteria();
criteria.andEqualTo("shenhe_state", CommonConst.AUDIT_SUCCESS);
criteria.andNotEqualTo("email_notice_state", CommonConst.NOTICE_SUCCESS);//状态不等于已通知
List<ShyLiveapply> shyLiveApplyList = shyLiveApplyMapper.selectByExample(example);
if (shyLiveApplyList.size() > 0) {
String app_id = email_app_id; //开发者对应的id,与app_key相对应
String app_key = email_app_key; //开发者帐号对应的key. 请开发者谨慎保管此值。
String URL = email_send_URL;//调用邮件发送服务器的地址
List<ShyEmail> shyEmailList=emailServiceImpl.getEmailSendList(CommonConst.EMAIL_LIVEAPPLY);
logger.info("直播申请邮件通知开始,共"+shyLiveApplyList.size()+"个申请,每个申请通知"+shyEmailList.size()+"个邮箱");
for(ShyLiveapply liveApply : shyLiveApplyList){
Integer notice_state = liveApply.getEmail_notice_state();//初始化通知状态
String notice_msg = liveApply.getEmail_notice_msg();//初始化通知消息
//显示spid简称
ShySites shySites = sitesService.findspidDescByspid(liveApply.getSp_id());
if (CommonUtils.isNotNull(shySites)) {
liveApply.setSpid_desc(shySites.getName());
}
for(ShyEmail shyEmail:shyEmailList){//循环需要发送邮件的邮箱
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 dateTime=CommonUtils.getCurrentDate("yyyy-MM-dd HH:mm:ss");//获取一个格式化后的当前时间
String emailAddr = shyEmail.getEmail();
String title = liveApply.getSpid_desc()+"新直播开播申请";
String templateId = "4017";
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_state=CommonConst.NOTICE_FAIL;
notice_msg=notice_msg+"\n"+dateTime+" 邮件服务器调用失败,result为空";
break;
}
Integer code = result.getInteger("errorCode");
if (code != 0) {
notice_state=CommonConst.NOTICE_FAIL;
notice_msg=notice_msg+"\n"+dateTime+" 邮件服务器调用失败,result返回消息为:"+result.getString("errorMessage");
break;
}else{
notice_state=CommonConst.NOTICE_SUCCESS;
notice_msg=notice_msg+"\n"+dateTime+" 邮件"+emailAddr+"("+shyEmail.getRemark()+")发送成功";
}
} catch (Exception e) {
notice_state=CommonConst.NOTICE_FAIL;
notice_msg=notice_msg+"\n"+dateTime+" 邮件服务器调用失败,服务器报错了";
break;
}
}
liveApply.setEmail_notice_state(notice_state);
liveApply.setEmail_notice_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);
}
}
}
}