suqinyi 1 year ago
parent
commit
70d201177b
21 changed files with 4429 additions and 608 deletions
  1. 3 0
      business/base-service/src/main/java/com/yihu/jw/area/dao/BaseCityDao.java
  2. 3 0
      business/base-service/src/main/java/com/yihu/jw/area/dao/BaseProvinceDao.java
  3. 4 0
      business/base-service/src/main/java/com/yihu/jw/area/dao/BaseStreetDao.java
  4. 13 0
      business/base-service/src/main/java/com/yihu/jw/area/dao/BaseTownDao.java
  5. 4 1
      business/base-service/src/main/java/com/yihu/jw/order/dao/ConsultOrderDao.java
  6. 121 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/servicePackage/ServiceItemPlanDO.java
  7. 30 0
      common/common-entity/src/main/java/com/yihu/jw/entity/door/WlyyDoorServiceOrderDO.java
  8. 46 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/common/CommonItemController.java
  9. 272 130
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/controller/ConsultController.java
  10. 1667 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/controller/DoctorConsultController.java
  11. 1 2
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/service/ConsultService.java
  12. 92 83
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/service/ConsultTeamService.java
  13. 100 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/district/controller/DistrictController.java
  14. 249 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/district/service/DistrictService.java
  15. 2 5
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/controller/DoorOrderController.java
  16. 14 7
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/controller/WlyyDoorServiceOrderController.java
  17. 27 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/dao/ServiceItemPlanDao.java
  18. 203 159
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/service/DoorOrderService.java
  19. 464 221
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/service/WlyyDoorServiceOrderService.java
  20. 891 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/message/DoctorMessageController.java
  21. 223 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/utils/CommonUtil.java

+ 3 - 0
business/base-service/src/main/java/com/yihu/jw/area/dao/BaseCityDao.java

@ -31,4 +31,7 @@ public interface BaseCityDao extends JpaRepository<BaseCityDO, Integer>, JpaSpec
    @Query("select a from BaseCityDO a where a.province = ?1 order by id")
    Iterable<BaseCityDO> findByProvince(String province);
    @Query("select p from BaseCityDO p where p.name = ?1")
    BaseCityDO findByName(String name);
}

+ 3 - 0
business/base-service/src/main/java/com/yihu/jw/area/dao/BaseProvinceDao.java

@ -20,4 +20,7 @@ import org.springframework.data.repository.query.Param;
public interface BaseProvinceDao extends JpaRepository<BaseProvinceDO, Integer>, JpaSpecificationExecutor<BaseProvinceDO> {
    @Query("select name from BaseProvinceDO where code =:code")
    String getNameByCode(@Param("code") String code);
    @Query("select p from BaseProvinceDO p where p.name = ?1")
    BaseProvinceDO findByName(String name);
}

+ 4 - 0
business/base-service/src/main/java/com/yihu/jw/area/dao/BaseStreetDao.java

@ -4,6 +4,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.yihu.jw.entity.base.area.BaseStreetDO;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
@ -22,4 +23,7 @@ import java.util.List;
public interface BaseStreetDao extends JpaRepository<BaseStreetDO, Integer>, JpaSpecificationExecutor<BaseStreetDO>  {
    List<BaseStreetDO> findByTown(String town);
    @Query("select p from BaseStreetDO p where p.name = ?1")
    BaseStreetDO findByName(String name);
}

+ 13 - 0
business/base-service/src/main/java/com/yihu/jw/area/dao/BaseTownDao.java

@ -30,4 +30,17 @@ public interface BaseTownDao extends JpaRepository<BaseTownDO, Integer>, JpaSpec
    @Query("select a from BaseTownDO a where a.city = ?1 order by id")
    List<BaseTownDO> findByCityCode(String city);
    @Query("select a from BaseTownDO a where a.city = ?1 order by id")
    Iterable<BaseTownDO> findByCity(String province);
    @Query("select p from BaseTownDO p where p.name = ?1")
    BaseTownDO findByName(String name);
    @Query("select p from BaseTownDO p where p.name = ?1 and p.city = ?2")
    BaseTownDO findByNameAndCity(String name,String city);
}

+ 4 - 1
business/base-service/src/main/java/com/yihu/jw/order/dao/ConsultOrderDao.java

@ -11,7 +11,8 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 * @author huangwenjie
 */
public interface ConsultOrderDao extends JpaRepository<ConsultDo, String>, JpaSpecificationExecutor<ConsultDo> {
	
//	@Query("from ConsultDo a where a.relationCode = ?1")
//	ConsultDo findByRelationCode(String outpatientid);
@ -28,4 +29,6 @@ public interface ConsultOrderDao extends JpaRepository<ConsultDo, String>, JpaSp
//	// 查询患者咨询记录
//	@Query("select a.id,a.type,a.code,a.title,a.symptoms,a.czrq,b.status,b.doctor,b.team,b.evaluate,a.signCode  from ConsultDo a,ConsultTeamDo b where a.code = b.consult and a.patient = ?1 and a.del = '1' and a.type<>8 order by a.czrq desc")
//	Page<Object> findByPatient(String patient, Pageable pageRequest);
    ConsultDo queryByIdAndType(String id,Integer type);
}

+ 121 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/servicePackage/ServiceItemPlanDO.java

@ -0,0 +1,121 @@
package com.yihu.jw.entity.base.servicePackage;
import com.yihu.jw.entity.UuidIdentityEntityWithCreateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * 服务项执行计划
 * Created by yeshijie on 2023/10/28.
 */
@Entity
@Table(name = "base_service_item_plan")
public class ServiceItemPlanDO extends UuidIdentityEntityWithCreateTime {
    private String patient;//居民id
    private String status;//状态0未完成 1已完成
    private String planTime;//计划时间
    private String completeTime;//完成时间
    private String signId;//签约id
    private String servicePackId;//服务包id
    private String serviceItemId;//服务项id
    private String itemConfigId;//服务项配置id
    private String name;//服务项名称
    private String relationCode;//关联业务id
    private String relationType;//关联业务类型 doorService上门服务
    @Column(name = "patient")
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name = "status")
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    @Column(name = "sign_id")
    public String getSignId() {
        return signId;
    }
    public void setSignId(String signId) {
        this.signId = signId;
    }
    @Column(name = "service_pack_id")
    public String getServicePackId() {
        return servicePackId;
    }
    public void setServicePackId(String servicePackId) {
        this.servicePackId = servicePackId;
    }
    @Column(name = "service_item_id")
    public String getServiceItemId() {
        return serviceItemId;
    }
    public void setServiceItemId(String serviceItemId) {
        this.serviceItemId = serviceItemId;
    }
    @Column(name = "item_config_id")
    public String getItemConfigId() {
        return itemConfigId;
    }
    public void setItemConfigId(String itemConfigId) {
        this.itemConfigId = itemConfigId;
    }
    @Column(name = "name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Column(name = "relation_code")
    public String getRelationCode() {
        return relationCode;
    }
    public void setRelationCode(String relationCode) {
        this.relationCode = relationCode;
    }
    @Column(name = "relation_type")
    public String getRelationType() {
        return relationType;
    }
    public void setRelationType(String relationType) {
        this.relationType = relationType;
    }
    public String getPlanTime() {
        return planTime;
    }
    @Column(name = "plan_time")
    public void setPlanTime(String planTime) {
        this.planTime = planTime;
    }
    public String getCompleteTime() {
        return completeTime;
    }
    @Column(name = "complete_time")
    public void setCompleteTime(String completeTime) {
        this.completeTime = completeTime;
    }
}

+ 30 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/door/WlyyDoorServiceOrderDO.java

@ -214,6 +214,12 @@ public class WlyyDoorServiceOrderDO extends UuidIdentityEntityWithOperator {
    }
    private String packageId;//服务包的id
    private String feeAfter;//服务后收费标识(1是0否)
    private String signId;//签约id
    /**
     * 服务编号
     */
@ -1259,4 +1265,28 @@ public class WlyyDoorServiceOrderDO extends UuidIdentityEntityWithOperator {
    public void setNursingStaffType(String nursingStaffType) {
        this.nursingStaffType = nursingStaffType;
    }
    public String getPackageId() {
        return packageId;
    }
    public void setPackageId(String packageId) {
        this.packageId = packageId;
    }
    public String getFeeAfter() {
        return feeAfter;
    }
    public void setFeeAfter(String feeAfter) {
        this.feeAfter = feeAfter;
    }
    public String getSignId() {
        return signId;
    }
    public void setSignId(String signId) {
        this.signId = signId;
    }
}

+ 46 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/common/CommonItemController.java

@ -0,0 +1,46 @@
package com.yihu.jw.hospital.module.common;
import com.yihu.jw.hospital.module.door.service.DoorOrderService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by yeshijie on 2023/11/3.
 */
@RestController
@RequestMapping(value = "/common/item", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "通用项目接口")
public class CommonItemController extends EnvelopRestEndpoint {
    @Autowired
    private DoorOrderService doorOrderService;
    @ApiOperation("查询字典-通用字典接口")
    @GetMapping(value= "getServiceItem")
    public Envelop getServiceItem(@ApiParam(name = "name", value = "name", required = false)
                               @RequestParam(value = "name", required = false)String name,
                                  @ApiParam(name = "signId", value = "signId", required = true)
                               @RequestParam(value = "signId", required = true)String signId,
                                  @ApiParam(name = "type", value = "type", required = true)
                               @RequestParam(value = "type", required = true)String type,
                                  @ApiParam(name = "page", value = "page", required = true)
                               @RequestParam(value = "page", required = true) Integer page,
                                  @ApiParam(name = "size", value = "pageSize", required = true)
                               @RequestParam(value = "size", required = true)Integer size){
        try {
            return doorOrderService.getServiceItem(signId,name,type,page,size);
        }catch (Exception e){
            e.printStackTrace();
            return Envelop.getError("查询是吧",-1);
        }
    }
}

+ 272 - 130
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/controller/ConsultController.java

@ -1,6 +1,7 @@
package com.yihu.jw.hospital.module.consult.controller;
import com.alibaba.fastjson.JSON;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
@ -9,18 +10,23 @@ import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.im.ConsultTeamLogDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.message.MessageNoticeSetting;
import com.yihu.jw.entity.util.SystemConfEntity;
import com.yihu.jw.hospital.module.consult.service.ConsultTeamService;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.HttpUtil;
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.dao.ConsultTeamDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.im.util.ImageCompress;
import com.yihu.jw.message.service.MessageService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.util.common.CommonUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -38,9 +44,14 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
/**
 * 患者端:三师咨询控制类
@ -52,12 +63,13 @@ import java.util.Map;
@Api(description = "患者端-患者咨询")
public class ConsultController extends EnvelopRestEndpoint {
    @Autowired
    protected HttpServletRequest request;
    @Autowired
    private ConsultTeamService consultTeamService;
    //    @Autowired
//    private DoctorCommentService doctorCommentService;
//    @Autowired
//    private DoctorStatisticsService doctorStatisticsService;
    @Autowired
    private BaseDoctorInfoService doctorService;
@ -68,40 +80,53 @@ public class ConsultController extends EnvelopRestEndpoint {
    private BaseDoctorDao doctorDao;
    @Autowired
    private CommonUtil CommonUtil;
    private com.yihu.jw.util.common.CommonUtil CommonUtil;
    @Autowired
    private ImUtil imUtill;
    @Autowired
    private HttpUtil httpUtil;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private ConsultTeamDao consultTeamDao;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private ConsultDao consultDao;
    @Value("${doctorAssistant.api}")
    private String doctorAssistant;
    @Value("${doctorAssistant.target_url}")
    private String targetUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private MessageService messageService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private ConsultDao consultDao;
    @Autowired
    WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Value("${im.data_base_name}")
    private String im;
    @Value("${spring.profiles}")
    private String springProfile;
//    //    @Value("${doctorAssistant.api}")
//    private String doctorAssistant;
//
//    //    @Value("${doctorAssistant.target_url}")
//    private String targetUrl;
    @Autowired
    private RedisTemplate redisTemplate;
//    @Value("${spring.profiles}")
//    private String springProfile;
//    @Autowired
//    private RedisTemplate redisTemplate;
//    @Autowired
//    private PushMsgTask pushMsgTask;
//    @Autowired
//    private PrescriptionDao prescriptionDao;
//    @Autowired
//    private DoctorCommentService doctorCommentService;
//    @Autowired
//    private DoctorStatisticsService doctorStatisticsService;
//    @Autowired
//    private DoctorWorkTimeService doctorWorkTimeService;
//    @Autowired
@ -113,6 +138,7 @@ public class ConsultController extends EnvelopRestEndpoint {
//    @Autowired
//    private WlyyDynamicMessagesDao dynamicMessagesDao;
//    @ApiOperation("testRedis")
//    @RequestMapping(value = "testRedis",method = RequestMethod.POST)
//    public String testRedis(){
@ -1009,18 +1035,6 @@ public class ConsultController extends EnvelopRestEndpoint {
                log.setType(type);
                logs.add(log);
            } else if (type == 2) {
                if (!"laprod".equals(springProfile)) {
                    // 图片消息 -获取微信服务器图片
//                    content = fetchWxImages();
                    String path = null;//这边后面在搬
                    // 将临时图片拷贝到正式存储路径下
                    if (StringUtils.isNotEmpty(content)) {
                        content = CommonUtil.copyTempImage(content);
                    }
                    if (StringUtils.isEmpty(content)) {
                        return error(-1, "图片上传失败!");
                    }
                }
                String[] images = content.split(",");
                for (String image : images) {
                    ConsultTeamLogDo log = new ConsultTeamLogDo();
@ -1045,7 +1059,9 @@ public class ConsultController extends EnvelopRestEndpoint {
            BasePatientDO patient = patientDao.findById(getRepUID()).orElse(null);
            int i = 0;
            List<String> failed = new ArrayList<>();
            //这边还要看能不能获取到
            System.out.println("getUID():" + getUID());
            System.out.println("getRepUID():" + getRepUID());
            String agent = getUID() == getRepUID() ? null : getUID();
            for (ConsultTeamLogDo log : logs) {
                String response = imUtill.sendTopicIM(getRepUID(), patient.getName(), consult, String.valueOf(log.getType()), log.getContent(), agent);
@ -1092,38 +1108,38 @@ public class ConsultController extends EnvelopRestEndpoint {
                            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
                                BaseDoctorDO doctor = doctorDao.findById(doctorCode).orElse(null);
                                String doctorOpenID = doctor.getOpenid();
                                if (StringUtils.isNotEmpty(doctorOpenID)) {
                                    String title = "";
                                    ConsultDo 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());
                                    }
                                }
                            }
//                            if (flag) {
//                                //            新增发送医生助手模板消息 v1.4.0 by wujunjie
//                                BaseDoctorDO doctor = doctorDao.findById(doctorCode).orElse(null);
//                                String doctorOpenID = doctor.getOpenid();
//                                if (StringUtils.isNotEmpty(doctorOpenID)) {
//                                    String title = "";
//                                    ConsultDo consultSingle = consultDao.findById(log.getConsult()).orElse(null);
//                                    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();
@ -1176,27 +1192,31 @@ public class ConsultController extends EnvelopRestEndpoint {
     * @param pagesize 每页显示数,默认为10
     * @return
     */
//    @RequestMapping(value = "loglist")
//    @ApiOperation("网络咨询咨询日志查询")
//    public String loglist(@RequestParam String consult, @RequestParam int page, @RequestParam int pagesize) {
//        try {
//            ConsultTeamDo consultModel = consultTeamService.findByCode(consult);
//            if (consultModel == null) {
//                return error(-1, "咨询记录不存在!");
//            }
//            JSONObject messageObj = imUtill.getTopicMessage(consultModel.getConsult(), consultModel.getStartMsgId(), consultModel.getEndMsgId(), page, pagesize, getRepUID());
//
//            //过滤续签
    @RequestMapping(value = "loglist")
    @ApiOperation("网络咨询咨询日志查询")
    public String loglist(
            @RequestParam String consult,
            @RequestParam String loginUser,
            @RequestParam int page, @RequestParam int pagesize) {
        try {
            System.out.println("查询聊天日志");
            System.out.println("参数==>consult:" + consult + "  loginUser:" + loginUser);
            ConsultTeamDo consultModel = consultTeamService.findByCode(consult);
            System.out.println("ConsultTeamDo==>" + JSON.toJSONString(consultModel));
            if (consultModel == null) {
                return error(-1, "咨询记录不存在!");
            }
            System.out.println("调用im查询");
            com.alibaba.fastjson.JSONObject messageObj = imUtill.getTopicMessage(consultModel.getConsult(), consultModel.getStartMsgId(), consultModel.getEndMsgId(), page, pagesize, loginUser);
            System.out.println("查询完成");
            //过滤续签
//            consultTeamService.removeRenewPerson(messageObj, getRepUID());
//
//            return write(200, "查询成功", "list", messageObj);
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            error(e);
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
            return write(200, "查询成功", "list", messageObj);
        } catch (Exception e) {
            error(e);
            return "查询失败!";
        }
    }
    /**
     * 网络咨询咨询日志查询
@ -1301,11 +1321,10 @@ public class ConsultController extends EnvelopRestEndpoint {
    /**
     * 三师咨询评论
     *
     * @param consult 咨询标识
     * @param content 评价内容
     * @param star    星级
     * @return 操作结果
     * consult 咨询标识
     * content 评价内容
     * star    星级
     * 操作结果
     */
//    @RequestMapping(value = "comment")
//    @ApiOperation("三师咨询评论")
@ -1336,18 +1355,14 @@ public class ConsultController extends EnvelopRestEndpoint {
//        }
//
//    }
//    @RequestMapping(value = "getTopic")
//    public String getTopic(String consult) {
//        try {
//            return success(imUtill.getTopic(consult).get("data").toString());
//        } catch (ServiceException se) {
//            return error(-1, se.getMessage());
//        } catch (Exception e) {
//            error(e);
//            return error(-1, e.getMessage());
//        }
//    }
    @RequestMapping(value = "getTopic")
    public Envelop getTopic(String consult) {
        try {
            return success(imUtill.getTopic(consult).get("data").toString());
        } catch (Exception e) {
            return failed(e.getMessage());
        }
    }
//    @RequestMapping(value = "getConsult")
//    public String getConsult(String consult) {
@ -1716,30 +1731,32 @@ public class ConsultController extends EnvelopRestEndpoint {
//    }
//    @RequestMapping(value = "queryByRelationCode", method = RequestMethod.GET)
//    @ApiOperation("根据关联业务code查询咨询记录")
//    public String queryByRelationCode(@ApiParam(name = "code", value = "咨询关联业务code") @RequestParam(value = "code", required = true) String code) {
//        try {
//            ConsultTeam consultTeam = consultTeamService.queryByRelationCode(code);
//            return write(200, "提交成功", "data", consultTeam);
//        } catch (Exception e) {
//            error(e);
//            return error(-1, "添加失败");
//        }
//    }
    @RequestMapping(value = "queryByRelationCode", method = RequestMethod.GET)
    @ApiOperation("根据关联业务code查询咨询记录")
    public String queryByRelationCode(
            @ApiParam(name = "code", value = "咨询关联业务code") @RequestParam(value = "code", required = true) String code
    ) {
        try {
            ConsultTeamDo consultTeam = consultTeamService.queryByRelationCode(code);
            return write(200, "提交成功", "data", consultTeam);
        } catch (Exception e) {
            error(e);
            return error(-1, "添加失败");
        }
    }
//    @RequestMapping(value = "queryByConsultCode", method = RequestMethod.GET)
//    @ApiOperation("根据咨询code查询关联业务项详情")
//    public String queryByConsultCode(@ApiParam(name = "code", value = "咨询code") @RequestParam(value = "code", required = true) String code,
//                                     @ApiParam(name = "type", value = "咨询类型") @RequestParam(value = "type", required = true) Integer type) {
//        try {
//            com.alibaba.fastjson.JSONObject detail = consultTeamService.queryByConsultCode(code, type);
//            return write(200, "查询成功", "data", detail.get("data"));
//        } catch (Exception e) {
//            error(e);
//            return error(-1, "查询失败");
//        }
//    }
    @RequestMapping(value = "queryByConsultCode", method = RequestMethod.GET)
    @ApiOperation("根据咨询code查询关联业务项详情")
    public String queryByConsultCode(@ApiParam(name = "code", value = "咨询code") @RequestParam(value = "code", required = true) String code,
                                     @ApiParam(name = "type", value = "咨询类型") @RequestParam(value = "type", required = true) Integer type) {
        try {
            com.alibaba.fastjson.JSONObject detail = consultTeamService.queryByConsultCode(code, type);
            return write(200, "查询成功", "data", detail.get("data"));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "updateMsg", method = RequestMethod.POST)
    @ApiOperation("修改会话消息内容")
@ -1853,4 +1870,129 @@ public class ConsultController extends EnvelopRestEndpoint {
        }
    }
    /**
     * 获取微信服务器图片
     *
     * @return
     */
    public String fetchWxImages() {
        String photos = "";
        try {
            String images = request.getParameter("mediaIds");
            if (StringUtils.isEmpty(images)) {
                return photos;
            }
            String[] mediaIds = images.split(",");
            for (String mediaId : mediaIds) {
                if (StringUtils.isEmpty(mediaId)) {
                    continue;
                }
                String temp = saveImageToDisk(mediaId);
                if (StringUtils.isNotEmpty(temp)) {
                    if (photos.length() == 0) {
                        photos = temp;
                    } else {
                        photos += "," + temp;
                    }
                }
            }
        } catch (Exception e) {
            error(e);
        }
        return photos;
    }
    /**
     * 获取下载图片信息(jpg)
     *
     * @param mediaId 文件的id
     * @throws Exception
     */
    public String saveImageToDisk(String mediaId) throws Exception {
        // 文件保存的临时路径
        String tempPath = SystemConfEntity.getInstance().getTempPath() + File.separator;
        // 拼接年月日路径
        String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
        // 重命名文件
        String newFileName = DateUtil.dateToStr(new Date(), DateUtil.YYYYMMDDHHMMSS) + "_" + new Random().nextInt(1000) + ".png";
        // 保存路径
        File uploadFile = new File(tempPath + datePath + newFileName);
        InputStream inputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            if (!uploadFile.getParentFile().exists()) {
                uploadFile.getParentFile().mkdirs();
            }
            inputStream = getInputStream(mediaId);
            byte[] data = new byte[1024];
            int len = 0;
            fileOutputStream = new FileOutputStream(uploadFile);
            while ((len = inputStream.read(data)) != -1) {
                fileOutputStream.write(data, 0, len);
            }
            // 生成缩略图
            ImageCompress.compress(uploadFile.getAbsolutePath(), uploadFile.getAbsolutePath() + "_small", 300, 300);
            // 返回保存路径
            return datePath + newFileName;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    /**
     * 下载多媒体文件(请注意,视频文件不支持下载,调用该接口需http协议)
     *
     * @return
     */
    public InputStream getInputStream(String mediaId) {
        String accessToken = getAccessToken();
        InputStream is = null;
        String url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=" + accessToken + "&media_id=" + mediaId;
        try {
            URL urlGet = new URL(url);
            HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
            http.setRequestMethod("GET"); // 必须是get方式请求
            http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            http.setDoOutput(true);
            http.setDoInput(true);
            System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
            System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
            http.connect();
            // 获取文件转化为byte流
            is = http.getInputStream();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return is;
    }
    /**
     * 获取微信的access_token
     *
     * @return
     */
    public String getAccessToken() {
        return weiXinAccessTokenUtils.getAccessToken();
    }
}

+ 1667 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/controller/DoctorConsultController.java

@ -0,0 +1,1667 @@
package com.yihu.jw.hospital.module.consult.controller;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.hospital.message.service.SystemMessageService;
import com.yihu.jw.hospital.module.consult.service.ConsultTeamService;
import com.yihu.jw.hospital.module.followup.service.FollowUpService;
import com.yihu.jw.hospital.module.wx.dao.WechatTemplateConfigDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.DoctorAssistantUtil;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.util.common.CommonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * 医生端:三师咨询控制类
 *
 * @author George
 */
@RestController
@RequestMapping(value = "/doctor/consult", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "三师咨询")
public class DoctorConsultController extends EnvelopRestEndpoint {
//    @Value("${doctorAssistant.api}")
    private String doctorAssistant;
//    @Value("${doctorAssistant.target_url}")
    private String targetUrl;
    @Autowired
    private ConsultTeamService consultTeamService;
    @Autowired
    private BasePatientService patientService;
    @Autowired
    private BaseDoctorInfoService doctorInfoService;
    @Autowired
    private com.yihu.jw.util.common.CommonUtil CommonUtil;
    @Autowired
    private ImUtil imUtill;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private ConsultDao consultDao;
    @Autowired
    private FollowUpService followUpService;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private SystemMessageService messageService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private DoctorAssistantUtil doctorAssistantUtil;
    //    @Autowired
//    private DoctorHelpDao doctorHelpDao;
//    @Autowired
//    private HospitalInviteSpecialistDao inviteSpecialistDao;
//    @Autowired
//    private PrescriptionDiagnosisService prescriptionDiagnosisService;
//    @Autowired
//    private DoctorWorkTimeService doctorWorkTimeService;
//    @Autowired
//    private TalkGroupService talkGroupService;
//    @Autowired
//    private HttpClientUtil httpClientUtil;
    @RequestMapping(value = "queryByConsultCode", method = RequestMethod.GET)
    @ApiOperation("根据咨询code查询关联业务项详情")
    public String queryByConsultCode(@ApiParam(name = "code", value = "咨询code") @RequestParam(value = "code", required = true) String code,
                                     @ApiParam(name = "type", value = "咨询类型") @RequestParam(value = "type", required = true) Integer type) {
        try {
            com.alibaba.fastjson.JSONObject detail = consultTeamService.queryByConsultCode(code, type);
            return write(200, "查询成功", "data", detail.get("data"));
        } catch (Exception e) {
            return e.getMessage();
        }
    }
    @ApiOperation("咨询是否结束")
    @RequestMapping(value = "/getConsultStatus", method = RequestMethod.GET)
    public String getConsultStatus(@RequestParam(required = true) String consult) {
        try {
            ConsultTeamDo consultTeam = consultTeamService.findByConsultCode(consult);
            return write(200, "查询成功", "data", consultTeam.getStatus());
        } catch (Exception e) {
            return e.getMessage();
        }
    }
    @ApiOperation("咨询是否结束")
    @RequestMapping(value = "/getConsultStatusByPrescription", method = RequestMethod.GET)
    public String getConsultStatusByPrescription(@ApiParam(name = "prescriptionCode", value = "续方code")
                                                 @RequestParam(value = "prescriptionCode", required = true) String prescriptionCode) {
        try {
            ConsultTeamDo consultTeam = consultTeamService.getConsultStatus(prescriptionCode);
            if (consultTeam != null) {
                return write(200, "查询成功", "data", consultTeam.getStatus());
            } else {
                return error(-1, "咨询不存在");
            }
        } catch (Exception e) {
            return e.getMessage();
        }
    }
//
//    /**
//     * 设置消息已读
//     *
//     * @param consult
//     * @return
//     */
//    @ApiOperation("设置消息已读")
//    @RequestMapping(value = "/readed", method = RequestMethod.POST)
//    public String readMessage(String consult) {
//        try {
//            int result = consultTeamService.readMessage(consult);
//            return write(200, "设置成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//
//    @ApiOperation("医生发送topic消息")
//    @RequestMapping(value = "sendTopicIM", method = RequestMethod.POST)
//    public String sendTopicIM(@ApiParam(name = "consult", value = "咨询code")
//                              @RequestParam(value = "consult", required = true) String consult,
//                              @ApiParam(name = "sender_id", value = "发送者id")
//                              @RequestParam(value = "sender_id", required = true) String sender_id,
//                              @ApiParam(name = "sender_name", value = "发送者姓名")
//                              @RequestParam(value = "sender_name", required = true) String sender_name,
//                              @ApiParam(name = "content_type", value = "消息类型")
//                              @RequestParam(value = "content_type", required = true) String content_type,
//                              @ApiParam(name = "content", value = "消息内容")
//                              @RequestParam(value = "content", required = true) String content,
//                              @ApiParam(name = "sessionId", value = "会话id")
//                              @RequestParam(value = "sessionId", required = true) String sessionId) {
//        try {
//            imUtill.sendTopicIM(sender_id, sender_name, consult, content_type, content, null);
//            return success("发送成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return error(-1, "发送失败");
//    }
//
//    @ApiOperation("医生发送会话消息")
//    @RequestMapping(value = "sendImMsg", method = RequestMethod.POST)
//    public String sendImMsg(@ApiParam(name = "consult", value = "咨询code")
//                            @RequestParam(value = "consult", required = false) String consult,
//                            @ApiParam(name = "sender_id", value = "发送者id")
//                            @RequestParam(value = "sender_id", required = true) String sender_id,
//                            @ApiParam(name = "sender_name", value = "发送者姓名")
//                            @RequestParam(value = "sender_name", required = true) String sender_name,
//                            @ApiParam(name = "content_type", value = "消息类型")
//                            @RequestParam(value = "content_type", required = true) String content_type,
//                            @ApiParam(name = "business_type", value = "会话业务类型")
//                            @RequestParam(value = "business_type", required = true) String business_type,
//                            @ApiParam(name = "content", value = "消息内容")
//                            @RequestParam(value = "content", required = true) String content,
//                            @ApiParam(name = "sessionId", value = "会话id")
//                            @RequestParam(value = "sessionId", required = true) String sessionId) {
//        try {
//            imUtill.sendImMsg(sender_id, sender_name, sessionId, content_type, content_type, business_type);
//            return success("发送成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return error(-1, "发送失败");
//    }
//
//    @ApiOperation("医生主动发送im消息")
//    @RequestMapping(value = "doctorSendImMsg", method = RequestMethod.POST)
//    public String doctorSendImMsg(@ApiParam(name = "patient", value = "居民code")
//                                  @RequestParam(value = "patient", required = true) String patient,
//                                  @ApiParam(name = "doctor", value = "医生code")
//                                  @RequestParam(value = "doctor", required = true) String doctor,
//                                  @ApiParam(name = "doctorName", value = "医生姓名")
//                                  @RequestParam(value = "doctorName", required = true) String doctorName,
//                                  @ApiParam(name = "sessionId", value = "会话id")
//                                  @RequestParam(value = "sessionId", required = true) String sessionId,
//                                  @ApiParam(name = "content", value = "消息内容")
//                                  @RequestParam(value = "content", required = true) String content,
//                                  @ApiParam(name = "contentType", value = "消息类型")
//                                  @RequestParam(value = "contentType", required = true) String contentType) {
//        try {
//            consultTeamService.doctorSendImMsg(patient, doctor, doctorName, sessionId, content, contentType);
//            return success("发送成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return error(-1, "发送失败");
//        }
//    }
//
//    @ApiOperation("医生拒绝视频")
//    @RequestMapping(value = "refuseVideo", method = RequestMethod.POST)
//    public String refuseVideo(@ApiParam(name = "consult", value = "咨询code")
//                              @RequestParam(value = "consult", required = true) String consult,
//                              @ApiParam(name = "doctor", value = "医生code")
//                              @RequestParam(value = "doctor", required = true) String doctor) {
//        try {
//            Doctor d = doctorDao.findByCode(doctor);
//            d.setVideoStauts(0);
//            doctorDao.save(d);
//            imUtill.sendTopicIM(doctor, d.getName(), consult, "43", "医生在忙,建议提现预约视频通讯", null);
//            return success("拒绝成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//
//    }
//
//    @ApiOperation("医生接通视频")
//    @RequestMapping(value = "connectVideo", method = RequestMethod.POST)
//    public String connectVideo() {
//        try {
//            Doctor doctor = doctorDao.findByCode(getUID());
//            doctor.setVideoStauts(1);
//            doctorDao.save(doctor);
//            return success("接通成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//
//    }
//
//    @ApiOperation("医生挂断视频")
//    @RequestMapping(value = "handUpVideo", method = RequestMethod.POST)
//    public String handUpVideo(@ApiParam(name = "consult", value = "咨询code")
//                              @RequestParam(value = "consult", required = true) String consult,
//                              @ApiParam(name = "time", value = "视频接通时长")
//                              @RequestParam(value = "time", required = true) String time) {
//        try {
//            Doctor doctor = doctorDao.findByCode(getUID());
//            doctor.setVideoStauts(0);
//            doctorDao.save(doctor);
//            imUtill.sendTopicIM(doctor.getCode(), doctor.getName(), consult, "41", time, null);
//            return success("挂断成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//
//    }
//
//    /**
//     * 三师咨询列表查询
//     *
//     * @param type     咨询类型:0、全部,1、咨询我的,2、公共的, 3、参与过的,4、已结束的  5 名医咨询 全部
//     *                 6 名医咨询 进行中 7 名医咨询 已结束 8名医咨询 待处理 9咨询我的三师 + 家庭 + 名医   10查询我咨询的
//     * @param id
//     * @param pagesize 每页显示数,默认为10
//     * @return
//     */
//    @ApiOperation("三师咨询列表查询")
//    @RequestMapping(value = "list", method = RequestMethod.POST)
//    public String list(int type,
//                       int id,
//                       int pagesize,
//                       @RequestParam(required = false) String patient,
//                       @RequestParam(required = false) String title) {
//        try {
//            Page<ConsultTeamDo> list = consultTeamService.findByDoctor(getUID(), type, id, pagesize, patient, title);
//            JSONArray jsonArray = new JSONArray();
//            if (list != null) {
//                for (ConsultTeamDo consult : list) {
//                    if (consult == null) {
//                        continue;
//                    }
//
//                    if (StringUtils.isNotBlank(patient) && !StringUtils.equals(patient, consult.getPatient())) {
//                        continue;
//                    }
//
//                    JSONObject json = new JSONObject();
//                    json.put("id", consult.getId());
//                    // 设置咨询标识
//                    json.put("consult", consult.getConsult());
//                    // 设置患者标识
//                    json.put("patient", consult.getPatient());
//                    // 设置患者姓名
//                    json.put("name", consult.getName());
//                    // 设置醫生标识
//                    json.put("doctor", consult.getDoctor());
//                    Doctor doctor = doctorService.findDoctorByCode(consult.getDoctor());
//                    // 设置醫生标识
//                    json.put("doctorName", doctor.getName());
//                    // 设置医生photo
//                    json.put("doctorPhoto", doctor.getPhoto());
//                    // 设置医生sex
//                    json.put("doctorSex", doctor.getSex());
//                    if (consult.getType() == 7) {
//                        Doctor d = doctorInfoService.findDoctorByCode(consult.getPatient());
//                        // 设置患者头像
//                        json.put("photo", d.getPhoto());
//                        // 设置患者年龄
//                        json.put("age", IdCardUtil.getAgeForIdcard(d.getIdcard()));
//                        // 设置性别
//                        json.put("sex", d.getSex());
//                    } else {
//                        Patient p = patientService.findByCode(consult.getPatient());
//                        // 设置患者头像
//                        json.put("photo", p.getPhoto());
//                        // 设置患者年龄
//                        json.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(), p.getBirthday()));
//                        // 设置性别
//                        json.put("sex", p.getSex());
//                    }
//                    // 设置咨询标识
//                    json.put("title", consult.getSymptoms());
//                    // 设置评价内容
//                    json.put("comment", consult.getCommentContent());
//                    // 设置评价星级
//                    json.put("star", consult.getCommentStar());
//                    // 设置咨询类型:1三师咨询,2家庭医生咨询 6名医咨询
//                    json.put("type", consult.getType());
//                    // 设置咨询时间
//                    json.put("time", DateUtil.dateToStr(consult.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
//                    // 咨询状态
//                    json.put("status", consult.getStatus());
//                    // 未读消息
//                    json.put("doctorRead", consult.getDoctorRead());
//                    // 设置关联指导
//                    json.put("guidance", consult.getGuidance());
//                    json.put("startId", consult.getStartMsgId());
//                    json.put("endId", consult.getEndMsgId());
//                    List<WlyyTalkGroup> wlyyTalkGroups = talkGroupService.findAllConsultTalkGroup(consult.getConsult());
//                    if (wlyyTalkGroups != null && wlyyTalkGroups.size() > 0) {
//                        for (WlyyTalkGroup wlyyTalkGroup : wlyyTalkGroups) {
//                            json.put("group" + wlyyTalkGroup.getType(), wlyyTalkGroup.getCode());
//                            json.put("groupName" + wlyyTalkGroup.getType(), wlyyTalkGroup.getName());
//                        }
//                    }
//                    jsonArray.put(json);
//                }
//            }
//            return write(200, "查询成功", "list", list, jsonArray);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//
//    @RequestMapping(value = "list_by_team", method = RequestMethod.POST)
//    @ApiOperation(value = "居民咨询列表查询")
//    public String listByTeam(@RequestParam @ApiParam(value = "居民Code") String patient,
//                             @RequestParam @ApiParam(value = "团队Code") Long teamCode,
//                             @RequestParam @ApiParam(value = "第几页") int page,
//                             @RequestParam @ApiParam(value = "页大小") int pagesize) {
//        try {
//            if (StringUtils.isEmpty(patient)) {
//                return error(-1, "请输入需查询的居民");
//            }
//            if (teamCode == null || teamCode < 1) {
//                return error(-1, "请输入需查询的居民的团队");
//            }
//            page = page > 0 ? page - 1 : 0;
//            JSONArray jsonArray = consultTeamService.findByPatientAndTeam(patient, teamCode, page, pagesize);
//            return write(200, "查询成功", "data", jsonArray);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    /**
//     * 获取三师家庭咨询
//     *
//     * @param status   0未处理或未回复 1已回复 2已结束
//     * @param id
//     * @param pagesize
//     * @param patient
//     * @return
//     */
//    @ApiOperation("获取三师家庭咨询")
//    @RequestMapping(value = "/list_by_status", method = RequestMethod.POST)
//    public String listByStatus(int status, int id, int pagesize,
//                               @RequestParam(required = false) String patient) {
//        try {
//            Page<ConsultTeamDo> list = consultTeamService.findConsultByDoctor(getUID(), status, id, pagesize);
//            JSONArray jsonArray = new JSONArray();
//            for (ConsultTeamDo consult : list) {
//                if (consult == null) {
//                    continue;
//                }
//
//                if (StringUtils.isNotBlank(patient) && !StringUtils.equals(patient, consult.getPatient())) {
//                    continue;
//                }
//
//                Patient p = patientService.findByCode(consult.getPatient());
//
//                JSONObject json = new JSONObject();
//                json.put("id", consult.getId());
//                // 设置咨询标识
//                json.put("consult", consult.getConsult());
//                // 设置患者标识
//                json.put("patient", consult.getPatient());
//                // 设置患者头像
//                json.put("photo", p.getPhoto());
//                // 设置咨询标识
//                json.put("title", consult.getSymptoms());
//                // 设置患者姓名
//                json.put("name", consult.getName());
//                // 设置患者年龄
//                json.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(), p.getBirthday()));
//                // 设置评价内容
//                json.put("comment", consult.getCommentContent());
//                // 设置评价星级
//                json.put("star", consult.getCommentStar());
//                // 设置咨询类型:1三师咨询,2家庭医生咨询 6名医咨询
//                json.put("type", consult.getType());
//                // 设置咨询时间
//                json.put("time", DateUtil.dateToStr(consult.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
//                // 咨询状态
//                json.put("status", consult.getStatus());
//                json.put("doctor", consult.getDoctor());
//                json.put("doctorName", consult.getDoctorName());
//                // 设置性别
//                json.put("sex", p.getSex());
//                // 未读消息
//                json.put("doctorRead", consult.getDoctorRead());
//                // 设置关联指导
//                json.put("guidance", consult.getGuidance());
//                json.put("startId", consult.getStartMsgId());
//                json.put("endId", consult.getEndMsgId());
//                List<WlyyTalkGroup> wlyyTalkGroups = talkGroupService.findAllConsultTalkGroup(consult.getConsult());
//                if (wlyyTalkGroups != null && wlyyTalkGroups.size() > 0) {
//                    for (WlyyTalkGroup wlyyTalkGroup : wlyyTalkGroups) {
//                        json.put("group" + wlyyTalkGroup.getType(), wlyyTalkGroup.getCode());
//                        json.put("groupName" + wlyyTalkGroup.getType(), wlyyTalkGroup.getName());
//                    }
//                }
//                jsonArray.put(json);
//            }
//            return write(200, "查询成功", "list", jsonArray);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    @RequestMapping(value = "/hasTnvite", method = RequestMethod.POST)
//    public String hasTnvite(String groupCode) {
//        try {
//            JSONObject jo = new JSONObject();
//            List<WlyyTalkGroupMember> wlyyTalkGroupMembers = talkGroupService.findTalkGroupMembers(groupCode);
//            if (wlyyTalkGroupMembers.size() > 2) {
//                jo.put("hasTnvite", 1);//有邀请
//            } else {
//                jo.put("hasTnvite", 0);//没邀请
//            }
//            return write(200, "查询成功", "list", jo);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    /**
//     * 名医列表
//     *
//     * @return
//     */
//    @ApiOperation("名医列表")
//    @RequestMapping(value = "famousDoctorList", method = RequestMethod.POST)
//    public String famousDoctorList(
//            @RequestParam(required = false) String name) {
//        try {
//            JSONArray array = new JSONArray();
//            List<Doctor> list = doctorService.getDoctorFamousDoctorList(name);
//            if (list != null) {
//                for (Doctor doctor : list) {
//                    if (doctor == null) {
//                        continue;
//                    }
//                    // 过滤掉自己
//                    if (doctor.getCode().equals(getUID())) {
//                        continue;
//                    }
//
//                    // 判断名医是否在工作
//                    JSONObject isWorking = doctorWorkTimeService.isDoctorWorking(doctor.getCode());
//
//                    if (isWorking == null || !isWorking.getString("status").equals("1")) {
//                        continue;
//                    }
//
//                    JSONObject json = new JSONObject();
//                    json.put("id", doctor.getId());
//                    // 医生标识
//                    json.put("code", doctor.getCode());
//                    // 医生性别
//                    json.put("sex", doctor.getSex());
//                    // 医生姓名
//                    json.put("name", doctor.getName());
//                    // 类别
//                    json.put("level", doctor.getLevel());
//                    // 所在医院名称
//                    json.put("hospital", doctor.getHospital());
//                    // 所在医院名称
//                    json.put("hospital_name", doctor.getHospitalName());
//                    // 科室名称
//                    json.put("dept_name", (doctor.getDeptName() == null ||
//                            StringUtils.isEmpty(doctor.getDeptName().toString())) ? " " : doctor.getDeptName());
//                    // 职称名称
//                    json.put("job_name", (doctor.getJobName() == null ||
//                            StringUtils.isEmpty(doctor.getJobName().toString())) ? " " : doctor.getJobName());
//                    // 头像
//                    json.put("photo", doctor.getPhoto());
//                    // 简介
//                    json.put("introduce", doctor.getIntroduce());
//                    // 专长
//                    json.put("expertise", doctor.getExpertise());
//                    array.put(json);
//                }
//            }
//            return write(200, "获取医院医生列表成功!", "list", array);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 获取咨询全科医生签约量
//     *
//     * @param consults
//     * @return
//     */
//    @ApiOperation("获取咨询全科医生签约量")
//    @RequestMapping(value = "/consult_sign", method = RequestMethod.POST)
//    public String consultSign(String consults) {
//        try {
//            List<Map<String, Object>> list = consultTeamService.getConsultSign(consults.split(","));
//            return write(200, "查询成功", "data", new JSONArray(list));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 结束三师咨询接口
//     *
//     * @param consult 三师咨询标识
//     * @return
//     */
//    @ApiOperation("结束三师咨询接口")
//    @RequestMapping(value = "finish", method = RequestMethod.POST)
//
//    public String finish(String consult) {
//        try {
//            int flag = consultTeamService.finish(consult, getUID(), 2);
//            if (flag > 0) {
//                return success("咨询已关闭");
//            } else if (flag == -2) {
//                return error(-1, "续方未审核,不能结束续方咨询!");
//            } else {
//                return error(-1, "关闭失败!");
//            }
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "关闭失败!");
//        }
//    }
//
//
//    /**
//     * 医生咨询咨询日志查询
//     *
//     * @param consult  咨询标识
//     * @param patient  患者标识
//     * @param pagesize 每页显示数,默认为10
//     * @return
//     */
//    @ApiOperation("医生咨询咨询日志查询")
//    @RequestMapping(value = "record", method = RequestMethod.POST)
//    public String record(String consult, String patient, long id, int pagesize) {
//        try {
//            Patient patientTemp = null;
//            if (id <= 0) {
//                // 只有第一页才会查询患者信息
//                patientTemp = patientService.findByCode(patient);
//                // 更新医生未读数量为0
//                consultTeamService.clearDoctorRead(consult);
//            }
//            // 查询日志列表
//            JSONArray jsonArray = new JSONArray();
//            Page<ConsultTeamDoLog> list = consultTeamService.findLogByConsult(consult, id, pagesize);
//            if (list != null) {
//                for (ConsultTeamDoLog log : list) {
//                    if (consult == null) {
//                        continue;
//                    }
//                    JSONObject json = new JSONObject();
//                    json.put("id", log.getId());
//                    // 设置回复内容
//                    json.put("content", log.getContent());
//                    // 设置回复医生姓名
//                    json.put("doctorName", log.getDoctorName());
//                    // 设置回复人头像
//                    json.put("photo", log.getPhoto());
//                    // 设置日志类型
//                    json.put("type", log.getType());
//                    // 设置记录类型
//                    json.put("chatType", log.getChatType());
//                    // 设置咨询或回复时间
//                    json.put("time", DateUtil.dateToStr(log.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
//                    jsonArray.put(json);
//                }
//            }
//            // 设置返回结果
//            JSONObject values = new JSONObject();
//            if (patientTemp != null) {
//                JSONObject patientJson = new JSONObject();
//                // 设置患者标识
//                patientJson.put("patient", patientTemp.getCode());
//                // 设置姓名
//                patientJson.put("name", patientTemp.getName());
//                // 设置头像
//                patientJson.put("photo", patientTemp.getPhoto());
//                values.put("patient", patientJson);
//            }
//            values.put("list", jsonArray);
//            // 返回结果
//            return write(200, "查询成功", "data", values);
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    /**
//     * 医生回复网络咨询
//     *
//     * @param patient 患者标识
//     * @param consult 咨询标识
//     * @param content 回复内容
//     * @param type    回复类型,1文字,2图片,3语音
//     * @return
//     */
//    @ApiOperation("医生回复网络咨询")
//    @RequestMapping(value = "reply", method = RequestMethod.POST)
//    public String reply(String patient, String consult, String content, int type) {
//        try {
//            // 查询医生基本信息
//            Doctor doctor = doctorInfoService.findDoctorByCode(getUID());
//            if (doctor == null) {
//                return error(-1, "回复失败!");
//            } else {
//                ConsultTeamDoLog log = new ConsultTeamDoLog();
//                // 设置咨询标识
//                log.setConsult(consult);
//                // 拷贝图片
//                if (StringUtils.isNotEmpty(content)) {
//                    if (type == 3) {
//                        // 语音
//                        content = CommonUtil.copyTempVoice(content);
//                    } else if (type == 2) {
//                        // 图片
//                        content = CommonUtil.copyTempImage(content);
//                    }
//                }
//                // 设置回复内容
//                log.setContent(content);
//                log.setDel("1");
//                // 设置回复医生标识
//                log.setDoctor(doctor.getCode());
//                // 设置医生姓名
//                log.setDoctorName(doctor.getName());
//                // 设置医生头像
//                log.setPhoto(doctor.getPhoto());
//                // 设置咨询类型为医生回复
//                log.setType(1);
//                // 设置记录类型
//                log.setChatType(type);
//                // 保存医生回复内容
//                log = consultTeamService.reply(log, patient, getUID(), log.getType());
//                if (log == null) {
//                    return error(-1, "回复失败!");
//                } else {
//                    // 推送消息给患者
//                    // 推送消息给微信端
//                    ConsultTeamDo ct = consultTeamService.findByCode(consult);
//                    Patient p = patientService.findByCode(patient);
//                    if (ct != null && p != null && StringUtils.isNotEmpty(p.getOpenid())) {
//                        JSONObject json = new JSONObject();
//                        json.put("first", p.getName() + ",您好!\n您的健康咨询有新的回复");
//                        json.put("toUser", p.getCode());
//                        String symp = ct.getSymptoms();
//                        json.put("consultcontent", StringUtils.isNotEmpty(symp) && symp.length() > 50 ? (symp.substring(0, 50) + "...") : content);
//                        String replycontent = content.length() > 50 ? content.substring(0, 50) + "..." : content;
//                        if (type == 2) {
//                            replycontent = "[图片]";
//                        } else if (type == 3) {
//                            replycontent = "[语音]";
//                        }
//                        json.put("consult", consult);
//                        json.put("replycontent", replycontent);
//                        json.put("doctorName", doctor.getName());
//                        json.put("remark", "医生已为您提供问诊方案");
//                        // PushMsgTask.getInstance().putWxMsg(getAccessToken(), 3, p.getOpenid(), p.getName(), json);
//                    }
//                    if (type == 2) {
//                        return write(200, "回复成功!", "data", content);
//                    }
//                    return success("回复成功!");
//                }
//            }
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "回复失败!");
//        }
//    }
//
//    /**
//     * 查询医生的总咨询次数和今日咨询次数
//     *
//     * @param doctorCode
//     * @return
//     */
//    @ApiOperation("查询医生的总咨询次数和今日咨询次数")
//    @RequestMapping(value = "getConsultCount", method = RequestMethod.POST)
//    public String getAllCount(@RequestParam(required = true) String doctorCode) {
//        try {
//            JSONObject json = new JSONObject();
//            Map<String, Long> counts = consultTeamService.getAllCount(doctorCode);
//
//            json.put("all", counts.get("all"));
//            json.put("today", counts.get("today"));
//            return json.toString();
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 查询患者的服务数目
//     *
//     * @return
//     */
//    @ApiOperation("查询患者的服务数目")
//    @RequestMapping(value = "getPatientServicNum", method = RequestMethod.POST)
//    public String getPatientServicNum(String patientCode) {
//        try {
//            JSONObject json = new JSONObject();
//            //统计咨询数目
//            Integer allSize1 = consultTeamService.findByDoctorSize(patientCode, getUID());
//            //查询健康指导
//            Integer allSize2 = patientHealthGuidanceService.findGuidanceByPatient(patientCode, getUID());
//            json.put("consult", allSize1);
//            json.put("guide", allSize2);
//            //json.put("today", counts.get("today"));
//            return json.toString();
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 根据医生code和和患者code判断是否有存在进行中的咨询
//     *
//     * @param patientCode 多个患者 逗号分隔
//     * @param doctor
//     * @return 只返回存在咨询的患者的code
//     */
//    @ApiOperation("根据医生code和和患者code判断是否有存在进行中的咨询")
//    @RequestMapping(value = "getConsultByPatientAndDoctor", method = RequestMethod.POST)
//    public String getConsultByPatientAndDoctor(String patientCode, String doctor) {
//        try {
//            JSONArray json = new JSONArray();
//            String[] patients = patientCode.split(",");
//            //查询医生未结束居民列表
//            List<String> list = consultTeamService.getConsultListByPatientAndDoctor(doctor);
//            for (int i = 0; i < patients.length; i++) {
//                if (list.contains(patients[i])) {
//                    json.put(patients[i]);
//                }
//            }
//            return json.toString();
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 名医咨询添加接口
//     *
//     * @param when       发病时间
//     * @param symptoms   主要症状
//     * @param images     图片URL地址,多图以逗号分隔
//     * @param voice      语音URL地址
//     * @param doctorCode 名医的code
//     * @return
//     */
//    @ApiOperation("名医咨询添加接口")
//    @RequestMapping(value = "famousAdd", method = RequestMethod.POST)
//
//    public String famousAdd(
//            @RequestParam(required = false) String when,
//            String symptoms,
//            @RequestParam(required = false) String doctorCode,
//            @RequestParam(required = false) String images,
//            @RequestParam(required = false) String voice) {
//        try {
//            //判断医生是否是在工作时间
//            JSONObject jo = doctorWorkTimeService.isFamousDoctorWorking(doctorCode);
//            if (!jo.get("status").equals("1")) {
//                return error(-1, jo.get("msg").toString());
//            }
//            if (StringUtils.isEmpty(images)) {
//                images = fetchWxImages();
//                // 将临时图片拷贝到正式存储路径下
//                if (StringUtils.isNotEmpty(images)) {
//                    images = CommonUtil.copyTempImage(images);
//                }
//            }
//
//            if (StringUtils.isNotEmpty(voice)) {
//                voice = fetchWxVoices();
//            }
//            if (StringUtils.isNotEmpty(voice)) {
//                voice = CommonUtil.copyTempVoice(voice);
//            }
//
//            ConsultTeamDo consult = new ConsultTeamDo();
//            // 设置咨询类型:1三师咨询,2家庭医生咨询 6.患者发起名医咨询 7医生发起的名医咨询
//            consult.setType(7);
//            // 设置发病时间
//            consult.setWhen(when);
//            // 设置主要症状
//            consult.setSymptoms(symptoms);
//            // 设置咨询图片URL
//            consult.setImages(images);
//            // 设置咨询语音URL
//            consult.setVoice(voice);
//            consult.setDoctor(doctorCode);//设置专科医生
//            // 保存到数据库
//            JSONObject result = consultTeamService.famousConsult(consult, getUID(), "2", null);
//            // 推送消息给医生
//            pushMsgTask.put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.D_CT_04.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.名医咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.您有新的名医咨询.name(), consult.getConsult());
//            if (StringUtils.isNotEmpty(images)) {
//                String[] arr = images.split(",");
//                for (String img : arr) {
//                    pushMsgTask.put(consult.getDoctor(), "2", MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.名医咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM_DOCTOR.您有新的名医咨询.name(), img);
//                }
//            }
//            return write(200, "创建成功!", "data", result);
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "提交失败!");
//        }
//    }
//
//    /**
//     * 查询与某个医生是否存在未结束的咨询
//     *
//     * @param doctor 医生
//     * @return
//     */
//    @ApiOperation("查询与某个医生是否存在未结束的咨询")
//    @RequestMapping(value = "/is_consult_unfinished", method = RequestMethod.POST)
//    public String isExistsUnfinishedConsult(@RequestParam(required = false) String patient,
//                                            @RequestParam(required = false) String type,
//                                            @RequestParam(required = true) String doctor) {
//        try {
//            if ("1".equals(type)) {
//                //专科
//                List<ConsultHelp> helps = consultTeamService.findUnfinishedByPatientAndSpecialist(patient, doctor);
//                if (helps.size() > 0) {
//                    return write(200, "查询成功", "data", helps.get(0).getConsult());
//                } else {
//                    return write(200, "查询成功", "data", "");
//                }
//            }
//            List<ConsultTeamDo> consults = consultTeamService.getUnfinishedConsult(StringUtils.isEmpty(patient) ? getUID() : patient, doctor);
//
//            if (consults != null && consults.size() > 0) {
//                return write(200, "查询成功", "data", consults.get(0).getConsult());
//            } else {
//                return write(200, "查询成功", "data", "");
//            }
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//
//    /**
//     * 查询与某个医生是否存在未结束的咨询
//     *
//     * @param consult 咨询code
//     * @return
//     */
//    @ApiOperation("查询与某个医生是否存在未结束的咨询")
//    @RequestMapping(value = "/consultTeam", method = RequestMethod.POST)
//    public String consult(@RequestParam(required = false) String consult) {
//        try {
//            ConsultTeamDo consultTeam = consultTeamService.findByCode(consult);
//            return write(200, "查询成功", "data", consultTeam);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//
//    /**
//     * 三师咨询转接接口
//     *
//     * @param consult 图咨询标识
//     * @param doctor  转接对象标识 健康管理师转全科是 1个    全科转专科是多个  传多个doctor逗号分隔
//     * @param type    转接对象类型,1三师团队,2指定医生,3工作组团队
//     * @return
//     */
//    @ApiOperation("三师咨询转接接口")
//    @RequestMapping(value = "transfer", method = RequestMethod.POST)
//
//    public String transfer(
//            String consult,
//            String doctor,
//            @RequestParam(required = false) int type) {
//        try {
//            consultTeamService.transfers(getUID(), doctor, consult);
//            return success("转接成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 根据咨询code获取咨询的log
//     *
//     * @param consultCode
//     * @return
//     */
//    @ApiOperation("根据咨询code获取咨询的log")
//    @RequestMapping(value = "getConsultLog", method = RequestMethod.POST)
//    public String getConsultLog(
//            String consultCode) {
//        try {
//            List<ConsultTeamDoLog> consultTeamLogs = consultTeamService.getConsultLog(consultCode);
//            JSONArray ja = new JSONArray();
//            for (ConsultTeamDoLog log : consultTeamLogs) {
//                JSONObject json = new JSONObject();
//                json.put("id", log.getId());
//                // 设置回复内容
//                json.put("content", log.getContent());
//                // 设置回复医生姓名
//                json.put("doctorName", log.getDoctorName());
//                // 设置回复人头像
//                json.put("photo", log.getPhoto());
//                // 设置日志类型
//                json.put("type", log.getType());
//                // 设置记录类型
//                json.put("chatType", log.getChatType());
//                // 设置咨询或回复时间
//                json.put("time", DateUtil.dateToStr(log.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
//                ja.put(json);
//            }
//            return write(200, "查询成功", "data", ja);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 医生求助添加接口
//     *
//     * @param when       发病时间
//     * @param symptoms   主要症状
//     * @param groupCode  从哪个讨论组发起的求助
//     * @param images     图片URL地址,多图以逗号分隔
//     * @param voice      语音URL地址
//     * @param doctorCode 名医的code
//     * @return
//     */
//    @ApiOperation("医生求助添加接口")
//    @RequestMapping(value = "forHelpAdd", method = RequestMethod.POST)
//
//    public String forHelpAdd(
//            @RequestParam(required = false) String when,
//            String symptoms,
//            @RequestParam(required = false) String oldConsultCode,
//            @RequestParam(required = false) String groupCode,
//            @RequestParam(required = false) String doctorCode,
//            @RequestParam(required = false) String images,
//            @RequestParam(required = false) String voice) {
//        try {
//            if (StringUtils.isEmpty(images)) {
//                images = fetchWxImages();
//                // 将临时图片拷贝到正式存储路径下
//                if (StringUtils.isNotEmpty(images)) {
//                    images = CommonUtil.copyTempImage(images);
//                }
//            }
//
//            if (StringUtils.isEmpty(voice)) {
//                voice = fetchWxVoices();
//            }
//            if (StringUtils.isNotEmpty(voice)) {
//                voice = CommonUtil.copyTempVoice(voice);
//            }
//
//            ConsultTeamDo consult = new ConsultTeamDo();
//            // 设置咨询类型:1三师咨询,2家庭医生咨询 6.患者发起名医咨询 7医生发起的名医咨询 10医生发起的求助
//            consult.setType(10);
//            // 设置来源(从哪个讨论组发起的求助)
//            consult.setTeam(groupCode);
//            // 设置发病时间
//            consult.setWhen(when);
//            // 设置主要症状
//            consult.setSymptoms(symptoms);
//            // 设置咨询图片URL
//            consult.setImages(images);
//            // 设置咨询语音URL
//            consult.setVoice(voice);
//
//            consult.setDoctor(doctorCode);//设置专科医生
//            // 保存到数据库
//            if (consultTeamService.isCommonTeam(doctorCode, getUID())) {
//                consultTeamService.sendForHelpMsg(consult, getUID(), oldConsultCode);
//            } else {
//                consultTeamService.addForHelpTeamConsult(consult, getUID(), oldConsultCode);
//            }
//            return success("提交成功");
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "提交失败!");
//        }
//    }
//
//    @RequestMapping(value = "hasUnfinished", method = RequestMethod.POST)
//    public String hasUnfinished(String doctorCode) {
//        try {
//            String curDoc = getUID();
//            JSONObject json = new JSONObject();
//            if (consultTeamService.isCommonTeam(doctorCode, curDoc)) {
//                json.put("isCommonTeam", 1);
//                return write(200, "查询成功", "data", json);
//            }
//            List<ConsultTeamDo> ls = consultTeamService.hasUnfinished(doctorCode, curDoc);
//            if (ls != null && ls.size() > 0) {
//                ConsultTeamDo ct = ls.get(0);
//                json.put("consult", ct.getConsult());
//                //是否是医生求助医生
//                if (ct.getType() == 10) {
//                    //取出原有咨询求助返回原咨询的患者
//                    ConsultTeamDo consultTeam = consultTeamService.findByConsultCode(ct.getTeam());
//                    Patient patient = patientService.findByCode(consultTeam.getPatient());
//                    json.put("zxGroupCode", consultTeam.getPatient() + "_" + consultTeam.getTeam() + "_" + consultTeam.getType());
//                    json.put("from", ct.getPatient());
//                    json.put("patient_name", patient.getName());
//                }
//            }
//            return write(200, "查询成功", "data", json);
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "查询失败!");
//        }
//    }
//
//    /**
//     * 该咨询求助过的医生列表
//     *
//     * @param consult 关联的上一个咨询
//     * @return
//     */
//    @ApiOperation("该咨询求助过的医生列表")
//    @RequestMapping(value = "forHelpDocs", method = RequestMethod.POST)
//    public String forHelpDocs(String consult) {
//        try {
//            List<String> ls = consultTeamService.findByTeam(consult);
//            JSONObject json = new JSONObject();
//            if (ls != null) {
//                for (String o : ls) {
//                    json.put(o, 1);
//                }
//            }
//            return write(200, "查询成功", "data", json);
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "查询失败!");
//        }
//    }
//
//    @RequestMapping(value = "getConsult")
//    public String getConsult(String consult) {
//        try {
//            ConsultTeamDo consultTeam = consultTeamService.findByConsultCode(consult);
//            return write(200, "查询成功", "data", consultTeam);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "/isConsultFinished", method = RequestMethod.POST)
//    public String isConsultFinished(@RequestParam String consult) {
//        try {
//            ConsultTeamDo ct = consultTeamService.findByConsultCode(consult);
//            return write(200, "查询咨询状态成功", "data", ct.getStatus());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "seekHelp", method = RequestMethod.POST)
//
//    public String seekHelp(
//            @RequestParam(required = true) String symptoms,
//            @RequestParam(required = false) String oldConsultCode,
//            @RequestParam(required = false) String doctorCode,
//            @RequestParam(required = false) String images,
//            @RequestParam(required = true) Integer isSend) {
//        try {
//            if (StringUtils.isEmpty(images)) {
//                images = fetchWxImages();
//                // 将临时图片拷贝到正式存储路径下
//                if (StringUtils.isNotEmpty(images)) {
//                    images = CommonUtil.copyTempImage(images);
//                }
//            }
//            ConsultTeamDo consult = new ConsultTeamDo();
//            // 设置咨询类型:1三师咨询,2家庭医生咨询 6.患者发起名医咨询 7医生发起的名医咨询 10医生发起的求助
//            consult.setType(10);
//            // 设置主要症状
//            consult.setSymptoms(symptoms);
//            // 设置咨询图片URL
//            consult.setImages(images);
//
//            consult.setDoctor(doctorCode);//设置专科医生
//            // 保存到数据库
//            if (consultTeamService.isCommonTeam(doctorCode, getUID())) {
//                consultTeamService.addSeekHelpTeam(consult, getUID(), oldConsultCode, isSend);
//            } else {
//                consultTeamService.addSeekHelpOtherTeam(consult, getUID(), oldConsultCode, isSend);
//            }
//            return success("提交成功");
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "提交失败!");
//        }
//    }
//
//
//    /**
//     * 结束咨询接口
//     *
//     * @param consult 咨询标识
//     * @return
//     */
//    @ApiOperation("结束咨询接口")
//    @RequestMapping(value = "finish_consult", method = {RequestMethod.GET, RequestMethod.POST})
//
//    public String finishConsult(@RequestParam(required = false) String consult) {
//        try {
//            int flag = consultTeamService.finishConsult(consult, getUID(), 2);
//            if (flag > 0) {
//                return success("咨询已关闭");
//            } else if (flag == -1) {
//                return error(-1, "该咨询已经关闭,不需重复关闭!");
//            } else if (flag == -2) {
//                return error(-1, "续方未审核,不能结束续方咨询!");
//            } else {
//                return error(-1, "关闭失败!");
//            }
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "关闭失败!");
//        }
//    }
//
//
//    /**
//     * 网络咨询咨询日志查询
//     *
//     * @param consult  咨询标识
//     * @param pagesize 每页显示数,默认为10
//     * @return
//     */
//    @ApiOperation("网络咨询咨询日志查询")
//    @RequestMapping(value = "loglist", method = RequestMethod.GET)
//    public String loglist(@RequestParam String consult, @RequestParam int page, @RequestParam int pagesize) {
//        try {
//            ConsultTeamDo consultModel = consultTeamService.findByCode(consult);
//            if (consultModel == null) {
//                return error(-1, "咨询记录不存在!");
//            }
//            JSONObject messageObj = imUtill.getTopicMessage(consultModel.getConsult(), consultModel.getStartMsgId(), consultModel.getEndMsgId(), page, pagesize, getUID());
//            return write(200, "查询成功", "list", messageObj);
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            return invalidUserException(e, -1, "查询失败!");
//        }
//    }
//
//    /*********************************************续方咨询**************************************************************/
//
//    @RequestMapping(value = "prescriptionDetail", method = RequestMethod.GET)
//    @ApiOperation("获取续方信息")
//    public String prescriptionDetail(@ApiParam(name = "consult", value = "咨询code", defaultValue = "1")
//                                     @RequestParam(value = "consult", required = true) String consult) {
//        try {
//            JSONObject json = new JSONObject();
//
//            Consult consult1 = consultDao.findByCode(consult);
//            String prescriptionCode = consult1.getRelationCode();
//            Prescription prescription = prescriptionDao.findByCode(prescriptionCode);
//            json.put("status", prescription.getStatus());//状态 (-1 审核不通过 , 0 审核中, 10 审核通过/待支付 ,21支付失败  20 配药中/支付成功, 21 等待领药 ,30 配送中 ,100配送成功/已完成)
//            json.put("prescriptionDt", prescriptionDiagnosisService.getPrescriptionDiagnosis(prescriptionCode));//续方疾病类型
//            json.put("prescriptionInfo", prescriptionDiagnosisService.getPrescriptionInfo(prescriptionCode));//续方药品信息
//            json.put("followup", followUpService.getFollowupByPrescriptionCode(prescriptionCode));//续方关联的随访记录
//
//            //服务类型
//            List<SignFamilyServer> list = signFamilyServerDao.findBySignCodeAndType(consult1.getSignCode());
//            JSONArray jsonArray = new JSONArray();
//            if (list != null && list.size() > 0) {
//                for (SignFamilyServer server : list) {
//                    JSONObject jsonObject = new JSONObject();
//                    jsonObject.put("serverType", server.getServerType());
//                    jsonObject.put("serverTypeName", server.getServerTypeName());
//                    jsonArray.put(jsonObject);
//                }
//            }
//            json.put("signFamilyServer", jsonArray);
//            json.put("symptoms", consult1.getSymptoms());//咨询类型--- 1高血压,2糖尿病
//            json.put("jwCode", prescription.getJwCode());//基位处方code
//            json.put("code", prescription.getCode());//续方code
//            json.put("viewJiancha", prescription.getViewJiancha());//检查
//            json.put("viewTizhen", prescription.getViewTizhen());//体征
//            json.put("viewChufang", prescription.getViewChufang());//处方
//            json.put("viewXufang", prescription.getViewXufang());//续方
//            json.put("viewWenjuan", prescription.getViewWenjuan());//问卷
//            json.put("viewSuifang", prescription.getViewSuifang());//随访
//
//            return write(200, "查询成功!", "data", json);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "addPrescriptionBloodStatusConsult", method = RequestMethod.POST)
//
//    @ApiOperation("续方咨询-医生发送血糖血压快捷回复咨询")
//    public String addPrescriptionBloodStatusConsult(
//            @ApiParam(name = "prescriptionCode", value = "处方code", defaultValue = "")
//            @RequestParam(value = "prescriptionCode", required = true) String prescriptionCode,
//            @ApiParam(name = "type", value = "类型(1血压,2血糖)", defaultValue = "")
//            @RequestParam(value = "type", required = true) String type,
//            @ApiParam(name = "followupid", value = "随访记录ID", defaultValue = "")
//            @RequestParam(value = "followupid", required = true) String followupid) {
//        try {
//            consultTeamService.addPrescriptionBloodStatusConsult(prescriptionCode, type, followupid);
//            return write(200, "添加成功!");
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "addPrescriptionFollowupContentConsult", method = RequestMethod.POST)
//
//    @ApiOperation("续方咨询-医生发送问卷快捷回复咨询")
//    public String addPrescriptionFollowupContentConsult(
//            @ApiParam(name = "prescriptionCode", value = "处方code", defaultValue = "")
//            @RequestParam(value = "prescriptionCode", required = true) String prescriptionCode,
//            @ApiParam(name = "type", value = "类型(1症状,2体征及生活方式)", defaultValue = "")
//            @RequestParam(value = "type", required = true) String type,
//            @ApiParam(name = "followupid", value = "随访记录ID", defaultValue = "")
//            @RequestParam(value = "followupid", required = true) String followupid) {
//        try {
//            consultTeamService.addPrescriptionFollowupContentConsult(prescriptionCode, type, followupid);
//            return write(200, "添加成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "getSessionId", method = RequestMethod.GET)
//    @ApiOperation("pcim-获取居民的sessionId")
//    public String getSessionId(@ApiParam(name = "patient", value = "居民code", defaultValue = "")
//                               @RequestParam(value = "patient", required = true) String patient) {
//        try {
//            com.alibaba.fastjson.JSONObject re = consultTeamService.getSessionId(patient);
//            return write(200, "获取成功!", "data", re);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "sendBusinessCard", method = RequestMethod.POST)
//    @ApiOperation("发送居民的名片")
//
//    public String sendBusinessCard(@ApiParam(name = "patient", value = "居民code", defaultValue = "")
//                                   @RequestParam(value = "patient", required = true) String patient,
//                                   @ApiParam(name = "sessionId", value = "会话id", defaultValue = "")
//                                   @RequestParam(value = "sessionId", required = true) String sessionId,
//                                   @ApiParam(name = "businessType", value = "businessType", defaultValue = "1")
//                                   @RequestParam(value = "businessType", required = true) String businessType) {
//        try {
//            String doctorCode = getUID();
//            Doctor doctor = doctorService.findDoctorByCode(doctorCode);
//
//            Patient p = patientService.findByCode(patient);
//            com.alibaba.fastjson.JSONObject content = new com.alibaba.fastjson.JSONObject();
//            content.put("name", p.getName());
//            content.put("patient", patient);
//            content.put("photo", p.getPhoto());
//            content.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(), p.getBirthday()));
//            content.put("sex", IdCardUtil.getSexForIdcard_new(p.getIdcard()));
//            SignFamily signFamily = signFamilyDao.findByPatient(patient);
//            if (signFamily != null) {
//                content.put("hospitalName", signFamily.getHospitalName());
//            }
//            imUtill.sendImMsg(doctorCode, doctor.getName(), sessionId, ImUtill.ContentType.personalCard.getValue(), content.toString(), businessType);
//            return success("发送成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "messageForward", method = RequestMethod.POST)
//    @ApiOperation("请求转发消息")
//    public String messageForward(@ApiParam(name = "senderId", value = "发送者id", defaultValue = "")
//                                 @RequestParam(value = "senderId", required = true) String senderId,
//                                 @ApiParam(name = "senderName", value = "发送者姓名", defaultValue = "")
//                                 @RequestParam(value = "senderName", required = true) String senderName,
//                                 @ApiParam(name = "sessionId", value = "会话id", defaultValue = "")
//                                 @RequestParam(value = "sessionId", required = true) String sessionId,
//                                 @ApiParam(name = "content", value = "会话内容", defaultValue = "")
//                                 @RequestParam(value = "content", required = true) String content,
//                                 @ApiParam(name = "title", value = "会话标题", defaultValue = "")
//                                 @RequestParam(value = "title", required = true) String title,
//                                 @ApiParam(name = "sessionType", value = "原会话的会话类型", defaultValue = "")
//                                 @RequestParam(value = "sessionType", required = true) String sessionType,
//                                 @ApiParam(name = "businessType", value = "businessType", defaultValue = "1")
//                                 @RequestParam(value = "businessType", required = true) String businessType) {
//        try {
//            String message = consultTeamService.getMessageById(sessionType, content, title);
//            imUtill.sendImMsg(senderId, senderName, sessionId, ImUtill.ContentType.messageForward.getValue(), message, businessType);
//            return success("发送成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "examinationDetail", method = RequestMethod.GET)
//    @ApiOperation("获取在线复诊信息")
//    public String examinationDetail(@ApiParam(name = "consult", value = "咨询code", defaultValue = "1")
//                                    @RequestParam(value = "consult", required = true) String consult) {
//        try {
//            JSONObject json = new JSONObject();
//
//            Consult consult1 = consultDao.findByCode(consult);
//            String examinationCode = consult1.getRelationCode();
//            Examination examination = examinationDao.findByCode(examinationCode);
//            json.put("status", examination.getStatus());//状态 (-1 审核不通过 , 0 审核中, 10 审核通过/待支付 ,21支付失败  20 配药中/支付成功, 21 等待领药 ,30 配送中 ,100配送成功/已完成)
//            json.put("examinationDt", examination.getAdjustReason());//续方疾病类型
//
//            json.put("symptoms", consult1.getSymptoms());//咨询类型--- 1高血压,2糖尿病
//            json.put("visitNo", examination.getVisitNo());//基位处方code
//            json.put("code", examination.getCode());//续方code
//
//            return write(200, "查询成功!", "data", json);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "updateConsultParticipant", method = RequestMethod.POST)
//    @ApiOperation("更新会话成员(新增或删除)")
//
//    public String updateConsultParticipant(@ApiParam(name = "sessionid", value = "会话ID", defaultValue = "1")
//                                           @RequestParam(value = "sessionid", required = true) String sessionid,
//                                           @ApiParam(name = "userid", value = "新增成员ID,多个以英文逗号隔开", defaultValue = "1")
//                                           @RequestParam(value = "userid", required = true) String userid,
//                                           @ApiParam(name = "olduserid", value = "删除的成员id")
//                                           @RequestParam(value = "olduserid", required = false) String olduserid) {
//        try {
//            imUtill.updateParticipant(sessionid, userid, olduserid);
//            return write(200, "操作成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "inviteDoctor", method = RequestMethod.POST)
//    @ApiOperation("邀请医生回复居民问题")
//
//    public String inviteDoctor(@ApiParam(name = "sessionid", value = "会话ID")
//                               @RequestParam(value = "sessionid", required = true) String sessionid,
//                               @ApiParam(name = "doctor", value = "被邀请人")
//                               @RequestParam(value = "doctor", required = true) String doctor,
//                               @ApiParam(name = "topic", value = "咨询id")
//                               @RequestParam(value = "topic", required = true) String topic) {
//        try {
//            String uid = getUID();
//            imUtill.updateParticipant(sessionid, doctor, null);
//            //设置邀请消息
//            Doctor from = doctorDao.findByCode(uid);
//            Doctor d = doctorDao.findByCode(doctor);
//            String content = "已邀请" + d.getName() + "医生为您服务,请耐心等待";
//            imUtill.sendTopicIM(from.getCode(), from.getName(), topic, "1", content, null);
//            //发送邀请医生提醒消息
////            if(StringUtils.isNotEmpty(d.getOpenid())){
////                String first = from.getName()+"医生邀请您,为";
////                doctorAssistantUtil.sendWXTemplate(1,d.getOpenid(),d.getCid(),"咨询邀请回复","","");
////            }
//            return write(200, "操作成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "askSpecialist", method = RequestMethod.POST)
//    @ApiOperation("邀请专科-回复居民咨询")
//
//    public String askSpecialist(@ApiParam(name = "sessionid", value = "会话ID")
//                                @RequestParam(value = "sessionid", required = true) String sessionid,
//                                @ApiParam(name = "doctor", value = "被邀请人")
//                                @RequestParam(value = "doctor", required = true) String doctor,
//                                @ApiParam(name = "topic", value = "咨询id")
//                                @RequestParam(value = "topic", required = true) String topic) {
//        try {
//            consultTeamService.askSpecialist(topic, sessionid, getUID(), doctor);
//            return write(200, "操作成功!");
//        } catch (ServiceException se) {
//            return error(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    /**
//     * 家庭医生发起康复咨询
//     *
//     * @param when              发病时间
//     * @param oldConsultCode    从哪个讨论组发起的求助
//     * @param specialDoctorCode 专科医生
//     * @param specialDoctorCode 全科医生
//     * @param images            图片URL地址,多图以逗号分隔
//     * @param voice             语音URL地址
//     * @param doctorCode        名医的code
//     * @return
//     */
//    @ApiOperation("医生求助添加接口")
//    @RequestMapping(value = "forSpecialAdd", method = RequestMethod.POST)
//
//    public String forSpecialAdd(
//            @RequestParam(required = false) String when,
//            @RequestParam(required = false) String oldConsultCode,
//            @RequestParam(required = false) String specialDoctorCode,
//            @RequestParam(required = false) String doctorCode,
//            @RequestParam(required = false) String patientCode,
//            @RequestParam(required = false) String images,
//            @RequestParam(required = false) String voice) {
//        try {
//            String symptoms = "";
//            if (StringUtils.isNoneBlank(oldConsultCode)) {
//                Consult consult = consultDao.findByCode(oldConsultCode);
//                symptoms = consult.getSymptoms();
//            }
//
//            if (StringUtils.isEmpty(images)) {
//                images = fetchWxImages();
//            }
//            // 将临时图片拷贝到正式存储路径下
//            if (StringUtils.isNotEmpty(images)) {
//                images = CommonUtil.copyTempImage(images);
//            }
//            if (StringUtils.isEmpty(voice)) {
//                voice = fetchWxVoices();
//            }
//            if (StringUtils.isNotEmpty(voice)) {
//                voice = CommonUtil.copyTempVoice(voice);
//            }
//            ConsultTeamDo consult = new ConsultTeamDo();
//            // 设置咨询类型:1三师咨询,2家庭医生咨询  6.名医咨询   18.康复咨询
//            consult.setType(18);
//            // 设置发病时间
//            consult.setWhen(when);
//            // 设置主要症状
//            consult.setSymptoms(symptoms);
//            // 设置咨询图片URL
//            consult.setImages(images);
//            // 设置咨询语音URL
//            consult.setVoice(voice);
//
//            consult.setIsAuthentication(0);
//            consult.setIsRefinement(0);
//            // 保存到数据库
//            int res = 0;
//            JSONArray dts = null;
//            synchronized (getRepUID().intern()) {//新增同步方法。设备保存写在service层但是不生效,写在controller层才生效
//                JSONObject re = consultTeamService.addTeamSpecialConsult(consult, patientCode, getUID(), specialDoctorCode, doctorCode);
//                res = re.getInt("status");
//                dts = re.has("doctor") ? re.getJSONArray("doctor") : null;
//            }
//            if (res == -1) {
//                return error(-1, "家庭签约信息不存在或已过期,无法进行家庭医生咨询!");
//            } else if (res == -2) {
//                return error(-1, "家庭签约信息不存在或已过期,无法进行三师医生咨询!");
//            } else if (res == -3) {
//                return error(-1, "还有咨询未结束,不允许再次提交咨询!");
//            }
//            Boolean flag = messageService.getMessageNoticeSettingByMessageType(doctorCode, "1", MessageNoticeSetting.MessageTypeEnum.imSwitch.getValue());
//            if (flag) {
//                pushMsgTask.put(specialDoctorCode, MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.您有新的指定咨询.name(), consult.getConsult());
//                Doctor doctor = doctorDao.findByCode(specialDoctorCode);
//                if (doctor != null && StringUtils.isNotEmpty(doctor.getOpenid())) {
//                    String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
//                    List<NameValuePair> params = new ArrayList<>();
//                    params.add(new BasicNameValuePair("type", "4"));
//                    params.add(new BasicNameValuePair("openId", doctor.getOpenid()));
//                    params.add(new BasicNameValuePair("url", targetUrl));
//                    params.add(new BasicNameValuePair("first", doctor.getName() + "医生您好,有患者向您发起咨询"));
//                    params.add(new BasicNameValuePair("remark", "【" + consult.getSymptoms() + "】\r\n请进入手机APP查看"));
//                    String sex = consult.getSex() == 1 ? "男" : "女";
//                    String keywords = consult.getName() + "," + sex;
//                    params.add(new BasicNameValuePair("keywords", keywords));
//
//                    httpClientUtil.post(url, params, "UTF-8");
//                }
//            }
////                }
////            }
//
//            BusinessLogs.info(BusinessLogs.BusinessType.consult, getRepUID(), getUID(), new JSONObject(consult));
//            return write(200, "提交成功", "data", consult);
//        } catch (ServiceException se) {
//            return write(-1, se.getMessage());
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, "提交失败!");
//        }
//    }
//
//    @RequestMapping(value = "getKangFuConsultList", method = RequestMethod.GET)
//    @ApiOperation("获取续方咨询列表")
//    public String getKangFuConsultList(@ApiParam(name = "title", value = "咨询标题") @RequestParam(required = false) String title,
//                                       @ApiParam(name = "patient", value = "居民CODE") @RequestParam(required = false) String patient,
//                                       @ApiParam(name = "id", value = "第几页") @RequestParam(required = true) long id,
//                                       @ApiParam(name = "pagesize", value = "页面大小") @RequestParam(required = true) int pagesize) {
//        try {
//            JSONArray array = new JSONArray();
//            Page<Object> data = consultTeamService.findConsultRecordByType(patient, id, pagesize, 18, title);//18表示康复咨询
//            Patient patientobj = patientService.findByCode(patient);
//            if (data != null) {
//                for (Object consult : data.getContent()) {
//                    if (consult == null) {
//                        continue;
//                    }
//                    Object[] result = (Object[]) consult;
//                    JSONObject json = new JSONObject();
//                    json.put("id", result[0]);
//                    // 设置咨询类型:1三师咨询,2视频咨询,3图文咨询,4公共咨询,5病友圈,8 续方咨询  18康复咨询
//                    json.put("type", result[1]);
//                    // 设置咨询标识
//                    json.put("code", result[2]);
//                    // 设置显示标题
//                    json.put("title", result[3]);
//                    json.put("patientName", patientobj.getName());
//                    json.put("patientPhoto", patientobj.getPhoto());
//                    // 设置主诉
//                    json.put("symptoms", result[4]);
//                    // 咨询状态
//                    json.put("status", result[6]);
//                    // 设置咨询日期
//                    json.put("czrq", DateUtil.dateToStrLong((Date) result[5]));
//                    // 咨询状态
//                    json.put("doctorCode", result[7]);
//                    json.put("evaluate", result[8]);
//                    array.put(json);
//                }
//            }
//            return write(200, "查询成功!", "list", array);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "/getDoctorConsultSessions", method = RequestMethod.GET)
//    @ApiOperation("获取医生咨询列表,带专家咨询")
//    public String getDoctorConsultSessions(@ApiParam(name = "user_id", value = "会话医生code", required = true)
//                                           @RequestParam(value = "user_id", required = true) String user_id,
//                                           @ApiParam(name = "business_type", required = true)
//                                           @RequestParam(value = "business_type", required = true, defaultValue = "2") String business_type,
//                                           @ApiParam(name = "status", value = "0未结束,1已结束", required = true)
//                                           @RequestParam(value = "status", required = true) String status,
//                                           @ApiParam(name = "page", required = true)
//                                           @RequestParam(value = "page", required = true, defaultValue = "0") String page,
//                                           @ApiParam(name = "size", required = true)
//                                           @RequestParam(value = "size", required = true, defaultValue = "50") String size
//    ) {
//        try {
//            return write(200, "查询成功", "data", consultTeamService.getDoctorConsultSessions(user_id, business_type, status, page, size));
//        } catch (ServiceException se) {
//            return error(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//
//    @RequestMapping(value = "/getIMkangFuConsultSessions", method = RequestMethod.GET)
//    @ApiOperation("获取医生康复咨询IM列表")
//    public String getIMkangFuConsultSessions(@ApiParam(name = "user_id", value = "会话医生code", required = true)
//                                             @RequestParam(value = "user_id", required = true) String user_id,
//                                             @ApiParam(name = "type", required = true)
//                                             @RequestParam(value = "type", required = true, defaultValue = "18") String type,
//                                             @ApiParam(name = "status", value = "0未结束,1已结束", required = false)
//                                             @RequestParam(value = "status", required = false) String status,
//                                             @ApiParam(name = "name", value = "居民姓名支持模糊", required = false)
//                                             @RequestParam(value = "name", required = false) String name,
//                                             @ApiParam(name = "page", required = true)
//                                             @RequestParam(value = "page", required = true, defaultValue = "0") String page,
//                                             @ApiParam(name = "size", required = true)
//                                             @RequestParam(value = "size", required = true, defaultValue = "50") String size
//    ) {
//        try {
//            return write(200, "查询成功", "data", consultTeamService.getIMkangFuConsultSessions(user_id, type, status, page, size, name));
//        } catch (ServiceException se) {
//            return error(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//
//    @RequestMapping(value = "/getSpecialAndKangFuConsultUnreadInfo", method = RequestMethod.GET)
//    @ApiOperation("获取专家咨询、康复咨询是否存在未处理")
//    public String getSpecialAndKangFuConsultUnreadInfo(@ApiParam(name = "user_id", value = "医生code")
//                                                       @RequestParam(value = "user_id", required = true) String user_id
//    ) {
//        try {
//            return write(200, "查询成功", "data", consultTeamService.getSpecialAndKangFuConsultUnreadInfo(user_id));
//        } catch (ServiceException se) {
//            return error(-1, se.getMessage());
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
}

+ 1 - 2
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/service/ConsultService.java

@ -13,7 +13,6 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.UUID;
@Component
@Transactional
@ -71,7 +70,7 @@ public class ConsultService {
            String patient, String title, String symptoms, String images, int type
    ) throws Exception {
        ConsultDo consult = new ConsultDo();
        consult.setCode(UUID.randomUUID().toString().replaceAll("-", ""));//UUID
//        consult.setCode(UUID.randomUUID().toString().replaceAll("-", ""));//UUID
        consult.setCzrq(new Date());
        consult.setDel("1");
        consult.setPatient(patient);

+ 92 - 83
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/consult/service/ConsultTeamService.java

@ -1,5 +1,6 @@
package com.yihu.jw.hospital.module.consult.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.entity.base.im.ConsultDo;
@ -8,23 +9,15 @@ import com.yihu.jw.entity.base.im.ConsultTeamLogDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.door.WlyyDoorServiceOrderDO;
import com.yihu.jw.entity.wechat.WechatTemplateConfig;
import com.yihu.jw.hospital.HospitalDao;
import com.yihu.jw.hospital.module.door.dao.WlyyDoorServiceOrderDao;
import com.yihu.jw.hospital.module.door.service.WlyyDoorServiceOrderService;
import com.yihu.jw.hospital.module.wx.dao.WechatTemplateConfigDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDiagnosisDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionExpressageDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionInfoDao;
import com.yihu.jw.hospital.prescription.service.PrescriptionLogService;
import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
import com.yihu.jw.hospital.utils.WeiXinOpenIdUtils;
import com.yihu.jw.im.dao.ConsultTeamDoctorDao;
import com.yihu.jw.im.dao.ConsultTeamLogDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.message.dao.MessageDao;
import com.yihu.jw.message.service.MessageService;
import com.yihu.jw.order.dao.ConsultTeamOrderDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.service.BasePatientService;
@ -41,9 +34,6 @@ import org.springframework.data.domain.Page;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springside.modules.utils.Clock;
import java.text.DecimalFormat;
@ -74,38 +64,36 @@ public class ConsultTeamService extends ConsultService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    private MessageDao messageDao;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private BasePatientDao patientDao;
    @Autowired
    private PrescriptionLogService prescriptionLogService;
    @Autowired
    private PrescriptionInfoDao prescriptionInfoDao;
    @Autowired
    private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
//    @Autowired
//    private PrescriptionLogService prescriptionLogService;
//    @Autowired
//    private PrescriptionInfoDao prescriptionInfoDao;
//    @Autowired
//    private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
    @Autowired
    private WeiXinAccessTokenUtils accessTokenUtils;
//    @Autowired
//    private WeiXinAccessTokenUtils accessTokenUtils;
    @Autowired
    private BasePatientService patientService;
    @Autowired
    private MessageService messageService;
//    @Autowired
//    private MessageService messageService;
//
//    @Autowired
//    private PrescriptionExpressageDao expressageDao;
//    @Autowired
//    private HospitalDao hospitalDao;
    @Autowired
    private PrescriptionExpressageDao expressageDao;
    @Autowired
    private HospitalDao hospitalDao;
    @Autowired
    private WlyyDoorServiceOrderDao wlyyDoorServiceOrderDao;
    @Autowired
@ -180,6 +168,10 @@ public class ConsultTeamService extends ConsultService {
//    private PresModeAdapter presModeAdapter;
//    @Autowired
//    private ZyDictService zyDictService;
//    @Autowired
//    private WeiXinOpenIdUtils weiXinOpenIdUtils;
//    @Autowired
//    private MessageDao messageDao;
    /**
@ -206,7 +198,6 @@ public class ConsultTeamService extends ConsultService {
        //咨询详细信息
        ConsultTeamDo consultTeam = new ConsultTeamDo();
        consultTeam.setType(11);  //上门服务咨询
//        consultTeam.setAdminTeamId(signFamily.getAdminTeamId());//签约团队的信息-这边没有
        consultTeam.setRelationCode(doorServiceOrderDO.getId()); //关联业务code
        consultTeam.setSymptoms(doorServiceOrderDO.getServeDesc());
        consultTeam.setPatient(patient);
@ -220,31 +211,42 @@ public class ConsultTeamService extends ConsultService {
        consultTeam.setEvaluate(0);
        consultTeam.setDoctorRead(1); // 医生未读数量为1
        consult.setRelationCode(doorServiceOrderDO.getId());//关联业务code
        consultTeam.setConsult(consult.getCode()); // 设置咨询标识
        consultTeam.setConsult(consult.getId()); // 设置咨询标识
        //(im创建咨询) 上门服务咨询的sessionid为居民code+咨询code+工单编号+咨询类型
        String sessionId = patient + "_" + consult.getCode() + "_" + doorServiceOrderDO.getNumber() + "_" + consultTeam.getType();
        //原本:(im创建咨询) 上门服务咨询的sessionid为居民code+咨询code+工单编号+咨询类型
        String sessionId = patient + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consultTeam.getType();
        //4、 上门服务咨询-参与者
        JSONObject participants = new JSONObject();
        participants.put(patient, 0);
//        String content = signFamily.getHospitalName() + "为您服务";
        String content = doorServiceOrderDO.getDoctorName() + "为您服务";
        JSONObject messages = imUtill.getCreateTopicMessage(patient, patientDO.getName(), consult.getTitle(), content, consult.getImages(), "");
        //这边应该是要抛出异常比较合适
        JSONObject imResponseJson = imUtill.createTopics(sessionId, consult.getCode(), content, participants, messages, ImUtil.SESSION_TYPE_ONDOOR_NURSING);
        String content;
        if (StringUtils.isNotBlank(doorServiceOrderDO.getDoctorName())) {
            content = doorServiceOrderDO.getDoctorName() + "-为您服务";
        } else {
            content = "调度员即将分配人员为您服务";
        }
//        if (imResponseJson == null || imResponseJson.getString("status").equals("-1")) {
//            String failMsg = "发起服务咨询时:IM" + imResponseJson.getString("message");
//            throw new Exception(failMsg);
//        }
        //封装JSONObject的messages
        JSONObject messages = imUtill.getCreateTopicMessage(patient, patientDO.getName(), consult.getTitle(), content, consult.getImages(), "");
        /**
         * 创建议题
         */
        JSONObject imResponseJson = imUtill.createTopics(sessionId, consult.getId(), content, participants, messages, ImUtil.SESSION_TYPE_ONDOOR_NURSING);
        System.out.println("创建议题成功了!!!!!!!!!!!!!!!!");
        if (imResponseJson == null || imResponseJson.getString("status").equals("-1")) {
            String failMsg = "发起服务咨询时:IM" + imResponseJson.getString("message");
            throw new Exception(failMsg);
        }
        if (imResponseJson != null && imResponseJson.get("start_msg_id") != null) {
            consultTeam.setStartMsgId(imResponseJson.get("start_msg_id").toString());
        }
        System.out.println("准备保存consultTeam和consult");
        consultTeamDao.save(consultTeam);
        consultDao.save(consult);
        System.out.println("保存的consultTeam==>"+ JSON.toJSONString(consultTeam));
        System.out.println("保存的consult==>"+ JSON.toJSONString(consult));
        System.out.println("保存consultTeam和consult成功");
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg, consultTeam);
        return result;
@ -2179,6 +2181,10 @@ public class ConsultTeamService extends ConsultService {
        return consultTeamDao.findByConsult(code);
    }
    public ConsultTeamDo findById(String id) {
        return consultTeamDao.findById(id).orElse(null);
    }
    /**
     * 三师咨询转接医生
     *
@ -2323,7 +2329,7 @@ public class ConsultTeamService extends ConsultService {
//        }
//
//        String content = "进入了咨询";
//        BasePatientDO  p = patientDao.findById(patient).orElse(null);
//        BasePatientDO  p = patientDao.findById(patient);
//        String intoUserName = p.getName();
//        if (patient.equals(agent)) {
//            content = intoUserName + content;
@ -2396,7 +2402,7 @@ public class ConsultTeamService extends ConsultService {
//    public void addForHelpTeamConsult(ConsultTeamDo ct, String uid, String oldConsultCode) throws Exception {
//        // 设置患者信息
//        ct.setPatient(uid);
//        BaseDoctorDO doctorTemp = doctorDao.findById(uid).orElse(null);
//        BaseDoctorDO doctorTemp = doctorDao.findById(uid);
//        // 设置医生姓名
//        ct.setName(doctorTemp.getName());
//        // 设置医生生日
@ -2554,7 +2560,7 @@ public class ConsultTeamService extends ConsultService {
//                    }
//                }
//            }
//            BaseDoctorDO doctorTemp = doctorDao.findById(ct.getDoctor()).orElse(null);
//            BaseDoctorDO doctorTemp = doctorDao.findById(ct.getDoctor());
//            JSONObject qiuzuObj = new JSONObject();
//            qiuzuObj.put("session_id", oldConsult.getPatient() + "_consult_" + oldConsult.getType());
//            qiuzuObj.put("patient", ct.getPatient());
@ -3049,20 +3055,21 @@ public class ConsultTeamService extends ConsultService {
    /**
     * 根据续方code获取咨询
     */
//    public ConsultTeamDo getConsultStatus(String prescriptionCode) {
//        Prescription prescription = prescriptionDao.findByCode(prescriptionCode);
    public ConsultTeamDo getConsultStatus(String prescriptionCode) {
        //先注释掉
//        WlyyPrescriptionDO prescription = prescriptionDao.findByCode(prescriptionCode);
//        if (prescription != null) {
//            return consultTeamDao.findByConsult(prescription.getConsult());
//        }
//        return null;
//    }
        return null;
    }
    /**
     * pcim 使用
     */
    public com.alibaba.fastjson.JSONObject getSessionId(String patient) {
        com.alibaba.fastjson.JSONObject re = new com.alibaba.fastjson.JSONObject();
    public JSONObject getSessionId(String patient) {
        JSONObject re = new JSONObject();
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT a. STATUS, t.session_id FROM wlyy_consult_team a,  ");
        sql.append(imdb).append(".topics t WHERE a.patient = '").append(patient).append("' ");
@ -3107,7 +3114,7 @@ public class ConsultTeamService extends ConsultService {
     * 返回json
     */
    public String getMessageById(String sessionType, String content, String title) {
        com.alibaba.fastjson.JSONObject re = new com.alibaba.fastjson.JSONObject();
        JSONObject re = new JSONObject();
        re.put("title", title);
        content = "'" + content.replace(",", "','") + "'";
        String tableName = "";
@ -3130,7 +3137,7 @@ public class ConsultTeamService extends ConsultService {
        com.alibaba.fastjson.JSONArray ja = new com.alibaba.fastjson.JSONArray();
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = list.get(i);
            com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
            JSONObject json = new JSONObject();
            json.put("id", map.get("id"));
            json.put("session_id", map.get("session_id"));
            json.put("sender_id", map.get("sender_id"));
@ -3327,38 +3334,41 @@ public class ConsultTeamService extends ConsultService {
    /**
     * 根据关联业务code查询咨询记录 wlyyDoorServiceOrderService.queryOneDetail(consult.getRelationCode());
     */
//    public ConsultTeamDo queryByRelationCode(String relationCode) {
//        if (StringUtils.isEmpty(relationCode)) {
//            return null;
//        }
//        ConsultTeamDo consultTeam = consultTeamDao.queryByRelationCode(relationCode);
//        return consultTeam;
//    }
    public ConsultTeamDo queryByRelationCode(String relationCode) {
        if (StringUtils.isEmpty(relationCode)) {
            return null;
        }
        ConsultTeamDo consultTeam = consultTeamDao.queryByRelationCode(relationCode);
        return consultTeam;
    }
    /**
     * 根据咨询查关联业务记录
     */
//    public com.alibaba.fastjson.JSONObject queryByConsultCode(String code, Integer type) {
//        com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
//        if (StringUtils.isEmpty(code) || null == type) {
//            return null;
//        }
//        Consult consult = consultDao.queryByCodeAndType(code, type);
//
//        if (null == consult) {
//            result.put("data", "");
//            return result;
//        }
//
//        if (type == 11) {
//            WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(consult.getRelationCode());
//            com.alibaba.fastjson.JSONObject patientInfo = wlyyDoorServiceOrderService.queryOrderCardInfo(orderDO);
//            result.put("data", patientInfo);
//        }
//
//        result.putIfAbsent("data", consult);
//        return result;
//    }
    public JSONObject queryByConsultCode(String code, Integer type) {
        JSONObject result = new JSONObject();
        if (StringUtils.isEmpty(code) || null == type) {
            return null;
        }
        //这是id
        ConsultDo consult = consultDao.queryByIdAndType(code, type);
//        ConsultDo consult = consultDao.findByRelationCode(code);
        if (null == consult) {
            result.put("data", "");
            return result;
        }
        if (type == 11) {
            WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findById(consult.getRelationCode()).orElse(null);
            JSONObject patientInfo = wlyyDoorServiceOrderService.queryOrderCardInfo(orderDO);
            result.put("data", patientInfo);
        }
        result.putIfAbsent("data", consult);
        return result;
    }
    public org.json.JSONObject updateIMMsg(String sessionId, String sessionType, String msgId, String content) {
        org.json.JSONObject result = new org.json.JSONObject();
@ -3483,5 +3493,4 @@ public class ConsultTeamService extends ConsultService {
//    }
}

+ 100 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/district/controller/DistrictController.java

@ -0,0 +1,100 @@
package com.yihu.jw.hospital.module.district.controller;
import com.yihu.jw.hospital.module.district.service.DistrictService;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
 * 省市区三级地址控制类
 *
 * @author George
 */
@Controller
@RequestMapping(value = "common", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DistrictController extends EnvelopRestEndpoint {
    @Autowired
    private DistrictService districtService;
    @Autowired
    HttpServletRequest request;
    /**
     * 获取人群分类
     */
    @RequestMapping(value = "getProfessionalDict", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("职业状态字典")
    public String getProfessionalDict() {
        try {
            // 获取医生下的患者
            return write(200, "获取成功!", "data", districtService.getProfessionalDict());
        } catch (Exception e) {
            return error(-1, "获取字典信息失败!");
        }
    }
    @RequestMapping(value = "getNationDict",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取民族信息列表")
    public String getNationDict(){
        try {
            // 获取医生下的患者
            return write(200, "获取成功!", "data",districtService.getNationDict());
        } catch (Exception e) {
            return error(-1, "获取字典信息失败!");
        }
    }
    /**
     * 省市一二三级查询接口
     *
     * @param type 1一级目录,2二级目录,3三级目录,4街道目录
     * @param code 省或市标识
     * @return
     */
    @RequestMapping(value = "district")
    @ResponseBody
    public String district(int type, String code) {
        try {
            List<?> list = districtService.findByType(type, code);
            return write(200, "查询成功!", "list", list);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
        }
    }
    /**
     * 省市一二三级查询接口(包含权限控制)
     *
     * @param type 1一级目录,2二级目录,3三级目录,4街道目录
     * @param code 省或市标识
     * @return
     */
    @RequestMapping(value = "districtAuthority")
    @ResponseBody
    public String districtAuthority(int type, String code) {
        try {
            List<Map<String, String>> roleMap = (List<Map<String, String>>) request.getSession().getAttribute("roleMap");
            List<?> list = districtService.findByType(type, code, roleMap);
            return write(200, "查询成功!", "list", list);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
        }
    }
}

+ 249 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/district/service/DistrictService.java

@ -0,0 +1,249 @@
package com.yihu.jw.hospital.module.district.service;
import com.yihu.jw.area.dao.BaseCityDao;
import com.yihu.jw.area.dao.BaseProvinceDao;
import com.yihu.jw.area.dao.BaseStreetDao;
import com.yihu.jw.area.dao.BaseTownDao;
import com.yihu.jw.entity.base.area.BaseCityDO;
import com.yihu.jw.entity.base.area.BaseProvinceDO;
import com.yihu.jw.entity.base.area.BaseStreetDO;
import com.yihu.jw.entity.base.area.BaseTownDO;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
 * 省市区三级业务处理类
 *
 * @author George
 */
@Service
public class DistrictService extends EnvelopRestEndpoint {
    @Autowired
    private BaseProvinceDao provinceDao;
    @Autowired
    private BaseCityDao cityDao;
    @Autowired
    private BaseTownDao townDao;
    @Autowired
    private BaseStreetDao streetDao;
    @Autowired
    JdbcTemplate jdbcTemplate;
    /**
     * 查询省市区三级目录
     *
     * @param type 1一级目录,2二级目录,3三级目录,4街道目录
     * @param code 目录标识
     * @return
     */
    public List<?> findByType(int type, String code) {
        switch (type) {
            case 1:
                return findProvince();
            case 2:
                return findCity(code);
            case 3:
                return findTown(code);
            case 4:
                return findStreet(code);
        }
        return null;
    }
    /**
     * 查询省市区三级目录
     *
     * @param type 1一级目录,2二级目录,3三级目录,4街道目录
     * @param code 目录标识
     * @return
     */
    public List<?> findByType(int type, String code, List<Map<String, String>> roleMap) {
        switch (type) {
            case 1:
                return findProvince();
            case 2:
                return findCity(code);
            case 3:
                return findTown(code, roleMap);
            case 4:
                return findStreet(code);
        }
        return null;
    }
    /**
     * 查询所有的省份信息
     *
     * @return
     */
    public List<BaseProvinceDO> findProvince() {
        List<BaseProvinceDO> list = new ArrayList<BaseProvinceDO>();
        Iterable<BaseProvinceDO> iterable = provinceDao.findAll(Sort.by(Direction.ASC, "id"));
        if (iterable != null) {
            Iterator<BaseProvinceDO> it = iterable.iterator();
            while (it != null && it.hasNext()) {
                list.add(it.next());
            }
        }
        return list;
    }
    /**
     * 查询省份下的城市信息
     *
     * @param province 省编码
     * @return
     */
    public List<BaseCityDO> findCity(String province) {
        List<BaseCityDO> list = new ArrayList<BaseCityDO>();
        Iterable<BaseCityDO> iterable = cityDao.findByProvince(province);
        if (iterable != null) {
            Iterator<BaseCityDO> it = iterable.iterator();
            while (it != null && it.hasNext()) {
                list.add(it.next());
            }
        }
        return list;
    }
    /**
     * 查询城市下的区县信息
     *
     * @param city 城市编码
     * @return
     */
    public List<BaseTownDO> findTown(String city) {
        List<BaseTownDO> list = new ArrayList<BaseTownDO>();
        Iterable<BaseTownDO> iterable = townDao.findByCity(city);
        if (iterable != null) {
            Iterator<BaseTownDO> it = iterable.iterator();
            while (it != null && it.hasNext()) {
                list.add(it.next());
            }
        }
        return list;
    }
    /**
     * 查询城市下的区县信息(包含权限控制)
     *
     * @param city 城市编码
     * @return
     */
    public List<BaseTownDO> findTown(String city, List<Map<String, String>> roleMap) {
        List<BaseTownDO> list = new ArrayList<BaseTownDO>();
        Iterable<BaseTownDO> iterable = townDao.findByCity(city);
        if (iterable != null) {
            String areaString = "";
            Boolean cityFlag = false;
            for (Map<String, String> map : roleMap) {
                String code = map.get("code");
                if ("350200".equals(code)) {
                    cityFlag = true;
                    break;
                } else if (code.length() == 6) {
                    areaString += map.get("areas") + ",";
                }
            }
            Iterator<BaseTownDO> it = iterable.iterator();
            while (it != null && it.hasNext()) {
                BaseTownDO town = it.next();
                String townCode = town.getCode();
                if (cityFlag) {
                    list.add(town);
                } else {
                    if (areaString.indexOf(townCode) >= 0) {
                        list.add(town);
                    }
                }
            }
        }
        return list;
    }
    /**
     * 查询城市下的街道信息
     *
     * @param town 区县编码
     * @return
     */
    public List<BaseStreetDO> findStreet(String town) {
        List<BaseStreetDO> list = new ArrayList<BaseStreetDO>();
        Iterable<BaseStreetDO> iterable = streetDao.findByTown(town);
        if (iterable != null) {
            Iterator<BaseStreetDO> it = iterable.iterator();
            while (it != null && it.hasNext()) {
                list.add(it.next());
            }
        }
        return list;
    }
//    /**
//     * 查询城市下的街道信息
//     *
//     * @param street 街道编码
//     * @return
//     */
//    public List<Country> findCountry(String street) {
//        List<Country> list = new ArrayList<Country>();
//        Iterable<Country> iterable = countryDao.findByStreet(street);
//        if (iterable != null) {
//            Iterator<Country> it = iterable.iterator();
//            while (it != null && it.hasNext()) {
//                list.add(it.next());
//            }
//        }
//        return list;
//    }
    public BaseProvinceDO findProvinceByName(String name) {
        return provinceDao.findByName(name);
    }
    public BaseCityDO findCityByName(String name) {
        return cityDao.findByName(name);
    }
    public BaseTownDO finTownByName(String name) {
        return townDao.findByName(name);
    }
    public BaseTownDO finTownByNameAndCity(String name, String city) {
        return townDao.findByNameAndCity(name, city);
    }
    public BaseStreetDO findStreetByName(String name) {
        return streetDao.findByName(name);
    }
    public List<Map<String, Object>> getProfessionalDict() {
        String sql = "SELECT t.dict_code 'code',t.dict_value `value` FROM `base`.`wlyy_hospital_sys_dict`  t WHERE t.dict_name='PROFESSIONAL_STATE'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    public List<Map<String, Object>> getNationDict() {
        String sql = "SELECT t.NATION_CODE,t.NATION_NAME FROM zy_nation_dict t ";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
}

+ 2 - 5
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/controller/DoorOrderController.java

@ -368,7 +368,6 @@ public class DoorOrderController extends EnvelopRestEndpoint {
    }
    @GetMapping("/topStatusBarNum")
    @ApiOperation(value = "顶部状态栏订单分类tab")
    public Envelop topStatusBarNum(
@ -988,9 +987,6 @@ public class DoorOrderController extends EnvelopRestEndpoint {
    }
    @PostMapping(value = "updateServiceStatus")
    @ApiOperation(value = "更新预约服务项目类型")
@ -1378,7 +1374,8 @@ public class DoorOrderController extends EnvelopRestEndpoint {
                doorServiceOrderDO.getIsPatientConfirm();//当前状态
                Integer success = doorOrderService.sendInformedConsent(orderId, doorServiceOrderDO.getServeDesc(), doctor);
                wlyyDoorServiceOrderService.orderMsgTask(orderId);
                //微信模板信息
                //wlyyDoorServiceOrderService.orderMsgTask(orderId);
                if (success == 1) {
                    return success("知情同意书推送成功", doorServiceOrderDO);
                } else {

+ 14 - 7
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/controller/WlyyDoorServiceOrderController.java

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.hospital.module.door.service.DoorOrderService;
import com.yihu.jw.hospital.module.door.service.WlyyDoorPrescriptionService;
import com.yihu.jw.hospital.module.door.service.WlyyDoorServiceOrderService;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
@ -31,7 +32,8 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
    @Autowired
    private WlyyDoorServiceOrderService wlyyDoorServiceOrderService;
    @Autowired
    private ImUtil imUtil;
    @Autowired
    private DoorOrderService doorOrderService;
@ -187,10 +189,15 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
//        }else {
//            return failed("获取二维码失败,请确认工单",-1);
//        }
        if (wlyyDoorServiceOrderService.twoDimensionalCode(id, null) != null) {
            return success("获取二维码成功", 200, wlyyDoorServiceOrderService.twoDimensionalCode(id, null));
        } else {
            return failed("获取二维码失败,请确认工单", -1);
        try {
            if (wlyyDoorServiceOrderService.twoDimensionalCode(id, null) != null) {
                return success("获取二维码成功", 200, wlyyDoorServiceOrderService.twoDimensionalCode(id, null));
            } else {
                return failed("获取二维码失败,请确认工单", -1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }
@ -262,6 +269,7 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
            @ApiParam(name = "reason", value = "取消理由") @RequestParam(value = "reason", required = true) String reason) {
        JSONObject result = new JSONObject();
        try {
            System.out.println("取消工单--参数orderId:" + orderId);
            result = wlyyDoorServiceOrderService.cancelOrder(orderId, 2, reason, null, null);
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return failed(result.getString(ResponseContant.resultMsg));
@ -272,10 +280,9 @@ public class WlyyDoorServiceOrderController extends EnvelopRestEndpoint {
        }
        return success(result.get(ResponseContant.resultMsg));
    }
    @GetMapping(value = "queryDoctorList")
    @ApiOperation(value = "服务人员列表(医生列表)")
    public PageEnvelop queryDoctorList(

+ 27 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/dao/ServiceItemPlanDao.java

@ -0,0 +1,27 @@
package com.yihu.jw.hospital.module.door.dao;
import com.yihu.jw.entity.base.servicePackage.ServiceItemPlanDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
/**
 * Created by yeshijie on 2023/10/28.
 */
public interface ServiceItemPlanDao extends PagingAndSortingRepository<ServiceItemPlanDO, String>, JpaSpecificationExecutor<ServiceItemPlanDO> {
    @Query("from ServiceItemPlanDO w where w.signId =?1 ")
    List<ServiceItemPlanDO> findBySignId(String signId);
    @Query(value = "select * from base_service_item_plan w where w.sign_id =?1 and w.service_item_id=?2 order by w.plan_time desc", nativeQuery = true)
    List<ServiceItemPlanDO> findBySignIdAndServiceItemId(String signId, String serviceItemId);
    @Modifying
    @Query(value ="UPDATE  base_service_item_plan SET status='1' ,complete_time=?3 WHERE status='0' AND sign_id=?1 AND service_pack_id=?2 ORDER BY plan_time DESC LIMIT 1", nativeQuery = true)
    void updateState(String signId, String packageId, Date date);
}

+ 203 - 159
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/service/DoorOrderService.java

@ -1,5 +1,6 @@
package com.yihu.jw.hospital.module.door.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -8,22 +9,25 @@ import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.im.ConsultDo;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.servicePackage.ServicePackageSubItemDO;
import com.yihu.jw.entity.base.system.SystemDictDO;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.entity.door.*;
import com.yihu.jw.entity.ehr.dict.SystemDict;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.wechat.WechatTemplateConfig;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.hospital.module.door.dao.*;
import com.yihu.jw.hospital.module.wx.dao.WechatTemplateConfigDao;
import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.order.dao.ConsultTeamOrderDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
import jxl.Workbook;
import jxl.write.*;
import org.apache.commons.collections.CollectionUtils;
@ -63,9 +67,9 @@ public class DoorOrderService {
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Value("${sign.check_upload}")
    //    @Value("${sign.check_upload}")
    private String jwUrl;
    @Value("${server.server_url}")
    //    @Value("${server.server_url}")
    private String wxServerUrl;
    //图片服务地址
    @Value("${fastDFS.fastdfs_file_url}")
@ -118,8 +122,8 @@ public class DoorOrderService {
    private ConsultDao consultDao;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
//    @Autowired
    private WxTemplateConfigDao wxTemplateConfigDao;
    //    @Autowired
//    private HttpUtil httpUtil;
    @Autowired
    private WlyyDoorCommentDao doorCommentDao;
@ -129,13 +133,53 @@ public class DoorOrderService {
    @Autowired
    WeiXinAccessTokenUtils tokenUtils;
//    @Autowired
//    private SignFamilyDao signFamilyDao;
//    @Autowired
//    private ServerPackageItemPatientDao serverPackageItemPatientDao;
//    @Autowired
//    private DmJobService dmJobService;
    @Autowired
    BasePatientDao basePatientDao;
    @Autowired
    ServiceItemPlanDao serviceItemPlanDao;
    /**
     * 服务项查询
     *
     * @param signId 签约id
     * @param type   doorService 上门服务
     */
    public PageEnvelop getServiceItem(String signId, String name, String type, Integer page, Integer size) {
//        String sql = "SELECT si.* ";
//        String countSql = "select count(si.id) ";
//        String filter = " from base_service_package_sign_record r," +
//                "base_service_package_item i,base_service_package_sub_item si,base_service_package_item_relational ir " +
//                "WHERE r.id = '"+signId+"' and i.service_package_id=r.service_package_id and i.`code`='"+type+"' and si.status='1' " +
//                " and i.id = ir.item_id and ir.sub_item_id= si.id ";
//        if(StringUtils.isNotBlank(name)){
//            filter += " and si.name like '%"+name+"%' ";
//        }
//        String oderBy = " order by si.sort limit "+(page-1)*size+","+size;
        String sql = "SELECT e.* ";
        String countSql = "select count(e.id) ";
        String filter =
                "FROM\n" +
                        "	base_service_package_sign_record a \n" +
                        "	INNER JOIN base_service_package_item b ON a.service_package_id = b.service_package_id\n" +
                        "	INNER JOIN base_service_package_item c ON c.id=b.service_package_item_id\n" +
                        "	INNER JOIN base_service_package_item_relational d ON d.item_id=c.id \n" +
                        "	INNER JOIN base_service_package_sub_item e ON e.id=d.sub_item_id\n" +
                        "WHERE 1=1\n" +
                        "	AND b.`code` = '" + type + "' \n" +
                        "	AND e.`status` = '1' \n" +
                        "	AND a.id = '" + signId + "' ";
        if (StringUtils.isNotBlank(name)) {
            filter += " and e.name like '%" + name + "%' ";
        }
        String oderBy = " order by e.sort limit " + (page - 1) * size + "," + size;
        sql = sql + filter + oderBy;
        countSql = countSql + filter;
        List<ServicePackageSubItemDO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ServicePackageSubItemDO.class));
        long count = jdbcTemplate.queryForObject(countSql, Long.class);
        return PageEnvelop.getSuccessListWithPage("", list, page, size, count);
    }
    public Map<String, String> getNumGroupByStatusTeam(String doctor, Integer type) {
        String sql = "SELECT a.status, COUNT(DISTINCT a.id) as num FROM wlyy_door_service_order a ";
@ -361,7 +405,8 @@ public class DoorOrderService {
     * @return
     */
    public List<Map<String, Object>> getDoorFeeDetailGroupByStatus(String orderId) {
        String sql = "SELECT d.id, d.status,d.name,d.code,sum(d.number) num,fee,sum(d.number)*fee sum from wlyy_door_fee_detail d where order_id=? and type=1 GROUP BY status,code";
        String sql = "SELECT d.id, d.status,d.name,d.code,sum(d.number) num,fee,sum(d.number)*fee sum " +
                " from wlyy_door_fee_detail d where order_id=? and type=1 GROUP BY status,code";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, orderId);
        return list;
    }
@ -373,7 +418,8 @@ public class DoorOrderService {
     * @return
     */
    public List<Map<String, Object>> getDoorServiceDoctor(String orderId) {
        String sql = "SELECT dd.id as id,CONCAT(d.`name`,' (',dd.doctor_job_name,')') as name, dd.doctor from wlyy_door_doctor dd join wlyy_doctor d on d.`code` = dd.doctor WHERE order_id=?";
        String sql = "SELECT dd.id as id,CONCAT(d.`name`,' (',dd.doctor_job_name,')') as name, " +
                "dd.doctor from wlyy_door_doctor dd join base_doctor d on d.`id` = dd.doctor WHERE order_id=?";
        List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql, orderId);
        return mapList;
    }
@ -385,7 +431,7 @@ public class DoorOrderService {
     * @return
     */
    public WlyyDoorServiceOrderDO getDoorServiceOrderById(String id, Integer level) throws Exception {
        WlyyDoorServiceOrderDO doorServiceOrder = this.doorServiceOrderDao.findById(null).orElse(null);
        WlyyDoorServiceOrderDO doorServiceOrder = this.doorServiceOrderDao.findById(id).orElse(null);
        if (null == doorServiceOrder) {
            return null;
        }
@ -397,7 +443,7 @@ public class DoorOrderService {
            doorServiceOrder.setAge(age);
            doorServiceOrder.setPhoto(patient.getPhoto());
//            String typeValues = this.getTypeValueByPatientCode(patient.getCode());
           String typeValues = this.getTypeValueByPatientCode(patient.getId());
            String typeValues = this.getTypeValueByPatientCode(patient.getId());
            doorServiceOrder.setTypeValue(typeValues);
        }
        // 获取服务次数
@ -405,7 +451,7 @@ public class DoorOrderService {
        Integer times = wlyyDoorServiceOrderService.countPatientDoorTimes(doorServiceOrder.getPatient());
        //先注释-服务费用20231011
//        List<WlyyDoorDoctorDO> djDetailList = this.djDetailList(id, level, times);
//        doorServiceOrder.setDjDetailList(djDetailList);
//       doorServiceOrder.setDjDetailList(djDetailList);//出诊费
        List<Map<String, Object>> feeDetailDOS = this.getDoorFeeDetailGroupByStatus(id);
        String jsonData = this.serverPackagePriceByOrderId(id);
        if (null != feeDetailDOS && feeDetailDOS.size() > 0) {
@ -414,7 +460,7 @@ public class DoorOrderService {
            //计算扣服务包后应付的服务项费用
            /*Map<String, Object> map = this.countServerPackagePrice(jsonData, doorServiceOrder.getPatient());
            BigDecimal cashPrice = this.calculateCash(String.valueOf(map.get("cashPrice")), id, level, times);
            WlyyDoorServiceOrderDO wlyyDoorServiceOrderDO = this.doorServiceOrderDao.findById(null).orElse(null);
            WlyyDoorServiceOrderDO wlyyDoorServiceOrderDO = this.doorServiceOrderDao.findById(null);
            if(wlyyDoorServiceOrderDO.getTotalFee()!=cashPrice){
                wlyyDoorServiceOrderDO.setTotalFee(cashPrice);
                wlyyDoorServiceOrderService.save(wlyyDoorServiceOrderDO);
@ -428,12 +474,12 @@ public class DoorOrderService {
        if (null != doorServiceDoctors && doorServiceDoctors.size() > 0) {
            doorServiceOrder.setDoctors(doorServiceDoctors);
        }
        System.out.println("准备获取咨询==>参数:" + id);
        //获取咨询
        ConsultDo consult = consultDao.queryByRelationCode(id);
        System.out.println("consult==>" + JSON.toJSONString(consult));
        if (null != consult) {
            doorServiceOrder.setSessionId(doorServiceOrder.getPatient() + "_" + consult.getCode() + "_" + doorServiceOrder.getNumber() + "_" + consult.getType());
            doorServiceOrder.setSessionId(doorServiceOrder.getPatient() + "_" + consult.getId() + "_" + doorServiceOrder.getNumber() + "_" + consult.getType());
        }
        // 设置服务小结
@ -443,7 +489,7 @@ public class DoorOrderService {
        }
        doorConclusion.setServiceCount(count);
        doorServiceOrder.setDoorConclusion(doorConclusion);
        System.out.println("获取上门前后开方详情");
        //获取上门前后开方详情
        List<WlyyDoorPrescriptionDO> doorBeforePrescriptionDOList = doorPrescriptionDao.findByOrderIdAndIsAfterDoor(id, 1);
        List<WlyyDoorPrescriptionDO> doorAfterPrescriptionDOList = doorPrescriptionDao.findByOrderIdAndIsAfterDoor(id, 2);
@ -523,32 +569,37 @@ public class DoorOrderService {
     * @throws Exception
     */
    public WlyyDoorConclusionDO updateDoorConclusion(String model, Integer examPapeStatus) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
        WlyyDoorConclusionDO doorConclusion = objectMapper.readValue(model, WlyyDoorConclusionDO.class);
        WlyyDoorServiceOrderDO one = doorServiceOrderDao.findById(doorConclusion.getOrderId()).orElse(null);
        BaseDoctorDO doctorVO = doctorDao.findById(one.getDoctor()).orElse(null);
        if (doorConclusion != null && StringUtils.isNotEmpty(doorConclusion.getId())) {
            doorConclusion.setUpdateTime(new Date());
            doorConclusion.setUpdateUser(one.getDoctor());
            doorConclusion.setUpdateUserName(null != doctorVO ? doctorVO.getName() : null);
        } else {
            doorConclusion.setCreateTime(new Date());
            doorConclusion.setUpdateTime(new Date());
            doorConclusion.setCreateUser(one.getDoctor());
            doorConclusion.setCreateUserName(null != doctorVO ? doctorVO.getName() : null);
        }
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
            WlyyDoorConclusionDO doorConclusion = objectMapper.readValue(model, WlyyDoorConclusionDO.class);
            WlyyDoorServiceOrderDO one = doorServiceOrderDao.findById(doorConclusion.getOrderId()).orElse(null);
            BaseDoctorDO doctorVO = doctorDao.findById(one.getDoctor()).orElse(null);
            if (doorConclusion != null && StringUtils.isNotEmpty(doorConclusion.getId())) {
                doorConclusion.setUpdateTime(new Date());
                doorConclusion.setUpdateUser(one.getDoctor());
                doorConclusion.setUpdateUserName(null != doctorVO ? doctorVO.getName() : null);
            } else {
                doorConclusion.setCreateTime(new Date());
                doorConclusion.setUpdateTime(new Date());
                doorConclusion.setCreateUser(one.getDoctor());
                doorConclusion.setCreateUserName(null != doctorVO ? doctorVO.getName() : null);
            }
        //服务时间 为空的 默认使用医生签到时间 1.7.0.5修改
        if (null == doorConclusion.getServiceTime() || StringUtils.isBlank(doorConclusion.getServiceTime().toString())) {
            doorConclusion.setServiceTime(one.getDoctorSignTime());
            //服务时间 为空的 默认使用医生签到时间 1.7.0.5修改
            if (null == doorConclusion.getServiceTime() || StringUtils.isBlank(doorConclusion.getServiceTime().toString())) {
                doorConclusion.setServiceTime(one.getDoctorSignTime());
            }
            doorConclusionDao.save(doorConclusion);
            // 设置是否需要上传补录报告
            one.setExamPaperStatus(examPapeStatus);
            one.setConclusionStatus(2);
            doorServiceOrderDao.save(one);
            return doorConclusion;
        } catch (IOException e) {
            e.printStackTrace();
        }
        doorConclusionDao.save(doorConclusion);
        // 设置是否需要上传补录报告
        one.setExamPaperStatus(examPapeStatus);
        one.setConclusionStatus(2);
        doorServiceOrderDao.save(one);
        return doorConclusion;
        return null;
    }
    public WlyyDoorServiceOrderDO acceptOrder1(String orderId, String jobCode, String jobCodeName, int hospitalLevel) throws Exception {
@ -577,7 +628,7 @@ public class DoorOrderService {
            return null;
        }
        doorServiceOrderDao.save(doorServiceOrder);
        //删除407的消息
        systemMessageDao.orderMessageDel(doorServiceOrder.getDoctor(), orderId);
        if (doorServiceOrder.getType() == null || doorServiceOrder.getType() != 3) {
@ -591,12 +642,12 @@ public class DoorOrderService {
            //成功创建服务工单后,居民所在机构调度员向居民发起一条通知服务消息
            // 发送IM消息通知患者医生已接单
            String noticeContent = "我已接受您的服务工单预约," + doorServiceOrder.getDoctorName() + "医生正在为您服务!";
            wlyyDoorServiceOrderService.qucikSendIM(doorServiceOrder.getId(), doorServiceOrder.getDispatcher(), "智能助手", "1", noticeContent);
            String noticeContent = "已接受您的服务工单预约," + doorServiceOrder.getDoctorName() + "医生正在为您服务!";
            wlyyDoorServiceOrderService.qucikSendIM(doorServiceOrder.getId(), doorServiceOrder.getDoctor(), "智能助手", "1", noticeContent);
            // 发送居民上门服务简要信息
            JSONObject orderInfoContent = wlyyDoorServiceOrderService.queryOrderCardInfo(doorServiceOrder);
            orderInfoContent.put("re_msg_type", 0);
            wlyyDoorServiceOrderService.qucikSendIM(doorServiceOrder.getId(), doorServiceOrder.getDispatcher(), "智能助手", "2101", orderInfoContent.toJSONString());
            wlyyDoorServiceOrderService.qucikSendIM(doorServiceOrder.getId(), doorServiceOrder.getDoctor(), "智能助手", "2101", orderInfoContent.toJSONString());
        }
        return doorServiceOrder;
    }
@ -607,17 +658,18 @@ public class DoorOrderService {
     * @param orderId
     */
    public void acceptOrder(String orderId, String jobCode, String jobCodeName, int hospitalLevel) throws Exception {
        //接单和发送消息
        WlyyDoorServiceOrderDO doorServiceOrder = acceptOrder1(orderId, jobCode, jobCodeName, hospitalLevel);
        if (doorServiceOrder == null) {
            return;
        }
        
        // 发送微信模板消息通知患者医生已接单
        BasePatientDO patient = patientService.findPatientById(doorServiceOrder.getPatient());
        // 获取微信模板
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        try {
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback", "smyyyjjd");
            WxTemplateConfigDO templateConfig = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndScene("xm_test_ihealth_wx", "template_process_feedback", "smyyyjjd");
            String first = templateConfig.getFirst();
            first = first.replace("key1", (patient.getName() == null ? "" : patient.getName()));
            first = first.replace("key2", null != doorServiceOrder.getDoctorName() ? doorServiceOrder.getDoctorName() : "");
@ -629,7 +681,7 @@ public class DoorOrderService {
            json.put("url", templateConfig.getUrl());
            json.put("remark", templateConfig.getRemark());
            if (consult != null) {
                json.put("consult", consult.getCode());
                json.put("consult", consult.getId());
            }
            logger.info("上门服务已接单推送前");
            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 30, patient.getOpenid(), patient.getName(), json);
@ -638,7 +690,7 @@ public class DoorOrderService {
            logger.error(e.getMessage());
        }
        //  待接单消息设为已操作, 434 医生接单-- 王五接受了服务工单12345678
        //  待接单消息设为已操作, 434 医生接单-- 王五接受了服务工单12345678 ----407在上门已经删除了,这快代码其实没啥用
        List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId, new String[]{"403", "407"});
        if (CollectionUtils.isEmpty(messages)) {
            logger.error("当前工单没有医生待接单消息!orderId:" + orderId);
@ -663,10 +715,6 @@ public class DoorOrderService {
    /**
     * 拒单
     *
     * @param orderId
     * @param reason
     * @throws Exception
     */
    public void refuseOrder(String receiver, String orderId, String reason) throws Exception {
        WlyyDoorServiceOrderDO doorServiceOrder = doorServiceOrderDao.findById(orderId).orElse(null);
@ -678,16 +726,18 @@ public class DoorOrderService {
//            this.createMessage(doorServiceOrder.getId(), "system", doorServiceOrder.getProxyPatient(), 403, "代预约服务工单重新派单", doorServiceOrder.getPatientName() + "的代预约服务工单需重新派单,请您前往处理");
            //2021-12-29 代预约医生拒单直接取消
            doorServiceOrder.setStatus(WlyyDoorServiceOrderDO.Status.cancel.getType());
            doorServiceOrder.setCancelReason(reason);   // 拒绝原因
            doorServiceOrder.setCancelReason(reason);// 拒绝原因
            doorServiceOrder.setCancelTime(new Date());
            doorServiceOrderDao.save(doorServiceOrder);
        } else {
            //删除消息
            this.systemMessageDao.orderMessageDel(doorServiceOrder.getDoctor(), orderId);
            //有调度员
            if (StringUtils.isNotBlank(doorServiceOrder.getDispatcher())) {
                // 派单消息
                this.createMessage(doorServiceOrder.getId(), "system", doorServiceOrder.getDispatcher(), 404, "服务工单拒单待重新派单", doorServiceOrder.getDoctorName() + "拒绝了" + doorServiceOrder.getProxyPatientName() + "的服务预约申请,请重新派单");
                //  调度员-派单-实时工单消息:435 医生拒单-- 王五拒绝了服务工单12345678
                // 调度员-派单-实时工单消息:435 医生拒单-- 王五拒绝了服务工单12345678
                List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId, new String[]{"431", "433"});
                if (CollectionUtils.isEmpty(messages)) {
                    logger.error("当前工单没有医生待接单消息!orderId:" + orderId);
@ -713,11 +763,6 @@ public class DoorOrderService {
    /**
     * 添加【工单派单,转单】等系统消息
     *
     * @param orderId
     * @param sender
     * @param receiver
     * @param Content
     */
    public void createMessage(String orderId, String sender, String receiver, int type, String title, String Content) {
        SystemMessageDO message = new SystemMessageDO();
@ -850,7 +895,7 @@ public class DoorOrderService {
            object.put("feeDetailResultList", feeDetailResultList);
            // 获取或者基本信息
            
            BasePatientDO patient = patientService.findPatientById(String.valueOf(one.get("patientCode")));
            if (patient != null) {
                String sex = IdCardUtil.getSexForIdcard(patient.getIdcard());
@ -863,11 +908,11 @@ public class DoorOrderService {
                object.put("typeValue", typeValues);
            }
            String id = one.get("orderId").toString();
            WlyyDoorServiceOrderDO doorServiceOrder = this.doorServiceOrderDao.findById(null).orElse(null);
            WlyyDoorServiceOrderDO doorServiceOrder = this.doorServiceOrderDao.findById(id).orElse(null);
            //获取咨询
            ConsultDo consult = consultDao.queryByRelationCode(id);
            if (null != consult) {
                doorServiceOrder.setSessionId(doorServiceOrder.getPatient() + "_" + consult.getCode() + "_" + doorServiceOrder.getNumber() + "_" + consult.getType());
                doorServiceOrder.setSessionId(doorServiceOrder.getPatient() + "_" + consult.getId() + "_" + doorServiceOrder.getNumber() + "_" + consult.getType());
            }
            object.put("sessionId", doorServiceOrder.getSessionId());
@ -909,23 +954,26 @@ public class DoorOrderService {
    public JSONObject getDoorOrderList(String orderId, String patientName, String patientPhone, String hospitalCode,
                                       StringBuffer status, String createTimeStart, String createTimeEnd, String serverDoctorName,
                                       String doctorCode, Integer examPaperStatus, Integer page, Integer pageSize, Integer type, String name, String serverType) throws Exception {
        StringBuilder sqlList = new StringBuilder("select DISTINCT o.id as orderId,o.status,f.hospital,f.hospital_name as hospitalName1,o.is_trans_other_org,o.transed_org_code,h.name as hospitalName2,o.patient_name," +
                " o.patient_phone,o.remark,o.serve_desc,dc.service_time,o.patient as patientCode ,o.exam_paper_status as examPaperStatus,o.number as serverCode,o.total_fee,h.hos_level as hosLevel, " +
                "o.doctor, o.doctor_name as doctorName, o.doctor_type as doctorType ,(SELECT group_concat(DISTINCT dsv.type_value) FROM wlyy_door_service_voucher dsv WHERE dsv.patient_code = o.patient and dsv.status=1 ) AS serviceStatus ");
        StringBuilder sqlList = new StringBuilder(
                "select DISTINCT o.id as orderId,o.status," +
//                        "h.org_name AS hospitalName, " +//这个会重复
                        " h.org_code AS hospital," +
                        "o.is_trans_other_org,o.transed_org_code ,o.patient_name," +
                        " o.patient_phone,o.remark,o.serve_desc,dc.service_time,o.patient as patientCode ," +
                        "o.exam_paper_status as examPaperStatus,o.number as serverCode,o.total_fee, " +
                        " o.doctor, o.doctor_name as doctorName, o.doctor_type as doctorType ," +
                        "(SELECT group_concat(DISTINCT dsv.type_value) " +
                        " FROM wlyy_door_service_voucher dsv WHERE dsv.patient_code = o.patient and dsv.status=1 ) AS serviceStatus ");
        StringBuilder sqlCount = new StringBuilder(" select count(DISTINCT o.id) as total ");
        StringBuilder sql = new StringBuilder(" from wlyy_door_service_order o " +
                " LEFT JOIN wlyy_sign_family f ON f.patient = o.patient AND f.STATUS = 1 AND f.expenses_status = 1 " +
                " LEFT JOIN dm_hospital h on h.code=o.hospital and h.del=1 "
                " LEFT JOIN base_doctor_hospital h ON o.hospital=h.org_code "
                + " LEFT JOIN wlyy_door_doctor d on d.order_id = o.id " +
                " LEFT JOIN wlyy_patient p on p.code = o.patient " +
                " LEFT JOIN base_patient p on p.id = o.patient " +
                " LEFT JOIN wlyy_door_conclusion dc ON dc.order_id = o.id ");
        if (StringUtils.isNotBlank(serverType)) {
            sql.append(" INNER JOIN wlyy_door_service_voucher dsv on dsv.patient_code = o.patient and dsv.type='" + serverType + "' and dsv.status=1 ");
        }
//        if(!StringUtils.isEmpty(serverDoctorName)){
//            sql+=" RIGHT JOIN wlyy_door_doctor d on d.order_id = o.id";
//        }
        sql.append(" where 1=1 ");
        if (!StringUtils.isEmpty(orderId)) {
            sql.append(" and o.number = '" + orderId + "'");
@ -945,9 +993,7 @@ public class DoorOrderService {
        if (status != null) {
            sql.append(" and o.status in (" + status + ")");
        }
        /*else {
            sql += " and o.status != '-1' ";
        }*/
        if (!StringUtils.isEmpty(createTimeStart)) {
            sql.append(" and dc.service_time >='" + createTimeStart + "'");
        }
@ -966,8 +1012,12 @@ public class DoorOrderService {
        if (examPaperStatus != null) {
            sql.append(" and o.conclusion_status='" + examPaperStatus + "' ");
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(sqlCount.append(sql).toString());
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sqlList.append(sql).append(" order by o.create_time desc LIMIT " + (page - 1) * pageSize + "," + pageSize).toString());
        String sql01 = sqlList.append(sql).append(" order by o.create_time desc LIMIT " + (page - 1) * pageSize + "," + pageSize).toString();
        String sql02 = sqlCount.append(sql).toString();
        System.out.println("getDoorOrderList----sql01==>" + sql01);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql01);
        System.out.println("工单的数量list==>" + list.size());
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(sql02);
        Long count = 0L;
        if (rstotal != null && rstotal.size() > 0) {
            count = (Long) rstotal.get(0).get("total");
@ -1063,11 +1113,11 @@ public class DoorOrderService {
                object.put("typeValue", typeValues);
            }
            String id = one.get("orderId").toString();
            WlyyDoorServiceOrderDO doorServiceOrder = this.doorServiceOrderDao.findById(null).orElse(null);
            WlyyDoorServiceOrderDO doorServiceOrder = doorServiceOrderDao.findById(id).orElse(null);
            //获取咨询
            ConsultDo consult = consultDao.queryByRelationCode(id);
            if (null != consult) {
                doorServiceOrder.setSessionId(doorServiceOrder.getPatient() + "_" + consult.getCode() + "_" + doorServiceOrder.getNumber() + "_" + consult.getType());
                doorServiceOrder.setSessionId(doorServiceOrder.getPatient() + "_" + consult.getId() + "_" + doorServiceOrder.getNumber() + "_" + consult.getType());
            }
            object.put("sessionId", doorServiceOrder.getSessionId());
@ -1346,6 +1396,14 @@ public class DoorOrderService {
//        BigDecimal cashPrice = this.calculateCash(String.valueOf(map.get("cashPrice")), orderId, level, times);
//        one.setTotalFee(cashPrice);
        doorServiceOrderDao.save(one);
        //
        String signId = one.getSignId();//签约id
        String packageId = one.getPackageId();//服务包id
        Date date = new Date();
        //更新计划状态为完成
        serviceItemPlanDao.updateState(signId, packageId, date);
        WlyyDoorServiceOrderDO doorServiceOrderDO = this.getDoorServiceOrderById(orderId, level);
        // 发送微信通知  待付款
@ -1353,41 +1411,29 @@ public class DoorOrderService {
        // 获取微信模板 smfwdwk-上门服务待付款
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        try {
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback", "fwyspf");
            String first = templateConfig.getFirst();
            first = first.replace("key1", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm"));
            first = first.replace("key2", null != one.getDoctorName() ? one.getDoctorName() : "");
            org.json.JSONObject json = new org.json.JSONObject();
            json.put("first", first);
            json.put("keyword1", DateUtil.dateToStrShort(new Date()));
            json.put("keyword2", "服务医生评分");
            json.put("url", templateConfig.getUrl());
            json.put("remark", templateConfig.getRemark());
            json.put("id", orderId);
            //json.put("consult",consult.getCode());
            WlyyDoorCommentDO wlyyDoorCommentDO = this.doorCommentDao.selectCommentDoctor(patient.getId(), orderId);
            String finish = "";
            if (wlyyDoorCommentDO != null) {
                finish = "0";
                json.put("finish", finish);
            } else {
                finish = "1";
                json.put("finish", finish);
            }
            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 31, patient.getOpenid(), patient.getName(), json);
            /*WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","smfwdwk");
            String first = templateConfig.getFirst();
            first = first.replace("key1", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm"));
            first = first .replace("key2", null != one.getDoctorName() ? one.getDoctorName() : "");
           // String keyword1 = templateConfig.getKeyword1();
            org.json.JSONObject json = new org.json.JSONObject();
            json.put("first", first);
            json.put("keyword1", DateUtil.dateToStrShort(new Date()));
            json.put("keyword2", "上门服务待付款");
            json.put("url", templateConfig.getUrl());
            json.put("remark", templateConfig.getRemark());
            json.put("consult",consult.getCode());*/
//            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 30, patient.getOpenid(), patient.getName(), json);
//            //暂时没有微信模板消息的功能
//            WxTemplateConfigDO templateConfig = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndScene("xm_test_ihealth_wx", "template_process_feedback", "fwyspf");
//            String first = templateConfig.getFirst();
//            first = first.replace("key1", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm"));
//            first = first.replace("key2", null != one.getDoctorName() ? one.getDoctorName() : "");
//            org.json.JSONObject json = new org.json.JSONObject();
//            json.put("first", first);
//            json.put("keyword1", DateUtil.dateToStrShort(new Date()));
//            json.put("keyword2", "服务医生评分");
//            json.put("url", templateConfig.getUrl());
//            json.put("remark", templateConfig.getRemark());
//            json.put("id", orderId);
//            //json.put("consult",consult.getCode());
//            WlyyDoorCommentDO wlyyDoorCommentDO = this.doorCommentDao.selectCommentDoctor(patient.getId(), orderId);
//            String finish = "";
//            if (wlyyDoorCommentDO != null) {
//                finish = "0";
//                json.put("finish", finish);
//            } else {
//                finish = "1";
//                json.put("finish", finish);
//            }
//            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 31, patient.getOpenid(), patient.getName(), json);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
@ -1422,7 +1468,7 @@ public class DoorOrderService {
     * @param level
     */
//    public WlyyDoorServiceOrderDO confirmReceipt(String orderId, Integer level) throws Exception {
//        WlyyDoorServiceOrderDO one = doorServiceOrderDao.findById(orderId).orElse(null);
//        WlyyDoorServiceOrderDO one = doorServiceOrderDao.findById(orderId);
//        one.setPayWay(WlyyDoorServiceOrderDO.PayWay.offLine.getType());    // 1-微信支付,2-线下支付(居民自己向医院支付,具体怎么支付由医院来定)
//        one.setPayTime(new Date());
//        one.setStatus(WlyyDoorServiceOrderDO.Status.waitForCommnet.getType());   // 5-待评价
@ -1493,10 +1539,8 @@ public class DoorOrderService {
    /**
     * 修改预计到达时间
     *
     * @param orderId
     * @param arrivingTime
     * @return
     * orderId
     * arrivingTime
     */
    public WlyyDoorServiceOrderDO updateArrivingTime(String orderId, String arrivingTime) {
        WlyyDoorServiceOrderDO one = doorServiceOrderDao.findById(orderId).orElse(null);
@ -1713,7 +1757,8 @@ public class DoorOrderService {
     * @throws Exception
     */
    public String serverPackagePriceByOrderId(String orderId) throws Exception {
        String sql = "SELECT d.code itemCode,sum(d.number) number,fee from wlyy_door_fee_detail d where order_id=? and d.status in(1,2) and type=1 GROUP BY code";
        String sql = "SELECT d.code itemCode,sum(d.number) number,fee " +
                "from wlyy_door_fee_detail d where order_id=? and d.status in(1,2) and type=1 GROUP BY code";
        List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql, orderId);
        return objectMapper.writeValueAsString(mapList);
    }
@ -1775,27 +1820,26 @@ public class DoorOrderService {
        return typeValues;
    }
//    /**
//     * 修改保存服务项
//     *
//     * @param jsonData
//     */
//    @org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
//    public void updatePackageItemInfo(String jsonData) {
//        JSONObject jsonObjectParam = JSONObject.parseObject(jsonData);
//        String orderId = String.valueOf(jsonObjectParam.get("orderId"));
//        WlyyDoorServiceOrderDO order = doorServiceOrderDao.findById(orderId);
//        // 删除出诊医生或服务项
//        wlyyDoorServiceOrderService.orderWithFeeDelete(jsonObjectParam, order);
//        // 更新服务包信息
//        wlyyDoorServiceOrderService.orderWithPackageItemFeeAdd(new JSONObject(), jsonObjectParam, order);
//
//        // 发送微信模板消息,通知居民服务项目已经变更(smyyyjjd-服务项目变更通知)
//        BasePatientDO patient = patientService.findByCode(order.getProxyPatient());
//        ConsultDo consult = consultDao.queryByRelationCode(orderId);
//        Integer status = 0;
//        try {
//
    /**
     * 修改保存服务项
     *
     * @param jsonData
     */
    @org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
    public void updatePackageItemInfo(String jsonData) throws Exception {
        JSONObject jsonObjectParam = JSONObject.parseObject(jsonData);
        String orderId = String.valueOf(jsonObjectParam.get("orderId"));
        WlyyDoorServiceOrderDO order = doorServiceOrderDao.findById(orderId).orElse(null);
        // 删除出诊医生或服务项
        wlyyDoorServiceOrderService.orderWithFeeDelete(jsonObjectParam, order);
        // 更新服务包信息
        wlyyDoorServiceOrderService.orderWithPackageItemFeeAdd(new JSONObject(), jsonObjectParam, order);
        // 发送微信模板消息,通知居民服务项目已经变更(smyyyjjd-服务项目变更通知)
        BasePatientDO patient = basePatientDao.findById(order.getProxyPatient()).orElse(null);
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        Integer status = 0;
        try {
//            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback", "fwxmbgtz");
//            String first = templateConfig.getFirst();
//            first = first.replace("key1", (patient.getName() == null ? "" : patient.getName()));
@ -1807,14 +1851,14 @@ public class DoorOrderService {
//            json.put("keyword2", "服务项目变更确认");
//            json.put("url", templateConfig.getUrl());
//            json.put("remark", templateConfig.getRemark());
//            json.put("consult", consult.getCode());
//            json.put("consult", consult.getId());
//            json.put("status", status);
////            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 32, patient.getOpenid(), patient.getName(), json);
//        } catch (Exception e) {
//            logger.error(e.getMessage());
//        }
//
//    }
//            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 32, patient.getOpenid(), patient.getName(), json);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }
    /**
     * 获取管理员端上门服务菜单分类
@ -2017,9 +2061,9 @@ public class DoorOrderService {
        if (org.apache.commons.lang3.StringUtils.isBlank(sendId)) {
            wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findById(orderId).orElse(null);
            response = imUtill.sendTopicIM(wlyyDoorServiceOrder.getDispatcher(), "智能助手", consult.getCode(), contentType, content, null);
            response = imUtill.sendTopicIM(wlyyDoorServiceOrder.getDispatcher(), "智能助手", consult.getId(), contentType, content, null);
        } else {
            response = imUtill.sendTopicIM(sendId, sendName, consult.getCode(), contentType, content, null);
            response = imUtill.sendTopicIM(sendId, sendName, consult.getId(), contentType, content, null);
        }
        JSONObject resObj = JSONObject.parseObject(response);
        if (resObj.getIntValue("status") == -1) {
@ -2416,9 +2460,9 @@ public class DoorOrderService {
    /**
     * 字典查询List
     */
    public List<SystemDict> getDictionaryList(String dictName) {
        String sql = "SELECT * FROM system_dict WHERE dict_name = '" + dictName + "' ";
        List<SystemDict> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SystemDict.class));
    public List<SystemDictDO> getDictionaryList(String dictName) {
        String sql = "SELECT * FROM base_system_dict WHERE dict_name = '" + dictName + "' ";
        List<SystemDictDO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SystemDictDO.class));
        return list;
    }

+ 464 - 221
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/service/WlyyDoorServiceOrderService.java

@ -1,36 +1,40 @@
package com.yihu.jw.hospital.module.door.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.im.ConsultDo;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
import com.yihu.jw.entity.door.*;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.wechat.WechatTemplateConfig;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.hospital.HospitalDao;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.hospital.module.consult.service.ConsultTeamService;
import com.yihu.jw.hospital.module.door.dao.*;
import com.yihu.jw.hospital.module.wx.dao.WechatTemplateConfigDao;
import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.order.BusinessOrderService;
import com.yihu.jw.order.dao.BusinessOrderDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.restmodel.qvo.ParamQvo;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.fastdfs.FastDFSUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.EntityUtils;
import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
@ -53,7 +57,6 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
@ -79,6 +82,11 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private BusinessOrderDao businessOrderDao;
    @Autowired
    private BusinessOrderService businessOrderService;
    @Autowired
    private WlyyDoorServiceOrderDao wlyyDoorServiceOrderDao;
@ -150,12 +158,23 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    @Autowired
    private WlyyDoorPrescriptionDrugDao doorPrescriptionDrugDao;
    @Value("${neiwang.enable}")
    @Autowired
    private FastDFSUtil fastDFSUtil;
    @Autowired
    FileUploadService fileUploadService;
    //    @Value("${neiwang.enable}")
    private Boolean isneiwang;  //如果不是内网项目要转到到内网wlyy在上传
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    @Value("${neiwang.wlyy}")
    //    @Value("${neiwang.wlyy}")
    private String neiwangWlyy;  //内网的项目地址
    @Value("${wlyy.url}")
    private String wlyyUrl;
    @Autowired
    private WlyyDoorOrderItemDao doorOrderItemDao;
    @Autowired
@ -169,8 +188,11 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    @Autowired
    private WeiXinAccessTokenUtils tokenUtils;
//    @Autowired
//    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    private WxTemplateConfigDao wxTemplateConfigDao;
//    @Autowired
//    private DmJobService dmJobService;
@ -198,15 +220,14 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            return result;
        }
        //资质处理 .医生填写资质信息后,生成一个已通过审核的资质
        try {
            if (jsonObjectParam.get("doorServiceApplication") != null) {
                //创建审核
                doorServiceApplicationService.create("2", jsonObjectParam.get("doorServiceApplication").toString(), doctorCode);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        /**
         * 资质处理 .医生填写资质信息后,生成一个已通过审核的资质
         * 云照护没用资质审核模块
         */
//        if (jsonObjectParam.get("doorServiceApplication") != null) {
//            //创建审核
//            doorServiceApplicationService.create("2", jsonObjectParam.get("doorServiceApplication").toString(), doctorCode);
//        }
        WlyyDoorServiceOrderDO orderDO = null;
@ -277,8 +298,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            orderDO.setUpdateUser(orderDO.getProxyPatient());
            orderDO.setUpdateUserName(orderDO.getProxyPatientName());
        }
        orderDO.setStatus(2);
        orderDO.setType(3);
        orderDO.setStatus(2);//2-待(医生)接单
        orderDO.setType(3);//3医生代预约
        orderDO.setDispatcherResponseTime(new Date());
        this.save(orderDO);
        result.put("orderId", orderDO.getId());
@ -287,21 +308,24 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            return result;
        }
        if ("1".equals(orderDO.getShortcutType())) {
//            //快捷的当前医生直接接单
//            try {
//                Doctor doctor = doctorDao.findByCode(orderDO.getDoctor());
//                Hospital hospital = hospitalDao.findByCode(doctor.getHospital());
//                doorOrderService.acceptOrder1(orderDO.getId(), doctor.getJob(), doctor.getJobName(), hospital.getLevel());
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
        } else {
            // 给服务医生发接单消息
            this.createMessage(orderDO.getId(), orderDO.getProxyPatient(), orderDO.getDoctor(), 407, "服务工单待接单", "您有新的服务工单,请前往处理");
            //发送智能助手消息
            sendWeixinMessage(4, orderDO.getDoctor(), orderDO.getPatient());
        }
//        if ("1".equals(orderDO.getShortcutType())) {
////            //快捷的当前医生直接接单
////            try {
////                Doctor doctor = doctorDao.findByCode(orderDO.getDoctor());
////                Hospital hospital = hospitalDao.findByCode(doctor.getHospital());
////                doorOrderService.acceptOrder1(orderDO.getId(), doctor.getJob(), doctor.getJobName(), hospital.getLevel());
////            } catch (Exception e) {
////                e.printStackTrace();
////            }
//        } else {
//            // 给服务医生发接单消息
//            this.createMessage(orderDO.getId(), orderDO.getProxyPatient(), orderDO.getDoctor(), 407, "服务工单待接单", "您有新的服务工单,请前往处理");
//            //发送智能助手消息
//            sendWeixinMessage(4, orderDO.getDoctor(), orderDO.getPatient());
//        }
        //待预约走调度平台的模式
        result = submitDoorOrderAndSendMsg(orderDO, "5", jsonObjectParam);
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        return result;
@ -399,10 +423,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            wlyyDoorFeeDetailDao.saveAll(feeDetailDOList);
            doorOrderItemDao.saveAll(orderItemDOList);
//          //更新总费用-这边没用到
//           order.setTotalFee(totalFee);
//           wlyyDoorServiceOrderDao.save(order);
            //更新总费用
            order.setTotalFee(totalFee);
            wlyyDoorServiceOrderDao.save(order);
        }
        return false;
    }
@ -481,7 +504,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                    }
                    wlyyDoorFeeDetailService.delete(idStrSet.toArray());
                    totalFee = orderDO.getTotalFee().subtract(totalSubFee);
//                    orderDO.setTotalFee(totalFee);
                    orderDO.setTotalFee(totalFee);
                    wlyyDoorServiceOrderDao.save(orderDO);//保存总费用
                }
            }
            wlyyDoorDoctorService.delete(idStrSet.toArray());
@ -536,7 +560,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            ConsultDo consult = consultDao.queryByRelationCode(orderDO.getId());
            String sessionId = null;
            if (consult != null) {
                sessionId = orderDO.getPatient() + "_" + consult.getCode() + "_" + orderDO.getNumber() + "_" + consult.getType();
                sessionId = orderDO.getPatient() + "_" + consult.getId() + "_" + orderDO.getNumber() + "_" + consult.getType();
            }
            for (Object one : doctorArray) {
                WlyyDoorDoctorDO doorDoctorDO = null;
@ -629,9 +653,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                "	1 = 1 \n" +
                "	AND t.`code` = 'dispatcher' \n";
        if (StringUtils.isNotBlank(hospitalCode)) {
            sql += " AND a.org_code = '" + hospitalCode + "' \n";
        }
//        if (StringUtils.isNotBlank(hospitalCode)) {
//            sql += " AND a.org_code = '" + hospitalCode + "' \n";
//        }
        List<Map<String, Object>> dispatcherInfoList = jdbcTemplate.queryForList(sql);
        return dispatcherInfoList;
@ -639,11 +663,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    /**
     * 创建上门服务工单
     *
     * @param jsonData
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
//    @Transactional(rollbackFor = Exception.class)
    public JSONObject create(String jsonData) throws Exception {
        logger.info("创建上门服务jsonData参数:" + jsonData);
@ -653,11 +674,32 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        WlyyDoorServiceOrderDO orderDO = EntityUtils.jsonToEntity(
                jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.class);
        orderDO.setNumber(getRandomIntStr());
        orderDO.setCreateTime(new Date());
        orderDO.setCreateUser(orderDO.getProxyPatient());
        orderDO.setCreateUserName(orderDO.getProxyPatientName());
        orderDO.setOrderInfo("0");
        orderDO.setOrderInfo("0");//工单详情 0-未推送 1-未确认 2-已确认
//        //服务后收费标识(1是0否)
//        if ("1".equals(orderDO.getFeeAfter())) {
//            //工单状态:-1-已取消,1-待(调度员)派单,2-待(医生)接单,3-待服务,4-待付款,5-待评价,6-已完成
//            if (StringUtils.isNotBlank(orderDO.getDoctor())) {
//                orderDO.setStatus(2);//待接单(医生)
//            } else {
//                orderDO.setStatus(1);//待派单(调度员)
//            }
//        } else {
//            orderDO.setStatus(4);//待付款
//        }
        if (StringUtils.isNotBlank(orderDO.getDoctor())) {
            orderDO.setStatus(2);//待接单(医生)
        } else {
            orderDO.setStatus(1);//待派单(调度员)
        }
        if (StringUtils.isEmpty(orderDO.getPatient())) {
            throw new Exception("当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient());
@ -677,7 +719,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                });
        if (bool) {
            String failMsg = "当前服务对象存在未完成的上门服务,请先完成该服务!";
            String failMsg = "当前服务对象存在未完成或未付款的上门服务,请先完成该服务!";
            throw new Exception(failMsg);
        }
@ -689,77 +731,197 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        } else if (!orderDO.getProxyPatient().equals(orderDO.getPatient())) {
            orderDO.setType(2);
        }
        orderDO.setServiceStatus("1");
        orderDO.setServiceStatus("1");//服务类型 1-预约项目 2-即时项目
        //保存服务订单
        wlyyDoorServiceOrderDao.save(orderDO);
        //创建咨询
        JSONObject successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
        ConsultTeamDo consultTeam = (ConsultTeamDo) successOrNot.get(ResponseContant.resultMsg);
        //新增工单与服务项费用关联关系
        if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO)) {
            return result;
        }
        //获取机构的调度员
        List<Map<String, Object>> dispatcherList = queryDispatcherInfoByPatient(jsonObjectParam.getJSONObject("hospital").get("code").toString());
        //没有调度员的模式
//        if (dispatcherList.isEmpty()
//                && StringUtils.isEmpty(orderDO.getDoctor())
//                && StringUtils.isEmpty(orderDO.getExpectedDoctorName())) {
//            orderDO.setStatus(2);
//            //应该是康复模板的康复下转,才有签约--先注释
//            orderDO.setDoctor(signFamily.getDoctor());
//            orderDO.setDoctorName(signFamily.getDoctorName());
//            this.save(orderDO);
//            WlyyDoorServiceOrderDO wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findById(orderDO.getId()).orElse(null);
//            //新增工单医生关联关系
//            if (orderWithDoctorAdd(result, jsonObjectParam, wlyyDoorServiceOrder)) {
//                return result;
//            }
//            // 给服务医生发接单消息--先注释
//            this.createMessage(orderDO.getId(), orderDO.getProxyPatient(), signFamily.getDoctor(), 407, "服务工单待接单", "您有新的服务工单,请前往处理");
//            //发送智能助手消息-微信消息先注释
//            sendWeixinMessage(4, signFamily.getDoctor(), orderDO.getPatient());
//            result.put(ResponseContant.resultFlag, ResponseContant.success);
//            result.put(ResponseContant.resultMsg, consultTeam);
//            return result;
        /**
         * 1、发起支付订单
         * 2、发送咨询消息
         */
        result = submitDoorOrderAndSendMsg(orderDO, "5", jsonObjectParam);
        return result;
    }
    /**
     * 5表示上门服务
     * 情况
     * 1.直接付款走流程
     * 2.创建订单没付完款-待付款
     * 3.还要超时订单
     * -----
     * 这个上门服务是线下收费,不用在线支付
     */
    private JSONObject submitDoorOrderAndSendMsg(WlyyDoorServiceOrderDO orderDO, String type, JSONObject jsonObjectParam) throws Exception {
        boolean flag = true;
        JSONObject result = new JSONObject();
//        //创建订单信息
//        BasePatientDO pateint = patientDao.findById(orderDO.getPatient());
//        //查询是否存在订单信息
//        BusinessOrderDO businessOrderDO = businessOrderDao.findByOrderId(orderDO.getId());
//        if (businessOrderDO == null) {
//            businessOrderDO = new BusinessOrderDO();
//            businessOrderDO.setPatient(pateint.getId());
//            //支付账号
//            businessOrderDO.setYkOrderId(pateint.getMobile());
//            businessOrderDO.setPatientName(pateint.getName());
//            businessOrderDO.setOrderType(1);
//            businessOrderDO.setOrderCategory(type);
//            Date date = new Date();
//            Long lastPayTime = date.getTime() + 1000 * 60 * 30;//订单截至支付日期
//            businessOrderDO.setDescription("上门服务");
//            businessOrderDO.setRelationCode(orderDO.getId());//订单id
//            businessOrderDO.setRelationName("上门服务");
//            businessOrderDO.setCreateTime(date);
//            businessOrderDO.setUpdateTime(date);
//            businessOrderDO.setStatus(0);
//            businessOrderDO.setOrderNo(orderDO.getNumber());
//            businessOrderDO.setUploadStatus(0);
//            businessOrderDO.setPayType(1);
//            businessOrderDO.setPayPrice(Double.valueOf(orderDO.getTotalFee().doubleValue()));
//            businessOrderDO.setLastPayTime(lastPayTime);
//        } else {
//            /**
//             * 暂时没用,线下付款的
//             * 1、是否付款完成
//             * 2、判断付款时间是否超过时长了--还需要定时任务监听订单修改状态,把未付款改成已取消
//             */
////            if (businessOrderDO.getStatus() != 1) {
////                long nowTime = System.currentTimeMillis();
////                Long lastPayTime = businessOrderDO.getLastPayTime();
////                if (lastPayTime > nowTime) {
////                    //超时了 修改工单状态成已取消
////                    orderDO.setStatus(-1);//-已取消
////                    wlyyDoorServiceOrderDao.saveAll(orderDO);//更新上门工单
////                    businessOrderDO.setStatus(2);//已取消
////                    businessOrderDao.saveAll(businessOrderDO);//更新业务表
////                    flag = false;//不用创建咨询内容
////                }
////            }
//        }
        /**
         *  1、费用0时无需支付
         *  2、调用微信支付 再来更新flag标识
         */
//        if ("5".equals(type) && 0.0 == orderDO.getTotalFee().doubleValue()) {
//            businessOrderDO.setStatus(1);//1已支付
//            businessOrderDao.saveAll(businessOrderDO);
//        } else {
//            /**
//             * 保存订单信息-这边要判断付款回调修改状态值-付款失败取消订单
//             * businessOrderService
//             */
//            businessOrderDO.setStatus(0);//0待支付
//            businessOrderDao.saveAll(businessOrderDO);
//        }
        //有调度员
        if (!dispatcherList.isEmpty()) {
        //保存业务表
//        businessOrderDao.saveAll(businessOrderDO);
        /**
         * 目前是线下付款的
         * 给出标识是否成功,往下面创建咨询信息发送内容
         */
        if (flag) {
            //获取机构的调度员
            List<Map<String, Object>> dispatcherList = queryDispatcherInfoByPatient(jsonObjectParam.getJSONObject("hospital").get("code").toString());
            //支付成功或者不用支付
            //创建咨询
            JSONObject successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
            ConsultTeamDo consultTeam = (ConsultTeamDo) successOrNot.get(ResponseContant.resultMsg);
            System.out.println("===调度员的信息开始======");
            for (Map<String, Object> map : dispatcherList) {
                String dispatcher = map.get("code").toString();
                // 派单消息-首页
                this.createMessage(orderDO.getId(), "system", dispatcher, 402, "新增居民预约服务申请", orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
                // 派单-实时工单消息  430 居民提交工单申请-- 张三提交了服务工单12345678申请
                this.createMessage(orderDO.getId(), "system", dispatcher, 430, "居民提交工单申请", orderDO.getPatientName() + "提交了服务工单" + orderDO.getNumber() + "申请");
                System.out.println("调度员=>" + JSON.toJSONString(map));
            }
            System.out.println("===调度员的信息结束======");
            //判断其是否有分配执行人。如果有不用走调度平台
            if (StringUtils.isNotBlank(orderDO.getDoctor())) {
                orderDO.setStatus(2);//待接单
                orderDO.setDoctor(orderDO.getDoctor());
                orderDO.setDoctorName(orderDO.getDoctorName());
                this.save(orderDO);
                //新增工单医生关联关系
                if (orderWithDoctorAdd(result, jsonObjectParam, orderDO)) {
                    return result;
                }
                // 给服务医生发接单消息
                this.createMessage(orderDO.getId(), orderDO.getProxyPatient(), orderDO.getDoctor(), 407, "服务工单待接单", "您有新的服务工单,请前往处理");
                //发送智能助手消息-微信消息先注释
                sendWeixinMessage(4, orderDO.getDoctor(), orderDO.getPatient());
                result.put(ResponseContant.resultFlag, ResponseContant.success);
                result.put(ResponseContant.resultMsg, consultTeam);
                return result;
            }
        }
        //给机构调度员发送医生助手消息
        for (Map<String, Object> map : dispatcherList) {
            //这边还没有微信消息的功能呢。
            sendWeixinMessage(3, map.get("user_code") + "", orderDO.getPatient());
        }
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg, consultTeam);
            //有调度员
            if (!dispatcherList.isEmpty()) {
                for (Map<String, Object> map : dispatcherList) {
                    String dispatcher = map.get("code").toString();
                    // 派单消息-首页
                    this.createMessage(orderDO.getId(), "system", dispatcher, 402, "新增居民预约服务申请", orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
                    // 派单-实时工单消息  430 居民提交工单申请-- 张三提交了服务工单12345678申请
                    this.createMessage(orderDO.getId(), "system", dispatcher, 430, "居民提交工单申请", orderDO.getPatientName() + "提交了服务工单" + orderDO.getNumber() + "申请");
                }
            }
        //发送 预约卡片信息(2101类型)
        JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
        orderInfoContent.put("re_msg_type", 0);//居民预约
        //发送消息
        int i = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
//        if (i != 1) {
//            throw new Exception("上门服务工单消息发送失败");
//        }
            //给机构调度员发送医生助手消息
            for (Map<String, Object> map : dispatcherList) {
                //这边还没有微信消息的功能呢
                sendWeixinMessage(3, map.get("code") + "", orderDO.getPatient());
            }
            result.put(ResponseContant.resultFlag, ResponseContant.success);
            result.put(ResponseContant.resultMsg, consultTeam);
            //发送 预约卡片信息(2101类型)
            JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
            orderInfoContent.put("re_msg_type", 0);//居民预约
            System.out.println("准备发送预约卡片信息");
            int flagCount = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
            System.out.println("flagCount==>" + flagCount);
            //模拟一,重试3次
//            int tryCount = 3;
//            int flagCount = 0;
//            for (int i = 0; i < tryCount; i++) {
//                //发送消息
//                flagCount = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
//                if (flagCount == 1) {
//                    break;
//                }
//            }
        if (StringUtils.isNoneBlank(orderDO.getDoctor())) {
            //服务医生修改,直接转派
            BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor()).orElse(null);
            sendOrderToDoctor(orderDO.getId(), null, "system", "系统", transDoctor.getId(), transDoctor.getName(), transDoctor.getJobTitleName());
//            //模式2,睡眠1秒钟
//            Thread.sleep(1000);
//            flagCount = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
            //后面这个要修改下,加个字段判断下是否转派
            if (StringUtils.isNoneBlank(orderDO.getDoctor())) {
                //服务医生修改,直接转派
                BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor()).orElse(null);
                sendOrderToDoctor(orderDO.getId(), null, "system", "系统", transDoctor.getId(), transDoctor.getName(), transDoctor.getJobTitleName());
            }
        } else {
            //取消订单
            orderDO.setStatus(-1);//-已取消
            wlyyDoorServiceOrderDao.save(orderDO);//更新上门工单
        }
        return result;
    }
    /**
     * 发送微信消息
     * 三院暂时没这个功能--没有签约这个动作
@ -769,8 +931,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
//        if (type == 1) {
//            try {
//                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey", "zztj");
//                BasePatientDO patient1 = patientDao.findById(patient).orElse(null);
//                BaseDoctorDO doctor = doctorDao.findById(doctorCode).orElse(null);
//                BasePatientDO patient1 = patientDao.findById(patient);
//                BaseDoctorDO doctor = doctorDao.findById(doctorCode);
//                String doctorName = doctor.getName();
//                SignFamily signFamily = signFamilyDao.findByPatient(patient);//签约数据
//                String first = doctorName + "医生,您好!" + patient1.getName() + "提交了资质申请,请及时登录PC或APP处理";
@ -793,8 +955,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
//            //调度员转交给家庭医生
//            try {
//                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey", "zztj");
//                BasePatientDO patient1 = patientDao.findById(patient).orElse(null);
//                BaseDoctorDO doctor = doctorDao.findById(doctorCode).orElse(null);
//                BasePatientDO patient1 = patientDao.findById(patient);
//                BaseDoctorDO doctor = doctorDao.findById(doctorCode);
//                SignFamily signFamily = signFamilyDao.findByPatient(patient);
//                String doctorName = doctor.getName();
//                String first = doctorName + "医生,您好!" + patient1.getName() + "提交了资质申请,请及时登录PC或APP处理";
@ -817,8 +979,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
//            //上门预约申请
//            try {
//                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey", "zztj");
//                BasePatientDO patient1 = patientDao.findById(patient).orElse(null);
//                BaseDoctorDO doctor = doctorDao.findById(doctorCode).orElse(null);
//                BasePatientDO patient1 = patientDao.findById(patient);
//                BaseDoctorDO doctor = doctorDao.findById(doctorCode);
//                SignFamily signFamily = signFamilyDao.findByPatient(patient);
//                String doctorName = doctor.getName();
//                String first = doctorName + "医生,您好!" + patient1.getName() + "提交了上门出诊服务预约,请及时登录PC处理";
@ -841,7 +1003,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
//            try {
//                //社区调度员指派服务工单给家签医生
//                WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey", "zztj");
//                BaseDoctorDO doctor = doctorDao.findById(doctorCode).orElse(null);
//                BaseDoctorDO doctor = doctorDao.findById(doctorCode);
//                SignFamily signFamily = signFamilyDao.findByPatient(patient);
//                String doctorName = doctor.getName();
//                String first = doctorName + "医生,您好!您有新的服务工单,请及时登录APP或PC处理";
@ -880,14 +1042,16 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            return result;
        }
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        String sessionId = orderDO.getPatient() + "_" + consult.getCode() + "_" + orderDO.getNumber() + "_" + consult.getType();
        String sessionId = orderDO.getPatient() + "_" + consult.getId() + "_" + orderDO.getNumber() + "_" + consult.getType();
        // 把调度员拉入会话,作为其中一个成员,第一个进入会话的调度员,系统发送欢迎语和居民的预约卡片信息
        if (StringUtils.isEmpty(orderDO.getDispatcher())) {
            orderDO.setDispatcher(dispatcher);
            orderDO.setDispatcherName(dispatcherName);
            this.save(orderDO);
            // 先进入会话,再聊天
            imUtill.updateParticipant(sessionId, dispatcher, null);
//            String msg = imUtill.updateParticipant(sessionId, dispatcher, null);
            String msg = imUtill.updateParticipantNew(sessionId, dispatcher, null);
            System.out.println("进入会话,再聊天==>" + msg);
            String noticeContent = hospitalName + dispatcherName + "为您服务";
            this.qucikSendIM(orderId, dispatcher, "智能助手", "1", noticeContent);
//            imUtill.sendIntoTopicIM(dispatcher, sessionId, consult.getCode(), noticeContent, orderDO.getProxyPatient(), orderDO.getProxyPatientName());
@ -896,7 +1060,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        }
        // 把调度员拉入会话,作为其中一个成员
        imUtill.updateParticipant(sessionId, dispatcher, null);
//        String msg = imUtill.updateParticipant(sessionId, dispatcher, null);
        String msg = imUtill.updateParticipantNew(sessionId, dispatcher, null);
        System.out.println("把调度员拉入会话,作为其中一个成员==>" + msg);
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg, "调度员[" + dispatcherName + "]进入会话成功");
        return result;
@ -904,9 +1070,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    /**
     * 回写最后一个回复内容的调度员到工单表
     *
     * @param dispatcher
     * @param orderId
     */
    @Transactional(rollbackFor = Exception.class)
    public JSONObject saveLastDispatcher(String orderId, String dispatcher, String dispatcherName) {
@ -1036,9 +1199,12 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            e.printStackTrace();
        }
        if (!CollectionUtils.isEmpty(feeDetailDOS)) {
            //2023-10-11 先注释 计算服务费用
            Map<String, Object> map = doorOrderService.countServerPackagePrice(jsonData, orderDO.getPatient());
            orderBriefInfo.put("packageFee", map.get("serverPackagePrice"));
            /**
             *  2023-10-11 先注释 计算服务费用
             *  这边需要改写用表base_service_package_record
             */
//            Map<String, Object> map = doorOrderService.countServerPackagePrice(jsonData, orderDO.getPatient());
//            orderBriefInfo.put("packageFee", map.get("serverPackagePrice"));
        }
        orderJson.put("order", orderBriefInfo);
@ -1123,12 +1289,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    /**
     * 生成二維碼
     *
     * @param id
     * @param token
     * @return
     */
    public String twoDimensionalCode(String id, String token) {
    public UploadVO twoDimensionalCode(String id, String token) throws Exception {
        JSONObject orderJson = new JSONObject();
        List<WlyyDoorServiceOrderDO> orderList = this.findByField("id", id);
        if (orderList.size() > 0) {
@ -1138,35 +1300,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            //生成二维码图片
            String contentJsonStr = orderDO.getNumber();
            InputStream ipt = QrcodeUtil.createQrcode(contentJsonStr, 300, "png");
            if (isneiwang) {
                // 圖片列表
                List<String> tempPaths = new ArrayList<String>();
                try {
                    ObjectNode imgNode = FastDFSUtil.upload(ipt, "png", "plan_service_qrcode" + System.currentTimeMillis());
                    JSONObject json = JSONObject.parseObject(imgNode.toString());
                    tempPaths.add(json.getString("fid"));
                    String urls = "";
                    for (String image : tempPaths) {
                        if (urls.length() == 0) {
                            urls = image;
                        } else {
                            urls += "," + image;
                        }
                    }
                    fileUrl = fastdfs_file_url + urls;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    fileUrl = fastdfs_file_url + PrescriptionQRCodetoNeiWang(ipt);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            param.put("number", orderDO.getNumber());
            param.put("imageUrl", fileUrl);
            return fileUrl;
            UploadVO uploadVO = PrescriptionQRCodetoNeiWang(ipt);
            return uploadVO;
        } else {
            return null;
        }
@ -1175,28 +1310,33 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    /**
     * 长处方生成取药码,生成取药二维码
     * 如果是外网那是发送到内网的服务器
     *
     * @param ipt
     * @return
     */
    public String PrescriptionQRCodetoNeiWang(InputStream ipt) throws FileNotFoundException {
        String filename = "QRCode_" + System.currentTimeMillis();
    public UploadVO PrescriptionQRCodetoNeiWang(InputStream ipt) throws Exception {
        String filename = "QRCode_" + System.currentTimeMillis() + ".jpg";
        String fileUrls = "";
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String returnStr = request(request, ipt, filename);
        logger.info("returnStr :" + returnStr);
        logger.info("fileName :" + filename);
        logger.info("result :" + returnStr.toString());
        if (returnStr != null) {
            //1.3.7去掉前缀
            fileUrls += returnStr + ",";
        }
        return fileUrls.substring(0, fileUrls.length() - 1);
        UploadVO uploadVO = fileUploadService.uploadStream(ipt, filename, fastdfs_file_url);
//        System.out.println(uploadVO.getFullUri());
//        String returnStr = request(request, ipt, filename);
//        logger.info("returnStr :" + returnStr);
//        logger.info("fileName :" + filename);
//        logger.info("result :" + returnStr.toString());
//        if (returnStr != null) {
//            //1.3.7去掉前缀
//            fileUrls += returnStr + ",";
//        }
        return uploadVO;
    }
    public String request(HttpServletRequest request, InputStream in, String fileName) {
        String url = neiwangWlyy + "/wlyy/upload/commonUpload";//uri请求路径
        //上传地址
        String url = wlyyUrl + "/upload/chat";
//        String url = neiwangWlyy + "/wlyy/upload/commonUpload";//uri请求路径
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        String result = "";
@ -1251,8 +1391,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        String sql = "SELECT " +
                "  d.photo AS doctorPhoto, " +
                "  d.`name` AS doctorName, " +
                "  d.`job_name` AS doctorJobName, " +
                "  d.hospital_name AS hospitalName, " +
                "  d.`job_title_name` AS doctorJobName, " +
                "  d.visit_hospital_name AS hospitalName, " +
                "  d.mobile AS doctorPhone, " +
                "  o.id, " +
                "  o.number, " +
@ -1263,11 +1403,12 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                "  o.`pay_way` AS payWay, o.type," +
                "  ifnull(de.order_id,concat(rand(),'_notExist')) AS feeOrderId, " +
                "  a.mobile AS hospitalPhone, " +
                "  count(de.number) as itemCount " +
                "  count(de.number) as itemCount ," +
                "  o.sign_id 'signId' , o.package_id 'packageId' " +
                " FROM " +
                "  ( wlyy_door_service_order o " +
                " LEFT JOIN wlyy_doctor d ON o.doctor = d.`code`) " +
                " LEFT JOIN wlyy_door_fee_detail de on o.id = de.order_id " +
                " LEFT JOIN base_doctor d ON o.doctor = d.`id`) " +
                " LEFT JOIN wlyy_door_fee_detail de on o.id = de.order_id  and de.type='1' " +
                " LEFT JOIN base_org a on o.hospital = a.code " +
                " WHERE " +
                "  (o.patient = '{patient}') " +
@ -1285,7 +1426,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                "   count(DISTINCT o.id)  " +
                " FROM  " +
                "  ( wlyy_door_service_order o " +
                " LEFT JOIN wlyy_doctor d ON o.doctor = d.`code`) " +
                " LEFT JOIN base_doctor d ON o.doctor = d.`id`) " +
                " LEFT JOIN wlyy_door_fee_detail de on o.id = de.order_id " +
                " LEFT JOIN base_org a on o.hospital = a.code " +
                " WHERE  " +
@ -1296,8 +1437,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                .replace("{status}", String.valueOf(status));
        List sqlResultlist = new ArrayList<>();
        logger.info("infoList-info: " + finalSql);
        logger.info("infoList-count: " + finqlCountSql);
        try {
            sqlResultlist = jdbcTemplate.queryForList(finalSql);
        } catch (Exception e) {
@ -1377,10 +1516,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
    @Transactional(rollbackFor = Exception.class)
    public int updateOrderInfo(String orderId) {
        String sql = "UPDATE `wlyy_door_service_order` SET order_info =2 WHERE id = ?";
        Object[] params = new Object[]{orderId};
        int a = jdbcTemplate.update(sql, params);
        return a;
        String sql = "UPDATE `wlyy_door_service_order` SET order_info =2 WHERE id = '" + orderId + "'";
        int i = jdbcTemplate.update(sql);
        return i;
    }
@ -1530,7 +1668,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
        BasePatientDO patient = patientService.findPatientById(orderDO.getPatient());
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback", "smyyyqx");
        WxTemplateConfigDO templateConfig = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndScene("xm_test_ihealth_wx", "template_process_feedback", "smyyyqx");
        String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
        org.json.JSONObject json = new org.json.JSONObject();
        json.put("first", first);
@ -1539,7 +1677,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        json.put("url", templateConfig.getUrl());
        json.put("remark", templateConfig.getRemark());
        if (consult != null) {
            json.put("consult", consult.getCode());
            json.put("consult", consult.getId());
        } else {
            json.put("id", orderDO.getId());
        }
@ -1558,30 +1696,30 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        return result;
    }
    public JSONObject orderMsgTask(String orderId) throws Exception {
        JSONObject result = new JSONObject();
        WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findById(orderId).orElse(null);
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
        BasePatientDO patient = patientService.findPatientById(orderDO.getPatient());
        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback", "smyyyqx");
        String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
        org.json.JSONObject json = new org.json.JSONObject();
        json.put("first", orderDO.getPatientName() + ",您好!您的上门服务知情同意书已送达");
        json.put("keyword1", DateUtil.dateToStrShort(new Date()));
        json.put("keyword2", "知情同意书已推送");
//        json.put("url", templateConfig.getUrl());
        json.put("url", "appoint_service/html/appoint-serviceDetail.html?id=" + orderId);
//        appoint_service/html/appoint-serviceDetail.html?openid=ojsU-1XJVftkfdbP1F5bi8JVPtOo&consult=e0d17c67ab07477f8e96534bc610e51b
        json.put("remark", templateConfig.getRemark());
        if (consult != null) {
            json.put("consult", consult.getCode());
        } else {
            json.put("id", orderDO.getId());
        }
        pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 30, patient.getOpenid(), patient.getName(), json);
        return result;
    }
//    public JSONObject orderMsgTask(String orderId) throws Exception {
//        JSONObject result = new JSONObject();
//        WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findById(orderId).orElse(null);;
//        ConsultDo consult = consultDao.queryByRelationCode(orderId);
//        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
//        BasePatientDO patient = patientService.findPatientById(orderDO.getPatient());
//        WxTemplateConfigDO templateConfig = wxTemplateConfigDao.findByScene("template_process_feedback", "smyyyqx");
//        String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
//        org.json.JSONObject json = new org.json.JSONObject();
//        json.put("first", orderDO.getPatientName() + ",您好!您的上门服务知情同意书已送达");
//        json.put("keyword1", DateUtil.dateToStrShort(new Date()));
//        json.put("keyword2", "知情同意书已推送");
////        json.put("url", templateConfig.getUrl());
//        json.put("url", "appoint_service/html/appoint-serviceDetail.html?id=" + orderId);
////        appoint_service/html/appoint-serviceDetail.html?openid=ojsU-1XJVftkfdbP1F5bi8JVPtOo&consult=e0d17c67ab07477f8e96534bc610e51b
//        json.put("remark", templateConfig.getRemark());
//        if (consult != null) {
//            json.put("consult", consult.getId());
//        } else {
//            json.put("id", orderDO.getId());
//        }
//        pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 30, patient.getOpenid(), patient.getName(), json);
//        return result;
//    }
    /**
     * 统计居民一个月内工单取消次数
@ -1881,7 +2019,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                "  o.serve_lat as lat, " +
                "  o.`status` as status, " +
                "  o.`dispatcher_name` as dispatcherName, " +
                "  concat( o.patient,'_' ,c.`code`, '_',o.`number`,'_11' ) as sessionId, " +
                "  concat( o.patient,'_' ,c.`id`, '_',o.`number`,'_11' ) as sessionId, " +
                "   t1.`type` as patientType " +
                " FROM " +
                " ( wlyy_door_service_order o " +
@ -1936,7 +2074,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        List<Map<String, Object>> sqlResultlist = new ArrayList<>();
        try {
            sqlResultlist = jdbcTemplate.queryForList(finalSql);
            logger.info(finalSql);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg, "从数据库查询【调度员】上门服务工单列表信息失败:" + e.getMessage());
@ -1961,6 +2098,8 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        }
        String serviceSql = "SELECT count(d.id) times FROM wlyy_door_doctor d where d.order_id in(SELECT id from wlyy_door_service_order WHERE DATE_FORMAT(doctor_sign_time, '%Y') = DATE_FORMAT(NOW(), '%Y') AND patient=?)";
//        final Set<String>  patientSet = doorServiceVoucherDao.queryByTypeIn(types);
        sqlResultlist.forEach(
                oneMap -> {
                    // 获取服务次数
@ -1974,10 +2113,10 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (parArray!=null){
                    if (parArray != null) {
                        parArray.forEach(
                                oneParObj -> {
                                    org.json.JSONObject oneParJson = (org.json.JSONObject) oneParObj;
                                    com.alibaba.fastjson.JSONObject oneParJson = (com.alibaba.fastjson.JSONObject) oneParObj;
                                    if (StringUtils.equalsIgnoreCase(oneParJson.getString("id"), dispatcher)) {
                                        oneMap.put("isInSession", true);
                                    }
@ -2012,6 +2151,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        int end = 0 == size ? 15 : size;
        String sql = "SELECT " +
                "  a.dept_code 'deptCode',\ta.dept_name 'deptName',a.org_code 'orgCode',\ta.org_name 'orgName', " +
                "  d.id as doctor, " +
                "  d.photo as photo, " +
                "  d.name as name," +
@ -2020,7 +2160,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                "  when 1 then '男' " +
                "  when 2 then '女' " +
                "  end as sex, " +
                "  d.`job_title_name` AS jobName, " +
                "  d.job_title_code 'jobCode', d.`job_title_name` AS jobName, " +
                "  d.mobile as phone," +
                "  CONCAT(d.doctor_lat ,',',d.doctor_lon) 'position', " +
                "  IFNULL(ds.`status`,5) as status," +
@ -2072,7 +2212,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                .replace("{status}", String.valueOf(status));
        List<Map<String, Object>> sqlResultlist = jdbcTemplate.queryForList(finalSql);
        logger.info("服务医生人员sql:" + finalSql);
        Integer count = jdbcTemplate.queryForObject(finalCountSql, Integer.class);
        //添加未完成服务工单列表
@ -2082,7 +2221,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            if (notFinish > 0 && StringUtils.isNotBlank(doctor)) {
                String notFinishSql = "select o.id,o.number,o.patient,o.patient_name,o.patient_phone,o.patient_expected_serve_time,o.`status`, CASE p.sex when 1 then '男' when 2 THEN '女' END as sex,p.idcard, " +
                        "year(now()) - ((CASE LENGTH(p.idcard) WHEN 18 THEN substring(p.idcard, 7, 4) WHEN 15 THEN CONCAT('19',substring(p.idcard, 7, 2)) END )) as age , p.photo,o.serve_lat AS lat,o.serve_lon AS lon,o.id AS orderId " +
                        "from wlyy_door_service_order o LEFT JOIN wlyy_patient p on o.patient = p.`code` and p.`status`=1 " +
                        "from wlyy_door_service_order o LEFT JOIN base_patient p on o.patient = p.`id` and p.`del`=1 " +
                        "where o.doctor ='" + doctor + "' and o.status in (2,3,4)";
                List<Map<String, Object>> notFinishList = jdbcTemplate.queryForList(notFinishSql);
                map.put("notFinishList", notFinishList);
@ -2240,8 +2379,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        // 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getCode() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
        imUtill.updateParticipant(sessionId, doctor, null);
        String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
        String response = imUtill.updateParticipant(sessionId, doctor, null);
        System.out.println("给医生加入群聊==>" + response);
        // 调度员处理完该单(新增预约的,或者是拒单重新派单的)
        List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId, new String[]{"402", "404", "430", "435"});
@ -2341,7 +2481,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        // 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getCode() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
        String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
        imUtill.updateParticipant(sessionId, doctor, null);
        // 调度员处理完该单(新增预约的,或者是拒单重新派单的)
@ -2492,8 +2632,37 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     * @return
     */
    public int qucikSendIM(String orderId, String sendId, String sendName, String contentType, String content) throws Exception {
        int tryAgain = 3;
        int flag = 0;
        for (int i = 0; i < tryAgain; i++) {
            flag = sendMsg(orderId, sendId, sendName, contentType, content);
            if (flag == 1) {
                break;
            } else {
                System.out.println("开始重试发送");
            }
        }
        return flag;
    }
    public int sendMsg(String orderId, String sendId, String sendName, String contentType, String content) throws Exception {
        System.out.println("发送消息的方法【sendMsg】");
        int result = -1;
        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        System.out.println("查询ConsultDo==>参数:" + orderId);
        String sql = "SELECT * FROM wlyy_consult WHERE relation_code='" + orderId + "'";
        ConsultDo consult = null;
        List<ConsultDo> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ConsultDo.class));
        if (list != null && list.size() > 0) {
            consult = list.get(0);
            System.out.println("ConsultDo的list数量==>" + list.size());
        } else {
            throw new Exception("ConsultDo为空,参数RelationCode:" + orderId);
        }
//        ConsultDo consult = consultDao.queryByRelationCode(orderId);
        System.out.println("方法:【sendMsg】 内容:consult==>" + JSON.toJSONString(consult));
        if (null == consult) {
            System.out.println("当前工单未关联咨询,工单id:" + orderId);
            return result;
@ -2502,18 +2671,21 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
            String response = null;
            if (StringUtils.isBlank(sendId)) {
                WlyyDoorServiceOrderDO wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findById(orderId).orElse(null);
                System.out.println("方法:【wlyyDoorServiceOrder】 内容:consult==>" + JSON.toJSONString(consult));
                String sender = "system";
                if (StringUtils.isNoneBlank(wlyyDoorServiceOrder.getDispatcher())) {
                    sender = wlyyDoorServiceOrder.getDispatcher();
                }
                response = imUtill.sendTopicIM(sender, "智能助手", consult.getCode(), contentType, content, null);
                response = imUtill.sendTopicIM(sender, "智能助手", consult.getId(), contentType, content, null);
            } else {
                response = imUtill.sendTopicIM(sendId, sendName, consult.getCode(), contentType, content, null);
                response = imUtill.sendTopicIM(sendId, sendName, consult.getId(), contentType, content, null);
            }
            System.out.println("sendTopicIM结果==>" + response);
            JSONObject resObj = JSONObject.parseObject(response);
            if (resObj.getIntValue("status") == -1) {
                String msg = "上门服务工单消息发送失败:" + resObj.getString("message");
                System.out.println(msg);
                return -1;
            }
        } catch (Exception e) {
            e.printStackTrace();
@ -2524,6 +2696,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        return result;
    }
    /**
     * 判断消息订单是否已被取消
     *
@ -2532,7 +2705,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     */
    public JSONObject orderIsCancel(String messageId) {
        JSONObject result = new JSONObject();
        String sql = "SELECT m.* FROM `wlyy_message` m LEFT JOIN wlyy_door_service_order o on m.relation_code=o.id " +
        String sql = "SELECT m.* FROM `base_system_message` m LEFT JOIN wlyy_door_service_order o on m.relation_code=o.id " +
                "where  o.status = -1 and m.id='" + messageId + "'";
        List<Map<String, Object>> messageList = jdbcTemplate.queryForList(sql);
        if (messageList.size() == 0) {
@ -2551,6 +2724,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     *
     * @param orderId
     */
    @Transactional
    public void cancelConclusion(String orderId) {
        wlyyDoorServiceOrderDao.updateConclusionStatus(orderId);
    }
@ -2561,6 +2735,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     * @param orderId
     * @param isPatientConfirm
     */
    @Transactional
    public void updateIsPatientConfirm(String orderId, Integer isPatientConfirm) {
        WlyyDoorServiceOrderDO wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findById(orderId).orElse(null);
        wlyyDoorServiceOrder.setIsPatientConfirm(isPatientConfirm);
@ -2621,6 +2796,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     * @param positionStatus
     * @param position
     */
    @Transactional
    public void updateDoctorStatus(String doctor, Integer positionStatus, String position) {
        BaseDoctorDO doctor1 = doctorDao.findById(doctor).orElse(null);
        //先注释-需要在补字段
@ -2904,4 +3080,71 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
        }
        return map;
    }
    /**
     * 初始化社区医生
     */
    public void initDoorStatus(String hospital) {
        String sql = "SELECT * from base_doctor doc WHERE doctor_level=1 and id not in ( " +
                "SELECT doctor from wlyy_door_doctor_status " +
                ")";
        //机构就不要了
//        if (org.apache.commons.lang.StringUtils.isNotBlank(hospital)) {
//            sql += "and EXISTS (select id from base_doctor_hospital dh where doc.id = dh.doctor_code and dh.org_code='" + hospital + "' and dh.del=1 ) ";
//        }
        List<BaseDoctorDO> doctorDOs = jdbcTemplate.query(sql, new BeanPropertyRowMapper(BaseDoctorDO.class));
        List<WlyyDoorDoctorStatusDO> doctorList = new ArrayList<>(doctorDOs.size());
        for (BaseDoctorDO baseDoctorDO : doctorDOs) {
            WlyyDoorDoctorStatusDO doctorDoor = new WlyyDoorDoctorStatusDO();
            doctorDoor.setDoctor(baseDoctorDO.getId());
            doctorDoor.setStatus(1);
            doctorDoor.setCreateTime(new Date());
            doctorDoor.setCreateUser("System");
            doctorDoor.setCreateUserName("System");
            doctorList.add(doctorDoor);
        }
        wlyyDoorDoctorStatusDao.saveAll(doctorList);
    }
    public List<Map<String, Object>> getDotorOrgList() {
        String sql = "SELECT a.org_code 'hospitalCode',a.org_name 'hospitalName' \n" +
                "FROM base_doctor_hospital a INNER JOIN base_doctor b\n" +
                "WHERE b.doctor_level='1'\n";
        sql += " GROUP BY a.org_code,a.org_name ";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    public void updateOrderStatusAndTime(String orderId, String status, String doctorArrivingTime) {
        String sql = " update wlyy_door_service_order o set o.prescription_status = 0,o.status ='" + status + "' ,o.doctor_arriving_time='" + doctorArrivingTime + "'  where o.id = '" + orderId + "' ";
        jdbcTemplate.execute(sql);
    }
    public List<Map<String, Object>> getOgrById(String signId, String orderId) {
        String sql = "";
        if (StringUtils.isNotBlank(signId)) {
            sql = "SELECT\n" +
                    "	b.* \n" +
                    "FROM\n" +
                    "	base_service_package_sign_record a\n" +
                    "	INNER JOIN base_service_package_item b ON a.service_package_id = b.service_package_id\n" +
                    "	AND a.id='" + signId + "'";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
            return list;
        }
        if (StringUtils.isNotBlank(orderId)) {
            sql = "SELECT\n" +
                    "	DISTINCT b.* \n" +
                    "FROM\n" +
                    "	base_service_package_sign_record a\n" +
                    "	INNER JOIN wlyy_door_service_order b ON a.service_package_id=b.package_id\n" +
                    "	INNER JOIN base_service_package_item c ON b.package_id = c.service_package_id\n" +
                    "	AND b.id='" + orderId + "'\n";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
            return list;
        }
        return null;
    }
}

+ 891 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/message/DoctorMessageController.java

@ -0,0 +1,891 @@
package com.yihu.jw.hospital.module.message;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.hospital.message.service.SystemMessageService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping(value = "/doctor/message", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, method = {RequestMethod.GET, RequestMethod.POST})
@Api(description = "医生端-消息")
public class DoctorMessageController extends EnvelopRestEndpoint {
    @Autowired
    private SystemMessageService messageService;
    private ObjectMapper objectMapper = new ObjectMapper();
    @Autowired
    private SystemMessageDao messageDao;
//    @Autowired
//    private ThirdJkEduArticleService thirdJkEduArticleService;
//    @Autowired
//    private SpecialistEvaluateSevice specialistEvaluateSevice;
//    @Autowired
//    ElasticsearchUtil elasticsearchUtil;
    //    @Value("${demo.flag}")
    private Boolean demoFlag;
    @RequestMapping(value = "getWaitingMessages", method = RequestMethod.GET)
    @ApiOperation("获取服务工单待接单列表")
    @ResponseBody
    public Envelop getWaitingMessages(
            @ApiParam(name = "message", value = "消息对象") @RequestParam(value = "message") String message,
            @ApiParam(name = "types", value = "消息类型") @RequestParam(value = "types", required = true) String types,
            @ApiParam(name = "page", value = "第几页", defaultValue = "1") @RequestParam(value = "page", required = true) String page,
            @ApiParam(name = "pageSize", value = "", defaultValue = "10") @RequestParam(value = "pageSize", required = true) String pageSize
    ) {
        if (StringUtils.isBlank(pageSize)) {
            pageSize = "10";
        }
        if (page.equals("0")) {
            page = "1";
        }
        String[] split = StringUtils.split(types, ",");
        List<Integer> typeList = new ArrayList<>();
        for (String s : split) {
            typeList.add(Integer.valueOf(s));
        }
        SystemMessageDO message1 = new SystemMessageDO();
        com.alibaba.fastjson.JSONObject object = JSON.parseObject(message);
        message1.setOver(object.getString("over"));
        message1.setIsRead(object.getInteger("read").toString());
        System.out.println("getUID()=>" + getUID());
        message1.setReceiver(getUID());
        try {
            JSONObject waitingMessages = messageService.getWaitingMessages(message1, types, Integer.valueOf(page), Integer.valueOf(pageSize));
            return success("查询成功", waitingMessages);
        } catch (Exception e) {
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }
//    @ResponseBody
//    @RequestMapping(value = "messages")
//    @ApiOperation("查询医生未读消息和最后消息")
//    public Envelop messages(
//            @ApiParam(name = "type", value = "文章审核的时候必传,消息类型,14:提交文章审核,15:审核结果") @RequestParam(value = "type", required = false) Integer type,
//            @ApiParam(name = "flag", value = "标识家医/专科") @RequestParam(value = "flag", required = false) Integer flag
//    ) {
//        try {
//            JSONObject json = messageService.findDoctorAllMessage(getUID(), type, flag);
//            return success("获取消息总数成功!", json);
//        } catch (Exception e) {
//            return failed(e.getMessage());
//        }
//    }
    /**
     * 医生消息总数统计接口
     *
     * @return
     */
//    @RequestMapping(value = "amount")
//    @ResponseBody
//    @ApiOperation("医生消息总数统计接口")
//    public String amount() {
//        try {
//            JSONObject json = messageService.findDoctorAllMessageAmount(getUID());
//            if (json == null) {
//                return error(-1, "获取消息总数失败!");
//            } else {
//                return write(200, "获取消息总数成功!", "data", json);
//            }
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 健康咨询消息列表查询接口
     *
     * @param id
     * @param pagesize 分页大小
     * @return
     */
//    @RequestMapping(value = "consults")
//    @ResponseBody
//    @ApiOperation("健康咨询消息列表查询接口")
//    public String consultList(long id, int pagesize) {
//        try {
//            JSONArray array = new JSONArray();
//            Page<ConsultTeamDo> list = messageService.findConsultListByDoctor(getUID(), id, pagesize);
//            for (ConsultTeamDo consult : list) {
//                if (consult == null) {
//                    continue;
//                }
//                JSONObject json = new JSONObject();
//                json.put("id", consult.getId());
//                // 设置咨询标识
//                json.put("consult", consult.getConsult());
//                // 设置患者标识
//                json.put("patient", consult.getPatient());
//                // 设置患者头像
//                json.put("photo", consult.getPhoto());
//                // 设置主要症状
//                json.put("symptoms", consult.getSymptoms());
//                // 设置患者姓名
//                json.put("name", consult.getName());
//                // 设置状态(0进行中,1已完成,-1患者取消)
//                json.put("status", consult.getStatus());
//                // 设置消息未读数量
//                json.put("unread", consult.getDoctorRead());
//                // 设置咨询时间
//                json.put("time", DateUtil.dateToStr(consult.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
//                array.put(json);
//            }
//            return write(200, "获取健康咨询列表成功!", "list", array);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//    /**
//     * 更新体征消息为已读
//     *
//     * @param msgid
//     * @return
//     */
//    @RequestMapping(value = "read_health")
//    @ResponseBody
//    @ApiOperation("消息设置成已读")
//    public String readHealth(long msgid) {
//        try {
//            messageService.readHealth(msgid);
//            return success("操作成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 根据参数查询发送给我的消息
     */
//    @RequestMapping(value = "find")
//    @ResponseBody
//    @ApiOperation("查询发送给我的消息")
//    public String findMyMessage(String sender, String signStatus) {
//        try {
//            SystemMessageDO msg = messageService.findUnreadSign(sender, getUID(), signStatus);
//            JSONObject json = null;
//            if (msg != null) {
//                json = new JSONObject();
//                json.put("id", msg.getId());
//                json.put("sender", msg.getSender());
//                json.put("senderName", msg.getSenderName());
//                json.put("type", msg.getType());
//                json.put("read", msg.getIsRead()); // 是否已读:1未读,0已读
////                json.put("signStatus", msg.getSignStatus());
//                json.put("status", msg.getOver());
//                json.put("reason", msg.getReason());
//            }
//            return write(200, "获取消息成功!", "data", json);
//        } catch (Exception e) {
//            return "获取失败=>"+e.getMessage();
//        }
//    }
    /**
     * 系统消息(分配健管师 + 随访计划消息 )
     */
//    @RequestMapping(value = "getSystemMessage", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation("获取系统消息")
//    public String getSystemMessage(@ApiParam(value = "第几页", defaultValue = "1")
//                                   @RequestParam Integer page,
//                                   @ApiParam(value = "每页几行", defaultValue = "10")
//                                   @RequestParam Integer pagesize) {
//        try {
//            List<SystemMessageDO> list = messageService.getSystemMessage(getUID(), page, pagesize);
//            return write(200, "获取消息成功!", "list", list);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 续方
     */
//    @RequestMapping(value = "getPrescriptionMessage", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation("获取续方消息")
//    public String getPrescriptionMessage(@ApiParam(value = "第几页", defaultValue = "1")
//                                         @RequestParam Integer page,
//                                         @ApiParam(value = "每页几行", defaultValue = "10")
//                                         @RequestParam Integer pagesize,
//                                         @ApiParam(value = "类型(6团队长待审核,7健管师待取药)", defaultValue = "6")
//                                         @RequestParam Integer type) {
//        try {
//            List<SystemMessageDO> list = messageService.getPrescriptionMessage(getUID(), type, page, pagesize);
//            return write(200, "获取消息成功!", "list", list);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 文章审核
     *
     * @param page
     * @param pagesize
     * @return
     */
//    @RequestMapping(value = "getEduArticleMessage", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation("获取文章审核消息")
//    public String getEduArticleMessage(@ApiParam(name = "type", value = "文章审核的时候必传,消息类型,14:提交文章审核,15:审核结果")
//                                       @RequestParam(value = "type", required = false) Integer type,
//                                       @ApiParam(value = "第几页", defaultValue = "1")
//                                       @RequestParam Integer page,
//                                       @ApiParam(value = "每页几行", defaultValue = "10")
//                                       @RequestParam Integer pagesize) {
//        try {
//            List<SystemMessageDO> list = messageService.getEduArticleMessage(getUID(), type, page, pagesize);
//            return write(200, "获取消息成功!", "list", list);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//    @RequestMapping(value = "getHealthIndexMessage", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation("获取超标指标消息--根据患者分组")
//    public String getHealthIndexMessage() throws Exception {
//        try {
//            Map<String, List<Map<String, Object>>> list = messageService.getHealthIndexMessage(getUID());     //"D20161008003"
//
//            return write(200, "获取超标指标消息成功", "data", list);
//        } catch (Exception ex) {
//            return invalidUserException(ex, -1, ex.getMessage());
//        }
//    }
//    @RequestMapping(value = "getHealthIndexMessageByPatient", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation("获取患者超标指标消息")
//    public String getHealthIndexMessageByPatient(@ApiParam(name = "patient", value = "患者代码", defaultValue = "P20161008001")
//                                                 @RequestParam(value = "patient", required = true) String patient,
//                                                 @ApiParam(name = "type", value = "健康指标类型1血糖,2血压,3体重", defaultValue = "1")
//                                                 @RequestParam(value = "type", required = true) String type,
//                                                 @ApiParam(name = "page", value = "第几页", defaultValue = "1")
//                                                 @RequestParam(value = "page", required = true) Integer page,
//                                                 @ApiParam(name = "pagesize", value = "每页几行", defaultValue = "10")
//                                                 @RequestParam(value = "pagesize", required = true) Integer pagesize) throws Exception {
//        try {
//
//            List<Map<String, String>> list = messageService.getHealthIndexMessageByPatient(getUID(), patient, type, page, pagesize, getObserverStatus());
//            Map<Object, Object> map = new HashMap<Object, Object>();
//            ObjectMapper mapper = new ObjectMapper();
//            mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
//            map.put("status", 200);
//            map.put("msg", "获取超标指标消息成功");
//            map.put("data", list);
//            String tzCode = "";
//            for (Map<String, String> one : list) {
//                tzCode += "," + one.get("tzCode");
//            }
//            map.put("tzCode", StringUtils.isNotEmpty(tzCode) ? tzCode.substring(1) : "");
//            return mapper.writeValueAsString(map);
//        } catch (Exception ex) {
//            return ex.getMessage();
//        }
//    }
    /**
     * 设置某类消息已读
     *
     * @param type 消息类型
     * @return
     */
//    @RequestMapping(value = "setMessageReaded")
//    @ResponseBody
//    @ApiOperation("设置某类消息已读")
//    public Envelop setMessageReaded(@RequestParam @ApiParam(value = "消息类型") Integer type) {
//        try {
//            messageService.setMessageReaded(getUID(), type);
//            return success("设置成功");
//        } catch (Exception e) {
//            return failed(e.getMessage());
//        }
//    }
    /**
     * 设置某条消息已读
     */
//    @RequestMapping(value = "setMessageReadedById")
//    @ResponseBody
//    @ApiOperation("设置某条消息已读")
//    public String setMessageReadedById(@RequestParam @ApiParam(value = "消息id") Long id) {
//        try {
//            messageService.setMessageReadedById(getUID(), id);
//            return write(200, "设置成功");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    @RequestMapping(value = "getMessageNoticeSetting", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取消息设置")
    public String getMessageNoticeSetting() {
        try {
            com.alibaba.fastjson.JSONObject messageNoticeSetting = messageService.getMessageNoticSetting(getUID(), "1");
            return write(200, "查询成功", "data", messageNoticeSetting);
        } catch (Exception e) {
            return e.getMessage();
        }
    }
//    @RequestMapping(value = "saveMessageNoticeSetting", method = RequestMethod.POST)
//    @ResponseBody
//    @ApiOperation("保存消息提醒设置")
//    public Envelop saveMessageNoticeSetting(@ApiParam(name = "json", value = "数据json")
//                                            @RequestParam(value = "json", required = true) String json) {
//        try {
//            MessageNoticeSetting messageNoticeSetting = objectMapper.readValue(json, MessageNoticeSetting.class);
//            if (messageNoticeSetting.getId() == null) {
//                return failed( "参数错误");
//            }
//            messageService.saveMessageNoticeSetting(messageNoticeSetting);
//            return success("设置成功");
//        } catch (Exception e) {
//            return failed(  e.getMessage());;
//        }
//    }
//    /**
//     * 待处理
//     */
//    @RequestMapping(value = "unTreated", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation("专科医生待处理消息")
//    public String selectUntreated() {
//        try {
//            JSONObject json = messageService.selectUntreated(getUID());
//            return write(200, "获取消息总数成功!", "data", json);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//    /**
//     * @param message
//     * @param page
//     * @param pageSize
//     * @return
//     */
//    @RequestMapping(value = "getSpecialist", method = RequestMethod.GET)
//    @ApiOperation("专科医生待处理列表")
//    @ResponseBody
//    public String getSpecialist(@ApiParam(name = "message", value = "消息对象") @RequestParam(value = "message") String message,
//                                @ApiParam(name = "page", value = "第几页", defaultValue = "1") @RequestParam(value = "page", required = true) String page,
//                                @ApiParam(name = "pageSize", value = "", defaultValue = "10") @RequestParam(value = "pageSize", required = true) String pageSize) {
//        if (StringUtils.isBlank(pageSize)) {
//            pageSize = "10";
//        }
//        if (page.equals("0")) {
//            page = "1";
//        }
//        SystemMessageDO  message1 = new SystemMessageDO();
//        com.alibaba.fastjson.JSONObject object = JSON.parseObject(message);
//        message1.setOver(object.getString("over"));
////        message1.setRead(object.getInteger("read"));
//        message1.setReceiver(getUID());
//        try {
//            return write(200, "查询成功!", "data", messageService.getSpecialistUnTreated(message1, Integer.valueOf(page), Integer.valueOf(pageSize)));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//    @RequestMapping(value = "getSpecialistMessages", method = RequestMethod.GET)
//    @ApiOperation("专科医生待处理列表")
//    @ResponseBody
//    public String getSpecialistMessage(@ApiParam(name = "message", value = "消息对象") @RequestParam(value = "message") String message,
//                                       @ApiParam(name = "page", value = "第几页", defaultValue = "1") @RequestParam(value = "page", required = true) String page,
//                                       @ApiParam(name = "pageSize", value = "", defaultValue = "10") @RequestParam(value = "pageSize", required = true) String pageSize) {
//        if (StringUtils.isBlank(pageSize)) {
//            pageSize = "10";
//        }
//        if (page.equals("0")) {
//            page = "1";
//        }
//        SystemMessageDO  message1 = new SystemMessageDO();
//        com.alibaba.fastjson.JSONObject object = JSON.parseObject(message);
//        message1.setOver(object.getString("over"));
//        message1.setRead(object.getInteger("read"));
//        message1.setReceiver(getUID());
//        try {
//            return write(200, "查询成功!", "data", messageService.getSpecialistMessages(message1, Integer.valueOf(page), Integer.valueOf(pageSize)));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 转诊消息
     *
     * @param message
     * @param page
     * @param pageSize
     * @return
     */
//    @RequestMapping(value = "getTransferMessage", method = RequestMethod.GET)
//    @ApiOperation("转诊消息")
//    @ResponseBody
//    public String getTransferMessage(@ApiParam(name = "message", value = "消息对象") @RequestParam(value = "message") String message,
//                                     @ApiParam(name = "page", value = "第几页", defaultValue = "1") @RequestParam(value = "page", required = true) String page,
//                                     @ApiParam(name = "pageSize", value = "", defaultValue = "10") @RequestParam(value = "pageSize", required = true) String pageSize) {
//        if (StringUtils.isBlank(pageSize)) {
//            pageSize = "10";
//        }
//        if (page.equals("0")) {
//            page = "1";
//        }
//        SystemMessageDO  message1 = new SystemMessageDO();
//        com.alibaba.fastjson.JSONObject object = JSON.parseObject(message);
//        message1.setOver(object.getString("over"));
//        message1.setRead(object.getInteger("read"));
//        message1.setReceiver(getUID());
//        try {
//            return write(200, "查询成功!", "data", messageService.getTransferMessage(message1, Integer.valueOf(page), Integer.valueOf(pageSize)));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 发送消息 type:19 受理提醒,20 待办工作提醒 21 服务进展提醒-已完成 22 服务进展提醒-未完成
     * message{sender:"",receiver:"",relationCode:""}
     *
     * @param message
     * @param hospital
     * @param patient
     * @param time
     * @return
     */
//    @RequestMapping(value = "sendMessage", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation("发送消息")
//    public String sendMessage(@ApiParam(name = "message", value = "消息对象(如:{'sender':'','receiver':'','relationCode':'','type':19})", required = true)
//                              @RequestParam(value = "message", required = true) String message,
//                              @ApiParam(name = "hospital", value = "医院code", required = false)
//                              @RequestParam(value = "hospital", required = false) String hospital,
//                              @ApiParam(name = "patient", value = "居民code", required = true)
//                              @RequestParam(value = "patient", required = true) String patient,
//                              @ApiParam(name = "time", value = "时间", required = false)
//                              @RequestParam(value = "time", required = false) Integer time,
//                              @ApiParam(name = "jsonObject", value = "参数", required = false)
//                              @RequestParam(value = "jsonObject", required = false) String jsonObject) {
//        try {
//            com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(message);
//            SystemMessageDO message1 = new SystemMessageDO();
//            message1.setSender(object.getString("sender"));
//            message1.setType(object.getInteger("type").toString());
//            message1.setReceiver(object.getString("receiver"));
//            message1.setRelationCode(object.getString("relationCode"));
//            com.alibaba.fastjson.JSONObject jsonObject1 = com.alibaba.fastjson.JSONObject.parseObject(jsonObject);
//            return write(200, "获取消息成功!", "data", specialistEvaluateSevice.sendMessage(message1, hospital, patient, time, jsonObject1));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 一键已读
     *
     * @param types
     * @return
     */
//    @RequestMapping(value = "setMessageReads", method = RequestMethod.POST)
//    @ResponseBody
//    @ApiOperation("一键已读")
//    public String setMessageRead(
//            @ApiParam(name = "types", value = "消息集合") @RequestParam(value = "types") String types,
//            @ApiParam(name = "flag", value = "标识家医/专科") @RequestParam(value = "flag") Integer flag
//    ) {
//        try {
//            com.alibaba.fastjson.JSONArray array = com.alibaba.fastjson.JSONArray.parseArray(types);
//            List<Integer> typeList = new ArrayList<>();
//            for (int i = 0; i < array.size(); i++) {
//                typeList.add(array.getInteger(i));
//            }
//            return write(200, "获取消息总数成功!", "data", messageService.setMessageReaded(getUID(), typeList, flag));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 设置待办消息已处理
     *
     * @param id
     * @param type
     * @return
     */
//    @RequestMapping(value = "setSpecialistOver", method = RequestMethod.POST)
//    @ResponseBody
//    @ApiOperation("设置待办消息已处理")
//    public String setSpecialistOver(
//            @ApiParam(name = "id", value = "消息id") @RequestParam(value = "id") Long id,
//            @ApiParam(name = "type", value = "消息类型") @RequestParam(value = "type") Integer type
//    ) {
//        try {
//
//            return write(200, "获取消息总数成功!", "data", messageService.setSpecialistOver(id, type));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 获取协同服务消息列表
     */
//    @RequestMapping(value = "getSynergyMessages", method = RequestMethod.GET)
//    @ApiOperation("协同服务消息列表")
//    @ResponseBody
//    public String getSynergyMessage(@ApiParam(name = "message", value = "消息对象") @RequestParam(value = "message") String message,
//                                    @ApiParam(name = "page", value = "第几页", defaultValue = "1") @RequestParam(value = "page", required = true) String page,
//                                    @ApiParam(name = "pageSize", value = "", defaultValue = "10") @RequestParam(value = "pageSize", required = true) String pageSize) {
//        if (StringUtils.isBlank(pageSize)) {
//            pageSize = "10";
//        }
//        if (page.equals("0")) {
//            page = "1";
//        }
//        SystemMessageDO  message1 = new SystemMessageDO();
//        com.alibaba.fastjson.JSONObject object = JSON.parseObject(message);
//        message1.setReceiver(getUID());
//        try {
//            List<SystemMessageDO> messageList = messageService.getSynergyMessages(message1, Integer.valueOf(page), Integer.valueOf(pageSize));
//            return write(200, "查询成功!", "data", messageList);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 设置协同消息已读
     */
//    @RequestMapping(value = "setSynergyMessagesByRead", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation("设置协同消息已读")
//    public String setSynergyMessagesByRead() {
//        try {
//            return write(200, "获取消息总数成功!", "data", messageService.setSynergyMessagesByRead(getUID()));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * PCIM专科服务
     */
//    @RequestMapping(value = "getSpeciaistByType")
//    @ApiOperation("PCIM专科服务列表")
//    @ResponseBody
//    public String getSpeciaistByType(String types,
//                                     Integer page,
//                                     Integer pageSize) {
//        List<Integer> typeList = new ArrayList<>();
//        String str[] = types.split(",");
//        for (int i = 0; i < str.length; i++) {
//            typeList.add(Integer.parseInt(str[i]));
//        }
//        try {
//            return write(200, "查询成功!", "data", messageService.getSpeciaistByType(typeList, getUID(), page, pageSize));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * PCIM专科医生总条数
     *
     * @return
     */
//    @RequestMapping(value = "getDoctorBySpecialistAllMessage", method = RequestMethod.GET)
//    @ApiOperation("PCIM专科医生总条数")
//    @ResponseBody
//    public String getDoctorBySpecialistAllMessage() {
//        try {
//            return write(200, "查询成功!", "data", messageService.getDoctorBySpecialistAllMessage(getUID()));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * PCIM-转诊消息
     *
     * @param page
     * @param pageSize
     * @return
     */
//    @RequestMapping(value = "getTransferMessageByPCIM", method = RequestMethod.GET)
//    @ApiOperation("PCIM-转诊消息")
//    @ResponseBody
//    public String getTransferMessageByPCIM(@ApiParam(name = "page", value = "第几页", defaultValue = "1") @RequestParam(value = "page", required = true) String page,
//                                           @ApiParam(name = "pageSize", value = "", defaultValue = "10") @RequestParam(value = "pageSize", required = true) String pageSize) {
//        if (StringUtils.isBlank(pageSize)) {
//            pageSize = "10";
//        }
//        if (page.equals("0")) {
//            page = "1";
//        }
//        try {
//            return write(200, "查询成功!", "data", messageService.getTransferMessageByPCIM(getUID(), Integer.valueOf(page), Integer.valueOf(pageSize)));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * PCIM-签约服务列表
     *
     * @param types
     * @param page
     * @param pageSize
     * @return
     */
//    @RequestMapping(value = "getFamilyByType", method = RequestMethod.GET)
//    @ApiOperation("PCIM-签约服务列表")
//    @ResponseBody
//    public String getFamilyByType(@ApiParam(name = "types", value = "消息对象") @RequestParam(value = "types") String types,
//                                  @ApiParam(name = "page", value = "第几页", defaultValue = "1") @RequestParam(value = "page", required = true) Integer page,
//                                  @ApiParam(name = "pageSize", value = "", defaultValue = "10") @RequestParam(value = "pageSize", required = true) Integer pageSize) {
//        List<Integer> typeList = new ArrayList<>();
//        String str[] = types.split(",");
//        for (int i = 0; i < str.length; i++) {
//            typeList.add(Integer.parseInt(str[i]));
//        }
//        try {
//            return write(200, "查询成功!", "data", messageService.getFamilySignByType(typeList, getUID(), page, pageSize));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * 获取pcim家医服务
     *
     * @param page
     * @param pageSize
     * @return
     */
//    @RequestMapping(value = "getPCIMFamilyServer", method = RequestMethod.GET)
//    @ApiOperation("PCIM-家医服务")
//    @ResponseBody
//    public String getPCIMFamilyServer(@ApiParam(name = "types", value = "消息对象") @RequestParam(value = "types") String types,
//                                      @ApiParam(name = "page", value = "第几页", defaultValue = "1") @RequestParam(value = "page", required = true) Integer page,
//                                      @ApiParam(name = "pageSize", value = "", defaultValue = "10") @RequestParam(value = "pageSize", required = true) Integer pageSize) {
//        try {
//            List<Integer> typeList = new ArrayList<>();
//            String str[] = types.split(",");
//            for (int i = 0; i < str.length; i++) {
//                typeList.add(Integer.parseInt(str[i]));
//            }
//            return write(200, "查询成功!", "data", messageService.getPCIMFamilyServer(getUID(), typeList, page, pageSize));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * PCIM-其他业务
     */
//    @RequestMapping(value = "getOtherService", method = RequestMethod.GET)
//    @ApiOperation("PCIM-其他业务")
//    @ResponseBody
//    public String getOtherService(@ApiParam(name = "types", value = "消息对象") @RequestParam(value = "types") String types,
//                                  @ApiParam(name = "page", value = "第几页", defaultValue = "1") @RequestParam(value = "page", required = true) Integer page,
//                                  @ApiParam(name = "pageSize", value = "", defaultValue = "10") @RequestParam(value = "pageSize", required = true) Integer pageSize) {
//        try {
//            List<Integer> typeList = new ArrayList<>();
//            String str[] = types.split(",");
//            for (int i = 0; i < str.length; i++) {
//                typeList.add(Integer.parseInt(str[i]));
//            }
//            return write(200, "查询成功!", "data", messageService.getOtherService(getUID(), typeList, page, pageSize));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * PCIM--家庭医生消息总条数
     *
     * @return
     */
//    @RequestMapping(value = "getDoctorByFamilyAllMessage", method = RequestMethod.GET)
//    @ApiOperation("PCIM--家庭医生消息总条数")
//    @ResponseBody
//    public String getDoctorByFamilyAllMessage() {
//        try {
//            return write(200, "查询成功!", "data", messageService.getDoctorByFamilyAllMessage(getUID()));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
    /**
     * PCIM-分析总览
     *day         天数(3,7,30)
     *area        父code
     *level       等级  1 团队,2 机构,3 区,4 市
     *level2_type 指标代码 例如性别 1 男 2 女  不传就返回男和女的总和
     */
//    @RequestMapping(value = "AnalysisOverview", method = RequestMethod.GET)
//    @ApiOperation("PCIM-分析总览")
//    @ResponseBody
//    public String AnalysisOverview(@ApiParam(name = "day", value = "天数") @RequestParam(value = "day") int day,
//                                   @RequestParam(required = false) String area,
//                                   @RequestParam(required = false) Integer level,
//                                   @RequestParam(required = false) String level2_type) {
//        try {
//            if (demoFlag) {
//                return "{\n" +
//                        "    \"msg\": \"查询成功!\",\n" +
//                        "    \"data\": {\n" +
//                        "        \"weixinBindCount\": 1,\n" +
//                        "        \"weixinBindCountChange\": 7,\n" +
//                        "        \"articleCountChange\": \"0.01%\",\n" +
//                        "        \"consultCount\": 12,\n" +
//                        "        \"articleCount\": \"0.05%\",\n" +
//                        "        \"consultCount1\": 24,\n" +
//                        "        \"reservationCount1\": 24,\n" +
//                        "        \"articleCount1\": \"0.03%\",\n" +
//                        "        \"weixinBindCount1\": 8,\n" +
//                        "        \"reservationCount\": 34,\n" +
//                        "        \"consultCountChange\": 12,\n" +
//                        "        \"reservationCountChange\": 10\n" +
//                        "    },\n" +
//                        "    \"status\": 200\n" +
//                        "}";
//            }
//            if (level == null) {
//                level = 5;
//            }
//            return write(200, "查询成功!", "data", messageService.AnalysisOverview(getUID(), day, area, level, level2_type));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//    @RequestMapping(value = "getAllNotOverMessage", method = RequestMethod.GET)
//    @ApiOperation("PCIM--专科/家医不同type的消息的总数")
//    @ResponseBody
//    public String getAllNotOverMessage() {
//        try {
//            return write(200, "查询成功!", "data", messageService.getAllNotOverMessage(getUID()));
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//    @RequestMapping(value = "getExaminationMessage", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation("获取在线复诊消息")
//    public String getPrescriptionMessage(@ApiParam(value = "第几页", defaultValue = "1")
//                                         @RequestParam Integer page,
//                                         @ApiParam(value = "每页几行", defaultValue = "10")
//                                         @RequestParam Integer pagesize
//    ) {
//        try {
//            //31 在线复诊咨询待审核提醒
//            List<SystemMessageDO> list = messageService.getPrescriptionMessage(getUID(), 31, page, pagesize);
//            return write(200, "获取消息成功!", "list", list);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//    @RequestMapping(value = "getMessageByType")
//    @ResponseBody
//    @ApiOperation("根据类型获取消息")
//    public String getFollowupMessage(@ApiParam(name = "type", value = "消息类型,4:待随访消息")
//                                     @RequestParam(value = "type", required = false) Integer type,
//                                     @ApiParam(value = "第几页", defaultValue = "1")
//                                     @RequestParam Integer page,
//                                     @ApiParam(value = "每页几行", defaultValue = "10")
//                                     @RequestParam Integer pagesize) {
//        try {
//            List<SystemMessageDO> list = messageService.getMessageByType(getUID(), type, page, pagesize);
//            return write(200, "获取消息总数成功!", "data", list);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//    @RequestMapping(value = "getBingQingMessage")
//    @ResponseBody
//    @ApiOperation("获取病情跟踪消息")
//    public String getBingQingMessage(
//            @ApiParam(value = "第几页", defaultValue = "1")
//            @RequestParam Integer page,
//            @ApiParam(value = "每页几行", defaultValue = "10")
//            @RequestParam Integer pagesize) {
//        try {
//            List<SystemMessageDO> list = messageService.getBingQingMessage(getUID(), page, pagesize);
//            return write(200, "获取消息总数成功!", "data", list);
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
//    @RequestMapping(value = "setMessageOverBySender", method = RequestMethod.POST)
//    @ResponseBody
//    @ApiOperation("根据接收者和类型设消息为已处理")
//    public String setMessageOverBySender(@ApiParam(name = "sender", value = "发送者")
//                                         @RequestParam(value = "sender") String sender,
//                                         @ApiParam(name = "type", value = "消息类型")
//                                         @RequestParam(value = "type") Integer type) {
//        try {
//            messageService.setMessageOverBySender(sender, type);
//            return write(200, "更新成功!");
//        } catch (Exception e) {
//            return e.getMessage();
//        }
//    }
}

+ 223 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/utils/CommonUtil.java

@ -0,0 +1,223 @@
//package com.yihu.jw.hospital.utils;
//
//import com.fasterxml.jackson.databind.node.ObjectNode;
//import com.yihu.fastdfs.FastDFSUtil;
//import com.yihu.jw.entity.util.SystemConfEntity;
//import com.yihu.jw.util.http.HttpClientUtil;
//import org.apache.commons.lang3.StringEscapeUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.http.HttpEntity;
//import org.apache.http.HttpResponse;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.entity.ContentType;
//import org.apache.http.entity.mime.MultipartEntityBuilder;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClientBuilder;
//import org.apache.http.util.EntityUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.*;
//import java.net.URLDecoder;
//import java.nio.charset.Charset;
//import java.text.DecimalFormat;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.UUID;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
///**
// * Created by yeshijie on 2023/2/13.
// */
//@Component
//public class CommonUtil {
//
//    private Logger logger = LoggerFactory.getLogger(CommonUtil.class);
//
//    @Value("${fastDFS.fastdfs_file_url}")
//    private String fastdfs_file_url;
//
//    @Autowired
//    private HttpClientUtil httpClientUtil;
//
//    public static String getCode() {
//        return UUID.randomUUID().toString().replaceAll("-", "");
//    }
//
//    /**
//     * 传入身高体重,计算BMI值
//     *
//     * @param weightStr 体重
//     * @param heightStr 身高
//     * @return
//     */
//    public static double getBMIByWeightAndHeight(String weightStr, String heightStr) {
//
//        DecimalFormat df2 = new DecimalFormat("###.00");
//
//        double weight = Double.parseDouble(weightStr);
//        Integer heightCM = Integer.parseInt(heightStr);
//        heightStr = df2.format(heightCM / 100d);
//
//        double height = Double.parseDouble(heightStr);
//        double bmi = weight / (height * height);
//
//        return bmi;
//    }
//
//    /**
//     * 删除文件夹
//     * @param folder
//     */
//    public static void deleteFolder(File folder){
//        File[] files  = folder.listFiles();
//        if (files != null){
//            for(File f: files){
//                if (f.isDirectory()){
//                    deleteFolder(f);
//                }else {
//                    f.delete();
//                }
//            }
//        }
//        folder.delete();
//    }
//
//    /**
//     * double转字符串,在转int
//     * double*100转int 有bug 34.3会会变成3429
//     * @param d
//     * @return
//     */
//    public static Integer doubleToInt(Double d){
//        if(d==null){
//            return 0;
//        }
//        String currency = String.valueOf(d);
//        int index = currency.indexOf(".");
//        int length = currency.length();
//        Integer amLong = 0;
//        if(index == -1){
//            amLong = Integer.valueOf(currency+"00");
//        }else if(length - index >= 3){
//            amLong = Integer.valueOf((currency.substring(0, index+3)).replace(".", ""));
//            if(length-index>3){
//                if(Integer.valueOf(currency.substring(index+3,index+4))>=5){
//                    amLong++;
//                }
//            }
//        }else if(length - index == 2){
//            amLong = Integer.valueOf((currency.substring(0, index+2)).replace(".", "")+0);
//        }else{
//            amLong = Integer.valueOf((currency.substring(0, index+1)).replace(".", "")+"00");
//        }
//        return amLong;
//    }
//
//    public static List<String> getTagContent(String source, String regString) {
//        List<String> result = new ArrayList<String>();
//        Matcher m = Pattern.compile(regString).matcher(source);
//        while (m.find()) {
//            try {
//                String r = StringEscapeUtils.unescapeHtml3(URLDecoder.decode(m.group(1),"utf-8"));
//                result.add(r);
//            } catch (UnsupportedEncodingException e) {
//                e.printStackTrace();
//            }
//        }
//        return result;
//    }
//
//    public String copyTempVoice(String voices) throws Exception {
//        // 文件保存的临时路径
//        String serverUrl = fastdfs_file_url;
//        FastDFSUtil fastDFSUtil = new FastDFSUtil();
//        String fileUrls = "";
//        File f = new File(voices);
//        if (f.exists()) {
//            String fileName = f.getName();
//            InputStream in = new FileInputStream(f);
//            ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
//            in.close();
//            if (result != null) {
//                fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",") + serverUrl
//                        + result.get("groupName").toString().replaceAll("\"", "") + "/"
//                        + result.get("remoteFileName").toString().replaceAll("\"", "");
//                f.delete();
//            }
//        }
//        return fileUrls;
//    }
//
//
//    public String request(String remote_url, MultipartFile file, String type) {
//        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
//        logger.info(file.getOriginalFilename());
//        String result = "";
//        try {
//            String fileName = file.getOriginalFilename();
//            HttpPost httpPost = new HttpPost(remote_url);
//            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
//            builder.addBinaryBody("file", file.getInputStream(), ContentType.MULTIPART_FORM_DATA, fileName);// 文件流
//            builder.addTextBody("filename", fileName);// 类似浏览器表单提交,对应input的name和value
//            if (!org.springframework.util.StringUtils.isEmpty(type)) {
//                builder.addTextBody("type", type); //发送类型
//            }
//            HttpEntity entity = builder.build();
//            httpPost.setEntity(entity);
//            HttpResponse response = httpClient.execute(httpPost);// 执行提交
//            HttpEntity responseEntity = response.getEntity();
//            if (responseEntity != null) {
//                // 将响应内容转换为字符串
//                result = EntityUtils.toString(responseEntity, Charset.forName("UTF-8"));
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                httpClient.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        return result;
//    }
//
//    public String copyTempImage(String files) throws Exception {
//        String tempPath = SystemConfEntity.getInstance().getTempPath() + File.separator;
//        // 文件保存的临时路径
//        String[] fileArray = files.split(",");
//        FastDFSUtil fastDFSUtil = new FastDFSUtil();
//        String fileUrls = "";
//        for (String file : fileArray) {
//            File f = new File(tempPath + file);
//            File fs = new File(tempPath + file + "_small");
//            if (f.exists()) {
//                String fileName = f.getName();
//                InputStream in = new FileInputStream(f);
//                ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
//                in.close();
//                if (result != null) {
//                    //1.3.7去掉前缀
//                    fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",")
//                            + result.get("groupName").toString().replaceAll("\"", "") + "/"
//                            + result.get("remoteFileName").toString().replaceAll("\"", "");
//                    f.delete();
//                    if (fs.exists()) {
//                        fs.delete();
//                    }
//                }
//            }
//        }
//        System.out.println("文件地址:"+fileUrls);
//        return fileUrls;
//
//    }
//}