2023年10月24日 新增关闭教室定时任务

This commit is contained in:
bai 2023-10-24 11:31:34 +08:00
parent da94a1a426
commit 871cd07712
1 changed files with 135 additions and 0 deletions

View File

@ -0,0 +1,135 @@
package org.jeecg.modules.kc.grab.SynchronizationService;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.beust.jcommander.internal.Sets;
import com.xkcoding.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.kc.grab.SynchronizationService.base.BaseSync;
import org.jeecg.modules.kc.jiaoshi.entity.KcZhihuijiaoshi;
import org.jeecg.modules.kc.jiaoshi.entity.KcZhihuijiaoshiOperateLog;
import org.jeecg.modules.kc.jiaoshi.service.IKcZhihuijiaoshiOperateLogService;
import org.jeecg.modules.kc.jiaoshi.service.IKcZhihuijiaoshiService;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Slf4j
public class RefreshCloseLiveServer extends BaseSync {
@Autowired
private IKcZhihuijiaoshiService kcZhihuijiaoshiService;
@Autowired
private IKcZhihuijiaoshiOperateLogService kcZhihuijiaoshiOperateLogService;
/**
* 若参数变量名修改 QuartzJobController中也需对应修改
*/
@Override
public void execute(JobExecutionContext jobExecutionContext) {
start();
run(getParamMap());
end();
}
/**
* 有参定时任务实现
* @param param 执行参数
*/
public void run(Map<String, Object> param){
QueryWrapper<KcZhihuijiaoshi> qw = new QueryWrapper<KcZhihuijiaoshi>();
qw.eq("xm","教师近景");
List<KcZhihuijiaoshi> list = kcZhihuijiaoshiService.list(qw);
// Map<Integer,Boolean> liveOnMap = Maps.newHashMap();
Set<Integer> onList = Sets.newHashSet();
Set<Integer> outList = Sets.newHashSet();
list.forEach(x -> {
try{
String res = HttpUtil.get(x.getPullUrl());
// liveOnMap.put(x.getId(),true);
onList.add(x.getId());
log.info("返回内容:" + res);//live_setParam_ret=ok
} catch (Exception e){
KcZhihuijiaoshiOperateLog operateLog = new KcZhihuijiaoshiOperateLog();
// liveOnMap.put(x.getId(),false);
outList.add(x.getId());
log.error(e.getMessage(),e);
//打开推送开关
//访问汇总结果
//http://${ip}/cgi-bin/plat.cgi?action=9&user=${user}&pwsd=${getMd5Str(pwd)}&command=1
String hex = Convert.toHex("live_setParam_enable=0", CharsetUtil.CHARSET_UTF_8);
String buildUrl = UrlBuilder.create()
.setScheme("http")
.setHost(x.getIp())
.addPath("/cgi-bin")
.addPath("/plat.cgi")
.addQuery("action", "9")
.addQuery("user", x.getUser())
.addQuery("pwsd", SecureUtil.md5(x.getMima()))
.addQuery("command", "1")
.addQuery("data", hex)
.build();
log.info("访问奥威亚接口地址"+buildUrl);
// Map<String,String> rm = Maps.newHashMap();
// rm.put("xm",x.getXm());
// rm.put("jsmc",x.getJsmc());
// rm.put("url",buildUrl);
operateLog.setOperateUrl(buildUrl);//操作URL
operateLog.setJxlId(x.getJxlId());//教学楼ID
operateLog.setJxlName(x.getJxlName());//教学楼名称
operateLog.setJsbh(x.getJsbh());//教室编号
operateLog.setJsmc(x.getJsmc());//教室名称
operateLog.setOperateType("0");//操作类型打开还是关闭
operateLog.setLogType(1);//日志类型
operateLog.setOperateResultType("0");//调用成功还是失败
try{
String resText = HttpUtil.get(buildUrl);
log.info("奥威亚返回接口内容:" + resText);//live_setParam_ret=ok
// rm.put("resText",resText);
operateLog.setOperateResult(resText);
// res.setResult(rm);
} catch (Exception e2){
log.error(e2.getMessage(),e2);
// rm.put("resText",e2.getMessage());
operateLog.setOperateResultType("1");
operateLog.setOperateResult(e2.getMessage());
// res.setResult(rm);
}finally {
kcZhihuijiaoshiOperateLogService.save(operateLog);
}
}
});
if(!onList.isEmpty()){
UpdateWrapper<KcZhihuijiaoshi> onUw = new UpdateWrapper<>();
onUw.set("sfyx",0);
onUw.in("id",onList);
kcZhihuijiaoshiService.update(onUw);
}
if(!outList.isEmpty()) {
UpdateWrapper<KcZhihuijiaoshi> outUw = new UpdateWrapper<>();
outUw.set("sfyx", 1);
outUw.in("id", outList);
kcZhihuijiaoshiService.update(outUw);
}
}
/**
* 无参定时任务实现
*/
public void run(){
run(null);
}
}