|
@ -1,22 +1,35 @@
|
|
|
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.ChildFamilyImmuneDao;
|
|
|
import com.yihu.wlyy.repository.imm.ChildImmuneVaccinDao;
|
|
|
import com.yihu.wlyy.repository.imm.ChildInfoDao;
|
|
|
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.third.guahao.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;
|
|
|
|
|
|
import java.sql.Array;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@ -26,7 +39,9 @@ import java.util.*;
|
|
|
*/
|
|
|
@Service
|
|
|
public class ChildFamilyImmuneService extends BaseService {
|
|
|
|
|
|
|
|
|
private static org.slf4j.Logger logger = LoggerFactory.getLogger(ChildFamilyImmuneService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ChildFamilyImmuneDao childFamilyImmuneDao;
|
|
|
@Autowired
|
|
@ -37,7 +52,23 @@ public class ChildFamilyImmuneService extends BaseService {
|
|
|
private ChildImmuneVaccinDao childImmuneVaccinDao;
|
|
|
@Autowired
|
|
|
private ImmuneService immuneService;
|
|
|
|
|
|
@Autowired
|
|
|
private ElasticFactory elasticFactory;
|
|
|
@Autowired
|
|
|
private ElastricSearchSave elastricSearchSave;
|
|
|
@Value("${es.type.patientRemindRecord}")
|
|
|
private String esType;
|
|
|
@Value("${es.index.patientRemindRecord}")
|
|
|
private String esIndex;
|
|
|
@Autowired
|
|
|
private WechatTemplateConfigDao templateConfigDao;
|
|
|
@Autowired
|
|
|
private DoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
@Autowired
|
|
|
private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
|
|
|
|
|
|
/**
|
|
|
* 绑定家庭成员免疫关系
|
|
|
* @param childInfo
|
|
@ -48,30 +79,30 @@ public class ChildFamilyImmuneService extends BaseService {
|
|
|
*/
|
|
|
@Transactional
|
|
|
public void addFamilyMembers(ChildInfo childInfo, String uid, String idcard, String ssc,Integer relation) throws Exception {
|
|
|
|
|
|
|
|
|
ChildFamilyImmune childFamilyImmune = new ChildFamilyImmune();
|
|
|
if(childInfo.getId() == null){
|
|
|
childInfoDao.save(childInfo);
|
|
|
}else{
|
|
|
childFamilyImmune = childFamilyImmuneDao.findByfaAndChildCodeAndFamilyCode(childInfo.getCode(),uid);
|
|
|
|
|
|
|
|
|
if(childFamilyImmune == null){
|
|
|
childFamilyImmune = new ChildFamilyImmune();
|
|
|
}else{
|
|
|
throw new Exception("您已绑定过该新生儿,无法重复绑定");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
childFamilyImmune.setCode(UUID.randomUUID().toString());
|
|
|
childFamilyImmune.setChildCode(childInfo.getCode());
|
|
|
childFamilyImmune.setFamilyCode(uid);
|
|
|
childFamilyImmune.setDel(0);
|
|
|
childFamilyImmune.setCreate_time(new Date());
|
|
|
childFamilyImmune.setRelation(relation);
|
|
|
|
|
|
|
|
|
childFamilyImmuneDao.save(childFamilyImmune);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取家人免疫关系成员列表
|
|
|
* @param repUID
|
|
@ -90,11 +121,11 @@ public class ChildFamilyImmuneService extends BaseService {
|
|
|
"from wlyy_child_family_immune a " +
|
|
|
"join wlyy_child_info b on b.code = a.child_code and b.del = 0 " +
|
|
|
"where a.del = 0 and a.family_code = '"+repUID+"'";
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> rs = jdbcTemplate.queryForList(sql);
|
|
|
return rs;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取签约居民待接种疫苗列表
|
|
|
* @param doctorcode
|
|
@ -114,16 +145,124 @@ public class ChildFamilyImmuneService extends BaseService {
|
|
|
List<Map<String, Object>> rs = jdbcTemplate.queryForList(sql);
|
|
|
return rs;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据免疫条码获取待接种免疫记录
|
|
|
* @param barcode
|
|
|
* @return
|
|
|
*/
|
|
|
public ChildImmuneVaccin getChildImmuneVaccinByBarcode(String barcode){
|
|
|
public List<ChildImmuneVaccin> getChildImmuneVaccinByBarcode(String barcode){
|
|
|
return childImmuneVaccinDao.getChildImmuneVaccinByBarcode(barcode);
|
|
|
}
|
|
|
|
|
|
public boolean alertImmVacclinByChildInfoCodes(String alertDataJsonStr, String doctor)throws Exception{
|
|
|
if (StringUtils.isEmpty(alertDataJsonStr)){
|
|
|
return false;
|
|
|
}
|
|
|
Doctor doctorObj = doctorDao.findByCode(doctor);
|
|
|
String doctorName = "";
|
|
|
String doctorLevel = "";
|
|
|
if (doctorObj!=null){
|
|
|
doctorName = doctorObj.getName();
|
|
|
if (doctorObj.getLevel()==1) {
|
|
|
doctorLevel="专科";
|
|
|
}
|
|
|
if (doctorObj.getLevel()==2) {
|
|
|
doctorLevel="全科";
|
|
|
}
|
|
|
if (doctorObj.getLevel()==3){
|
|
|
doctorLevel="健管";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
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", "ymjztx");
|
|
|
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", doctorName+"("+doctorLevel+")"));
|
|
|
json.put("remark", temp.getRemark());
|
|
|
json.put("first", temp.getFirst().replace("key1",String.valueOf(map.get("name"))).replace("key2", childName).replace("key3",vaccinName));
|
|
|
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(doctor);
|
|
|
patientRemindRecordESDO.setDoctorName(doctorName);
|
|
|
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的提醒日志表中
|
|
|
return esSavePatientRemindRecord(patientRemindRecordESDOList);
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int getChildImmuneVaccinEveryDay()throws Exception{
|
|
|
int result = 0;
|
|
@ -175,7 +314,7 @@ public class ChildFamilyImmuneService extends BaseService {
|
|
|
}else {
|
|
|
//判断是否过了7天提醒时间
|
|
|
if (childImmuneVaccin.getAlert_tag()==1 && DateUtil.getPreDays(childImmuneVaccin.getAlert_time(),7).before(new Date())){
|
|
|
childImmuneVaccinDao.updateAlertTagByCode(childImmuneVaccin.getCode());
|
|
|
childImmuneVaccinDao.updateAlertTagByCode(childImmuneVaccin.getCode(),0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -201,6 +340,7 @@ public class ChildFamilyImmuneService extends BaseService {
|
|
|
childImmuneVaccin.setIdcard(String.valueOf(map.get("idcard")));
|
|
|
childImmuneVaccin.setSsc(String.valueOf(map.get("ssc")));
|
|
|
childImmuneVaccin.setBarcode(barcode);
|
|
|
childImmuneVaccin.setChildInfoCode(String.valueOf(map.get("code")));
|
|
|
childImmuneVaccin.setYmkc(vaccinJsonJSONArray.getJSONObject(j).getString("ymkc"));
|
|
|
childImmuneVaccin.setYmmc(vaccinJsonJSONArray.getJSONObject(j).getString("ymmc"));
|
|
|
childImmuneVaccin.setYmkcsm(vaccinJsonJSONArray.getJSONObject(j).getString("ymkcsm"));
|
|
@ -221,25 +361,6 @@ public class ChildFamilyImmuneService extends BaseService {
|
|
|
}
|
|
|
}
|
|
|
childImmuneVaccinDao.save(vaccins);
|
|
|
/*for (int j=0;j<vaccinJsonJSONArray.length();j++){
|
|
|
String ymbm = vaccinJsonJSONArray.getJSONObject(j).getString("ymBm");
|
|
|
String jzzc = vaccinJsonJSONArray.getJSONObject(j).getString("jzZc");
|
|
|
if (childImmuneVaccinDao.findByBarcodeAndYmbmAndJzzc(barcode,ymbm,jzzc)==null){
|
|
|
ChildImmuneVaccin childImmuneVaccin = new ChildImmuneVaccin();
|
|
|
childImmuneVaccin.setCode(getUUID());
|
|
|
childImmuneVaccin.setName(String.valueOf(map.get("name")));
|
|
|
childImmuneVaccin.setIdcard(String.valueOf(map.get("idcard")));
|
|
|
childImmuneVaccin.setSsc(String.valueOf(map.get("ssc")));
|
|
|
childImmuneVaccin.setBarcode(barcode);
|
|
|
childImmuneVaccin.setYmkc(vaccinJsonJSONArray.getJSONObject(j).getString("ymkc"));
|
|
|
childImmuneVaccin.setYmmc(vaccinJsonJSONArray.getJSONObject(j).getString("ymmc"));
|
|
|
childImmuneVaccin.setYmkcsm(vaccinJsonJSONArray.getJSONObject(j).getString("ymkcsm"));
|
|
|
childImmuneVaccin.setYmbm(ymbm);
|
|
|
childImmuneVaccin.setJzzc(jzzc);
|
|
|
childImmuneVaccin.setAlert_tag(0);
|
|
|
childImmuneVaccin.setCreate_time(new Date());
|
|
|
}
|
|
|
}*/
|
|
|
}
|
|
|
}
|
|
|
}
|