|
@ -9,8 +9,9 @@ import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
|
|
|
import com.yihu.wlyy.repository.deviece.PatientHealthTimeDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
|
|
|
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
|
|
|
import com.yihu.wlyy.service.app.device.PatientDeviceLogService;
|
|
|
import com.yihu.wlyy.service.app.device.PatientDeviceService;
|
|
|
import com.yihu.wlyy.service.app.device.WlyyDeviceDetailService;
|
|
|
import com.yihu.wlyy.service.app.device.DeviceDetailService;
|
|
|
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
|
|
|
import com.yihu.wlyy.service.common.account.PatientService;
|
|
|
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
|
|
@ -18,7 +19,6 @@ import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.yihu.wlyy.util.HttpClientUtil;
|
|
|
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;
|
|
@ -59,11 +59,9 @@ public class PatientDeviceController extends BaseController {
|
|
|
@Autowired
|
|
|
private PatientDeviceDao patientDeviceDao;
|
|
|
@Autowired
|
|
|
private HttpClientUtil HttpClientUtil;
|
|
|
@Autowired
|
|
|
private PatientHealthIndexService patientHealthIndexService;
|
|
|
@Autowired
|
|
|
private WlyyDeviceDetailService wlyyDeviceDetailService;
|
|
|
private DeviceDetailService deviceDetailService;
|
|
|
@Autowired
|
|
|
private CreditLogService creditLogService;
|
|
|
@Autowired
|
|
@ -74,6 +72,8 @@ public class PatientDeviceController extends BaseController {
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
@Autowired
|
|
|
private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
|
|
|
@Autowired
|
|
|
private PatientDeviceLogService patientDeviceLogService;
|
|
|
|
|
|
@Value("${yihu.yihu_OpenPlatform_url}")
|
|
|
private String url;
|
|
@ -213,66 +213,62 @@ public class PatientDeviceController extends BaseController {
|
|
|
// 设置患者标识
|
|
|
device.setUser(getRepUID());
|
|
|
// device.setUser(getUID());
|
|
|
//首绑和设备类型判断
|
|
|
//患者和设备是否首绑
|
|
|
Map<String,Object> checkMap = patientDeviceService.checkBindingFirstAndType(device);
|
|
|
boolean flag = (Boolean)checkMap.get("flag");
|
|
|
int checkCode = Integer.valueOf(String.valueOf(checkMap.get("code")));
|
|
|
//已经绑定过同样的设备类型了,无法继续绑定
|
|
|
if (checkCode == -10000){
|
|
|
return write(-1,String.valueOf(checkMap.get("msg")));
|
|
|
}
|
|
|
|
|
|
Patient patient = patientService.findByCode(device.getUser());
|
|
|
if(!getUID().equals(getRepUID())&&device.getId()==null){
|
|
|
device.setAgent(getRepUID());
|
|
|
device.setAgentName(patient.getName());
|
|
|
}
|
|
|
String sn = device.getDeviceSn();
|
|
|
synchronized (sn.intern()){
|
|
|
patientDeviceService.saveDevice(device);
|
|
|
patientDeviceLogService.savePatientDeviceLog(device,2,1);
|
|
|
}
|
|
|
//判断是否为积分设备
|
|
|
DeviceDetail deviceDetail = wlyyDeviceDetailService.findBySn(device.getDeviceSn());
|
|
|
if (deviceDetail!=null){
|
|
|
//修改设备表中{"1":"0", "2":"0"}的绑定次数 和其他绑定信息,
|
|
|
wlyyDeviceDetailService.updateAfterBinding(device.getDeviceSn(),device.getUserIdcard(),device.getUserType(),new Date(),flag);
|
|
|
Patient patient = patientService.findByCode(device.getUser());
|
|
|
if (flag && "350205".equals(patient.getTown())){
|
|
|
String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"BIND\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+device.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(creditDetail);
|
|
|
com.alibaba.fastjson.JSONObject response = creditLogService.insert(jsonObject);
|
|
|
System.out.println("添加积分返回数据======"+response.toJSONString());
|
|
|
String status = response.getString("status");
|
|
|
if ("200".equals(status)){
|
|
|
List<Map<String,Object>> list = (List<Map<String,Object>>)response.get("detailModelList");
|
|
|
if (list!=null && list.size()>0){
|
|
|
String integrate = String.valueOf(list.get(0).get("integrate"));
|
|
|
String flagType = String.valueOf(list.get(0).get("flag"));
|
|
|
//@TODO 调用发送微信模板接口
|
|
|
//Patient people = patientDao.findByCode(device.getUser());
|
|
|
}
|
|
|
//修改设备表中{"1":"0", "2":"0"}的绑定次数 和其他绑定信息,
|
|
|
deviceDetailService.updateAfterBinding(device,new Date(),flag);
|
|
|
if (flag && "350205".equals(patient.getTown())){
|
|
|
String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"BIND\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+device.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(creditDetail);
|
|
|
com.alibaba.fastjson.JSONObject response = creditLogService.insert(jsonObject);
|
|
|
System.out.println("添加积分返回数据======"+response.toJSONString());
|
|
|
String status = response.getString("status");
|
|
|
/*if ("200".equals(status)){
|
|
|
List<Map<String,Object>> list = (List<Map<String,Object>>)response.get("detailModelList");
|
|
|
if (list!=null && list.size()>0){
|
|
|
String integrate = String.valueOf(list.get(0).get("integrate"));
|
|
|
String flagType = String.valueOf(list.get(0).get("flag"));
|
|
|
//@TODO 调用发送微信模板接口
|
|
|
//Patient people = patientDao.findByCode(device.getUser());
|
|
|
}
|
|
|
}*/
|
|
|
if (!"200".equals(status)){
|
|
|
logger.info("添加积分失败!");
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
String openId = patient.getOpenid();
|
|
|
String name = patient.getName();
|
|
|
|
|
|
org.json.JSONObject sendJson = new org.json.JSONObject();
|
|
|
String first = "";
|
|
|
String remark = "";
|
|
|
String deviceName = device.getDeviceName();
|
|
|
WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_patient_bind_device","bdsb");
|
|
|
first = templateConfig.getFirst();
|
|
|
first = first.replace("key1",(deviceName==null?"":deviceName));
|
|
|
remark = templateConfig.getRemark();
|
|
|
|
|
|
sendJson.put("keyword1", deviceName);
|
|
|
sendJson.put("keyword2", DateUtil.dateToStrLong(device.getCzrq()));
|
|
|
sendJson.put("keyword3", templateConfig.getKeyword3());
|
|
|
sendJson.put("first", first);
|
|
|
sendJson.put("remark", remark);
|
|
|
sendJson.put("url", templateConfig.getUrl());//带参数的模板跳转链接
|
|
|
System.out.println(sendJson.toString());
|
|
|
pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 22, openId, name, sendJson);
|
|
|
}
|
|
|
try {
|
|
|
String openId = patient.getOpenid();
|
|
|
String name = patient.getName();
|
|
|
|
|
|
org.json.JSONObject sendJson = new org.json.JSONObject();
|
|
|
String first = "";
|
|
|
String remark = "";
|
|
|
String deviceName = device.getDeviceName();
|
|
|
WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_patient_bind_device","bdsb");
|
|
|
first = templateConfig.getFirst();
|
|
|
first = first.replace("key1",(deviceName==null?"":deviceName));
|
|
|
remark = templateConfig.getRemark();
|
|
|
|
|
|
sendJson.put("keyword1", deviceName);
|
|
|
sendJson.put("keyword2", DateUtil.dateToStrLong(device.getCzrq()));
|
|
|
sendJson.put("keyword3", templateConfig.getKeyword3());
|
|
|
sendJson.put("first", first);
|
|
|
sendJson.put("remark", remark);
|
|
|
sendJson.put("url", templateConfig.getUrl());//带参数的模板跳转链接
|
|
|
System.out.println(sendJson.toString());
|
|
|
pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 22, openId, name, sendJson);
|
|
|
// //发送代理人
|
|
|
// jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);
|
|
|
// if (jsonArray != null && jsonArray.length() > 0) {
|
|
@ -289,13 +285,10 @@ public class PatientDeviceController extends BaseController {
|
|
|
// pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 19, member.getOpenid(), name, sendJson);
|
|
|
// }
|
|
|
// }
|
|
|
}catch (Exception e){
|
|
|
logger.info("设备绑定微信模板消息发送失败:"+e.getMessage());
|
|
|
}catch (Exception e){
|
|
|
logger.info("设备绑定微信模板消息发送失败:"+e.getMessage());
|
|
|
// e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return success("设备保存成功!");
|
|
|
} catch (Exception ex) {
|
|
|
error(ex);
|