|
@ -17,10 +17,12 @@ import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.patient.SignFamilyDao;
|
|
|
import com.yihu.wlyy.repository.security.TokenDao;
|
|
|
import com.yihu.wlyy.task.SignSsGetTask;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.yihu.wlyy.util.EncodesUtil;
|
|
|
import com.yihu.wlyy.util.IdcardInfoExtractor;
|
|
|
import com.yihu.wlyy.util.SystemData;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
@ -31,6 +33,8 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springside.modules.utils.Clock;
|
|
|
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@ -58,6 +62,8 @@ public class PatientService extends TokenService {
|
|
|
JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
private Clock clock = Clock.DEFAULT;
|
|
|
//可续签月份
|
|
|
private int[] canRenewMonth = {4, 5, 6, 7};
|
|
|
|
|
|
public void setClock(Clock clock) {
|
|
|
this.clock = clock;
|
|
@ -214,7 +220,7 @@ public class PatientService extends TokenService {
|
|
|
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE idcard = ?";
|
|
|
|
|
|
jdbcTemplate.update(sql, new Object[]{code, idcard, name, ssc, mobile, password, salt, imei, 1, ie.getBirthday()
|
|
|
, ie.getGender(), clock.getCurrentDate(),clock.getCurrentDate(), 0, 0, 0, 0,idcard});
|
|
|
, ie.getGender(), clock.getCurrentDate(), clock.getCurrentDate(), 0, 0, 0, 0, idcard});
|
|
|
|
|
|
Patient temp = patientDao.findByIdcard(idcard);
|
|
|
if (temp != null) {
|
|
@ -299,10 +305,11 @@ public class PatientService extends TokenService {
|
|
|
|
|
|
/**
|
|
|
* 判断是否续签
|
|
|
*
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject checkCanRenew(String patient){
|
|
|
public JSONObject checkCanRenew(String patient) {
|
|
|
// 是否可以续签逻辑
|
|
|
//A:wlyy_sign_family
|
|
|
//B: wlyy_sign_family_renew
|
|
@ -311,60 +318,158 @@ public class PatientService extends TokenService {
|
|
|
|
|
|
JSONObject rs = new JSONObject();
|
|
|
//判断是否签约
|
|
|
List<SignFamily> signs = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status ='1' AND t.patient ='"+patient+"' AND NOW() >= t.begin AND NOW() <= t.end",SignFamily.class);
|
|
|
if(signs!=null){
|
|
|
List<SignFamily> signs = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status ='1' AND t.patient ='" + patient + "' AND NOW() >= t.begin AND NOW() <= t.end", SignFamily.class);
|
|
|
if (signs != null) {
|
|
|
//当前年度已经签约
|
|
|
rs.put("issign","1");
|
|
|
}else{
|
|
|
rs.put("issign", "1");
|
|
|
} else {
|
|
|
//当前年度未签约
|
|
|
rs.put("issign","0");
|
|
|
rs.put("issign", "0");
|
|
|
}
|
|
|
|
|
|
//A表有已签约,但还没有扣费的记录的,不允许续签
|
|
|
List<SignFamily> signFamilys1 = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status <>'1' AND t.patient ='"+patient+"'",SignFamily.class);
|
|
|
if(signFamilys1!=null){
|
|
|
rs.put("isrenew","0");
|
|
|
List<SignFamily> signFamilys1 = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status <>'1' AND t.patient ='" + patient + "'", SignFamily.class);
|
|
|
if (signFamilys1 != null) {
|
|
|
rs.put("isrenew", "0");
|
|
|
return rs;
|
|
|
}
|
|
|
|
|
|
//A表有已签约,且已扣费,当前日期超过了7月1日,且当前日期在合约的有效期范围内,不允许续签
|
|
|
Calendar calendar =Calendar.getInstance();
|
|
|
String year = calendar.get(Calendar.YEAR)+"";
|
|
|
List<SignFamily> signFamilys2 = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status ='1' AND t.patient ='"+patient+"' AND CURDATE()>'"+year+"-07-01' NOW() >= t.begin and NOW() <= t.end",SignFamily.class);
|
|
|
if(signFamilys2!=null){
|
|
|
rs.put("isrenew","0");
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
String year = calendar.get(Calendar.YEAR) + "";
|
|
|
List<SignFamily> signFamilys2 = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family t WHERE t.status >=0 AND t.expenses_status ='1' AND t.patient ='" + patient + "' AND CURDATE()>'" + year + "-07-01' NOW() >= t.begin and NOW() <= t.end", SignFamily.class);
|
|
|
if (signFamilys2 != null) {
|
|
|
rs.put("isrenew", "0");
|
|
|
return rs;
|
|
|
}
|
|
|
|
|
|
//B表:已签约且未生效,不允许续签
|
|
|
List<SignFamilyRenew> signFamilyRenews = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family_renew t WHERE t.status>=0 AND t.is_valid = 0 AND t.patient ='"+patient+"'",SignFamilyRenew.class);
|
|
|
if(signFamilyRenews!=null){
|
|
|
rs.put("isrenew","0");
|
|
|
List<SignFamilyRenew> signFamilyRenews = jdbcTemplate.queryForList("SELECT t.id FROM wlyy_sign_family_renew t WHERE t.status>=0 AND t.is_valid = 0 AND t.patient ='" + patient + "'", SignFamilyRenew.class);
|
|
|
if (signFamilyRenews != null) {
|
|
|
rs.put("isrenew", "0");
|
|
|
return rs;
|
|
|
}
|
|
|
//都未有记录则允许续签
|
|
|
rs.put("isrenew","1");
|
|
|
rs.put("isrenew", "1");
|
|
|
return rs;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断是否可以续签
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject checkCanSignRenew(String patient) {
|
|
|
|
|
|
JSONObject rs = new JSONObject();
|
|
|
//得到当前年度,和当前月份,年度
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
int month = cal.get(Calendar.MONTH) + 1;
|
|
|
int year = cal.get(Calendar.YEAR);
|
|
|
//判断是否在续签允许的范围内
|
|
|
boolean flag = false;
|
|
|
for (int i = 0; i < canRenewMonth.length; i++) {
|
|
|
if (month == canRenewMonth[i]) {
|
|
|
flag = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!flag) {
|
|
|
rs.put("mes", "当前时间段不允许续签");
|
|
|
rs.put("code", "-1");
|
|
|
return rs;
|
|
|
}
|
|
|
//判断是否有生效记录SQL
|
|
|
String sql = "SELECT t.id,t.sign_year signYear FROM wlyy_sign_family t WHERE t.patient ='" + patient + "' AND t.status>=0 AND t.expenses_status='1'";
|
|
|
//用于判断续签表是否有记录QL,有记录则不允许续签
|
|
|
String sqlRenew = "SELECT t.id,t.sign_year signYear FROM wlyy_sign_family_renew t WHERE t.patient ='" + patient + "' AND t.status>=0 ";
|
|
|
//判读是否有当前年度的记录SQL
|
|
|
String signSql = "SELECT t.id,t.sign_year signYear FROM wlyy_sign_family t WHERE t.patient ='" + patient + "' AND t.status>=0 AND t.expenses_status='1' AND t.sign_year ='" + year + "'";
|
|
|
//判读是否有旧的已到期记录SQL
|
|
|
String oldSignSql = "SELECT t.id,t.sign_year signYear FROM wlyy_sign_family t WHERE t.patient ='" + patient + "' AND t.status=-4 AND t.expenses_status='1' AND t.sign_year ='" + (year - 1) + "'";
|
|
|
//判断时间是否在6月30之前
|
|
|
if (month < 7) {
|
|
|
//判断是否有签约记录
|
|
|
List<SignFamily> signFamilys1 = jdbcTemplate.queryForList(sql, SignFamily.class);
|
|
|
if (signFamilys1 != null && signFamilys1.size() > 0) {
|
|
|
//如果有记录则判断其年份是否为当前年份,如果为当前年份,不允许续签
|
|
|
SignFamily sign = signFamilys1.get(0);
|
|
|
if (StringUtils.isNotBlank(sign.getSignYear())) {
|
|
|
int y = Integer.parseInt(sign.getSignYear());
|
|
|
if (y == year) {
|
|
|
rs.put("mes", "当前年度已经签约");
|
|
|
rs.put("code", "-2");
|
|
|
return rs;
|
|
|
//如果不等于当前年份,则判断续签表是否有数据
|
|
|
} else {
|
|
|
return checkRenewData(sqlRenew,rs);
|
|
|
}
|
|
|
} else {
|
|
|
rs.put("mes", "签约记录为脏数据");
|
|
|
rs.put("code", "0");
|
|
|
return rs;
|
|
|
}
|
|
|
} else {
|
|
|
//没有签约记录,不允许续签,提示前往签约
|
|
|
rs.put("mes", "没有签约记录,请前往签约");
|
|
|
rs.put("code", "-4");
|
|
|
return rs;
|
|
|
}
|
|
|
} else {
|
|
|
//如果在签约七月份之后判断是否已经生效,判断是否有旧数据
|
|
|
List<SignFamily> signFamilys1 = jdbcTemplate.queryForList(signSql, SignFamily.class);
|
|
|
if (signFamilys1 != null && signFamilys1.size() > 0) {
|
|
|
rs.put("mes", "当前年度已经签约");
|
|
|
rs.put("code", "-2");
|
|
|
return rs;
|
|
|
}
|
|
|
List<SignFamily> signFamilys2 = jdbcTemplate.queryForList(oldSignSql, SignFamily.class);
|
|
|
if (signFamilys1 != null && signFamilys1.size() > 0) {
|
|
|
rs.put("mes", ",可以续签(已到期)");
|
|
|
rs.put("code", "2");
|
|
|
return rs;
|
|
|
} else {
|
|
|
rs.put("mes", "没有签约记录,请前往签约");
|
|
|
rs.put("code", "-4");
|
|
|
return rs;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public JSONObject checkRenewData(String sqlRenew,JSONObject rs){
|
|
|
List<SignFamilyRenew> renews = jdbcTemplate.queryForList(sqlRenew, SignFamilyRenew.class);
|
|
|
//如果续签表没有数据,则可以续签,有数据提示已经续签
|
|
|
if (renews != null && renews.size() > 0) {
|
|
|
rs.put("mes", "已经提交续签");
|
|
|
rs.put("code", "-3");
|
|
|
return rs;
|
|
|
} else {
|
|
|
rs.put("mes", ",可以续签(未到期)");
|
|
|
rs.put("code", "1");
|
|
|
return rs;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据居民ID查询签约CODE
|
|
|
*
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public String getSignCodeByPatient(String patient){
|
|
|
public String getSignCodeByPatient(String patient) {
|
|
|
|
|
|
if(StringUtils.isBlank(patient)){
|
|
|
if (StringUtils.isBlank(patient)) {
|
|
|
return "";
|
|
|
}
|
|
|
try{
|
|
|
List<SignFamily> signFamilies = jdbcTemplate.queryForList("SELECT * FROM wlyy_sign_family WHERE t.patient = '"+patient+"' AND t.status >=0 AND t.expenses_status ='1' ",SignFamily.class);
|
|
|
if(signFamilies!=null && signFamilies.size()>0){
|
|
|
try {
|
|
|
List<SignFamily> signFamilies = jdbcTemplate.queryForList("SELECT * FROM wlyy_sign_family WHERE t.patient = '" + patient + "' AND t.status >=0 AND t.expenses_status ='1' ", SignFamily.class);
|
|
|
if (signFamilies != null && signFamilies.size() > 0) {
|
|
|
return signFamilies.get(0).getCode();
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
} catch (Exception e) {
|
|
|
return "";
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
}
|