|
@ -0,0 +1,74 @@
|
|
|
package com.yihu.wlyy.job.consult;
|
|
|
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamMemberDao;
|
|
|
import com.yihu.wlyy.util.ImUtill;
|
|
|
import org.json.JSONObject;
|
|
|
import org.quartz.Job;
|
|
|
import org.quartz.JobExecutionContext;
|
|
|
import org.quartz.JobExecutionException;
|
|
|
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.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 每天同步一次im group团队成员
|
|
|
* @author yeshijie on 2018/5/18.
|
|
|
*/
|
|
|
public class ParticipantsCleanJob implements Job {
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ParticipantsCleanJob.class);
|
|
|
|
|
|
@Value("${im.data_base_name}")
|
|
|
private String imDb;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private ImUtill imUtill;
|
|
|
@Autowired
|
|
|
private DoctorAdminTeamMemberDao doctorAdminTeamMemberDao;
|
|
|
|
|
|
@Override
|
|
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
try{
|
|
|
logger.info("ParticipantsCleanJob start.....");
|
|
|
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
|
|
|
//查询会话列表找出type=3的group会话
|
|
|
StringBuffer sql1 = new StringBuffer();
|
|
|
sql1.append("SELECT s.id,name FROM ").append(imDb).append(".sessions s ").append("WHERE s.type= 3 ");
|
|
|
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql1.toString());
|
|
|
list.stream().forEach(one->{
|
|
|
String sessionId = one.get("id").toString();
|
|
|
String sessionName = one.get("name").toString();
|
|
|
//删除不在团队的成员
|
|
|
StringBuffer sql2 = new StringBuffer();
|
|
|
sql2.append("delete from ").append(imDb).append(".participants WHERE session_id = '")
|
|
|
.append(sessionId).append("' and participant_id not in (")
|
|
|
.append("SELECT doctor_code from wlyy_admin_team_member WHERE team_id = ")
|
|
|
.append(sessionId).append(" and available =1)");
|
|
|
jdbcTemplate.execute(sql2.toString());
|
|
|
//新增团队成员直接调用im接口
|
|
|
List<Doctor> doctors = doctorAdminTeamMemberDao.findAllMembers(Long.parseLong(sessionId));
|
|
|
if(doctors!=null&&doctors.size()>0){
|
|
|
JSONObject participants = new JSONObject();
|
|
|
doctors.forEach(doctor -> {
|
|
|
participants.put(doctor.getCode(),0);
|
|
|
});
|
|
|
imUtill.createSession(participants,"3",sessionName,sessionId);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
logger.info("ParticipantsCleanJob end.....");
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
logger.error("ParticipantsCleanJob error....."+e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|