Selaa lähdekoodia

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

liuwenbin 7 vuotta sitten
vanhempi
commit
1693bbf885
42 muutettua tiedostoa jossa 3747 lisäystä ja 904 poistoa
  1. 3 2
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/controller/manager/device/DeviceHealthIndexController.java
  2. 362 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/controller/manager/notification/WeChatController.java
  3. 147 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/wechat/WechatTemplateConfig.java
  4. 71 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/wechat/WeixinTemplate.java
  5. 18 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/repository/wechat/WechatTemplateConfigDao.java
  6. 49 1
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/device/DeviceHealthIndexService.java
  7. 509 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/wechat/WeChatService.java
  8. 191 0
      patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_edit.jsp
  9. 575 0
      patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_edit_js.jsp
  10. 44 0
      patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_list.jsp
  11. 284 0
      patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_list_js.jsp
  12. 10 0
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/entity/Patient.java
  13. 4 4
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/service/SignRenewZYService.java
  14. 1 1
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/service/SignZYService.java
  15. 0 1
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java
  16. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/health/repository/DevicePatientHealthIndexDao.java
  17. 115 81
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java
  18. 63 37
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java
  19. 13 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java
  20. 49 10
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyMemberService.java
  21. 19 15
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthGuidanceService.java
  22. 178 6
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java
  23. 69 48
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/physicalExamination/PhysicalExaminationRemindService.java
  24. 18 4
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prenatalInspector/PrenatalInspectorPreCardService.java
  25. 58 14
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionNoticesService.java
  26. 178 166
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  27. 34 21
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/PatientRemindService.java
  28. 236 186
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java
  29. 50 43
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java
  30. 13 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorFeldsherTemplateService.java
  31. 56 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/iot/IotDeviceService.java
  32. 36 19
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/task/RemindExpensesTask.java
  33. 14 24
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultPublicController.java
  34. 17 17
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java
  35. 32 36
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java
  36. 82 65
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/booking/PatientBookingController.java
  37. 54 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java
  38. 8 4
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/PatientHealthController.java
  39. 3 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/iot/IotMonitoringHealthController.java
  40. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/iot/IotDeviceController.java
  41. 81 85
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/zysoft/BookingController.java
  42. 1 1
      patient-co/patient-co-wlyy/src/main/resources/application-test.yml

+ 3 - 2
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/controller/manager/device/DeviceHealthIndexController.java

@ -97,9 +97,10 @@ public class DeviceHealthIndexController extends BaseController{
            @RequestParam(value = "indexTypeMax1",required = false) Double indexTypeMax1,
            @RequestParam(value = "indexTypeMin2",required = false) Double indexTypeMin2,
            @RequestParam(value = "indexTypeMax2",required = false) Double indexTypeMax2,
            @RequestParam(value = "doctorName",required = false) String doctorName,
            HttpServletResponse response){
        try {
            List<DeviceHealthIndexVO> deviceHealthIndexes = healthIndexService.getExcelByFilter(deviceSn,date, idcard, userName, indexType,indexTypeMin1,indexTypeMax1,indexTypeMin2,indexTypeMax2);
            List<DeviceHealthIndexVO> deviceHealthIndexes = healthIndexService.getExcelByFilter(deviceSn,date, idcard, userName, indexType,indexTypeMin1,indexTypeMax1,indexTypeMin2,indexTypeMax2,doctorName);
            response.setContentType("octets/stream");
            response.setHeader("Content-Disposition", "attachment; filename="+ new String( "patientHealthIndexDataList.xls"));
            OutputStream os = response.getOutputStream();
@ -182,7 +183,7 @@ public class DeviceHealthIndexController extends BaseController{
                addCell(ws, i, 1, format.format(m.getCzrq()),"");
                addCell(ws, i, 2, m.getIdcard(),"");
                addCell(ws, i, 3, m.getUserName(),"");
                addCell(ws, i, 4, "","");
                addCell(ws, i, 4, type,"");
                addCell(ws, i, 5, m.getValue1(),"");
                addCell(ws, i, 6, m.getValue2(),"");
                addCell(ws, i, 7, m.getValue3(),"");

+ 362 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/controller/manager/notification/WeChatController.java

@ -0,0 +1,362 @@
package com.yihu.wlyy.controller.manager.notification;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.controller.BaseController;
import com.yihu.wlyy.entity.User;
import com.yihu.wlyy.entity.WlyyAuditNotice;
import com.yihu.wlyy.entity.WlyyAuditNoticeScope;
import com.yihu.wlyy.entity.WlyyUserRole;
import com.yihu.wlyy.service.manager.notification.WlyyAuditNoticeScopeService;
import com.yihu.wlyy.service.manager.notification.WlyyAuditNoticeService;
import com.yihu.wlyy.service.manager.wlyyrole.WlyyUserRoleService;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
 * Created by yww on 2017/1/22.
 */
@Controller
@RequestMapping("/admin/notification")
public class NotificationController extends BaseController {
    @Autowired
    private WlyyAuditNoticeService wlyyAuditNoticeService;
    @Autowired
    private WlyyAuditNoticeScopeService wlyyAuditNoticeScopeService;
    @Autowired
    private WlyyUserRoleService wlyyUserRoleService;
    @RequestMapping(value = "initial", method = RequestMethod.GET)
    @ApiIgnore
    public String notificationListInitial(Model model) {
        User currentUser = (User) request.getSession().getAttribute("current_user");
        model.addAttribute("isAuditor", wlyyAuditNoticeService.isAuditor(currentUser));
        return "notification/notification_list";
    }
    //跳转消息通知详情页
    @RequestMapping(value = "view", method = RequestMethod.GET)
    @ApiIgnore
    public String notificationView(Model model, @RequestParam(value = "id", required = true) Long id, String mode) {
        User currentUser = (User) request.getSession().getAttribute("current_user");
        WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
        WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeService.findByNoticeId(id);
        model.addAttribute("notice", notice);
        model.addAttribute("noticeId", notice.getId());
        model.addAttribute("title", notice.getTitle());
        model.addAttribute("status", notice.getStatus());
        model.addAttribute("time", notice.getSendTime());
        model.addAttribute("scope", notice.getConditionDescription());
        model.addAttribute("content", notice.getContent());
        model.addAttribute("totalCount", "总共 " + notice.getTotalCount() + " 人");
        model.addAttribute("isAuditor", wlyyAuditNoticeService.isAuditor(currentUser));
        model.addAttribute("isOwned", false);//页面判断用于显示操作按钮
        if (StringUtils.equals(notice.getApplyUserId(), currentUser.getCode())) {
            model.addAttribute("isOwned", true);
        }
        if (noticeScope != null) {
            if (!StringUtils.isEmpty(noticeScope.getServerTypeContent())) {
                model.addAttribute("serverTypeContent", noticeScope.getServerTypeContent());
            }
            if (!StringUtils.isEmpty(noticeScope.getHealthSituationContent())) {
                model.addAttribute("healthSituationContent", noticeScope.getHealthSituationContent());
            }
            if (!StringUtils.isEmpty(noticeScope.getDiseaseTypeContent())) {
                model.addAttribute("diseaseTypeContent", noticeScope.getDiseaseTypeContent());
            }
        }
        model.addAttribute("mode",mode);
        return "notification/notification_view";
    }
    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ResponseBody
    public String searchNotificationList(
            @ApiParam(name = "searchNm", value = "标题/提交人名")
            @RequestParam(value = "searchNm", required = false) String searchNm,
            @ApiParam(name = "status", value = "状态")
            @RequestParam(value = "status", required = false) String status,
            @ApiParam(name = "page")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "rows")
            @RequestParam(value = "rows") int pageSize) {
        try {
            User currentUser = (User) request.getSession().getAttribute("current_user");
            Page<WlyyAuditNotice> notices = wlyyAuditNoticeService.searchList(searchNm, status, currentUser, page, pageSize);
            return write(200, "操作成功", page, pageSize, notices);
        } catch (Exception ex) {
            error(ex);
            return error(-1, "操作失败");
        }
    }
    //页面跳转(详情页面)
    @RequestMapping(value ="infoInit/{id}",method = RequestMethod.GET)
    public String infoInit(@PathVariable("id") Long id, String mode){
        if(id==0){
            request.setAttribute("UUID", UUID.randomUUID().toString().replace("-", ""));
        }
        User currentUser = (User) request.getSession().getAttribute("current_user");
        //范围权限
        String city = "350200";
        String cityAuthority = "0";
        String areaAuthority = "0";
        String communityAuthority = "0";
        List<Map<String, String>> roleMap = (List<Map<String, String>>)request.getSession().getAttribute("roleMap");
        if(roleMap.size()>0){//管理员
            for (Map<String, String> map : roleMap){
                String code = map.get("code");
                if(city.equals(code)){
                    cityAuthority = "1";
                    areaAuthority = "1";
                    communityAuthority = "1";
                }else if(code.length()==6){
                    areaAuthority = "1";
                    communityAuthority = "1";
                }else {
                    communityAuthority = "1";
                }
            }
        }else{
            //社区医生
            communityAuthority = "2";
        }
        request.setAttribute("cityAuthority", cityAuthority);
        request.setAttribute("areaAuthority", areaAuthority);
        request.setAttribute("communityAuthority", communityAuthority);
        request.setAttribute("id", id);
        request.setAttribute("mode",mode);
        request.setAttribute("isAuditor", wlyyAuditNoticeService.isAuditor(currentUser));
        return "notification/notification_edit";
    }
    //根据id获取单个
    @RequestMapping(value = "notice")
    @ResponseBody
    public String getNotice(@RequestParam(value = "id") Long id){
        try {
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeService.findByNoticeId(id);
            JSONObject json = new JSONObject();
            json.put("noticeId",notice.getId());
            json.put("title",notice.getTitle());
            json.put("content",notice.getContent());
            json.put("sendTime",notice.getSendTime());
            json.put("sendType",notice.getSendType());
            json.put("scope",noticeScope.getScope());
            json.put("scopeId",noticeScope.getScopeId());
            json.put("condition",noticeScope.getCondition());
            json.put("diseaseTypeId",noticeScope.getDiseaseTypeId());
            json.put("healthSituationId",noticeScope.getHealthSituationId());
            json.put("serverTypeId",noticeScope.getServerTypeId());
            return write(200,"操作成功!","data",json);
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    /**
     * 是否有有审核权限
     * @return
     */
    @RequestMapping(value = "isNoticeAuditor")
    @ResponseBody
    public String isNoticeAuditor(){
        try {
            User currentUser = (User) request.getSession().getAttribute("current_user");
            boolean flag = wlyyAuditNoticeService.isNoticeAuditor(currentUser.getCode(),String.valueOf(currentUser.getOrganizationId()));
            if(flag){
                return write(200,"有权限!","authority","1");
            }
            return write(200,"没权限!","authority","0");
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    //新增
    @RequestMapping(value = "create")
    @ResponseBody
    public String createNotice(String jsonData) {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String,String> map = objectMapper.readValue(jsonData, Map.class);
            User currentUser = (User) request.getSession().getAttribute("current_user");
            wlyyAuditNoticeService.create(map, currentUser);
            return success("新增成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "新增失败!");
        }
    }
    /**
     * 提交
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "submit")
    @ResponseBody
    public String submit(
            @RequestParam(value = "id", required = true) Long id) {
        try {
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            User currentUser = (User) request.getSession().getAttribute("current_user");
            //判断是否为审核者(审核者只能看到非本人的待审核通知,看不到待提交通知)
            if (!StringUtils.equals("1", notice.getStatus())) {
                return error(-1, "提交状态的消息通知才能进行提交操作!");
            }
            boolean res = wlyyAuditNoticeService.isAuditor(currentUser);
            if (res) {
                //审核者自己的消息通知,直接通过+发信息+保存发送对象信息
                wlyyAuditNoticeService.approve(id, notice, currentUser);
                return write(200, "操作成功");
            } else {
                notice.setStatus("2");
                wlyyAuditNoticeService.save(notice);
                return write(200, "操作成功");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    /**
     * 撤回
     * @param id
     * @return
     */
    @RequestMapping(value = "revoke")
    @ResponseBody
    public String revoke(
            @RequestParam(value = "id", required = true) Long id){
        try {
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            if("2".equals(notice.getStatus())){//待审核
                notice.setStatus("6");//撤回
                wlyyAuditNoticeService.save(notice);
            }else{
                return error(-1, "撤回失败,只有待审核才能撤回!");
            }
            return success("撤回成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "撤回失败!");
        }
    }
    //修改
    @RequestMapping(value = "update")
    @ResponseBody
    public String updateNotice(String jsonData){
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String,String> map = objectMapper.readValue(jsonData, Map.class);
            User currentUser = (User) request.getSession().getAttribute("current_user");
            wlyyAuditNoticeService.updateNotice(map, currentUser);
            return success("修改成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "修改失败!");
        }
    }
    //删除
    @RequestMapping(value = "delete")
    @ResponseBody
    public String deleteNotification(long id) {
        try {
            User currentUser = (User) request.getSession().getAttribute("current_user");
            //是本人的消息通知才能删除
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            if (notice == null) {
                return error(-1, "id有误!");
            }
            if (!StringUtils.equals(notice.getApplyUserId(), currentUser.getCode())) {
                return error(-1, "非本人的消息通知,没有权限删除!");
            }
            wlyyAuditNoticeService.deleteNotice(id);
            return write(200, "操作成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    //审核通过
    @RequestMapping(value = "approve")
    @ResponseBody
    public String approve(long id) {
        try {
            User currentUser = (User) request.getSession().getAttribute("current_user");
            //验证消息通知为待审核
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            if (notice == null) {
                return error(-1, "提供的id有误!");
            }
            if (!StringUtils.equals("2", notice.getStatus())) {
                return error(-1, "消息状态不符,待审核状态才能进行审核操作!");
            }
            String auditorCode = currentUser.getCode();
            String noticeHospital = notice.getApplyUserHospital();
            if (StringUtils.isEmpty(noticeHospital)) {
                return error(-1, "消息通知机构信息有误,为空值!");
            }
            //审核权限验证(审核者的下辖机构有此消息通知编辑者所属机构)
            boolean res = wlyyAuditNoticeService.isNoticeAuditor(auditorCode, noticeHospital);
            wlyyAuditNoticeService.approve(id, notice, currentUser);
            return write(200, "操作成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    @RequestMapping(value = "refuse")
    @ResponseBody
    public String refuse(
            @RequestParam(value = "id", required = true) Long id) {
        try {
            if (id == null) {
                return error(-1, "id不能为空!");
            }
            User currentUser = (User) request.getSession().getAttribute("current_user");
            //是本人的消息通知才能删除
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            if (notice == null) {
                return error(-1, "id有误!");
            }
            notice.setStatus("5");
            wlyyAuditNoticeService.save(notice);
            return write(200, "操作成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
}

+ 147 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/wechat/WechatTemplateConfig.java

@ -0,0 +1,147 @@
package com.yihu.wlyy.entity.wechat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * 微信消息模板按场景区分消息内容
 * @author WuJunjie
 */
@Entity
@Table(name = "weixin_template_config")
public class WechatTemplateConfig extends IdEntity {
	private static final long serialVersionUID = -7399054549159698617L;
	private String templateName;//'自定义模板名称'
    private String scene;//使用场景值
    private String sceneDescription;//'使用场景描述'
    private String first;
    private String url;//模板消息'跳转链接'
    private String remark;
    private String keyword1;
    private String keyword2;
    private String keyword3;
    private String keyword4;
    private String keyword5;
    private String keyword6;
    private String keyword7;
    private Integer status;//状态 1:正常 0:删除
    public static long getSerialVersionUID() {
        return serialVersionUID;
    }
    public String getTemplateName() {
        return templateName;
    }
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }
    public String getScene() {
        return scene;
    }
    public void setScene(String scene) {
        this.scene = scene;
    }
    public String getSceneDescription() {
        return sceneDescription;
    }
    public void setSceneDescription(String sceneDescription) {
        this.sceneDescription = sceneDescription;
    }
    public String getFirst() {
        return first;
    }
    public void setFirst(String first) {
        this.first = first;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    public String getKeyword1() {
        return keyword1;
    }
    public void setKeyword1(String keyword1) {
        this.keyword1 = keyword1;
    }
    public String getKeyword2() {
        return keyword2;
    }
    public void setKeyword2(String keyword2) {
        this.keyword2 = keyword2;
    }
    public String getKeyword3() {
        return keyword3;
    }
    public void setKeyword3(String keyword3) {
        this.keyword3 = keyword3;
    }
    public String getKeyword4() {
        return keyword4;
    }
    public void setKeyword4(String keyword4) {
        this.keyword4 = keyword4;
    }
    public String getKeyword5() {
        return keyword5;
    }
    public void setKeyword5(String keyword5) {
        this.keyword5 = keyword5;
    }
    public String getKeyword6() {
        return keyword6;
    }
    public void setKeyword6(String keyword6) {
        this.keyword6 = keyword6;
    }
    public String getKeyword7() {
        return keyword7;
    }
    public void setKeyword7(String keyword7) {
        this.keyword7 = keyword7;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 71 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/wechat/WeixinTemplate.java

@ -0,0 +1,71 @@
package com.yihu.wlyy.entity.wechat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * @Description: 记录各公众号模板详情及自定义类型
 * @Author: WuJunjie
 * @Date: Created in 2018/2/24 17:38
 */
@Entity
@Table(name = "weixin_template")
public class WeixinTemplate  extends IdEntity {
    private String accId;//'微信公众号原始ID'
    private String templateName;//'自定义模板名称'
    private String templateTitle;//'模板标题'
    private Integer type;//'自定义模板类型'
    private String format;//'模板内容格式'
    private Integer status;//'模板状态 1:正常  0:删除'
    public String getAccId() {
        return accId;
    }
    public void setAccId(String accId) {
        this.accId = accId;
    }
    public String getTemplateName() {
        return templateName;
    }
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }
    public String getTemplateTitle() {
        return templateTitle;
    }
    public void setTemplateTitle(String templateTitle) {
        this.templateTitle = templateTitle;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    public String getFormat() {
        return format;
    }
    public void setFormat(String format) {
        this.format = format;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 18 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/repository/wechat/WechatTemplateConfigDao.java

@ -0,0 +1,18 @@
package com.yihu.wlyy.repository.wechat;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @Description: 分场景值查询模板文案内容
 * @Author: WuJunjie
 * @Date: Created in 2018/2/23 11:51
 */
public interface WechatTemplateConfigDao extends PagingAndSortingRepository<WechatTemplateConfig, Long>, JpaSpecificationExecutor<WechatTemplateConfig> {
    //根据自定义模板名称、场景值查询有效模板内容
    @Query("select t  from WechatTemplateConfig t where t.templateName=?1 and t.scene=?2 and t.status = 1 ")
    WechatTemplateConfig findByScene(String templateName,String scene);
}

+ 49 - 1
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/device/DeviceHealthIndexService.java

@ -165,9 +165,21 @@ public class DeviceHealthIndexService extends BaseDeviceJpaService<DeviceHealthI
    }
    public List<DeviceHealthIndexVO> getExcelByFilter(String deviceSn,String date,String idcard,
                                                String userName,String indexType,Double indexTypeMin1,Double indexTypeMax1,Double indexTypeMin2,Double indexTypeMax2)throws Exception{
                                                String userName,String indexType,Double indexTypeMin1,Double indexTypeMax1,Double indexTypeMin2,Double indexTypeMax2,String doctorName)throws Exception{
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        User loginUser = (User) request.getSession().getAttribute("userInfo");
        StringBuilder filter = new StringBuilder();
        //1、管理员  2、医生 0、其他
        if(loginUser.getType()==2){
            Doctor doctor = doctorDao.findByCode(loginUser.getCode());
            String[] codes =signFamilyDao.findByHospital(doctor.getHospital());
            if(codes != null && codes.length >0){
                filter.append("user="+StringUtils.join(codes, ","));
            }
        }
        if(!StringUtils.isEmpty(deviceSn)){
            filter.append("deviceSn="+deviceSn+";");
        }
@ -192,9 +204,44 @@ public class DeviceHealthIndexService extends BaseDeviceJpaService<DeviceHealthI
                filter.append("user="+StringUtils.join(codes, ","));
            }
        }
        //根据医生名称过滤居民
        if(!StringUtils.isEmpty(doctorName)){
            String[] codes = signFamilyDao.findByDoctorName("%"+doctorName+"%");
            if(codes != null && codes.length >0){
                filter.append("user="+StringUtils.join(codes, ","));
            }
        }
        if(!StringUtils.isEmpty(indexType)){
            filter.append("type="+indexType+";");
        }
        if("1".equals(indexType)||"2".equals(indexType)||"4".equals(indexType)){
            if(indexTypeMin1!=null){
                filter.append("value1>="+indexTypeMin1+";");
            }
            if(indexTypeMax1!=null){
                filter.append("value1<="+indexTypeMax1+";");
            }
            if(indexTypeMin2!=null){
                filter.append("value2>="+indexTypeMin2+";");
            }
            if(indexTypeMax2!=null){
                filter.append("value2<="+indexTypeMax2+";");
            }
        }else{
            if(indexTypeMin1!=null){
                filter.append("value3>="+indexTypeMin1+";");
            }
            if(indexTypeMax1!=null){
                filter.append("value3<="+indexTypeMax1+";");
            }
            if(indexTypeMin2!=null){
                filter.append("value4>="+indexTypeMin2+";");
            }
            if(indexTypeMax2!=null){
                filter.append("value4<="+indexTypeMax2+";");
            }
        }
        List<DeviceHealthIndex> list = (List<DeviceHealthIndex>)search(filter.toString());
        String regex = "(\\w{3})(\\w+)(\\w{3})";
        List<DeviceHealthIndexVO> listTemp = new ArrayList<>();
@ -202,6 +249,7 @@ public class DeviceHealthIndexService extends BaseDeviceJpaService<DeviceHealthI
            for (DeviceHealthIndex info : list){
                DeviceHealthIndexVO bean = new DeviceHealthIndexVO();
                BeanUtils.copyProperties(info, bean);
//                BeanUtils.copyProperties(bean, info);
                Patient patient = findPatient(bean.getUser());
                bean.setUserName(patient== null?"":patient.getName());
                if(StringUtils.isNotBlank(bean.getIdcard())){

+ 509 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/wechat/WeChatService.java

@ -0,0 +1,509 @@
package com.yihu.wlyy.service.manager.notification;
import com.yihu.wlyy.entity.*;
import com.yihu.wlyy.repository.*;
import com.yihu.wlyy.service.SMSService;
import com.yihu.wlyy.service.manager.wlyyrole.WlyyRoleService;
import com.yihu.wlyy.service.manager.wlyyrole.WlyyUserRoleService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
 * Created by Administrator on 2017/1/22.
 */
@Service
public class WlyyAuditNoticeService extends BaseJpaService<WlyyAuditNotice, WlyyAuditNoticeDao> {
    @Autowired
    private WlyyRoleDao wlyyRoleDao;
    @Autowired
    private WlyyRoleService roleService;
    @Autowired
    private WlyyUserRoleDao wlyyUserRoleDao;
    @Autowired
    private WlyyUserRoleService wlyyUserRoleService;
    @Autowired
    private WlyyAuditNoticeDao wlyyAuditNoticeDao;
    @Autowired
    private WlyyAuditNoticeScopeDao wlyyAuditNoticeScopeDao;
    @Autowired
    private WlyyAuditNoticeObjectDao wlyyAuditNoticeObjectDao;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SMSService smsService;
    /**
     * 新增消息
     * @param map
     * @param user
     */
    @Transactional
    public void create(Map<String,String> map,User user){
        String communityAuthority = map.get("communityAuthority");
        String scope = map.get("scope");// 0- 全市 1 - 指定区 2 - 指定社区
        String scopeId = map.get("scopeId");//范围明细ID,scope=1时为区ID串,2时为社区id串
        String scopeContent = map.get("scopeContent");//
        String city = map.get("city");
        String town = map.get("town");
        String community = map.get("community");
        String conditionDescription = map.get("conditionDescription");
        String conditionType = map.get("condition_type");//筛选条件:0-全部;1-根据条件
        String condition = map.get("condition");//0 - 全部居民   1 - 设置条件?  设置的条件类别:1:卫计委三大分组(服务类型) 2:健康状况 3:疾病类型
        String conditionId = map.get("conditionId");//0 - 全部居民   1 - 设置条件
        String serverTypeContent = map.get("serverTypeContent");
        String serverTypeId = map.get("serverTypeId");
        String healthSituationContent = map.get("healthSituationContent");
        String healthSituationId = map.get("healthSituationId");
        String diseaseTypeContent = map.get("diseaseTypeContent");
        String diseaseTypeId = map.get("diseaseTypeId");
        String sendType = map.get("sendType");
        String content = map.get("content");
        List<Patient> list = getSendPatients(conditionType, scope, city, town, community, serverTypeId, healthSituationId, diseaseTypeId);
        //需要审核的通知公告主表
        WlyyAuditNotice notice = new WlyyAuditNotice();
        notice.setApplyTime(new Date());
        notice.setApplyUserHospital(user.getOrganizationId()+"");
        notice.setApplyUserId(user.getCode());
        notice.setApplyUserName(user.getName());
        notice.setConditionDescription(conditionDescription);
        notice.setContent(content);
        String status = "";// 0 - 创建(瞬间状态) 1- 待提交  2 - 待审核 3 - 待发送 4 - 已发送  5 - 已拒绝 6 - 撤回(处于待审核时可修改为该状态)
        if("2".equals(communityAuthority)){
            //医生 需要审核
            status = "2";
        }else{
            //管理员 直接发送(设置状态,还未执行)
            status = "4";
            notice.setAuditTime(new Date());
            notice.setAuditUserId(user.getCode());
            notice.setAuditUserName(user.getName());
        }
        notice.setStatus(status);
//        notice.setApplyUserHospital(user.getOrganizationName());
        notice.setSendType(sendType);
        if("1".equals(sendType)){
            notice.setSendTime(DateUtil.strToDateLong(map.get("sendTime")+":00"));
        }
        notice.setTitle(map.get("title"));
        notice.setTotalCount(list.size());
        wlyyAuditNoticeDao.save(notice);
        //消息公告对象范围主表
        WlyyAuditNoticeScope noticeScope = new WlyyAuditNoticeScope();
        noticeScope.setNoticeId(notice.getId());
        noticeScope.setScope(scope);
        noticeScope.setScopeContent(scopeContent);
        noticeScope.setScopeId(scopeId);
//        noticeScope.setCondition(condition);
        noticeScope.setCondition(conditionType);
        noticeScope.setServerTypeId(serverTypeId);
        noticeScope.setServerTypeContent(serverTypeContent);
        noticeScope.setHealthSituationId(healthSituationId);
        noticeScope.setHealthSituationContent(healthSituationContent);
        noticeScope.setDiseaseTypeId(diseaseTypeId);
        noticeScope.setDiseaseTypeContent(diseaseTypeContent);
        noticeScope.setConditionDescription(conditionDescription);
        wlyyAuditNoticeScopeDao.save(noticeScope);
        //审核自身消息通知自己发短信操作(新线程)****************新线程发彩信
        if (isAuditor(user)) {
            sendMsgThread(list, notice);
        }
//        if("3".equals(status)){
//            saveNoticeObject(list,notice);
//        }
    }
    /**
     * 保存消息通知对象
     * @param list
     * @param notice
     */
//    private void saveNoticeObject(List<Patient> list,WlyyAuditNotice notice){
//        //需要审核的通知公告对象
//        WlyyAuditNoticeObject noticeObject = null;
//        List<WlyyAuditNoticeObject> objectList = new ArrayList<>();
//        String mobiles = "";
//        int i = 0;
//        for (Patient p:list){
//            noticeObject = new WlyyAuditNoticeObject();
//            noticeObject.setNoticeId(notice.getId());
//            noticeObject.setToUserId(p.getCode());
//            noticeObject.setToUserTel(p.getMobile());
//            noticeObject.setContent(notice.getContent());
//            //TODO 每次条用发送短信接口,根据返回信息对应更新状态,保存数据(若被中断时?)
//            //smsService.sendMsg(mobiles,content);//判断返回值,设置发送状态--立即发送时
//
//            noticeObject.setStatus(notice.getStatus());//?未发送
//            noticeObject.setSendTime(new Date());
//            noticeObject.setInsertTime(new Date());
//            objectList.add(noticeObject);
//
//            i++;
//            mobiles += p.getMobile()+",";
//            if(i%901==0){//900条发一次
//                mobiles = mobiles.substring(0,mobiles.length()-1);
//                //smsService.sendMsg(mobiles,content);
//                System.out.println("i="+i+"---mobile="+mobiles);
//                mobiles = "";
//            }else if(i==list.size()){
//                mobiles = mobiles.substring(0,mobiles.length()-1);
//                //smsService.sendMsg(mobiles,content);
//                System.out.println("i="+i+"---mobile="+mobiles);
//                mobiles = "";
//            }
//        }
//
//        if(objectList.size()>0){
//            wlyyAuditNoticeObjectDao.save(objectList);
//        }
//    }
    /**
     * 按条件查询居民
     * @param conditionType
     * @param scope
     * @param city
     * @param town
     * @param community
     * @param serverTypeId
     * @param healthSituationId
     * @param diseaseTypeId
     * @return
     */
    public List<Patient> getSendPatients(String conditionType,String scope,String city,String town,String community,String serverTypeId,String healthSituationId,String diseaseTypeId){
        List<Patient> list = null;
        String sql = "";
        //根据发送范围,筛选条件过滤出居民
        if("0".equals(conditionType)){//筛选条件分支:全部居民
            if("0".equals(scope)){
                list = patientDao.findByCity(city);//全市全部居民
            }else if("1".equals(scope)){
                String towns[] = town.split(",");
                list = patientDao.findByCityAndTowns(city,towns);//指定区全部居民
            }else if("2".equals(scope)){
                String communitys[] = community.split(",");
                list = patientDao.findByCityAndHospital(city,communitys);//指定社区全部居民
            }
        }else if ("1".equals(conditionType)){//筛选条件分支:按条件(服务类型、健康状况、疾病类型)
            //筛选条件
            String conditionSql = "";
            if(!StringUtils.isEmpty(serverTypeId)){
                conditionSql += " (s.label_type=1 and s.label in ("+serverTypeId+")) ";
                String[] serverTypeIds = serverTypeId.split(",");
            }
            if(!StringUtils.isEmpty(healthSituationId)){
                if(StringUtils.isEmpty(conditionSql)){
                    conditionSql += " (s.label_type=2 and s.label in ("+healthSituationId+"))";
                }else {
                    conditionSql += " or (s.label_type=2 and s.label in ("+healthSituationId+"))";
                }
                String[] healthSituationIds = healthSituationId.split(",");
            }
            if(!StringUtils.isEmpty(diseaseTypeId)){
                if(StringUtils.isEmpty(conditionSql)){
                    conditionSql += " (s.label_type=3 and s.label in ("+diseaseTypeId+")) ";
                }else {
                    conditionSql += " or (s.label_type=3 and s.label in ("+diseaseTypeId+")) ";
                }
                String[] diseaseTypeIds = diseaseTypeId.split(",");
            }
            //-------------发送范围
            if("0".equals(scope)){
                sql += "SELECT DISTINCT p.* from wlyy_patient p " +
                        " WHERE p.city=350200 and p.mobile is not null and p.mobile!='' and p.code in(select DISTINCT s.patient " +
                        " from wlyy_sign_patient_label_info s " +
                        " where "+conditionSql+")";
                SQLQuery sqlQuery = currentSession().createSQLQuery(sql).addEntity(Patient.class);
                list = sqlQuery.list();
            }else if("1".equals(scope)){
                sql += "SELECT DISTINCT p.* from wlyy_patient p " +
                        " WHERE p.city=350200 and p.town in ("+town+") and p.mobile is not null and p.mobile!='' and p.code in(select DISTINCT s.patient " +
                        " from wlyy_sign_patient_label_info s " +
                        " where "+conditionSql+")";
                SQLQuery sqlQuery = currentSession().createSQLQuery(sql).addEntity(Patient.class);
                list = sqlQuery.list();
            }else if("2".equals(scope)){
                community = "'" + community.replace(",","','") + "'";//字符类型数据库需要添加''
                sql += "SELECT DISTINCT p.* from wlyy_patient p LEFT JOIN wlyy_sign_family f on p.code = f.patient " +
                        " WHERE p.city=350200 and f.hospital in ("+community+") and p.mobile is not null and p.mobile!='' and p.code in(select DISTINCT s.patient " +
                        " from wlyy_sign_patient_label_info s " +
                        " where "+conditionSql+")";
                SQLQuery sqlQuery = currentSession().createSQLQuery(sql).addEntity(Patient.class);
                list = sqlQuery.list();
            }
        }
        return list;
    }
    /**
     * 编辑消息
     * @param map
     * @param user
     */
    @Transactional
    public void updateNotice(Map<String,String> map,User user){
        Long noticeId = Long.parseLong(map.get("id"));
        String communityAuthority = map.get("communityAuthority");
        String scope = map.get("scope");// 0- 全市 1 - 指定区 2 - 指定社区
        String scopeId = map.get("scopeId");//范围明细ID,scope=1时为区ID串,2时为社区id串
        String scopeContent = map.get("scopeContent");//
        String city = map.get("city");
        String town = map.get("town");
        String community = map.get("community");
        String conditionDescription = map.get("conditionDescription");
        String conditionType = map.get("condition_type");//筛选条件:0-全部;1-根据条件
        String serverTypeContent = map.get("serverTypeContent");
        String serverTypeId = map.get("serverTypeId");
        String healthSituationContent = map.get("healthSituationContent");
        String healthSituationId = map.get("healthSituationId");
        String diseaseTypeContent = map.get("diseaseTypeContent");
        String diseaseTypeId = map.get("diseaseTypeId");
        String sendType = map.get("sendType");
        String content = map.get("content");
        List<Patient> list = getSendPatients(conditionType, scope, city, town, community, serverTypeId, healthSituationId, diseaseTypeId);
        //需要审核的通知公告主表
        WlyyAuditNotice notice = wlyyAuditNoticeDao.findOne(noticeId);
//        notice.setApplyTime(new Date());
//        notice.setApplyUserHospital(user.getOrganizationId()+"");
//        notice.setApplyUserId(user.getCode());
//        notice.setApplyUserName(user.getName());
        notice.setConditionDescription(conditionDescription);
        notice.setContent(content);
        //审核者自己的通知直接发送短信,状态为“4”
        if (isAuditor(user)) {
            notice.setStatus("4");
        } else {
            notice.setStatus("2");
        }
        notice.setSendType(sendType);
        if("1".equals(sendType)){
            notice.setSendTime(DateUtil.strToDateLong(map.get("sendTime")+":00"));
        }
        notice.setTitle(map.get("title"));
        notice.setTotalCount(list.size());
        wlyyAuditNoticeDao.save(notice);
        //消息公告对象范围主表
        WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeDao.findByNoticeId(noticeId);
        noticeScope.setScope(scope);
        noticeScope.setScopeContent(scopeContent);
        noticeScope.setScopeId(scopeId);
        noticeScope.setCondition(conditionType);
        noticeScope.setServerTypeId(serverTypeId);
        noticeScope.setServerTypeContent(serverTypeContent);
        noticeScope.setHealthSituationId(healthSituationId);
        noticeScope.setHealthSituationContent(healthSituationContent);
        noticeScope.setDiseaseTypeId(diseaseTypeId);
        noticeScope.setDiseaseTypeContent(diseaseTypeContent);
        noticeScope.setConditionDescription(conditionDescription);
        wlyyAuditNoticeScopeDao.save(noticeScope);
        //审核者本人修改操作,为待审核状态>>直接通过,发送短信**********************新线程发彩信
        if (isAuditor(user)) {
            sendMsgThread(list, notice);
        }
    }
    //查询通知列表
    public Page<WlyyAuditNotice> searchList(String searchNm, String status, User currentUser, int page, int pageSize) throws Exception {
        //1、根据当前用户判断其角色(是否有审核权限)1):无-查询本人的消息通知;有-管辖范围的所有消息通知(包括本人的)-添加是否为本人的标记(是本人的才有编辑、删除等操作)否则只是审核、查看
        boolean auditor = false;
        List<WlyyUserRole> userRoles = wlyyUserRoleDao.findByUser(currentUser.getCode());
        if (page <= 0) {
            page = 1;
        }
        if (pageSize <= 0) {
            pageSize = 15;
        }
        PageRequest pageRequest = new PageRequest(page - 1, pageSize);
        String filters = "";
        if (!StringUtils.isEmpty(searchNm)) {
            filters = "title?" + searchNm + " g1;applyUserName?" + searchNm + " g1;";
        }
        if (!StringUtils.isEmpty(status)) {
            filters += "status=" + status + ";";
        }
        if (userRoles.size() > 0) {
            auditor = true;
            String[] roleCodes = new String[userRoles.size()];
            for (int i = 0; i < userRoles.size(); i++) {
                roleCodes[i] = userRoles.get(i).getRole();
            }
            //获取管辖机构codes
            String applyUserHospital = "";
            List<String> orgCodeList = wlyyUserRoleService.getRoleOrgCodes(roleCodes);
            if (orgCodeList.size() > 0) {
                applyUserHospital = StringUtils.join(orgCodeList, ",");
                filters += "applyUserHospital=" + applyUserHospital + ";";
            }
        } else {
            filters += "applyUserId=" + currentUser.getCode() + ";";  //非管理员只能查看自己的信息通知
        }
        List<WlyyAuditNotice> list = search("", filters, "", page, pageSize);
        for (WlyyAuditNotice notice : list) {
            if (!StringUtils.equals(notice.getApplyUserId(), currentUser.getCode())) {
                notice.setOwned(false);
            }
            if (auditor) {
                notice.setAuditor(true);
            }
        }
        Page<WlyyAuditNotice> res = new PageImpl<WlyyAuditNotice>(list, pageRequest, getCount(filters));
        return res;
    }
    //删除消息通知,同时删除对应的消息通知范围
    @Transactional
    public boolean deleteNotice(Long noticeId) {
        wlyyAuditNoticeDao.delete(noticeId);
        WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeDao.findByNoticeId(noticeId);
        if (noticeScope != null) {
            wlyyAuditNoticeScopeDao.delete(noticeScope.getId());
        }
        return true;
    }
    //审核通过发送短信,保存发送对象
    @Transactional
    public void approve(long noticeId, WlyyAuditNotice notice, User currentUser) {
        //1) 查找出通知范围对象
        WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeDao.findByNoticeId(noticeId);
        String conditionType = noticeScope.getCondition();//筛选条件:0-全部;1-根据条件
        String scope = noticeScope.getScope();// 0- 全市 1 - 指定区 2 - 指定社区
        String scopeId = noticeScope.getScopeId();//范围明细ID,scope=1时为区ID串,2时为社区id串
        // scope为0时-空值;为1时-区编码;为2时区+社区编码
        String city = "350200";//厦门市
        String town = "";
        String community = "";
        String serverTypeId = noticeScope.getServerTypeId();
        String healthSituationId = noticeScope.getHealthSituationId();
        String diseaseTypeId = noticeScope.getDiseaseTypeId();
        if ("1".equals(scope)) {
            town = scopeId;
        }
        if ("2".equals(scope) && !StringUtils.isEmpty(scopeId)) {
            String[] values = scopeId.split(";|;");
            for (String value : values) {
                if (!StringUtils.isEmpty(value)) {
                    community += value.split(":|:")[1] + ",";
                }
            }
        }
        if (!StringUtils.isEmpty(community)) {
            community = community.substring(community.length() - 1);
        }
        //2)查找居民
        List<Patient> list = getSendPatients(conditionType, scope, city, town, community, serverTypeId, healthSituationId, diseaseTypeId);
        //3)发送短信,保存发送对象信息6
        if ("2".equals(notice.getStatus())) {
            notice.setStatus("4");//消息通知修改状态
            notice.setAuditUserId(currentUser.getCode());//审核者编码
            notice.setAuditUserName(currentUser.getName());//审核者名称
            wlyyAuditNoticeDao.save(notice);
            //审核通过发送短信*******************新线程
            sendMsgThread(list, notice);
        }
    }
    //判断是否具有对当前消息的审核权限
    public boolean isNoticeAuditor(String auditorCode, String noticeHospital) {
        String[] roleCodes = wlyyRoleDao.findRoleCodesByUser(auditorCode);
        if (roleCodes == null || roleCodes.length <= 0) {
            return false;
        }
        List<String> roleOrgCodes = wlyyUserRoleService.getRoleOrgCodes(roleCodes);
        if (roleOrgCodes != null && roleOrgCodes.size() > 0) {
            return roleOrgCodes.contains(noticeHospital);
        }
        return false;
    }
    //判断当前用户是否是审核者
    public boolean isAuditor(User currentUser) {
        List<WlyyUserRole> userCode = wlyyUserRoleService.findByUserCode(currentUser.getCode());
        if (userCode != null && userCode.size() > 0) {
            return true;
        }
        return false;
    }
    //开启发送短信线程
    private void sendMsgThread(List<Patient> list, WlyyAuditNotice notice) {
        Thread t = new Thread(new Runnable() {
            public void run() {
                sendMsg(list, notice);
            }
        });
        t.start();
    }
    //发送短信
    private void sendMsg(List<Patient> list, WlyyAuditNotice notice) {
        WlyyAuditNoticeObject noticeObject = null;
        List<WlyyAuditNoticeObject> objectList = new ArrayList<>();
        String mobiles = "";
        int i = 0;
        for (Patient p : list) {
            noticeObject = new WlyyAuditNoticeObject();
            noticeObject.setNoticeId(notice.getId());
            noticeObject.setToUserId(p.getCode());
            noticeObject.setToUserTel(p.getMobile());
            noticeObject.setContent(notice.getContent());
            noticeObject.setSendTime(new Date());
            noticeObject.setInsertTime(new Date());
            noticeObject.setStatus("1");//TODO 短信发送状态(1为已发送),待修改
            objectList.add(noticeObject);
            i++;
            mobiles += p.getMobile() + ",";
            if (i % 901 == 0) {//900条发一次
                mobiles = mobiles.substring(0, mobiles.length() - 1);
                //smsService.sendMsg(mobiles,content);
                System.out.println("i=" + i + "---mobile=" + mobiles);
                mobiles = "";
            } else if (i == list.size()) {
                mobiles = mobiles.substring(0, mobiles.length() - 1);
                //smsService.sendMsg(mobiles,content);
                System.out.println("i=" + i + "---mobile=" + mobiles);
                mobiles = "";
            }
        }
        //暂时未审核后才保存发送对象+发送短信,那是否有保存改发送对象信息的必要?(数据量大)
//        if (objectList.size() > 0) {
//            wlyyAuditNoticeObjectDao.save(objectList);
//        }
    }
}

+ 191 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_edit.jsp

@ -0,0 +1,191 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<%@ include file="../head/page_head.jsp"%>
	<title>机构管理</title>
</head>
<style>
	.m-form-group label.label_title {
		width: 100px
	}
	.m-form-group p.tip {
		width: auto;
        margin-left: 100px;
        line-height: 20px;
	}
	.m-form-group ul li{
		line-height: 30px;
		margin-left: 100px;
	}
	.m-form-group .inpRadio{
		 vertical-align: bottom;
		 margin: 8px 0 0;
	 }
	.m-form-group .inpChkb{
		vertical-align: sub;
	}
	.m-form-group .l-text-date{
		width: 140px;
	}
	.m-form-group .sendTime{
		width: 138px;
	}
    .m-form-group  span.community{
        width: 50px;
        display: inline-flex;
    }
	.f-pa{
		position: relative;
	}
	.f-pa .m-form-control{
		margin-left: 200px;
		margin-top: 10px;
	}
	.wordwrap{
		float: left;
		display: block;
		margin: 140px 0 0 10px;
	}
	.wordCount .word{
		color: red;
		padding: 0 4px;
	}
	#messageContent .j-text-wrapper{
		float: left;
	}
	#messageContent .l-text-trigger-cancel{
		display: none!important;
	}
</style>
<body>
<div id="div_roles_info_form" class="m-form-inline f-mt20 f-ml30"
	 data-role-form>
	<input type="hidden" id="uuid" value='${UUID}'/>
	<input type="hidden" id="cityAuthority" value='${cityAuthority}'/>
	<input type="hidden" id="areaAuthority" value='${areaAuthority}'/>
	<input type="hidden" id="communityAuthority" value='${communityAuthority}'/>
	<input type="hidden" id="mode" value='${mode}'/>
	<input type="hidden" id="scopeId"/>
	<input type="hidden" id="diseaseTypeId"/>
	<input type="hidden" id="healthSituationId"/>
	<input type="hidden" id="serverTypeId"/>
	<input type="hidden" id="noticeId" value='${id}' data-attr-scan="id" />
	<div class="m-form-group">
		<label class="label_title" style="">发送范围:</label>
		<div class="u-radio-wrap m-form-control">
			<input type="radio" value="0" name="scope" id="cityScope" class="inpRadio" data-attr-scan=""> 全市
			<input type="radio" value="1" name="scope" id="areaScope" class="inpRadio" data-attr-scan=""> 指定区
			<input type="radio" value="2" name="scope" id="communityScope" class="inpRadio" data-attr-scan=""> 指定社区
		</div>
	</div>
	<div class="m-form-group" id="scope_area" style="display: none">
		<label class="label_title" style="">选择区:</label>
		<div class="u-checkbox-wrap m-form-control scope_areaDiv">
			<%--<input type="checkbox" name="scope_area" class="inpChkb" value="1" data-attr-scan>选项一--%>
			<%--<input type="checkbox" name="scope_area" class="inpChkb" value="2" data-attr-scan>选项二--%>
			<%--<input type="checkbox" name="scope_area" class="inpChkb" value="3" data-attr-scan>选项三--%>
		</div>
	</div>
	<div class="m-form-group" id="scope_community" style="display: none">
		<label class="label_title" style="">选择社区:</label>
		<div class="m-form-control scope_communityDiv" style="margin-top: 5px;">
			<%--<input type="checkbox" name="scope_community" class="inpChkb" value="1" data-attr-scan>选项一--%>
			<%--<input type="checkbox" name="scope_community" class="inpChkb" value="2" data-attr-scan>选项二--%>
			<%--<input type="checkbox" name="scope_community" class="inpChkb" value="3" data-attr-scan>选项三--%>
		</div>
	</div>
	<div class="m-form-group">
		<label class="label_title" style="">筛选条件:</label>
		<div class="u-radio-wrap m-form-control">
			<input type="radio" value="0" name="condition_type" class="inpRadio" data-attr-scan=""> 全部居民
			<input type="radio" value="1" name="condition_type" class="inpRadio" data-attr-scan=""> 设置条件
		</div>
	</div>
	<div class="m-form-group" id="inpCondition" style="display: none;padding-bottom: 0px">
		<label class="label_title" style=""></label>
		<div class="u-checkbox-wrap m-form-control">
			<input type="checkbox" name="condition" class="inpChkb" value="1" data-class=".serverType" data-name="serverType" data-tip="服务类型" data-attr-scan>按服务类型
			<input type="checkbox" name="condition" class="inpChkb" value="2" data-class=".health_situation" data-name="health_situation" data-tip="健康情况" data-attr-scan>按健康情况
			<input type="checkbox" name="condition" class="inpChkb" value="3" data-class=".diease" data-name="diease" data-tip="疾病类型" data-attr-scan>按疾病类型
		</div>
	</div>
	<div class="m-form-group" style=" ">
		<ul style="display: block; vertical-align: middle;">
			<li>
				<div class="m-form-group serverType" style="display: none;padding-bottom: 0px;">
					<label class="label_title" style="text-align: left;width: auto;line-height: 20px;">服务类型:</label>
					<div class="u-checkbox-wrap m-form-control serverTypeDiv" style="line-height: 20px;">
						<%--<input type="checkbox" name="server" class="inpChkb" value="1" data-attr-scan>按服务类型--%>
						<%--<input type="checkbox" name="server" class="inpChkb" value="2" data-attr-scan>按健康情况--%>
						<%--<input type="checkbox" name="server" class="inpChkb" value="3" data-attr-scan>按疾病类型--%>
					</div>
				</div>
			</li>
			<li>
				<div class="m-form-group health_situation" style="display: none;padding-bottom: 0px;">
					<label class="label_title" style="text-align: left;width: auto;line-height: 20px;">健康情况:</label>
					<div class="u-checkbox-wrap m-form-control health_situationDiv" style="line-height: 20px;">
						<%--<input type="checkbox" name="health_situation" class="inpChkb" value="1" data-attr-scan>按服务类型--%>
						<%--<input type="checkbox" name="health_situation" class="inpChkb" value="2" data-attr-scan>按健康情况--%>
						<%--<input type="checkbox" name="health_situation" class="inpChkb" value="3" data-attr-scan>按疾病类型--%>
					</div>
				</div>
			</li>
			<li>
				<div class="m-form-group diease" style="display: none;padding-bottom: 0px;">
					<label class="label_title" style="text-align: left;width: auto;line-height: 20px;">疾病类型:</label>
					<div class="u-checkbox-wrap m-form-control dieaseDiv" style="line-height: 20px;">
						<%--<input type="checkbox" name="diease" class="inpChkb" value="1" data-attr-scan>按服务类型--%>
						<%--<input type="checkbox" name="diease" class="inpChkb" value="2" data-attr-scan>按健康情况--%>
						<%--<input type="checkbox" name="diease" class="inpChkb" value="3" data-attr-scan>按疾病类型--%>
					</div>
				</div>
			</li>
		</ul>
	</div>
	<div class="m-form-group" style="">
		<label class="label_title" style="">通知标题:</label>
		<div class="l-text-wrapper m-form-control essential">
			<input type="text" id="title" class="required useTitle validate-special-char" required-title="请输入通知标题" placeholder="请输入通知标题" data-attr-scan="title" />
		</div>
	</div>
    <div class="m-form-group">
        <label class="label_title" style="">通知内容:</label>
        <div class="l-text-wrapper m-form-control" id="messageContent">
				<textarea type="text" id="content"  maxlength="120"
                          class="required max-length-120 validate-special-char" placeholder="请输入通知具体内容,最多120字,因每条短信限制70字,若大于70字可能将被分割成两条短信" data-attr-scan="content"></textarea>
				<span class="wordwrap" id="wordwrap"><var class="word">0</var>/120</span>
        </div>
    </div>
	<div class="m-form-group">
		<label class="label_title">发送时间:</label>
		<div class="l-text-wrapper m-form-control useTitle ajax validate-special-char">
			<input id="send_type_combo_select" data-type="text" class="" data-name="text" data-attr-scan="sendType">
		</div>
		<div class="m-form-control essential send_time" style="margin-left: 10px;">
			<input type="text" id="send_time" class="sendTime required" placeholder="输入发送时间"  required-title="不能为空" data-attr-scan="sendTime"/>
		</div>
	</div>
	<div class="m-form-group">
		<p class="tip">1、立即发送,则审核通过后立即发送</p>
		<p class="tip">2、定时发送,则审核通过后将在指定时间发送。如在指定时间前未审核通过,则将自动撤回</p>
	</div>
	<div class="m-form-group f-pa" id="btn_save_close" style="right: 10px;bottom: 0;">
		<div class="m-form-control">
			<input type="button" value="提    交" id="btn_save" class="l-button u-btn u-btn-primary u-btn-large f-ib f-vam" />
			<div id="btn_cancel" class="l-button u-btn u-btn-cancel u-btn-large f-ib f-vam" >
				<span>关闭</span>
			</div>
		</div>
	</div>
</div>
</body>
<%@ include file="../head/page_foot.jsp"%>
<%@ include file="notification_edit_js.jsp" %>
</html>

+ 575 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_edit_js.jsp

@ -0,0 +1,575 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<script language="javascript">
    $(function(){
        //先选出 textarea 和 统计字数 dom 节点
        var wordCount = $("#messageContent"),
                textArea = wordCount.find("textarea"),
                word = wordCount.find(".word");
        //调用
        statInputNum(textArea,word);
    });
    /*
     * 剩余字数统计
     * 注意 最大字数只需要在放数字的节点哪里直接写好即可 如:<var class="word">200</var>
     */
    function statInputNum(textArea,numItem) {
        var max = numItem.text(), curLength;
        curLength = textArea.val().length;
        numItem.text(max - curLength);
        textArea.on('input propertychange', function () {
            var _value = $(this).val().replace(/\n/gi,"");
            numItem.text(_value.length);
        });
    }
</script>
<script>
    (function ($, win) {
		$(function () {
			/* ************************** 变量定义 ******************************** */
			var Util = $.Util;
			var notificationInfo = null;
            var serviceLabelType = 1;
            var healthLabelType = 2;
            var dieaseLabelType = 3;
			var province = 350000;
			var city = 350200;
			var isAuditor = ${isAuditor};
			// 表单校验工具类
			var jValidation = $.jValidation;
			/* *************************** 函数定义 ******************************* */
			function pageInit() {
				notificationInfo.init();
			}
			//发送范围事件
            $(":radio[name='scope']").click(function(){
                var scope = $(this).val();
                var scopeId = $("#scopeId").val();//修改时选中值
                if(scope=="0"){
                    $("#scope_area").hide();
                    $("#scope_community").hide();
                }else if(scope=="1"){//展示区
                    $.ajax({
                        url: ctx + "/common/districtAuthority",
                        method: "post",
                        dataType: "json",
                        data: {"type": 3, "code": city},
                        success: function (data) {
                            if(data.status=='200'){
                                var html = "";
                                if(scopeId){
                                    var scopeIds = scopeId.split(",");
                                    for(var i=0;i<data.list.length;i++){
                                        var town = data.list[i];
                                        if(scopeId.indexOf(town.code)<0){
                                            html +="<input type='checkbox' name='scope_area' class='inpChkb' data-name='"+town.name+"' value='"+town.code+"' >"+town.name+"&nbsp;";
                                        }else{
                                            html +="<input type='checkbox' checked='checked' name='scope_area' class='inpChkb' data-name='"+town.name+"' value='"+town.code+"' >"+town.name+"&nbsp;";
                                        }
                                    }
                                }else{
                                    for(var i=0;i<data.list.length;i++){
                                        var town = data.list[i];
                                        html +="<input type='checkbox' name='scope_area' class='inpChkb' data-name='"+town.name+"' value='"+town.code+"' >"+town.name+"&nbsp;";
                                    }
                                }
                                $(".scope_areaDiv").html(html);
                            }else{
                                $.Notice.error(data.msg);
                            }
                        }
                    });
                    $("#scope_area").show();
                    $("#scope_community").hide();
                }else if(scope=="2"){//展示社区
                    $.ajax({
                        url: ctx + "/admin/hos/community",
                        method: "post",
                        dataType: "json",
                        data: {"city": city},
                        success: function (data) {
                            if(data.status=='200'){
                                var communityAuthority = $("#communityAuthority").val();
                                var html = "";
                                var attrTown = "";
                                for(var i=0;i<data.list.length;i++){
                                    var town = data.list[i];
                                    attrTown += town.town+";";
                                    var tn = town.town.split(":");
                                    html +="<div  class='m-form-group u-checkbox-wrap m-form-control' style='height: auto;line-height: 15px;'>";
                                    if("2"==communityAuthority||scopeId.indexOf(tn[0])>=0){
                                        html +="<input type='checkbox' name='"+tn[0]+"' checked='checked' class='inpChkb chkCommunity' data-name='"+town.town+"' data-area='"+tn[1]+"' value='"+tn[0]+"' >"+tn[1]+"&nbsp;";
                                    }else{
                                        html +="<input type='checkbox' name='"+tn[0]+"' class='inpChkb chkCommunity' data-name='"+town.town+"' data-area='"+tn[1]+"' value='"+tn[0]+"' >"+tn[1]+"&nbsp;";
                                    }
                                    for(var j=0;j<town.community.length;j++){
                                        community = town.community[j];
                                        if(j>0&&j%6==0){
                                            html+="<br><span style='display: inline-block;width: 61px;'></span>";
                                        }
                                        var comName = community.name;
                                        comName = comName.substring(3,comName.length);
                                        if("2"==communityAuthority||scopeId.indexOf(community.code)>=0){
                                            html +="<input type='checkbox' name='"+town.town+"' checked='checked' class='inpChkb' data-name='"+comName+"' value='"+community.code+"' ><span class='community'>"+comName+"</span>&nbsp;";
                                        }else{
                                            html +="<input type='checkbox' name='"+town.town+"' class='inpChkb' data-name='"+comName+"' value='"+community.code+"' ><span class='community'>"+comName+"</span>&nbsp;";
                                        }
                                    }
                                    html +="</div>"
                                    html +="<br>";
                                }
                                $(".scope_communityDiv").attr("attr-towns",attrTown);
                                $(".scope_communityDiv").html(html);
                            }else{
                                $.Notice.error(data.msg);
                            }
                        }
                    });
                    $("#scope_area").hide();
                    $("#scope_community").show();
                }
            });
            //选择区 全选/反选 社区
            $(document).on("click",".chkCommunity",function () {
                var name = $(this).attr("data-name");
                $("[name = '"+name+"']:checkbox").prop("checked", $(this).is(':checked'));
            });
            //筛选条件
            $(":radio[name='condition_type']").click(function(){
                var condition_type = $(this).val();
                if(condition_type=="0"){
                    $("#inpCondition").hide();
                    $("[name = 'condition']:checkbox").prop("checked",false);
                    $(".serverType").hide();
                    $(".health_situation").hide();
                    $(".diease").hide();
                }else if(condition_type=="1"){
                    $("#inpCondition").show();
                }
            });
            //标签事件
            $(":checkbox[name='condition']").change(function () {
                var chkValue = $(this).val();
                var selClass = $(this).attr("data-class");
                if($(this).is(':checked')){
                    $.ajax({
                        url: ctx + "/common/label/signPatientLabel",
                        method: "post",
                        dataType: "json",
                        data: {"labelType": chkValue},
                        success: function (data) {
                            if(data.status=='200'){
                                var html = "";
                                var name = selClass.substring(1,selClass.length);
                                for(var i=0;i<data.list.length;i++){
                                    var patiemtLabel = data.list[i];
                                    if(i>0&&i%6==0){
                                        html+="<br>";
                                    }
                                    var selectId = "";
                                    if("1"==chkValue){
                                        selectId = $("#serverTypeId").val();
                                    }
                                    if("2"==chkValue){
                                        selectId = $("#healthSituationId").val();
                                    }
                                    if("3"==chkValue){
                                        selectId = $("#diseaseTypeId").val();
                                    }
                                    if(selectId&&selectId.indexOf(patiemtLabel.code)>=0){
                                        html +="<input type='checkbox' name='"+name+"' checked='checked' class='inpChkb' data-name='"+patiemtLabel.name+"' value='"+patiemtLabel.code+"' >"+patiemtLabel.name+"&nbsp;";
                                    }else{
                                        html +="<input type='checkbox' name='"+name+"' class='inpChkb' data-name='"+patiemtLabel.name+"' value='"+patiemtLabel.code+"' >"+patiemtLabel.name+"&nbsp;";
                                    }
                                }
                                $(selClass+"Div").html(html);
                            }else{
                                $.Notice.error(data.msg);
                            }
                            $(selClass).show();
                        }
                    });
                }else{
                    $(selClass).hide();
                }
            });
			/* *************************** 模块初始化 ***************************** */
			notificationInfo = {
				$form: $("#div_roles_info_form"),
				$scope: $("input[name='scope']"),//发送范围
				$scope_area: $("input[name='scope_area']"),//指定区
				$scope_community: $("input[name='scope_community']"),//指定社区
				$condition_type: $("input[name='condition_type']"),//筛选条件
				$condition: $("input[name='condition']"),//筛选条件
				$server: $("input[name='server']"),//服务类型
				$health_situation: $("input[name='health_situation']"),//健康情况
				$diease: $("input[name='diease']"),//疾病类型
				$title: $("#title"),//消息标题
				$content: $("#content"),//消息内容
				$send_type_combo_select: $("#send_type_combo_select"),//发送方式
				$send_time: $("#send_time"),//发送时间
				$btnsave: $("#btn_save"),//保存按钮
				$btncancle: $("#btn_cancel"),//结束按钮
				init: function () {
					_this = this;
                    //范围权限控制
                    var cityAuthority = $("#cityAuthority").val();
                    var areaAuthority = $("#areaAuthority").val();
                    var communityAuthority = $("#communityAuthority").val();
                    if("0"==cityAuthority){
                        $("#cityScope").attr("disabled", false);
                        $("#cityScope").attr("disabled","disabled")
                    }
                    if("0"==areaAuthority){
                        $("#areaScope").attr("disabled", false);
                        $("#areaScope").attr("disabled", "disabled");
                    }
                    if("0"==communityAuthority){
                        $("#communityScope").attr("disabled", false);
                        $("#communityScope").attr("disabled", "disabled");
                    }
//                    if("2"==communityAuthority){
//                        $("#communityScope").attr("checked", true);
//                    }
					this.$title.ligerTextBox({width: 240, validate: {required: true}});
                    var sendTypeSelect = this.$send_type_combo_select.ligerComboBox({
                        with:180,
                        data: [
                            { text: "立即发送", id: "0" },
//                            { text: "定时发送", id: "1" }//暂时只做立即发送(有审核权限-新增时立即发送,无权限-审核通过后立即发送)
                        ],
                        valueField: 'id',
                        textField: 'text',
                        cancelable: false,
                        initIsTriggerEvent: false,
                        onSelected: function (newvalue){
                            if(newvalue=="0"){
                                $(".send_time").hide();
                            }else{
                                $(".send_time").show();
                            }
                        }
                    });
                    sendTypeSelect.setValue("0");
                    this.$content.ligerTextBox({width: 430, height: 150, validate: {required: true}});
					this.$form.attrScan();
					_this = this;
					var noticeId = $("#noticeId").val();
					var mode = $("#mode").val();//模式  (新增/修改/查看)
					if (isNoEmpty(noticeId) && noticeId != 0) {
						//id不为空时 :为修改页面,进行修改操作
						//异步根据id获取消息信息
                        $.ajax({
                            url: ctx + "/admin/notification/notice",
                            method: "post",
                            dataType: "json",
                            data: {id: noticeId},
                            success: function (result) {
                                if (result.status == '200') {
                                    var notice = result.data;
                                    var scope = notice.scope;
                                    var scopeId = notice.scopeId;
                                    $("#scopeId").val(scopeId);//范围
                                    $(":radio[name='scope'][value='" + scope + "']").click();
                                    var conditionType = notice.condition;//筛选条件
                                    var diseaseTypeId = notice.diseaseTypeId;
                                    var healthSituationId = notice.healthSituationId;
                                    var serverTypeId = notice.serverTypeId;
                                    $("#serverTypeId").val(serverTypeId);
                                    $("#healthSituationId").val(healthSituationId);
                                    $("#diseaseTypeId").val(diseaseTypeId);
                                    $(":radio[name='condition_type'][value='" + conditionType + "']").click();
                                    if(serverTypeId){
                                        $(":checkbox[name='condition'][value='1']").click();
                                    }
                                    if(healthSituationId){
                                        $(":checkbox[name='condition'][value='2']").click();
                                    }
                                    if(diseaseTypeId){
                                        $(":checkbox[name='condition'][value='3']").click();
                                    }
                                    _this.$form.Fields.fillValues({
                                        title: notice.title,
                                        content: notice.content,
                                    });
                                    $(".word").text(notice.content.length);
                                    //发送方式
                                    var sendType = notice.sendType;
                                    if("1"==sendType){
                                        var sendTime = notice.sendTime;
                                        sendTime = sendTime.substring(0,16);
                                        sendTypeSelect.setValue(sendType);
                                        $("#send_time").ligerDateEditor({showTime: true,initValue: sendTime});
                                        $(".send_time").show();
                                    }
                                } else {
                                    $.Notice.error(result.msg);
                                }
                            },
                            error: function (data) {
                                $.Notice.error("系统异常,请联系管理员!");
                            }
                        });
					}else{
                        this.$send_time.ligerDateEditor({showTime: true});
                    }
					this.$form.show();
					this.bindEvents();
				},
				bindEvents: function () {
					var self = this;
					var flag = false;
					$("#btn_save").click(function () {
						var values = self.$form.Fields.getValues();
						if (values.id == '') {
							values.id = 0;
						}
                        values.city = city+"";
                        var s = self.$send_type_combo_select;
                        values.sendType = self.$send_type_combo_select.ligerComboBox().getValue();
                        values.sendTime = self.$send_time.val();
                        values.communityAuthority = $("#communityAuthority").val();
						if (isEmpty(values.scope)) {
							$.Notice.error("请选择发送范围!");
							return false;
						}
						if(values.scope=="0"){
                            values.conditionDescription = "厦门市 全市";
                        }else if(values.scope=="1"){
                            var area = "";
                            var areaName = "";
                            $("input[name='scope_area']:checked").each(function(){
                                area+=$(this).val()+",";
                                areaName+=$(this).attr("data-name")+",";
                            });
                            if(area==""){
                                $.Notice.error("请至少选择一个区!");
                                return false;
                            }
                            areaName = areaName.substring(0,areaName.length-1);
                            area = area.substring(0,area.length-1);
                            values.town = area;
                            values.scopeId = area;
                            values.scopeContent = areaName;
                            values.conditionDescription = "厦门市 "+areaName;
                        }else if(values.scope=="2"){
                            var attrTowns = $(".scope_communityDiv").attr("attr-towns");
                            if(attrTowns.length==0){
                                $.Notice.error("请至少选择一个社区!");
                                return false;
                            }
                            var towns = attrTowns.split(";");
                            var selctCommunity = "";
                            var townCommunity = "";
                            var conditionDescription = "";
                            for(var i=0;i<towns.length;i++){
                                var townName = towns[i];
                                var strCom = "";
                                var strComName = "";
                                $("input[name='"+townName+"']:checked").each(function(){
                                    strCom+=$(this).val()+",";
                                    strComName+=$(this).attr("data-name")+",";
                                });
                                if(strCom.length>0){
                                    //selctCommunity += strCom.substring(0,strCom.length-1);
                                    selctCommunity += strCom;
                                    townCommunity += townName.split(":")[0] +":"+strCom.substring(0,strCom.length-1)+";";
                                    conditionDescription += townName.split(":")[1] +":"+strComName.substring(0,strComName.length-1)+";\n ";
                                }
                            }
                            if(selctCommunity.length==0){
                                $.Notice.error("请至少选择一个社区!");
                                return false;
                            }
                            values.community = selctCommunity.substring(0,selctCommunity.length-1);
                            //values.townCommunity = townCommunity;
                            values.scopeId = townCommunity.substring(0,townCommunity.length-1);
                            values.scopeContent = conditionDescription;
                            values.conditionDescription = "厦门市 "+ conditionDescription;
                        }
                        if (isEmpty(values.condition_type)) {
                            $.Notice.error("请选择筛选条件!");
                            return false;
                        }
						if (values.condition_type=='0') {//全部居民
							var condition = "0";
							var conditionId = "";
							values.condition = condition;
							values.conditionId = conditionId;
						}
                        if(values.condition_type=='1'){
                            var condition = "";
                            var conditionId = "";
                            $("input[name='condition']:checked").each(function(){
                                condition+=$(this).val()+",";
                                var conDetail = "";
                                var nameDetail = "";
                                var dataName = $(this).attr("data-name");
                                $("input[name='"+dataName+"']:checked").each(function(){
                                    conDetail+=$(this).val()+",";
                                    conditionId+=$(this).val()+",";
                                    nameDetail+=$(this).attr("data-name")+",";
                                });
                                if(conDetail.length==0){
                                    $.Notice.error("请至少选择一个"+$(this).attr("data-tip")+"!");
                                    return false;
                                }
                                if(dataName=="serverType"){
                                    values.serverTypeId = conDetail.substring(0,conDetail.length-1);
                                    values.serverTypeContent = nameDetail.substring(0,nameDetail.length-1);
                                }else if(dataName=="health_situation"){
                                    values.healthSituationId = conDetail.substring(0,conDetail.length-1);
                                    values.healthSituationContent = nameDetail.substring(0,nameDetail.length-1);
                                }else if(dataName=="diease"){
                                    values.diseaseTypeId = conDetail.substring(0,conDetail.length-1);
                                    values.diseaseTypeContent= nameDetail.substring(0,nameDetail.length-1);
                                }
                            });
                            if(condition.length==0){
                                $.Notice.error("请至少选择一个设置条件!");
                                return false;
                            }
                            values.condition = condition;
                            values.conditionId = conditionId;
                        }
                        var validator = new jValidation.Validation(self.$form, {
                            immediate: true, onSubmit: false,
                            onElementValidate: function (result,elm) {
                                if (Util.isStrEquals($(elm).attr("id"), 'title')) {
                                    if (isEmpty(values.title)) {
                                        result.setResult(false);
                                        return result;
                                    }
                                }
                                if (Util.isStrEquals($(elm).attr("id"), 'content')) {
                                    if (isEmpty(values.content)) {
                                        result.setResult(false);
                                        return result;
                                    }
                                }
                                if (Util.isStrEquals($(elm).attr("id"), 'send_time')) {
                                    if (values.sendType=="1"&&isEmpty(values.sendTime)) {
                                        result.setResult(false);
                                        return result;
                                    }
                                }
                            }
                        });
                        validator.validate();
						if (isEmpty(values.title)) {
							$.Notice.error("通知标题不能为空!");
							return false;
						}
                        if (isEmpty(values.content)) {
                            $.Notice.error("通知内容不能为空!");
                            return false;
                        }
                        if(values.sendType=="1"&&isEmpty(values.sendTime)){
                            $.Notice.error("发送时间不能为空!");
                            return false;
                        }
						var ddf = $.ligerDialog.open({
                            height: 100,
                            width: 300,
                            title: "提示",
                            isHidden: true,
                            target: "<div style='margin: 0 auto; width: 200px;' >是否确认提交消息通知?提交后无法变更</div>",
							buttons: [
								{
									text: '立即提交', onclick: function (i, d) {
									d.hide();
									update(values);
								}
								},
                                { text: '我在看看', onclick: function (i, d) { d.hide(); }}
                            ]
                        });
//                        $.ajax({
//                            url: ctx + "/admin/notification/isNoticeAuditor",
//                            async: false,
//                            method: "post",
//                            dataType: "json",
//                            data: {},
//                            success: function (data) {
//                                if (data.status == 200) {
//                                    var authority = data.authority;
//
//                                    $.ligerDialog.open({
//                                        height: 250,
//                                        width: 300,
//                                        title: "tishi",
//                                        isHidden: true,
//                                        target: "是否确认提交消息通知?提交后无法变更",
//                                        buttons: [  { text: '立即提交', onclick: function (i, d) { update(values); }},
//                                            { text: '我在看看', onclick: function (i, d) { d.hide(); }}
//                                        ]
//                                    });
//                                } else {
//                                    $.Notice.error(data.msg);
//                                }
//                            }
//                        });
					});
					function update(values) {
						var dataModel = $.DataModel.init();
						var message = "保存中...";
						var url = "update";
						if (values.id == 0) {
							url = "create";
						}
						var wattingDialog = $.Notice.waitting(message);
						dataModel.updateRemote(ctx + "/admin/notification/" + url, {
							data: {jsonData: JSON.stringify(values)},
							success: function (data) {
								wattingDialog.close();
								if (data.status == 200) {
									parent.window.reloadMasterGrid(data.msg);
									parent.window.closeInfoDialog();
								} else {
									$.Notice.error(data.msg);
								}
							},
							error: function (data) {
								wattingDialog.close();
								$.Notice.error("系统异常,请联系管理员!");
							}
						});
					}
					$("#btn_cancel").click(function () {
						parent.window.closeInfoDialog();
					});
				}
			};
			/* *************************** 页面初始化 **************************** */
			pageInit();
		})
	})(jQuery, window);
</script>

+ 44 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_list.jsp

@ -0,0 +1,44 @@
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<%@ include file="../head/page_head.jsp" %>
	<title>用户管理</title>
</head>
<style>
</style>
<body>
<div id="div_wrapper">
	<!-- 检索条件 -->
	<div class="m-retrieve-area f-h50 f-dn f-pr m-form-inline" data-role-form style='display: block;'>
		<div class="m-form-group f-mt10">
			<%--<sec:authorize url="/admin/roles/rolesList">--%>
			<div class="m-form-control f-fs12 f-ml10">
				<input type="text" id="inp_searchNm" placeholder="请输入标题/提交人">
			</div>
			<div class="m-form-control f-fs12 f-ml10">
				<input id="sel_status" placeholder="选择状态"/>
			</div>
			<%--</sec:authorize>--%>
			<%--<sec:authorize url="/admin/roles/create">--%>
			<div class="m-form-control f-mr20" style="float: right">
				<div id="div_new_notice" class="l-button u-btn u-btn-primary u-btn-small f-ib f-vam">
					<span>新增消息通知</span>
				</div>
			</div>
			<%--</sec:authorize>--%>
		</div>
	</div>
	<!-- 列表 -->
	<div id="div_notice_list">
	</div>
</div>
</body>
<%@ include file="../head/page_foot.jsp" %>
<%@ include file="notification_list_js.jsp" %>
</html>

+ 284 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_list_js.jsp

@ -0,0 +1,284 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<script>
	(function ($, win) {
		$(function () {
			/* ************************** 变量定义 ******************************** */
			// 通用工具类库
			var Util = $.Util;
			var retrieve = null;
			var master = null;
			var isFirstPage = false;
			var status = '';
			var isAuditor = ${isAuditor};
			/* *************************** 函数定义 ******************************* */
			function pageInit() {
				retrieve.init();
				master.init();
			}
			function reloadGrid(params) {
				if (isFirstPage) {
					master.grid.options.newPage = 1;
				}
				master.grid.setOptions({parms: params});
				master.grid.loadData(true);
			}
			/* *************************** 模块初始化 ***************************** */
			retrieve = {
				$element: $('.m-retrieve-area'),
				$addBtn: $('#div_new_notice'),
				$searchNm: $("#inp_searchNm"),
				$status: $('#sel_status'),
				init: function () {
					_this = this;
					this.$searchNm.ligerTextBox({
						width: 240, isSearch: true, search: function () {
							master.reloadGrid();//参数:标签/提交人+消息通知状态
						}
					})
					//状态复选框,选择时也刷新列表
					_this.statusBox = _this.$status.ligerComboBox({
						width: 180,
						data: [
							{text: '全部', statusId: ''},
							{text: '待提交', statusId: '1'},
							{text: '待审核', statusId: '2'},
							{text: '待发送', statusId: '3'},
							{text: '已发送', statusId: '4'},
							{text: '已拒绝', statusId: '5'},
							{text: '已撤回', statusId: '6'},
						],
						initIsTriggerEvent: false,
						valueFieldID: 'statusId',
						valueField: 'statusId',
						onSelected: function (newvalue) {
							status = newvalue;
							if (!master || !master.grid) {
								return
							}
							master.reloadGrid();//参数:标签/提交人+消息通知状态
						},
					});
                    this.bindEvents();
					if (isAuditor) {
						_this.statusBox.setValue('2');//根据是否是审核者设置默认值,审核者:默认选中待审核
					} else {
						_this.statusBox.setValue('');//根据是否是审核者设置默认值,审核者:待审核;非:默认全部
					}
				},bindEvents: function () {
                    var self = this;
                    self.$addBtn.click(function () {
                        master.infoDialog = $.ligerDialog.open({
                            height: 550,
                            width: 750,
                            title: '新增消息',
                            url: ctx + '/admin/notification/infoInit/' + "0" + "?mode=add"
                        })
                    });
                }
			};
			master = {
				infoDialog: null,
				grid: null,
				init: function () {
					this.grid = $("#div_notice_list").ligerGrid($.LigerGridEx.config({
						url: ctx + '/admin/notification/list',
						parms: {status: status},
						ajaxHeader: ajaxHeaderName,
						ajaxHeaderValue: ajaxHeaderValue,
						columns: [
							{display: 'ID', name: 'id', hide: true},
							{display: '标题', name: 'title', width: '14%', align: "left"},
							{display: '状态', name: 'status', hide: true},
							{
								display: '状态', name: 'status', width: '6%', align: "center",
								render: function (row) {
									var html = '';
									if (row.status == '0') {
										return "创建中"
									}
									;
									if (row.status == '1') {
										return "待提交"
									}
									;
									if (row.status == '2') {
										return "待审核"
									}
									;
									if (row.status == '3') {
										return "待发送"
									}
									;
									if (row.status == '4') {
										return "已发送"
									}
									;
									if (row.status == '5') {
										return "已拒绝"
									}
									;
									if (row.status == '6') {
										return "已撤回"
									}
									;
								}
							},
							{display: '通知总人数', name: 'totalCount', width: '15%', align: "center"},
//							{display: '定时发送时间', name: 'sendTime', width: '15%', align: "center"},
							{display: '提交人Id', name: 'applyUserId', hide: true},
							{display: '提交人', name: 'applyUserName', width: '10%', align: "center"},
							{display: '提交时间', name: 'applyTime', width: '15%', align: "center"},
							{display: '审核Id', name: 'auditUserId', hide: true},
							{display: '审核人', name: 'auditUserName', width: '10%', align: "center"},
							{display: '审核时间', name: 'auditTime', width: '15%', align: "center"},
							{
								display: '操作', name: 'operator', width: '15%', align: "center", isSort: false,
								render: function (row) {
									var html = '';
									html += '<a  href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}'])", "info:view", row.id) + '">查看</a>';
									if (row.owned == true) {
										if (row.status == 5 || row.status == 6) {
											html += '<a  style="margin-left:10px;"href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}'])", "info:edit", row.id) + '">编辑</a>';
											html += '<a  style="margin-left:10px;" title="删除" href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}','{2}'])", "info:del", row.id) + '">删除</a>';
										}
										if (row.status == 2) {
											html += '<a  style="margin-left:10px;"href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}'])", "info:revoke", row.id) + '">撤回</a>';
										}
										if (row.status == 1) {
											html += '<a  style="margin-left:10px;" title="删除" href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}','{2}'])", "info:del", row.id) + '">删除</a>';
										}
									}
									<%--<sec:authorize url="/admin/user/update">--%>
									if (row.owned == false && row.auditor == true && row.status == 2) {
										html += '<a  style="margin-left:10px;"href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}'])", "info:edit", row.id) + '">审核</a>';
									}
									<%--</sec:authorize>--%>
									return html;
								}
							}
						],
					}));
					// 自适应宽度
					this.grid.adjustToWidth();
					this.bindEvents();
				},
				reloadGrid: function (msg) {
					if (msg) {
						//如果是新增,直接刷新页面
						master.grid.loadData();
					} else {
						debugger
						//如果是查询(获取查询参数)
						var searchNm = retrieve.$searchNm.val() || '';
						var status = retrieve.statusBox.getValue() || '';
						var values = {
							searchNm: searchNm,
							status: status
						}
						reloadGrid.call(this, values);
					}
				},
				delRecord: function (id, code) {
					var self = this;
					$.ajax({
						url: ctx + "/admin/notification/delete",
						data: {"id": id},
						method: "post",
						dataType: "json",
						success: function (result) {
							if (result.status == '200') {
								window.reloadMasterGrid(result.msg);
							} else {
								$.Notice.error(result.msg);
							}
						},
						error: function (data) {
							$.Notice.error("系统异常,请联系管理员!");
						}
					})
				},
				bindEvents: function () {
					var self = this;
					$.subscribe('info:view', function (event, id) {
						var title = '消息通知详情';
						self.infoDialog = $.ligerDialog.open({
							height: 550,
							width: 750,
							urlParms: {"id": id, "mode": "view"},
							title: title,
							url: ctx + '/admin/notification/view'
						})
					});
                    $.subscribe('info:revoke', function (event, id) {
                        var title = '消息通知撤回';
                        self.infoDialog = $.ligerDialog.open({
                            height: 550,
                            width: 750,
                            urlParms: {"id": id, "mode": "revoke"},
                            title: title,
                            url: ctx + '/admin/notification/view'
                        })
                    });
					$.subscribe('info:edit', function (event, id) {
						var title = '编辑用户信息';
						self.infoDialog = $.ligerDialog.open({
							height: 550,
							width: 750,
							title: title,
                            url: ctx + '/admin/notification/infoInit/' + id + "?mode=edit"
						})
					});
					$.subscribe('info:create', function (event, id) {
						var title = '新增消息';
						self.infoDialog = $.ligerDialog.open({
							height: 460,
							width: 490,
							title: title,
							url: ctx + '/notification/infoInit' + "0" + "?mode=add"
						})
					});
					$.subscribe('info:del', function (event, id, code) {
						$.ligerDialog.confirm('确认删除该行信息?<br>如果是请点击确认按钮,否则请点击取消。', function (yes) {
							if (yes) {
								self.delRecord(id, code);
							}
						});
					})
				}
			};
			/* ************************* Dialog页面回调接口 ************************** */
			win.reloadMasterGrid = function (msg) {
				if (isNoEmpty(msg)) {
					$.Notice.success(msg);
				}
				master.reloadGrid(msg);
			};
			win.closeUserInfoDialog = function () {
				master.infoDialog.close();
			};
            win.closeInfoDialog = function () {
                master.infoDialog.close();
            };
			win.openEditInfoDialog = function (id) {
				master.infoDialog.close();
				$.publish("info:edit", id);
			}
			win.deleteNoticeDialog = function (id) {
				master.delRecord(id);
				master.infoDialog.close();
			}
			/* *************************** 页面初始化 **************************** */
			pageInit();
		});
	})(jQuery, window);
</script>

+ 10 - 0
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/entity/Patient.java

@ -78,6 +78,8 @@ public class Patient extends IdEntity {
	private String sickVillage;
	//居民预警状态:0为标准,1为预警状态
	private Integer standardStatus;
	//医疗保险号
	private String medicareNumber;
	public Patient() {
	}
@ -332,4 +334,12 @@ public class Patient extends IdEntity {
	public void setStandardStatus(Integer standardStatus) {
		this.standardStatus = standardStatus;
	}
	
	public String getMedicareNumber() {
		return medicareNumber;
	}
	
	public void setMedicareNumber(String medicareNumber) {
		this.medicareNumber = medicareNumber;
	}
}

+ 4 - 4
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/service/SignRenewZYService.java

@ -1461,7 +1461,7 @@ public class SignRenewZYService {
                        params.put("BIRTHDAY", DateUtil.dateToStrShort(patient.getBirthday()));
                        params.put("IDENTITY_CARD_NO", patient.getIdcard() == null ? sign.getIdcard() : patient.getIdcard());
                        params.put("CARD_NO", patient.getSsc() == null ? sign.getSsc() : patient.getSsc());
                        params.put("INSUR_SAFETY_NO", "");  //医疗保险号
                        params.put("INSUR_SAFETY_NO", patient.getMedicareNumber());  //医疗保险号
                        params.put("SICK_PHONE", patient.getMobile() == null ? "" : patient.getMobile());   //联系电话
                        params.put("SICK_COUNTY", patient.getTown() == null ? "" : patient.getTown());    //行政区
                        params.put("SICK_COUNTRY", patient.getStreet() == null ? "" : patient.getStreet());    //街道
@ -1541,7 +1541,7 @@ public class SignRenewZYService {
                        params.put("BIRTHDAY", DateUtil.dateToStrShort(patient.getBirthday()));
                        params.put("IDENTITY_CARD_NO", patient.getIdcard() == null ? sign.getIdcard() : patient.getIdcard());
                        params.put("CARD_NO", patient.getSsc() == null ? sign.getSsc() : patient.getSsc());
                        params.put("INSUR_SAFETY_NO", "");  //医疗保险号
                        params.put("INSUR_SAFETY_NO", patient.getMedicareNumber());  //医疗保险号
                        params.put("SICK_PHONE", patient.getMobile() == null ? "" : patient.getMobile());   //联系电话
                        params.put("SICK_COUNTY", patient.getTown() == null ? "" : patient.getTown());    //行政区
                        params.put("SICK_COUNTRY", patient.getStreet() == null ? "" : patient.getStreet());    //街道
@ -1697,7 +1697,7 @@ public class SignRenewZYService {
                    params.put("BIRTHDAY", DateUtil.dateToStrShort(patient.getBirthday()));
                    params.put("IDENTITY_CARD_NO", patient.getIdcard() == null ? sign.getIdcard() : patient.getIdcard());
                    params.put("CARD_NO", patient.getSsc() == null ? sign.getSsc() : patient.getSsc());
                    params.put("INSUR_SAFETY_NO", "");  //医疗保险号
                    params.put("INSUR_SAFETY_NO",patient.getMedicareNumber());  //医疗保险号
                    params.put("SICK_PHONE", patient.getMobile() == null ? "" : patient.getMobile());   //联系电话
                    params.put("SICK_COUNTY", patient.getTown() == null ? "" : patient.getTown());    //行政区
                    params.put("SICK_COUNTRY", patient.getStreet() == null ? "" : patient.getStreet());    //街道
@ -2087,7 +2087,7 @@ public class SignRenewZYService {
                    params.put("BIRTHDAY", DateUtil.dateToStrShort(patient.getBirthday()));
                    params.put("IDENTITY_CARD_NO", patient.getIdcard() == null ? sign.getIdcard() : patient.getIdcard());
                    params.put("CARD_NO", patient.getSsc() == null ? sign.getSsc() : patient.getSsc());
                    params.put("INSUR_SAFETY_NO", "");  //医疗保险号
                    params.put("INSUR_SAFETY_NO", patient.getMedicareNumber());  //医疗保险号
                    params.put("SICK_PHONE", patient.getMobile() == null ? "" : patient.getMobile());   //联系电话
                    params.put("SICK_COUNTY", patient.getTown() == null ? "" : patient.getTown());    //行政区
                    params.put("SICK_COUNTRY", patient.getStreet() == null ? "" : patient.getStreet());    //街道

+ 1 - 1
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/service/SignZYService.java

@ -1407,7 +1407,7 @@ public class SignZYService {
                    params.put("BIRTHDAY", DateUtil.dateToStrShort(patient.getBirthday()));
                    params.put("IDENTITY_CARD_NO", patient.getIdcard() == null ? sign.getIdcard() : patient.getIdcard());
                    params.put("CARD_NO", patient.getSsc() == null ? sign.getSsc() : patient.getSsc());
                    params.put("INSUR_SAFETY_NO", "");  //医疗保险号
                    params.put("INSUR_SAFETY_NO", patient.getMedicareNumber());  //医疗保险号
                    params.put("SICK_PHONE", patient.getMobile() == null ? "" : patient.getMobile());   //联系电话
                    params.put("SICK_COUNTY", patient.getTown() == null ? "" : patient.getTown());    //行政区
                    params.put("SICK_COUNTRY", patient.getStreet() == null ? "" : patient.getStreet());    //街道

+ 0 - 1
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java

@ -1274,7 +1274,6 @@ public class JwPrescriptionService {
                elastricSearchSave.save(resultdata,esIndex,esType);
            }
//            logger.info("同步单条随访记录-ES数据保存成功,时间:"+DateUtil.getStringDate());
            jestClient.shutdownClient();
        }catch (Exception e){
            logger.error(" save error :" + e.getMessage());
            e.printStackTrace();

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/health/repository/DevicePatientHealthIndexDao.java

@ -60,7 +60,7 @@ public interface DevicePatientHealthIndexDao
	List<DevicePatientHealthIndex> findIndexByPatient(String patient, int type, Pageable pageRequest);
	@Query("SELECT a FROM DevicePatientHealthIndex a where a.user = ?1 and a.del = '1' order by a.recordDate desc ")
	Iterable<DevicePatientHealthIndex> findRecentByPatient(String patient);
	List<DevicePatientHealthIndex> findRecentByPatient(String patient);
	@Query("select DATE_FORMAT(a.recordDate,'%Y-%m-%d') from DevicePatientHealthIndex a where a.user = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' group by DATE_FORMAT(a.recordDate,'%Y-%m-%d') order by DATE_FORMAT(a.recordDate,'%Y-%m-%d') desc")
	List<String> findDateList(String patient, Date start, Date end, Pageable pageRequest);

+ 115 - 81
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java

@ -15,6 +15,7 @@ import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.WlyyPatientSick;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.address.CityDao;
import com.yihu.wlyy.repository.address.ProvinceDao;
import com.yihu.wlyy.repository.address.TownDao;
@ -26,6 +27,7 @@ import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientSickDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.app.sign.FamilyContractService;
@ -133,6 +135,8 @@ public class DoctorInfoService extends BaseService {
    @Autowired
    private FamilyContractService familyContractService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    /**
     * 获取医生的签约病人
@ -876,63 +880,79 @@ public class DoctorInfoService extends BaseService {
        Patient p = patientDao.findByCode(patient);
        JSONObject data = new JSONObject();
        if (StringUtils.isNotEmpty(oldDoctorCode)) {
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","jgsbg");
            String first = templateConfig.getFirst();
            first = first.replace("key1",(p.getName()==null?"":p.getName()));
            String remark = templateConfig.getRemark();
            String keyword3 = templateConfig.getKeyword3();
            data.put("toUser", patient);
            data.put("represented",patient);//被代理人
            data.put("doctor", newD.getCode());
            data.put("doctorName", newD.getName());
            data.put("first", p.getName() + ",您好!您签约团队的健康管理师已变更,您的新健管师信息如下:");
            data.put("keyword3", "家庭医生-健康管理师");
//            data.put("first", p.getName() + ",您好!您签约团队的健康管理师已变更,您的新健管师信息如下:");
            data.put("first", first);
//            data.put("keyword3", "家庭医生-健康管理师");
            data.put("keyword3", keyword3);
            data.put("keyword2", DateUtil.dateToStrNoSecond(new Date()));
            data.put("keyword1", newD.getName());
            if (StringUtils.isEmpty(signFamily.getDoctor()) || signFamily.getDoctorHealth().equals(signFamily.getDoctor())) {
                data.put("remark", newD.getName() + "健管师将专门为您提供优质健康服务");
                remark = remark.replace("key1",(newD.getName()==null?"":newD.getName()+"健管师将专门"));
                data.put("remark", remark);
//                data.put("remark", newD.getName() + "健管师将专门为您提供优质健康服务");
            } else {
                data.put("remark", newD.getName() + "健管师与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
                remark = remark.replace("key1",newD.getName() + "健管师与" + signFamily.getDoctorName() + "医生一道,");
                data.put("remark", remark);
//                data.put("remark", newD.getName() + "健管师与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
            }
        } else {
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","jgsxz");
            String first = templateConfig.getFirst();
            first = first.replace("key1",(p.getName()==null?"":p.getName()));
            String remark = templateConfig.getRemark();
            String keyword3 = templateConfig.getKeyword3();
            data.put("toUser", patient);
            data.put("represented",patient);//被代理人
            data.put("doctor", newD.getCode());
            data.put("doctorName", newD.getName());
            data.put("first", p.getName() + ",您好!您的签约团队已为您新增一位健康管理师,医生信息如下:");
            data.put("keyword3", "家庭医生-健康管理师");
            data.put("first", first);
//            data.put("first", p.getName() + ",您好!您的签约团队已为您新增一位健康管理师,医生信息如下:");
//            data.put("keyword3", "家庭医生-健康管理师");
            data.put("keyword3", keyword3);
            data.put("keyword2", DateUtil.dateToStrNoSecond(new Date()));
            data.put("keyword1", newD.getName());
            if (StringUtils.isEmpty(signFamily.getDoctor()) || signFamily.getDoctorHealth().equals(signFamily.getDoctor())) {
                data.put("remark", newD.getName() + "健管师将专门为您提供优质的健康服务");
//                data.put("remark", newD.getName() + "健管师将专门为您提供优质的健康服务");
                remark.replace("key1",(newD.getName()==null?"":newD.getName()));
                data.put("remark", remark);
            } else {
                data.put("remark", newD.getName() + "健管师与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
                templateConfig = templateConfigDao.findByScene("template_doctor_change","jgsxzqk");
                remark = templateConfig.getRemark();
                remark.replace("key1",(newD.getName()==null?"":newD.getName())).replace("key2",(signFamily.getDoctorName()==null?"":signFamily.getDoctorName()));
//                data.put("remark", newD.getName() + "健管师与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
                data.put("remark", remark);
            }
        }
        //判断是否判定openId,有没有发则查找家人发送
        if (StringUtils.isNotBlank(p.getOpenid())) {
            pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), data);
        }
//        else {
//            JSONObject json = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//            Patient member = (Patient) json.get("member");
//            if (StringUtils.isNotBlank(member.getOpenid())) {
//                String first = (String) data.get("first");
//                data.remove("first");
//                data.put("first", weiXinOpenIdUtils.getTitleMes(p, json.getInt("relation"), member.getName()) + first);
//                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
//
//            }
//        }
        //发送代理人
        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
        if(jsonArray!=null&&jsonArray.length()>0){
            String first = (String) data.get("first");
            for (int i = 0;i<jsonArray.length();i++){
                JSONObject j  = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                JSONObject json = data;
                json.remove("toUser");
                json.put("toUser",member.getCode());
                json.remove("first");
                json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName())+first);
                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), json);
        }else {
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                String first = (String) data.get("first");
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject json = data;
                    json.remove("toUser");
                    json.put("toUser", member.getCode());
                    json.remove("first");
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), json);
                }
            }
        }
    }
@ -1032,49 +1052,53 @@ public class DoctorInfoService extends BaseService {
        Patient p = patientDao.findByCode(patient);
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","jgsxz");
        String first = templateConfig.getFirst();
        first = first.replace("key1",(p.getName()==null?"":p.getName()));
        String remark = templateConfig.getRemark();
        String keyword3 = templateConfig.getKeyword3();
        JSONObject data = new JSONObject();
        data.put("toUser", patient);
        data.put("represented",patient);//被代理人
        data.put("doctor", newD.getCode());
        data.put("doctorName", newD.getName());
        data.put("first", p.getName() + ",您好!您的签约团队已为您新增一位健康管理师,医生信息如下:");
        data.put("keyword3", "家庭医生-健康管理师");
        data.put("first", first);
        data.put("keyword3", keyword3);
        /*data.put("first", p.getName() + ",您好!您的签约团队已为您新增一位健康管理师,医生信息如下:");
        data.put("keyword3", "家庭医生-健康管理师");*/
        data.put("keyword2", DateUtil.dateToStrNoSecond(new Date()));
        data.put("keyword1", newD.getName());
        if (StringUtils.isEmpty(signFamily.getDoctor()) || signFamily.getDoctorHealth().equals(signFamily.getDoctor())) {
            data.put("remark", newD.getName() + "健管师将专门为您提供优质的健康服务");
//            data.put("remark", newD.getName() + "健管师将专门为您提供优质的健康服务");
            remark.replace("key1",(newD.getName()==null?"":newD.getName()));
            data.put("remark", remark);
        } else {
            data.put("remark", newD.getName() + "健管师与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
            templateConfig = templateConfigDao.findByScene("template_doctor_change","jgsxzqk");
            remark = templateConfig.getRemark();
            remark.replace("key1",(newD.getName()==null?"":newD.getName())).replace("key2",(signFamily.getDoctorName()==null?"":signFamily.getDoctorName()));
            data.put("remark", remark);
//            data.put("remark", newD.getName() + "健管师与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
        }
        if (StringUtils.isNotBlank(p.getOpenid())) {
            pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), data);
        }
//        else {
//            JSONObject json = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//            Patient member = (Patient) json.get("member");
//
//            if (StringUtils.isNotBlank(member.getOpenid())) {
//                String first = (String) data.get("first");
//                data.remove("first");
//                data.put("first", weiXinOpenIdUtils.getTitleMes(p, json.getInt("relation"), member.getName()) + first);
//                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
//            }
//        }
        //发送代理人
        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
        if(jsonArray!=null&&jsonArray.length()>0){
            String first = (String) data.get("first");
            for (int i = 0;i<jsonArray.length();i++){
                JSONObject j  = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                JSONObject json = data;
                json.remove("toUser");
                json.put("toUser",member.getCode());
                json.remove("first");
                json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName())+first);
                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), json);
        }else {
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                first = (String) data.get("first");
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject json = data;
                    json.remove("toUser");
                    json.put("toUser", member.getCode());
                    json.remove("first");
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), json);
                }
            }
        }
        return 1;
@ -1258,37 +1282,47 @@ public class DoctorInfoService extends BaseService {
        try{
            Patient p = patientDao.findByCode(patient);
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","qkxz");
            String first = templateConfig.getFirst();
            first = first.replace("key1",(p.getName()==null?"":p.getName()));
            String remark = templateConfig.getRemark();
            remark = remark.replace("key1",(newD.getName()==null?"":newD.getName()));
            String keyword3 = templateConfig.getKeyword3();
            JSONObject data = new JSONObject();
            data.put("toUser", patient);
            data.put("represented",patient);//被代理人
            data.put("doctor", newD.getCode());
            data.put("doctorName", newD.getName());
            data.put("keyword3", "家庭医生-全科医生");
//            data.put("keyword3", "家庭医生-全科医生");
            data.put("keyword3", keyword3);
            data.put("keyword2", DateUtil.dateToStrNoSecond(new Date()));
            data.put("keyword1", newD.getName());
            if (StringUtils.isEmpty(signFamily.getDoctorHealth()) || signFamily.getDoctor().equals(signFamily.getDoctorHealth())) {
//            data.put("first", p.getName() + ",您签约团队的全科医生已变更,您的新全科医生信息如下:");
            data.put("first", first);
            data.put("remark", remark);
            /*if (StringUtils.isEmpty(signFamily.getDoctorHealth()) || signFamily.getDoctor().equals(signFamily.getDoctorHealth())) {
                data.put("remark", newD.getName() + "医生将继续为您提供优质健康服务");
            } else {
                data.put("remark", newD.getName() + "医生将继续为您提供优质健康服务");
            }
            }*/
            if (StringUtils.isNotBlank(p.getOpenid())) {
                data.put("first", p.getName() + ",您签约团队的全科医生已变更,您的新全科医生信息如下:");
                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), data);
            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
            if(jsonArray!=null&&jsonArray.length()>0){
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject json = data;
                    json.remove("toUser");
                    json.put("toUser",member.getCode());
                    json.remove("first");
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) json.get("relation"), p.getName()) + p.getName() + ",您好!您签约团队的全科医生已变更,您的新全科医生信息如下:");
                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), json);
            }else {
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject json = data;
                        json.remove("toUser");
                        json.put("toUser", member.getCode());
                        json.remove("first");
                        json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) json.get("relation"), p.getName()) + p.getName() + ",您好!您签约团队的全科医生已变更,您的新全科医生信息如下:");
                        pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), json);
                    }
                }
            }
        }catch (Exception e){

+ 63 - 37
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -18,6 +18,7 @@ import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientFamilyMember;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.prescription.*;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.entity.zydict.ZyIvPhysicDict;
import com.yihu.wlyy.repository.consult.ConsultTeamDao;
import com.yihu.wlyy.repository.consult.ConsultTeamDoctorDao;
@ -32,6 +33,7 @@ import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.prescription.*;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.health.HealthEduArticleService;
import com.yihu.wlyy.service.app.health.PatientHealthGuidanceService;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
@ -162,6 +164,8 @@ public class ConsultTeamService extends ConsultService {
    
    @Autowired
    private PrescriptionFollowupContentService prescriptionFollowupContentService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    Map<Integer, String> relations = new HashMap<>();
@ -2399,36 +2403,45 @@ public class ConsultTeamService extends ConsultService {
            endName = p.getName();
            if (consultTeam.getType() == 2||consultTeam.getType()==8) {
                String openId = p.getOpenid();
                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","zxpj");
                String first = templateConfig.getFirst();
                first = first.replace("key1",(endName==null?"":endName));
                String keyword1 = templateConfig.getKeyword1();
                JSONObject json = new JSONObject();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                json.put("keyword1", "医生评价");
                json.put("keyword1", keyword1);
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", p.getCode());
                json.put("represented",p.getCode());//被代理人
                json.put("remark", "");
                json.put("consult", consult);
                String first = endName + ",您好!您有1条";;
//                String first = endName + ",您好!您有1条";;
                if(consultTeam.getType()==8){
                    first += "续方";
//                    first += "续方";
                    first = first.replace("key2","续方");
                }else {
                    first = first.replace("key2","");
                }
                first += "咨询已结束,请及时对咨询医生进行评价。";
//                first += "咨询已结束,请及时对咨询医生进行评价。";
                json.put("first", first);
                if(StringUtils.isNotBlank(p.getOpenid())){
                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 17, openId, p.getName(), json);
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                if(jsonArray!=null&&jsonArray.length()>0){
                    for (int i = 0;i<jsonArray.length();i++){
                        JSONObject j  = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser",member.getCode());
                        data.remove("first");
                        data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName())+first);
                        pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 17, member.getOpenid(), p.getName(), data);
                }else {
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                    if (jsonArray != null && jsonArray.length() > 0) {
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject j = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser", member.getCode());
                            data.remove("first");
                            data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
                            pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 17, member.getOpenid(), p.getName(), data);
                        }
                    }
                }
            }
@ -2437,40 +2450,53 @@ public class ConsultTeamService extends ConsultService {
                Patient p = patientDao.findByCode(consultTeam.getPatient());
                String name = p.getName();
                String openId = p.getOpenid();
                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","zxpj");
                if (endOperator.equals("admin")) {
                    templateConfig = templateConfigDao.findByScene("template_doctor_survey","zxcspj");
                }
                String first = templateConfig.getFirst();
                first = first.replace("key1",(name==null?"":name));
                String keyword1 = templateConfig.getKeyword1();
                JSONObject json = new JSONObject();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                json.put("keyword1", "医生评价");
                json.put("keyword1", keyword1);
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", p.getCode());
                json.put("represented",p.getCode());//被代理人
                json.put("remark", "");
                json.put("consult", consult);
                String first = name + ",您好!您有1条";;
//                String first = name + ",您好!您有1条";;
                if(consultTeam.getType()==8){
                    first += "续方";
//                    first += "续方";
                    first  = first.replace("key2","续方");
                }else {
                    first  = first.replace("key2","");
                }
                if (endOperator.equals("admin")) {
                /*if (endOperator.equals("admin")) {
                    first += "咨询超时未回复,系统自动关闭,请及时对咨询医生进行评价。";
                }else {
                    first += "咨询已结束,请及时对咨询医生进行评价。";
                }
                }*/
                json.put("first", first);
                if(StringUtils.isNotBlank(p.getOpenid())){
                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 17, openId, p.getName(), json);
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                if(jsonArray!=null&&jsonArray.length()>0){
                    for (int i = 0;i<jsonArray.length();i++){
                        JSONObject j  = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser",member.getCode());
                        data.remove("first");
                        data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName())+first);
                        pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 17, member.getOpenid(), p.getName(), data);
                }else {
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                    if(jsonArray!=null&&jsonArray.length()>0){
                        for (int i = 0;i<jsonArray.length();i++){
                            JSONObject j  = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser",member.getCode());
                            data.remove("first");
                            data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName())+first);
                            pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 17, member.getOpenid(), p.getName(), data);
                        }
                    }
                }

+ 13 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java

@ -766,7 +766,8 @@ public class PatientDeviceService extends BaseService {
     * @param page
     * @param pageSize
     */
    public List<com.alibaba.fastjson.JSONObject> searchPatient(String name,Integer page,Integer pageSize){
    public List<com.alibaba.fastjson.JSONObject> searchPatient(String name,Integer page,Integer pageSize,String idcards){
        Object o[] = null;
        StringBuffer sql = new StringBuffer("SELECT p.code,p.name,p.address,p.idcard,p.sex,GROUP_CONCAT(label_name) labelName,t.doctor_name doctorName ");
        sql.append("FROM ( SELECT DISTINCT f.* FROM wlyy_patient_device d, wlyy_sign_family f ");
        sql.append("WHERE f.`status` > 0 AND f.patient = d.`user` ) t, wlyy_patient p LEFT JOIN ");
@ -775,8 +776,17 @@ public class PatientDeviceService extends BaseService {
        if(StringUtils.isNotBlank(name)){
            sql.append(" and (p.`name` like '%"+name+"%' or t.doctor_name like '%"+name+"%') ");
        }
        sql.append("GROUP BY p.code,p.name,p.address,p.idcard,p.sex LIMIT ?,? ");
        List<com.alibaba.fastjson.JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),new Object[]{(page-1)*pageSize,pageSize});
        if(StringUtils.isNotBlank(idcards)){
            idcards = "'"+idcards.replaceAll(",","','")+"'";
            sql.append(" and p.idcard in ("+idcards+") ");
            sql.append("GROUP BY p.code,p.name,p.address,p.idcard,p.sex ");
            o = new Object[]{};
        }else {
            sql.append("GROUP BY p.code,p.name,p.address,p.idcard,p.sex LIMIT ?,? ");
            o = new Object[]{(page-1)*pageSize,pageSize};
        }
        List<com.alibaba.fastjson.JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),o);
        list.forEach(json->{
            json.put("age", IdCardUtil.getAgeForIdcard(String.valueOf(json.get("idcard"))));
        });

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

@ -6,10 +6,12 @@ import com.yihu.wlyy.entity.patient.PatientFamilyTemp;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.invitation.PatientInvitationLog;
import com.yihu.wlyy.entity.security.AccessToken;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao;
import com.yihu.wlyy.repository.patient.PatientFamilyTempDao;
import com.yihu.wlyy.repository.patient.PatientInvitationLogDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.sign.FamilyContractService;
import com.yihu.wlyy.service.common.SMSService;
@ -69,6 +71,8 @@ public class FamilyMemberService extends BaseService {
    private String appSecret;
    @Value("${wechat.accId}")
    private String accId;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @PostConstruct
    public void init() {
@ -1027,16 +1031,30 @@ public class FamilyMemberService extends BaseService {
                    if(StringUtils.isNotBlank(p.getOpenid())){
                        //发送添加成功消息模板
                        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","xzcy");
                        String first = templateConfig.getFirst();
                        first = first.replace("key1",(p.getName()==null?"":p.getName())).replace("key2",(m.getName()==null?"":m.getName()));
                        String remark = templateConfig.getRemark();
                        remark = remark.replace("key1",(m.getName()==null?"":m.getName()))
                                .replace("key2",(relations.get(temp.getFamilyRelation())==null?"":relations.get(temp.getFamilyRelation())))
                                .replace("br","\n");
                        String keyword1 = templateConfig.getKeyword1();
                        JSONObject json = new JSONObject();
                        json.put("first", p.getName() + ",您好!"+m.getName()+"已加入到您的家庭成员。");
                        json.put("keyword1", "添加家人申请成功");
                        json.put("first", first);
//                        json.put("first", p.getName() + ",您好!"+m.getName()+"已加入到您的家庭成员。");
                        json.put("keyword1", keyword1);
//                        json.put("keyword1", "添加家人申请成功");
                        json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
                        json.put("remark", remark);
//                        json.put("keyword3", m.getName());
//                        json.put("keyword4", relations.get(temp.getFamilyRelation()));
                        json.put("remark",
                        /*json.put("remark",
                                "家人:"+m.getName()+"\n"+
                                "家庭关系:"+relations.get(temp.getFamilyRelation())+"\n"+
                                "点击查看家人。");
                                "点击查看家人。");*/
                        System.out.println("-----sendMes----:openId "+p.getOpenid()+"-----access_token-----:"+access_token+"--json--");
                        //此消息为定向推送,无需家人代收
                        pushMsgTask.putWxMsg(access_token, 13, p.getOpenid(), p.getName(), json);
@ -1052,10 +1070,18 @@ public class FamilyMemberService extends BaseService {
                Patient p = patientDao.findByCode(temp.getPatient());
                Patient m = patientDao.findByCode(temp.getFamilyMember());
                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","xzcysb");
                String first = templateConfig.getFirst();
                first = first.replace("key1",(p.getName()==null?"":p.getName())).replace("key2",(m.getName()==null?"":m.getName()));
                String keyword1 = templateConfig.getKeyword1();
                //发送添加成功消息模板
                JSONObject json = new JSONObject();
                json.put("first", p.getName() + ",您好!"+m.getName()+"拒绝了您的家人申请。");
                json.put("keyword1", "添加家人申请失败");
                json.put("first", first);
//                json.put("first", p.getName() + ",您好!"+m.getName()+"拒绝了您的家人申请。");
//                json.put("keyword1", "添加家人申请失败");
                json.put("keyword1", keyword1);
                json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
                json.put("remark"," ");
                System.out.println("-----sendMes----:openId "+p.getOpenid()+"-----access_token-----:"+access_token+"--json--");
@ -1214,15 +1240,28 @@ public class FamilyMemberService extends BaseService {
            patientFamilyTempDao.save(temp);
        }
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","xzcysq");
        String first = templateConfig.getFirst();
        first = first.replace("key1",(m.getName()==null?"":m.getName())).replace("key2",(p.getName()==null?"":p.getName()));
        String remark = templateConfig.getRemark();
        remark = remark.replace("key1",(p.getName()==null?"":p.getName()))
                .replace("key2",(relations.get(relation)==null?"":relations.get(relation)))
                .replace("br","\n");
        String keyword1 = templateConfig.getKeyword1();
        JSONObject json = new JSONObject();
        json.put("first", m.getName() + ",您好!" + p.getName() + "向您发起添加家人申请,添加成功后,对方可使用您的账号,为您处理各类健康服务。");
        json.put("keyword1", "添加家人申请");
//        json.put("first", m.getName() + ",您好!" + p.getName() + "向您发起添加家人申请,添加成功后,对方可使用您的账号,为您处理各类健康服务。");
        json.put("first", first);
//        json.put("keyword1", "添加家人申请");
        json.put("keyword1", keyword1);
        json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        json.put("remark", remark);
//        json.put("keyword3", p.getName());
//        json.put("keyword4", relations.get(relation));
        json.put("remark", "申请人:"+p.getName()+"\n"+
       /* json.put("remark", "申请人:"+p.getName()+"\n"+
                "家庭关系:"+relations.get(relation)+"\n"+
                "点击立即处理。");
                "点击立即处理。");*/
        json.put("member", member);
        //此消息为定向推送,无需家人代收
        pushMsgTask.putWxMsg(access_token, 12, m.getOpenid(), m.getName(), json);

+ 19 - 15
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthGuidanceService.java

@ -4,10 +4,12 @@ import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientHealthGuidance;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientHealthGuidanceDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
@ -55,6 +57,8 @@ public class PatientHealthGuidanceService extends BaseService {
	@Autowired
	private PushMsgTask pushMsgTask;
	@Autowired
	private WechatTemplateConfigDao templateConfigDao;
	public JSONObject findById(Long id){
		PatientHealthGuidance guidance = patientHealthGuidanceDao.findOne(id);
@ -155,23 +159,23 @@ public class PatientHealthGuidanceService extends BaseService {
			if(StringUtils.isNotEmpty(openId)){
				// 推送消息到微信端
				pushMsgTask.putWxMsg(accessToken, 4, openId, patient.getName(), json);
			}
			//发送代理人
			JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(),patient.getOpenid());
			if(jsonArray!=null&&jsonArray.length()>0){
				for (int i = 0;i<jsonArray.length();i++){
					JSONObject j  = jsonArray.getJSONObject(i);
					Patient member = (Patient) j.get("member");
					JSONObject data = json;
					data.remove("toUser");
					data.put("toUser",member.getCode());
					//String first = (String) json.get("first");
					data.remove("first");
					data.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), patient.getName()) + "健康指导提醒");
					pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 4, member.getOpenid(), patient.getName(), data);
			}else {
				//发送代理人
				JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
				if (jsonArray != null && jsonArray.length() > 0) {
					for (int i = 0; i < jsonArray.length(); i++) {
						JSONObject j = jsonArray.getJSONObject(i);
						Patient member = (Patient) j.get("member");
						JSONObject data = json;
						data.remove("toUser");
						data.put("toUser", member.getCode());
						//String first = (String) json.get("first");
						data.remove("first");
						data.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), patient.getName()) + "健康指导提醒");
						pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 4, member.getOpenid(), patient.getName(), data);
					}
				}
			}
		}
		return guidance;
	}

+ 178 - 6
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java

@ -26,6 +26,7 @@ import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.third.iot.IotDeviceService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.*;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.NameValuePair;
@ -228,7 +229,8 @@ public class PatientHealthIndexService extends BaseService {
                " ORDER BY " +
                " a.record_date DESC " +
                "LIMIT 0,1 ";
        List<Map<String, Object>> devicePatient = jdbcTemplate.queryForList(sql, patient, type);
//        List<Map<String, Object>> devicePatient = jdbcTemplate.queryForList(sql, patient, type);
        List<Map<String, Object>> devicePatient = findDataByPatient(sql, patient, type);
        Map<String, Object> map = new HashMap<>();
        for (Map<String, Object> device : devicePatient) {
            String time = device.get("record_date") == null ? null : device.get("record_date").toString();
@ -429,7 +431,8 @@ public class PatientHealthIndexService extends BaseService {
                " and del = '1' " +
                " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
                " order by record_date,id desc ";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
//        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> list = getPatientXT_JsonIot(sql,patient,dateString);
        if (list != null && list.size() > 0) {
            obj.put("type", 1);
            obj.put("czrq", date);
@ -639,6 +642,171 @@ public class PatientHealthIndexService extends BaseService {
        }
    }
    /**
     * 查询最近的一条体征数据
     * @param sql
     * @param patient
     * @param type
     * @return
     */
    public List<Map<String, Object>> findDataByPatient(String sql,String patient,Integer type){
        if(iotDeviceService.isUploadIot()){
            List<Map<String, Object>> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndType(patient,type,1);
            if(list!=null&&list.size()>0){
                re.add(indexToMap(list.get(0)));
            }
            return re;
        }else {
            return jdbcTemplate.queryForList(sql, patient, type);
        }
    }
    /**
     * 患者最近填写的健康指标
     * @param patient
     * @return
     */
    public List<DevicePatientHealthIndex> findRecentByPatientIterable(String patient){
        if(iotDeviceService.isUploadIot()){
            return iotDeviceService.findByPatientAndType(patient,null,1000);
        }else {
            return patientHealthIndexDao.findRecentByPatient(patient);
        }
    }
    /**
     * 根据患者标志获取健康指标
     * @param patient
     * @param type
     * @return
     */
    public DevicePatientHealthIndex findLastByPatienIot(String patient,Integer type){
        if(iotDeviceService.isUploadIot()){
            DevicePatientHealthIndex index = null;
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndType(patient,type,1);
            if(list!=null&&list.size()>0){
                index = list.get(0);
            }
            return index;
        }else {
            return findLastByPatien(patient,type);
        }
    }
    /**
     * 查询指标记录
     * @param patient
     * @param startDate
     * @param endDate
     * @param page
     * @param size
     * @return
     */
    public List<String> findDateListIot(String patient,Date startDate,Date endDate, Integer page, Integer size,String start, String end){
        if(iotDeviceService.isUploadIot()){
            List<String> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, null,page, size, null, start, end);
            if(list!=null&&list.size()>0){
                list.forEach(one->{
                    re.add(DateUtil.dateToStrShort(one.getRecordDate()));
                });
            }
            return re;
        }else {
            return patientHealthIndexDao.findDateList(patient,startDate,endDate,page,size);
        }
    }
    /**
     * 按时间查找
     * @param sql
     * @param patient
     * @param type
     * @param size
     * @param gi_type
     * @param begin
     * @param end
     * @return
     */
    public List<Map<String, Object>> findByPatientAndTime(String sql,String patient,Integer type,Integer size,Integer gi_type, String begin, String end){
        if(iotDeviceService.isUploadIot()){
            List<Map<String, Object>> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, type,1, size, gi_type, begin, end);
            if(list!=null&&list.size()>0){
                list.forEach(one->{
                    re.add(indexToMap(one));
                });
            }
            return re;
        }else {
            return jdbcTemplate.queryForList(sql);
        }
    }
    /**
     * 按时间查找
     * @param sql
     * @param patient
     * @param date
     * @return
     */
    public List<Map<String, Object>> getPatientXT_JsonIot(String sql,String patient, String date){
        String begin = date +" 00:00:00";
        String end= date +" 23:59:59";
        if(iotDeviceService.isUploadIot()){
            List<Map<String, Object>> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, 1,1, 100, null, begin, end);
            if(list!=null&&list.size()>0){
                list.forEach(one->{
                    re.add(indexToMap(one));
                });
            }
            return re;
        }else {
            return jdbcTemplate.queryForList(sql);
        }
    }
    /**
     * 按时间查找
     * @param sql
     * @param patient
     * @return
     */
    public List<Map<String, Object>> getPatientXT_JsonIot(String sql,String patient,Integer type,Integer page,Integer size, String begin,String end){
        if(iotDeviceService.isUploadIot()){
            List<Map<String, Object>> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, type,page, size, null, begin, end);
            if(list!=null&&list.size()>0){
                list.forEach(one->{
                    re.add(indexToMap(one));
                });
            }
            return re;
        }else {
            return jdbcTemplate.queryForList(sql);
        }
    }
    /**
     * 转map
     * @param index
     * @return
     */
    private Map<String, Object> indexToMap(DevicePatientHealthIndex index){
        Map<String, Object> map = new HashedMap();
        map.put("value1",index.getValue1());
        map.put("value2",index.getValue2());
        map.put("value3",index.getValue3());
        map.put("value4",index.getValue4());
        map.put("value5",index.getValue5());
        map.put("value6",index.getValue6());
        map.put("value7",index.getValue7());
        map.put("device_sn",index.getDeviceSn());
        map.put("record_date",index.getRecordDate());
        return map;
    }
    /********************************************物联网 end***********************************************************/
@ -1177,7 +1345,8 @@ public class PatientHealthIndexService extends BaseService {
        sql = sql + conditionApp +
                " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
                " order by record_date desc ,sort_date desc limit " + 0 + " ," + 1000 + " ";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
//        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> list = findByPatientAndTime(sql,patient,type,1000,gi_type,begin,end);
        for (Map<String, Object> map : list) {
            JSONObject json = new JSONObject();
            json.put("id", map.get("id"));
@ -1464,7 +1633,8 @@ public class PatientHealthIndexService extends BaseService {
                    " and del = '1' " +
                    " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
                    " order by record_date desc ,sort_date desc limit " + pageRequest.getOffset() + " ," + pageRequest.getPageSize() + " ";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
//            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
            List<Map<String, Object>> list = getPatientXT_JsonIot(sql,patient,type,pageRequest.getOffset(),pageRequest.getPageSize(),start,end);
            for (Map<String, Object> map : list) {
                JSONObject json = new JSONObject();
                json.put("id", map.get("id"));
@ -1519,7 +1689,8 @@ public class PatientHealthIndexService extends BaseService {
        {
            PageRequest pageRequest = new PageRequest(page, pageSize);
            //根据时间过滤排序
            List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
//            List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
            List<String> dateList = findDateListIot(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize(), start, end);
            if (dateList != null && dateList.size() > 0) {
                for (String dateString : dateList) {
                    com.alibaba.fastjson.JSONObject obj = getPatientXT_Json(patient, dateString);
@ -1564,7 +1735,8 @@ public class PatientHealthIndexService extends BaseService {
     */
    public JSONArray findRecentByPatient(String patient) {
        JSONArray array = new JSONArray();
        Iterable<DevicePatientHealthIndex> iterable = patientHealthIndexDao.findRecentByPatient(patient);
//        List<DevicePatientHealthIndex> iterable = patientHealthIndexDao.findRecentByPatient(patient);
        List<DevicePatientHealthIndex> iterable = findRecentByPatientIterable(patient);
        if (iterable != null) {
            Iterator<DevicePatientHealthIndex> iterator = iterable.iterator();
            while (iterator != null && iterator.hasNext()) {

+ 69 - 48
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/physicalExamination/PhysicalExaminationRemindService.java

@ -6,10 +6,12 @@ import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientRemindRecords;
import com.yihu.wlyy.entity.patient.PatientTeamRemindRecord;
import com.yihu.wlyy.entity.patient.vo.PatientVO;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientRemindRecordsDao;
import com.yihu.wlyy.repository.patient.PatientTeamRemindRecordDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.task.PushMsgTask;
@ -62,6 +64,8 @@ public class PhysicalExaminationRemindService extends BaseService {
    private DoctorDao doctorDao;
    @Autowired
    private PatientTeamRemindRecordDao patientTeamRemindRecordDao;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    /**
     * 单个提醒居民按钮
@ -335,37 +339,46 @@ public class PhysicalExaminationRemindService extends BaseService {
        Boolean flag = true;
        // 推送消息给微信端
        String url = "jkda/html/jiankangtijian.html?openid=" + patient.getOpenid() +"&toUser="+patient.getCode()+"&toName=" + patient.getName();
        String first = "您的家庭医生" + doctName + "提醒,您可以到签约社区进行65岁以上老年人的免费健康体检啦~";
//        String first = "您的家庭医生" + doctName + "提醒,您可以到签约社区进行65岁以上老年人的免费健康体检啦~";
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","qkxz");
        String first = templateConfig.getFirst();
        first = first.replace("key1",(doctName==null?"":doctName));
        String remark = templateConfig.getRemark();
        String keyword1 = templateConfig.getKeyword1();
        JSONObject json = new org.json.JSONObject();
        json.put("first",first);
        json.put("url",url);
        json.put("keyword1", "健康体检");
        json.put("keyword1", keyword1);
//        json.put("keyword1", "健康体检");
        json.put("keyword2", format.format(new Date()));
        json.put("remark", "为了您和您的家庭医生了解您近期的健康状况,请及时到您签约的社区体检哟~(如已体检请忽略)");
//        json.put("remark", "为了您和您的家庭医生了解您近期的健康状况,请及时到您签约的社区体检哟~(如已体检请忽略)");
        json.put("remark", remark);
        if (StringUtils.isNotBlank(patient.getOpenid())) {
            pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
            flag = false;
        }
        //发送代理人
        JSONArray jsonArray = openIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
        if (jsonArray != null && jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                org.json.JSONObject j = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                int start = url.indexOf("&toUser=");
                int end = url.indexOf("&", start + 1);
                String touser = url.substring(start, end);
                url = url.replace(touser, "&toUser=" + member.getCode());
                json.remove("first");
                try {
                    json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName())+first);
                    json.put("url", url);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
                    flag = false;
        }else {
            //发送代理人
            JSONArray jsonArray = openIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    org.json.JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    int start = url.indexOf("&toUser=");
                    int end = url.indexOf("&", start + 1);
                    String touser = url.substring(start, end);
                    url = url.replace(touser, "&toUser=" + member.getCode());
                    json.remove("first");
                    try {
                        json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()) + first);
                        json.put("url", url);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (StringUtils.isNotBlank(member.getOpenid())) {
                        pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
                        flag = false;
                    }
                }
            }
        }
@ -396,11 +409,18 @@ public class PhysicalExaminationRemindService extends BaseService {
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        String accessToken = accessTokenUtils.getAccessToken();
        Boolean flag = true;
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","qkxz");
        String first = templateConfig.getFirst();
        first = first.replace("key1",(doctName==null?"":doctName));
        String remark = templateConfig.getRemark();
        String keyword1 = templateConfig.getKeyword1();
        // 推送消息给微信端
        JSONObject json = new org.json.JSONObject();
        json.put("keyword1", "健康体检");
        json.put("keyword1", keyword1);
        json.put("keyword2", format.format(new Date()));
        json.put("remark", "为了您和您的家庭医生了解您近期的健康状况,请及时到您签约的社区体检哟~(如已体检请忽略)");
//        json.put("remark", "为了您和您的家庭医生了解您近期的健康状况,请及时到您签约的社区体检哟~(如已体检请忽略)");
        json.put("remark", remark);
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
@ -409,7 +429,7 @@ public class PhysicalExaminationRemindService extends BaseService {
        List<Patient> patients = patientDao.findExaminationRemind(teamId, yesteryear);
        for (Patient patient : patients) {
            String url = "jkda/html/jiankangtijian.html?openid=" + patient.getOpenid() +"&toUser="+patient.getCode()+"&toName=" + patient.getName();
            String first = "您的家庭医生" + doctName + "提醒,您可以到签约社区进行65岁以上老年人的免费健康体检啦~";
//            String first = "您的家庭医生" + doctName + "提醒,您可以到签约社区进行65岁以上老年人的免费健康体检啦~";
            json.put("first",first);
            json.put("url",url);
            String mobile = patient.getMobile();
@ -420,27 +440,28 @@ public class PhysicalExaminationRemindService extends BaseService {
            if (StringUtils.isNotBlank(patient.getOpenid())) {
                pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
                flag = false;
            }
            //发送代理人
            JSONArray jsonArray = openIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    org.json.JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    int start = url.indexOf("&toUser=");
                    int end = url.indexOf("&", start + 1);
                    String touser = url.substring(start, end);
                    url = url.replace(touser, "&toUser=" + member.getCode());
                    json.remove("first");
                    try {
                        json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName())+first);
                        json.put("url", url);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (StringUtils.isNotBlank(member.getOpenid())) {
                        pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
                        flag = false;
            }else {
                //发送代理人
                JSONArray jsonArray = openIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        org.json.JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        int start = url.indexOf("&toUser=");
                        int end = url.indexOf("&", start + 1);
                        String touser = url.substring(start, end);
                        url = url.replace(touser, "&toUser=" + member.getCode());
                        json.remove("first");
                        try {
                            json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()) + first);
                            json.put("url", url);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (StringUtils.isNotBlank(member.getOpenid())) {
                            pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
                            flag = false;
                        }
                    }
                }
            }

+ 18 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prenatalInspector/PrenatalInspectorPreCardService.java

@ -11,9 +11,11 @@ import com.yihu.wlyy.entity.patient.prenatal.PrenatalInspectorPlan;
import com.yihu.wlyy.entity.patient.prenatal.PrenatalInspectorPlanLibrary;
import com.yihu.wlyy.entity.patient.prenatal.PrenatalInspectorPreCard;
import com.yihu.wlyy.entity.patient.prenatal.PrenatalInspectorRecord;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.health.repository.DevicePatientHealthIndexDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.patient.*;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
import com.yihu.wlyy.service.app.sign.FamilyContractService;
@ -75,6 +77,8 @@ public class PrenatalInspectorPreCardService extends BaseService {
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private SMSService smsService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
//    public
@ -940,18 +944,28 @@ public class PrenatalInspectorPreCardService extends BaseService {
            String name = patient.getName();
            String openId = patient.getOpenid();
            String mobile = patient.getMobile();
            String first = name + ",您好!您和您的宝宝需要进行产检啦~请及时预约产检,如已预约,请忽略";
//            String first = name + ",您好!您和您的宝宝需要进行产检啦~请及时预约产检,如已预约,请忽略";
            String url = "wdyy/html/appointment-register.html?openid=" + openId + "&toUser=" + code + "&toName=" + name;
            PrenatalInspectorPlan plan = prenatalInspectorPlanDao.findOne(prenatalId);
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","cjtx");
            String first = templateConfig.getFirst();
            first = first.replace("key1",(name==null?"":name));
            String remark = templateConfig.getRemark();
            String keyword1 = templateConfig.getKeyword1();
            String keyword2 = templateConfig.getKeyword2();
            keyword2 = keyword2.replace("key1",DateUtil.getStringDateShort()).replace("key2",plan.getCheckItem()).replace("br","\n");
            org.json.JSONObject json = new org.json.JSONObject();
            //产检提醒
            json.put("remark", "产检内容以医生实际检查为准。点击进行预约");
//            json.put("remark", "产检内容以医生实际检查为准。点击进行预约");
            json.put("remark", remark);
            json.put("first", first);
            json.put("url", url);
            json.put("keyword1", "产检提醒");
            String keyword2 = DateUtil.getStringDateShort() + "\n产检内容:" + plan.getCheckItem();
            json.put("keyword1", keyword1);
//            String keyword2 = DateUtil.getStringDateShort() + "\n产检内容:" + plan.getCheckItem();
            json.put("keyword2", keyword2);
            if (StringUtils.isNotEmpty(openId) && !("undefined".equals(openId))) {
                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 18, openId, name, json);

+ 58 - 14
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionNoticesService.java

@ -1,7 +1,9 @@
package com.yihu.wlyy.service.app.prescription;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
@ -29,6 +31,8 @@ public class PrescriptionNoticesService extends BaseService {
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Autowired
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    private static final Logger LOGGER = LoggerFactory.getLogger(PrescriptionNoticesService.class);
@ -64,9 +68,16 @@ public class PrescriptionNoticesService extends BaseService {
        if (type == 1) {
            switch (status) {
                case 0:
                    first = name + "您好,你的续方申请医生已审核。";
                    WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_audit","xfbtg");
                    first = templateConfig.getFirst();
                    first = first.replace("key1",(name==null?"":name));
                    remark = templateConfig.getRemark();
                    String keyword1 = templateConfig.getKeyword1();
                    /*first = name + "您好,你的续方申请医生已审核。";
                    remark = "您可点击消息查看详情,修改续方信息后重新提交。";
                    sendJson.put("keyword1", "审核不通过");
                    sendJson.put("keyword1", "审核不通过");*/
                    sendJson.put("keyword1", keyword1);
                    sendJson.put("keyword2", doctName);
                    sendJson.put("first", first);
                    sendJson.put("remark", remark);
@ -90,9 +101,16 @@ public class PrescriptionNoticesService extends BaseService {
                    }
                    break;
                case 1:
                    first = name + "您好,你的续方申请医生已审核。";
                    templateConfig = templateConfigDao.findByScene("template_doctor_audit","xftg");
                    first = templateConfig.getFirst();
                    first = first.replace("key1",(name==null?"":name));
                    remark = templateConfig.getRemark();
                    String keyword = templateConfig.getKeyword1();
                    /*first = name + "您好,你的续方申请医生已审核。";
                    remark = "您可点击消息查看详情并完成支付。";
                    sendJson.put("keyword1", "审核通过");
                    sendJson.put("keyword1", "审核通过");*/
                    sendJson.put("keyword1", keyword);
                    sendJson.put("keyword2", doctName);
                    sendJson.put("first", first);
                    sendJson.put("remark", remark);
@ -116,9 +134,16 @@ public class PrescriptionNoticesService extends BaseService {
                    }
                    break;
                case 2:
                    first = name + "您好,您的续方申请医生已修改处方清单并审核。";
                    templateConfig = templateConfigDao.findByScene("template_doctor_audit","tztg");
                    first = templateConfig.getFirst();
                    first = first.replace("key1",(name==null?"":name));
                    remark = templateConfig.getRemark();
                    String keyword2 = templateConfig.getKeyword1();
                    /*first = name + "您好,您的续方申请医生已修改处方清单并审核。";
                    remark = "您可点击消息查看详情并完成支付。";
                    sendJson.put("keyword1", "审核通过");
                    sendJson.put("keyword1", "审核通过");*/
                    sendJson.put("keyword1", keyword2);
                    sendJson.put("keyword2", doctName);
                    sendJson.put("first", first);
                    sendJson.put("remark", remark);
@ -143,9 +168,15 @@ public class PrescriptionNoticesService extends BaseService {
                    break;
            }
        } else if (type == 2) {
            first = name + "您好,您的续方订单已完成配药,请尽快致社区医院取药。";
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","xfqy");
            first = templateConfig.getFirst();
            first = first.replace("key1",(name==null?"":name));
            String keyword1 = templateConfig.getKeyword1();
//            first = name + "您好,您的续方订单已完成配药,请尽快致社区医院取药。";
            remark = "";
            sendJson.put("keyword1", "续方订单取药");
            sendJson.put("keyword1", keyword1);
//            sendJson.put("keyword1", "续方订单取药");
            sendJson.put("keyword2", dateFormat.format(new Date()));
            sendJson.put("first", first);
            sendJson.put("remark", remark);
@ -169,11 +200,17 @@ public class PrescriptionNoticesService extends BaseService {
            }
        }
        if (type == 3) {
            first = name + "您好,您的续方订单配送员" + doctName + "已顺利取药,续方状态变更为配送中。";
            remark = "您可点击消息查看详情。";
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","xfqy");
            first = templateConfig.getFirst();
            remark = templateConfig.getRemark();
            first = first.replace("key1",(name==null?"":name)).replace("key2",(doctName==null?"":doctName));
            String keyword3 = templateConfig.getKeyword3();
           /* first = name + "您好,您的续方订单配送员" + doctName + "已顺利取药,续方状态变更为配送中。";
            remark = "您可点击消息查看详情。";*/
            sendJson.put("keyword1", doctName);
            sendJson.put("keyword2", dateFormat.format(new Date()));
            sendJson.put("keyword3", "续方状态");
            sendJson.put("keyword3", keyword3);
            sendJson.put("first", first);
            sendJson.put("remark", remark);
            sendJson.put("url", url);//带参数的模板跳转链接
@ -196,9 +233,16 @@ public class PrescriptionNoticesService extends BaseService {
            }
        }
        if (type == 4) {
            first = name + ",您好!您的续方订单已成功配送。";
            remark = "感谢您的使用。";
            sendJson.put("keyword1", "续方申请");
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_service","xfwc");
            first = templateConfig.getFirst();
            remark = templateConfig.getRemark();
            first = first.replace("key1",(name==null?"":name));
            String keyword1 = templateConfig.getKeyword1();
//            first = name + ",您好!您的续方订单已成功配送。";
//            remark = "感谢您的使用。";
//            sendJson.put("keyword1", "续方申请");
            sendJson.put("keyword1", keyword1);
            sendJson.put("keyword2", doctName);//审核医生姓名 开处方的医生(团队长?)
            sendJson.put("keyword3", ordenTime);//订单完成时间
            sendJson.put("first", first);

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

@ -14,6 +14,7 @@ import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.message.MessageNoticeSetting;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.*;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.consult.ConsultDao;
import com.yihu.wlyy.repository.consult.ConsultTeamDao;
@ -23,6 +24,7 @@ import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.patient.*;
import com.yihu.wlyy.repository.statistics.WlyySignFamilyCodeDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
@ -163,6 +165,8 @@ public class FamilyContractService extends BaseService {
    private HttpClientUtil httpClientUtil;
    @Autowired
    private TrackPatientDao trackPatientDao;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    public SignFamily findSignFamilyByCode(String code) {
@ -1254,17 +1258,24 @@ public class FamilyContractService extends BaseService {
            Doctor doc = doctorDao.findByCode(sf.getDoctor());
            Hospital hos = hospitalDao.findByCode(doc.getHospital());
            String content = sf.getName() + ",您好!祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_success", "self");
            String first = templateConfig.getFirst();
            String keyword4 = templateConfig.getKeyword4();
            keyword4 = keyword4.replace("key1",sf.getName()==null?"":sf.getName()).replace("key2",sf.getDoctorName()==null?"":sf.getDoctorName())
                        .replace("key3",(hos != null ? hos.getName() : "") ).replace("key4",(hos != null ? hos.getAddress() : ""));
            /*String content = sf.getName() + ",您好!祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                    "为了给您提供更好的服务,请尽快完成缴费。您可点击此条消息,跳转缴费页面完成缴费,或进入签约管理,选择待缴费的签约记录进行缴费操作,如需线下缴费,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                    (hos != null ? hos.getAddress() : "") + ")缴费。";
                    (hos != null ? hos.getAddress() : "") + ")缴费。";*/
            JSONObject json = new JSONObject();
            json.put("first", "签约成功通知");
            json.put("first", first);
            json.put("toUser", sf.getPatient());
            json.put("represented", sf.getPatient());//被代理人
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
            json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
            json.put("content", content);
            json.put("content", keyword4);
            json.put("remark", ""); //您好,您成功签约家庭医生
//            添加签约code by wjj  2017.7.18
            json.put("signCode", signCode);
@ -1272,21 +1283,9 @@ public class FamilyContractService extends BaseService {
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                pushMsgTask.putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
            }
//            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");
//                        json.remove("first");
//                        json.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), sf.getName()));
//                        pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), sf.getName(), json);
//                    }
//                }
//            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient(), sf.getOpenid());
            } else{
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient(), sf.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject j = jsonArray.getJSONObject(i);
@ -1299,17 +1298,22 @@ public class FamilyContractService extends BaseService {
                    data.put("represented", member.getCode());
                    data.put("agent", "1");
                    String ms = sf.getName() + ",您好!祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                    templateConfig = templateConfigDao.findByScene("template_sign_success", "agent");
                    keyword4 = templateConfig.getKeyword4();
                    keyword4 = keyword4.replace("key1",sf.getName()==null?"":sf.getName()).replace("key2",sf.getDoctorName()==null?"":sf.getDoctorName())
                            .replace("key3",(hos != null ? hos.getName() : "") ).replace("key4",(hos != null ? hos.getAddress() : ""));
                    /*String ms = sf.getName() + ",您好!祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                            "为了给您提供更好的服务,请尽快完成缴费。您可登录签约居民的微信账号,进入签约管理,选择待缴费的签约记录进行缴费操作,如需线下缴费,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                            (hos != null ? hos.getAddress() : "") + ")缴费。";
                            (hos != null ? hos.getAddress() : "") + ")缴费。";*/
                    data.put("content", ms);
                    data.put("content", keyword4);
                    //String first = (String) json.get("first");
                    data.remove("first");
                    data.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), patient.getName()));
                    pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), patient.getName(), data);
                }
            }
        }
            new Thread(new SignUploadTask(sf.getCode(), httpUtil, jwUrl)).start();
            JSONObject participants = new JSONObject();
@ -1553,9 +1557,16 @@ public class FamilyContractService extends BaseService {
            if (StringUtils.isNotEmpty(refuseReason)){
                sf.setRefuseSpeak(refuseReason);
            }
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_failed","self");
            String first = templateConfig.getFirst();
            String keyword4 = templateConfig.getKeyword4();
            keyword4 = keyword4.replace("key1",(sf.getName()==null?"":sf.getName())).replace("key2",(StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorName()));
            String remark = templateConfig.getRemark();
            // 拒绝签约
            JSONObject json = new JSONObject();
            json.put("first", "签约失败通知");
            json.put("first",first);
            json.put("toUser", sf.getPatient());
            json.put("represented", sf.getPatient());//被代理人
            json.put("doctor", StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealth() : sf.getDoctor());
@ -1563,27 +1574,18 @@ public class FamilyContractService extends BaseService {
            json.put("signCode", sf.getCode());
            json.put("doctorName", StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorName());
            json.put("date", DateUtil.dateToStrShort(new Date()));
            json.put("content", sf.getName() + ",您好!您与 " + (StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorName()) + " 医生建立家庭医生签约关系失败,请查看!");
//            json.put("content", sf.getName() + ",您好!您与 " + (StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorName()) + " 医生建立家庭医生签约关系失败,请查看!");
            json.put("content", keyword4);
            if (StringUtils.isNotEmpty(refuseReason)){
                json.put("remark", refuseReason);
            }else {
                json.put("remark", "您好,签约家庭医生失败通知");
                json.put("remark", remark);
            }
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                pushMsgTask.putWxMsg(access_token, 2, 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");
//                    json.remove("first");
//                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
//                    pushMsgTask.putWxMsg(access_token, 2, member.getOpenid(), p.getName(), json);
//                }
//            }
            }else{
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient(), sf.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
@ -1599,6 +1601,7 @@ public class FamilyContractService extends BaseService {
                    pushMsgTask.putWxMsg(access_token, 2, member.getOpenid(), p.getName(), data);
                }
            }
        }
            result.put("status", 2);
@ -1616,18 +1619,25 @@ public class FamilyContractService extends BaseService {
            Doctor doc = doctorDao.findByCode(StringUtils.isNotEmpty(doctor) ? sf.getDoctorHealth() : sf.getDoctor());
            Hospital hos = hospitalDao.findByCode(doc.getHospital());
            String content = sf.getName() + ",您好!祝贺您,成功签约" + doc.getName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_success", "self");
            String first = templateConfig.getFirst();
            String keyword4 = templateConfig.getKeyword4();
            keyword4 = keyword4.replace("key1",sf.getName()==null?"":sf.getName()).replace("key2",sf.getDoctorName()==null?"":sf.getDoctorName())
                    .replace("key3",(hos != null ? hos.getName() : "") ).replace("key4",(hos != null ? hos.getAddress() : ""));
            /*String content = sf.getName() + ",您好!祝贺您,成功签约" + doc.getName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                    "为了给您提供更好的服务,请尽快完成缴费。您可点击此条消息,跳转缴费页面完成缴费,或进入签约管理,选择待缴费的签约记录进行缴费操作,如需线下缴费,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                    (hos != null ? hos.getAddress() : "") + ")缴费。";
                    (hos != null ? hos.getAddress() : "") + ")缴费。";*/
            // 同意签约
            JSONObject json = new JSONObject();
            json.put("first", "签约成功通知");
            json.put("first", first);
            json.put("toUser", sf.getPatient());
            json.put("represented", sf.getPatient());//被代理人
            json.put("doctor", doc.getCode());
            json.put("doctorName", doc.getName());
            json.put("date", DateUtil.dateToStrShort(new Date()));
            json.put("content", content);
//            json.put("content", content);
            json.put("content", keyword4);
            json.put("remark", ""); //您好,您成功签约家庭医生
//            添加签约code by wjj 2017.7.18
            json.put("signCode", sf.getCode()); //签约code
@ -1635,38 +1645,34 @@ public class FamilyContractService extends BaseService {
            // 添加到发送队列
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                pushMsgTask.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");
//                    json.remove("first");
//                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
//                    pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), p.getName(), json);
//                }
//            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient(), sf.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject data = json;
            }else {
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient(), sf.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
//                    data.remove("toUser");
                    data.remove("agent");
                        data.remove("agent");
//                    data.put("toUser", member.getCode());
                    data.put("agent", "1");
                    data.remove("represented");
                    data.put("represented", member.getCode());
                    String ms = sf.getName() + ",您好!祝贺您,成功签约" + doc.getName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                            "为了给您提供更好的服务,请尽快完成缴费。您可登录签约居民的微信账号,进入签约管理,选择待缴费的签约记录进行缴费操作,如需线下缴费,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                            (hos != null ? hos.getAddress() : "") + ")缴费。";
                    data.put("content", ms);
                    //String first = (String) json.get("first");
                    data.remove("first");
                    data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                    pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), p.getName(), data);
                        data.put("agent", "1");
                        data.remove("represented");
                        data.put("represented", member.getCode());
                        /*String ms = sf.getName() + ",您好!祝贺您,成功签约" + doc.getName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                                "为了给您提供更好的服务,请尽快完成缴费。您可登录签约居民的微信账号,进入签约管理,选择待缴费的签约记录进行缴费操作,如需线下缴费,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                                (hos != null ? hos.getAddress() : "") + ")缴费。";*/
                        templateConfig = templateConfigDao.findByScene("template_sign_success", "agent");
                        keyword4 = templateConfig.getKeyword4();
                        keyword4 = keyword4.replace("key1",sf.getName()==null?"":sf.getName()).replace("key2",sf.getDoctorName()==null?"":sf.getDoctorName())
                                .replace("key3",(hos != null ? hos.getName() : "") ).replace("key4",(hos != null ? hos.getAddress() : ""));
                        data.put("content", keyword4);
                        //String first = (String) json.get("first");
                        data.remove("first");
                        data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                        pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), p.getName(), data);
                    }
                }
            }
@ -1737,91 +1743,82 @@ public class FamilyContractService extends BaseService {
            //结束患者家庭签约咨询
            consultTeamDao.updateStatusByPatient(patient);
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_termination","jycg");
            String first = templateConfig.getFirst();
            String remark = templateConfig.getRemark();
            remark = remark.replace("key1",(sf.getName()==null?"":sf.getName()));
            // 推送消息消息给微信端
            JSONObject json = new JSONObject();
            json.put("first", "解约申请通知");
            json.put("first", first);
            json.put("toUser", sf.getPatient());
            json.put("represented", sf.getPatient());//被代理人
            json.put("date", DateUtil.getStringDateShort());
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
            json.put("orgName", sf.getHospitalName());
            json.put("remark", sf.getName() + ",您好!您的签约医生已同意您的解约申请,解约已生效。");
//            json.put("remark", sf.getName() + ",您好!您的签约医生已同意您的解约申请,解约已生效。");
            json.put("remark", remark);
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                pushMsgTask.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");
//                    json.remove("first");
//                    Patient p = patientDao.findByCode(patient);
//                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
//                    pushMsgTask.putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
//                }
//            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient(), sf.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                Patient p = patientDao.findByCode(patient);
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject data = json;
                    data.remove("toUser");
                    data.put("toUser", member.getCode());
                    //String first = (String) json.get("first");
                    data.remove("first");
                    data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                    pushMsgTask.putWxMsg(access_token, 5, member.getOpenid(), p.getName(), data);
            }else {
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient(), sf.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    Patient p = patientDao.findByCode(patient);
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        //String first = (String) json.get("first");
                        data.remove("first");
                        data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                        pushMsgTask.putWxMsg(access_token, 5, member.getOpenid(), p.getName(), data);
                    }
                }
            }
        } else {
            // 更新状态为正常
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_termination","jysb");
            String first = templateConfig.getFirst();
            String remark = templateConfig.getRemark();
            remark = remark.replace("key1",(sf.getName()==null?"":sf.getName()));
            signFamilyDao.refuseSurrender(patient);
            // 拒绝解约,推送消息消息给微信端
            JSONObject json = new JSONObject();
            json.put("first", "解约申请通知");
            json.put("first", first);
            json.put("toUser", sf.getPatient());
            json.put("represented", sf.getPatient());//被代理人
            json.put("date", DateUtil.getStringDateShort());
            json.put("doctor", sf.getDoctor());
            json.put("doctorName", sf.getDoctorName());
            json.put("orgName", sf.getHospitalName());
            json.put("remark", sf.getName() + ",您好!您的签约医生拒绝您的解约申请,解约失败。");
//            json.put("remark", sf.getName() + ",您好!您的签约医生拒绝您的解约申请,解约失败。");
            json.put("remark", remark);
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                pushMsgTask.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");
//                    json.remove("first");
//                    Patient p = patientDao.findByCode(patient);
//                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
//                    pushMsgTask.putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
//                }
//            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient(), sf.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                Patient p = patientDao.findByCode(patient);
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject data = json;
                    data.remove("toUser");
                    data.put("toUser", member.getCode());
                    //String first = (String) json.get("first");
                    data.remove("first");
                    data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                    pushMsgTask.putWxMsg(access_token, 5, member.getOpenid(), p.getName(), data);
            }else {
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(sf.getPatient(), sf.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    Patient p = patientDao.findByCode(patient);
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        //String first = (String) json.get("first");
                        data.remove("first");
                        data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                        pushMsgTask.putWxMsg(access_token, 5, member.getOpenid(), p.getName(), data);
                    }
                }
            }
@ -2332,22 +2329,38 @@ public class FamilyContractService extends BaseService {
                    doctorTeamDoctor.save(teamMember);
                }
                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","jgsbg");
                String first = templateConfig.getFirst();
                first = first.replace("key1",(p.getName()==null?"":p.getName()));
                String keyword3 = templateConfig.getKeyword3();
                String remark = templateConfig.getRemark();
                remark = remark.replace("key1",(docHealth.getName()==null?"":docHealth.getName()));
                JSONObject data = new JSONObject();
                data.put("toUser", patient);
                data.put("represented", patient);//被代理人
                data.put("doctor", docHealth.getCode());
                data.put("doctorName", docHealth.getName());
                data.put("first", p.getName() + ",您好!您签约团队的健康管理师已变更,您的新健管师信息如下:");
                data.put("keyword3", "家庭医生-健康管理师");
//                data.put("first", p.getName() + ",您好!您签约团队的健康管理师已变更,您的新健管师信息如下:");
                data.put("first", first);
                data.put("keyword3", keyword3);
                data.put("keyword2", DateUtil.dateToStrNoSecond(new Date()));
                data.put("keyword1", docHealth.getName());
                if (StringUtils.isEmpty(signFamily.getDoctor()) || docHealth.getCode().equals(signFamily.getDoctor())) {
                data.put("remark", remark);
                /*if (StringUtils.isEmpty(signFamily.getDoctor()) || docHealth.getCode().equals(signFamily.getDoctor())) {
                    data.put("remark", docHealth.getName() + "健管师将继续为您提供优质健康服务");
                } else {
                    data.put("remark", docHealth.getName() + "健管师将继续为您提供优质健康服务");
                }
                }*/
                wxMessages.add(data);
            } else {
                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","jgsxz");
                String first = templateConfig.getFirst();
                first = first.replace("key1",(p.getName()==null?"":p.getName()));
                String keyword3 = templateConfig.getKeyword3();
                String remark = templateConfig.getRemark();
                remark = remark.replace("key1",(docHealth.getName()==null?"":docHealth.getName()));
                JSONObject data = new JSONObject();
                data.put("toUser", patient);
                data.put("represented", patient);//被代理人
@ -2358,9 +2371,14 @@ public class FamilyContractService extends BaseService {
                data.put("keyword2", DateUtil.dateToStrNoSecond(new Date()));
                data.put("keyword1", docHealth.getName());
                if (StringUtils.isEmpty(signFamily.getDoctor()) || docHealth.getCode().equals(signFamily.getDoctor())) {
                    data.put("remark", docHealth.getName() + "健管师将继续为您提供优质健康服务");
//                    data.put("remark", docHealth.getName() + "健管师将继续为您提供优质健康服务");
                    data.put("remark", remark);
                } else {
                    data.put("remark", docHealth.getName() + "健管师与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
                    templateConfig = templateConfigDao.findByScene("template_doctor_change","jgsxzqk");
                    remark = templateConfig.getRemark();
                    remark = remark.replace("key1",(docHealth.getName()==null?"":docHealth.getName())).replace("key2",(signFamily.getDoctorName()==null?"":signFamily.getDoctorName()));
                    data.put("remark", remark);
//                    data.put("remark", docHealth.getName() + "健管师与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
                }
                wxMessages.add(data);
                try {
@ -2448,20 +2466,29 @@ public class FamilyContractService extends BaseService {
            signFamily.setDoctorName(docQk.getName());
            signFamily.setCzrq(new Date());
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","qkxz");
            String first = templateConfig.getFirst();
            first = first.replace("key1",(p.getName()==null?"":p.getName()));
            String keyword3 = templateConfig.getKeyword3();
            String remark = templateConfig.getRemark();
            remark = remark.replace("key1",(docQk.getName()==null?"":docQk.getName()));
            JSONObject data = new JSONObject();
            data.put("toUser", patient);
            data.put("represented", patient);//被代理人
            data.put("doctor", docQk.getCode());
            data.put("doctorName", docQk.getName());
            data.put("first", p.getName() + ",您好!您签约团队的全科医生已变更,您的新全科医生信息如下:");
            data.put("keyword3", "家庭医生-全科医生");
//            data.put("first", p.getName() + ",您好!您签约团队的全科医生已变更,您的新全科医生信息如下:");
            data.put("first", first);
            data.put("keyword3", keyword3);
            data.put("keyword2", DateUtil.dateToStrNoSecond(new Date()));
            data.put("keyword1", docQk.getName());
            if (StringUtils.isEmpty(signFamily.getDoctorHealth()) || signFamily.getDoctor().equals(signFamily.getDoctorHealth())) {
            data.put("remark", remark);
            /*if (StringUtils.isEmpty(signFamily.getDoctorHealth()) || signFamily.getDoctor().equals(signFamily.getDoctorHealth())) {
                data.put("remark", docQk.getName() + "医生将专门为您提供优质健康服务");
            } else {
                data.put("remark", docQk.getName() + "医生将继续为您提供优质健康服务");
            }
            }*/
            wxMessages.add(data);
        }
@ -2482,36 +2509,21 @@ public class FamilyContractService extends BaseService {
            if (StringUtils.isNotBlank(p.getOpenid())) {
                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), msg);
            }
//            else {
//                //如果自己没有绑定,则发给家人
//                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//                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) {
//                        e.printStackTrace();
//                    }
//                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), msg);
//                }
//            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject data = msg;
                    data.remove("toUser");
                    data.put("toUser", member.getCode());
                    String first = (String) data.get("first");
                    data.remove("first");
                    data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), data);
            }else {
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = msg;
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        String first = (String) data.get("first");
                        data.remove("first");
                        data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                        pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), data);
                    }
                }
            }

+ 34 - 21
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/PatientRemindService.java

@ -4,10 +4,12 @@ import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.common.SMSService;
@ -62,6 +64,8 @@ public class PatientRemindService extends BaseService {
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    /**
     * 缴费提醒
     *
@ -224,6 +228,12 @@ public class PatientRemindService extends BaseService {
                }
            }
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_expenses_remind","jftx");
            String first = templateConfig.getFirst();
            first = first.replace("key1",(doc.getName()==null?"":doc.getName()));
            String remark = templateConfig.getRemark();
            remark = remark.replace("key1",(p.getName()==null?"":p.getName())).replace("key2",(hos.getName()==null?"":hos.getName()))
                            .replace("key3",(hos.getAddress()==null?"":hos.getAddress()));
            // 微信提醒
            JSONObject json = new JSONObject();
            json.put("first", "缴费提醒");
@ -231,9 +241,11 @@ public class PatientRemindService extends BaseService {
            json.put("represented",p.getCode());//被代理人
            json.put("name", p.getName());
            json.put("doctor", doc.getCode());
            json.put("doctorName", "提醒医生:  "+doc.getName());
//            json.put("doctorName", "提醒医生:  "+doc.getName());
            json.put("doctorName", first);
            json.put("date", DateUtil.dateToStrShort(new Date()));
            json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费");
//            json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费");
            json.put("content", remark);
            json.put("remark", "");
            //判断是否判定openId,有没有发则查找家人发送
@ -242,29 +254,30 @@ public class PatientRemindService extends BaseService {
                // 添加到发送队列
                pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 8, p.getOpenid(), p.getName(), json);
                wFlag = true;
            }
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
            if(jsonArray!=null&&jsonArray.length()>0){
                String first = (String) json.get("doctorName");
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    isOpenIdExist = true;
                    JSONObject data = json;
                    data.remove("toUser");
                    data.put("toUser",member.getCode());
                    data.remove("doctorName");
                    data.put("doctorName", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) +"\n"+first);
                    pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 8, member.getOpenid(), p.getName(), data);
                    wFlag = true;
            }else {
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    first = (String) json.get("doctorName");
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        isOpenIdExist = true;
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        data.remove("doctorName");
                        data.put("doctorName", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + "\n" + first);
                        pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 8, member.getOpenid(), p.getName(), data);
                        wFlag = true;
                    }
                }
            }
            //发送IM
            consultService.sendMucMessageBySingnType(doc.getCode(), doc.getName(), p.getCode(), doc.getName() + "医生提醒您:为完成家庭医生签约," +
                    "尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费", "1",p.getName());
          /*  consultService.sendMucMessageBySingnType(doc.getCode(), doc.getName(), p.getCode(), doc.getName() + "医生提醒您:为完成家庭医生签约," +
                    "尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费", "1",p.getName());*/
            consultService.sendMucMessageBySingnType(doc.getCode(), doc.getName(), p.getCode(), doc.getName() + "医生提醒您:"+remark, "1",p.getName());
            if (wFlag || mFlag) {
                reObj.put("status", 200);

+ 236 - 186
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java

@ -12,6 +12,7 @@ import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeamMember;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.patient.*;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.address.CountryDao;
import com.yihu.wlyy.repository.address.StreetDao;
import com.yihu.wlyy.repository.address.TownDao;
@ -24,6 +25,7 @@ import com.yihu.wlyy.repository.doctor.DoctorTeamDao;
import com.yihu.wlyy.repository.doctor.DoctorTeamMemberDao;
import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.repository.patient.*;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
@ -126,6 +128,8 @@ public class SignWebService extends BaseService {
    private String esIndex;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    /**
     * 厦门市
     */
@ -1424,35 +1428,47 @@ public class SignWebService extends BaseService {
                String openid = (String) signFamily.get("openid");
                String name = (String) signFamily.get("name");
                String doctorName = (String) signFamily.get("doctorName");
                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","xqtx");
                String first = templateConfig.getFirst();
                first = first.replace("key1",(name==null?"":name)).replace("br","\n");
                String remark = templateConfig.getRemark();
                remark = remark.replace("key1",(doctorName==null?"":doctorName)).replace("br","\n");
                String keyword1 = templateConfig.getKeyword1();
                JSONObject json = new JSONObject();
                String patient = (String) signFamily.get("code");
                json.put("toUser", patient);
                json.put("represented", patient);//被代理人
                json.put("keyword1", "续签家庭医生");
                json.put("keyword1", keyword1);
                json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
                json.put("remark", "提醒医生 :" + doctorName + "\n"
                        + "我们将继续为您提供优质的健康服务。");
                json.put("remark", remark);
                json.put("first", first);
                if (StringUtils.isNotBlank(openid)) {
                    flag = false;
                    json.put("first", name + ",您好!\n" +
                            "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
                    /*json.put("first", name + ",您好!\n" +
                            "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");*/
                    pushMsgTask.putWxMsg(access_token, 16, openid, name, json);
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openid);
                if (jsonArray != null && jsonArray.length() > 0) {
                    Patient p = patientService.findByCode(patient);
                    for (int i = 0; i < jsonArray.length(); i++) {
                        flag = false;
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()) + "\n" +
                                name + ",您好!\n" +
                                "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
                        pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 8, member.getOpenid(), p.getName(), data);
                }else {
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openid);
                    if (jsonArray != null && jsonArray.length() > 0) {
                        Patient p = patientService.findByCode(patient);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            flag = false;
                            JSONObject j = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser", member.getCode());
                            /*json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()) + "\n" +
                                    name + ",您好!\n" +
                                    "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");*/
                            json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()) + "\n" +first);
                            pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 8, member.getOpenid(), p.getName(), data);
                        }
                    }
                }
@ -1528,40 +1544,53 @@ public class SignWebService extends BaseService {
        List<Map<String, Object>> signFamilies = jdbcTemplate.queryForList(sql);
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","xqtx");
        if (signFamilies != null && signFamilies.size() > 0) {
            for (Map<String, Object> signFamily : signFamilies) {
                String openid = (String) signFamily.get("openid");
                String name = (String) signFamily.get("name");
                String doctorName = (String) signFamily.get("doctorName");
                String first = templateConfig.getFirst();
                first = first.replace("key1",(name==null?"":name)).replace("br","\n");
                String remark = templateConfig.getRemark();
                remark = remark.replace("key1",(doctorName==null?"":doctorName)).replace("br","\n");
                String keyword1 = templateConfig.getKeyword1();
                JSONObject json = new JSONObject();
                Boolean flag = true;
                String patient = (String) signFamily.get("code");
                json.put("toUser", patient);
                json.put("represented", patient);//被代理人
                json.put("keyword1", "续签家庭医生");
                json.put("keyword1", keyword1);
                json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
                json.put("remark", "提醒医生 :" + doctorName + "\n"
                        + "我们将继续为您提供优质的健康服务。");
                json.put("remark", remark);
                json.put("first", first);
                if (StringUtils.isNotBlank(openid)) {
                    json.put("first", name + ",您好!\n" +
                            "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
                    /*json.put("first", name + ",您好!\n" +
                            "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");*/
                    pushMsgTask.putWxMsg(access_token, 16, openid, name, json);
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openid);
                if (jsonArray != null && jsonArray.length() > 0) {
                    Patient p = patientService.findByCode(patient);
                    for (int i = 0; i < jsonArray.length(); i++) {
                        flag = false;
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()) + "\n" +
                                name + ",您好!\n" +
                                "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
                        pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 16, member.getOpenid(), p.getName(), data);
                }else {
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openid);
                    if (jsonArray != null && jsonArray.length() > 0) {
                        Patient p = patientService.findByCode(patient);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            flag = false;
                            JSONObject j = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser", member.getCode());
                            json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()) + "\n" +first);
                            /*json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()) + "\n" +
                                    name + ",您好!\n" +
                                    "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");*/
                            pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 16, member.getOpenid(), p.getName(), data);
                        }
                    }
                }
                if (flag) {
@ -1667,7 +1696,7 @@ public class SignWebService extends BaseService {
                JSONObject data = new JSONObject();
                data.put("doctorName", renew.getDoctorName());
                data.put("date", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
                data.put("content", "家庭医生续签");
//                data.put("content", "家庭医生续签");
                data.put("doctor", dotorCode);
                data.put("represented", patientCode);
                data.put("toUser", patientCode);
@ -1681,64 +1710,82 @@ public class SignWebService extends BaseService {
                if (patient != null && StringUtils.isNotBlank(patient.getOpenid())) {
                    if ("0".equals(state)) {
                        data.put("first", renew.getName() + ",您好!\n" +
                        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_failed","failed");
                        String first = templateConfig.getFirst();
                        first = first.replace("key1",(renew.getName()==null?"":renew.getName())).replace("br","\n");
                        String remark = templateConfig.getRemark();
                        String keyword4 = templateConfig.getKeyword4();
                        /*data.put("first", renew.getName() + ",您好!\n" +
                                "您的家庭医生续签申请已被拒绝");
                        data.put("remark", "您可选择其他医生进行签约。");
                        data.put("remark", "您可选择其他医生进行签约。");*/
                        data.put("first", first);
                        data.put("remark", remark);
                        data.put("content", keyword4);
                        pushMsgTask.putWxMsg(access_token, 2, patient.getOpenid(), patient.getName(), data);
                    } else if ("1".equals(state)) {
                        data.put("first", renew.getName() + ",您好!\n" +
                        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_success","success");
                        String first = templateConfig.getFirst();
                        first = first.replace("key1",(renew.getName()==null?"":renew.getName())).replace("br","\n");
                        String remark = templateConfig.getRemark();
                        String keyword4 = templateConfig.getKeyword4();
                        data.put("first", first);
                        data.put("remark", remark);
                        data.put("content", keyword4);
                        /*data.put("first", renew.getName() + ",您好!\n" +
                                "您的家庭医生续签申请已通过");
                        data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");
                        data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");*/
                        pushMsgTask.putWxMsg(access_token, 1, patient.getOpenid(), patient.getName(), data);
                    }
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        //String first = (String) json.get("first");
                        if ("0".equals(state)) {
                            data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
                                    patient.getName() + ",您好!\n" +
                                    "您的家庭医生续签申请已被拒绝");
                            data.put("remark", "您可选择其他医生进行签约。");
                            pushMsgTask.putWxMsg(access_token, 2, member.getOpenid(), patient.getName(), data);
                        } else if ("1".equals(state)) {
                            data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
                                    patient.getName() + ",您好!\n" +
                                    "您的家庭医生续签申请已通过");
                            data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");
                            pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), patient.getName(), data);
                }else {
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
                    if (jsonArray != null && jsonArray.length() > 0) {
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject j = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            data.remove("toUser");
                            data.put("toUser", member.getCode());
                            //String first = (String) json.get("first");
                            if ("0".equals(state)) {
                                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_failed","failed");
                                String first = templateConfig.getFirst();
                                first = first.replace("key1",(patient.getName()==null?"":patient.getName())).replace("br","\n");
                                String remark = templateConfig.getRemark();
                                String keyword4 = templateConfig.getKeyword4();
                                data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" + first);
                                data.put("remark", remark);
                                data.put("content", keyword4);
                                /*data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
                                        patient.getName() + ",您好!\n" +
                                        "您的家庭医生续签申请已被拒绝");
                                data.put("remark", "您可选择其他医生进行签约。");*/
                                pushMsgTask.putWxMsg(access_token, 2, member.getOpenid(), patient.getName(), data);
                            } else if ("1".equals(state)) {
                                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_success","success");
                                String first = templateConfig.getFirst();
                                first = first.replace("key1",(patient.getName()==null?"":patient.getName())).replace("br","\n");
                                String remark = templateConfig.getRemark();
                                String keyword4 = templateConfig.getKeyword4();
                                data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" + first);
                                data.put("remark", remark);
                                data.put("content", keyword4);
                                /*data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
                                        patient.getName() + ",您好!\n" +
                                        "您的家庭医生续签申请已通过");
                                data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");*/
                                pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), patient.getName(), data);
                            }
                        }
                    }
                }
//                else {
//                    //如果自己没有绑定,则发给家人
//                    JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient.getCode());
//                    Patient member = (Patient) j.get("member");
//                    if (StringUtils.isNotBlank(member.getOpenid())) {
//
//                        if ("0".equals(state)) {
//                            data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
//                                    patient.getName() + ",您好!\n" +
//                                    "您的家庭医生续签申请已被拒绝");
//                            data.put("remark", "您可选择其他医生进行签约。");
//                            pushMsgTask.putWxMsg(access_token, 2, member.getOpenid(), patient.getName(), data);
//                        } else if ("1".equals(state)) {
//                            data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
//                                    patient.getName() + ",您好!\n" +
//                                    "您的家庭医生续签申请已通过");
//                            data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");
//                            pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), patient.getName(), data);
//                        }
//                    }
//                }
                //-1患者已取消,-2已拒绝,-3已解约,-4已到期,0待签约,1已签约,2患者申请取消签约,3医生申请取消签约
            } else if (status == 1) {
                //已经同意
@ -1851,64 +1898,76 @@ public class SignWebService extends BaseService {
                        }else {
                            data.put("content", "家庭医生续签");
                        }
                        data.put("first", renew.getName() + ",您好!\n" +
                        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_failed","failed");
                        String first = templateConfig.getFirst();
                        first = first.replace("key1",(renew.getName()==null?"":renew.getName())).replace("br","\n");
                        String remark = templateConfig.getRemark();
                        data.put("first", first);
                        data.put("remark", remark);
                        /*data.put("first", renew.getName() + ",您好!\n" +
                                "您的家庭医生续签申请已被拒绝");
                        data.put("remark", "您可在到期后选择其他医生进行签约。");
                        data.put("remark", "您可在到期后选择其他医生进行签约。");*/
                        pushMsgTask.putWxMsg(access_token, 2, patient.getOpenid(), patient.getName(), data);
                    } else if ("1".equals(state)) {
                        data.put("content", "家庭医生续签");
                        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_success","success");
                        String first = templateConfig.getFirst();
                        first = first.replace("key1",(renew.getName()==null?"":renew.getName())).replace("br","\n");
                        String remark = templateConfig.getRemark();
                        String keyword4 = templateConfig.getKeyword4();
                        data.put("first", first);
                        data.put("remark", remark);
                        data.put("content", keyword4);
                        /*data.put("content", "家庭医生续签");
                        data.put("first", renew.getName() + ",您好!\n" +
                                "您的家庭医生续签申请已通过");
                        data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");
                        data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");*/
                        pushMsgTask.putWxMsg(access_token, 1, patient.getOpenid(), patient.getName(), data);
                    }
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        //String first = (String) json.get("first");
                        if ("0".equals(state)) {
                            data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
                                    patient.getName() + ",您好!\n" +
                                    "您的家庭医生续签申请已被拒绝");
                            data.put("remark", "您可在到期后选择其他医生进行签约。");
                            pushMsgTask.putWxMsg(access_token, 2, member.getOpenid(), patient.getName(), data);
                        } else if ("1".equals(state)) {
                            data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
                                    patient.getName() + ",您好!\n" +
                                    "您的家庭医生续签申请已通过");
                            data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");
                            pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), patient.getName(), data);
                }else {
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
                    if (jsonArray != null && jsonArray.length() > 0) {
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject j = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            data.remove("toUser");
                            data.put("toUser", member.getCode());
                            //String first = (String) json.get("first");
                            if ("0".equals(state)) {
                                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_failed","failed");
                                String first = templateConfig.getFirst();
                                first = first.replace("key1",(patient.getName()==null?"":patient.getName())).replace("br","\n");
                                String remark = templateConfig.getRemark();
                                data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" + first);
                                data.put("remark", remark);
                                /*data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
                                        patient.getName() + ",您好!\n" +
                                        "您的家庭医生续签申请已被拒绝");
                                data.put("remark", "您可在到期后选择其他医生进行签约。");*/
                                pushMsgTask.putWxMsg(access_token, 2, member.getOpenid(), patient.getName(), data);
                            } else if ("1".equals(state)) {
                                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_sign_success","success");
                                String first = templateConfig.getFirst();
                                first = first.replace("key1",(patient.getName()==null?"":patient.getName())).replace("br","\n");
                                String remark = templateConfig.getRemark();
                                data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" + first);
                                data.put("remark", remark);
                                /*data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
                                        patient.getName() + ",您好!\n" +
                                        "您的家庭医生续签申请已通过");
                                data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");*/
                                pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), patient.getName(), data);
                            }
                        }
                    }
                }
//                else {
//                    //如果自己没有绑定,则发给家人
//                    JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient.getCode());
//                    Patient member = (Patient) j.get("member");
//                    if (StringUtils.isNotBlank(member.getOpenid())) {
//
//                        if ("0".equals(state)) {
//                            data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
//                                    patient.getName() + ",您好!\n" +
//                                    "您的家庭医生续签申请已被拒绝");
//                            data.put("remark", "您可在到期后选择其他医生进行签约。");
//                            pushMsgTask.putWxMsg(access_token, 2, member.getOpenid(), patient.getName(), data);
//                        } else if ("1".equals(state)) {
//                            data.put("first", weiXinOpenIdUtils.getTitleMes(patient, (int) j.get("relation"), patient.getName()) + "\n" +
//                                    patient.getName() + ",您好!\n" +
//                                    "您的家庭医生续签申请已通过");
//                            data.put("remark", "待自动扣费成功后,家庭医生将续签成功。");
//                            pushMsgTask.putWxMsg(access_token, 1, member.getOpenid(), patient.getName(), data);
//                        }
//                    }
//                }
            } else if (status == 1) {
                //已经同意
                return 2;
@ -2101,39 +2160,52 @@ public class SignWebService extends BaseService {
        }
        //发送微信模板消息
        Patient p = patientService.findByCode(patientCode);
        String openid = p.getOpenid();
        String name = p.getName();
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","xqtx");
        String first = templateConfig.getFirst();
        first = first.replace("key1",(name==null?"":name)).replace("br","\n");
        String remark = templateConfig.getRemark();
        remark = remark.replace("key1",(d.getName()==null?"":d.getName())).replace("br","\n");
        String keyword1 = templateConfig.getKeyword1();
        JSONObject json = new JSONObject();
        json.put("toUser", patientCode);
        json.put("represented", patientCode);//被代理人
        json.put("keyword1", "续签家庭医生");
        json.put("keyword1", keyword1);
        json.put("keyword2", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        json.put("remark", "提醒医生 :" + d.getName() + "\n"
                + "我们将继续为您提供优质的健康服务。");
        String openid = p.getOpenid();
        String name = p.getName();
        /*json.put("remark", "提醒医生 :" + d.getName() + "\n"
                + "我们将继续为您提供优质的健康服务。");*/
        json.put("remark", remark);
        boolean flag = true;
        if (StringUtils.isNotBlank(openid)) {
            json.put("first", name + ",您好!\n" +
                    "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
            /*json.put("first", name + ",您好!\n" +
                    "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");*/
            json.put("first", first);
            pushMsgTask.putWxMsg(access_token, 16, openid, name, json);
            patientSetReminFlag(patientCode);
            return 1;
        }
        //发送代理人
        boolean flag = true;
        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patientCode, openid);
        if (jsonArray != null && jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                flag = false;
                JSONObject j = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                JSONObject data = json;
                data.remove("toUser");
                data.put("toUser", member.getCode());
                json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()) + "\n" +
                        name + ",您好!\n" +
                        "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
                pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 16, member.getOpenid(), p.getName(), data);
        }else {
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patientCode, openid);
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    flag = false;
                    JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject data = json;
                    data.remove("toUser");
                    data.put("toUser", member.getCode());
                    /*json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()) + "\n" +
                            name + ",您好!\n" +
                            "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");*/
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), p.getName()) + "\n" +first);
                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 16, member.getOpenid(), p.getName(), data);
                    flag = false;
                }
            }
        }
        if (flag) {
@ -2147,28 +2219,6 @@ public class SignWebService extends BaseService {
        } else {
            return 1;
        }
//        else {
//            //如果自己没有绑定,则发给家人
//            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patientCode);
//            Patient member = (Patient) j.get("member");
//            if (StringUtils.isNotBlank(member.getOpenid())) {
//                json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) j.get("relation"), name) + "\n" +
//                        name + ",您好!\n" +
//                        "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。");
//                pushMsgTask.putWxMsg(access_token, 16, member.getOpenid(), name, json);
//                patientSetReminFlag(patientCode);
//                return 1;
//            } else {
//                //发送短信
//                String mobile = p.getMobile();
//                if (StringUtils.isNotBlank(mobile)) {
//                    SMSService.sendMsg(mobile, name + "您好!您的家庭医生将于6月30日到期,为了继续给您提供健康服务,请关注“厦门i健康”公众号,回复“续签”,进行家庭医生线上续签。");
//                    patientSetReminFlag(patientCode);
//                    return 2;
//                }
//            }
//        }
        return -1;
    }

+ 50 - 43
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -4,15 +4,18 @@ import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.survey.*;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -81,6 +84,8 @@ public class ManagerQuestionnaireService extends BaseService {
    WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
@ -242,8 +247,9 @@ public class ManagerQuestionnaireService extends BaseService {
        //            发送居民模板 send=1发送
        if ("1".equals(send)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
            JSONObject json = new JSONObject(str);
//            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
//            JSONObject json = new JSONObject(str);
            JSONObject json = new JSONObject();
 /*           for (String code : codes) {
//            codes.stream().forEach(c -> {
//                Patient p = patientDao.findByCode(c);
@ -281,57 +287,58 @@ public class ManagerQuestionnaireService extends BaseService {
                }
//            });
            }*/
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","survey");
            String remark = templateConfig.getRemark();
            String keyword1 = templateConfig.getKeyword1();
            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("represented", c);
                        json.put("survey_id", surveyCode);
                        String first = name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。";
                        json.put("first", first);
                        Patient p = null;
                        String name = null;
                        String openId = null;
                        String first = null;
                        try {
                            p = patientDao.findByCode(c);
                            name = p.getName();
                            openId = p.getOpenid();
                            json.put("keyword2", sdf.format(new Date()));
                            json.put("toUser", c);
                            json.put("represented", c);
                            json.put("survey_id", surveyCode);
//                        String first = name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。";
                            first = templateConfig.getFirst();
                            first = first.replace("key1",(name==null?"":name));
                            json.put("first", first);
                            json.put("remark", remark);
                            json.put("keyword1", keyword1);
                        } catch (JSONException e) {
                            continue;
                        }
                        //判断是否判定openId,有没有发则查找家人发送
                        if (StringUtils.isNotBlank(p.getOpenid())) {
                            // 添加到发送队列
                            logger.error("json =======>" + json);
//                            PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                            pushMsgTask.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);
//                            }
//                        }
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                        if (jsonArray != null && jsonArray.length() > 0) {
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject j = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                if (StringUtils.isNotBlank(member.getOpenid())) {
                                    json.remove("toUser");
                                    json.put("toUser", member.getCode());
                                    json.remove("first");
                                    try {
                                        json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                        }else {
                            //发送代理人
                            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                            if (jsonArray != null && jsonArray.length() > 0) {
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    JSONObject j = jsonArray.getJSONObject(i);
                                    Patient member = (Patient) j.get("member");
                                    if (StringUtils.isNotBlank(member.getOpenid())) {
                                        json.remove("toUser");
                                        json.put("toUser", member.getCode());
                                        json.remove("first");
                                        try {
                                            json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                        pushMsgTask.sendWeixinMessage(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), p.getName(), json);
                                    }
                                    pushMsgTask.sendWeixinMessage(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), p.getName(), json);
                                }
                            }
                        }

+ 13 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorFeldsherTemplateService.java

@ -45,6 +45,8 @@ public class DoctorFeldsherTemplateService extends BaseService {
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private ImUtill imUtill;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    private static final Logger logger = LoggerFactory.getLogger(DoctorFeldsherTemplateService.class);
@ -63,12 +65,20 @@ public class DoctorFeldsherTemplateService extends BaseService {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        JSONArray jsonArray = null;
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","jcfa");
        String first = templateConfig.getFirst();
        first = first.replace("key1",(name==null?"":name));
        String remark = templateConfig.getRemark();
        String keyword3 = templateConfig.getKeyword3();
        JSONObject sendJson = new JSONObject();
        String first = name + "您好,您的家庭医生已为您设置了血糖(血压)监测方案,请按照方案及时测量及上传您的体征数据。";
        String remark = "您可使用详情查看方案内容";
        /*String first = name + "您好,您的家庭医生已为您设置了血糖(血压)监测方案,请按照方案及时测量及上传您的体征数据。";
        String remark = "您可使用详情查看方案内容";*/
        sendJson.put("keyword1", name);
        sendJson.put("keyword2", dateFormat.format(new Date()));
        sendJson.put("keyword3", "血糖(血压)监测方案");
//        sendJson.put("keyword3", "血糖(血压)监测方案");
        sendJson.put("keyword3", keyword3);
        sendJson.put("first", first);
        sendJson.put("remark", remark);
        sendJson.put("url", url);//带参数的模板跳转链接

+ 56 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/iot/IotDeviceService.java

@ -274,17 +274,70 @@ public class IotDeviceService {
     * @param type
     * @return
     */
    public List<DevicePatientHealthIndex> findByPatientAndType(String patient,Integer type){
    public List<DevicePatientHealthIndex> findByPatientAndType(String patient,Integer type,Integer size){
        List<DevicePatientHealthIndex> list = new ArrayList<>();
        JSONArray jsonArray = new JSONArray();
        field("and","usercode","=",patient,jsonArray);
        field("and","del","=","1",jsonArray);
        field("and","type","=",String.valueOf(type),jsonArray);
        if(type!=null){
            field("and","type","=",String.valueOf(type),jsonArray);
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("filter",jsonArray);
        jsonObject.put("page","1");
        jsonObject.put("size","5");
        jsonObject.put("size",size);
        JSONArray sort = new JSONArray();
        sort(sort,"measure_time","desc");
        jsonObject.put("sort",sort);
        String url = baseUrl+"/dataSearch/getById";
        String response = httpClientUtil.iotPostBody(url, jsonObject.toString());
        try {
            JSONObject json = JSONObject.parseObject(response);
            JSONArray obj = json.getJSONArray("obj");
            if(obj!=null&&obj.size()>0){
                for (int i=0;i<obj.size();i++){
                    DevicePatientHealthIndex index = transforHealthIndex(obj.getJSONObject(i),null);
                    list.add(index);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }
    /**
     * 按时间段查找
     * @param patient 居民code
     * @param type    健康指标类型(1血糖,2血压,3体重,4腰围)
     * @param gi_type 血糖就餐时间段(早餐前,早餐后等)
     * @param begin   开始时间
     * @param end     结束时间
     * @return
     */
    public List<DevicePatientHealthIndex> findByPatientAndTime(String patient,Integer type,Integer page,Integer size,Integer gi_type, String begin, String end){
        List<DevicePatientHealthIndex> list = new ArrayList<>();
        JSONArray jsonArray = new JSONArray();
        field("and","usercode","=",patient,jsonArray);
        field("and","del","=","1",jsonArray);
        if(type!=null){
            field("and","type","=",String.valueOf(type),jsonArray);
        }
        if(gi_type!=null){
            field("and","blood_sugar_result","=",String.valueOf(gi_type),jsonArray);
        }
        field("and","measure_time",">=",begin,jsonArray);
        field("and","measure_time","<=",end,jsonArray);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("filter",jsonArray);
        jsonObject.put("page",page);
        jsonObject.put("size",size);
        JSONArray sort = new JSONArray();
        sort(sort,"measure_time","desc");

+ 36 - 19
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/task/RemindExpensesTask.java

@ -3,6 +3,8 @@ package com.yihu.wlyy.task;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.util.DateUtil;
@ -38,6 +40,8 @@ public class RemindExpensesTask implements Runnable {
    private PushMsgTask pushMsgTask;
    private SMSService smsService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    public RemindExpensesTask(List<Patient> patients, Doctor doctor, Hospital hospital,SMSService smsService) {
@ -52,6 +56,10 @@ public class RemindExpensesTask implements Runnable {
    public void run() {
        StringBuffer sb = new StringBuffer();
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_expenses_remind","jftx");
        String first = templateConfig.getFirst();
        String remark = templateConfig.getRemark();
        for (Patient p : patients) {
            try {
                if (StringUtils.isNotEmpty(p.getMobile())) {
@ -60,6 +68,11 @@ public class RemindExpensesTask implements Runnable {
                    }
                    sb.append(p.getMobile());
                }
                first = first.replace("key1",( doctor.getName()==null?"": doctor.getName()));
                remark = remark.replace("key1",(p.getName()==null?"":p.getName())).replace("key2",(hospital.getName()==null?"":hospital.getName()))
                        .replace("key3",(hospital.getAddress()==null?"":hospital.getAddress()));
                // 微信提醒
                JSONObject json = new JSONObject();
                json.put("first", "缴费提醒");
@ -67,39 +80,43 @@ public class RemindExpensesTask implements Runnable {
                json.put("represented",p.getCode());//被代理人
                json.put("name", p.getName());
                json.put("doctor", doctor.getCode());
                json.put("doctorName", doctor.getName());
//                json.put("doctorName", doctor.getName());
                json.put("doctorName", first);
                json.put("date", DateUtil.dateToStrShort(new Date()));
                json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
//                json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
                json.put("content", remark);
                json.put("remark", "");
                if (StringUtils.isNotEmpty(p.getOpenid())) {
                    // 添加到发送队列
                    pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 8, p.getOpenid(), p.getName(), json);
                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                if(jsonArray!=null&&jsonArray.length()>0){
                    String first = (String) json.get("doctorName");
                    for (int i = 0;i<jsonArray.length();i++){
                        JSONObject j  = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser",member.getCode());
                        data.remove("doctorName");
                        data.put("doctorName", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) +"\n"+first);
                        pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 8, member.getOpenid(), p.getName(), data);
                }else {
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                    if (jsonArray != null && jsonArray.length() > 0) {
                        first = (String) json.get("doctorName");
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject j = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser", member.getCode());
                            data.remove("doctorName");
                            data.put("doctorName", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + "\n" + first);
                            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 8, member.getOpenid(), p.getName(), data);
                        }
                    }
                }
                //发送IM
                consultService.sendMucMessageBySingnType(doctor.getCode(), doctor.getName(), p.getCode(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
                        "尽早为您提供家庭医生服务,请尽快到" + doctor.getName() + "(地址:" + hospital.getAddress() + ")缴费", "1", p.getName());
                /*consultService.sendMucMessageBySingnType(doctor.getCode(), doctor.getName(), p.getCode(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
                        "尽早为您提供家庭医生服务,请尽快到" + doctor.getName() + "(地址:" + hospital.getAddress() + ")缴费", "1", p.getName());*/
                consultService.sendMucMessageBySingnType(doctor.getCode(), doctor.getName(), p.getCode(), doctor.getName() + "医生提醒您:" +remark, "1", p.getName());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        JSONObject result = smsService.sendMsg(sb.toString(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
                "尽早为您提供家庭医生服务,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
                "尽早为您提供家庭医生服务,您可登录微信账号,进入签约管理,选择待缴费的签约记录进行缴费操作,如需线下缴费,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
    }
}

+ 14 - 24
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultPublicController.java

@ -262,33 +262,23 @@ public class DoctorConsultPublicController extends BaseController {
				if(StringUtils.isNotBlank(p.getOpenid())){
					// 添加到发送队列
					pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 3, p.getOpenid(), p.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");
//						json.remove("first");
//						json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//						pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 3, member.getOpenid(), member.getName(), json);
//					}
//				}
				//发送代理人
				JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
				if(jsonArray!=null&&jsonArray.length()>0){
					for (int i = 0;i<jsonArray.length();i++){
						JSONObject j  = jsonArray.getJSONObject(i);
						Patient member = (Patient) j.get("member");
						JSONObject data = json;
						data.remove("toUser");
						data.put("toUser",member.getCode());
						data.remove("first");
						data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName())+first);
						pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 3, member.getOpenid(), p.getName(), data);
				}else {
					//发送代理人
					JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
					if (jsonArray != null && jsonArray.length() > 0) {
						for (int i = 0; i < jsonArray.length(); i++) {
							JSONObject j = jsonArray.getJSONObject(i);
							Patient member = (Patient) j.get("member");
							JSONObject data = json;
							data.remove("toUser");
							data.put("toUser", member.getCode());
							data.remove("first");
							data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
							pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 3, member.getOpenid(), p.getName(), data);
						}
					}
				}
				// 推送消息给患者
				//pushMsgTask.put(cp.getPatient(), MessageType.MESSAGE_TYPE_PATIENT_CONSULT_PUBLIC_REPLY.P_CP_01.name(), MessageType.MESSAGE_TYPE_PATIENT_CONSULT_PUBLIC_REPLY.公共咨询.name(), MessageType.MESSAGE_TYPE_PATIENT_CONSULT_PUBLIC_REPLY.医生回复了您.name(), consult);
				return success("回复成功!");

+ 17 - 17
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java

@ -466,27 +466,27 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
                                map.get("openid") == null ? "" : map.get("openid").toString(),
                                map.get("name") == null ? "" : map.get("name").toString(),
                                (JSONObject) map.get("json"));
                    }
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId((String)map.get("code"),openid);
                    if(jsonArray!=null&&jsonArray.length()>0){
                        Patient p = patientService.findByCode((String)map.get("code"));
                        for (int i=0;i<jsonArray.length();i++){
                            JSONObject j = jsonArray.getJSONObject(i);
                            Patient member = (Patient)j.get("member");
                            JSONObject data = (JSONObject) map.get("json");
                            data.remove("toUser");
                            data.put("toUser",member.getCode());
                            String first = (String)data.get("first");
                            data.remove("first");
                            data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.isNull("relation")?1:j.getInt("relation"),p.getName()));
                            if(StringUtils.isNotBlank(member.getOpenid())){
                                pushMsgTask.putWxMsg(getAccessToken(), 9, member.getOpenid(), p.getName(), data);
                    }else {
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId((String) map.get("code"), openid);
                        if (jsonArray != null && jsonArray.length() > 0) {
                            Patient p = patientService.findByCode((String) map.get("code"));
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject j = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                JSONObject data = (JSONObject) map.get("json");
                                data.remove("toUser");
                                data.put("toUser", member.getCode());
                                String first = (String) data.get("first");
                                data.remove("first");
                                data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.isNull("relation") ? 1 : j.getInt("relation"), p.getName()));
                                if (StringUtils.isNotBlank(member.getOpenid())) {
                                    pushMsgTask.putWxMsg(getAccessToken(), 9, member.getOpenid(), p.getName(), data);
                                }
                            }
                        }
                    }
                }
                for (HealthEduArticlePatient heap : list) {
                    BusinessLogs.info(BusinessLogs.BusinessType.article, getUID(), heap.getPatient(), new JSONObject(heap));

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

@ -2,8 +2,10 @@ package com.yihu.wlyy.web.doctor.survey;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.doctor.SurveyUserDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.survey.ManagerQuestionnaireService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.web.WeixinBaseController;
@ -53,6 +55,8 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    /**
     * 获取问卷列表
     *
@ -429,8 +433,9 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            String accessToken = getAccessToken();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
            JSONObject json = new JSONObject(str);
//            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
//            JSONObject json = new JSONObject(str);
            JSONObject json = new JSONObject();
           /* codes.stream().forEach(c -> {
                Patient p = patientDao.findByCode(c);
                String name = p.getName();
@ -464,7 +469,9 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
                    }
                }
            });*/
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_change","qkxz");
            String remark = templateConfig.getRemark();
            String keyword1 = templateConfig.getKeyword1();
            new Thread() {
                public void run() {
                    for (String c : codes) {
@ -475,47 +482,36 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
                        json.put("toUser", c);
                        json.put("represented", c);
                        json.put("survey_id", code);
                        String first = name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。";
//                        String first = name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。";
                        String first = templateConfig.getFirst();
                        first = first.replace("key1",(name==null?"":name));
                        json.put("first", first);
                        json.put("remark", remark);
                        json.put("keyword1", keyword1);
                        //判断是否判定openId,有没有发则查找家人发送
                        if (StringUtils.isNotBlank(p.getOpenid())) {
                            // 添加到发送队列
                            logger.error("json =======>" + json);
//                            PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                            pushMsgTask.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);
//                            }
//                        }
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                        if(jsonArray!=null&&jsonArray.length()>0){
                            for (int i = 0;i<jsonArray.length();i++){
                                JSONObject j  = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                if(StringUtils.isNotBlank(member.getOpenid())){
                                    json.remove("toUser");
                                    json.put("toUser",member.getCode());
                                    json.remove("first");
                                    try {
                                        json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                        }else {
                            //发送代理人
                            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                            if (jsonArray != null && jsonArray.length() > 0) {
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    JSONObject j = jsonArray.getJSONObject(i);
                                    Patient member = (Patient) j.get("member");
                                    if (StringUtils.isNotBlank(member.getOpenid())) {
                                        json.remove("toUser");
                                        json.put("toUser", member.getCode());
                                        json.remove("first");
                                        try {
                                            json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                        pushMsgTask.sendWeixinMessage(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), p.getName(), json);
                                    }
                                    pushMsgTask.sendWeixinMessage(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), p.getName(), json);
                                }
                            }
                        }

+ 82 - 65
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/booking/PatientBookingController.java

@ -7,11 +7,13 @@ import com.yihu.wlyy.entity.message.SMS;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientReservation;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.imm.ChildImmuneRegisterRecordDao;
import com.yihu.wlyy.repository.message.SMSDao;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.reservation.PatientReservationService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.imm.ChildInfoService;
@ -84,6 +86,8 @@ public class PatientBookingController extends WeixinBaseController{
    private SMSDao smsDao;
    @Autowired
    private ChildImmuneRegisterRecordDao childImmuneRegisterRecordDao;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @RequestMapping(value = "CancelOrder", method = RequestMethod.POST)
@ -118,6 +122,11 @@ public class PatientBookingController extends WeixinBaseController{
//                patientReservationService.patientCancelOrder(orderId,getUID());//"9aa5c557e06a4324911487a035195545"
                //微信消息
                Patient p = patientService.findByCode(obj.getPatient());
                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_appoint_failed","qxgh");
                String remark = templateConfig.getRemark();
                remark = remark.replace("key1",(obj.getName()==null?"":obj.getName())).replace("key2",(obj.getStartTime()==null?"":obj.getStartTime()+""))
                             .replace("br","\n");
                if (StringUtils.isNotEmpty(p.getOpenid())) {
                    JSONObject json = new JSONObject();
                    json.put("first", "");
@ -127,36 +136,28 @@ public class PatientBookingController extends WeixinBaseController{
                    json.put("date", obj.getStartTime());
                    json.put("doctorName", obj.getDoctorName());
                    json.put("orgName", obj.getOrgName());
                    json.put("remark", obj.getName() + ",您好!\n您已取消了" + obj.getStartTime() + "的挂号!");
//                    json.put("remark", obj.getName() + ",您好!\n您已取消了" + obj.getStartTime() + "的挂号!");
                    json.put("remark", remark);
                    //判断是否判定openId,有没有发则查找家人发送
                    if(StringUtils.isNotBlank(p.getOpenid())){
                        // 添加到发送队列
                        pushMsgTask.putWxMsg(getAccessToken(), 7, p.getOpenid(), obj.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");
//                            json.remove("first");
//                            json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//                            PushMsgTask.getInstance().putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), json);
//                        }
//                    }
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                    if(jsonArray!=null&&jsonArray.length()>0){
                        String first = (String) json.get("first");
                        for (int i = 0;i<jsonArray.length();i++){
                            JSONObject j  = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser",member.getCode());
                            data.remove("first");
                            data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName())+first);
                            pushMsgTask.putWxMsg(getAccessToken(), 7, member.getOpenid(), p.getName(), data);
                    }else {
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                        if (jsonArray != null && jsonArray.length() > 0) {
                            String first = (String) json.get("first");
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject j = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                JSONObject data = json;
                                data.remove("toUser");
                                data.put("toUser", member.getCode());
                                data.remove("first");
                                data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
                                pushMsgTask.putWxMsg(getAccessToken(), 7, member.getOpenid(), p.getName(), data);
                            }
                        }
                    }
                }
@ -288,8 +289,15 @@ public class PatientBookingController extends WeixinBaseController{
//            Patient p = patientService.findByCode("e5a46f0264d9492897b1d3789c5b164a");
            String hospitalcode = hospitalMappingDao.getCodeByMapping(OrgCode, "1");
            Hospital hospital = hospitalDao.findByCode(hospitalcode);
    
            String msg = "您成功为"+PatientName+"预约了" + hospital.getName() + "的计划免疫 "+date+" 的号源!";
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_appoint_success","yymycg");
            String remark = templateConfig.getRemark();
            remark = remark.replace("key1",(p.getName()==null?"":p.getName()))
                        .replace("key2",(PatientName==null?"":PatientName))
                        .replace("key3",(hospital.getName()==null?"":hospital.getName()))
                        .replace("key4",(date==null?"":date));
//            String msg = "您成功为"+PatientName+"预约了" + hospital.getName() + "的计划免疫 "+date+" 的号源!";
            // 推送消息给微信端
            org.json.JSONObject json = new org.json.JSONObject();
            json.put("first", "");
@ -301,8 +309,9 @@ public class PatientBookingController extends WeixinBaseController{
            json.put("orgName", "-");
            json.put("doctorName", "-");
            json.put("deptName", "-");
            json.put("remark", p.getName() + ",您好!" + msg);
    
//            json.put("remark", p.getName() + ",您好!" + msg);
            json.put("remark", remark);
            //本地保存计划免疫预约记录
            ChildImmuneRegisterRecord childImmuneRegisterRecord = new ChildImmuneRegisterRecord();
            childImmuneRegisterRecord.setCode(UUID.randomUUID().toString());
@ -328,30 +337,30 @@ public class PatientBookingController extends WeixinBaseController{
            if(org.apache.commons.lang3.StringUtils.isNotBlank(p.getOpenid())){
                // 添加到发送队列
                pushMsgTask.putWxMsg(getAccessToken(), 6, p.getOpenid(), p.getName(), json);
            }
    
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
            if(jsonArray!=null&&jsonArray.length()>0){
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject data = json;
                    data.remove("toUser");
                    data.put("toUser",member.getCode());
                    //String first = (String) json.get("first");
                    data.remove("first");
                    data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName()));
                    pushMsgTask.putWxMsg(getAccessToken(), 6, member.getOpenid(), p.getName(), data);
            }else {
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        //String first = (String) json.get("first");
                        data.remove("first");
                        data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                        pushMsgTask.putWxMsg(getAccessToken(), 6, member.getOpenid(), p.getName(), data);
                    }
                }
            }
    
            //发送短信消息
            //调用总部发送信息的接口
            String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
            String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(remark, p.getMobile()), "GBK");
            JSONObject r = toJson(result);
            SMS sms = new SMS();
            sms.setContent(msg);
            sms.setContent(remark);
            sms.setCaptcha(null);
            Date dateMsg = new Date();
            sms.setDeadline(dateMsg);
@ -414,8 +423,15 @@ public class PatientBookingController extends WeixinBaseController{
            Patient p = patientService.findByCode(getRepUID());
            String hospitalcode = hospitalMappingDao.getCodeByMapping(OrgCode, "1");
            Hospital hospital = hospitalDao.findByCode(hospitalcode);
    
            String msg = "您已取消了为"+PatientName+"预约的" + hospital.getName() + "的计划免疫 "+date+" 的挂号!";
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_appoint_success","qxmyyy");
            String remark = templateConfig.getRemark();
            remark = remark.replace("key1",(p.getName()==null?"":p.getName()))
                    .replace("key2",(PatientName==null?"":PatientName))
                    .replace("key3",(hospital.getName()==null?"":hospital.getName()))
                    .replace("key4",(date==null?"":date));
//            String msg = "您已取消了为"+PatientName+"预约的" + hospital.getName() + "的计划免疫 "+date+" 的挂号!";
            // 推送消息给微信端
            org.json.JSONObject json = new org.json.JSONObject();
            json.put("first", "");
@ -425,8 +441,9 @@ public class PatientBookingController extends WeixinBaseController{
            json.put("date", date);
            json.put("doctorName", "-");
            json.put("orgName", hospital.getName());
            json.put("remark", p.getName() + ",您好!" + msg);
    
//            json.put("remark", p.getName() + ",您好!" + msg);
            json.put("remark", remark);
            //本地保存计划免疫预约记录
            ChildImmuneRegisterRecord childImmuneRegisterRecord = new ChildImmuneRegisterRecord();
            childImmuneRegisterRecord.setCode(UUID.randomUUID().toString());
@ -452,21 +469,21 @@ public class PatientBookingController extends WeixinBaseController{
            if(org.apache.commons.lang3.StringUtils.isNotBlank(p.getOpenid())){
                // 添加到发送队列
                pushMsgTask.putWxMsg(getAccessToken(), 7, p.getOpenid(), p.getName(), json);
            }
    
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
            if(jsonArray!=null&&jsonArray.length()>0){
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject data = json;
                    data.remove("toUser");
                    data.put("toUser",member.getCode());
                    //String first = (String) json.get("first");
                    data.remove("first");
                    data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName()));
                    pushMsgTask.putWxMsg(getAccessToken(), 7, member.getOpenid(), p.getName(), data);
            }else {
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser", member.getCode());
                        //String first = (String) json.get("first");
                        data.remove("first");
                        data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                        pushMsgTask.putWxMsg(getAccessToken(), 7, member.getOpenid(), p.getName(), data);
                    }
                }
            }
    

+ 54 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -49,6 +50,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 患者端:三师咨询控制类
@ -102,6 +104,8 @@ public class ConsultController extends WeixinBaseController {
    private HttpClientUtil httpClientUtil;
    @Autowired
    private MessageService messageService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 患者咨询记录查询
@ -854,7 +858,7 @@ public class ConsultController extends WeixinBaseController {
                    }
                    failed.add(String.valueOf(resObj.get("data")));
                    try {
                        if(messageService.getMessageNoticeSettingByMessageType(consultModel.getDoctor(),"1",MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue())){
                         /*if(messageService.getMessageNoticeSettingByMessageType(consultModel.getDoctor(),"1",MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue())){
                            //            新增发送医生助手模板消息 v1.4.0 by wujunjie
                            Doctor doctor = doctorDao.findByCode(consultModel.getDoctor());
                            String doctorOpenID = doctor.getOpenid();
@ -883,6 +887,55 @@ public class ConsultController extends WeixinBaseController {
                                    httpClientUtil.post(url, params, "UTF-8");
                                }
                            }
                        }*/
                        String sql = "SELECT t.participant_id FROM im_new.participants t where t.session_id = '" +
                                patient.getCode() + "_" + consultModel.getTeam() + "_" + consultModel.getType() +
                                "' and t.participant_role = 0";
                        List<Map<String, Object>> participants = jdbcTemplate.queryForList(sql);
                        for (Map<String, Object> participant : participants) {
//                          //有居民、健管、全科
                            String doctorCode = participant.get("participant_id").toString();
                            if (doctorCode.equals(patient.getCode())) {
                                continue;
                            }
                            //健管
                            Boolean flag = messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue());
                            //全科
//                            Boolean flag2 = !messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.familyTopicSwitch.getValue());
                            if (flag) {
                                //            新增发送医生助手模板消息 v1.4.0 by wujunjie
                                Doctor doctor = doctorDao.findByCode(doctorCode);
                                String doctorOpenID = doctor.getOpenid();
                                if (StringUtils.isNotEmpty(doctorOpenID)) {
                                    String title = "";
                                    Consult consultSingle = consultDao.findByCode(log.getConsult());
                                    if (consultSingle != null) {
                                        Integer singleType = consultSingle.getType();
                                        if (singleType != null && singleType == 8) {
                                            title = consultSingle.getTitle();
                                        } else if (singleType != null && singleType != 8) {
                                            title = consultSingle.getSymptoms();
                                        }
                                        String repContent = parseContentType(type + "", content);
                                        String first = "居民" + patient.getName() + "的健康咨询有新的回复。";
                                        String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
                                        List<NameValuePair> params = new ArrayList<>();
                                        params.add(new BasicNameValuePair("type", "8"));
                                        params.add(new BasicNameValuePair("openId", doctorOpenID));
                                        params.add(new BasicNameValuePair("url", targetUrl));
                                        params.add(new BasicNameValuePair("first", first));
                                        params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
                                        String keywords = title + "," + repContent + "," + doctor.getName();
                                        params.add(new BasicNameValuePair("keywords", keywords));
                                        httpClientUtil.post(url, params, "UTF-8");
                                        System.out.println("发送对象:"+doctorCode);
                                        System.out.println("发送对象名字:"+doctor.getName());
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();

+ 8 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/PatientHealthController.java

@ -265,19 +265,23 @@ public class PatientHealthController extends BaseController {
            Map<String, Object> map = new HashMap<>();
            String patient = getRepUID();
//            String patient = getUID();
            DevicePatientHealthIndex xt = healthIndexService.findLastByPatien(patient, 1);
//            DevicePatientHealthIndex xt = healthIndexService.findLastByPatien(patient, 1);
            DevicePatientHealthIndex xt = healthIndexService.findLastByPatienIot(patient, 1);
            if (xt != null) {
                map.put("xt", xt);
            }
            DevicePatientHealthIndex xy = healthIndexService.findLastByPatien(patient, 2);
//            DevicePatientHealthIndex xy = healthIndexService.findLastByPatien(patient, 2);
            DevicePatientHealthIndex xy = healthIndexService.findLastByPatienIot(patient, 2);
            if (xy != null) {
                map.put("xy", xy);
            }
            DevicePatientHealthIndex tz = healthIndexService.findLastByPatien(patient, 3);
//            DevicePatientHealthIndex tz = healthIndexService.findLastByPatien(patient, 3);
            DevicePatientHealthIndex tz = healthIndexService.findLastByPatienIot(patient, 3);
            if (tz != null) {
                map.put("tz", tz);
            }
            DevicePatientHealthIndex sg = healthIndexService.findLastByPatien(patient, 4);
//            DevicePatientHealthIndex sg = healthIndexService.findLastByPatien(patient, 4);
            DevicePatientHealthIndex sg = healthIndexService.findLastByPatienIot(patient, 4);
            if (sg != null) {
                map.put("sg", sg);
            }

+ 3 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/iot/IotMonitoringHealthController.java

@ -86,6 +86,8 @@ public class IotMonitoringHealthController extends BaseController {
    public String searchPatient(
            @ApiParam(name="name",value="居民姓名")
            @RequestParam(value="name",required = false) String name,
            @ApiParam(name="idcards",value="身份证(多个用逗号间隔)")
            @RequestParam(value="idcards",required = false) String idcards,
            @ApiParam(name="page",value="第几页(默认第一页)",defaultValue = "1")
            @RequestParam(value="page",required = false) Integer page,
            @ApiParam(name="pageSize",value="每页几行(默认10条记录)",defaultValue = "10")
@ -97,7 +99,7 @@ public class IotMonitoringHealthController extends BaseController {
            if(pageSize==null){
                pageSize = 10;
            }
            return write(200,"查询成功","data",patientDeviceService.searchPatient(name,page,pageSize));
            return write(200,"查询成功","data",patientDeviceService.searchPatient(name,page,pageSize,idcards));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/iot/IotDeviceController.java

@ -251,7 +251,7 @@ public class IotDeviceController extends BaseController{
                                                    @ApiParam(name="type",value = "类型")
                                                    @RequestParam(name="type",required = true)Integer type){
        try {
            return write(200,"查询成功","data",iotDeviceService.findByPatientAndType(patientCode,type));
            return write(200,"查询成功","data",iotDeviceService.findByPatientAndType(patientCode,type,5));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());

+ 81 - 85
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/zysoft/BookingController.java

@ -3,8 +3,10 @@ package com.yihu.wlyy.web.third.zysoft;
import com.yihu.wlyy.entity.message.SMS;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientReservation;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.message.SMSDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.app.reservation.PatientReservationService;
import com.yihu.wlyy.service.common.SMSService;
@ -75,6 +77,8 @@ public class BookingController extends WeixinBaseController {
    private HttpClientUtil HttpClientUtil;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    /**
@ -330,7 +334,12 @@ public class BookingController extends WeixinBaseController {
                    consultService.sendMucMessageBySingnType(obj.getDoctor(),obj.getDoctorName(),patient,"我已成功为您预约:" + DateUtil.dateToStrLong(obj.getStartTime()) + "," + hospitalName + hosDeptName + doctorName + "医生的号源。您可直接前往医院就诊</br><a name='guahao' href='javascript:void(0)' data-id='" + obj.getId() + "'>点击查看详情</a>","1",p.getName());
                }
                String msg = "您成功预约了 " + obj.getOrgName() + " " + obj.getDoctorName() + " " + obj.getStartTime() + " 的号源!";
                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_appoint_success","yyghcg");
                String remark = templateConfig.getRemark();
                remark = remark.replace("key1",(p.getName()==null?"":p.getName()))
                        .replace("key2",(obj.getOrgName() + " " + obj.getDoctorName() + " " + obj.getStartTime()));
//                String msg = "您成功预约了 " + obj.getOrgName() + " " + obj.getDoctorName() + " " + obj.getStartTime() + " 的号源!";
                // 推送消息给微信端
                JSONObject json = new JSONObject();
                json.put("first", "");
@ -342,46 +351,35 @@ public class BookingController extends WeixinBaseController {
                json.put("orgName", obj.getOrgName());
                json.put("doctorName", obj.getDoctorName());
                json.put("deptName", obj.getDeptName());
                json.put("remark", p.getName() + ",您好!" + msg);
                json.put("remark",  remark);
                //判断是否判定openId,有没有发则查找家人发送
                if(StringUtils.isNotBlank(p.getOpenid())){
                        // 添加到发送队列
                        pushMsgTask.putWxMsg(getAccessToken(), 6, p.getOpenid(), p.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");
//                        json.remove("first");
//                        json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//                        pushMsgTask.putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), json);
//                    }
//                }
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                if(jsonArray!=null&&jsonArray.length()>0){
                    for (int i = 0;i<jsonArray.length();i++){
                        JSONObject j  = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject data = json;
                        data.remove("toUser");
                        data.put("toUser",member.getCode());
                        //String first = (String) json.get("first");
                        data.remove("first");
                        data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName()));
                        pushMsgTask.putWxMsg(getAccessToken(), 6, member.getOpenid(), p.getName(), data);
                }else {
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                    if (jsonArray != null && jsonArray.length() > 0) {
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject j = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser", member.getCode());
                            //String first = (String) json.get("first");
                            data.remove("first");
                            data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                            pushMsgTask.putWxMsg(getAccessToken(), 6, member.getOpenid(), p.getName(), data);
                        }
                    }
                }
                //发送短信消息
                 //调用总部发送信息的接口
                String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(msg, p.getMobile()), "GBK");
                String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(remark, p.getMobile()), "GBK");
                JSONObject r = toJson(result);
                SMS sms = new SMS();
                sms.setContent(msg);
                sms.setContent(remark);
                sms.setCaptcha(null);
                Date date = new Date();
                sms.setDeadline(date);
@ -441,6 +439,13 @@ public class BookingController extends WeixinBaseController {
                patientReservationService.updateStatus(orderId, 0);
                //微信消息
                Patient p = patientService.findByCode(obj.getPatient());
                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_appoint_failed","qxgh");
                String remark = templateConfig.getRemark();
                remark = remark.replace("key1",(obj.getName()==null?"":obj.getName()))
                            .replace("key2",(obj.getStartTime()==null?"":obj.getStartTime()+""))
                            .replace("br","\n");
                if (StringUtils.isNotEmpty(p.getOpenid())) {
                    JSONObject json = new JSONObject();
                    json.put("first", "");
@ -450,36 +455,28 @@ public class BookingController extends WeixinBaseController {
                    json.put("date", obj.getStartTime());
                    json.put("doctorName", obj.getDoctorName());
                    json.put("orgName", obj.getOrgName());
                    json.put("remark", obj.getName() + ",您好!\n您已取消了" + obj.getStartTime() + "的挂号!");
//                    json.put("remark", obj.getName() + ",您好!\n您已取消了" + obj.getStartTime() + "的挂号!");
                    json.put("remark", remark);
                    //判断是否判定openId,有没有发则查找家人发送
                    if(StringUtils.isNotBlank(p.getOpenid())){
                        // 添加到发送队列
                        pushMsgTask.putWxMsg(getAccessToken(), 7, p.getOpenid(), obj.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");
//                            json.remove("first");
//                            json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//                            pushMsgTask.putWxMsg(getAccessToken(), 7, member.getOpenid(), member.getName(), json);
//                        }
//                    }
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                    if(jsonArray!=null&&jsonArray.length()>0){
                        for (int i = 0;i<jsonArray.length();i++){
                            JSONObject j  = jsonArray.getJSONObject(i);
                            Patient member = (Patient) j.get("member");
                            JSONObject data = json;
                            data.remove("toUser");
                            data.put("toUser",member.getCode());
                            //String first = (String) json.get("first");
                            data.remove("first");
                            data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName()));
                            pushMsgTask.putWxMsg(getAccessToken(), 7, member.getOpenid(), p.getName(), data);
                    }else {
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                        if (jsonArray != null && jsonArray.length() > 0) {
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject j = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                JSONObject data = json;
                                data.remove("toUser");
                                data.put("toUser", member.getCode());
                                //String first = (String) json.get("first");
                                data.remove("first");
                                data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                                pushMsgTask.putWxMsg(getAccessToken(), 7, member.getOpenid(), p.getName(), data);
                            }
                        }
                    }
                }
@ -583,17 +580,25 @@ public class BookingController extends WeixinBaseController {
            if (obj != null) {
                String des = "";
                try {
                    String msg = obj.getDname() + "医生已成功为您预约:" + DateUtil.dateToChinese(obj.getStartTime()) + "," + obj.getOrgName() +
                            obj.getDeptName() + obj.getDoctorName() + "医生的号源。您可直接前往医院就诊。";
                   /* String msg = obj.getDname() + "医生已成功为您预约:" + DateUtil.dateToChinese(obj.getStartTime()) + "," + obj.getOrgName() +
                            obj.getDeptName() + obj.getDoctorName() + "医生的号源。您可直接前往医院就诊。";*/
                    WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_appoint_success","ysyycg");
                    String remark = templateConfig.getRemark();
                    remark = remark.replace("key1",(patientName==null?"":patientName))
                            .replace("key2",(obj.getDname()==null?"":obj.getDname()))
                            .replace("key3",(DateUtil.dateToChinese(obj.getStartTime()) + "," + obj.getOrgName() +
                                    obj.getDeptName() + obj.getDoctorName()))
                            .replace("br","\n");
                    //发送短信消息,调用总部发送信息的接口
                    JSONObject resultJson = smsService.sendMsg(patientPhone,msg);
                    JSONObject resultJson = smsService.sendMsg(patientPhone,remark);
                    if (resultJson != null && resultJson.getInt("result") != 0) {
                        des = "短信提醒失败!(原因:"+resultJson.getString("description")+")";
                    }
                    //保存短信记录
                    SMS sms = new SMS();
                    sms.setContent(msg+des);
                    sms.setContent(remark+des);
                    sms.setCaptcha(null);
                    Date date = new Date();
                    sms.setDeadline(date);
@ -618,40 +623,31 @@ public class BookingController extends WeixinBaseController {
                        json.put("orgCode", obj.getOrgCode());
                        json.put("doctorName", obj.getDeptName());
                        json.put("deptName", obj.getDeptName());
                        json.put("remark", patientName + ",您好!\n" + msg);
//                        json.put("remark", patientName + ",您好!\n" + msg);
                        json.put("remark", remark);
                        //判断是否判定openId,有没有发则查找家人发送
                        if(StringUtils.isNotBlank(p.getOpenid())){
                            // 添加到发送队列
                            pushMsgTask.putWxMsg(getAccessToken(), 6, p.getOpenid(), patientName, 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");
//                                json.remove("first");
//                                json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
//                                pushMsgTask.putWxMsg(getAccessToken(), 6, member.getOpenid(), member.getName(), json);
//                            }
//                        }
                        //发送代理人
                        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
                        if(jsonArray!=null&&jsonArray.length()>0){
                            for (int i = 0;i<jsonArray.length();i++){
                                JSONObject j  = jsonArray.getJSONObject(i);
                                Patient member = (Patient) j.get("member");
                                JSONObject data = json;
                                data.remove("toUser");
                                data.put("toUser",member.getCode());
                                //String first = (String) json.get("first");
                                data.remove("first");
                                data.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),p.getName()));
                                pushMsgTask.putWxMsg(getAccessToken(), 6, member.getOpenid(), p.getName(), data);
                        }else {
                            //发送代理人
                            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                            if (jsonArray != null && jsonArray.length() > 0) {
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    JSONObject j = jsonArray.getJSONObject(i);
                                    Patient member = (Patient) j.get("member");
                                    JSONObject data = json;
                                    data.remove("toUser");
                                    data.put("toUser", member.getCode());
                                    //String first = (String) json.get("first");
                                    data.remove("first");
                                    data.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()));
                                    pushMsgTask.putWxMsg(getAccessToken(), 6, member.getOpenid(), p.getName(), data);
                                }
                            }
                        }
                    }
                    else{
                        des +=" 微信提醒失败,患者无绑定微信!";

+ 1 - 1
patient-co/patient-co-wlyy/src/main/resources/application-test.yml

@ -30,7 +30,7 @@ im:
#物联网配置
iot:
  url: http://172.19.103.88:8088/svr-iot/
  url: http://172.19.103.33:8088/svr-iot/
wechat:
  appId: wx1f129f7b51701428