소스 검색

中山医院

Trick 5 년 전
부모
커밋
a086a97c39

+ 13 - 0
business/base-service/src/main/java/com/yihu/jw/version/dao/AppVersionDao.java

@ -0,0 +1,13 @@
package com.yihu.jw.version.dao;
import com.yihu.jw.entity.base.version.AppVersionDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2020/2/24.
 */
public interface AppVersionDao extends PagingAndSortingRepository<AppVersionDO, Integer>, JpaSpecificationExecutor<AppVersionDO> {
    AppVersionDO findByCode(String code);
}

+ 21 - 0
business/base-service/src/main/java/com/yihu/jw/version/service/AppVersionService.java

@ -0,0 +1,21 @@
package com.yihu.jw.version.service;
import com.yihu.jw.entity.base.version.AppVersionDO;
import com.yihu.jw.version.dao.AppVersionDao;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created by Trick on 2020/2/24.
 */
@Service
public class AppVersionService extends BaseJpaService<AppVersionDO, AppVersionDao> {
    @Autowired
    private AppVersionDao appVersionDao;
    public AppVersionDO findVersionByCode(String code) {
        return appVersionDao.findByCode(code);
    }
}

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

@ -686,4 +686,13 @@ public class BaseHospitalRequestMapping {
        public static final String findWorkTimeInfo="/findWorkTimeInfo";
        public static final String findLevelOneDoctorUpcoming="/findLevelOneDoctorUpcoming";
    }
    /**
     * app升级
     */
    public static class Version extends Basic{
        public static final String PREFIX  = "/open/version";
        public static final String app="/app";
    }
}

+ 3 - 5
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/methlog/BaseMethodLogService.java

@ -1,7 +1,5 @@
package com.yihu.jw.gateway.methlog;
import com.yihu.jw.gateway.log.dao.*;
import com.yihu.jw.gateway.log.entity.*;
import com.yihu.jw.gateway.useragent.UserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -21,10 +19,10 @@ import java.util.Date;
@Transactional
public class BaseMethodLogService {
    private static final Logger logger = LoggerFactory.getLogger(com.yihu.jw.gateway.log.service.BaseMethodLogService.class);
    private static final Logger logger = LoggerFactory.getLogger(BaseMethodLogService.class);
    @Autowired
    private com.yihu.jw.gateway.log.dao.BaseMethodLogDao baseMethodLogDao;
    private BaseMethodLogDao baseMethodLogDao;
    @Autowired
    private UserAgent userAgent;
@ -35,7 +33,7 @@ public class BaseMethodLogService {
    public void saveMethodLog(HttpServletRequest request){
        try{
            logger.info("saveMethodLog");
            com.yihu.jw.gateway.log.entity.BaseMethodLogDO log = new com.yihu.jw.gateway.log.entity.BaseMethodLogDO();
            BaseMethodLogDO log = new BaseMethodLogDO();
            log.setUuid(userAgent.getUID());
            log.setName(userAgent.getUNAME());
            log.setIp(getIpAddress(request));

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

@ -19,8 +19,10 @@ 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.utils.AES;
import com.yihu.jw.security.utils.DateUtil;
import com.yihu.jw.security.utils.SerializeUtil;
import com.yihu.jw.sms.service.ZhongShanSMSService;
@ -65,6 +67,7 @@ import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URLDecoder;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.interfaces.RSAPrivateKey;
@ -124,6 +127,8 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    private ZhongShanSMSService zhongShanSMSService;
    @Autowired
    private OauthCaConfigSerivce oauthCaConfigSerivce;
    @Autowired
    private OauthWjwConfigService oauthWjwConfigService;
    @PostConstruct
@ -752,9 +757,80 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    }
    /**
     * 获取易联众授权码
     * 卫健委授权登录
     * @param authCode
     * @param client_id
     * @return
     */
    @RequestMapping(value = "/oauth/wjwLogin", method = RequestMethod.POST)
    public ObjEnvelop getWjwDecrypt(String authCode,String client_id) {
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
        }
        try {
            logger.info("authCode :"+authCode);
            String base64 = URLDecoder.decode(authCode,"UTF-8");
            logger.info("base64 :"+base64);
            //固定秘钥解密
            String key = "FEA5049E4CCD16A9";
            String data = AES.decrypt(key,base64);
            logger.info("wjwLogin :"+data);
            BasePatientDO patientDO = oauthWjwConfigService.savePatient(data);
            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("授权登录失败!");
    }
        /**
         * 获取易联众授权码
         * @return
         */
    @RequestMapping(value = "/oauth/getOauthQRCode", method = RequestMethod.GET)
    public ObjEnvelop getOauthQRCode(){
        logger.info("/oauth/getOauthQRCode");

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

@ -0,0 +1,100 @@
package com.yihu.jw.security.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.security.dao.patient.BasePatientDao;
import com.yihu.jw.security.utils.AES;
import com.yihu.jw.security.utils.IdCardUtil;
import com.yihu.utils.security.MD5;
import org.apache.commons.codec.binary.Base64;
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.net.URLDecoder;
import java.util.Date;
import java.util.UUID;
import org.springframework.util.Base64Utils;
/**
 * Created by Trick on 2020/2/24.
 */
@Service
@Transactional
public class OauthWjwConfigService {
    private Logger logger = LoggerFactory.getLogger(OauthWjwConfigService.class);
    @Autowired
    private BasePatientDao basePatientDao;
    public BasePatientDO savePatient(String data)throws Exception{
        logger.info("savePatient :"+data);
        if(StringUtils.isNotBlank(data)){
            JSONObject d = JSON.parseObject(data);
            logger.info("data:"+d.toString());
            JSONObject info = (JSONObject) d.get("data");
            logger.info("info:"+info.toString());
            String name = info.getString("userName");
            String cardNo = info.getString("cardNo");
            String cardType = info.getString("cardType");
            String userPhone = info.getString("userPhone");
            String userSex = info.getString("userSex");
            String userIdNo = info.getString("userIdNo");
            String dType = info.getString("dType");
            if(StringUtils.isNotBlank(userIdNo)){
                BasePatientDO basePatientDO = basePatientDao.findByIdcardAndDel(userIdNo,"1");
                if(basePatientDO!=null){
                    return basePatientDO;
                }
                BasePatientDO patient = new BasePatientDO();
                String salt = UUID.randomUUID().toString().substring(0,5);
                String pw = userIdNo.substring(userIdNo.length()-6);
                patient.setIdcard(userIdNo);
                patient.setName(name);
                patient.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                patient.setSalt(salt);
                patient.setMobile(userPhone);
                patient.setDel("1");
                patient.setEnabled(1);
                patient.setLocked(0);
                patient.setCreateTime(new Date());
                patient.setUpdateTime(new Date());
                patient.setBirthday(IdCardUtil.getBirthdayForIdcard(userIdNo));
                patient.setSex(Integer.parseInt(IdCardUtil.getSexForIdcard_new(userIdNo)));
                basePatientDao.save(patient);
                return basePatientDO;
            }
            return null;
        }
        return null;
    }
    public static void main(String arg[])throws Exception{
        String authCode ="KzR3c2ozVlhKQjMyZjJiL0ZQTWUxdENXNTk2YldKLzl4UnpzbnZUcWhnQXcrZVlVRnV6c1hHdHB1Z2dQWkpzclUyeStldmtaOXpGTg0KSklOcUlTZVVBRFN4Ulh1dTJ2eS9WNEl1OG9GSXJhRnpjMHRuVTdCbjBKVS9yWEhKbmphVEZOU0ZhT2ZtVEhUNE5oMXZDenVtMlErZw0KcFBBb1VXK1BhSUVIb2hjUFMrT3g5aEFTWnZRZSs3bndZS1NxMCtoL2FMa2FOQjVkWnpXRmluY2ZweGZSV1pQZk50SnEzNnZ0YmVYbQ0KUFdrVjRQMGlKeHNyMkwwaU43c0ZRUzRDN3RlMw==";
        String str = URLDecoder.decode(authCode,"UTF-8");
        String base64Sign = Base64Utils.encodeToString(str.getBytes());
        //固定秘钥解密
        String key = "FEA5049E4CCD16A9";
        String data = AES.decrypt(key,base64Sign);
        System.out.println(data);
    }
}

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

@ -0,0 +1,54 @@
package com.yihu.jw.security.utils;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.lang3.StringUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
 * Created by Trick on 2020/2/24.
 */
public class AES {
    //AES解密方法
    public static String decrypt(String strKey, String strIn) throws Exception {
        if(StringUtils.isEmpty(strKey)|| StringUtils.isEmpty(strIn)){
            return null;
        }
        try{
            SecretKeySpec skeySpec = getKey(strKey);
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes());
            cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
            BASE64Decoder base64de = new BASE64Decoder();
            byte[] encrypted1 = base64de.decodeBuffer(strIn);
            //byte[] encrypted1 =strIn.getBytes();
            byte[] original = cipher.doFinal(encrypted1);
            String originalString = new String(original,"UTF-8");
            return originalString;
        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    private static SecretKeySpec getKey(String strKey) throws Exception {
        byte[] arrBTmp = strKey.getBytes();
        byte[] arrB = new byte[16]; // 创建一个空的16位字节数组(默认值为0)
        for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
            arrB[i] = arrBTmp[i];
        }
        SecretKeySpec skeySpec = new SecretKeySpec(arrB, "AES");
        return skeySpec;
    }
}

+ 21 - 21
svr/svr-base/src/main/java/com/yihu/jw/base/dao/version/AppVersionDao.java

@ -1,21 +1,21 @@
package com.yihu.jw.base.dao.version;
import com.yihu.jw.entity.base.version.AppVersionDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * 
 * app版本号表 数据库访问层
 * 
 * @version 
 * <pre>
 * Author	Version		Date		Changes
 * litaohong 	1.0  		2018年09月07日 	Created
 *
 * </pre>
 * @since 1.
 */
public interface AppVersionDao extends PagingAndSortingRepository<AppVersionDO, Integer>, JpaSpecificationExecutor<AppVersionDO>  {
}
//package com.yihu.jw.base.dao.version;
//
//import com.yihu.jw.entity.base.version.AppVersionDO;
//import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
//import org.springframework.data.repository.PagingAndSortingRepository;
//
//
///**
// *
// * app版本号表 数据库访问层
// *
// * @version
// * <pre>
// * Author	Version		Date		Changes
// * litaohong 	1.0  		2018年09月07日 	Created
// *
// * </pre>
// * @since 1.
// */
//public interface AppVersionDao extends PagingAndSortingRepository<AppVersionDO, Integer>, JpaSpecificationExecutor<AppVersionDO>  {
//}

+ 1 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/version/AppVersionEndpoint.java

@ -1,6 +1,5 @@
package com.yihu.jw.base.endpoint.version;
import com.yihu.jw.base.service.version.AppVersionService;
import com.yihu.jw.entity.base.version.AppVersionDO;
import com.yihu.jw.restmodel.base.version.AppVersionVO;
import com.yihu.jw.restmodel.web.Envelop;
@ -9,6 +8,7 @@ import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.version.service.AppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

+ 22 - 22
svr/svr-base/src/main/java/com/yihu/jw/base/service/version/AppVersionService.java

@ -1,22 +1,22 @@
package com.yihu.jw.base.service.version;
import com.yihu.jw.base.dao.version.AppVersionDao;
import com.yihu.jw.entity.base.version.AppVersionDO;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.stereotype.Service;
/**
 * 
 * app版本号表服务service
 * 
 * @version 
 * <pre>
 * Author	Version		Date		Changes
 * litaohong    1.0  2018年09月07日 Created
 *
 * </pre>
 * @since 1.
 */
@Service
public class AppVersionService extends BaseJpaService<AppVersionDO, AppVersionDao> {
}
//package com.yihu.jw.base.service.version;
//
//import com.yihu.jw.base.dao.version.AppVersionDao;
//import com.yihu.jw.entity.base.version.AppVersionDO;
//import com.yihu.mysql.query.BaseJpaService;
//import org.springframework.stereotype.Service;
//
///**
// *
// * app版本号表服务service
// *
// * @version
// * <pre>
// * Author	Version		Date		Changes
// * litaohong    1.0  2018年09月07日 Created
// *
// * </pre>
// * @since 1.
// */
//@Service
//public class AppVersionService extends BaseJpaService<AppVersionDO, AppVersionDao> {
//}

+ 57 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/version/VersionEndpoint.java

@ -0,0 +1,57 @@
package com.yihu.jw.hospital.endpoint.version;
import com.yihu.jw.entity.base.version.AppVersionDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.version.service.AppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * Created by Trick on 2020/2/24.
 */
@RestController
@RequestMapping(value = BaseHospitalRequestMapping.Version.PREFIX)
@Api(value = "app升级", description = "app升级", tags = {"app升级"})
public class VersionEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private AppVersionService versionsService;
    /**
     * 校验APP版本号
     * @param code 版本类型编码
     * @param version 当前版本号
     * @return
     */
    @GetMapping(value = BaseHospitalRequestMapping.Version.app)
    @ApiOperation(value = "app升级")
    public Envelop appVersion(String code, double version) {
            AppVersionDO temp = versionsService.findVersionByCode(code);
            if (temp == null) {
                return Envelop.getError( "无效的APP类型失败!");
            }
            if (version > 0) {
                if (temp.getVersionInt() > version) {
                    // 有新的版本号
                    return success("发现新版本!", temp.getUrl());
                } else {
                    // 已是最新版本
                    return success("已是最新版本!");
                }
            } else {
                JSONObject json = new JSONObject();
                json.put("version_int", temp.getVersionInt());
                json.put("version_str", temp.getVersionStr());
                json.put("url", temp.getUrl());
                json.put("info", temp.getInfo());
                json.put("size", temp.getSize());
                return success("读取版本号成功!", json);
            }
    }
}