trick9191 7 years ago
parent
commit
13a36782ac

+ 2 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientDao.java

@ -82,4 +82,6 @@ public interface PatientDao extends PagingAndSortingRepository<Patient, Long> {
    //根据code获取地址
    @Query("select p.address from Patient p where p.code = ?1")
    String getAddress(String patient);
    Patient findByUnionid(String unionid);
}

+ 7 - 7
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/specialist/SpecialistService.java

@ -93,7 +93,7 @@ public class SpecialistService extends BaseService {
    public Long getAssistantPatientCount(String doctor)throws Exception{
        Map<String,Object> param = new HashedMap();
        param.put("doctor",doctor);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"getAssistantPatientCount",param);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"svr-specialist/getAssistantPatientCount",param);
        JSONObject  rs = new JSONObject(response.getContent());
        if("succes".equals(rs.getString("message"))){
            return rs.getLong("obj");
@ -148,7 +148,7 @@ public class SpecialistService extends BaseService {
        param.put("doctor",doctor);
        param.put("labelType",labelType);
        param.put("labelCode",labelCode);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"getLabelpatientCount",param);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"svr-specialist/getLabelpatientCount",param);
        JSONObject  rs = new JSONObject(response.getContent());
        if("succes".equals(rs.getString("message"))){
            return rs.getLong("obj");
@ -160,7 +160,7 @@ public class SpecialistService extends BaseService {
    public Long findSpecialistPatientRelationCout(String doctor)throws Exception{
        Map<String,Object> param = new HashedMap();
        param.put("doctor",doctor);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"findSpecialistPatientRelationCout",param);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"svr-specialist/findSpecialistPatientRelationCout",param);
        JSONObject  rs = new JSONObject(response.getContent());
        if("succes".equals(rs.getString("message"))){
            return rs.getLong("obj");
@ -171,7 +171,7 @@ public class SpecialistService extends BaseService {
    public JSONArray findNoLabelPatientRelation(String doctor)throws Exception{
        Map<String,Object> param = new HashedMap();
        param.put("doctor",doctor);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"findNoLabelPatientRelation",param);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"svr-specialist/findNoLabelPatientRelation",param);
        JSONObject  rs = new JSONObject(response.getContent());
        if("succes".equals(rs.getString("message"))){
            return rs.getJSONArray("obj");
@ -184,7 +184,7 @@ public class SpecialistService extends BaseService {
        param.put("assistant",assistant);
        param.put("page",page);
        param.put("size",size);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"findPatientRelatioByAssistant",param);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"svr-specialist/findPatientRelatioByAssistant",param);
        JSONObject  rs = new JSONObject(response.getContent());
        if("succes".equals(rs.getString("message"))){
            return rs.getJSONArray("obj");
@ -196,7 +196,7 @@ public class SpecialistService extends BaseService {
    public Boolean saveHealthAssistant(String json)throws Exception{
        Map<String,Object> param = new HashedMap();
        param.put("json",json);
        HttpResponse response = HttpUtils.doPost(specialistUrl+"saveHealthAssistant",param);
        HttpResponse response = HttpUtils.doPost(specialistUrl+"svr-specialist/saveHealthAssistant",param);
        JSONObject  rs = new JSONObject(response.getContent());
        if("succes".equals(rs.getString("message"))){
            return rs.getBoolean("obj");
@ -211,7 +211,7 @@ public class SpecialistService extends BaseService {
        param.put("labelCode",labelCode);
        param.put("page",page);
        param.put("size",size);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"getPatientByLabel",param);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"svr-specialist/getPatientByLabel",param);
        JSONObject  rs = new JSONObject(response.getContent());
        if("succes".equals(rs.getString("message"))){
            return rs.getJSONArray("obj");

+ 92 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/applets/AppletsService.java

@ -1,15 +1,24 @@
package com.yihu.wlyy.service.weixin.applets;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientAimSports;
import com.yihu.wlyy.repository.patient.PatientAimSportsDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.SecretUtils;
import com.yihu.wlyy.util.http.HttpResponse;
import com.yihu.wlyy.util.http.HttpUtils;
import org.apache.commons.collections.map.HashedMap;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
@ -17,13 +26,18 @@ import java.util.Map;
 */
@Service
@Transactional
public class AppletsService {
public class AppletsService extends BaseService {
    @Value("${applets.appId}")
    private String appid;
    @Value("${applets.appSecret}")
    private String appSecret;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private PatientAimSportsDao patientAimSportsDao;
    public Map<String, Object> checkApplets(String code) throws Exception {
        HttpUtils httpUtils = new HttpUtils();
@ -54,4 +68,80 @@ public class AppletsService {
        return jsonObject;
    }
    public List<Map<String,Object>> getPatientRankLine(Integer size){
        String sql ="SELECT " +
                " @rownum:=@rownum+1 AS rank , " +
                " s.patientcode AS patient, " +
                " p.`name`, " +
                " p.photo, " +
                " s.daily_step_count AS stepCount " +
                " FROM " +
                " (SELECT@rowNum := 0) b, " +
                " wlyy_patient_aim_sports s " +
                "  JOIN wlyy_patient p ON s.patientcode = p.`code`  " +
                " WHERE " +
                " s.create_time > timestamp(date(sysdate())) " +
                " ORDER BY daily_step_count DESC  " +
                " LIMIT 0,"+size;
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    public Map<String,Object> getPatientRank(String patient){
        String sql = "SELECT " +
                " r.rank, " +
                " r.patientcode " +
                " FROM  " +
                " ( " +
                " SELECT " +
                " @rownum :=@rownum + 1 AS rank, " +
                " s.patientcode " +
                " FROM " +
                " wlyy_patient_aim_sports s, " +
                " (SELECT@rowNum := 0) b " +
                " WHERE " +
                " s.create_time > timestamp(date(sysdate())) " +
                " ORDER BY daily_step_count DESC " +
                " ) r  " +
                " WHERE r.patientcode = '"+patient+"'";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return list.get(0);
    }
    public Boolean setPatientStep(String patient,Integer step){
        String sql = "SELECT " +
                " s.id, " +
                " s.patientcode " +
                " FROM " +
                " wlyy_patient_aim_sports s " +
                " WHERE " +
                " s.create_time > timestamp(date(sysdate())) " +
                " AND s.patientcode='"+patient+"'";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        if(list!=null&&list.size()>0){
            Integer id = (Integer)list.get(0).get("id");
            PatientAimSports patientAimSports =  patientAimSportsDao.findOne(id.longValue());
            patientAimSports.setDailyStepCount(step);
            patientAimSportsDao.save(patientAimSports);
        }else{
            PatientAimSports patientAimSports = new PatientAimSports();
            patientAimSports.setCode(getCode());
            patientAimSports.setDailyStepCount(step);
            patientAimSports.setCreateTime(new Date());
            patientAimSports.setPatientcode(patient);
            patientAimSportsDao.save(patientAimSports);
        }
        return true;
    }
    public Map<String,Object> getPatientByUid(String unionid){
        Patient patient = patientDao.findByUnionid(unionid);
        Map<String,Object> map = new HashedMap();
        map.put("patient",patient.getCode());
        map.put("patientName",patient.getName());
        map.put("photo",patient.getPhoto());
        return map;
    }
}

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SecretUtils.java

@ -17,6 +17,7 @@ public class SecretUtils {
    public static String AES128CBCdecrypt(String encryptedData, String iv, String appId, String sessionKey) throws Exception {
        //System.out.println("encryptedData: "+encryptedData);
        // 被加密的数据
        byte[] dataByte = Base64.decodeBase64(encryptedData);
        // 加密秘钥

+ 47 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/AppletsController.java

@ -28,7 +28,7 @@ public class AppletsController extends WeixinBaseController {
    @RequestMapping(value = "/checkApplets", method = RequestMethod.GET)
    public String checkApplets(@ApiParam(name = "code", value = "小程序登录时获取的Code", required = true) @RequestParam(value = "code", required = true)String code){
        try {
            return write(200, "创建成功", "data", appletsService.checkApplets(code));
            return write(200, "请求成功", "data", appletsService.checkApplets(code));
        }catch (Exception e){
            error(e);
            return error(-1, "失败");
@ -39,10 +39,55 @@ public class AppletsController extends WeixinBaseController {
    @RequestMapping(value = "/getWeRunData", method = RequestMethod.GET)
    public String getWeRunData(String encryptedData,String iv,String sessionKey){
        try {
            return write(200, "创建成功", "data", appletsService.getWeRunData(encryptedData,iv,sessionKey));
            return write(200, "请求成功", "data", appletsService.getWeRunData(encryptedData,iv,sessionKey));
        }catch (Exception e){
            error(e);
            return error(-1, "失败");
        }
    }
    @ApiOperation(value = "获取排行版列表")
    @RequestMapping(value = "/getPatientRankLine", method = RequestMethod.GET)
    public String getPatientRankLine(@ApiParam(name = "size", value = "显示前几名排行", required = true) @RequestParam(value = "size", required = true)Integer size) {
        try {
            return write(200, "请求成功", "data", appletsService.getPatientRankLine(size));
        } catch (Exception e) {
            error(e);
            return error(-1, "失败");
        }
    }
    @ApiOperation(value = "获取居民排行")
    @RequestMapping(value = "/getPatientRank", method = RequestMethod.GET)
    public String getPatientRank(@ApiParam(name = "patient", value = "居民code", required = true) @RequestParam(value = "patient", required = true)String patient) {
        try {
            return write(200, "请求成功", "data", appletsService.getPatientRank(patient));
        } catch (Exception e) {
            error(e);
            return error(-1, "失败");
        }
    }
    @ApiOperation(value = "设置居民步数")
    @RequestMapping(value = "/setPatientStep", method = RequestMethod.POST)
    public String setPatientStep(@ApiParam(name = "patient", value = "居民code", required = true) @RequestParam(value = "patient", required = true)String patient,
                                 @ApiParam(name = "step", value = "步数", required = true) @RequestParam(value = "step", required = true)Integer step) {
        try {
            return write(200, "请求成功", "data", appletsService.setPatientStep(patient,step));
        } catch (Exception e) {
            error(e);
            return error(-1, "失败");
        }
    }
    @ApiOperation(value = "根据unionId获取居民信息")
    @RequestMapping(value = "/getPatientByUid", method = RequestMethod.POST)
    public String getPatientByUid(@ApiParam(name = "unionId", value = "开放平台唯一标识", required = true) @RequestParam(value = "unionId", required = true)String unionId) {
        try {
            return write(200, "请求成功", "data", appletsService.getPatientByUid(unionId));
        } catch (Exception e) {
            error(e);
            return error(-1, "失败");
        }
    }
}

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

@ -35,7 +35,7 @@ im:
#专病配置
specialist:
  url: http://localhost:10051/svr-specialist/
  url: http://localhost:10051/
#物联网配置
iot:
  url: http://192.168.131.24:8088/svr-iot/

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

@ -35,7 +35,7 @@ im:
#专病配置
specialist:
  url: http://localhost:10051/svr-specialist/
  url: http://localhost:10051/
#物联网配置
iot:
#  url: http://192.168.131.24:8088/svr-iot/

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

@ -34,7 +34,7 @@ im:
#专病配置
specialist:
  url: http://localhost:10051/svr-wlyy-specialist/
  url: http://127.0.0.1:10051/svr-wlyy-specialist/
#物联网配置
iot:
  url: http://192.168.131.24:8088/svr-iot/

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

@ -30,7 +30,7 @@ im:
#专病配置基础服务地址
specialist:
  url: http://172.19.103.33:10051/svr-specialist/
  url: http://172.19.103.33:9797/svr-wlyy-specialist/
#物联网配置
iot:
  url: http://172.19.103.33:8088/svr-iot/