|
@ -7,6 +7,8 @@ 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.service.BaseService;
|
|
|
import com.yihu.wlyy.service.third.guahao.ImmuneService;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
@ -15,10 +17,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 家人免疫关系业务层
|
|
@ -36,6 +35,8 @@ public class ChildFamilyImmuneService extends BaseService {
|
|
|
JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private ChildImmuneVaccinDao childImmuneVaccinDao;
|
|
|
@Autowired
|
|
|
private ImmuneService immuneService;
|
|
|
|
|
|
/**
|
|
|
* 绑定家庭成员免疫关系
|
|
@ -122,4 +123,131 @@ public class ChildFamilyImmuneService extends BaseService {
|
|
|
public ChildImmuneVaccin getChildImmuneVaccinByBarcode(String barcode){
|
|
|
return childImmuneVaccinDao.getChildImmuneVaccinByBarcode(barcode);
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int getChildImmuneVaccinEveryDay()throws Exception{
|
|
|
int result = 0;
|
|
|
try {
|
|
|
String sql ="SELECT" +
|
|
|
" DISTINCT ci.`code`," +
|
|
|
" ci.idcard," +
|
|
|
" ci.`name`," +
|
|
|
" ci.ssc," +
|
|
|
" ci.barcode" +
|
|
|
" FROM" +
|
|
|
" wlyy_child_family_immune fi" +
|
|
|
" LEFT JOIN wlyy_child_info ci ON fi.child_code = ci.`code`" +
|
|
|
" WHERE" +
|
|
|
" fi.del = 0";
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String,Object> map : list){
|
|
|
String barcode = String.valueOf(map.get("barcode"));
|
|
|
System.out.println("===============barcode=============="+barcode);
|
|
|
String deptStr = immuneService.findDept(barcode);
|
|
|
if (StringUtils.isNotBlank(deptStr)){
|
|
|
JSONObject jsonObject = new JSONObject(deptStr);
|
|
|
if (jsonObject.getInt("status")==200) {
|
|
|
JSONObject json = new JSONObject(jsonObject.getString("data"));
|
|
|
JSONArray jsonArray = json.getJSONArray("body");
|
|
|
for (int i = 0;i<jsonArray.length();i++){
|
|
|
String deptNum = jsonArray.getJSONObject(i).getString("deptNum");
|
|
|
String vaccinStr = immuneService.findMyVaccin(barcode,deptNum);
|
|
|
JSONObject vaccinJson = new JSONObject(vaccinStr);
|
|
|
if (vaccinJson.getInt("status")==200) {
|
|
|
JSONObject vaccinJson2 = new JSONObject(vaccinJson.getString("data"));
|
|
|
JSONArray vaccinJsonJSONArray = vaccinJson2.getJSONArray("body");
|
|
|
List<ChildImmuneVaccin> vaccinList = childImmuneVaccinDao.findByBarcode(barcode);
|
|
|
//原来有的则不用新增,原来有的但是在返回回来的数据没有的话删除数据
|
|
|
for (ChildImmuneVaccin childImmuneVaccin : vaccinList){
|
|
|
int count = 0;
|
|
|
for (int j=0;j<vaccinJsonJSONArray.length();j++){
|
|
|
String ymbm = vaccinJsonJSONArray.getJSONObject(j).getString("ymBm");
|
|
|
String jzzc = vaccinJsonJSONArray.getJSONObject(j).getString("jzZc");
|
|
|
if (childImmuneVaccin.getYmbm().equals(ymbm) && childImmuneVaccin.getJzzc().equals(jzzc)){
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
//原来有的疫苗要判断是否有超过预约时间的7天,并且看提醒是否超过7天,超过7天可以重新提醒
|
|
|
if (count>0 && childImmuneVaccin.getIsOut()==1){
|
|
|
if (DateUtil.getPreDays(childImmuneVaccin.getJzrq(),7).before(new Date())){
|
|
|
//过了预约时间7天,更新为isOut=0,则不能预约了
|
|
|
childImmuneVaccinDao.updateIsOutByCode(childImmuneVaccin.getCode());
|
|
|
}else {
|
|
|
//判断是否过了7天提醒时间
|
|
|
if (childImmuneVaccin.getAlert_tag()==1 && DateUtil.getPreDays(childImmuneVaccin.getAlert_time(),7).before(new Date())){
|
|
|
childImmuneVaccinDao.updateAlertTagByCode(childImmuneVaccin.getCode());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (count==0){
|
|
|
result+= childImmuneVaccinDao.updateDelByCode(childImmuneVaccin.getCode());
|
|
|
}
|
|
|
}
|
|
|
//如果本地没有就是新增的
|
|
|
List<ChildImmuneVaccin> vaccins = new ArrayList<>();
|
|
|
for (int j=0;j<vaccinJsonJSONArray.length();j++){
|
|
|
String ymbm = vaccinJsonJSONArray.getJSONObject(j).getString("ymBm");
|
|
|
String jzzc = vaccinJsonJSONArray.getJSONObject(j).getString("jzZc");
|
|
|
int count = 0;
|
|
|
for (ChildImmuneVaccin childImmuneVaccin : vaccinList){
|
|
|
if (childImmuneVaccin.getYmbm().equals(ymbm) && childImmuneVaccin.getJzzc().equals(jzzc)){
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
if (count==0){
|
|
|
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.setJzrq(DateUtil.strToDate(vaccinJsonJSONArray.getJSONObject(j).getString("jzRq"),DateUtil.YYYY_MM_DD));
|
|
|
childImmuneVaccin.setAlert_tag(0);
|
|
|
childImmuneVaccin.setDel(0);
|
|
|
childImmuneVaccin.setCreate_time(new Date());
|
|
|
if (DateUtil.getPreDays(DateUtil.strToDate(vaccinJsonJSONArray.getJSONObject(j).getString("jzRq")),7).before(new Date())){
|
|
|
//过了预约时间7天,更新为isOut=0,则不能预约了
|
|
|
childImmuneVaccin.setIsOut(0);
|
|
|
}else {
|
|
|
childImmuneVaccin.setIsOut(1);
|
|
|
}
|
|
|
vaccins.add(childImmuneVaccin);
|
|
|
result++;
|
|
|
}
|
|
|
}
|
|
|
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());
|
|
|
}
|
|
|
}*/
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
}
|