|
@ -1,16 +1,28 @@
|
|
|
package com.yihu.wlyy.service.imm;
|
|
|
|
|
|
import com.yihu.es.entity.PatientRemindRecordESDO;
|
|
|
import com.yihu.wlyy.config.es.ElasticFactory;
|
|
|
import com.yihu.wlyy.config.es.ElastricSearchSave;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.imm.ChildFamilyImmune;
|
|
|
import com.yihu.wlyy.entity.imm.ChildImmuneVaccin;
|
|
|
import com.yihu.wlyy.entity.imm.ChildInfo;
|
|
|
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
import com.yihu.wlyy.repository.imm.ChildImmuneVaccinDao;
|
|
|
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.third.jw.ImmuneService;
|
|
|
import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
|
|
|
import io.searchbox.client.JestClient;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
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.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@ -24,21 +36,38 @@ import java.util.*;
|
|
|
*/
|
|
|
@Service
|
|
|
public class ChildVaccinImmuneService extends BaseService {
|
|
|
|
|
|
|
|
|
private static org.slf4j.Logger logger = LoggerFactory.getLogger(ChildVaccinImmuneService.class);
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private ChildImmuneVaccinDao childImmuneVaccinDao;
|
|
|
@Autowired
|
|
|
private ImmuneService immuneService;
|
|
|
@Autowired
|
|
|
private DoctorDao doctorDao;
|
|
|
@Value("${es.type.patientRemindRecord}")
|
|
|
private String esType;
|
|
|
@Value("${es.index.patientRemindRecord}")
|
|
|
private String esIndex;
|
|
|
@Autowired
|
|
|
private WechatTemplateConfigDao templateConfigDao;
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
@Autowired
|
|
|
private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
|
|
|
@Autowired
|
|
|
private ElasticFactory elasticFactory;
|
|
|
|
|
|
@Autowired
|
|
|
private ElastricSearchSave elastricSearchSave;
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int getChildImmuneVaccinEveryDay()throws Exception{
|
|
|
int result = 0;
|
|
|
try {
|
|
|
String sql ="SELECT" +
|
|
|
/*String sql ="SELECT" +
|
|
|
" DISTINCT ci.`code`," +
|
|
|
" ci.idcard," +
|
|
|
" ci.`name`," +
|
|
@ -48,7 +77,9 @@ public class ChildVaccinImmuneService extends BaseService {
|
|
|
" wlyy_child_family_immune fi" +
|
|
|
" LEFT JOIN wlyy_child_info ci ON fi.child_code = ci.`code`" +
|
|
|
" WHERE" +
|
|
|
" fi.del = 0";
|
|
|
" fi.del = 0";*/
|
|
|
|
|
|
String sql ="SELECT `code`,`name`,idcard,ssc FROM wlyy_child_info WHERE del=0";
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String,Object> map : list){
|
|
|
String barcode = String.valueOf(map.get("barcode"));
|
|
@ -165,4 +196,140 @@ public class ChildVaccinImmuneService extends BaseService {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public int alertBefore()throws Exception{
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
String sql ="SELECT" +
|
|
|
" v.*, i.birthday" +
|
|
|
" FROM" +
|
|
|
" wlyy_child_immune_vaccin v" +
|
|
|
" LEFT JOIN wlyy_child_info i ON v.child_info_code = i.`code`" +
|
|
|
" WHERE" +
|
|
|
" v.del = 0" +
|
|
|
" AND ymkc = 'true'";
|
|
|
List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
|
|
|
String nowDate = DateUtil.dateToStrShort(new Date());
|
|
|
for (Map<String,Object> map : mapList){
|
|
|
Calendar calendar=Calendar.getInstance();
|
|
|
String birthDayStr = String.valueOf(map.get("birthday"));
|
|
|
if (StringUtils.isNotBlank(birthDayStr)){
|
|
|
String[] biStr = birthDayStr.split("-");
|
|
|
int birthdayDate = Integer.valueOf(biStr[biStr.length-1]);
|
|
|
int nowDayDate = calendar.get(GregorianCalendar.DAY_OF_MONTH);
|
|
|
int nowMonthDate = calendar.get(GregorianCalendar.MONTH)+1;
|
|
|
int nowYearDate = calendar.get(GregorianCalendar.YEAR);
|
|
|
//如果生日在今天的日期之前,则取下个月生日的日期的15天的是否是今天.
|
|
|
if (birthdayDate<nowDayDate){
|
|
|
calendar.set(nowYearDate,nowMonthDate+1,birthdayDate);
|
|
|
}else {
|
|
|
//如果生日在今天之前后,则看生日的15天之前是否是今天
|
|
|
calendar.set(nowYearDate,nowMonthDate,birthdayDate);
|
|
|
}
|
|
|
String needAlertDate = DateUtil.dateToStrShort(DateUtil.getPreDays(calendar.getTime(),-15));
|
|
|
if (needAlertDate.equals(nowDate)){
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("vaccinCode",map.get("code"));//待接种疫苗记录code
|
|
|
jsonObject.put("childName", map.get("name"));//儿童姓名
|
|
|
jsonObject.put("childCode", map.get("child_info_code"));//儿童code
|
|
|
jsonObject.put("vaccinName", map.get("ymmc"));//疫苗名称
|
|
|
jsonArray.put(jsonObject);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return alertImmVacclinByChildInfoCodes(jsonArray.toString());
|
|
|
}
|
|
|
|
|
|
public int alertImmVacclinByChildInfoCodes(String alertDataJsonStr)throws Exception{
|
|
|
if (StringUtils.isEmpty(alertDataJsonStr)){
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
List<PatientRemindRecordESDO> patientRemindRecordESDOList = new ArrayList<>();
|
|
|
JSONArray jsonArray = new JSONArray(alertDataJsonStr);
|
|
|
for (int i=0;i<jsonArray.length();i++){
|
|
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
String childCode = jsonObject.getString("childCode");
|
|
|
String childName = jsonObject.getString("childName");
|
|
|
String vaccinName = jsonObject.getString("vaccinName");
|
|
|
String vaccinCode = jsonObject.getString("vaccinCode");
|
|
|
String sql ="SELECT" +
|
|
|
" cfi.relation," +
|
|
|
" p.`code`," +
|
|
|
" p.`name`," +
|
|
|
" p.openid" +
|
|
|
" FROM" +
|
|
|
" wlyy_child_family_immune cfi" +
|
|
|
" LEFT JOIN wlyy_patient p ON cfi.family_code = p.`code`" +
|
|
|
" WHERE" +
|
|
|
" cfi.child_code = '"+childCode+"'" +
|
|
|
" AND cfi.del = 0 and (p.openid is not null or p.openid !='')";
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
if (list.size()==0){
|
|
|
return -10000;
|
|
|
}
|
|
|
List<String> openIdList = new ArrayList<>();
|
|
|
for (Map<String,Object> map : list){
|
|
|
//如果父母亲都在就都发
|
|
|
if (!openIdList.contains(String.valueOf(map.get("openid")))){
|
|
|
if (("1".equals(String.valueOf(map.get("relation"))) || "2".equals(String.valueOf(map.get("relation")))) && StringUtils.isNotBlank(String.valueOf(map.get("openid")))){
|
|
|
boolean flag =true;
|
|
|
try {
|
|
|
WechatTemplateConfig temp = templateConfigDao.findByScene("template_deal_with_job", "dsymjztx");
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("toUser",String.valueOf(map.get("code")));
|
|
|
json.put("keyword1", temp.getKeyword1().replace("key1",DateUtil.dateToStr(new Date(), "yyyy-MM-dd")));
|
|
|
json.put("keyword2", temp.getKeyword2().replace("key1", vaccinName));
|
|
|
json.put("remark", temp.getRemark());
|
|
|
json.put("first", temp.getFirst().replace("key1", childName));
|
|
|
logger.info("weiTempJOSN:"+json.toString());
|
|
|
pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 24,String.valueOf(map.get("openid")) , String.valueOf(map.get("name")), json);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
flag = false;
|
|
|
}
|
|
|
//发送微信消息并且插入一条es提醒数据
|
|
|
PatientRemindRecordESDO patientRemindRecordESDO = new PatientRemindRecordESDO();
|
|
|
patientRemindRecordESDO.setCode(getCode());
|
|
|
patientRemindRecordESDO.setPatient(String.valueOf(map.get("code")));
|
|
|
patientRemindRecordESDO.setPatientName(String.valueOf(map.get("name")));
|
|
|
patientRemindRecordESDO.setDoctor("admin");
|
|
|
patientRemindRecordESDO.setDoctorName("admin");
|
|
|
patientRemindRecordESDO.setCreateDate(new Date());
|
|
|
patientRemindRecordESDO.setRemindType(1);
|
|
|
if (flag) {
|
|
|
patientRemindRecordESDO.setStatus(1);
|
|
|
String update="UPDATE wlyy_child_immune_vaccin SET alert_tag=1,alert_time='"+DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD_HH_MM_SS)+"' where `code`='"+vaccinCode+"'";
|
|
|
jdbcTemplate.update(update);
|
|
|
}else {
|
|
|
patientRemindRecordESDO.setStatus(0);
|
|
|
}
|
|
|
patientRemindRecordESDOList.add(patientRemindRecordESDO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//保存到es的提醒日志表中
|
|
|
esSavePatientRemindRecord(patientRemindRecordESDOList);
|
|
|
return 200;
|
|
|
}
|
|
|
|
|
|
public boolean esSavePatientRemindRecord(List<PatientRemindRecordESDO> patientRemindRecordESDOList)throws Exception{
|
|
|
JestClient jestClient = null;
|
|
|
boolean flag = true;
|
|
|
try {
|
|
|
jestClient = elasticFactory.getJestClient();
|
|
|
if(patientRemindRecordESDOList != null && patientRemindRecordESDOList.size()>0){
|
|
|
flag = elastricSearchSave.save(patientRemindRecordESDOList, esIndex, esType);
|
|
|
}
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
flag = false;
|
|
|
} finally{
|
|
|
if (jestClient != null) {
|
|
|
jestClient.shutdownClient();
|
|
|
}
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
}
|