|  | @ -16,6 +16,7 @@ import com.yihu.wlyy.repository.patient.SignFamilyDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.BaseService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.IdCardUtil;
 | 
	
		
			
				|  |  | import org.apache.commons.beanutils.converters.CalendarConverter;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.json.JSONArray;
 | 
	
		
			
				|  |  | import org.json.JSONObject;
 | 
	
	
		
			
				|  | @ -24,6 +25,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
	
		
			
				|  | @ -74,22 +76,55 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |         String sql = "";
 | 
	
		
			
				|  |  |         Object[] args = null;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (labelCode.equals("0")) {
 | 
	
		
			
				|  |  |             sql = "select a.*" +
 | 
	
		
			
				|  |  |                     " from" +
 | 
	
		
			
				|  |  |                     "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 and admin_team_code = ?) a" +
 | 
	
		
			
				|  |  |                     " left join" +
 | 
	
		
			
				|  |  |                     "     (select * from wlyy_sign_patient_label_info where label_type = ? and status = 1) b" +
 | 
	
		
			
				|  |  |                     " on a.patient = b.patient where b.patient is null limit " + start + "," + pagesize;
 | 
	
		
			
				|  |  |             args = new Object[]{doctor, teamCode, labelType};
 | 
	
		
			
				|  |  |         if (labelType.equals("5")) {
 | 
	
		
			
				|  |  |             Calendar today = Calendar.getInstance();
 | 
	
		
			
				|  |  |             Calendar startDate = Calendar.getInstance();
 | 
	
		
			
				|  |  |             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
 | 
	
		
			
				|  |  |             sql = "select * " +
 | 
	
		
			
				|  |  |                     " from " +
 | 
	
		
			
				|  |  |                     "     wlyy_sign_family " +
 | 
	
		
			
				|  |  |                     " where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 and admin_team_code = ? ";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (labelCode.equals("1")) {
 | 
	
		
			
				|  |  |                 int week = today.get(Calendar.DAY_OF_WEEK) - 1;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (week == 0) {
 | 
	
		
			
				|  |  |                     week = 6;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 startDate.add(Calendar.DATE, -week);
 | 
	
		
			
				|  |  |                 sql += " and apply_date >= '" + (df.format(startDate.getTime()) + " 00:00:00")
 | 
	
		
			
				|  |  |                         + "' and apply_date <= '" + (df.format(today.getTime()) + " 23:59:59");
 | 
	
		
			
				|  |  |             } else if (labelCode.equals("2")) {
 | 
	
		
			
				|  |  |                 startDate.set(Calendar.DATE, 1);
 | 
	
		
			
				|  |  |                 sql += " and apply_date >= '" + (df.format(startDate.getTime()) + " 00:00:00")
 | 
	
		
			
				|  |  |                         + "' and apply_date <= '" + (df.format(today.getTime()) + " 23:59:59");
 | 
	
		
			
				|  |  |             } else if (labelCode.equals("3")) {
 | 
	
		
			
				|  |  |                 startDate.add(Calendar.DATE, 29);
 | 
	
		
			
				|  |  |                 sql += " and apply_date >= '" + (df.format(today.getTime()) + " 00:00:00")
 | 
	
		
			
				|  |  |                         + "' and apply_date <= '" + (df.format(startDate.getTime()) + " 23:59:59");
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 throw new Exception("label is not exist");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             args = new Object[]{doctor, teamCode};
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             sql = "select a.*" +
 | 
	
		
			
				|  |  |                     " from" +
 | 
	
		
			
				|  |  |                     "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 and admin_team_code = ?) a" +
 | 
	
		
			
				|  |  |                     " join" +
 | 
	
		
			
				|  |  |                     "     (select * from wlyy_sign_patient_label_info where label = ? and label_type = ? and status = 1) b" +
 | 
	
		
			
				|  |  |                     " on a.patient = b.patient limit " + start + "," + pagesize;
 | 
	
		
			
				|  |  |             args = new Object[]{doctor, teamCode, labelCode, labelType};
 | 
	
		
			
				|  |  |             if (labelCode.equals("0")) {
 | 
	
		
			
				|  |  |                 sql = "select a.*" +
 | 
	
		
			
				|  |  |                         " from" +
 | 
	
		
			
				|  |  |                         "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 and admin_team_code = ?) a" +
 | 
	
		
			
				|  |  |                         " left join" +
 | 
	
		
			
				|  |  |                         "     (select * from wlyy_sign_patient_label_info where label_type = ? and status = 1) b" +
 | 
	
		
			
				|  |  |                         " on a.patient = b.patient where b.patient is null limit " + start + "," + pagesize;
 | 
	
		
			
				|  |  |                 args = new Object[]{doctor, teamCode, labelType};
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 sql = "select a.*" +
 | 
	
		
			
				|  |  |                         " from" +
 | 
	
		
			
				|  |  |                         "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 and admin_team_code = ?) a" +
 | 
	
		
			
				|  |  |                         " join" +
 | 
	
		
			
				|  |  |                         "     (select * from wlyy_sign_patient_label_info where label = ? and label_type = ? and status = 1) b" +
 | 
	
		
			
				|  |  |                         " on a.patient = b.patient limit " + start + "," + pagesize;
 | 
	
		
			
				|  |  |                 args = new Object[]{doctor, teamCode, labelCode, labelType};
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         signList = jdbcTemplate.queryForList(sql, args);
 | 
	
	
		
			
				|  | @ -181,31 +216,67 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |                 String sql = "";
 | 
	
		
			
				|  |  |                 Object[] args = null;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (label.getLabelCode().equals("0")) {
 | 
	
		
			
				|  |  |                     sql = "select count(DISTINCT a.patient) count" +
 | 
	
		
			
				|  |  |                             " from" +
 | 
	
		
			
				|  |  |                             "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 " +
 | 
	
		
			
				|  |  |                             (teamCode > 0 ? "and admin_team_code = ?" : "") + ") a " +
 | 
	
		
			
				|  |  |                             " left join" +
 | 
	
		
			
				|  |  |                             "     (select * from wlyy_sign_patient_label_info where label_type = ? and status = 1) b" +
 | 
	
		
			
				|  |  |                             " on a.patient = b.patient where b.patient is null ";
 | 
	
		
			
				|  |  |                     if (teamCode > 0) {
 | 
	
		
			
				|  |  |                         args = new Object[]{doctor, teamCode, labelType};
 | 
	
		
			
				|  |  |                 if(labelType.equals("5")){
 | 
	
		
			
				|  |  |                     Calendar today = Calendar.getInstance();
 | 
	
		
			
				|  |  |                     Calendar startDate = Calendar.getInstance();
 | 
	
		
			
				|  |  |                     SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
 | 
	
		
			
				|  |  |                     sql = "select count(DISTINCT patient) " +
 | 
	
		
			
				|  |  |                             " from " +
 | 
	
		
			
				|  |  |                             "     wlyy_sign_family " +
 | 
	
		
			
				|  |  |                             " where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 " +
 | 
	
		
			
				|  |  |                             (teamCode > 0 ? " and admin_team_code = ? " : "");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     if (label.getLabelCode().equals("1")) {
 | 
	
		
			
				|  |  |                         int week = today.get(Calendar.DAY_OF_WEEK) - 1;
 | 
	
		
			
				|  |  |                         if (week == 0) {
 | 
	
		
			
				|  |  |                             week = 6;
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         startDate.add(Calendar.DATE, -week);
 | 
	
		
			
				|  |  |                         sql += " and apply_date >= '" + (df.format(startDate.getTime()) + " 00:00:00")
 | 
	
		
			
				|  |  |                                 + "' and apply_date <= '" + (df.format(today.getTime()) + " 23:59:59");
 | 
	
		
			
				|  |  |                     } else if (label.getLabelCode().equals("2")) {
 | 
	
		
			
				|  |  |                         startDate.set(Calendar.DATE, 1);
 | 
	
		
			
				|  |  |                         sql += " and apply_date >= '" + (df.format(startDate.getTime()) + " 00:00:00")
 | 
	
		
			
				|  |  |                                 + "' and apply_date <= '" + (df.format(today.getTime()) + " 23:59:59");
 | 
	
		
			
				|  |  |                     } else if (label.getLabelCode().equals("3")) {
 | 
	
		
			
				|  |  |                         startDate.add(Calendar.DATE, 29);
 | 
	
		
			
				|  |  |                         sql += " and apply_date >= '" + (df.format(today.getTime()) + " 00:00:00")
 | 
	
		
			
				|  |  |                                 + "' and apply_date <= '" + (df.format(startDate.getTime()) + " 23:59:59");
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         args = new Object[]{doctor, labelType};
 | 
	
		
			
				|  |  |                         throw new Exception("label is not exist");
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     sql = "select count(DISTINCT a.patient) count" +
 | 
	
		
			
				|  |  |                             " from" +
 | 
	
		
			
				|  |  |                             "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 " +
 | 
	
		
			
				|  |  |                             (teamCode > 0 ? "and admin_team_code = ?" : "") + ") a " +
 | 
	
		
			
				|  |  |                             " join" +
 | 
	
		
			
				|  |  |                             "     (select * from wlyy_sign_patient_label_info where label = ? and label_type = ? and status = 1) b" +
 | 
	
		
			
				|  |  |                             " on a.patient = b.patient ";
 | 
	
		
			
				|  |  |                     if (teamCode > 0) {
 | 
	
		
			
				|  |  |                         args = new Object[]{doctor, teamCode, label.getLabelCode(), labelType};
 | 
	
		
			
				|  |  |                         args = new Object[]{doctor, teamCode};
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         args = new Object[]{doctor};
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     if (label.getLabelCode().equals("0")) {
 | 
	
		
			
				|  |  |                         sql = "select count(DISTINCT a.patient) count" +
 | 
	
		
			
				|  |  |                                 " from" +
 | 
	
		
			
				|  |  |                                 "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 " +
 | 
	
		
			
				|  |  |                                 (teamCode > 0 ? "and admin_team_code = ?" : "") + ") a " +
 | 
	
		
			
				|  |  |                                 " left join" +
 | 
	
		
			
				|  |  |                                 "     (select * from wlyy_sign_patient_label_info where label_type = ? and status = 1) b" +
 | 
	
		
			
				|  |  |                                 " on a.patient = b.patient where b.patient is null ";
 | 
	
		
			
				|  |  |                         if (teamCode > 0) {
 | 
	
		
			
				|  |  |                             args = new Object[]{doctor, teamCode, labelType};
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             args = new Object[]{doctor, labelType};
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         args = new Object[]{doctor, label.getLabelCode(), labelType};
 | 
	
		
			
				|  |  |                         sql = "select count(DISTINCT a.patient) count" +
 | 
	
		
			
				|  |  |                                 " from" +
 | 
	
		
			
				|  |  |                                 "     (select * from wlyy_sign_family where " + (doc.getLevel() == 2 ? " doctor" : "doctor_health") + " = ? and status > 0 " +
 | 
	
		
			
				|  |  |                                 (teamCode > 0 ? "and admin_team_code = ?" : "") + ") a " +
 | 
	
		
			
				|  |  |                                 " join" +
 | 
	
		
			
				|  |  |                                 "     (select * from wlyy_sign_patient_label_info where label = ? and label_type = ? and status = 1) b" +
 | 
	
		
			
				|  |  |                                 " on a.patient = b.patient ";
 | 
	
		
			
				|  |  |                         if (teamCode > 0) {
 | 
	
		
			
				|  |  |                             args = new Object[]{doctor, teamCode, label.getLabelCode(), labelType};
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             args = new Object[]{doctor, label.getLabelCode(), labelType};
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -471,7 +542,7 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 添加居民到某个标签
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient 患者
 | 
	
		
			
				|  |  |      * @param patient   患者
 | 
	
		
			
				|  |  |      * @param labelCode 标签code
 | 
	
		
			
				|  |  |      * @param labelType 标签类型
 | 
	
		
			
				|  |  |      * @return
 | 
	
	
		
			
				|  | @ -513,7 +584,7 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 删除居民的某个标签
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient 患者
 | 
	
		
			
				|  |  |      * @param patient   患者
 | 
	
		
			
				|  |  |      * @param labelCode 标签code
 | 
	
		
			
				|  |  |      * @param labelType 标签类型
 | 
	
		
			
				|  |  |      * @return
 |