|
@ -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);
|
|
|
}
|
|
|
}
|