Selaa lähdekoodia

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

wangzhinan 5 vuotta sitten
vanhempi
commit
3573320ebb

+ 5 - 1
business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorInfoService.java

@ -367,5 +367,9 @@ public class BaseDoctorInfoService extends BaseJpaService<BaseDoctorDO, BaseDoct
        redisTemplate.opsForValue().set(key,valueJson.toJSONString());
        return true;
    }
    
    public List<BaseDoctorDO> findDoctorsByIdcard(String idcard){
        List<BaseDoctorDO> doctors = baseDoctorDao.findByIdcard(idcard);
        return doctors;
    }
}

+ 1 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/hospital/BaseHospitalRequestMapping.java

@ -724,6 +724,7 @@ public class BaseHospitalRequestMapping {
        public static final String getJobBySaasId ="/getJobBySaasId";
        public static final String findWorkTimeInfo="/findWorkTimeInfo";
        public static final String findLevelOneDoctorUpcoming="/findLevelOneDoctorUpcoming";
        public static final String getUpcomingByDoctor="/getUpcomingByDoctor";
    }
    /**

+ 170 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyYkyyEndpoint.java

@ -0,0 +1,170 @@
package com.yihu.jw.security.oauth2.provider.endpoint;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.login.BaseLoginLogDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.security.core.userdetails.jdbc.WlyyUserDetailsService;
import com.yihu.jw.security.dao.doctor.BaseDoctorDao;
import com.yihu.jw.security.login.service.BaseLoginLogService;
import com.yihu.jw.security.model.WlyyUserSimple;
import com.yihu.jw.security.oauth2.provider.WlyyTokenGranter;
import com.yihu.jw.security.service.YkyyService;
import io.swagger.annotations.Api;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.exceptions.InvalidRequestException;
import org.springframework.security.oauth2.common.exceptions.UnsupportedGrantTypeException;
import org.springframework.security.oauth2.provider.*;
import org.springframework.security.oauth2.provider.endpoint.AbstractEndpoint;
import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory;
import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestValidator;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.Map;
/**
 * Created by yeshijie on 2020/4/24.
 *
 * @author yeshijie.
 */
@Api(description = "眼科医院")
@RestController
public class WlyyYkyyEndpoint extends AbstractEndpoint {
    private final Logger LOG = LoggerFactory.getLogger(getClass());
    private OAuth2RequestFactory oAuth2RequestFactory;
    private OAuth2RequestValidator oAuth2RequestValidator = new DefaultOAuth2RequestValidator();
    @Autowired
    private YkyyService ykyyService;
    @Autowired
    private WlyyUserDetailsService userDetailsService;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private ClientDetailsService clientDetailsService;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private BaseLoginLogService baseLoginLogService;
    @Autowired
    private AuthenticationManager authenticationManager;
    @Autowired
    private WlyyTokenGranter tokenGranter;
    @PostConstruct
    private void init() {
        super.setTokenGranter(tokenGranter);
    }
    /**
     * 眼科医生登录
     * @param verifyCode
     * @param client_id
     * @param login_type 用户类型 1或默认为user,2:医生登录
     * @return
     */
    @RequestMapping(value = "/oauth/ykyyDoctorLogin", method = RequestMethod.POST)
    public ObjEnvelop ykyyDoctorLogin(String verifyCode, String client_id,String login_type) {
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
        }
        if (StringUtils.isEmpty(login_type)) {
            throw new InvalidRequestException("login_type is null");
        }
        try {
            logger.info("verifyCode :"+verifyCode);
            String data = ykyyService.getDoctorInfoByVerifycode(verifyCode);
            JSONObject jsonObject = JSONObject.parseObject(data);
            if(!jsonObject.getString("code").equalsIgnoreCase("10000")){
                logger.info(jsonObject.getString("message"));
                return ObjEnvelop.getError("授权登录失败!");
            }
            JSONObject value = jsonObject.getJSONObject("value");
            String doctorId = value.getString("doctorId");
            String tel = value.getString("tel");
            String idCard = value.getString("idCard");
            String loginId = value.getString("loginId");
//            String idCard = "352103197207090030";
            BaseDoctorDO doctorDO = doctorDao.findByIdcard(idCard);
            if(doctorDO == null){
                return ObjEnvelop.getError("授权登录失败!");
            }
            ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
            Map<String, String> parameters = new HashedMap();
            parameters.put("username", idCard);
            parameters.put("grant_type", "ihealthDcotor");
            TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient);
            if (authenticatedClient != null) {
                oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient);
            }
            OAuth2AccessToken token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);
            if (token == null) {
                throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
            }
            WlyyUserSimple wlyyUserSimple = userDetailsService.authSuccess(parameters.get("username"));
            wlyyUserSimple.setAccessToken(token.getValue());
            wlyyUserSimple.setTokenType(token.getTokenType());
            wlyyUserSimple.setExpiresIn(token.getExpiresIn());
            wlyyUserSimple.setRefreshToken(token.getRefreshToken().getValue());
            wlyyUserSimple.setUser(parameters.get("username"));
            String loginType = parameters.get("login_type");
            BaseLoginLogDO baseLoginLogDO = new BaseLoginLogDO();
            userDetailsService.setRolePhth(loginType, token, wlyyUserSimple.getId(), redisTemplate);
            baseLoginLogDO.setUserId(wlyyUserSimple.getId());
            baseLoginLogDO.setCreateTime(new Date());
            String userAgent = JSONObject.toJSONString(wlyyUserSimple);
            baseLoginLogDO.setUserAgent(userAgent);
            baseLoginLogDO.setLoginType(loginType);
            baseLoginLogService.save(baseLoginLogDO);
            return ObjEnvelop.getSuccess("success",wlyyUserSimple);
        }catch (Exception e){
            logger.error(e);
        }
        return ObjEnvelop.getError("登录失败!");
    }
    @Override
    protected TokenGranter getTokenGranter() {
        return this.tokenGranter;
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.state(clientDetailsService != null, "ClientDetailsService must be provided");
        Assert.state(authenticationManager != null, "AuthenticationManager must be provided");
        oAuth2RequestFactory = new DefaultOAuth2RequestFactory(clientDetailsService);
    }
}

+ 33 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/service/YkyyService.java

@ -0,0 +1,33 @@
package com.yihu.jw.security.service;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.security.dao.doctor.BaseDoctorDao;
import com.yihu.jw.security.utils.HttpClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * 眼科医院
 * Created by yeshijie on 2020/4/24.
 *
 * @author yeshijie.
 */
@Service
public class YkyyService {
    @Autowired
    private HttpClientUtil httpClientUtil;
    private static String yktUrl = "http://www.yanketong.com:90/";
    /**
     * 眼科医院单点登录接口
     * @return
     */
    public String getDoctorInfoByVerifycode(String verifyCode){
        String url = "api/Doctor/GetDoctorInfoByverifycode";
        return httpClientUtil.get(yktUrl+url+"?verifyCode="+verifyCode,"GBK");
    }
}

+ 19 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/patient/PatientNoLoginEndPoint.java

@ -213,4 +213,23 @@ public class PatientNoLoginEndPoint extends EnvelopRestEndpoint {
        }
        return success("请求成功",result);
    }
    
    
    @GetMapping(value = BaseHospitalRequestMapping.PatientNoLogin.getUpcomingByDoctor)
    @ApiOperation(value = "获取医生待办详情", notes = "获取医生待办详情")
    public Envelop getUpcomingByDoctor(@ApiParam(name = "doctorIdcard", value = "doctorIdcard", required = true)
                                       @RequestParam(value = "doctorIdcard",required = true)String doctorIdcard){
        JSONObject result = new JSONObject();
        List<BaseDoctorDO> doctors = baseDoctorService.findDoctorsByIdcard(doctorIdcard);
        BaseDoctorDO doctor = new BaseDoctorDO();
        if(!doctors.isEmpty()){
            doctor = doctors.get(0);
        }else{
            return success("该身份证无法找到医生",-1);
        }
        //专家咨询
        result.put("zxCount",imService.sessionCountByType(doctor.getId(),1,0));
        result.put("fzCount",prescriptionService.getWaitVideoCount(doctor.getId(),"1","1"));//图文复诊数量
        return success("请求成功",result);
    }
}