Forráskód Böngészése

Merge branch 'dev' of wujunjie/patient-management into dev

linzhuo 8 éve
szülő
commit
92ab4717dc
15 módosított fájl, 691 hozzáadás és 392 törlés
  1. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateOptionsDao.java
  2. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateQuestionsDao.java
  3. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyMemberService.java
  4. 69 51
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java
  5. 164 89
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  6. 82 41
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java
  7. 4 64
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/PatientQuestionnaireService.java
  8. 18 12
      patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java
  9. 12 13
      patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ImUtill.java
  10. 8 36
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/im/imController.java
  11. 75 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java
  12. 48 13
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java
  13. 146 10
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java
  14. 61 58
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java
  15. 1 1
      patient-co-wlyy/src/main/resources/system.properties

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateOptionsDao.java

@ -17,5 +17,5 @@ public interface SurveyTemplateOptionsDao extends PagingAndSortingRepository<Sur
    @Modifying
    @Query("update SurveyTemplateOptions t set t.haveComment=?4,t.content=?5," +
            "t.questionCodeNext=?6,t.isRequired=?7,t.sort=?8 where  t.templateQuestionCode = ?1 and t.templateCode = ?2 and t.code=?3")
    void modifyOption(String tempCode, String qstcode, String optcode, Integer haveCommment, String content, String nextCode, Integer isRequired, Integer sort);
    int modifyOption(String tempCode, String qstcode, String optcode, Integer haveCommment, String content, String nextCode, Integer isRequired, Integer sort);
}

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateQuestionsDao.java

@ -23,6 +23,6 @@ public interface SurveyTemplateQuestionsDao extends PagingAndSortingRepository<S
    @Modifying
    @Query("update SurveyTemplateQuestions t set t.title=?3,t.questionComment=?4,t.questionType=?5," +
            "t.isRequired=?6,t.minNum=?7,t.maxNum=?8,t.sort=?9,t.questionCodeNext=?10  where t.templateCode = ?1 and t.code = ?2 ")
    void modifyQuestion(String tempCode, String qstCode, String qstTitle, String qstComment, Integer qstType,
    int modifyQuestion(String tempCode, String qstCode, String qstTitle, String qstComment, Integer qstType,
                        Integer isRequired, Integer minNum, Integer maxNum, Integer sort, String next);
}

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyMemberService.java

@ -526,7 +526,7 @@ public class FamilyMemberService extends BaseService {
        //2.判断手机过滤
        //判断是否绑定了手机
        if (StringUtils.isNotBlank(p.getMobile())) {
        if (StringUtils.isNoneBlank(p.getMobile())) {
            //如果用户绑定了微信,将状态更改为4
            if (result == 1) {
                result = 3;

+ 69 - 51
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java

@ -12,6 +12,7 @@ import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelInfoDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientDiseaseDao;
@ -26,6 +27,8 @@ import org.apache.commons.lang3.StringUtils;
import org.hibernate.type.descriptor.sql.JdbcTypeFamilyInformation;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
@ -69,6 +72,10 @@ public class SignPatientLabelInfoService extends BaseService {
    StringRedisTemplate redisTemplate;
    @Autowired
    AdminTeamService adminTeamService;
    @Autowired
    SignPatientLabelDao labelDao;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * 查询单个居民信息
@ -412,7 +419,7 @@ public class SignPatientLabelInfoService extends BaseService {
            }
        }
        if(result.size() > 0) {
        if (result.size() > 0) {
            List<JSONObject> list = Lists.newArrayList(result.values());
            Collections.sort(list, new Comparator<JSONObject>() {
@ -1241,7 +1248,54 @@ public class SignPatientLabelInfoService extends BaseService {
        return result;
    }
//    =========================================================================================================================================================
    //    =========================================================================================================================================================
    /**
     * 获取没有健康管理师的患者列表
     *
     * @param teamCode
     * @return
     * @throws Exception
     */
    public List findNoHealthSignFamilyHealth(String filter, Long teamCode,int page,int pagesize) throws Exception {
        List list = new ArrayList();
        String sql = "SELECT  DISTINCT " +
                "  p.photo photo, " +
                "  p.name name, " +
                "  p.code code, " +
                "  p.sex sex," +
                "  p.address address," +
                "  p.idcard idcard " +
                " FROM " +
                " wlyy_sign_family sf " +
                " JOIN wlyy_patient p ON sf.patient = p.CODE " +
                " left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.`status` = 1 " +
                " WHERE " +
                " sf.type = 2 " +
                " AND sf. STATUS > 0 " +
                " and sf.admin_team_code = ? " +
                " AND ( sf.doctor_health is null or sf.doctor_health ='' ) " +
                "  AND (p.name like ? or p.address like ? or p.idcard like ? ) " +
                " ORDER BY  p.name DESC,p.address DESC, p.idcard DESC " +
                " limit "+(page-1)+","+pagesize;
        List<Map<String, Object>> datas = jdbcTemplate.queryForList(sql, teamCode, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%");
        if (datas != null && datas.size() > 0) {
            for (Map<String, Object> map : datas) {
                Map ma = new HashMap();
                ma.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard")==null?"":map.get("idcard").toString()));
                ma.put("photo",map.get("photo")==null?"":map.get("photo").toString());
                ma.put("name",map.get("name")==null?"":map.get("name").toString());
                ma.put("code",map.get("code")==null?"":map.get("code").toString());
                ma.put("sex",map.get("sex")==null?"":map.get("sex").toString());
                ma.put("address",map.get("address")==null?"":map.get("address").toString());
                ma.put("idcard",map.get("idcard")==null?"":map.get("idcard").toString());
                list.add(ma);
            }
        }
        return list;
    }
    /**
     * 根据姓名,地址,身份证号搜索团队内居民
     *
@ -1251,55 +1305,23 @@ public class SignPatientLabelInfoService extends BaseService {
     * @throws Exception
     */
    public JSONArray getPatientByParams(String doctor, String filter,
                                                String labelCode, String labelType, long teamCode,
                                                String exLabelCode,
                                                String exLabelType,
                                                int page, int pagesize) throws Exception {
                                        String labelCode, String labelType, long teamCode,
                                        String exLabelCode,
                                        String exLabelType,
                                        int page, int pagesize) throws Exception {
        Doctor doc = doctorDao.findByCode(doctor);
        System.out.print("-------------teamCode--------->" + teamCode);
        if (doc == null) {
            throw new Exception("doctor info can not find");
        }
        Map<String, JSONObject> result = new HashMap<>();
        List<Map<String, Object>> signList = new ArrayList<>();
        page = page * pagesize;
        page = (page - 1) * pagesize;
        Object[] args = null;
        String sql = "";
//        String reg = "(^\\d{15}$)|(^\\d{17}([0-9]|X)$)";
//        String reg = "^(\\d+)([0-9]|X|x)$";
        String reg = "^\\d+$";
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(filter);
       /* if (matcher.find()) {
//            按数字查询身份证号和地址
            sql = " select DISTINCT t.* " +
                    " from" +
                    "     wlyy_sign_family t join wlyy_patient p " +
                    "     on t.patient = p.code " +
                    (StringUtils.isNotEmpty(labelCode) ? (" join wlyy_sign_patient_label_info l " +
                            " on t.patient = l.patient ") : "") +
                    " where " +
                    "    (t.doctor = ? or t.doctor_health = ?) " +
                    (teamCode > 0 ? ("    and t.admin_team_code = " + teamCode) : "") +
                    (StringUtils.isNotEmpty(labelCode) ? " and l.label = ? and l.label_type = ? " : "") +
                    "     and ( p.idcard like ? OR p.address like ?  ) " +
//            "     and ( p.idcard like ?   ) ";
                    " ORDER BY  p.address DESC,p.idcard DESC ";
            if (StringUtils.isNotEmpty(labelCode)) {
                args = new Object[]{doctor, doctor, labelCode, labelType, "%" + filter + "%", "%" + filter + "%"};
            } else {
                args = new Object[]{doctor, doctor, "%" + filter + "%", "%" + filter + "%"};
            }
            System.out.println("=====================================>" + sql);
        } else {*/
//            非数字查询姓名和地址
        sql = "select " +
        String sql = "select " +
                "    DISTINCT t1.* " +
                " FROM " +
                "    (wlyy_sign_family t1,wlyy_patient p)  " +
//                    "    wlyy_sign_family t1   " +
                (StringUtils.isNotEmpty(labelCode) ?
                        " join " : " left join ") +
                "    wlyy_sign_patient_label_info t2 " +
@ -1307,7 +1329,6 @@ public class SignPatientLabelInfoService extends BaseService {
                (teamCode > 0 ? " join (select * from wlyy_sign_patient_label where label_type != '4' or team_code = " + teamCode + " or (label_type = '4' and (label_code in (1,2)))) lb on t2.label = lb.label_code and t2.label_type = lb.label_type " : "") +
                " WHERE " +
                " p.code = t1.patient " +
//                    " p.code = t1.patient " +
                "   AND (t1.doctor = ? or t1.doctor_health = ?) " +
                "    AND t1.status > 0 " +
                "    AND (" + (StringUtils.isNotEmpty(labelCode) || StringUtils.isNotEmpty(labelType) ? "" : " t2.patient is null OR ") + " t2.status = 1) " +
@ -1315,9 +1336,7 @@ public class SignPatientLabelInfoService extends BaseService {
                (StringUtils.isNotEmpty(labelType) ? " AND t2.label_type = ? " : "") +
                (teamCode > 0 ? (" AND admin_team_code = " + teamCode) : "") +
                "  AND (t1.name like ? or p.address like ? or p.idcard like ? ) " +
//                    "  AND (t1.name like ? or t2.label_name like ?  ) " ;
                " ORDER BY  p.name DESC,p.address DESC, p.idcard DESC ";
        System.out.println("=====================================>" + sql);
        if (StringUtils.isNotEmpty(labelCode)) {
            args = new Object[]{doctor, doctor, labelCode, labelType, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%"};
        } else if (StringUtils.isEmpty(labelCode) && StringUtils.isNotEmpty(labelType)) {
@ -1325,7 +1344,6 @@ public class SignPatientLabelInfoService extends BaseService {
        } else {
            args = new Object[]{doctor, doctor, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%"};
        }
//        }
        sql += " limit " + page + "," + pagesize;
        signList = jdbcTemplate.queryForList(sql, args);
@ -1832,7 +1850,7 @@ public class SignPatientLabelInfoService extends BaseService {
                    "   f.admin_team_code," +
                    "   f. STATUS," +
                    "   t.id teamCode," +
                    "   t.name teamName"+
                    "   t.name teamName" +
                    "  FROM" +
                    "   wlyy_patient p" +
                    "  LEFT JOIN (" +
@ -1854,7 +1872,7 @@ public class SignPatientLabelInfoService extends BaseService {
                    "  LEFT JOIN wlyy_admin_team t ON t.id = f.admin_team_code" +
                    "  WHERE" +
                    "   p. idcard = ?";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, filter,filter);
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, filter, filter);
            for (Map<String, Object> p : list) {
                JSONObject pJson = new JSONObject();
@ -1866,7 +1884,7 @@ public class SignPatientLabelInfoService extends BaseService {
                pJson.put("photo", p.get("photo") != null ? p.get("photo") : "");
                pJson.put("id", p.get("id") != null ? p.get("id") : "");
                pJson.put("doctor", p.get("doctor") != null ? p.get("doctor") : "");
                pJson.put("isSign",p.get("status")!=null?(Integer.parseInt(p.get("status").toString())>=1?"1":"0"):"0");
                pJson.put("isSign", p.get("status") != null ? (Integer.parseInt(p.get("status").toString()) >= 1 ? "1" : "0") : "0");
                pJson.put("doctorHealth", p.get("doctor_health") != null ? p.get("doctor_health") : "");
                if (p.get("id") != null && (doctorCode.equals(pJson.get("doctor")) || doctorCode.equals(pJson.get("doctorHealth")))) {
                    if (p.get("teamCode") != null && StringUtils.isNotEmpty(p.get("teamCode").toString())) {
@ -1901,7 +1919,7 @@ public class SignPatientLabelInfoService extends BaseService {
                    "   f.admin_team_code," +
                    "   f. STATUS," +
                    "   t.id teamCode," +
                    "   t.name teamName"+
                    "   t.name teamName" +
                    "  FROM" +
                    "   wlyy_patient p" +
                    "  LEFT JOIN (" +
@ -1923,7 +1941,7 @@ public class SignPatientLabelInfoService extends BaseService {
                    "  LEFT JOIN wlyy_admin_team t ON t.id = f.admin_team_code" +
                    "  WHERE" +
                    "   p. name  = ?";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, filter,filter);
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, filter, filter);
            for (Map<String, Object> p : list) {
                JSONObject pJson = new JSONObject();
@ -1935,7 +1953,7 @@ public class SignPatientLabelInfoService extends BaseService {
                pJson.put("photo", p.get("photo") != null ? p.get("photo") : "");
                pJson.put("id", p.get("id") != null ? p.get("id") : "");
                pJson.put("doctor", p.get("doctor") != null ? p.get("doctor") : "");
                pJson.put("isSign",p.get("status")!=null?(Integer.parseInt(p.get("status").toString())>=1?"1":"0"):"0");
                pJson.put("isSign", p.get("status") != null ? (Integer.parseInt(p.get("status").toString()) >= 1 ? "1" : "0") : "0");
                pJson.put("doctorHealth", p.get("doctor_health") != null ? p.get("doctor_health") : "");
                if (p.get("id") != null && (doctorCode.equals(pJson.get("doctor")) || doctorCode.equals(pJson.get("doctorHealth")))) {
                    if (p.get("teamCode") != null && StringUtils.isNotEmpty(p.get("teamCode").toString())) {
@ -2703,7 +2721,7 @@ public class SignPatientLabelInfoService extends BaseService {
            }
        }
        if(result.size() > 0) {
        if (result.size() > 0) {
            List<JSONObject> list = Lists.newArrayList(result.values());
            Collections.sort(list, new Comparator<JSONObject>() {

+ 164 - 89
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -241,11 +241,12 @@ public class FamilyContractService extends BaseService {
    /**
     * 根据医生和患者获取患者的签约状态
     *
     * @param patient
     * @param doctor
     * @return
     */
    public List<SignFamily> getSign(String patient,String doctor){
    public List<SignFamily> getSign(String patient, String doctor) {
        List<SignFamily> sfList = signFamilyDao.findSSandFamilyByDoctorPatient(patient, doctor);
        return sfList;
    }
@ -528,8 +529,8 @@ public class FamilyContractService extends BaseService {
    /**
     * 申请签约
     *
     * @param doctor     签约医生
     * @param patient    居民code
     * @param doctor  签约医生
     * @param patient 居民code
     * @return
     */
    public int sign(String doctor, String patient) throws Exception {
@ -996,38 +997,38 @@ public class FamilyContractService extends BaseService {
            json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
            json.put("content", content);
            json.put("remark", ""); //您好,您成功签约家庭医生
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
            }else{
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient.getCode());
                if(j!=null){
                    Patient member = (Patient)j.get("member");
                    if(StringUtils.isNotBlank(member.getOpenid())){
                        String first = (String)json.get("first");
                if (j != null) {
                    Patient member = (Patient) j.get("member");
                    if (StringUtils.isNotBlank(member.getOpenid())) {
                        String first = (String) json.get("first");
                        json.remove("first");
                        json.put("first",weiXinOpenIdUtils.getTitleMes(patient,j.getInt("relation"),member.getName()));
                        json.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), member.getName()));
                        PushMsgTask.getInstance().putWxMsg(access_token, 1, member.getOpenid(), member.getName(), json);
                    }
                }
            }
            new Thread(new SignUploadTask(sf.getCode())).start();
            JSONObject participants = new JSONObject();
            participants.put(sf.getPatient(),0);
            if(StringUtils.equals(sf.getDoctor(),sf.getDoctorHealth())){//全科和建管同一个人
                participants.put(sf.getDoctor(),0);
            }else{//全科和建管不同一个人
                participants.put(sf.getDoctorHealth(),0);
                participants.put(sf.getDoctor(),1);
            participants.put(sf.getPatient(), 0);
            if (StringUtils.equals(sf.getDoctor(), sf.getDoctorHealth())) {//全科和建管同一个人
                participants.put(sf.getDoctor(), 0);
            } else {//全科和建管不同一个人
                participants.put(sf.getDoctorHealth(), 0);
                participants.put(sf.getDoctor(), 1);
            }
            //创建医生会话讨论组
            JSONObject sessionObj  =  ImUtill.createSession(participants,ImUtill.SESSION_TYPE_MUC,patient.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2);
            if(sessionObj.getInt("status")==-1){
                throw  new RuntimeException(sessionObj.getString("message"));
            JSONObject sessionObj = ImUtill.createSession(participants, ImUtill.SESSION_TYPE_MUC, patient.getName(), patient.getCode() + "_" + sf.getTeamCode() + "_" + 2);
            if (sessionObj.getInt("status") == -1) {
                throw new RuntimeException(sessionObj.getString("message"));
            }
            ImUtill.updateSessionStatus(patient.getCode()+"_"+sf.getTeamCode()+"_"+2,ImUtill.SESSION_STATUS_END);
            ImUtill.updateSessionStatus(patient.getCode() + "_" + sf.getTeamCode() + "_" + 2, ImUtill.SESSION_STATUS_END);
            ImUtill.sendImMsg(doc.getCode(),doc.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2,"0","家庭医生代理签约成功!","1");
            ImUtill.sendImMsg(doc.getCode(), doc.getName(), patient.getCode() + "_" + sf.getTeamCode() + "_" + 2, "0", "家庭医生代理签约成功!", "1");
        }
        BusinessLogs.info(BusinessLogs.BusinessType.sign, signDoctorCode, sf.getPatient(), new JSONObject(sf));
        return temp;
@ -1077,7 +1078,7 @@ public class FamilyContractService extends BaseService {
            result.put("status", 0);
            return result;
        }
        String doctorTeamCode  =null;//服务团队的CODE;
        String doctorTeamCode = null;//服务团队的CODE;
        if (type == 1) {
            //判断是否有三师签约 并且判断全科医生一致
            SignFamily sssignFamily = signFamilyDao.findSSByIdcard(p.getIdcard());
@ -1234,17 +1235,17 @@ public class FamilyContractService extends BaseService {
            json.put("content", sf.getName() + ",您好!您与 " + (StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorName()) + " 医生建立家庭医生签约关系失败,请查看!");
            json.put("remark", "您好,签约家庭医生失败通知");
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 2, sf.getOpenid(), sf.getName(), json);
            }else{
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                   String first = (String)json.get("first");
                   json.remove("first");
                   json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                   PushMsgTask.getInstance().putWxMsg(access_token, 2, member.getOpenid(), member.getName(), json);
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 2, member.getOpenid(), member.getName(), json);
                }
            }
@ -1277,15 +1278,15 @@ public class FamilyContractService extends BaseService {
            json.put("content", content);
            json.put("remark", ""); //您好,您成功签约家庭医生
            // 添加到发送队列
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
            }else{
                JSONObject j =  weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    String first = (String)json.get("first");
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 1, member.getOpenid(), member.getName(), json);
                }
            }
@ -1293,20 +1294,20 @@ public class FamilyContractService extends BaseService {
            new Thread(new SignUploadTask(sf.getCode())).start();
            JSONObject participants = new JSONObject();
            participants.put(sf.getPatient(),0);
            if(StringUtils.equals(sf.getDoctor(),sf.getDoctorHealth())){//全科和建管同一个人
                participants.put(sf.getDoctor(),0);
            }else{//全科和建管不同一个人
                participants.put(sf.getDoctorHealth(),0);
                participants.put(sf.getDoctor(),1);
            participants.put(sf.getPatient(), 0);
            if (StringUtils.equals(sf.getDoctor(), sf.getDoctorHealth())) {//全科和建管同一个人
                participants.put(sf.getDoctor(), 0);
            } else {//全科和建管不同一个人
                participants.put(sf.getDoctorHealth(), 0);
                participants.put(sf.getDoctor(), 1);
            }
            Patient patient = patientDao.findByCode(sf.getPatient());
            //创建医生会话讨论组
            JSONObject sessionObj  =  ImUtill.createSession(participants,ImUtill.SESSION_TYPE_MUC,patient.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2);
            if(sessionObj.getInt("status")==-1){
                throw  new RuntimeException(sessionObj.getString("message"));
            JSONObject sessionObj = ImUtill.createSession(participants, ImUtill.SESSION_TYPE_MUC, patient.getName(), patient.getCode() + "_" + sf.getTeamCode() + "_" + 2);
            if (sessionObj.getInt("status") == -1) {
                throw new RuntimeException(sessionObj.getString("message"));
            }
            ImUtill.sendImMsg(doc.getCode(),doc.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2,"0","家庭医生签约成功!","1");
            ImUtill.sendImMsg(doc.getCode(), doc.getName(), patient.getCode() + "_" + sf.getTeamCode() + "_" + 2, "0", "家庭医生签约成功!", "1");
        }
        result.put("status", 1);
        BusinessLogs.info(BusinessLogs.BusinessType.sign, caller, sf.getPatient(), new JSONObject(sf));
@ -1364,17 +1365,17 @@ public class FamilyContractService extends BaseService {
            json.put("orgName", sf.getHospitalName());
            json.put("remark", sf.getName() + ",您好!您的签约医生已同意您的解约申请,解约已生效。");
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
            }else{
                JSONObject j =  weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    String first = (String)json.get("first");
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    Patient p = patientDao.findByCode(patient);
                    json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
                }
            }
@ -1393,17 +1394,17 @@ public class FamilyContractService extends BaseService {
            json.put("orgName", sf.getHospitalName());
            json.put("remark", sf.getName() + ",您好!您的签约医生拒绝您的解约申请,解约失败。");
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
            }else{
                JSONObject j =  weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    String first = (String)json.get("first");
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    Patient p = patientDao.findByCode(patient);
                    json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
                }
            }
@ -1853,14 +1854,14 @@ public class FamilyContractService extends BaseService {
                    result.put("msg", "与当前健管师有未结束的咨询");
                    return result;
                }
                try{
                    if(signFamily.getDoctorHealth().equals(signFamily.getDoctor())){
                        ImUtill.deleteMucUser(healthDoctor,"",patient+"_"+signFamily.getTeamCode()+"_2");
                    }else{
                        ImUtill.deleteMucUser(healthDoctor,signFamily.getDoctorHealth(),patient+"_"+signFamily.getTeamCode()+"_2");
                try {
                    if (signFamily.getDoctorHealth().equals(signFamily.getDoctor())) {
                        ImUtill.deleteMucUser(healthDoctor, "", patient + "_" + signFamily.getTeamCode() + "_2");
                    } else {
                        ImUtill.deleteMucUser(healthDoctor, signFamily.getDoctorHealth(), patient + "_" + signFamily.getTeamCode() + "_2");
                    }
                }catch (Exception e){
                } catch (Exception e) {
                    result.put("status", -1);
                    result.put("msg", e.getMessage());
                    return result;
@ -1903,9 +1904,9 @@ public class FamilyContractService extends BaseService {
                    data.put("remark", docHealth.getName() + "医生与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
                }
                wxMessages.add(data);
                try{
                    ImUtill.deleteMucUser(docHealth.getCode(),"",patient+"_"+signFamily.getTeamCode()+"_2");
                }catch (Exception e){
                try {
                    ImUtill.deleteMucUser(docHealth.getCode(), "", patient + "_" + signFamily.getTeamCode() + "_2");
                } catch (Exception e) {
                    result.put("status", -1);
                    result.put("msg", e.getMessage());
                    return result;
@ -1949,9 +1950,9 @@ public class FamilyContractService extends BaseService {
            String oldDoctorName = signFamily.getDoctorName();
            if (StringUtils.isNotEmpty(signFamily.getDoctor())) {
                DoctorTeamMember teamMember = doctorTeamDoctor.findMemberByTeamAndQkCode(signFamily.getTeamCode(), signFamily.getDoctor());
                 try{
                    ImUtill.deleteMucUser(doctor,signFamily.getDoctor(),patient+"_"+signFamily.getTeamCode()+"_2");
                }catch (Exception e){
                try {
                    ImUtill.deleteMucUser(doctor, signFamily.getDoctor(), patient + "_" + signFamily.getTeamCode() + "_2");
                } catch (Exception e) {
                    result.put("status", -1);
                    result.put("msg", e.getMessage());
                    return result;
@ -2014,19 +2015,19 @@ public class FamilyContractService extends BaseService {
        for (JSONObject msg : wxMessages) {
            if(StringUtils.isNotBlank(p.getOpenid())){
            if (StringUtils.isNotBlank(p.getOpenid())) {
                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), msg);
            }else{
            } else {
                //如果自己没有绑定,则发给家人
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    String first = (String)msg.get("first");
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) msg.get("first");
                    msg.remove("first");
                    try{
                        msg.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                    }catch (Exception e){
                    try {
                        msg.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), msg);
@ -2050,7 +2051,7 @@ public class FamilyContractService extends BaseService {
        return result;
    }
    public JSONObject findByParamsWithDoctor(String doctorCode, String teamCode, String params,int level) throws Exception {
    public JSONObject findByParamsWithDoctor(String doctorCode, String teamCode, String params, int level) throws Exception {
        JSONObject returnMap = new JSONObject();
        String addressSql = "select a.signcode,a.name,a.address,a.code,a.hasopenid,a.idcard,a.photo from( SELECT " +
                "  sf.CODE signcode, " +
@ -2068,11 +2069,11 @@ public class FamilyContractService extends BaseService {
                " AND sf. STATUS > 0 " +
                // " and sf.doctor = ? " +
                " and sf.admin_team_code = ? " +
                " AND ( "+(level==2?"sf.doctor =?":"sf.doctor_health =? ")+") ) a where 1=1";
                " AND ( " + (level == 2 ? "sf.doctor =?" : "sf.doctor_health =? ") + ") ) a where 1=1";
        if (!org.springframework.util.StringUtils.isEmpty(params)) {
            addressSql += " AND a.address like '%" + params + "%'";
        }
        List<Map<String, Object>> datas = jdbcTemplate.queryForList(addressSql, teamCode,doctorCode);
        List<Map<String, Object>> datas = jdbcTemplate.queryForList(addressSql, teamCode, doctorCode);
        if (datas != null && datas.size() > 0) {
            JSONArray jsonArray = new JSONArray();
            for (Map<String, Object> map : datas) {
@ -2105,12 +2106,12 @@ public class FamilyContractService extends BaseService {
                " AND sf. STATUS > 0 " +
                //" and sf.doctor = ? " +
                " and sf.admin_team_code = ? " +
                " AND ( "+(level==2?"sf.doctor =?":"sf.doctor_health =? ")+") ) a where 1=1";
                " AND ( " + (level == 2 ? "sf.doctor =?" : "sf.doctor_health =? ") + ") ) a where 1=1";
        if (!org.springframework.util.StringUtils.isEmpty(params)) {
            patientNameSql += " AND a.name like '%" + params + "%'";
        }
        datas = jdbcTemplate.queryForList(patientNameSql, teamCode,doctorCode);
        datas = jdbcTemplate.queryForList(patientNameSql, teamCode, doctorCode);
        if (datas != null && datas.size() > 0) {
            JSONArray jsonArray = new JSONArray();
            for (Map<String, Object> map : datas) {
@ -2460,12 +2461,13 @@ public class FamilyContractService extends BaseService {
    /**
     * 根据会话信息拉取对应的人员信息
     *
     * @param sessionId
     * @return
     */
    public JSONObject getTeamDoctors(String sessionId,String doctor){
    public JSONObject getTeamDoctors(String sessionId, String doctor) {
        String infos[] = sessionId.split("_");
        String patient  = infos[0];
        String patient = infos[0];
        JSONObject result = new JSONObject();
        Map<String, JSONObject> docMap = new HashMap<>();
        SignFamily ssSign = signFamilyDao.findSignByPatient(patient, 1);
@ -2532,7 +2534,7 @@ public class FamilyContractService extends BaseService {
    public JSONObject getPatientSignDoctorsByTeam(String sessionId) {
        String infos[] =sessionId.split("_");
        String infos[] = sessionId.split("_");
        JSONObject result = new JSONObject();
        Map<String, JSONObject> docMap = new HashMap<>();
        SignFamily ssSign = signFamilyDao.findSignByPatient(infos[0], 1);
@ -2631,6 +2633,79 @@ public class FamilyContractService extends BaseService {
        return returnMap;
    }
    //根据姓名、地址、身份证搜索已分配健管师的居民
    public List getPatientByLable(String doctorCode, String filter, String level, Long team,int page,int pagesize) throws Exception {
        List list = new ArrayList();
        //判断当前用户是健康管理师还是全科
        List<Map<String, Object>> datas = null;
        if (level.equals("3")) {
            //健康管理师
            String sql = "SELECT DISTINCT " +
                    "  p.photo photo, " +
                    "  p.name name, " +
                    "  p.code code, " +
                    "  p.sex sex," +
                    "  p.address address," +
                    "  p.idcard idcard " +
                    " FROM " +
                    " wlyy_sign_family sf " +
                    " JOIN wlyy_patient p ON sf.patient = p.CODE " +
                    " left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.`status` = 1 " +
                    " WHERE " +
                    " sf.type = 2 " +
                    " AND sf. STATUS > 0 " +
                    " and sf.doctor_health = ? " +
                    " and sf.admin_team_code = ? " +
                    " AND (p.name like ? or p.address like ? or p.idcard like ? ) " +
                    " ORDER BY  p.name DESC,p.address DESC, p.idcard DESC " +
                    " limit "+(page-1)+","+pagesize;
            //查找居民
            datas = jdbcTemplate.queryForList(sql, doctorCode, team,"%"+filter+"%","%"+filter+"%","%"+filter+"%");
        } else if (level.equals("2")) {
            //全科
            String sql = "SELECT  DISTINCT " +
                    "  p.photo photo, " +
                    "  p.name name, " +
                    "  p.code code, " +
                    "  p.sex sex," +
                    "  p.address address," +
                    "  p.idcard idcard " +
                    " FROM " +
                    " wlyy_sign_family sf " +
                    " JOIN wlyy_patient p ON sf.patient = p.CODE " +
                    " left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.`status` = 1 " +
                    " WHERE " +
                    " sf.type = 2 " +
                    " AND sf. STATUS > 0 " +
                    " and  sf.doctor = ?  " +
                    " and sf.admin_team_code = ? " +
                    " AND (p.name like ? or p.address like ? or p.idcard like ? ) " +
                    " ORDER BY  p.name DESC,p.address DESC, p.idcard DESC " +
                    " limit "+(page-1)+","+pagesize;
            //查找居民
            datas = jdbcTemplate.queryForList(sql, doctorCode, team,"%"+filter+"%","%"+filter+"%","%"+filter+"%");
        } else {
            throw new Exception("参数错误!");
        }
        if (datas != null && datas.size() > 0) {
            for (Map<String, Object> map : datas) {
                Map ma = new HashMap();
                ma.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard")==null?"":map.get("idcard").toString()));
                ma.put("photo",map.get("photo")==null?"":map.get("photo").toString());
                ma.put("name",map.get("name")==null?"":map.get("name").toString());
                ma.put("code",map.get("code")==null?"":map.get("code").toString());
                ma.put("sex",map.get("sex")==null?"":map.get("sex").toString());
                ma.put("address",map.get("address")==null?"":map.get("address").toString());
                ma.put("idcard",map.get("idcard")==null?"":map.get("idcard").toString());
                list.add(ma);
            }
        }
        return list;
    }
    public JSONObject getPatientByLable(String doctorCode, String labelType, String level, Long team) throws Exception {
        JSONObject returnMap = new JSONObject();
        //判断当前用户是健康管理师还是全科

+ 82 - 41
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -90,9 +90,11 @@ public class ManagerQuestionnaireService extends BaseService {
    @Autowired
    WeiXinOpenIdUtils weiXinOpenIdUtils;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public String createSurvey(String doctor, JSONObject jsonStr, String accessToken) throws Exception {
        System.out.println("=============>" + jsonStr);
        System.out.println("createSurvey ======》" + jsonStr);
//        问卷信息
        String surveyCode = getCode();
        String surveyName = jsonStr.getString("surveyName");
@ -262,19 +264,6 @@ public class ManagerQuestionnaireService extends BaseService {
//            String code = patient.get("patient").toString();
            SurveyUser user = new SurveyUser(surveyCode, code, 0, 1, new Date(), new Date());
            surveyUserDao.save(user);
//            发送居民模板 send=1发送
           /* if ("1".equals(send)) {
                String name = patient.get("name").toString();
                String openId = patient.get("openid").toString();
//            String openId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A";
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", code);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                System.out.println("*************************" + json + "******************");
                System.out.println("********name*********************" + name + "openId" + openId);
                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
            }*/
        }
        //            发送居民模板 send=1发送
//        ====================================================
@ -282,19 +271,25 @@ public class ManagerQuestionnaireService extends BaseService {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
            JSONObject json = new JSONObject(str);
            codes.stream().forEach(c -> {
                Patient p = patientDao.findByCode(c);
 /*           for (String code : codes) {
//            codes.stream().forEach(c -> {
//                Patient p = patientDao.findByCode(c);
                Patient p = patientDao.findByCode(code);
                String name = p.getName();
                String openId = p.getOpenid();
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", c);
//                json.put("toUser", c);
                json.put("toUser", code);
                json.put("survey_id", surveyCode);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                logger.error("patient =======>" + code);
                logger.error("name =======>" + name);
                logger.error("openId =======>" + openId);
                //判断是否判定openId,有没有发则查找家人发送
                //判断是否有openId,有发送没有则查找家人发送
                if (StringUtils.isNotBlank(p.getOpenid())) {
                    // 添加到发送队列
                    logger.error("json =======>" + json);
                    PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                } else {
                    JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
@ -307,10 +302,49 @@ public class ManagerQuestionnaireService extends BaseService {
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        logger.error("没有opIn  json =======>" + json);
                        PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                    }
                }
            });
//            });
            }*/
            new Thread() {
                public void run() {
                    for (String c : codes) {
                        Patient p = patientDao.findByCode(c);
                        String name = p.getName();
                        String openId = p.getOpenid();
                        json.put("keyword2", sdf.format(new Date()));
                        json.put("toUser", c);
                        json.put("survey_id", surveyCode);
                        json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                        //判断是否判定openId,有没有发则查找家人发送
                        if (StringUtils.isNotBlank(p.getOpenid())) {
                            // 添加到发送队列
                            logger.error("json =======>" + json);
//                            PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                            PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
                        } else {
                            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
                            Patient member = (Patient) j.get("member");
                            if (StringUtils.isNotBlank(member.getOpenid())) {
                                String first = (String) json.get("first");
                                json.remove("first");
                                try {
                                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                logger.error("没有opIn  json =======>" + json);
//                                PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, member.getOpenid(), member.getName(), json);
                            }
                        }
                    }
                }
            }.start();
        }
//       =====================================================
//     获取标签数组
@ -1215,7 +1249,6 @@ public class ManagerQuestionnaireService extends BaseService {
        jsonObject.put("comment", tempComment);
        jsonObject.put("label", labels);
        jsonObject.put("questions", questions);
        System.out.println("==========jsonObject============" + jsonObject);
        return jsonObject;
    }
@ -1299,6 +1332,7 @@ public class ManagerQuestionnaireService extends BaseService {
        String title = survey.getTitle();
        String templateComment = survey.getSurveyComment();
//        查询问卷标题重复情况
//       int number = surveyTemplatesDao.distinctByTitle(title);
        int number = 0;
        if (StringUtils.isEmpty(modifyTitle)) {
            number = surveyTemplatesDao.distinctByTitle(title);
@ -1306,7 +1340,7 @@ public class ManagerQuestionnaireService extends BaseService {
            number = surveyTemplatesDao.distinctByTitle(modifyTitle);
            title = modifyTitle;
        }
        if (number != 0 && StringUtils.isEmpty(modifyTitle)) {
        if (number != 1 && StringUtils.isEmpty(modifyTitle)) {
            int likeNum = surveyTemplatesDao.distinctLikeTitle(title + "%");
            return likeNum;
        }
@ -1314,20 +1348,15 @@ public class ManagerQuestionnaireService extends BaseService {
            int likeNum = surveyTemplatesDao.distinctLikeTitle(modifyTitle + "%");
            return likeNum;
        }
//        SurveyTemplates surveyTemplates = new SurveyTemplates(templateCode, title, templateComment, creater, 1, creater, updateTime);
//        更改模板信息
//        surveyTemplatesDao.save(surveyTemplates);
        surveyTemplatesDao.modifyTemplate(templateCode, title, templateComment);
        List<SurveyLabelInfo> surveyLabelInfos = surveyLabelInfoDao.findByCode(code);
        for (SurveyLabelInfo surveyLabelInfo : surveyLabelInfos) {
//        更改模板标签信息
//            SurveyLabelInfo surveyLabelInfo1 = new SurveyLabelInfo(getCode(), templateCode, 0, surveyLabelInfo.getLabel());
//            surveyLabelInfoDao.save(surveyLabelInfo1);
            surveyLabelInfoDao.modifyLabel(templateCode, surveyLabelInfo.getLabel());
        }
        List<SurveyQuestionnaire> surveyQuestionnaires = surveyQuestionnaireDao.findById(code);
        for (SurveyQuestionnaire question : surveyQuestionnaires) {
//            String qstCode = getCode();
            String qstCode = question.getCode();
            String qstTitle = question.getTitle();
            String qstComment = question.getQuestionComment();
@ -1335,26 +1364,38 @@ public class ManagerQuestionnaireService extends BaseService {
            Integer isRequired = question.getIsRequired();
            Integer minNum = question.getMinNum();
            Integer maxNum = question.getMaxNum();
//            Date createTiem = question.getCreateTime();
//            Date updateTiem = question.getUpdateTime();
            Integer sort = question.getSort();
//            Integer de = question.getDel();
            String next = question.getQuestionCodeNext();
//            SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, templateCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
            //            更改问题到模板问题表
//            surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
            System.out.println(templateCode+","+qstCode+qstTitle+","+qstComment+","+qstType+","+isRequired+","+minNum+","+maxNum+","+sort+","+next);
            surveyTemplateQuestionsDao.modifyQuestion(templateCode, qstCode, qstTitle, qstComment, qstType, isRequired, minNum, maxNum, sort, next);
            //            更改问题到模板问题表(修改模板新增的问题怎么办?)
            System.out.println(templateCode + "," + qstCode + qstTitle + "," + qstComment + "," + qstType + "," + isRequired + "," + minNum + "," + maxNum + "," + sort + "," + next);
            int rows = surveyTemplateQuestionsDao.modifyQuestion(templateCode, qstCode, qstTitle, qstComment, qstType, isRequired, minNum, maxNum, sort, next);
//            新增问题直接保存
            if (rows == 0) {
                Integer de = question.getDel();
                Date createTiem = question.getCreateTime();
                Date updateTiem = question.getUpdateTime();
                SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, templateCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
                surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
            }
            if (qstType != 2) {
                List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
                for (SurveyQuestionnaireOptions option : surveyQuestionnaireOptions) {
                    SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(getCode(), option.getHaveComment(), qstCode, option.getContent(),
                            templateCode, option.getQuestionCodeNext(), null, option.getIsRequired(), option.getSort(), option.getDel());
                    //         更改到模板选项表   survey_template_options
//                    surveyTemplateOptionsDao.save(surveyTemplateOptions);
                    surveyTemplateOptionsDao.modifyOption(templateCode, qstCode, option.getCode(),
                            option.getHaveComment(), option.getContent(), option.getQuestionCodeNext(), option.getIsRequired(), option.getSort());
                    System.out.println("=============>");
                    String optCode = option.getCode();
                    Integer have = option.getHaveComment();
                    String content = option.getContent();
                    String nextCode = option.getQuestionCodeNext();
                    Integer required = option.getIsRequired();
                    Integer optsort = option.getSort();
                    int row = surveyTemplateOptionsDao.modifyOption(templateCode, qstCode, optCode,
                            have, content, nextCode, required, optsort);
//            新增问题的选项直接保存
                    if (row == 0) {
                        Integer del = option.getDel();
                        SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(optCode, have, qstCode, content,
                                templateCode, nextCode, null, required, optsort, del);
                        surveyTemplateOptionsDao.save(surveyTemplateOptions);
                    }
                }
            }
        }

+ 4 - 64
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/PatientQuestionnaireService.java

@ -6,6 +6,8 @@ import com.yihu.wlyy.service.BaseService;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -32,6 +34,7 @@ public class PatientQuestionnaireService extends BaseService {
    private SurveyAnswersDao surveyAnswersDao;
    @Autowired
    SurveyStatisticsDao surveyStatisticsDao;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public JSONObject getSurveySummary(String patient, String id) throws Exception {
        JSONObject jsonObject = new JSONObject();
@ -159,72 +162,9 @@ public class PatientQuestionnaireService extends BaseService {
        jsonObject.put("sort", sorts);
//        题目数量是变量
        jsonObject.put("totalNum", total);
        logger.error("居民获取题目信息==》" + jsonObject);
        return jsonObject;
    }
//==================================原来========================================
/*public JSONObject getQuestions(String id, Integer sort, Integer pageNo, Integer total, String nextCode) throws  Exception{
    JSONObject jsonObject = new JSONObject();
    SurveyQuestionnaire question = null;
    int sorts = 0;
    if (!StringUtils.isEmpty(nextCode)) {
//            跳题
//            question = surveyQuestionnaireDao.findByIdAndSort(id, Integer.parseInt(nextCode));
        question = surveyQuestionnaireDao.findByIdAndQstId(id,nextCode);
        sorts = question.getSort();
        total = total - (sorts -(sort + 1));
    } else {
//            不跳题
        if (total == null) {
            //      该套问卷总题目数
            total = surveyQuestionnaireDao.findTotalById(id);
        }
        question = surveyQuestionnaireDao.findTotalByIdAndSort(id, sort + 1);
        sorts = question.getSort();
    }
    String qstCode = question.getCode();
    String qstTitle = question.getTitle();
    int isRequired = question.getIsRequired();
    int type = question.getQuestionType();
//        int sorts = question.getSort();
    switch (type) {
        case 0:
            List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(qstCode);
            for (SurveyQuestionnaireOptions option : options) {
                String content = option.getContent();
//                        可构造集合,返回选项特定值
            }
            jsonObject.put("options", options);
            break;
        case 1:
            List<SurveyQuestionnaireOptions> optionss = surveyQuestionnaireOptionsDao.findById(qstCode);
            for (SurveyQuestionnaireOptions option : optionss) {
                String content = option.getContent();
            }
            int maxNum = question.getMaxNum();
            int minNum = question.getMinNum();
            jsonObject.put("maxNum", maxNum);
            jsonObject.put("minNum", minNum);
            jsonObject.put("options", optionss);
            break;
        case 2:
            String questionCodeNext = question.getQuestionCodeNext();
            jsonObject.put("questionCodeNext", questionCodeNext);
            break;
    }
    jsonObject.put("qstCode", qstCode);
    jsonObject.put("qstTitle", qstTitle);
    jsonObject.put("isRequired", isRequired);
    jsonObject.put("type", type);
    jsonObject.put("sort", sorts);
//        题目数量是变量
    jsonObject.put("totalNum", total);
    jsonObject.put("percent", (Math.round(((float) pageNo / total) * 100)) + "%");
    return jsonObject;
}*/
//    ======================================================================================
    public void saveAnswer(String patient, JSONObject jsonData) throws Exception {
        System.out.println("********jsonData********* " + jsonData);

+ 18 - 12
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -91,6 +91,7 @@ public class PushMsgTask {
            json.put("name", name);
            json.put("data", data);
            queue.put(json);
            String str = "";
        } catch (Exception e) {
            logger.error("添加到微信消息列队列失败!", e);
            e.printStackTrace();
@ -141,6 +142,7 @@ public class PushMsgTask {
                        String access_token = json.has("access_token") ? json.getString("access_token") : "";
                        String openid = json.has("openid") ? json.getString("openid") : "";
                        String name = json.has("name") ? json.getString("name") : "";
//                        String name = data.has("name") ? json.getString("name") : "";
                        // 发送消息到微信端
                        sendWeixinMessage(access_token, type, openid, name, data);
                    } else {
@ -185,12 +187,12 @@ public class PushMsgTask {
     *             type==7时:{"first":"消息主题","name":"就诊人名","date":"预约时间","doctorName":"医生名","orgName":"预约医院","remark":"消息备注"}
     *             type==9时:{"first":"消息主题","name":"患教标题","doctorName":"医生名","date":"发送时间","remark":"消息备注"}
     *             type==10时:{"first":"消息主题","name":"患教标题","doctorName":"医生名","date":"发送时间","remark":"消息备注"}
     *
     *             <p>
     *             type==11时:{"first":"消息主题","name":"患教标题","doctorName":"医生名","date":"发送时间","remark":"消息备注"}
     * @return
     */
//    private boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
    private boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
    public boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
        try {
            if (StringUtils.isEmpty(openid)) {
                logger.error("send wechat message failed:openid is empty");
@ -437,9 +439,9 @@ public class PushMsgTask {
                keyword3.setValue(json.getString("keyword3"));
                m.put("keyword3", keyword3);
            } else if (type == 11) {
                temp.setUrl(url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                String xinurl = url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name;
//                temp.setUrl(url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(xinurl);
//                temp.setTemplate_id("fgYiMntj1amEkE8_GLUPmAIyssUAroJrNSHqvydt-PQ");
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties()
                        .getProperty("template_doctor_survey"));
@ -453,17 +455,19 @@ public class PushMsgTask {
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
                logger.info("type=====>openId " + openid);
            }else if(type == 12){
                System.out.println("url=======type =11 =====================>"+xinurl);
                logger.error("url=======type =11 =====================>"+xinurl);
            } else if (type == 12) {
                temp.setUrl(url + "jtgx/html/application-msg-list.html?openid=" + openid+ "&member=" + json.getString("member"));
                temp.setUrl(url + "jtgx/html/application-msg-list.html?openid=" + openid + "&member=" + json.getString("member"));
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties().getProperty("template_doctor_survey"));
                WechatTemplateData  keyword1= new WechatTemplateData();
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
                keyword1.setValue(json.getString("keyword1"));
                m.put("keyword1", keyword1);
                WechatTemplateData  keyword2= new WechatTemplateData();
                WechatTemplateData keyword2 = new WechatTemplateData();
                keyword2.setColor("#000000");
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
@ -478,17 +482,17 @@ public class PushMsgTask {
//                keyword4.setValue(json.getString("keyword4"));
//                m.put("keyword4", keyword4);
            }else if(type == 13){
            } else if (type == 13) {
                temp.setUrl(url + "jtgx/html/family.html?openid=" + openid);
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties().getProperty("template_doctor_survey"));
                WechatTemplateData  keyword1= new WechatTemplateData();
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
                keyword1.setValue(json.getString("keyword1"));
                m.put("keyword1", keyword1);
                WechatTemplateData  keyword2= new WechatTemplateData();
                WechatTemplateData keyword2 = new WechatTemplateData();
                keyword2.setColor("#000000");
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
@ -507,6 +511,8 @@ public class PushMsgTask {
            temp.setData(m);
            ObjectMapper mapper = new ObjectMapper();
            String strJson = mapper.writeValueAsString(temp);
            System.out.println("send message================>" + strJson);
            logger.error("send message================>" + strJson);
            return strJson;
        } catch (Exception e) {
            e.printStackTrace();

+ 12 - 13
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ImUtill.java

@ -18,16 +18,15 @@ public class ImUtill {
     * @param status
     * @param reply
     * @return
     *
     */
    public static String getConsultData(String user, Integer status, Integer reply) {
        String imAddr = im_host + "api/v2/sessions/topics/count/reply";
        imAddr+="?user="+user;
        if (status!=null) {
            imAddr+="&status="+status;
        imAddr = imAddr + "?user=" + user;
        if (status != null) {
            imAddr += ("&status=" + status);
        }
        if (reply!=null) {
            imAddr+="&reply="+reply;
        if (reply != null) {
            imAddr += ("&reply=" + reply);
        }
        String response = HttpClientUtil.get(imAddr, "UTF-8");
        return response;
@ -46,18 +45,18 @@ public class ImUtill {
     * @return
     */
    public static String getConsultByStatus(String user, Integer status, Integer reply, int page, int pagesize) {
        String imAddr = im_host + "api/v2/sessions/topics?user="+user+"&page="+page+"&pagesize="+pagesize;
        if (status!=null) {
            imAddr+="&status="+status;
        String imAddr = im_host + "api/v2/sessions/topics";
        imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
        if (status != null) {
            imAddr += ("&status=" + status);
        }
        if (reply!=null) {
            imAddr+="&reply="+reply;
        if (reply != null) {
            imAddr += ("&reply=" + reply);
        }
        String response = HttpClientUtil.get(imAddr, "UTF-8");
        return response;
    }
//    ===============================
    /**
     * 发送消息给IM
     *

+ 8 - 36
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/im/imController.java

@ -41,21 +41,17 @@ public class imController extends BaseController {
     */
    @RequestMapping(value = "/consult/getList", method = RequestMethod.GET)
    @ResponseBody
    public String getTeamData(
    public String getConsultByStatus(
            @RequestParam(required = false) String doctor,
            @RequestParam Integer status,
            @RequestParam(required = false) Integer reply,
            @RequestParam int page,
            @RequestParam int pagesize) {
        try {
//            后端校验
            if (StringUtils.isEmpty(doctor)) {
                doctor = getUID();
            }
            String consult = ImUtill.getConsultByStatus(doctor, status, reply, page, pagesize);
//            Doctor dct = doctorDao.findByCode(doctor);
            /*String photo = dct.getPhoto();
            String dctName = dct.getName();*/
            JSONArray jsonArray = new JSONArray(consult);
            Iterator<Object> it = jsonArray.iterator();
            List list = new ArrayList();
@ -69,6 +65,8 @@ public class imController extends BaseController {
                String createTime = ob.get("create_time").toString();
                String description = ob.get("description").toString();
                String sex = ob.get("sex").toString();
                String startId = ob.get("start_message_id").toString();
                String endId = ob.get("end_message_id").toString();
                map.put("id", id);
                map.put("session_id", session_id);
                map.put("photo", avatar);
@ -76,6 +74,8 @@ public class imController extends BaseController {
                map.put("sex", sex);
                map.put("create_time", createTime);
                map.put("description", description);
                map.put("start_message_id", startId);
                map.put("end_message_id", endId);
                list.add(map);
            }
@ -97,7 +97,6 @@ public class imController extends BaseController {
    public String getTeamData() {
        try {
            String uid = getUID();
//           String uid = "6c0cfe5065e011e69f7c005056850d66";
            List<Map<String, Object>> doctors = getMemberByDoctor(uid);
            JSONObject json = new JSONObject();
            List list = new ArrayList();
@ -109,11 +108,11 @@ public class imController extends BaseController {
            for (Map<String, Object> doc : doctors) {
                Map map = new HashMap();
                String doctor = doc.get("code").toString();
                map.put("photo", doc.get("photo").toString());
                map.put("photo", doc.get("photo")==null?"":doc.get("photo").toString());
                map.put("name", doc.get("name").toString());
                map.put("sex", doc.get("sex").toString());
                map.put("doctor", doctor);
//                map.put("code", "ec6714314d6d48a6bfcf1e9119187e02");
                map.put("type",doc.get("level")==null?"":doc.get("level").toString());
                String totalUnReply = ImUtill.getConsultData(doctor, 0, 0);
                int unReply = Integer.parseInt(totalUnReply);
                map.put("totalUnReply", unReply);
@ -140,30 +139,6 @@ public class imController extends BaseController {
        }
    }
    /**
     * 获取团队内医生的健康咨询状况
     *
     * @param code
     * @param type 0待回复 1进行中 2已完成
     * @return
     *//*
    @RequestMapping(value = "/getTeamDoctor", method = RequestMethod.GET)
    @ResponseBody
    public String getTeamDoctor(@RequestParam String code,
                                @RequestParam int type,
                                @RequestParam int pageNo,
                                @RequestParam int pageSize) {
        try {
//			List list = consultTeamService.getTeamDoctor(code, type);
//			return write(200, "查询成功", "data", list);
            return write(200, "查询成功");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
/**/
    /**
     * 获取团队医生下居民的咨询
     *
@ -177,11 +152,9 @@ public class imController extends BaseController {
//            1.调im接口
//            2.判断团队长和当前咨询居民是否存在签约关系
            String doctor = getUID();
//			Boolean flag = consultTeamService.getConsultByPatient(patient,doctor);
            int count = signFamilyDao.findByPatientAndDoctor(patient, doctor);
            boolean flag = (count == 0) ? false : true;
            return write(200, "查询成功", "data", flag);
//            return write(200, "查询成功");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
@ -189,8 +162,7 @@ public class imController extends BaseController {
    }
    public List getMemberByDoctor(String doctor) {
//        List<Doctor> doctors = doctorDao.findMemberByLeader(doctor);
        String sql = "SELECT d.photo,d.`name`,d.sex,d.`code` " +
        String sql = "SELECT d.photo,d.`name`,d.sex,d.`code`,d.level " +
                " from wlyy_admin_team t,wlyy_admin_team_member m,wlyy_doctor d " +
                " where t.id = m.team_id and m.doctor_code = d.`code` and t.available = 1 and m.available=1 " +
                " and t.leader_code = ? ";

+ 75 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java

@ -1,10 +1,13 @@
package com.yihu.wlyy.web.doctor.account;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import com.yihu.wlyy.entity.consult.ConsultTeam;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.profile.DoctorComment;
@ -12,6 +15,7 @@ import com.yihu.wlyy.entity.organization.HospitalDept;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelDao;
import com.yihu.wlyy.service.app.account.PatientInfoService;
import com.yihu.wlyy.service.app.consult.ConsultTeamService;
import com.yihu.wlyy.service.app.hospital.HospitalDeptService;
@ -19,6 +23,7 @@ import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.common.account.RoleService;
import com.yihu.wlyy.util.*;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -83,6 +88,8 @@ public class DoctorController extends BaseController {
    private RoleService roleService;
    @Autowired
    private DoctorAdminTeamDao doctorAdminTeamDao;
    @Autowired
    SignPatientLabelDao labelDao;
    /**
     * 社区医院下医生列表查询接口 没分页
@ -605,7 +612,7 @@ public class DoctorController extends BaseController {
                List<Map<String, String>> roleMap = roleService.getUserRoleAndArea(temp.getCode());
                json.put("userRole", roleMap);
//                是否团队长
                json.put("isLeader", leader==0?"0":"1");
                json.put("isLeader", leader == 0 ? "0" : "1");
                return write(200, "医生信息查询成功!", "data", json);
            } else {
                return error(-1, "医生信息查询失败!");
@ -1778,4 +1785,71 @@ public class DoctorController extends BaseController {
            return error(-1, "查询失败");
        }
    }
    /**
     * 分配及转移健管师
     *
     * @param newDoctorCode
     * @param oldDoctorCode
     * @param patients      多个患者用,隔开
     * @param group         团队标签分组名称
     * @param sendCount
     * @param teamId
     * @param typeId
     * @return
     */
    @RequestMapping(value = "/allotOrMoveHealth")
    @ResponseBody
    public String allotOrMoveHealth(
            @RequestParam String newDoctorCode,
            @RequestParam(required = false) String oldDoctorCode,
            @RequestParam(required = false) String patients,
            @RequestParam(required = false) String group,
            @RequestParam(required = false) Integer sendCount,
            @RequestParam(required = false) String teamId,
            @RequestParam(required = false) String typeId) {
        try {
//            patients不为空是由团队中搜索居民 否则是分组分配健管师
            if (StringUtils.isNotEmpty(patients)) {
                String result = updateTeamHealthDoctors(newDoctorCode, oldDoctorCode, patients, null);
                return result;
            } else {
//            按条件获取居民
                patients = "";
                if (StringUtils.isEmpty(group)||StringUtils.isEmpty(teamId)||StringUtils.isEmpty(typeId)||sendCount==null){
                    return write(-1, "参数不能为空!");
                }
                Long teamCode = Long.parseLong(teamId);
                JSONObject list = familyContractService.findNoHealthSignFamilyHealth(null, typeId, null, teamCode);
                List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(typeId, 1, teamCode);
                for (SignPatientLabel label :s) {
//                    String labelName = label.getLabelCode();
                    String labelName = label.getLabelName();
                    if (labelName.equals(group)){
                        JSONArray jsonArray = list.getJSONArray(labelName);
                        for (int i=0;i<sendCount;i++){
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            String  patient = jsonObject.get("code").toString();
//                转移时需要剔除处于咨询状态的居民
                            if (StringUtils.isNotEmpty(oldDoctorCode)){
                                ConsultTeam consultTeam = consultTeamService.getConsultByPatientAndDoctor(patient, oldDoctorCode);
                                if (consultTeam == null) {
//                                   不是咨询状态
                                    patients+=(patient+",");
                                }
                            }else {
                                patients+=(patient+",");
                            }
                        }
                    }
                }
                patients =  patients.substring(0,patients.length()-1);
                String result = updateTeamHealthDoctors(newDoctorCode, oldDoctorCode, patients, null);
                return result;
            }
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败");
        }
    }
}

+ 48 - 13
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java

@ -29,27 +29,62 @@ public class SignPatientLabelInfoController extends BaseController {
    /**
     * 根据姓名,地址,身份证号搜索团队内居民
     *
     * @param str
     * @param filter   筛选关键字
     * @param teamCode 团队编码
     * @param page
     * @param pagesize
     * @return
     */
    @RequestMapping(value = "getPatientByParams", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("由姓名|地址|身份证号搜索签约居民")
    public String getPatientByParams(@RequestParam String str,
                                     @RequestParam String teamCode) {
    public String getPatientByParams(@RequestParam String filter,
                                     @RequestParam String teamCode,
                                     @RequestParam int page,
                                     @RequestParam int pagesize) {
        try {
            if (StringUtils.isEmpty(str)) {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索条件不能为空!");
            }
            if (StringUtils.isEmpty(teamCode)) {
                return error(-1, "团队不能为空!");
            }
            JSONObject temp = labelInfoService.search(str, getUID());
            long team = Long.parseLong(teamCode);
            JSONArray temp = labelInfoService.getPatientByParams(getUID(), filter, null, null, team, null, null, page, pagesize);
            return write(200, "查询成功!", "data", temp);
        } catch (Exception e) {
            error(e);
//            return error(-1, "查询失败!");
            return invalidUserException(e,-1, "查询失败!");
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    /**
     * 根据姓名,地址,身份证号搜索团队内未分配健管的居民
     *
     * @param filter   筛选关键字
     * @param teamCode 团队编码
     * @return
     */
    @RequestMapping(value = "getPatientUnSign", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("由姓名|地址|身份证号搜索团队内未分配健管的居民")
    public String getPatientUnSign(@RequestParam String filter,
                                   @RequestParam String teamCode,
                                   @RequestParam int page,
                                   @RequestParam int pagesize) {
        try {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索条件不能为空!");
            }
            if (StringUtils.isEmpty(teamCode)) {
                return error(-1, "团队不能为空!");
            }
            long team = Long.parseLong(teamCode);
            List list = labelInfoService.findNoHealthSignFamilyHealth(filter, team,page,pagesize);
            return write(200, "查询成功!", "data", list);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
@ -394,12 +429,12 @@ public class SignPatientLabelInfoController extends BaseController {
     */
    @RequestMapping(value = "/patient_search_exitdoc")
    public String searchPatientByNameOrLabelExitDoc(@RequestParam(required = true) String filter,
                                             @RequestParam(required = false) String labelCode,
                                             @RequestParam(required = false) String labelType,
                                             @RequestParam(required = true) Long teamCode,
                                             @RequestParam(required = false) String exLabelCode,
                                             @RequestParam(required = false) String exLabelType,
                                             @RequestParam(required = true) int page, @RequestParam(required = true) int pagesize) {
                                                    @RequestParam(required = false) String labelCode,
                                                    @RequestParam(required = false) String labelType,
                                                    @RequestParam(required = true) Long teamCode,
                                                    @RequestParam(required = false) String exLabelCode,
                                                    @RequestParam(required = false) String exLabelType,
                                                    @RequestParam(required = true) int page, @RequestParam(required = true) int pagesize) {
        try {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索字段不能为空");

+ 146 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java

@ -2,15 +2,14 @@ package com.yihu.wlyy.web.doctor.sign;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.doctor.SignPatientLabelDao;
import com.yihu.wlyy.service.app.account.PatientInfoService;
import com.yihu.wlyy.service.app.family.FamilyMemberService;
import com.yihu.wlyy.service.app.message.MessageService;
@ -69,7 +68,77 @@ public class DoctorFamilyContractController extends WeixinBaseController {
    AdminTeamService teamService;
    @Autowired
    FamilyMemberService familyMemberService;
    @Autowired
    SignPatientLabelDao labelDao;
    /**
     * 根据姓名、地址、身份证搜索已分配的居民
     *
     * @param filter
     * @param teamCode
     * @param doctor 健管师编码
     * @param page
     * @param pagesize
     * @return
     */
    @RequestMapping(value = "getPatientByParams")
    @ResponseBody
    @ApiOperation("由姓名|地址|身份证号搜索团队内已分配健管的居民")
    public String getPatientByParams(@RequestParam String filter,
                                     @RequestParam String teamCode,
                                     @RequestParam String doctor,
                                     @RequestParam String level,
                                     @RequestParam int page,
                                     @RequestParam int pagesize) {
        try {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索条件不能为空!");
            }
            if (StringUtils.isEmpty(teamCode)) {
                return error(-1, "团队不能为空!");
            }
            long team = Long.parseLong(teamCode);
//            level 医生身份
            List list = familyContractService.getPatientByLable(doctor, filter, level, team, page, pagesize);
            return write(200, "查询成功!", "data", list);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    /**
     * 分组查询已分配健管的居民的数量
     *
     * @param labelType
     * @param teamCode
     * @return
     */
    @RequestMapping(value = "getPatientByParamsNum")
    @ResponseBody
    public String getPatientByParamsNum(
            @RequestParam String labelType,
            @RequestParam String level,
            @RequestParam Long teamCode) {
        try {
            List listNum = new ArrayList();
            JSONObject list = familyContractService.getPatientByLable(getUID(), labelType, level, teamCode);
            List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(labelType, 1, teamCode);
            for (SignPatientLabel label : s) {
                Map map = new HashMap();
                String labelName = label.getLabelName();
                JSONArray jsonArray = list.getJSONArray(label.getLabelName());
                int length = jsonArray.length();
                map.put("label", labelName);
                map.put("number", length);
                listNum.add(map);
            }
            return write(200, "查询成功!", "data", listNum);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败");
        }
    }
    /**
     * 查看当前医生签约的居民
@ -102,10 +171,10 @@ public class DoctorFamilyContractController extends WeixinBaseController {
        try {
            List<Patient> patients = patientService.findByMobile(mobile);
            return write(200, "获取数据成功!", "data", patients);
        }catch (Exception e) {
                error(e);
                return error(-1, "获取数据失败!");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "获取数据失败!");
        }
    }
    private void addList(JSONObject returnJO, List<Patient> pts, JSONArray array, String key) {
@ -146,6 +215,40 @@ public class DoctorFamilyContractController extends WeixinBaseController {
        }
    }
    /**
     * 根据标签查看当前医生签约的居民  3 健康管理师  2是全科
     */
    @RequestMapping(value = "/getPatientLables")
    @ResponseBody
    public String getPatientLables(String labelType, String level, String oldDoctorCode, Long teamCode) {
        try {
            List listNum = new ArrayList();
            JSONObject list = familyContractService.getPatientByLable(oldDoctorCode, labelType, level, teamCode);
            List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(labelType, 1, teamCode);
            for (SignPatientLabel label : s) {
                Map map = new HashMap();
                String labelName = label.getLabelName();
                JSONArray jsonArray = list.getJSONArray(label.getLabelName());
                List codes = new ArrayList();
                for (int i = 0 ;i<jsonArray.length();i++){
                    JSONObject json = jsonArray.getJSONObject(i);
                    Map info = new HashMap();
                    String code = json.getString("code");
                    String name = json.getString("name");
                    info.put("code",code);
                    info.put("name",name);
                    codes.add(info);
                }
                map.put("label", labelName);
                map.put("codes", codes);
                listNum.add(map);
            }
            return write(200, "查询成功", "data", listNum);
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
    }
    /**
     * 医生签约患者列表查询接口
     *
@ -851,6 +954,38 @@ public class DoctorFamilyContractController extends WeixinBaseController {
        }
    }
    /**
     * 获取没有健康管理师的患者数量
     *
     * @param patientName 患者名称
     * @return
     */
    @RequestMapping(value = "/findNoHealthSignFamilyHealthNum")
    @ResponseBody
    public String findNoHealthSignFamilyHealthNum(
            String labelType,
            @RequestParam(required = false) String patientName,
            Long teamCode) {
        try {
            List listNum = new ArrayList();
            JSONObject list = familyContractService.findNoHealthSignFamilyHealth(getUID(), labelType, patientName, teamCode);
            List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(labelType, 1, teamCode);
            for (SignPatientLabel label : s) {
                Map map = new HashMap();
                String labelName = label.getLabelName();
                JSONArray jsonArray = list.getJSONArray(label.getLabelName());
                int length = jsonArray.length();
                map.put("label", labelName);
                map.put("number", length);
                listNum.add(map);
            }
            return write(200, "查询成功!", "data", listNum);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败");
        }
    }
    /**
     * 获取没有健康管理师的患者列表
     *
@ -901,9 +1036,9 @@ public class DoctorFamilyContractController extends WeixinBaseController {
    @ResponseBody
    public String findByParamsWithDoctor(
            String teamCode,
            String params,String doctor,int level) {
            String params, String doctor, int level) {
        try {
            JSONObject list = familyContractService.findByParamsWithDoctor(doctor, teamCode, params,level);
            JSONObject list = familyContractService.findByParamsWithDoctor(doctor, teamCode, params, level);
            return write(200, "签约数据加载成功!", "data", list);
        } catch (Exception e) {
            return error(-1, "查询失败");
@ -1078,6 +1213,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
    /**
     * 查询患者责任医生、团队医生
     *
     * @return
     */
    @RequestMapping(value = "/consult_doctors", method = {RequestMethod.GET, RequestMethod.POST})

+ 61 - 58
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java

@ -50,6 +50,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    private SurveyUserDao surveyUserDao;
    @Autowired
    WeiXinOpenIdUtils weiXinOpenIdUtils;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * 获取问卷列表
@ -108,7 +109,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            @RequestParam String id) {
        try {
            JSONObject jsonObject = managerQuestionnaireService.getQuestionnaireDetail(id);
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+jsonObject);
            logger.error("jsonObject=====>" + jsonObject);
            return write(200, "查询成功", "data", jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
@ -206,7 +207,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
        try {
//        解析整套问卷json字符串并保存
            JSONObject jsonStr = new JSONObject(jsonData.toString());
            System.out.println("==============================>"+jsonStr);
            System.out.println("==============================>" + jsonStr);
//            获取医生信息(仅限市级管理员)
            String doctor = getUID();
            String accessToken = getAccessToken();
@ -218,25 +219,6 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
        }
    }
    /**
     * 模板列表(按时间降序)和由模板标签获取模板概述getTemplateByLabel合并无标签值为默认列表
     *
     * @return
     *//*
    @RequestMapping(value = "getTemplateList", method = RequestMethod.GET)
    @ApiOperation(value = "模板列表")
    @ResponseBody
    public String getTemplateList(@RequestParam int pageNo,
                                  @RequestParam int pageSize) {
        try {
            List templates = managerQuestionnaireService.getTemplateList(pageNo, pageSize);
            return write(200, "查询成功!", "data", templates);
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "查询失败!");
        }
    }*/
    /**
     * 获取模板标签
     *
@ -247,7 +229,6 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    @ResponseBody
    public String getTemplateLabel() {
        try {
//            JSONObject jsonObject = managerQuestionnaireService.getTemplateLabel();
            List list = managerQuestionnaireService.getTemplateLabel();
            return write(200, "查询成功!", "data", list);
        } catch (Exception e) {
@ -304,6 +285,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            @RequestParam String code) {
        try {
            JSONObject jsonObject = managerQuestionnaireService.getTemplateDetail(code);
            System.out.println("createSurvey's template===============>" + jsonObject);
            return write(200, "查询成功!", "data", jsonObject);
        } catch (Exception e) {
            error(e);
@ -378,7 +360,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    /**
     * 新建问卷保存为模板
     * 引用模板新建问卷保存变更到模板
     * 引用模板新建问卷保存变更到模板(可以增加删除问题)
     *
     * @param code
     * @return
@ -397,17 +379,17 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            int num = 0;
            if (StringUtils.isEmpty(templateCode)) {
//                保存为新模板(重复之后才会有title传进来)
                if (StringUtils.isEmpty(title)){
                if (StringUtils.isEmpty(title)) {
                    num = managerQuestionnaireService.savaSurveyAsTemplate(code, null);
                }else {
                } else {
                    num = managerQuestionnaireService.savaSurveyAsTemplate(code, title);
                }
            } else {
//                修改原模板(重复之后才会有title传进来)
                if (StringUtils.isEmpty(title)){
                if (StringUtils.isEmpty(title)) {
                    num = managerQuestionnaireService.modifyTemplate(code, templateCode, null);
                }else {
                } else {
                    num = managerQuestionnaireService.modifyTemplate(code, templateCode, title);
                }
@ -440,32 +422,13 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            @ApiParam(value = "问卷编码")
            @RequestParam String code) {
        try {
            /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//            sdf.format(new Date());
            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
            String accessToken = getAccessToken();
            System.out.println("accessToken=====>" + accessToken);
            JSONObject json = new JSONObject(str);
            List<String> codes = surveyUserDao.findBySurveyCodeAndStatus(code);
            json.put("survey_id", code);
            for (String cod : codes) {
                Patient p = patientDao.findByCode(cod);
                String name = p.getName();
                String openId = p.getOpenid();
                System.out.println("controller=====>cod " + cod + " name " + name + " openId " + openId);
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", cod);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                pushMsgTask.sendWeixinMessage(accessToken, 11, openId, name, json);
            }*/
            List<String> codes = surveyUserDao.findBySurveyCodeAndStatus(code);
            String accessToken = getAccessToken();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
            JSONObject json = new JSONObject(str);
            codes.stream().forEach(c -> {
           /* codes.stream().forEach(c -> {
                Patient p = patientDao.findByCode(c);
                String name = p.getName();
                String openId = p.getOpenid();
@ -473,27 +436,67 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
                json.put("toUser", c);
                json.put("survey_id", code);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                logger.error("patient =======>" + code);
                logger.error("name =======>" + name);
                logger.error("openId =======>" + openId);
                //判断是否判定openId,有没有发则查找家人发送
                if(StringUtils.isNotBlank(p.getOpenid())){
                //判断是否有openId,有发送没有则查找家人发送
                if (StringUtils.isNotBlank(p.getOpenid())) {
                    // 添加到发送队列
                    logger.error("json =======>" + json);
                    PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                }else{
                    JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                } else {
                    JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
                    Patient member = (Patient) j.get("member");
                    if(StringUtils.isNotBlank(member.getOpenid())){
                    if (StringUtils.isNotBlank(member.getOpenid())) {
                        String first = (String) json.get("first");
                        json.remove("first");
                        try{
                            json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                        }catch (Exception e){
                        try {
                            json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        PushMsgTask.getInstance().putWxMsg(getAccessToken(), 11, member.getOpenid(), member.getName(), json);
                        logger.error("没有opIn  json =======>" + json);
                        PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                    }
                }
            });*/
            new Thread() {
                public void run() {
                    for (String c : codes) {
                        Patient p = patientDao.findByCode(c);
                        String name = p.getName();
                        String openId = p.getOpenid();
                        json.put("keyword2", sdf.format(new Date()));
                        json.put("toUser", c);
                        json.put("survey_id", code);
                        json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                        //判断是否判定openId,有没有发则查找家人发送
                        if (StringUtils.isNotBlank(p.getOpenid())) {
                            // 添加到发送队列
                            logger.error("json =======>" + json);
//                            PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                            PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
                        } else {
                            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
                            Patient member = (Patient) j.get("member");
                            if (StringUtils.isNotBlank(member.getOpenid())) {
                                String first = (String) json.get("first");
                                json.remove("first");
                                try {
                                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                logger.error("没有opIn  json =======>" + json);
//                                PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, member.getOpenid(), member.getName(), json);
                            }
                        }
                    }
                }
            });
            }.start();
            return write(200, "发送成功!");
        } catch (Exception e) {

+ 1 - 1
patient-co-wlyy/src/main/resources/system.properties

@ -80,7 +80,7 @@ chat_server=http://weixin.xmtyw.cn/res/chat/
sign_check_upload=http://172.19.103.87:8011/wlyy_service
# IM配置
im_list_get=http://172.19.103.88:3000/
im_list_get=http://172.19.103.29:3008/
#im_list_get=http://192.168.131.102:3008/
im_group_server=http://172.19.103.29:3000/api/v1/chats/gm
msg_push_server=http://172.19.103.29:3000/api/v1/chats/sm