浏览代码

[cmd]健康银行接口

wangzhinan 7 年之前
父节点
当前提交
6bb23597d0

+ 6 - 11
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/BaseService.java

@ -1,21 +1,16 @@
package com.yihu.wlyy.service;
import java.security.KeyPair;
import java.util.Iterator;
import java.util.UUID;
import com.yihu.wlyy.entity.security.AccessToken;
import com.yihu.wlyy.service.common.account.AccessTokenService;
import com.yihu.wlyy.util.HttpUtil;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import com.yihu.wlyy.entity.security.RSA;
import com.yihu.wlyy.repository.security.RSADao;
import com.yihu.wlyy.service.common.account.AccessTokenService;
import com.yihu.wlyy.util.CommonUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.security.KeyPair;
import java.util.Iterator;
import java.util.UUID;
@Service
public class BaseService {

+ 543 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/CreditLogService.java

@ -0,0 +1,543 @@
package com.yihu.wlyy.service.app.health.bank;/**
 * Created by nature of king on 2018/5/7.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.util.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author wangzhinan
 * @create 2018-05-07 9:24
 * @desc wlyy health bank service
 **/
@Service
@Transactional
public class CreditLogService {
    private Logger logger = LoggerFactory.getLogger(CreditLogService.class);
    private static String URL = "health:blank:url";
    //    private String baseUrl = "http://192.168.131.24:8088/svr-iot/";
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PatientDeviceService patientDeviceService;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private SystemDictDao systemDictDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    /**
     * 获取url
     *
     * @return
     */
    public  String getBaseUrl(){
        String url = redisTemplate.opsForValue().get(URL);
        String url1 = systemDictDao.findByDictNameAndCode("HEALTH_BANK_URL","HEALTH_BANK_URL");
        if (url != null && url1.equalsIgnoreCase(url)){
            return url;
        }else {
            redisTemplate.opsForValue().set(URL,url1);
            return url1;
        }
    }
    /**
     * 调用第三方积分排名接口
     *
     * @param doctorId
     * @param page
     * @param name
     * @param size
     * @return
     */
    public JSONObject selectByRanking(String doctorId,String name, Integer page, Integer size){
        String sql = null;
        if (name == null || name == ""){
            sql  = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"')";
        } else if (name != null) {
            sql  = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"') AND name = '"+name+"'";
        }
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientIds.add(signFamily.getPatient());
            }
        }
        JSONObject object = new JSONObject();
        object.put("filter",patientIds.toArray());
        object.put("page",page);
        object.put("size",size);
        String url = getBaseUrl() + "selectByRanking";
        String response = null;
        JSONArray data =null;
        JSONObject object1 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object.toString());
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            for (int i = 0;i<array.size();i++){
                JSONObject object2 = array.getJSONObject(i);
                String patientId = object2.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object2.put("patient",patient);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 调用添加积分接口
     *
     * @param object
     * @return
     */
    public JSONObject insert(JSONObject object) throws Exception {
        String response = null;
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        object.put("idCard",patient.getIdcard());
        object.put("openId",patient.getOpenid());
        String url =getBaseUrl() + "createCreditsDetail";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 按条件查询积分
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByCondition(JSONObject object,Integer page,Integer size){
        String response = null;
        String url =getBaseUrl() + "findCreditsLogInfo";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询账户积分详情
     *
     * @param object
     * @return
     */
    public JSONObject selectAccount(JSONObject object) throws Exception {
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        String response = null;
        String url =getBaseUrl() + "selectAccount";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询任务完成情况
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByTask(JSONObject object,Integer page,Integer size){
        JSONObject object1 = new JSONObject();
        String response = null;
        String url =getBaseUrl() + "findTask";
        Map<String,String> params = new HashMap<>();
        params.put("task",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        String patientId = object.getString("patientId");
        try {
            response = httpClientUtil.httpPost(url,params);
            Map<String,Object> taskInfo = patientDeviceService.getPatientDeviceTaskInfo(patientId);
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            JSONArray array1 = new JSONArray();
            for (int i =0 ;i<array.size();i++){
                JSONObject jsonObject = array.getJSONObject(i);
                String taskCode = jsonObject.getString("taskCode");
                if (taskCode.equalsIgnoreCase("BIND")){
                    jsonObject.put("deviceCount",taskInfo.get("deviceCount"));
                }else if (taskCode.equalsIgnoreCase("MEASURE")){
                    jsonObject.put("resultHealty",taskInfo.get("resultHealty"));
                }
                array1.add(jsonObject);
            }
            object1.put("detailModelList",array1);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 查询银行账户信息
     *
     * @param object 账户对象
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    public JSONObject selectByAccount(JSONObject object,Integer page,Integer size){
        String signSql = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND patient = '"+object.getString("patientId") +"'";
        List<SignFamily> signFamilyList1 = jdbcTemplate.query(signSql,new BeanPropertyRowMapper(SignFamily.class));
        String sql = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +signFamilyList1.get(0).getDoctor() + "' OR doctor_health = '" + signFamilyList1.get(0).getDoctor() +"')";
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientIds.add(signFamily.getPatient());
            }
        }
        String response = null;
        String url =getBaseUrl() + "findAccount";
        object.put("patientIds",patientIds.toArray());
        Map<String,String> params = new HashMap<>();
        params.put("account",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        JSONObject object1 = null;
        try {
            response = httpClientUtil.httpPost(url,params);
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            for (int i = 0;i<array.size();i++){
                JSONObject object2 = array.getJSONObject(i);
                String patientId = object2.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object2.put("patient",patient);
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 获取活动所有排名
     *
     * @param activityId 活动对象
     * @param page 页码
     * @param size
     * @return
     */
    public JSONObject selectByActivityRanking1(String activityId,Integer page,Integer size){
        String response = null;
        String url =getBaseUrl() + "selectByActivityRanking1";
        Map<String,String> params = new HashMap<>();
        params.put("activityId",activityId);
        params.put("page",page.toString());
        params.put("size",size.toString());
        JSONObject object1 = null;
        try {
            response = httpClientUtil.httpPost(url,params);
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            for (int i = 0;i<array.size();i++){
                JSONObject object2 = array.getJSONObject(i);
                String patientId = object2.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object2.put("patient",patient);
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 查询参与活动
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByPatient(JSONObject object,Integer page,Integer size){
        Patient patient = new Patient();
        if (object.getString("openId") != null){
            patient = patientDao.findByOpenid(object.getString("openId"));
        }else if (object.getString("patientId") != null){
            patient = patientDao.findByCode(object.getString("patientId"));
        }
        object.put("openId",patient.getOpenid());
        object.put("unionId",patient.getUnionid());
        object.put("patientIdcard",patient.getIdcard());
        String response = null;
        String url =getBaseUrl() + "selectByPatient";
        Map<String,String> params = new HashMap<>();
        params.put("activity",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 根据活动查找积分
     *
     * @param patientId 居民id
     *
     * @param activityId 活动id
     * @param page 页码
     *
     * @param size  分页大小
     * @return
     */
    public JSONObject selectByActivity(String patientId,String activityId,Integer page,Integer size){
        String response = null;
        String url =getBaseUrl() + "selectByActivity";
        Map<String,String> params = new HashMap<>();
        params.put("patientId",patientId);
        params.put("activityId",activityId);
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 按照活动排名
     *
     * @param activityId 活动id
     * @param doctorId 医生id
     * @param name 居民名称
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    public JSONObject selectByActivityRanking(String activityId,String doctorId,String name, Integer page, Integer size){
        String sql = null;
        if (name == null || name ==""){
            sql  = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"')";
        } else if (name != null) {
            sql  = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"') AND name = '"+name+"'";
        }
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientOpenIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientOpenIds.add(signFamily.getOpenid());
            }
        }
        JSONObject object = new JSONObject();
        object.put("filter",patientOpenIds.toArray());
        object.put("activityId",activityId);
        object.put("page",page);
        object.put("size",size);
        String url = getBaseUrl() + "selectByActivityRanking";
        String response = null;
        JSONArray data =null;
        JSONObject object1 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object.toString());
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            for (int i = 0;i<array.size();i++){
                JSONObject object2 = array.getJSONObject(i);
                String patientId = object2.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object2.put("patient",patient);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 根据条件获取信息
     *
     * @param object 对象
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    public JSONObject selectAccountByCondition(JSONObject object,Integer page,Integer size){
        String doctorId = object.getString("doctorId");
        String sql = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"')";
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientIds.add(signFamily.getPatient());
            }
        }
        JSONObject object1 = new JSONObject();
        JSONArray array = object.getJSONArray("deviceTypes");
        object1.put("patientIds",patientIds.toArray());
        object1.put("bindStatus",object.getInteger("bindStatus"));
        object1.put("deviceTypes",array);
        object1.put("page",page);
        object1.put("size",size);
        String response = null;
        String url =getBaseUrl() + "findAccounByCondition";
        JSONObject object2 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object1.toString());
            object2 = JSONObject.parseObject(response);
            JSONArray array1 = object2.getJSONArray("detailModelList");
            for (int i = 0;i<array1.size();i++){
                JSONObject object3 = array1.getJSONObject(i);
                String patientId = object3.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object3.put("patient",patient);
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object2;
    }
    /**
     * 医生添加积分
     *
     * @param object {patientIds:[],ruleId:"",description:""}
     * @return
     */
    public JSONObject doctorAddIntegrate(JSONObject object){
        String response = null;
        String url =getBaseUrl() + "doctorAddIntegrate";
        JSONArray array = object.getJSONArray("patientIds");
        JSONObject object1 = new JSONObject();
        object1.put("patientIds",array);
        object1.put("ruleId",object.getString("ruleId"));
        object1.put("description",object.getString("description"));
        JSONObject object2 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object1.toString());
            object2 = JSONObject.parseObject(response);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object2;
    }
    /**
     * 步数获取积分
     *
     * @param object
     * @return
     * @throws Exception
     */
    public JSONObject stepAddIntegrate(JSONObject object) throws Exception {
        String response = null;
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        object.put("idCard",patient.getIdcard());
        object.put("openId",patient.getOpenid());
        object.put("unionId",patient.getUnionid());
        String url =getBaseUrl() + "addStepIntegrate";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
}

+ 78 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/TaskRuleService.java

@ -0,0 +1,78 @@
package com.yihu.wlyy.service.app.health.bank;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.util.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by wangzhinan on 2018/6/14.
 */
@Service
@Transactional
public class TaskRuleService {
    private Logger logger = LoggerFactory.getLogger(TaskRuleService.class);
    private static String URL = "health:blank:url";
    @Autowired
    private SystemDictDao systemDictDao;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 获取url
     *
     * @return
     */
    public  String getBaseUrl(){
        String url = redisTemplate.opsForValue().get(URL);
        String url1 = systemDictDao.findByDictNameAndCode("HEALTH_BANK_URL","HEALTH_BANK_URL");
        if (url != null && url1.equalsIgnoreCase(url)){
            return url;
        }else {
            redisTemplate.opsForValue().set(URL,url1);
            return url1;
        }
    }
    /**
     * 查找规则
     *
     * @param object 规则对象
     *
     * @param page 页码
     *
     * @param size 分页大小
     *
     * @return
     */
    public JSONObject selectTaskRule(JSONObject object, Integer page, Integer size){
        String response = null;
        String url =getBaseUrl() + "findTaskRule";
        Map<String,String> params = new HashMap<>();
        params.put("taskRule",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
}

+ 167 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/TaskService.java

@ -0,0 +1,167 @@
package com.yihu.wlyy.service.app.health.bank;/**
 * Created by nature of king on 2018/6/11.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.util.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author wangzhinan
 * @create 2018-06-11 8:54
 * @desc 健康银行活动
 **/
@Service
@Transactional
public class TaskService {
    private Logger logger = LoggerFactory.getLogger(TaskService.class);
    private static String URL = "health:blank:url";
    @Autowired
    private SystemDictDao systemDictDao;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PatientDao patientDao;
    /**
     * 获取url
     *
     * @return
     */
    public  String getBaseUrl(){
        String url = redisTemplate.opsForValue().get(URL);
        String url1 = systemDictDao.findByDictNameAndCode("HEALTH_BANK_URL","HEALTH_BANK_URL");
        if (url != null && url1.equalsIgnoreCase(url)){
            return url;
        }else {
            redisTemplate.opsForValue().set(URL,url1);
            return url1;
        }
    }
    /**
     * 查看活动列表
     *
     * @param object
     * @return
     */
    public JSONObject selectActivity(JSONObject object,Integer page,Integer size){
        String response = null;
        String url =getBaseUrl() + "findActivity";
        Map<String,String> params = new HashMap<>();
        params.put("activity",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询任务获取积分
     *
     * @param taskCodeIds taskCode集合
     * @param patientId 居民id
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    public JSONObject selectTask(JSONArray taskCodeIds,String patientId, Integer page, Integer size){
        String response = null;
        String url =getBaseUrl() + "selectByCode";
        JSONObject object = new JSONObject();
        object.put("taskCode",taskCodeIds.toJSONString());
        object.put("patientId",patientId);
        object.put("page",page.toString());
        object.put("size",size.toString());
        try {
            response = httpClientUtil.iotPostBody(url,object.toString());
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 参加任务
     *
     * @param object 参加任务JSON
     * @return
     */
    public JSONObject attendTask(JSONObject object){
        String response = null;
        Patient patient = patientDao.findByCode(object.getString("patientId"));
        String unionId = "1";
        patient.setUnionid(unionId);
        patientDao.save(patient);
        object.put("unionId",unionId);
        object.put("patientIdcard",patient.getIdcard());
        String url =getBaseUrl() + "attendTask";
        Map<String,String> params = new HashMap<>();
        params.put("taskPatientDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 根据openId获取用户数据
     *
     * @param openId 微信id
     *
     * @param page 页码
     *
     * @param size 分页大小
     *
     * @return
     */
    public JSONObject selectByOpenId(String openId, Integer page,Integer size){
        String sql = "select * from wlyy_patient where openid = '"+ openId +"' LIMIT "+(page-1)*size+","+size;
        List<Patient> patientList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(Patient.class));
        String sqlcount = "select * from wlyy_patient where openid = '"+ openId +"'";
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        JSONObject object = new JSONObject();
        object.put("patientList",patientList);
        object.put("total",count);
        object.put("page",page);
        object.put("size",size);
        return object;
    }
}

+ 0 - 330
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/health/bank/CreditLogService.java

@ -1,330 +0,0 @@
package com.yihu.wlyy.service.third.health.bank;/**
 * Created by nature of king on 2018/5/7.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
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.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author wangzhinan
 * @create 2018-05-07 9:24
 * @desc wlyy health bank service
 **/
@Service
@Transactional
public class CreditLogService {
    private Logger logger = LoggerFactory.getLogger(CreditLogService.class);
    @Value("${healthBank.url}")
    private String baseUrl;
    //    private String baseUrl = "http://192.168.131.24:8088/svr-iot/";
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PatientDeviceService patientDeviceService;
    
    @Autowired
    private PatientService patientService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Autowired
    private PatientDao patientDao;
    /**
     * 调用第三方积分排名接口
     *
     * @param doctorId
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByRanking(String doctorId, Integer page, Integer size){
        String sql = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"')";
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientIds.add(signFamily.getPatient());
            }
        }
        JSONObject object = new JSONObject();
        object.put("filter",patientIds.toArray());
        object.put("page",page);
        object.put("size",size);
        String url = baseUrl + "selectByRanking";
        String response = null;
        JSONArray data =null;
        JSONObject object1 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object.toString());
            object1 = JSONObject.parseObject(response);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 调用添加积分接口
     *
     * @param object
     * @return
     */
    public JSONObject insert(JSONObject object) throws Exception {
    
        JSONObject result = new JSONObject();
        
        init();
        String response = null;
        String integrate = getIntegrate("health:blank:integrate:"+object.getString("flag"));
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        object.put("integrate",integrate);
        String url =baseUrl + "createCreditsDetail";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
    
        result = JSONObject.parseObject(response);
    
    
        String status = result.getString("status");
    
        logger.info("健康银行居民新增积分:"+result.toString());
        if ("200".equals(status)){
            List<Map<String,Object>> list = (List<Map<String,Object>>)result.get("detailModelList");
            if (list!=null && list.size()>0){
                //积分
                String integrateresult = String.valueOf(list.get(0).get("integrate"));
                String patientid = String.valueOf(list.get(0).get("patientId"));
                String total = String.valueOf(list.get(0).get("total"));
            
            
                try {
                    //@TODO 获取积分调用发送微信模板接口
                    Patient people = patientDao.findByCode(patientid);
                    String openId = people.getOpenid();
                    String name = people.getName();
                
                    org.json.JSONObject sendJson = new org.json.JSONObject();
                    String first = "";
                    String remark = "";
                    String urlresult = "";
                
                    WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_healthbank_credit","jfdztz");
                    first = templateConfig.getFirst();
                    remark = templateConfig.getRemark();
//                    String keyword1 = templateConfig.getKeyword1();
                
                    sendJson.put("keyword1", integrateresult);
                    sendJson.put("keyword2", DateUtil.getStringDate());
                    sendJson.put("keyword3", total);
                    sendJson.put("first", first);
                    sendJson.put("remark", remark);
                    urlresult = templateConfig.getUrl();
                    urlresult = urlresult.replace("key1",(integrate==null?"":integrate));
                    sendJson.put("url", urlresult);//带参数的模板跳转链接
                    System.out.println(sendJson.toString());
                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 23, openId, name, sendJson);
//	                    //发送代理人
//	                    jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);
//	                    if (jsonArray != null && jsonArray.length() > 0) {
//		                    for (int i = 0; i < jsonArray.length(); i++) {
//			                    org.json.JSONObject j = jsonArray.getJSONObject(i);
//			                    Patient member = (Patient) j.get("member");
//			                    int start = url.indexOf("&toUser=");
//			                    int end = url.indexOf("&", start + 1);
//			                    String touser = url.substring(start, end);
//			                    url = url.replace(touser, "&toUser=" + member.getCode());
//			                    //name患者姓名
//			                    sendJson.put("first", weiXinOpenIdUtils.getTitleMes(people, (int) j.get("relation"), name) + first);
//			                    sendJson.put("url", url);
//			                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 19, member.getOpenid(), name, sendJson);
//		                    }
//	                    }
                }catch (Exception e){
                    logger.info("健康银行居民新增积分,微信模板消息发送失败:"+e.getMessage());
//	                        e.printStackTrace();
                }
            
            }
        }
        return result;
    }
    /**
     * 按条件查询积分
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByCondition(JSONObject object,Integer page,Integer size){
        String response = null;
        String url =baseUrl + "findCreditsLogInfo";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询账户积分详情
     *
     * @param object
     * @return
     */
    public JSONObject selectAccount(JSONObject object) throws Exception {
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        String response = null;
        String url =baseUrl + "selectAccount";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询任务完成情况
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByTask(JSONObject object,Integer page,Integer size){
        JSONObject object1 = new JSONObject();
        String response = null;
        String url =baseUrl + "findTask";
        Map<String,String> params = new HashMap<>();
        params.put("task",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        String patientId = object.getString("patientId");
        try {
            response = httpClientUtil.httpPost(url,params);
            Map<String,Object> taskInfo = patientDeviceService.getPatientDeviceTaskInfo(patientId);
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            JSONArray array1 = new JSONArray();
            for (int i =0 ;i<array.size();i++){
                JSONObject jsonObject = array.getJSONObject(i);
                String taskCode = jsonObject.getString("taskCode");
                if (taskCode.equalsIgnoreCase("BIND")){
                    jsonObject.put("deviceCount",taskInfo.get("deviceCount"));
                }else if (taskCode.equalsIgnoreCase("MEASURE")){
                    jsonObject.put("resultHealty",taskInfo.get("resultHealty"));
                }
                array1.add(jsonObject);
            }
            object1.put("detailModelList",array1);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 查询银行账户信息
     *
     * @param object 账户对象
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    public JSONObject selectByAccount(JSONObject object,Integer page,Integer size){
        String response = null;
        String url =baseUrl + "findAccount";
        Map<String,String> params = new HashMap<>();
        params.put("account",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    public void init(){
        redisTemplate.opsForValue().set("health:blank:integrate:BIND","1");
        redisTemplate.opsForValue().set("health:blank:integrate:MEASURE","1");
    }
    public String getIntegrate(String key){
        return redisTemplate.opsForValue().get(key);
    }
}

+ 5 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java

@ -3,7 +3,6 @@ package com.yihu.wlyy.web.doctor.device;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.device.DeviceWxMessage;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.device.vo.DeviceWxMessageDTO;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
@ -16,10 +15,9 @@ import com.yihu.wlyy.service.app.device.DeviceDetailService;
import com.yihu.wlyy.service.app.device.DeviceWxMessageService;
import com.yihu.wlyy.service.app.device.PatientDeviceLogService;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.CommonUtil;
import com.yihu.wlyy.util.DateUtil;
@ -35,11 +33,13 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
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 javax.jms.JMSException;
import javax.jms.Message;

+ 272 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/bank/ActivityController.java

@ -0,0 +1,272 @@
package com.yihu.wlyy.web.doctor.health.bank;/**
 * Created by nature of king on 2018/6/13.
 */
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.service.app.health.bank.TaskRuleService;
import com.yihu.wlyy.service.app.health.bank.TaskService;
import com.yihu.wlyy.web.BaseController;
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.http.MediaType;
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;
/**
 * @authorwangzhinan
 * @create 2018-06-13 15:04
 * @desc 活动广场
 **/
@RestController
@RequestMapping(value = "/doctor/healthBank", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-健康广场")
public class ActivityController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(ActivityController.class);
    @Autowired
    private CreditLogService service;
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskRuleService taskRuleService;
    /**
     * 查询活动排名
     * @param doctorId 医生id
     *
     * @param activityId 活动id
     * @param page 页码
     *
     * @param size 分页大小
     * @return
     */
    @RequestMapping(value = "/findActivityRanking",method = RequestMethod.POST)
    @ApiOperation("查询活动排名")
    public String getById(@ApiParam(name = "doctorId",value = "医生Id")
                          @RequestParam(name = "doctorId")String doctorId,
                          @ApiParam(name = "activityId",value = "活动id")
                          @RequestParam(name = "activityId") String activityId,
                          @ApiParam(name = "name",value = "居民名称")
                          @RequestParam(name = "name",required = false)String name,
                          @ApiParam(name = "page", value = "第几页,从1开始")
                          @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                          @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                          @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByActivityRanking(activityId,doctorId,name,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 查询积分排名
     *
     * @param doctorId
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/findCreditRanking",method = RequestMethod.POST)
    @ApiOperation("查询积分排名")
    public String getById(@ApiParam(name = "doctorId",value = "医生Id")
                          @RequestParam(name = "doctorId")String doctorId,
                          @ApiParam(name = "name",value = "居民名称")
                          @RequestParam(name = "name",required = false)String name,
                          @ApiParam(name = "page", value = "第几页,从1开始")
                          @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                          @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                          @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByRanking(doctorId,name,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 活动广场
     *
     * @param task
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/selectTask",method = RequestMethod.POST)
    @ApiOperation("活动列表")
    public String selectByCondition(@ApiParam(name = "task",value = "任务JSON")
                                    @RequestParam(name = "task") String task,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(task);
            object.put("openId",getOpenid());
            return write(200,"查询成功","data",taskService.selectActivity(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 查看任务规则
     *
     * @param taskRule 任务规则对象
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    @RequestMapping(value = "/selectTaskRule",method = RequestMethod.POST)
    @ApiOperation("查看任务规则")
    public String selectByTaskRule(@ApiParam(name = "taskRule",value = "规则JSON")
                                    @RequestParam(name = "taskRule") String taskRule,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(taskRule);
            return write(200,"查询成功","data",taskRuleService.selectTaskRule(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 根据条件查找用户信息
     *
     * @param condition {"doctorId":,"bindStatus":"","deviceTypes":[]}
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/selectAccountByCondition",method = RequestMethod.POST)
    @ApiOperation("根据条件查找用户信息")
    public String selectAccountByCondition(@ApiParam(name = "condition",value = "条件JSON")
                                   @RequestParam(name = "condition") String condition,
                                   @ApiParam(name = "page", value = "第几页,从1开始")
                                   @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                   @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                   @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(condition);
            return write(200,"查询成功","data",service.selectAccountByCondition(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 医生添加积分
     *
     * @param object {"patientIds":["915cc456-5b1d-11e6-8344-fa163e8aee56"],"ruleId":"4028037363fc550f0163fc633a1a0007","description":"321321"}
     * @return
     */
    @RequestMapping(value = "/doctorAddInteger",method = RequestMethod.POST)
    @ApiOperation("医生添加积分")
    public String doctorAddInteger(@ApiParam(name = "object",value = "object")
                                   @RequestParam(name = "object") String object){
        try {
            JSONObject object1 = JSONObject.parseObject(object);
            return write(200,"查询成功","data",service.doctorAddIntegrate(object1));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * find credits log details
     *
     * @param creditsLogDo
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/selectDetails",method = RequestMethod.POST)
    @ApiOperation("积分详情")
    public String selectByCondition1(@ApiParam(name = "creditsLogDo",value = "积分JSON")
                                    @RequestParam(name = "creditsLogDo") String creditsLogDo,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(creditsLogDo);
            return write(200,"查询成功","data",service.selectByCondition(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     *  根据条件查看银行账户信息
     *
     * @param account 银行账户
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    @RequestMapping(value = "/findAccount",method = RequestMethod.POST)
    @ApiOperation("银行账户信息")
    public String selectByAccount(@ApiParam(name = "account",value = "任务JSON")
                                  @RequestParam(name = "account") String account,
                                  @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(account);
            return write(200,"查询成功","data",service.selectByAccount(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 医生端查询居民参与活动
     *
     * @param patientId 居民id
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    @RequestMapping(value = "/selectByPatient",method = RequestMethod.POST)
    @ApiOperation("参与活动列表")
    public String selectByPatient(@ApiParam(name = "patientId",value = "居民id")
                                      @RequestParam(value = "patientId") String patientId,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = new JSONObject();
            object.put("patientId",patientId);
            return write(200,"查询成功","data",service.selectByPatient(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}

+ 2 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java

@ -1,7 +1,6 @@
package com.yihu.wlyy.web.patient.device;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.device.DeviceDetail;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.device.PatientHealthTime;
import com.yihu.wlyy.entity.message.Message;
@ -13,12 +12,12 @@ import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.device.DeviceDetailService;
import com.yihu.wlyy.service.app.device.PatientDeviceLogService;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.app.device.DeviceDetailService;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.BaseController;

+ 108 - 45
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/health/bank/CreditsLogController.java

@ -1,20 +1,11 @@
/**
 * Created by nature of king on 2018/5/7.
 */
package com.yihu.wlyy.web.third.health.bank;
import com.alibaba.fastjson.JSONArray;
package com.yihu.wlyy.web.patient.health.bank;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.doctor.device.DoctorDeviceController;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -22,10 +13,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
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 wangzhinan
@ -33,7 +24,7 @@ import java.util.Map;
 * @desc credit log controller
 **/
@RestController
@RequestMapping(value = "/healthBank",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = "/patient/healthBank",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "积分处理机制")
public class CreditsLogController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(CreditsLogController.class);
@ -50,7 +41,7 @@ public class CreditsLogController extends BaseController {
     * @param size
     * @return
     */
    @RequestMapping(value = "/findCreditRanking",method = RequestMethod.POST)
    /*@RequestMapping(value = "/findCreditRanking",method = RequestMethod.POST)
    @ApiOperation("查询积分排名")
    public String getById(@ApiParam(name = "doctorId",value = "医生Id")
                              @RequestParam(name = "doctorId")String doctorId,
@ -64,7 +55,7 @@ public class CreditsLogController extends BaseController {
            error(e);
            return error(-1,e.getMessage());
        }
    }
    }*/
    /**
@ -75,7 +66,7 @@ public class CreditsLogController extends BaseController {
     */
    @RequestMapping(value = "/insertCredits",method = RequestMethod.POST)
    @ApiOperation("添加积分")
    public String insert(@ApiParam(name = "creditsDetail",value = "居民id集合")
    public String insert(@ApiParam(name = "creditsDetail",value = "居民对象JSON")
                          @RequestParam(name = "creditsDetail") String creditsDetail){
        try {
            JSONObject object = JSONObject.parseObject(creditsDetail);
@ -87,6 +78,8 @@ public class CreditsLogController extends BaseController {
        }
    }
    /**
     * find credits log details
     *
@ -132,54 +125,124 @@ public class CreditsLogController extends BaseController {
    }
    /**
     * 查询任务完成情况
     *  根据条件查看银行账户信息
     *
     * @param task
     * @param page
     * @param size
     * @param account 银行账户
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    @RequestMapping(value = "/selectTasks",method = RequestMethod.POST)
    @ApiOperation("任务完成情况")
    public String selectByTask(@ApiParam(name = "task",value = "任务JSON")
                                    @RequestParam(name = "task") String task,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
    @RequestMapping(value = "/findAccount",method = RequestMethod.POST)
    @ApiOperation("银行账户信息")
    public String selectByAccount(@ApiParam(name = "account",value = "任务JSON")
                               @RequestParam(name = "account") String account,
                               @ApiParam(name = "page", value = "第几页,从1开始")
                               @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                               @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                               @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(account);
            return write(200,"查询成功","data",service.selectByAccount(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "/selectByActivityRanking1",method = RequestMethod.POST)
    @ApiOperation("获取活动所有排名")
    public String selectByActivityRanking1(@ApiParam(name = "activityId",value = "活动id")
                                  @RequestParam(name = "activityId") String activityId,
                                  @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByActivityRanking1(activityId,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     *  参与活动列表
     *
     * @param page 页码
     *
     * @param size 分页大小
     *
     * @return
     */
    @RequestMapping(value = "/selectByPatient",method = RequestMethod.POST)
    @ApiOperation("参与活动列表")
    public String selectByPatient(@ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(task);
            return write(200,"查询成功","data",service.selectByTask(object,page,size));
            JSONObject object = new JSONObject();
            object.put("openId",getOpenid());
            return write(200,"查询成功","data",service.selectByPatient(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     *  根据条件查看银行账户信息
     * 根据活动查积分
     *
     * @param activityId 活动id
     *
     * @param patientId 居民id
     *
     * @param account 银行账户
     * @param page 页码
     * @param size 每页大小
     *
     * @param size 分页大小
     *
     * @return
     */
    @RequestMapping(value = "/findAccount",method = RequestMethod.POST)
    @ApiOperation("银行账户信息")
    public String selectByAccount(@ApiParam(name = "account",value = "任务JSON")
                               @RequestParam(name = "account") String account,
                               @ApiParam(name = "page", value = "第几页,从1开始")
                               @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                               @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                               @RequestParam(value = "size", required = false)Integer size){
    @RequestMapping(value = "/selectByActivity",method = RequestMethod.POST)
    @ApiOperation("根据活动查积分")
    public String selectByActivity(@ApiParam(name = "activityId",value = "活动id")
                                  @RequestParam(name = "activityId") String activityId,
                                   @ApiParam(name = "patientId",value = "居民id")
                                   @RequestParam(name = "patientId") String patientId,
                                  @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByActivity(patientId,activityId,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
            JSONObject object = JSONObject.parseObject(account);
            return write(200,"查询成功","data",service.selectByAccount(object,page,size));
    /**
     * 步数获取积分
     *
     * @param creditsDetail {"patientId":"","transactionId":"","stepNumber":""}
     * @return
     */
    @RequestMapping(value = "/stepAddIntegrate",method = RequestMethod.POST)
    @ApiOperation("步数获取积分")
    public String stepAddIntegrate(@ApiParam(name = "creditsDetail",value = "对象JSON")
                         @RequestParam(name = "creditsDetail") String creditsDetail){
        try {
            JSONObject object = JSONObject.parseObject(creditsDetail);
            JSONObject result = service.insert(object);
            return write(200,"获取成功","data",result);
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}

+ 131 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/bank/TaskController.java

@ -0,0 +1,131 @@
package com.yihu.wlyy.web.patient.health.bank;/**
 * Created by nature of king on 2018/6/11.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.app.health.bank.TaskService;
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.http.MediaType;
import org.springframework.web.bind.annotation.*;
/**
 * @author wangzhinan
 * @create 2018-06-11 10:49
 * @desc 健康任务
 **/
@RestController
@RequestMapping(value = "/patient/healthBank",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "健康活动")
public class TaskController extends BaseController{
    @Autowired
    private TaskService service;
    /**
     * 活动广场
     *
     * @param task
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/selectTask",method = RequestMethod.POST)
    @ApiOperation("活动列表")
    public String selectByCondition(@ApiParam(name = "task",value = "任务JSON")
                                    @RequestParam(name = "task") String task,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(task);
            object.put("openId",getOpenid());
            return write(200,"查询成功","data",service.selectActivity(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 查看任务列表
     *
     * @param task (taskCode:[],patientId:")
     *
     * @param page 页码
     *
     * @param size 分页大小
     *
     * @return
     */
    @RequestMapping(value = "/selectTasks",method = RequestMethod.POST)
    @ApiOperation("任务列表")
    public String selectByTask(@ApiParam(name = "task", value = "任务JSON")
                                    @RequestParam(name ="task" )String task,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(task);
            JSONArray array = object.getJSONArray("taskCode");
            String patientId = object.getString("patientId");
            return write(200,"查询成功","data",service.selectTask(array,patientId,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 参加任务
     *
     * @param taskPatientDetail
     * @return
     */
    @RequestMapping(value = "/attendTask",method = RequestMethod.POST)
    @ApiOperation("参加任务")
    public String attendTask(@ApiParam(name = "taskPatientDetail",value = "参与活动JSON")
                             @RequestParam(name = "taskPatientDetail")String taskPatientDetail){
        try {
            JSONObject object = JSONObject.parseObject(taskPatientDetail);
            object.put("patientOpenid",getOpenid());
            return write(200,"报名成功","data",service.attendTask(object));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 获取用户信息
     *
     * @param page 页码
     *
     * @param size  分页大小
     *
     * @return
     */
    @RequestMapping(value = "/selectByOpenId",method = RequestMethod.POST)
    @ApiOperation("获取用户信息")
    public String selectByOpenId( @ApiParam(name = "page", value = "第几页,从1开始")
                                      @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                      @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"添加成功","data",service.selectByOpenId(getOpenid(),page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}

+ 83 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/health/bank/AccountController.java

@ -0,0 +1,83 @@
/**
 * Created by nature of king on 2018/5/7.
 */
package com.yihu.wlyy.web.third.health.bank;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.web.BaseController;
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.http.MediaType;
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 wangzhinan
 * @create 2018-05-07 8:50
 * @desc credit log controller
 **/
@RestController
@RequestMapping(value = "/healthBank",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "小程序")
public class AccountController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(AccountController.class);
    @Autowired
    private CreditLogService service;
    /**
     *  根据条件查看银行账户信息
     *
     * @param account 银行账户
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    @RequestMapping(value = "/findAccount",method = RequestMethod.POST)
    @ApiOperation("银行账户信息")
    public String selectByAccount(@ApiParam(name = "account",value = "任务JSON")
                               @RequestParam(name = "account") String account,
                               @ApiParam(name = "page", value = "第几页,从1开始")
                               @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                               @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                               @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(account);
            return write(200,"查询成功","data",service.selectByAccount(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "/selectByActivityRanking1",method = RequestMethod.POST)
    @ApiOperation("获取活动所有排名")
    public String selectByActivityRanking1(@ApiParam(name = "activityId",value = "活动id")
                                  @RequestParam(name = "activityId") String activityId,
                                  @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByActivityRanking1(activityId,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}