Browse Source

Merge branch 'dev' of yeshijie/wlyy2.0 into dev

叶仕杰 4 years ago
parent
commit
020af0dd48

+ 256 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/consult/PatientConsultEndpoint.java

@ -0,0 +1,256 @@
package com.yihu.jw.care.endpoint.consult;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
import com.yihu.jw.doctor.service.BaseDoctorInfoService;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.hospital.family.service.WlyyFamilyMemberService;
import com.yihu.jw.hospital.message.service.SystemMessageService;
import com.yihu.jw.im.service.ImService;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import com.yihu.jw.util.common.FileUtil;
import com.yihu.jw.wechat.dao.WechatDao;
import com.yihu.jw.wechat.service.WechatInfoService;
import com.yihu.jw.wlyy.service.WlyyBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.web.bind.annotation.*;
import java.security.MessageDigest;
import java.util.*;
/**
 * @author huangwenjie
 */
@RestController
@RequestMapping(value = BaseHospitalRequestMapping.PatientIM.PREFIX)
@Api(value = "居民端咨询IM接口", description = "居民端咨询IM接口", tags = {"居民端咨询IM接口"})
public class PatientConsultEndpoint extends EnvelopRestEndpoint {
	private static final Logger logger = LoggerFactory.getLogger(PatientConsultEndpoint.class);
	@Autowired
	private ImService imService;
	@Autowired
	private BasePatientService basePatientService;
	
	
	@Autowired
	private WechatInfoService wechatInfoService;
	
	@Autowired
	private WechatDao wechatDao;
	@Autowired
	private WlyyBusinessService wlyyBusinessService;
	@Autowired
	private BaseDoctorDao baseDoctorDao;
	@Autowired
	private BasePatientDao basePatientDao;
	
	@Autowired
	FileUploadService fileUploadService;
	@Autowired
	private BaseDoctorInfoService doctorInfoService;
	@Autowired
	private SystemMessageService systemMessageService;
	@Autowired
	private BaseDoctorRoleDao doctorRoleDao;
	@Autowired
	public ImUtil imUtil;
	@Autowired
	private WlyyFamilyMemberService familyMemberService;
	@Value("${fastDFS.fastdfs_file_url}")
	private String fastdfs_file_url;
	@Value("${testPattern.sign}")
	private String isClose;
	@Value("${wechat.id}")
	private String wechat_appid;
	@Autowired
	private FileUtil fileUtil;
	
	@GetMapping(value = BaseHospitalRequestMapping.PatientIM.participants)
	@ApiOperation(value = "获取会话成员")
	public ListEnvelop participants(
			@ApiParam(name = "sessionId", value = "会话ID")
			@RequestParam(value = "sessionId",required = true) String sessionId)throws Exception{
		
		JSONArray participants = imService.getSessions(sessionId);
		return success(participants);
	}
	
	@GetMapping(value = BaseHospitalRequestMapping.PatientIM.getSessionMessage)
	@ApiOperation(value = "根据会话ID获取消息记录")
	public ListEnvelop getSessionMessage(
			@ApiParam(name = "sessionId", value = "会话ID")
			@RequestParam(value = "sessionId",required = true) String sessionId,
			@ApiParam(name = "startMsgId", value = "开始的消息记录ID")
			@RequestParam(value = "startMsgId",required = false) String startMsgId,
			@ApiParam(name = "endMsgId", value = "结束的消息记录ID")
			@RequestParam(value = "endMsgId",required = false) String endMsgId,
			@ApiParam(name = "page", value = "第几页")
			@RequestParam(value = "page",required = true) int page,
			@ApiParam(name = "pagesize", value = "分页数")
			@RequestParam(value = "pagesize",required = true) int pagesize)throws Exception{
		JSONArray messageArray = imService.getSessionMessage(sessionId, startMsgId, endMsgId, page, pagesize, getUID());
		return success(messageArray);
	}
	
	@PostMapping(value = BaseHospitalRequestMapping.PatientIM.getSign)
	@ApiOperation(value = "获取微信签名", notes = "获取微信签名")
	public Envelop getSign(@ApiParam(name = "pageUrl", value = "授权页面")
	                       @RequestParam(value = "pageUrl", required = true)String pageUrl,
	                       @ApiParam(name = "wxId", value = "微信id")
	                       @RequestParam(value = "wxId", required = true)String wxId) throws Exception {
		logger.info("pageUrl="+pageUrl);
		logger.info("wxId="+wxId);
		String ticket = wechatInfoService.getJsapi_ticketByToken(wxId);
		WxWechatDO wxWechatDO = wechatDao.findById(wxId);
		Map<Object, Object> map = new HashMap<Object, Object>();
		if (ticket != null) {
			String noncestr = UUID.randomUUID().toString();
			long timestamp = System.currentTimeMillis() / 1000;
			String url = pageUrl;
			logger.info("getSign.url="+url);
			String str = "jsapi_ticket=" + ticket + "&noncestr=" + noncestr + "&timestamp=" + timestamp + "&url=" + url;
			logger.info("getSign.str="+str);
			// sha1加密
			String signature = SHA1(str);
			map.put("noncestr", noncestr);
			map.put("timestamp", timestamp);
			map.put("signature", signature);
			map.put("appid", wxWechatDO.getAppId());
			return success(PatientRequestMapping.Wechat.api_success,map);
		}
		return failed(PatientRequestMapping.Wechat.api_error);
	}
	
	/**
	 * @description: SHA、SHA1加密 @parameter: str:待加密字符串 @return: 加密串
	 **/
	public String SHA1(String str) throws Exception {
		try {
			MessageDigest digest = MessageDigest.getInstance("SHA-1"); // 如果是SHA加密只需要将"SHA-1"改成"SHA"即可
			digest.update(str.getBytes());
			byte messageDigest[] = digest.digest();
			// Create Hex String
			StringBuffer hexStr = new StringBuffer();
			// 字节数组转换为 十六进制 数
			for (int i = 0; i < messageDigest.length; i++) {
				String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
				if (shaHex.length() < 2) {
					hexStr.append(0);
				}
				hexStr.append(shaHex);
			}
			return hexStr.toString();
			
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		}
	}
	
	@PostMapping(value = BaseHospitalRequestMapping.PatientIM.updateConsultParticipant)
	@ApiOperation(value = "更新会话成员(新增或删除)", notes = "更新会话成员(新增或删除)")
	public Envelop 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)throws Exception{
		imService.updateParticipant(sessionid,userid,olduserid);
		return success("操作成功");
	}
	
	@PostMapping(value = "messageAppend")
	@ApiOperation(value = "居民单聊会话发送消息", notes = "居民单聊会话发送消息")
	public Envelop messageAppend(
			@ApiParam(name = "sender_id", value = "发送者id", defaultValue = "")
			@RequestParam(value = "sender_id", required = true) String sender_id,
			@ApiParam(name = "sender_name", value = "发送者姓名", defaultValue = "")
			@RequestParam(value = "sender_name", required = true) String sender_name,
			@ApiParam(name = "session_id", value = "session_id", defaultValue = "")
			@RequestParam(value = "session_id", required = false) String session_id,
			@ApiParam(name = "content_type", value = "内容类型", defaultValue = "")
			@RequestParam(value = "content_type", required = true) String content_type,
			@ApiParam(name = "content", value = "消息内容", defaultValue = "")
			@RequestParam(value = "content", required = true) String content,
			@ApiParam(name = "extend", value = "扩展内容", defaultValue = "")
			@RequestParam(value = "extend", required = false) String extend,
			@ApiParam(name = "type", value = "咨询type", defaultValue = "")
			@RequestParam(value = "type", required = false) String type,
			@ApiParam(name = "times", value = "times", defaultValue = "")
			@RequestParam(value = "times", required = false) Integer times
	)throws Exception{
		List<String> failed = new ArrayList<>();
		//处理语音文件
		if(!org.springframework.util.StringUtils.isEmpty(wechat_appid)){
			if("3".equalsIgnoreCase(content_type)){//语音文件
				String voicepath = imService.fetchWxVoices(wechat_appid);
				logger.info("voice_path:"+voicepath);
				JSONObject obj = new JSONObject();
				String voiceurl = "";
				// 将临时语音拷贝到正式存储路径下
				if (org.apache.commons.lang3.StringUtils.isNotEmpty(voicepath)) {
					voiceurl = fileUtil.copyTempVoice(voicepath,fastdfs_file_url);
					obj.put("path", voiceurl);
					obj.put("times", times);
					content = obj.toString();
				}
			}else if("2".equalsIgnoreCase(content_type)){//图片文件
				String imagepath = imService.fetchWxImages(wechat_appid);
				logger.info("image_path:"+imagepath);
				String imgeUrl = "";
				// 将临时语音拷贝到正式存储路径下
				if (org.apache.commons.lang3.StringUtils.isNotEmpty(imagepath)) {
					imgeUrl = fileUtil.copyTempVoice(imagepath,fastdfs_file_url);
					content = imgeUrl;
				}
			}else{
			}
		}
		session_id = imService.getPatientGuaidenceConsult(sender_id,session_id,type);
		String result = imService.patientGuaidenceAppend(sender_id,sender_name,session_id,content_type,content,"1",extend);
		List<BaseDoctorRoleDO> doctorRoleDOS = doctorRoleDao.findByRoleCode("guidance");
		for (BaseDoctorRoleDO doctorRoleDO:doctorRoleDOS){
			System.out.println("发送外层SOCKET消息:通知医生导诊");
			JSONObject object = new JSONObject();
			object.put("socket_sms_type",13);
			object.put("relation_code",session_id);
			imService.sendWaiSocketMessage(sender_id,doctorRoleDO.getDoctorCode(),object.toString(),"1");
		}
		return success(result);
	}
}

+ 3 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/sign/SignEndpoint.java

@ -237,6 +237,9 @@ public class SignEndpoint extends EnvelopRestEndpoint {
            @RequestParam String doctorId) {
        try{
            JSONObject result = capacityAssessmentRecordService.capacityAssessment(jsonData,doctorId);
            if(result == null){
                return ObjEnvelop.getError("已存在评估报告,请勿重复生成");
            }
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return ObjEnvelop.getError(result.getString(ResponseContant.resultMsg));
            }

+ 1 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/sign/CapacityAssessmentRecordService.java

@ -119,7 +119,7 @@ public class CapacityAssessmentRecordService extends BaseJpaService<CapacityAsse
        res.put("2",0);
        res.put("3",0);
        String sql = "SELECT COUNT(DISTINCT ar.patient),level_conclusion from  " +
        String sql = "SELECT COUNT(DISTINCT ar.patient) count,level_conclusion from  " +
                "base_capacity_assessment_record ar, " +
                "base_service_package_sign_record sr,base_service_package_record r,  " +
                "                base_service_package_item i,base_team_member m  " +