liuwenbin 8 лет назад
Родитель
Сommit
8da4f0d38b

+ 288 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/pc/prescription/PCPrescriptionExpressageService.java

@ -0,0 +1,288 @@
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;
    }
}

+ 228 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/account/PCLoginController.java

@ -0,0 +1,228 @@
package com.yihu.wlyy.web.common.account;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.login.LoginLog;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.security.Token;
import com.yihu.wlyy.repository.security.TokenDao;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.common.account.RoleService;
import com.yihu.wlyy.service.common.account.TokenService;
import com.yihu.wlyy.service.common.login.LoginLogService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.MD5;
import com.yihu.wlyy.util.RSAUtils;
import com.yihu.wlyy.util.SystemData;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.patchca.color.SingleColorFactory;
import org.patchca.filter.predefined.*;
import org.patchca.service.ConfigurableCaptchaService;
import org.patchca.utils.encoder.EncoderHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
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.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.io.IOException;
import java.util.*;
import java.util.List;
//import io.swagger.annotations.Api;
/**
 * @author calvin
 */
@Controller
@RequestMapping(value = "/loginPC", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "健康师登录取药系统")
public class PCLoginController extends BaseController {
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private SMSService smsService;
    @Autowired
    public TokenDao tokenDao;
    @Autowired
    private RoleService roleService;
    @Autowired
    private LoginLogService loginLogService;
    /**
     *
     * @param mobile 手机号
     * @param captcha 短信验证码
     * @param platform  1、患者端,2、医生端app,3、微信公众号wechat,4、医生端pc,5PC端取药系统
     * @param password 密码
     * @return
     */
    @RequestMapping(value = "doctor",method = RequestMethod.POST)
    @ResponseBody
    public String doctor(@ApiParam(required = false, name = "mobile", value = "手机号") @RequestParam(required = false,value = "mobile") String mobile,
                         @ApiParam(required = false, name = "captcha", value = "短信验证码") @RequestParam(required = false) String captcha,
                         @ApiParam(required = false, name = "platform", value = "医生端pc") @RequestParam(required = false,defaultValue = "5") Integer platform,
                         @ApiParam(required = false, name = "password", value = "密码") @RequestParam(required = false) String password) {
        String errorMessage;
        LoginLog loginLog=new LoginLog();
        loginLog.setCreateTime(new Date());
        loginLog.setPhone(mobile);
        loginLog.setType("2");
        loginLog.setUserType("2");
        loginLog.setAppVersion(super.getAppVersion());
        try {
            if(platform==null){
                platform = 5;//默认为医生app端
            }
            //身份证登录
            if(StringUtils.isNoneEmpty(mobile)&&StringUtils.isNoneEmpty(password)){
                password = RSAUtils.getInstance(doctorService).decryptString(password);
                password=StringUtils.reverse(password);
                Doctor doctor=doctorService.findDoctorByMobile(mobile);
                loginLog.setLoginType("2");
                if(doctor==null){
                    errorMessage="该号码未注册!";
                    loginLog.setErrorMessage(errorMessage);
                    loginLogService.saveLog(loginLog);
                    return error(-1,errorMessage);
                }
                loginLog.setUserCode(doctor.getCode());
                String loginPassword= MD5.GetMD5Code(password+doctor.getSalt());
                if(loginPassword.equals(doctor.getPassword())){
                    //使用i健康系统账号体系,只有健康师有权限登录取药系统
                    if(doctor.getLevel()!=3){
                        loginLog.setType("2");
                        errorMessage="该用户角色没有登录权限!";
                        loginLog.setErrorMessage(errorMessage);
                        loginLogService.saveLog(loginLog);
                        return error(-1, errorMessage);
                    }
                    // 用户校验通过,生成token
                    Token token = tokenService.newToken(doctor.getCode(), "pc", platform);
                    loginLog.setTokenId(token.getId());
                    loginLog.setType("1");
                    Map<String, Object> map = new HashMap<>();
                    map.put("id", doctor.getId());
                    map.put("uid", doctor.getCode());
                    map.put("token", token.getToken());
                    map.put("name", doctor.getName());
                    map.put("hospital", doctor.getHospital());
                    map.put("photo", doctor.getPhoto());
                    // 设置医生类型:1专科医生,2全科医生,3健康管理师
                    map.put("doctorType", doctor.getLevel());
                    //获取医生角色和区域权限
//                    List<Map<String, String>> roleMap = roleService.getUserRoleAndArea(doctor.getCode());
//                    map.put("userRole", roleMap);
//                    if("10".equals(doctor.getLevel())&&roleMap.size()==0){
//                        errorMessage="该用户没有管理员权限";
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        return error(-1, errorMessage);
//                    }
                    loginLogService.saveLog(loginLog);
                    return write(200, "登录成功", "data", map);
                }else{
                    errorMessage="密码错误,登录失败";
                    loginLog.setErrorMessage(errorMessage);
                    loginLogService.saveLog(loginLog);
                    return error(-1, errorMessage);
                }
            }
            if(StringUtils.isNoneEmpty(mobile)&&StringUtils.isNoneEmpty(captcha)){
                // 对验证码进行校验
                int res = smsService.check(mobile, 5, captcha);
                switch (res) {
                    case -2:{
                        errorMessage="验证码已过期!";
                        loginLog.setErrorMessage(errorMessage);
                        loginLogService.saveLog(loginLog);
                        return error(-1, errorMessage);}
                    case -1:{
                        errorMessage="请输入正确的验证码!";
                        loginLog.setErrorMessage(errorMessage);
                        loginLogService.saveLog(loginLog);
                        return error(-1, errorMessage);}
                    case 0:{
                        errorMessage="验证码无效!";
                        loginLog.setErrorMessage(errorMessage);
                        loginLogService.saveLog(loginLog);
                        return error(-1, errorMessage);}
                }
                Doctor doctor = doctorService.findDoctorByMobile(mobile);
                loginLog.setLoginType("1");
                if (doctor == null) {
                    errorMessage="该手机号未注册,请确认!";
                    loginLog.setErrorMessage(errorMessage);
                    loginLogService.saveLog(loginLog);
                    return error(-1, errorMessage);
                } else {
                    loginLog.setUserCode(doctor.getCode());
                    //使用i健康系统账号体系,只有健康师有权限登录取药系统
                    if(doctor.getLevel()!=3){
                        loginLog.setType("2");
                        errorMessage="该用户角色没有登录权限!";
                        loginLog.setErrorMessage(errorMessage);
                        loginLogService.saveLog(loginLog);
                        return error(-1, errorMessage);
                    }
                    // 用户校验通过,生成token
                    Token token = tokenService.newToken(doctor.getCode(), "pc", platform);
                    loginLog.setTokenId(token.getId());
                    loginLog.setType("1");
                    Map<String, Object> map = new HashMap<>();
                    map.put("id", doctor.getId());
                    map.put("uid", doctor.getCode());
                    map.put("token", token.getToken());
                    map.put("name", doctor.getName());
                    map.put("hospital", doctor.getHospital());
                    map.put("photo", doctor.getPhoto());
                    // 设置医生类型:1专科医生,2全科医生,3健康管理师
                    map.put("doctorType", doctor.getLevel());
                    //获取医生角色和区域权限
//                    List<Map<String, String>> roleMap = roleService.getUserRoleAndArea(doctor.getCode());
//                    map.put("userRole", roleMap);
//                    if("10".equals(doctor.getLevel())&&roleMap.size()==0){
//                        errorMessage="改用户没有管理员权限";
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        return error(-1, errorMessage);
//                    }
                    loginLogService.saveLog(loginLog);
                    return write(200, "登录成功", "data", map);
                }
            }
            errorMessage="登录信息不完整,请重新输入!";
            loginLog.setErrorMessage(errorMessage);
            loginLogService.saveLog(loginLog);
            return error(-1,errorMessage);
        } catch (Exception e) {
            loginLog.setErrorMessage(e.getMessage());
            loginLogService.saveLog(loginLog);
            error(e);
            return error(-1, "系统异常,登录失败");
        }
    }
}

+ 28 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/prescriptionPC/PrescriptionExpressagePCController.java

@ -0,0 +1,28 @@
package com.yihu.wlyy.web.doctor.prescriptionPC;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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;
/**
 * Created by liuwenbin on 2017/8/12.
 */
@Api(description = "PC端-长处方取药/领药接口")
@RestController
@RequestMapping(value = "/PC/prescription")
public class PrescriptionExpressagePCController extends BaseController {
    @ApiOperation(value = "取药/领药")
    @RequestMapping(value = "/getMedicine", method = RequestMethod.POST)
    public String getMedicine(
            @ApiParam(required = true, name = "code", value = "二维码(取药码、配送码)") @RequestParam(value = "code", required = true) String code){
        return "";
    }
}