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

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

wangzhinan 5 éve
szülő
commit
62582e267e

+ 17 - 14
business/base-service/src/main/java/com/yihu/jw/internet/service/ykyy/YkyyInternetService.java

@ -506,29 +506,32 @@ public class YkyyInternetService extends BaseJpaService<InternetUpErrorLogDO, In
        int dataError = 0;
        String sql ="SELECT " +
                " i.id, " +
                " i.`code`, " +
                " i.dept, " +
                " o.doctor, " +
                " o.register_date, " +
                " i.create_time, " +
                " p.`name`, " +
                " p.idcard, " +
                " d.idcard AS doctorIdCard," +
                " p.mobile " +
                " i.id AS \"id\", " +
                " i.code AS \"code\", " +
                " o.dept AS \"dept\", " +
                " o.doctor AS \"doctor\", " +
                " o.register_date AS \"register_date\", " +
                " i.create_time AS \"create_time\", " +
                " p.name AS \"name\", " +
                " p.idcard AS \"idcard\", " +
                " d.idcard AS \"doctorIdCard\"" +
                "FROM " +
                " wlyy_inspection i " +
                " JOIN wlyy_outpatient o ON o.id = i.outpatient_id  " +
                " JOIN base_patient p ON p.id = o.patient " +
                " JOIN base_doctor d ON d.id = o.doctor " +
                "WHERE " +
                " i.create_time >='"+startDate+"' " +
                " and i.create_time <='"+endDate+"'" +
                " and i.dept is not null" +
                " i.dept is not null" +
                " and o.register_date is not null";
        if(StringUtils.isNotBlank(keyId)){
            sql +=" and i.id = '"+keyId+"'";
        }
        if(StringUtils.isNotBlank(startDate)){
            sql +=" and i.create_time >='"+startDate+"' ";
        }
        if(StringUtils.isNotBlank(endDate)){
            sql +=" and i.create_time <='"+endDate+"' ";
        }
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        if(list != null && list.size() > 0){
@ -554,7 +557,7 @@ public class YkyyInternetService extends BaseJpaService<InternetUpErrorLogDO, In
                    jb.put("ge_code", sex=="3"?"9":sex);
                    jb.put("card_type", "1");
                    jb.put("id_no", ins.get("idcard").toString());
                    jb.put("pt_tel", ins.get("mobile").toString());
                    jb.put("pt_tel", "00000000000");
                    jb.put("crt_date",DateUtil.dateToStrLong(DateUtil.getNow()));
                }catch (Exception e){
                    errorFlag = true;

+ 61 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/auth/OauthRsaKeyDO.java

@ -0,0 +1,61 @@
package com.yihu.jw.entity.auth;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Trick on 2020/3/10.
 */
@Entity
@Table(name = "oauth_rsa_key")
public class OauthRsaKeyDO extends UuidIdentityEntity{
    private String code;//第三方用户唯一标识',
    private String appId;//客户端唯一标识',
    private String publicKey;//公钥',
    private String privateKey;//私钥',
    private Date createTime;//创建时间',
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    public String getPublicKey() {
        return publicKey;
    }
    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }
    public String getPrivateKey() {
        return privateKey;
    }
    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}

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

@ -0,0 +1,15 @@
package com.yihu.jw.security.dao;
import com.yihu.jw.entity.auth.OauthRsaKeyDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Trick on 2020/3/10.
 */
public interface OauthRsaKeyDao extends PagingAndSortingRepository<OauthRsaKeyDO, String>, JpaSpecificationExecutor<OauthRsaKeyDO> {
    List<OauthRsaKeyDO> findByCodeAndAppId(String Code,String appId);
}

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

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import com.yihu.jw.entity.auth.OauthRsaKeyDO;
import com.yihu.jw.entity.base.login.BaseLoginLogDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
@ -18,10 +19,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.OauthCaConfigSerivce;
import com.yihu.jw.security.service.OauthWjwConfigService;
import com.yihu.jw.security.service.OauthWlyyConfigService;
import com.yihu.jw.security.service.OauthYlzConfigService;
import com.yihu.jw.security.service.*;
import com.yihu.jw.security.utils.AES;
import com.yihu.jw.security.utils.DateUtil;
import com.yihu.jw.security.utils.SerializeUtil;
@ -126,6 +124,8 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    private OauthCaConfigSerivce oauthCaConfigSerivce;
    @Autowired
    private OauthWjwConfigService oauthWjwConfigService;
    @Autowired
    private OauthSsoService oauthSsoService;
    @PostConstruct
@ -1085,4 +1085,83 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        }
        return pass;
    }
    @RequestMapping(value = "/oauth/getSsoPublicKey", method = RequestMethod.GET)
    @ApiOperation("获取通用公钥")
    public ObjEnvelop getSsoPublicKey(String code,String appId)throws Exception{
        return ObjEnvelop.getSuccess("success",oauthSsoService.getSsoPublic(code,appId));
    }
    @RequestMapping(value = "/oauth/test", method = RequestMethod.GET)
    @ApiOperation("test dd")
    public ObjEnvelop test()throws Exception{
        return ObjEnvelop.getSuccess("success",oauthSsoService.getAuthCode());
    }
    @RequestMapping(value = "/oauth/ssoPatientLogin", method = RequestMethod.POST)
    public ObjEnvelop ssoPatientLogin(String authCode,String client_id,String code,String appId,String login_type){
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
        }
        if (StringUtils.isEmpty(authCode)) {
            throw new InvalidRequestException("authCode is null");
        }
        if (StringUtils.isEmpty(code)) {
            throw new InvalidRequestException("code is null");
        }
        if (StringUtils.isEmpty(appId)) {
            throw new InvalidRequestException("appId is null");
        }
        try {
            logger.info("authCode :"+authCode);
            BasePatientDO patientDO = oauthSsoService.savePatient(code,appId,authCode);
            if(patientDO == null){
                return ObjEnvelop.getError("授权登录失败!");
            }
            ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
            Map<String, String> parameters = new HashedMap();
            parameters.put("username",patientDO.getIdcard());
            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);
            return ObjEnvelop.getSuccess("success",wlyyUserSimple);
        }catch (Exception e){
            logger.error(e);
        }
        return ObjEnvelop.getError("登录失败!");
    }
}

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

@ -0,0 +1,125 @@
package com.yihu.jw.security.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.auth.OauthRsaKeyDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.security.dao.OauthRsaKeyDao;
import com.yihu.jw.security.dao.patient.BasePatientDao;
import com.yihu.jw.security.utils.IdCardUtil;
import com.yihu.jw.security.utils.RSAEncrypt;
import com.yihu.utils.security.MD5;
import org.apache.commons.lang3.StringUtils;
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.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
 * Created by Trick on 2020/3/10.
 */
@Service
@Transactional
public class OauthSsoService {
    Logger logger = LoggerFactory.getLogger(OauthSsoService.class);
    @Autowired
    private OauthRsaKeyDao rsaKeyDao;
    @Autowired
    private BasePatientDao basePatientDao;
    public String getAuthCode()throws Exception{
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name","测试用户");
        jsonObject.put("idcard","350600456789456123");
        jsonObject.put("mobile","15426852352");
        String authCode = jsonObject.toJSONString();
        logger.info("authCode:"+authCode);
        String publicKey = getSsoPublic("1", "appid");
        String jm = RSAEncrypt.encrypt(authCode,publicKey);
        return jm;
    }
    public String getSsoPublic(String code,String appId)throws Exception{
        /**
         * 删除之前秘钥
         */
        List<OauthRsaKeyDO> oauthRsaKeyDOs = rsaKeyDao.findByCodeAndAppId(code,appId);
        if(oauthRsaKeyDOs!=null&&oauthRsaKeyDOs.size()>0){
            rsaKeyDao.delete(oauthRsaKeyDOs);
        }
        /**
         * 生成新的秘钥
         */
        OauthRsaKeyDO oauthRsaKeyDO = new OauthRsaKeyDO();
        Map<Integer, String> key  = RSAEncrypt.genKeyPair();
        oauthRsaKeyDO.setCode(code);
        oauthRsaKeyDO.setAppId(appId);
        oauthRsaKeyDO.setPublicKey(key.get(0));
        oauthRsaKeyDO.setPrivateKey(key.get(1));
        oauthRsaKeyDO.setCreateTime(new Date());
        rsaKeyDao.save(oauthRsaKeyDO);
        return oauthRsaKeyDO.getPublicKey();
    }
    public BasePatientDO savePatient(String code,String appId,String authCode)throws Exception{
        String jsonStr = decrypt(code,appId,authCode);
        JSONObject info = JSON.parseObject(jsonStr);
        String name = info.getString("name");
        String idcard = info.getString("idcard");
        String mobile = info.getString("mobile");
        if(StringUtils.isNotBlank(idcard)){
            BasePatientDO basePatientDO = basePatientDao.findByIdcardAndDel(idcard,"1");
            if(basePatientDO!=null){
                return basePatientDO;
            }
            BasePatientDO patient = new BasePatientDO();
            String salt = UUID.randomUUID().toString().substring(0,5);
            String pw = idcard.substring(idcard.length()-6);
            patient.setIdcard(idcard);
            patient.setName(name);
            patient.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
            patient.setSalt(salt);
            patient.setMobile(mobile);
            patient.setDel("1");
            patient.setEnabled(1);
            patient.setLocked(0);
            patient.setCreateTime(new Date());
            patient.setUpdateTime(new Date());
            patient.setBirthday(IdCardUtil.getBirthdayForIdcard(idcard));
            patient.setSex(Integer.parseInt(IdCardUtil.getSexForIdcard_new(idcard)));
            basePatientDao.save(patient);
            return basePatientDO;
        }
        return null;
    }
    public String decrypt(String code,String appId,String authCode)throws Exception{
        List<OauthRsaKeyDO> oauthRsaKeyDOs = rsaKeyDao.findByCodeAndAppId(code,appId);
        OauthRsaKeyDO oauthRsaKeyDO = oauthRsaKeyDOs.get(0);
        String str = RSAEncrypt.decrypt(authCode,oauthRsaKeyDO.getPrivateKey());
        logger.info("decrypt : "+str);
        return  str;
    }
}

+ 101 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/utils/RSAEncrypt.java

@ -0,0 +1,101 @@
package com.yihu.jw.security.utils;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;
public class RSAEncrypt {
    /**
     * 随机生成密钥对
     * @throws NoSuchAlgorithmException
     */
    public static Map<Integer, String> genKeyPair() throws NoSuchAlgorithmException {
        Map<Integer, String> keyMap = new HashMap<Integer, String>();
        // KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象
        KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
        // 初始化密钥对生成器,密钥大小为96-1024位
        keyPairGen.initialize(1024,new SecureRandom());
        // 生成一个密钥对,保存在keyPair中
        KeyPair keyPair = keyPairGen.generateKeyPair();
        RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();   // 得到私钥
        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();  // 得到公钥
        String publicKeyString = new String(Base64.encodeBase64(publicKey.getEncoded()));
        // 得到私钥字符串
        String privateKeyString = new String(Base64.encodeBase64((privateKey.getEncoded())));
        // 将公钥和私钥保存到Map
        keyMap.put(0,publicKeyString);  //0表示公钥
        keyMap.put(1,privateKeyString);  //1表示私钥
        return keyMap;
    }
    /**
     * RSA公钥加密
     *
     * @param str
     *            加密字符串
     * @param publicKey
     *            公钥
     * @return 密文
     * @throws Exception
     *             加密过程中的异常信息
     */
    public static String encrypt( String str, String publicKey) throws Exception{
        //base64编码的公钥
        byte[] decoded = Base64.decodeBase64(publicKey);
        RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
        //RSA加密
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, pubKey);
        String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8")));
        return outStr;
    }
    /**
     * RSA私钥解密
     *
     * @param str
     *            加密字符串
     * @param privateKey
     *            私钥
     * @return 铭文
     * @throws Exception
     *             解密过程中的异常信息
     */
    public static String decrypt(String str, String privateKey) throws Exception{
        //64位解码加密后的字符串
        byte[] inputByte = Base64.decodeBase64(str.getBytes("UTF-8"));
        //base64编码的私钥
        byte[] decoded = Base64.decodeBase64(privateKey);
        RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded));
        //RSA解密
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.DECRYPT_MODE, priKey);
        String outStr = new String(cipher.doFinal(inputByte));
        return outStr;
    }
//    public static void main(String[] args) throws Exception {
//        //生成公钥和私钥
//        Map<Integer, String> keyMap = genKeyPair();
//        //加密字符串
//        String message = "test";
//        System.out.println("随机生成的公钥为:" + keyMap.get(0));
//        System.out.println("随机生成的私钥为:" + keyMap.get(1));
//        String messageEn = encrypt(message,keyMap.get(0));
//        System.out.println(message + "\t加密后的字符串为:" + messageEn);
//        String messageDe = decrypt(messageEn,keyMap.get(1));
//        System.out.println("还原后的字符串为:" + messageDe);
//    }
}

+ 4 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/web/quota/JobController.java

@ -409,6 +409,10 @@ public class JobController extends BaseController {
                    //语句
                    ykyyInternetService.upAppointmentOnline(null,null,null);
                    break; //可选
                case "2.6" :
                    //语句
                    ykyyInternetService.upMedicalOnline(null,null,null);
                    break; //可选
                case "2.7" :
                    //语句
                    ykyyInternetService.upNsDoctorScore(null,null,null);

+ 34 - 1
svr/svr-internet-hospital-job/src/main/resources/application.yml

@ -104,7 +104,7 @@ wlyy:
  url: http://www.xmtyw.cn/wlyytest/
---
spring:
  profiles: jwOracleProd
  profiles: jwOracleTest
  datasource:
    driver-class-name: oracle.jdbc.driver.OracleDriver
    url: jdbc:oracle:thin:@172.26.0.141:1521:helowin
@ -117,6 +117,39 @@ spring:
        show_sql: true
    database: oracle
hlwyyEntrance:
  url: http://172.16.1.42:10023
# mq 是否获取his数据,flag代表获取演示数据,false代表获取his真实数据
demo:
  flag: false
hospital:
  url: https://wx.xmzsh.com
  mqUser: JKZL
  mqPwd: 123456
  SourceSysCode: S60
  TargetSysCode: S01
im:
  im_list_get: http://172.26.0.105:3000/
  data_base_name: im_internet_hospital
fastDFS:
  fastdfs_file_url: http://172.26.0.110:8888/
wlyy:
  url: http://www.xmtyw.cn/wlyytest/
---
spring:
  profiles: jwOracleProd
  datasource:
    driver-class-name: oracle.jdbc.driver.OracleDriver
    url: jdbc:oracle:thin:@192.168.20.55:1521:orcl
    username: system
    password: hxyk9573
  jpa:
    properties:
      hibernate:
        dialect: org.hibernate.dialect.Oracle10gDialect
        show_sql: true
    database: oracle
hlwyyEntrance:
  url: http://172.16.1.42:10023
# mq 是否获取his数据,flag代表获取演示数据,false代表获取his真实数据

+ 7 - 0
svr/svr-internet-hospital-job/src/main/resources/bootstrap.yml

@ -23,6 +23,13 @@ spring:
      uri: ${wlyy.spring.config.uri:http://172.26.0.107:1221}
      label: ${wlyy.spring.config.label:jwdev}
---
spring:
  profiles: jwOracleTest
  cloud:
    config:
      uri: ${wlyy.spring.config.uri:http://172.26.0.107:1221}
      label: ${wlyy.spring.config.label:jwdev}
---
spring:
  profiles: jwOracleProd
  cloud:

+ 0 - 14
svr/svr-internet-hospital-job/src/main/resources/system.properties

@ -7,17 +7,3 @@ prescription_overdue_job=0 0 1 * * ?
#每天13 点触发
data_upload_job=0 0 2 * * ?
#data_upload_25_job=0 0 1 * * ?
#
#data_upload_26_job=0 0 1 * * ?
#
#data_upload_27_job=0 0 1 * * ?
#
#data_upload_28_job=0 0 1 * * ?
#
#data_upload_29_job=0 0 1 * * ?
#
#data_upload_210_job=0 0 1 * * ?
#
#data_upload_211_job=0 0 1 * * ?