|
@ -0,0 +1,205 @@
|
|
|
package com.yihu.jw.hospital.endpoint.hospital;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorBackgroundDO;
|
|
|
import com.yihu.jw.hospital.family.service.PatientMemberDictService;
|
|
|
import com.yihu.jw.hospital.family.service.WlyyFamilyMemberService;
|
|
|
import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
|
|
|
import com.yihu.jw.restmodel.web.Envelop;
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
|
|
|
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
|
|
|
import com.yihu.jw.sms.service.ZhongShanSMSService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping(value = BaseHospitalRequestMapping.WlyyFamilyMember.wlyyFamilyMember)
|
|
|
@Api(value = "互联网医院家人关联管理", description = "互联网医院家人关联管理", tags = {"互联网医院 - 互联网医院家人关联管理"})
|
|
|
public class WlyyFamilyMemberController extends EnvelopRestEndpoint {
|
|
|
@Autowired
|
|
|
private WlyyFamilyMemberService wlyyFamilyMemberService;
|
|
|
@Autowired
|
|
|
private PatientMemberDictService patientMemberDictService;
|
|
|
@Autowired
|
|
|
private EntranceService entranceService;
|
|
|
@Autowired
|
|
|
private RedisTemplate redisTemplate;
|
|
|
private final String KEY_SUFFIX = ":code";
|
|
|
@Autowired
|
|
|
private ZhongShanSMSService zhongShanSMSService;
|
|
|
|
|
|
@ApiOperation("获取家人关系")
|
|
|
@PostMapping(value = BaseHospitalRequestMapping.WlyyFamilyMember.findRelationDict)
|
|
|
public Envelop findRelationDict() {
|
|
|
return success(patientMemberDictService.findAllMemberDict());
|
|
|
}
|
|
|
|
|
|
@ApiOperation("发送验证码")
|
|
|
@PostMapping(value = BaseHospitalRequestMapping.WlyyFamilyMember.sendZSFamily)
|
|
|
public MixEnvelop sendZSCaptcha(@ApiParam(name = "jsonData", value = "jsonData", required = false)
|
|
|
@RequestParam(value = "jsonData", required = false) String jsonData) throws Exception {
|
|
|
MixEnvelop mixEnvelop = new MixEnvelop();
|
|
|
JSONObject obj = JSONObject.parseObject(jsonData);
|
|
|
String client_id = obj.getString("client_id");
|
|
|
String username = obj.getString("phoneNum");
|
|
|
String idCard = obj.getString("idCard");
|
|
|
String familyName = obj.getString("familyName");
|
|
|
JSONArray jsonArray = entranceService.BS10008(idCard, familyName, username, null, null, null, true);
|
|
|
if (StringUtils.isEmpty(client_id)) {
|
|
|
mixEnvelop.setStatus(468);
|
|
|
mixEnvelop.setMessage("client_id不能为空");
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
if (StringUtils.isEmpty(username)) {
|
|
|
mixEnvelop.setStatus(468);
|
|
|
mixEnvelop.setMessage("username不能为空");
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
if (username.length() > 12) {
|
|
|
mixEnvelop.setStatus(468);
|
|
|
mixEnvelop.setMessage("请输入正确的手机号");
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
//验证请求间隔超时,防止频繁获取验证码
|
|
|
if (!this.isIntervalTimeout(client_id, username)) {
|
|
|
throw new IllegalAccessException("SMS request frequency is too fast");
|
|
|
//发送短信获取验证码
|
|
|
}
|
|
|
String captcha = this.getCodeNumber();
|
|
|
int result = 1;
|
|
|
if (jsonArray.size() > 0) {
|
|
|
result = zhongShanSMSService.ZhongShangSendSMS(username, "您好,您当前操作的验证码是:" + captcha + ",2分钟内有效。");
|
|
|
} else {
|
|
|
result = 2;
|
|
|
}
|
|
|
if (0 == result) {
|
|
|
this.store(client_id, username, captcha, 120);
|
|
|
mixEnvelop.setMessage("验证码发送成功");
|
|
|
} else if (2 == result) {
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("您所添加的家属无就诊记录,无法发送验证码");
|
|
|
} else {
|
|
|
mixEnvelop.setMessage("验证码发送失败");
|
|
|
mixEnvelop.setStatus(500);
|
|
|
}
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
|
|
|
public void store(String client_id, String username, String code, int expire) {
|
|
|
String key = client_id + ":" + username + KEY_SUFFIX;
|
|
|
redisTemplate.opsForValue().set(key, code);
|
|
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
|
|
String intervalKey = key + ":" + code + "_interval";
|
|
|
redisTemplate.opsForValue().set(intervalKey, 60);
|
|
|
redisTemplate.expire(intervalKey, 60, TimeUnit.SECONDS);
|
|
|
}
|
|
|
|
|
|
public boolean isIntervalTimeout(String client_id, String username) {
|
|
|
String key = client_id + ":" + username + KEY_SUFFIX;
|
|
|
String code = (String) redisTemplate.opsForValue().get(key);
|
|
|
if (null == code) {
|
|
|
return true;
|
|
|
}
|
|
|
String intervalKey = key + ":" + code + "_interval";
|
|
|
if (redisTemplate.opsForValue().get(intervalKey) != null) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//生成6位随机数
|
|
|
public String getCodeNumber() {
|
|
|
return (int) ((Math.random() * 9 + 1) * 100000) + "";
|
|
|
}
|
|
|
|
|
|
//验证验证码
|
|
|
public boolean verification(String client_id, String username, String code) {
|
|
|
if (StringUtils.isEmpty(code)) {
|
|
|
return false;
|
|
|
}
|
|
|
String key = client_id + ":" + username + KEY_SUFFIX;
|
|
|
String _code = (String) redisTemplate.opsForValue().get(key);
|
|
|
if (null == _code) {
|
|
|
return false;
|
|
|
}
|
|
|
if (code.equalsIgnoreCase(_code)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@ApiOperation("保存家人关系")
|
|
|
@PostMapping(value = BaseHospitalRequestMapping.WlyyFamilyMember.saveFamilyRelation)
|
|
|
public MixEnvelop saveFamilyRelation(@ApiParam(name = "jsonData", value = "jsonData", required = false)
|
|
|
@RequestParam(value = "jsonData", required = false) String jsonData) {
|
|
|
MixEnvelop mixEnvelop = new MixEnvelop();
|
|
|
try {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(jsonData);
|
|
|
String client_id = jsonObject.getString("client_id");
|
|
|
String username = jsonObject.getString("phoneNum");
|
|
|
String code = jsonObject.getString("code");
|
|
|
boolean checkCode = this.verification(client_id, username, code);
|
|
|
if (true) {
|
|
|
String patientId = jsonObject.getString("patientId");
|
|
|
String familyName = jsonObject.getString("familyName");
|
|
|
String dictId = jsonObject.getString("dictId");
|
|
|
String cardType = jsonObject.getString("cardType");
|
|
|
String idCard = jsonObject.getString("idCard");
|
|
|
String id = "";
|
|
|
if (null != jsonObject.get("id")) {
|
|
|
id = jsonObject.get("id").toString();
|
|
|
}
|
|
|
;
|
|
|
mixEnvelop = wlyyFamilyMemberService.addFamily(id, patientId, familyName, dictId, cardType, idCard, username, true);
|
|
|
} else {
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("验证码不正确");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
|
|
|
@ApiOperation("查询就诊人")
|
|
|
@PostMapping(value = BaseHospitalRequestMapping.WlyyFamilyMember.findFamilyMumber)
|
|
|
public Envelop findFamilyMumberByPatientId(@ApiParam(name = "patientId", value = "patientId", required = false)
|
|
|
@RequestParam(value = "patientId", required = false) String patientId) {
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
try {
|
|
|
list = wlyyFamilyMemberService.findFamilyByPatientId(patientId);
|
|
|
} catch (ParseException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return success(list);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("删除就诊人")
|
|
|
@PostMapping(value = BaseHospitalRequestMapping.WlyyFamilyMember.delFamilyMumber)
|
|
|
public Envelop delFamilyMumber(@ApiParam(name = "id", value = "id", required = false)
|
|
|
@RequestParam(value = "id", required = false) String id) {
|
|
|
return wlyyFamilyMemberService.delMember(id);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("获取单个亲属信息")
|
|
|
@PostMapping(value = BaseHospitalRequestMapping.WlyyFamilyMember.findSingleMember)
|
|
|
public Envelop findSingleMember(@ApiParam(name = "id", value = "id", required = false)
|
|
|
@RequestParam(value = "id", required = false) String id) {
|
|
|
return success(wlyyFamilyMemberService.findMemberById(id));
|
|
|
}
|
|
|
}
|