|
@ -1,288 +0,0 @@
|
|
|
package com.yihu.wlyy.service.pc.prescription;
|
|
|
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.patient.prescription.PrescriptionDispensaryCode;
|
|
|
import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog;
|
|
|
import com.yihu.wlyy.repository.prescription.PrescriptionDispensaryCodeDao;
|
|
|
import com.yihu.wlyy.repository.prescription.PrescriptionExpressageDao;
|
|
|
import com.yihu.wlyy.repository.prescription.PrescriptionLogDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.app.prescription.PrescriptionInfoService;
|
|
|
import com.yihu.wlyy.service.common.account.DoctorService;
|
|
|
import com.yihu.wlyy.service.common.account.RoleService;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* Created by liuwenbin on 2017/8/12.
|
|
|
* PC端长处方取药/领药业务层
|
|
|
*/
|
|
|
@Service
|
|
|
public class PCPrescriptionExpressageService extends BaseService {
|
|
|
|
|
|
@Autowired
|
|
|
private PrescriptionDispensaryCodeDao prescriptionDispensaryCodeDao;
|
|
|
@Autowired
|
|
|
private PrescriptionLogDao prescriptionLogDao;
|
|
|
@Autowired
|
|
|
private RoleService roleService;
|
|
|
@Autowired
|
|
|
private DoctorService doctorService;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private PrescriptionExpressageDao prescriptionExpressageDao;
|
|
|
@Autowired
|
|
|
private PrescriptionInfoService prescriptionInfoService;
|
|
|
|
|
|
public Integer getMedicine(String code,String userCode){
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
//获取根据wlyy_prescription_dispensary_code的code处方编码
|
|
|
PrescriptionDispensaryCode prescriptionDispensaryCode = prescriptionDispensaryCodeDao.finByCode(code);
|
|
|
Integer returnStatus = -1;
|
|
|
if (prescriptionDispensaryCode == null) {
|
|
|
//保存验证二维码的日志
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
prescriptionLog.setPrescriptionCode(prescriptionDispensaryCode.getPrescriptionCode());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.expressage.getValue());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setUserCode(userCode);
|
|
|
prescriptionLog.setUserType(2);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing_error.getValue());
|
|
|
prescriptionLog.setRemark("编码不存在");
|
|
|
prescriptionLogDao.save(prescriptionLog);
|
|
|
returnStatus = -1;
|
|
|
return returnStatus;
|
|
|
}
|
|
|
if (prescriptionDispensaryCode.getIsUse() == 1) {
|
|
|
//判断编码是否使用过
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
prescriptionLog.setPrescriptionCode(prescriptionDispensaryCode.getPrescriptionCode());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.expressage.getValue());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setUserCode(userCode);
|
|
|
prescriptionLog.setUserType(2);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing_error.getValue());
|
|
|
prescriptionLog.setRemark("编码重复扫描");
|
|
|
prescriptionLogDao.save(prescriptionLog);
|
|
|
returnStatus = -2;
|
|
|
return returnStatus;
|
|
|
}
|
|
|
|
|
|
// 判断出药机构是否与健管师所属机构一致,不一致弹窗提示:“出药机构与您所在机构不一致,无法出药,请重新确认”。一致则进入下一步。
|
|
|
//获取医生角色和区域权限
|
|
|
// List<Map<String, String>> roleMap = roleService.getUserRoleAndArea(userCode);
|
|
|
// if("10".equals(doctor.getLevel())&&roleMap.size()==0){
|
|
|
// errorMessage="该用户没有管理员权限";
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// return error(-1, errorMessage);
|
|
|
// }
|
|
|
switch (prescriptionDispensaryCode.getType()) {
|
|
|
case 1: {
|
|
|
//判断是1 居民取药码
|
|
|
// returnStatus = dispensaryCode_1(userCode, prescriptionDispensaryCode);
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
case 2: {
|
|
|
//判断是2 配送员(健管师)取药码
|
|
|
// returnStatus = dispensaryCode_2(userCode, prescriptionDispensaryCode);
|
|
|
break;
|
|
|
}
|
|
|
case 3: {
|
|
|
//判断是3 配送员(健管师)配送码
|
|
|
// returnStatus = dispensaryCode_3(userCode, prescriptionDispensaryCode);
|
|
|
break;
|
|
|
}
|
|
|
default: {
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
prescriptionLog.setPrescriptionCode(prescriptionDispensaryCode.getPrescriptionCode());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.expressage.getValue());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setUserCode(userCode);
|
|
|
prescriptionLog.setUserType(2);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing_error.getValue());
|
|
|
prescriptionLog.setRemark("编码类型错误");
|
|
|
prescriptionLogDao.save(prescriptionLog);
|
|
|
returnStatus = -3;
|
|
|
return returnStatus;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
//健管师取药码
|
|
|
public JSONObject dispensaryCode_2(String userCode,PrescriptionDispensaryCode prescriptionDispensaryCode){
|
|
|
// Integer returnStatus = -3;
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
Doctor doctor = doctorService.findDoctorByCode(userCode);
|
|
|
String sql = "select a.type,c.status,b.hospital_code as hospitalCode from wlyy_prescription_dispensary_code a \n" +
|
|
|
"left join wlyy_prescription_expressage b on a.prescription_code = b.prescription_code \n" +
|
|
|
"left join wlyy_prescription c on a.prescription_code = c.code \n" +
|
|
|
"where a.prescription_code=?";
|
|
|
Map<String, Object> result = jdbcTemplate.queryForMap(sql,prescriptionDispensaryCode.getPrescriptionCode());
|
|
|
if(result.size()>0){
|
|
|
|
|
|
int status = (Integer)result.get("status");
|
|
|
if((Integer)result.get("type")==1){//居民取药码
|
|
|
if(status>=30){
|
|
|
if(status==30){
|
|
|
jsonObject.put("status",-5);//订单正在配药中,暂时无法出药
|
|
|
}else if(status==40){
|
|
|
jsonObject.put("status",1);//取药成功
|
|
|
}else{
|
|
|
jsonObject.put("status",-6);//”订单已取药,出药人:张三,出药时间:XXXX-XX-XX,无法重新出药
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}else if((Integer)result.get("type")==2){//健管师取药码
|
|
|
if(result.get("hospitalCode").toString().equals(doctor.getHospital())){
|
|
|
|
|
|
//20开方完成/待支付, 21 支付失败 , 30 支付成功/待配药 , 40配药成功/待配送 41配送失败 42分配健管师 45配送中 49配送到服务站 100配送到患者手中/已完成
|
|
|
if(status==30){
|
|
|
jsonObject.put("status",-5);//订单正在配药中,暂时无法出药
|
|
|
}else if(status>=45){
|
|
|
jsonObject.put("status",-6);//”订单已取药,出药人:张三,出药时间:XXXX-XX-XX,无法重新出药
|
|
|
}else if(status==40){
|
|
|
jsonObject.put("status",1);
|
|
|
}
|
|
|
}else{
|
|
|
jsonObject.put("status",-4);//出药机构与您所在机构不一致,无法出药,请重新确认
|
|
|
// return jsonObject;
|
|
|
}
|
|
|
}else{
|
|
|
jsonObject.put("status",-7); //取药码错误
|
|
|
//保存验证二维码的日志
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
prescriptionLog.setPrescriptionCode(prescriptionDispensaryCode.getPrescriptionCode());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.expressage.getValue());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setUserCode(userCode);
|
|
|
prescriptionLog.setUserType(2);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing_error.getValue());
|
|
|
prescriptionLog.setRemark("PC端取药码输入错误!");
|
|
|
prescriptionLogDao.save(prescriptionLog);
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
jsonObject.put("status",-7); //取药码错误
|
|
|
//保存验证二维码的日志
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
prescriptionLog.setPrescriptionCode(prescriptionDispensaryCode.getPrescriptionCode());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.expressage.getValue());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setUserCode(userCode);
|
|
|
prescriptionLog.setUserType(2);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing_error.getValue());
|
|
|
prescriptionLog.setRemark("编码不存在");
|
|
|
prescriptionLogDao.save(prescriptionLog);
|
|
|
}
|
|
|
|
|
|
jsonObject.put("result",result);
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
public JSONObject getMedicine2(String code,String userCode){
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
Doctor doctor = doctorService.findDoctorByCode(userCode);
|
|
|
String sql = "select a.type,a.prescription_code as prescriptionCode c.status,b.hospital_code as hospitalCode, \n" +
|
|
|
"b.code as expressageCode, b.hospital_name as hospitalName,c.dispensary_type as dispensaryType, \n" +
|
|
|
"b.expressage_name as expressageName, b.expressage_code as expressageCode,b.expressage_mobile as expressageMobile \n" +
|
|
|
"from wlyy_prescription_dispensary_code a \n" +
|
|
|
"left join wlyy_prescription_expressage b on a.prescription_code = b.prescription_code \n" +
|
|
|
"left join wlyy_prescription c on a.prescription_code = c.code \n" +
|
|
|
"where a.is_use=0 and a.cod=? and c.status>=30";
|
|
|
Map<String, Object> result = jdbcTemplate.queryForMap(sql,code);
|
|
|
if(result.size()>0){
|
|
|
int type = result.get("type")!=null?(Integer) result.get("type"):0;
|
|
|
int status = result.get("status")!=null?(Integer) result.get("status"):-100;
|
|
|
switch (type){
|
|
|
//居民取药码
|
|
|
case 1:{
|
|
|
if(status==30){
|
|
|
jsonObject.put("status",-5);//订单正在配药中,暂时无法出药
|
|
|
}else if(status==40){
|
|
|
jsonObject.put("status",1);
|
|
|
}else{
|
|
|
jsonObject.put("status",-6);//”订单已取药,出药人:张三,出药时间:XXXX-XX-XX,无法重新出药
|
|
|
}
|
|
|
}
|
|
|
//健管师取药码
|
|
|
case 2:{
|
|
|
|
|
|
//判断出药机构是否与健管师所属机构一致,不一致弹窗提示:“出药机构与您所在机构不一致,无法出药,请重新确认”。一致则进入下一步。
|
|
|
if(doctor.getHospital().equals(result.get("hospitalCode").toString())){
|
|
|
//20开方完成/待支付, 21 支付失败 , 30 支付成功/待配药 , 40配药成功/待配送 41配送失败 42分配健管师 45配送中 49配送到服务站 100配送到患者手中/已完成
|
|
|
if(status==30){
|
|
|
jsonObject.put("status",-5);//订单正在配药中,暂时无法出药
|
|
|
}else if(status>=45){
|
|
|
jsonObject.put("status",-6);//”订单已取药,出药人:张三,出药时间:XXXX-XX-XX,无法重新出药
|
|
|
}else if(status==40){
|
|
|
jsonObject.put("status",1);
|
|
|
}
|
|
|
}else{
|
|
|
jsonObject.put("status",-4);//出药机构与您所在机构不一致,无法出药,请重新确认
|
|
|
}
|
|
|
}
|
|
|
default:{
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
prescriptionLog.setPrescriptionCode(result.get("prescriptionCode").toString());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.expressage.getValue());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setUserCode(userCode);
|
|
|
prescriptionLog.setUserType(2);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing_error.getValue());
|
|
|
prescriptionLog.setRemark("编码类型错误");
|
|
|
prescriptionLogDao.save(prescriptionLog);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
//保存验证二维码的日志
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
// prescriptionLog.setPrescriptionCode(result.get("").toString());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.expressage.getValue());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setUserCode(userCode);
|
|
|
prescriptionLog.setUserType(2);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing_error.getValue());
|
|
|
prescriptionLog.setRemark("PC端取药码输入错误!");
|
|
|
}
|
|
|
// prescriptionInfoService.
|
|
|
jsonObject.put("expressageCode",result.get("expressageCode"));
|
|
|
jsonObject.put("hospitalCode",result.get("hospitalCode"));
|
|
|
jsonObject.put("hospitalName",result.get("hospitalName"));
|
|
|
jsonObject.put("status",result.get("status"));
|
|
|
jsonObject.put("dispensaryType",result.get("dispensaryType"));
|
|
|
jsonObject.put("expressageName",result.get("expressageName"));
|
|
|
jsonObject.put("expressageMobile",result.get("expressageMobile"));
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
}
|