Browse Source

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

trick9191 7 years ago
parent
commit
9ba1391b69

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

@ -25,7 +25,7 @@ public interface PrenatalInspectorPlanDao extends PagingAndSortingRepository<Pre
    //应产检时间前14天后14天待产检计划(不包括应产检当天)
    @Query(value = "SELECT a.* FROM wlyy_prenatal_inspector_plan a, (SELECT t.* from wlyy_prenatal_inspector_plan t where t.id = ?1 )b  " +
            " WHERE a.inspection_time >= DATE_ADD(b.inspection_time,INTERVAL -14 DAY) and a.inspection_time <= DATE_ADD(b.inspection_time,INTERVAL 14 DAY) " +
            "and a.inspection_time != b.inspection_time ORDER BY a.inspection_time DESC ",nativeQuery = true)
            " and a.inspection_time != b.inspection_time and a.patient = b.patient ORDER BY a.inspection_time DESC ",nativeQuery = true)
    List<PrenatalInspectorPlan> getScopeById(Long prenatalId);

+ 0 - 106
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/ylz/ThirdEHCService.java

@ -1,106 +0,0 @@
package com.yihu.wlyy.service.third.ylz;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.ylz.PayLog;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.ylz.PayLogDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.procedure.spi.ParameterRegistrationImplementor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
 * Created by Reece on 2017/9/20.
 * 日志服务
 */
@Service
public class ThirdEHCService extends BaseService {
    private static Logger logger = LoggerFactory.getLogger(ThirdEHCService.class);
    @Autowired
    private PayLogDao payLogDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private PatientDao patientDao;
    /**
     *公众号消息推送接口
     */
    public String pushMessage(JSONObject json) {
        String flag = "0000";
        try {
            logger.info("push message "+ json);
            org.json.JSONObject model = new org.json.JSONObject();
            String url = null;
            model.put("remark", "产检内容以医生实际检查为准。点击进行预约");
            model.put("first", "电子健康卡提醒");
            model.put("url",url);
            model.put("keyword1", "电子健康卡提醒");
            json.put("keyword2", "电子健康卡推送");
            String messageType = json.containsKey("message_type") ? json.getString("message_type") : null;
            JSONObject messageContent = json.containsKey("message_content") ? json.getJSONObject("message_content") : null;
            String idType = json.containsKey("id_type") ? json.getString("id_type") : null;
            String idNo = json.containsKey("id_no") ? json.getString("id_no") : null;
            String openId = json.containsKey("open_id") ? json.getString("open_id") : null;
            if (idNo == null && openId ==null) {
                return "0001";
            }
            if (idNo != null) {
                Patient patient = patientDao.findByIdcard(idNo);
                pushMsgTask.putAgentWxMsg(patient.getCode(), 18, model);
            }
            if (StringUtils.isNotEmpty(openId) && !"undefined".equals(openId)) {
                List<Patient> patients = patientDao.findPatientByOpenid(openId);
                for (Patient patient : patients) {
                    Patient patient1 = patientDao.findByCode(patient.getCode());
                    pushMsgTask.putAgentWxMsg(patient1.getCode(), 18, model);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            flag = "1000";
        }
        return flag;
    }
    /**
     * 保存http调用日志  type 0家庭签约支付 1续方支付
     */
    public void saveHttpLog(Boolean isSuccess, String url, String content, String method, String header, String params, String response, String error, String type) {
        try {
            //新增日志
            PayLog log = new PayLog();
            log.setType(type);
            log.setApi(url);
            log.setContent(content);
            log.setMethod(method);
            log.setHeader(header);
            log.setParams(params);
            log.setCreateTime(new Date());
            log.setResponse(response);
            log.setError(error);
            log.setStatus(isSuccess ? "1" : "0");
            payLogDao.save(log);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

+ 113 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/ylz/ThirdMessageService.java

@ -0,0 +1,113 @@
package com.yihu.wlyy.service.third.ylz;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created by Reece on 2017/9/20.
 * 第三方消息功能
 */
@Service
public class ThirdMessageService extends BaseService {
    private static Logger logger = LoggerFactory.getLogger(ThirdMessageService.class);
    @Autowired
    private WeiXinAccessTokenUtils accessTokenUtils;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private PatientDao patientDao;
    /**
     * 公众号消息推送接口
     */
    public JSONObject pushMessage(int type, JSONObject json) throws Exception {
        JSONObject response = new JSONObject();
        response.put("ret_code", "0000");
        response.put("ret_msg", "操作成功");
        try {
            String openId = json.has("openId") ? json.getString("openId") : null;
            JSONObject messageContent = json.has("messageContent") ? json.getJSONObject("messageContent") : null;
            String name = json.has("name") ? json.getString("name") : null;
            if (StringUtils.isEmpty(openId)) {
                response.put("ret_code", "0001");
                response.put("ret_msg", "openId参数不能为空!");
                return response;
            }
            if (messageContent == null) {
                response.put("ret_code", "0002");
                response.put("ret_msg", "messageContent参数不能为空!");
                return response;
            }
            switch (type) {
                case 0:
                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 18, openId, name, messageContent);
                    break;
                case 1:
                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 18, openId, name, messageContent);
                    break;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            response.put("ret_code", "1000");
            response.put("ret_msg", ex.getMessage());
        }
        return response;
    }
    /**
     * 公众号消息推送接口
     */
    public JSONObject physicalExamination(String idCard, String medicalNo, String medicalOrg, String medicalTime) throws Exception {
        JSONObject response = new JSONObject();
        response.put("ret_code", "0000");
        response.put("ret_msg", "操作成功");
        try {
            if (StringUtils.isEmpty(idCard)) {
                response.put("ret_code", "0001");
                response.put("ret_msg", "身份证不能为空!");
            }
            Patient patient = patientDao.findByIdcard(idCard);
            String name = patient.getName();
            String mobile = patient.getMobile();
            String openId = patient.getOpenid();
            JSONObject model = new JSONObject();
            String url = "jkda/html/jiankangtijianxiangqing.html?medicalNo=" + medicalNo;
            model.put("remark", "您可以点击查看报告详情,或通过”健康档案—体检记录“入口查看");
            model.put("first", "您好,您的体检报告已经生成");
            model.put("url", url);
            model.put("keyword1", name);
            model.put("keyword2", StringUtils.isEmpty(mobile) ? "" : mobile);
            model.put("keyword3", medicalNo);
            model.put("keyword4", medicalOrg);
            model.put("keyword5", medicalTime);
            if (StringUtils.isNotEmpty(openId) && !"undefined".equals(openId)) {
                pushMsgTask.putAgentWxMsg(patient.getCode(), 18, model);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            response.put("ret_code", "1000");
            response.put("ret_msg", ex.getMessage());
        }
        return response;
    }
}

+ 77 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/template/ThirdMessageController.java

@ -0,0 +1,77 @@
package com.yihu.wlyy.web.third.template;
import com.yihu.wlyy.service.third.ylz.ThirdMessageService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * 提供给第三方消息功能(有token验证无身份登录验证)
 * Created by Reece on 2017/12/7
 */
@RestController
@RequestMapping("/wlyygc/template/")
@Api(description = "第三方模板消息")
public class ThirdMessageController extends BaseController {
    @Autowired
    private ThirdMessageService thirdMessageService;
    /**
     * 公众号消息推送接口(第三方已有openId)
     *
     * @param type 0电子健康注册 1电子健康卡用卡
     * @param data
     * @return
     */
    @ApiOperation("公众号推送接口")
    @RequestMapping(value = "/pushMessage", method = RequestMethod.POST)
    @ResponseBody
    public String pushMessage(@ApiParam(name = "type", defaultValue = "0")
                              @RequestParam(value = "type", required = true) int type,
                              @ApiParam(name = "data", defaultValue = "{ \"openId\": \"o7NFZwynwEkr5JkuVIYkpvYGN9Ic\", \"name\": \"赵卫\", \"messageContent\": { \"first\": \"尊敬的用户,您已成功在中山医院注册居民电子健康卡,请点击领取使用。\", \"remark\": \"请点击领取使用。\", \"url\": \"http://www.baidu.com\", \"keyword1\": \"电子健康卡\", \"keyword2\": \"赵卫\", \"keyword3\": \"2017-12-08 18:00\" } }")
                              @RequestParam(value = "data", required = true) String data) {
        JSONObject param = new JSONObject(data);
        try {
            JSONObject response = thirdMessageService.pushMessage(type, param);
            return write(200, "推送成功!", "data", response);
        } catch (Exception ex) {
            ex.printStackTrace();
            return write(-1, "推送失败!");
        }
    }
    /**
     * 体检提醒模板消息推送接口(第三方没有openId)
     *
     * @param idCard 居民身份证号
     * @param medicalNo   体检号
     * @param medicalOrg   体检机构
     * @param medicalTime 体检时间
     * @return
     */
    @ApiOperation("体检提醒模板消息")
    @RequestMapping(value = "/physicalExamination", method = RequestMethod.POST)
    @ResponseBody
    public String physicalExamination(
            @ApiParam(name = "idCard", defaultValue = "360403195512282415")
            @RequestParam(value = "idCard", required = true) String idCard,
            @ApiParam(name = "medicalNo", defaultValue = "201712111825")
            @RequestParam(value = "medicalNo", required = true) String medicalNo,
            @ApiParam(name = "medicalOrg", defaultValue = "201712111825")
            @RequestParam(value = "medicalOrg", required = true) String medicalOrg,
            @ApiParam(name = "medicalTime", defaultValue = "2017-12-11 20:30")
            @RequestParam(value = "medicalTime", required = true) String medicalTime) {
        try {
            JSONObject response = thirdMessageService.physicalExamination(idCard, medicalNo, medicalOrg, medicalTime);
            return write(200, "推送成功!", "data", response);
        } catch (Exception ex) {
            ex.printStackTrace();
            return write(-1, "推送失败!");
        }
    }
}

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/template/ThirdTemplateController.java

@ -13,7 +13,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
/**
 * 第三方推往健康模板消息
 * 第三方推往健康模板消息(无token验证无身份登录验证)
 * Created by Reece on 2017/11/14.
 */
@Controller

+ 0 - 49
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/ylzpay/ThirdEHCController.java

@ -1,49 +0,0 @@
package com.yihu.wlyy.web.third.ylzpay;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.app.health.HealthEduArticleService;
import com.yihu.wlyy.service.third.ylz.ThirdEHCService;
import com.yihu.wlyy.web.BaseController;
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.web.bind.annotation.*;
/**
 * 提供给易联众电子健康卡功能
 * Created by Reece on 2017/12/7
 *
 */
@RestController
@RequestMapping("/wlyygc/ehc/")
@Api(description = "易联众电子健康卡")
public class ThirdEHCController extends BaseController {
	
	@Autowired
	private ThirdEHCService thirdEHCService;
	/**
	 *公众号消息推送接口
	 * @param data
	 * @return
	 */
	@ApiOperation("公众号推送接口")
	@RequestMapping(value = "/pushMessage",method = RequestMethod.POST)
	@ResponseBody
	public JSON pushMessage(@ApiParam(name="data",value="推送json串",defaultValue = "{\"message_type\":\"01\",\"message_content\":{\"content\":\"尊敬的用户,您已成功在中山医院注册居民电子健康卡,请点击领取使用。\"},\"id_type\":\"01\",\"id_no\":\"350322199008207716\",\"open_id\":\"14552525252\"}")
								@RequestParam(value="data",required = true) String data) {
		JSONObject response = new JSONObject();
		try {
			String res = thirdEHCService.pushMessage(JSON.parseObject(data));
			response.put("ret_code",res);
			response.put("ret_msg","操作成功");
		} catch (Exception ex) {
			error(ex);
			response.put("ret_code","0001");
			response.put("ret_msg","操作失败");
		}
		return response;
	}
}