| 
					
				 | 
			
			
				@ -1,17 +1,27 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.wlyy.web.gateway.controller; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.deser.Deserializers; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.doctor.profile.Doctor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.gateway.GcClientDetails; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.gateway.GcToken; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.login.LoginLog; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.security.Token; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.account.DoctorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.account.TokenService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.login.LoginLogService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.gateway.GcClientDetailsService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.gateway.GcTokenService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.MD5; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.NetworkUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.RSAUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.web.gateway.vo.GcTokenModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.web.gateway.vo.LoginModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.web.gateway.vo.base.BaseResultModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.web.gateway.vo.base.ResultOneModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.annotations.Api; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.annotations.ApiOperation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.annotations.ApiParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.bind.annotation.RequestMapping; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -21,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by chenweida on 2017/8/17. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -31,10 +42,17 @@ import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Api(description = "token相关服务") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class GcTokenController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private GcTokenService tokenService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private GcTokenService gcTokenService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private GcClientDetailsService clientDetailsService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private DoctorService doctorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private TokenService tokenService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private LoginLogService loginLogService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @ApiOperation("获取accesstoken") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @RequestMapping(value = "accesstoken", method = RequestMethod.GET) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ResultOneModel<GcTokenModel> getToken( 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -59,7 +77,7 @@ public class GcTokenController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //生成token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        GcToken gcToken = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            gcToken = tokenService.createToken(appid, appSecret, NetworkUtil.getIpAddress(request)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            gcToken = gcTokenService.createToken(appid, appSecret, NetworkUtil.getIpAddress(request)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -67,4 +85,93 @@ public class GcTokenController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BeanUtils.copyProperties(gcToken, gcTokenModel); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return new ResultOneModel(gcTokenModel); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 医生端要传  userAgent:{"id":4816,"uid":"xh1D2017031503333","token":"5d68d84dbb79996efba31192856139a4","platform":4,"imei":"05948CE4F079E998306CFCCF86A5A77F"} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param imei 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param account 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param platform 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param password 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @RequestMapping(value = "/doctor/login", method = RequestMethod.GET) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @ApiOperation("医生端登陆") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ResultOneModel<LoginModel> doctorLogin( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            @ApiParam(required = false, name = "imei", value = "imei号") @RequestParam(required = true, value = "imei") String imei, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            @ApiParam(required = false, name = "account", value = "手机号/身份证") @RequestParam(required = false, value = "account") String account, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            @ApiParam(required = false, name = "platform", value = "医生端pc,取药系统 或者对外系统") @RequestParam(required = false, defaultValue = "4") 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(account); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        loginLog.setType("2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        loginLog.setUserType("2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (StringUtils.isEmpty(imei)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                errorMessage = "获取IMEI码失败!"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                loginLog.setErrorMessage(errorMessage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                loginLogService.saveLog(loginLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return new ResultOneModel<>(BaseResultModel.codeEm.login_IMEI_error.getCode(), BaseResultModel.codeEm.login_IMEI_error.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (platform == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                platform = 2;//默认为医生app端 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //身份证登录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (StringUtils.isNoneEmpty(account) && StringUtils.isNoneEmpty(password)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                password = RSAUtils.getInstance(doctorService).decryptString(password); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                password = StringUtils.reverse(password); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //根据电话号码找 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Doctor doctor = doctorService.findDoctorByMobile(account); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (doctor == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //如果电话号码找不到 根据身份证找 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    doctor = doctorService.findbyIdCard(account); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                loginLog.setLoginType("2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (doctor == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    errorMessage = "该号码未注册!"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginLog.setErrorMessage(errorMessage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginLogService.saveLog(loginLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return new ResultOneModel<>(BaseResultModel.codeEm.login_account_error.getCode(), BaseResultModel.codeEm.login_account_error.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                loginLog.setUserCode(doctor.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String loginPassword = MD5.GetMD5Code(password + doctor.getSalt()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (loginPassword.equals(doctor.getPassword())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Token token = tokenService.findDoctorToken(doctor.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (token != null && platform == 4) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //pc版本要做单点登陆 所以如果platform =4 并且 token存在直接返回之前的token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        // 用户校验通过,生成token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        token = tokenService.newToken(doctor.getCode(), imei, platform); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginLog.setTokenId(token.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginLog.setType("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    LoginModel loginModel = new LoginModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginModel.setDoctorCode(doctor.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginModel.setDoctorName(doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginModel.setToken(token.getToken()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginModel.setDoctorPhoto(doctor.getPhoto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginModel.setDoctorType(doctor.getLevel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginLogService.saveLog(loginLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return new ResultOneModel<>(loginModel); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    errorMessage = "密码错误,登录失败"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginLog.setErrorMessage(errorMessage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    loginLogService.saveLog(loginLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return new ResultOneModel<>(BaseResultModel.codeEm.login_password_error.getCode(), BaseResultModel.codeEm.login_password_error.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return new ResultOneModel<>(BaseResultModel.codeEm.error_params.getCode(), BaseResultModel.codeEm.error_params.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            loginLog.setErrorMessage(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            loginLogService.saveLog(loginLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return new ResultOneModel<>(BaseResultModel.codeEm.login_system_error.getCode(), BaseResultModel.codeEm.login_system_error.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |