Forráskód Böngészése

Merge branch 'dev' of trick9191/wlyy2.0 into dev

trick9191 5 éve
szülő
commit
026a0b2d50

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/mapping/service/PatientMappingService.java

@ -93,7 +93,7 @@ public class PatientMappingService {
            return mappingCode;
        }else{
            throw new RuntimeException("获取his居民信息失败!");
            return null;
        }
    }
}

+ 9 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -153,6 +153,9 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    public  List<WlyyOutpatientVO> findOutpatientList(String patient, String startTime, String endTime, boolean demoFlag)throws Exception{
        logger.info("findOutpatientList patient:"+patient);
        String patNo =patientMappingService.findHisPatNoByPatient(patient);
        if(StringUtils.isBlank(patNo)){
            return null;
        }
        logger.info("findOutpatientList patNo "+patNo);
        return entranceService.BS30025(patNo,null,startTime,endTime,demoFlag);
    }
@ -166,6 +169,9 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    public WlyyOutpatientVO findOutpatientInfo(String patient,String conNo)throws Exception{
        logger.info("findOutpatientList patient:"+patient);
        String patNo =patientMappingService.findHisPatNoByPatient(patient);
        if(StringUtils.isBlank(patNo)){
            return null;
        }
        logger.info("findOutpatientList patNo:"+patNo);
        List<WlyyOutpatientVO> list = entranceService.BS30025(patNo,conNo,null,null,demoFlag);
@ -184,6 +190,9 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     */
    public List<WlyyPrescriptionVO> findOriginPrescriptionList(String registerSn,String patient,String admNo,boolean demoFlag)throws Exception{
        String patNo =patientMappingService.findHisPatNoByPatient(patient);
        if(StringUtils.isBlank(patNo)){
            return null;
        }
        //BS16017(String REGISTER_SN,String realOrder,String PAT_NO,String ADM_NO,boolean demoFlag) throws Exception {
        logger.info("findOriginPrescriptionList: registerSn:"+registerSn+" patient"+patient+" patNo:"+patNo+" admNo:"+admNo);
        return entranceService.BS16017(registerSn,null,patNo,admNo,demoFlag);

+ 60 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/wlyyinfo/OauthWlyyConfigDO.java

@ -0,0 +1,60 @@
package com.yihu.jw.entity.wlyyinfo;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Trick on 2019/8/7.
 */
@Entity
@Table(name = "oauth_wlyy_config")
public class OauthWlyyConfigDO extends UuidIdentityEntity {
    private String appId;//appid',
    private String appSecret;//app秘钥',
    private String tokenUrl;//获取token接口地址',
    private String url;//获取基本信息接口地址',
    private String remark;//备注接口地址',
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    public String getAppSecret() {
        return appSecret;
    }
    public void setAppSecret(String appSecret) {
        this.appSecret = appSecret;
    }
    public String getTokenUrl() {
        return tokenUrl;
    }
    public void setTokenUrl(String tokenUrl) {
        this.tokenUrl = tokenUrl;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
}

+ 11 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/dao/OauthWlyyConfigDao.java

@ -0,0 +1,11 @@
package com.yihu.jw.security.dao;
import com.yihu.jw.entity.wlyyinfo.OauthWlyyConfigDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2019/8/7.
 */
public interface OauthWlyyConfigDao extends PagingAndSortingRepository<OauthWlyyConfigDO, String>, JpaSpecificationExecutor<OauthWlyyConfigDO> {
}

+ 26 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/dao/doctor/BaseDoctorDao.java

@ -0,0 +1,26 @@
package com.yihu.jw.security.dao.doctor;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 *
 * 医生基础信息 数据库访问层
 *
 * @version
 * <pre>
 * Author	Version		Date		Changes
 * litaohong 	1.0  		2018年08月31日 	Created
 *
 * </pre>
 * @since 1.
 */
public interface BaseDoctorDao extends PagingAndSortingRepository<BaseDoctorDO, String>, JpaSpecificationExecutor<BaseDoctorDO>  {
    BaseDoctorDO findById(String id);
    BaseDoctorDO findByIdcard(String idcard);
}

+ 29 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/dao/doctor/BaseDoctorHospitalDao.java

@ -0,0 +1,29 @@
package com.yihu.jw.security.dao.doctor;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface BaseDoctorHospitalDao extends PagingAndSortingRepository<BaseDoctorHospitalDO, Integer>, JpaSpecificationExecutor<BaseDoctorHospitalDO> {
    List<BaseDoctorHospitalDO> findByOrgCodeAndDoctorCode(String orgCode, String doctorCode);
    @Query("select id from BaseDoctorHospitalDO where doctorCode = ?1")
    Set<Object> findIdListByOrgCodeAndDoctorCode(String doctorCode);
    @Query(value = "select org_code as orgCode,org_name as orgName,doctor_duty_code as doctorDutyCode ,doctor_duty_name as doctorDutyName from base_doctor_hospital where doctor_code = ?1 GROUP BY orgCode ORDER BY orgName DESC",nativeQuery = true)
    List<Map<String,Object>> getOrgAndDutyByDoctorCode(String doctorCode);
    List<BaseDoctorHospitalDO> findByDoctorCode(String doctorCode);
    List<BaseDoctorHospitalDO> findByOrgCodeAndDeptCode(String orgCode, String deptCode);
    @Query("select bdo from BaseDoctorHospitalDO bdo where bdo.orgCode=?1 and bdo.deptCode=?2 and bdo.doctorCode = ?3 and bdo.del=1")
    List<BaseDoctorHospitalDO> findByOrgCodeAndDeptCodeAndDoctorCode(String orgCode, String deptCode, String doctorCode);
}

+ 30 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/dao/doctor/BaseDoctorRoleDao.java

@ -0,0 +1,30 @@
package com.yihu.jw.security.dao.doctor;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import java.util.Set;
/**
 * 
 * 医生与业务模块角色关联信息 数据库访问层
 * 
 * @version 
 * <pre>
 * Author	Version		Date		Changes
 * litaohong 	1.0  		2018年10月25日 	Created
 *
 * </pre>
 * @since 1.
 */
public interface BaseDoctorRoleDao extends PagingAndSortingRepository<BaseDoctorRoleDO, Integer>, JpaSpecificationExecutor<BaseDoctorRoleDO>  {
    @Query("select id from BaseDoctorRoleDO where doctorCode = ?1")
    Set<Object> findIdListByDoctorCode(String doctorCode);
    List<BaseDoctorRoleDO> findByDoctorCode(String doctorCode);
}

+ 70 - 2
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java

@ -14,6 +14,7 @@ import com.yihu.jw.security.model.*;
import com.yihu.jw.security.oauth2.core.redis.WlyyRedisVerifyCodeService;
import com.yihu.jw.security.oauth2.provider.WlyyTokenGranter;
import com.yihu.jw.security.oauth2.provider.error.WlyyOAuth2ExceptionTranslator;
import com.yihu.jw.security.service.OauthWlyyConfigService;
import com.yihu.jw.security.service.OauthYlzConfigService;
import com.yihu.jw.security.utils.SerializeUtil;
import com.yihu.utils.security.RSAUtils;
@ -69,7 +70,7 @@ import com.alibaba.fastjson.JSON;
 * </p>
 *
 * @author Progr1mmer
 * @created on 2018/8/29.
 * @created on 2018/8/29
 */
@RestController
public class WlyyLoginEndpoint extends AbstractEndpoint {
@ -103,6 +104,8 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    private OauthKeypairDao oauthKeypairDao;
    @Autowired
    private OauthYlzConfigService oauthYlzConfigService;
    @Autowired
    private OauthWlyyConfigService oauthWlyyConfigService;
    @PostConstruct
    private void init() {
@ -725,7 +728,72 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        baseLoginLogService.save(baseLoginLogDO);
        map.put("WlyyUserSimple",wlyyUserSimple);
        map.remove("patient");
        return ObjEnvelop.getSuccess("error",map);
        return ObjEnvelop.getSuccess("success",map);
    }
    /**
     * I健康医生端授权登录
     * @param code 医生code
     * @param client_id
     * @param login_type 3
     * @param httpSession
     * @return
     */
    @RequestMapping(value = "/oauth/checkWlyyLogin", method = RequestMethod.POST)
    public ObjEnvelop checkQRCodeLogin(String code,String client_id,String login_type,HttpSession httpSession){
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
        }
        if (StringUtils.isEmpty(code)) {
            throw new InvalidRequestException("doctor is null");
        }
        KeyPair keyPair = (KeyPair) httpSession.getAttribute("privateKey");
        String doctorCode = com.yihu.jw.security.utils.RSAUtils.decryptBase64(code, keyPair);
        JSONObject map = oauthWlyyConfigService.checkWlyyDoctor(doctorCode);
        String authCode = map.getString("authCode");
        if(!"1".equals(authCode)){
            return ObjEnvelop.getSuccess("error",map);
        }
        ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
        JSONObject doctor = map.getJSONObject("doctor");
        Map<String, String> parameters = new HashedMap();
        parameters.put("username",doctor.getString("idcard"));
        parameters.put("grant_type", "ihealthCode");
        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);
        map.put("WlyyUserSimple",wlyyUserSimple);
        map.remove("doctor");
        return ObjEnvelop.getSuccess("success",map);
    }
}

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

@ -0,0 +1,154 @@
package com.yihu.jw.security.service;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.jw.entity.wlyyinfo.OauthWlyyConfigDO;
import com.yihu.jw.security.dao.OauthWlyyConfigDao;
import com.yihu.jw.security.dao.doctor.BaseDoctorDao;
import com.yihu.jw.security.dao.doctor.BaseDoctorHospitalDao;
import com.yihu.jw.security.dao.doctor.BaseDoctorRoleDao;
import com.yihu.jw.security.utils.HttpClientUtil;
import com.yihu.utils.security.MD5;
import org.apache.commons.collections.map.HashedMap;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
 * Created by Trick on 2019/8/6.
 */
@Service
@Transactional
public class OauthWlyyConfigService {
    private static final Logger logger = LoggerFactory.getLogger(OauthWlyyConfigService.class);
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private OauthWlyyConfigDao oauthWlyyConfigDao;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private BaseDoctorHospitalDao baseDoctorHospitalDao;
    @Autowired
    private BaseDoctorRoleDao baseDoctorRoleDao;
    public JSONObject checkWlyyDoctor(String code){
        OauthWlyyConfigDO oauthWlyyConfigDO = oauthWlyyConfigDao.findOne("wlyyConfig");
        //token获取accesstoken
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("appid", oauthWlyyConfigDO.getAppId()));
        params.add(new BasicNameValuePair("appSecret", oauthWlyyConfigDO.getAppSecret()));
        String res = httpClientUtil.post(oauthWlyyConfigDO.getTokenUrl(),params,"UTF-8");
        String token = null;
        JSONObject rsjson = JSONObject.parseObject(res);
        logger.info("checkWlyyDoctor token :"+rsjson.toString());
        Integer status = rsjson.getInteger("status");
        if(status==10000){
            //设置入参
            List<NameValuePair> p = new ArrayList<>();
            p.add(new BasicNameValuePair("doctor", oauthWlyyConfigDO.getAppId()));
            //设置头部
            token = rsjson.getJSONObject("result").getString("accesstoken");
            Map<String,Object> headerMap = new HashedMap();
            headerMap.put("accesstoken",token);
            String rs = httpClientUtil.headerPost(oauthWlyyConfigDO.getUrl(),p,"UTF-8",headerMap);
            JSONObject auth = JSONObject.parseObject(rs);
            Integer s = auth.getInteger("status");
            logger.info("checkWlyyDoctor doctorInfo :"+s.toString());
            if(s == 200){
                JSONObject data = rsjson.getJSONObject("data");
                String authCode =  data.getString("authCode");
                if("1".equals(authCode)){
                    JSONObject doctorJson = data.getJSONObject("doctor");
                    String idcard = doctorJson.getString("idcard");
                    BaseDoctorDO doctorDO = baseDoctorDao.findByIdcard(idcard);
                    if(doctorDO!=null){
                        return data;
                    }else{
                        //存储医生全科医生信息
                        BaseDoctorDO doctor = new BaseDoctorDO();
                        doctor.setId(doctorJson.getString("code"));
                        doctor.setName(doctorJson.getString("name"));
                        doctor.setIdcard(doctorJson.getString("idcard"));
                        doctor.setMobile(doctorJson.getString("mobile"));
                        doctor.setSex(doctorJson.getInteger("sex"));
                        doctor.setBirthday(doctorJson.getDate("birthday"));
                        doctor.setProvinceCode(doctorJson.getString("province"));
                        doctor.setProvinceName(doctorJson.getString("provinceName"));
                        doctor.setCityCode(doctorJson.getString("city"));
                        doctor.setCityName(doctorJson.getString("cityName"));
                        //认证信息设置
                        String salt = randomString(5);
                        String pw = idcard.substring(idcard.length()-6);
                        MD5.md5Hex(pw + "{" + salt + "}");
                        doctor.setDel("1");
                        doctor.setEnabled(1);
                        doctor.setLocked(0);
                        doctor.setCreateTime(new Date());
                        baseDoctorDao.save(doctor);
                        //机构信息
                        BaseDoctorHospitalDO hospitalDO = new BaseDoctorHospitalDO();
                        hospitalDO.setDoctorCode(doctorJson.getString("code"));
                        hospitalDO.setOrgCode(doctorJson.getString("hospital"));
                        hospitalDO.setOrgName(doctorJson.getString("hospitalName"));
                        hospitalDO.setDel("1");
                        baseDoctorHospitalDao.save(hospitalDO);
                        BaseDoctorRoleDO role = new BaseDoctorRoleDO();
                        role.setDoctorCode(doctorJson.getString("code"));
                        role.setRoleCode("generalDoctor");
                        baseDoctorRoleDao.save(role);
                        return data;
                    }
                }else{
                    return data;
                }
            }else{
                //请求异常
                JSONObject data = new JSONObject();
                data.put("authCode","-2");
                return data;
            }
        }else {
            //请求异常
            JSONObject data = new JSONObject();
            data.put("authCode","-2");
            return data;
        }
    }
    public String randomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        StringBuffer buffer = new StringBuffer();
        Random random = new Random();
        for(int i = 0; i < length; ++i) {
            int pos = random.nextInt(str.length());
            buffer.append(str.charAt(pos));
        }
        return buffer.toString();
    }
}