Browse Source

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

trick9191 5 years ago
parent
commit
44ed84a770

+ 6 - 1
business/base-service/pom.xml

@ -121,7 +121,12 @@
            <version>2.5.0</version>
        </dependency>
        <!-- webService end -->
        <!-- 易联众工具-->
        <dependency>
            <groupId>com.ylz.loginsdk</groupId>
            <artifactId>ehcsdk</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
    <build>

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

@ -1,5 +1,6 @@
package com.yihu.jw.hospital.prescription.service;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.dict.dao.DictHospitalDeptDao;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
@ -20,6 +21,7 @@ import com.yihu.jw.entity.hospital.doctor.WlyyPatientRegisterTimeDO;
import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.prescription.*;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.hospital.consult.dao.HospitalWaitingRoomDao;
import com.yihu.jw.hospital.dict.WlyyChargeDictDao;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
@ -38,14 +40,20 @@ import com.yihu.jw.restmodel.base.org.BaseOrgVO;
import com.yihu.jw.restmodel.hospital.consult.WlyyHospitalSysDictVO;
import com.yihu.jw.restmodel.hospital.doctor.WlyyDoctorWorkTimeVO;
import com.yihu.jw.restmodel.hospital.prescription.*;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.util.security.Code16;
import com.yihu.jw.util.security.MD5;
import com.yihu.mysql.query.BaseJpaService;
import com.ylzinfo.ehc.EhcHandler;
import com.ylzinfo.ehc.common.utils.DateUtils;
import com.ylzinfo.ehc.trans.TransRequest;
import com.ylzinfo.ehc.trans.TransResponse;
import jxl.write.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@ -60,8 +68,10 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ErrorHandler;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.Boolean;
import java.util.*;
@ -2384,50 +2394,65 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        return rs;
    }
    @Autowired
    private HttpClientUtil httpClientUtil;
    public String test() {
        /**
         * http://www.mstpay.com:1811/ehcService/gateway.do
         public String app_id = "1BQA48ETK000A718A8C000001FFAA482";
         public String app_key = "1BQA48ETK001A718A8C00000FE996B9B";
         public String term_id = "35020010001";
         */
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("method", "ehc.ehealthcard.authurl"));
        params.add(new BasicNameValuePair("app_id", "1BQA48ETK000A718A8C000001FFAA482"));
        params.add(new BasicNameValuePair("term_id", "35020010001"));
        params.add(new BasicNameValuePair("version","X.M.0.1"));
        params.add(new BasicNameValuePair("timestamp", DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss")));
        params.add(new BasicNameValuePair("sign_type", "MD5"));
        params.add(new BasicNameValuePair("sign", getSign()));
        params.add(new BasicNameValuePair("enc_type","AES"));
        params.add(new BasicNameValuePair("biz_content", ""));
        String res = httpClientUtil.post("http://www.mstpay.com:1811/ehcService/gateway.do", params, "UTF-8");
        return res;
//        com.alibaba.fastjson.JSONObject jsonObject=new com.alibaba.fastjson.JSONObject();
//        jsonObject.put("openId","o0hubt3byGmNYLyC-UvmSVyUuZkI");
//        String responseMsg =httpClientUtil.sendPost("https://wx.xmzsh.com/interface/getUserInfoByOpenId.htm",jsonObject.toString());
//        com.alibaba.fastjson.JSONObject object1 = com.alibaba.fastjson.JSONObject.parseObject(responseMsg);
//        return object1.toString();
    }
    public String getSign(){
        String str ="app_id=1BQA48ETK000A718A8C000001FFAA482" +
                "&enc_type=AES" +
                "&method=ehc.ehealthcard.authurl" +
                "&sign_type=MD5" +
                "&term_id=35020010001" +
                "&timestamp=" +DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss")+
                "&version=X.M.0.1key=<你的密钥>";
        String md5str =  MD5.GetMD5Code(str);
        String str16 = Code16.toStringHex1(md5str);
        return str16.substring(0,16).toUpperCase();
    private FileUploadService fileUploadService;
    public Map<String,Object> test() {
        try {
            TransRequest e = new TransRequest();
            e.setMethod("ehc.ehealthcard.authurl");
            e.setApp_id("1BQA48ETK000A718A8C000001FFAA482");
            e.setTerm_id("35020010001");
            e.setVersion("X.M.0.1");
            e.setTimestamp(DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"));
            e.setSign_type("MD5");
            e.setEnc_type("AES");
            com.alibaba.fastjson.JSONObject bizContent = new com.alibaba.fastjson.JSONObject();
            String no = UUID.randomUUID().toString().substring(0,30);
            bizContent.put("out_authorize_no", no);
            bizContent.put("out_authorize_time", DateUtils.getOutTradeTime());
            e.setBiz_content(JSON.toJSONString(bizContent));
            EhcHandler ehcHandler = new EhcHandler("http://www.mstpay.com:1811/ehcService/gateway.do", "1BQA48ETK000A718A8C000001FFAA482", "35020010001", "1BQA48ETK001A718A8C00000FE996B9B");
            TransResponse re = ehcHandler.execute(e);
            String rs = com.alibaba.fastjson.JSONObject.toJSONString(re);
            com.alibaba.fastjson.JSONObject json = (com.alibaba.fastjson.JSONObject) com.alibaba.fastjson.JSONObject.parse(rs);
            com.alibaba.fastjson.JSONObject biz = json.getJSONObject("biz_content");
            InputStream qrcode = QrcodeUtil.createQrcode(biz.getString("ehealth_authurl"),300,"jpg");
            UploadVO uploadVO = fileUploadService.uploadStream(qrcode,"qrcode.jpg","http://172.26.0.110:8888/");
            Map<String,Object> map = new HashedMap();
            map.put("fileName",uploadVO.getFileName());
            map.put("fileType",uploadVO.getFileType());
            map.put("fullUrl",uploadVO.getFullUrl());
            map.put("fullUri",uploadVO.getFullUri());
            map.put("out_authorize_no",no);
            return map;
        } catch (Exception var5) {
            var5.printStackTrace();
        }
        return null;
    }
    public String test2(String no) throws Exception{
        TransRequest e = new TransRequest();
        e.setMethod("ehc.ehealthcard.auth.query");
        e.setApp_id("1BQA48ETK000A718A8C000001FFAA482");
        e.setTerm_id("35020010001");
        e.setVersion("X.M.0.1");
        e.setTimestamp(DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"));
        e.setSign_type("MD5");
        e.setEnc_type("AES");
        com.alibaba.fastjson.JSONObject bizContent = new com.alibaba.fastjson.JSONObject();
        bizContent.put("out_authorize_no", no);
        bizContent.put("out_authorize_time", DateUtils.getOutTradeTime());
        e.setBiz_content(JSON.toJSONString(bizContent));
        EhcHandler ehcHandler = new EhcHandler("http://www.mstpay.com:1811/ehcService/gateway.do", "1BQA48ETK000A718A8C000001FFAA482", "35020010001", "1BQA48ETK001A718A8C00000FE996B9B");
        TransResponse re = ehcHandler.execute(e);
        String rs = com.alibaba.fastjson.JSONObject.toJSONString(re);
        return rs;
    }
    
    /**
     * 获取正在进行中的视频复诊/协同门诊

+ 78 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/ylzinfo/OauthYlzConfigDO.java

@ -0,0 +1,78 @@
package com.yihu.jw.entity.ylzinfo;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Trick on 2019/7/26.
 */
@Entity
@Table(name = "oauth_ylz_config")
public class OauthYlzConfigDO extends UuidIdentityEntity {
    private String appId;
    private String appKey;
    private String termId;
    private String version;
    private String signType;
    private String encType;
    private String url;
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    public String getAppKey() {
        return appKey;
    }
    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }
    public String getTermId() {
        return termId;
    }
    public void setTermId(String termId) {
        this.termId = termId;
    }
    public String getVersion() {
        return version;
    }
    public void setVersion(String version) {
        this.version = version;
    }
    public String getSignType() {
        return signType;
    }
    public void setSignType(String signType) {
        this.signType = signType;
    }
    public String getEncType() {
        return encType;
    }
    public void setEncType(String encType) {
        this.encType = encType;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
}

+ 21 - 0
server/svr-authentication/pom.xml

@ -114,6 +114,27 @@
            <version>2.0.0</version>
        </dependency>
        <!-- 易联众工具-->
        <dependency>
            <groupId>com.ylz.loginsdk</groupId>
            <artifactId>ehcsdk</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>fastdfs-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>javase</artifactId>
            <version>RELEASE</version>
        </dependency>
    </dependencies>
    <build>

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

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

+ 45 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/dao/patient/BasePatientDao.java

@ -0,0 +1,45 @@
package com.yihu.jw.security.dao.patient;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import org.springframework.data.domain.Pageable;
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;
/**
 * Created by Trick on 2018/8/31.
 */
public interface BasePatientDao extends PagingAndSortingRepository<BasePatientDO, String>, JpaSpecificationExecutor<BasePatientDO> {
    BasePatientDO findById(String id);
    BasePatientDO findByIdcardAndDel(String Idcard, String del);
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,mobile as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO where idcard like ?1")
    List<Map<String,Object>> findByIdcard(String idcard, Pageable pageable);
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,mobile as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO where name like ?1")
    List<Map<String,Object>> findByName(String name, Pageable pageable);
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,mobile as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO")
    List<Map<String,Object>> findBaseInfo(Pageable pageable);
    boolean existsByIdcardAndIdNotAndDel(String idcard, String id, String del);
    boolean existsByIdcardAndDel(String idcard, String del);
    @Query("from BasePatientDO where mobile = ?1")
    List<BasePatientDO> findByMobile(String mobile);
    @Query("from BasePatientDO p where p.mobile = ?1 and p.del=?2")
    List<BasePatientDO> findByMobileAndDel(String mobile, String del);
//    @Modifying
//    @Query(" update BasePatientDO a set a.openid=?2 where a.id=?1 ")
//    int updateOpenId(String id, String openId);
    BasePatientDO findByIdAndDel(String id, String del);
}

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

@ -3,6 +3,8 @@ package com.yihu.jw.security.oauth2.provider.endpoint;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.entity.base.login.BaseLoginLogDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
import com.yihu.jw.restmodel.ResultStatus;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.security.core.userdetails.jdbc.WlyyUserDetailsService;
@ -12,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.OauthYlzConfigService;
import com.yihu.jw.security.utils.SerializeUtil;
import com.yihu.utils.security.RSAUtils;
import org.apache.commons.collections.map.HashedMap;
@ -98,6 +101,8 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    private BaseLoginLogService baseLoginLogService;
    @Autowired
    private OauthKeypairDao oauthKeypairDao;
    @Autowired
    private OauthYlzConfigService oauthYlzConfigService;
    @PostConstruct
    private void init() {
@ -112,7 +117,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
     *                    captcha 验证码
     *                    password 密码
     *                    username 用户名/手机/身份证号
     *                    login_type 用户类型 1或默认为user,2:医生登录,3:患者登录,4:第三方同步账号登录
     *                    login_type 用户类型 1或默认为user,2:医生登录,3:患者登录,4:第三方同步账号登录,5.易联众居民健康卡授权登录
     * @param httpSession
     * @return
     * @throws Exception
@ -663,4 +668,64 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        }
        return ObjEnvelop.getSuccess("success", rs);
    }
    /**
     * 获取易联众授权码
     * @return
     */
    @RequestMapping(value = "/oauth/getOauthQRCode", method = RequestMethod.GET)
    public ObjEnvelop getOauthQRCode(){
        return ObjEnvelop.getSuccess("success", oauthYlzConfigService.getOauthQRCode());
    }
    @RequestMapping(value = "/oauth/checkQRCodeLogin", method = RequestMethod.POST)
    public ObjEnvelop checkQRCodeLogin(String no,String client_id,String login_type){
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
        }
        Map<String,Object> map = oauthYlzConfigService.checkOauthQRCode(no);
        String sCode = (String)map.get("sCode");
        if(!"succ".equals(sCode)){
            return ObjEnvelop.getSuccess("error",map);
        }
        BasePatientDO patient = (BasePatientDO)map.get("patient");
        ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
        Map<String, String> parameters = new HashedMap();
        parameters.put("username",patient.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);
        map.put("WlyyUserSimple",wlyyUserSimple);
        map.remove("patient");
        return ObjEnvelop.getSuccess("error",map);
    }
}

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

@ -0,0 +1,192 @@
package com.yihu.jw.security.service;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.exception.business.file_upload.*;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import org.apache.commons.lang3.StringUtils;
import org.csource.common.MyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
/**
 * 文件上传服务
 */
@Service
public class FileUploadService {
    @Autowired
    private FastDFSUtil fastDFSHelper;
    /**
     * 文件流上传图片
     * @param inputStream
     * @param originalFileName
     * @return
     * @throws Exception
     */
    public UploadVO uploadImg(InputStream inputStream, String originalFileName,long fileSize,String fastdfs_file_url) throws NoSuchAlgorithmException, IOException, MyException {
        // 得到文件的完整名称  xxx.txt
        if( null == inputStream){
            throw new FileInputStreamEmptyException("图片文件流不可为空!");
        }
        if(StringUtils.isBlank(originalFileName)){
            throw new FileNameEmptyException("图片文件名不可为空!");
        }
        if(StringUtils.isBlank(fastdfs_file_url)){
            throw new FastfdsFileURLEmptyException("fastdfs url不可为空!");
        }
        //得到文件类型
        String fileType = originalFileName.substring(originalFileName.lastIndexOf(".") + 1).toLowerCase();
        if(StringUtils.isBlank(fileType)||!"jpg,jpeg,png".contains(fileType)){
            throw new FileWrongFormatException("图片文件格式不正确,请上传jpg,jpeg,png等任一格式!");
        }
        long max = 5*1024*1024;
        if(fileSize > max){
            throw new FileTooLargeSizeException("图片文件过大,请不要超过5M!");
        }
        String fileName = originalFileName.substring(0, originalFileName.lastIndexOf("."));
        //上传到fastdfs
        ObjectNode objectNode = fastDFSHelper.upload(inputStream, fileType, "");
        //解析返回的objectNode
        UploadVO uploadVO = new UploadVO();
        uploadVO.setFileName(fileName);
        uploadVO.setFileType(fileType);
        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
        return uploadVO;
    }
     /*
     * 文件流上传附件
     * @param file
     * @return
     * @throws Exception
     */
    public UploadVO uploadAttachment(InputStream inputStream, String originalFileName,long fileSize,String fastdfs_file_url) throws Exception{
        // 得到文件的完整名称  xxx.txt
        if( null == inputStream){
            throw new FileInputStreamEmptyException("附件文件流不可为空!");
        }
        if(StringUtils.isBlank(originalFileName)){
            throw new FileNameEmptyException("图片文件名不可为空!");
        }
        if(StringUtils.isBlank(fastdfs_file_url)){
            throw new FastfdsFileURLEmptyException("fastdfs url不可为空!");
        }
        //得到文件类型
        String fileType = originalFileName.substring(originalFileName.lastIndexOf(".") + 1).toLowerCase();
        if(StringUtils.isBlank(fileType)||!"doc、docx、pdf、xls、xlsx、jpg、jpeg、png".contains(fileType)){
            throw new FileWrongFormatException("附件文件格式不正确,请上传doc、docx、pdf、xls、xlsx、jpg、jpeg、png等任一格式!");
        }
        long max = 5*1024*1024;
        if(fileSize > max){
            throw new FileTooLargeSizeException("附件文件过大,请不要超过5M!");
        }
        String fileName = originalFileName.substring(0, originalFileName.lastIndexOf("."));
        //上传到fastdfs
        ObjectNode objectNode = fastDFSHelper.upload(inputStream, fileType, "");
        //解析返回的objectNode
        UploadVO uploadVO = new UploadVO();
        uploadVO.setFileName(fileName);
        uploadVO.setFileType(fileType);
        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
        return uploadVO;
    }
    /*
     * 文件流上传文件
     * @param file
     * @return
     * @throws Exception
     */
    public UploadVO uploadStream(InputStream inputStream, String originalFileName,String fastdfs_file_url) throws Exception{
        if( null == inputStream){
            throw new FileInputStreamEmptyException("文件内容不可为空!");
        }
        if(StringUtils.isBlank(originalFileName)){
            throw new FileNameEmptyException("文件名不可为空!");
        }
        if(StringUtils.isBlank(fastdfs_file_url)){
            throw new FastfdsFileURLEmptyException("fastdfs url不可为空!");
        }
        //得到文件类型
        String fileType = originalFileName.substring(originalFileName.lastIndexOf(".") + 1).toLowerCase();
        String fileName = originalFileName.substring(0, originalFileName.lastIndexOf("."));
        //上传到fastdfs
        ObjectNode objectNode = fastDFSHelper.upload(inputStream, fileType, "");
        //解析返回的objectNode
        UploadVO uploadVO = new UploadVO();
        uploadVO.setFileName(fileName);
        uploadVO.setFileType(fileType);
        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
        return uploadVO;
    }
    /*
     * base64上传图片
     * @param jsonData,头像转化后的输入流
     * @return
     * @throws Exception
     */
    public UploadVO uploadImages(String jsonData,String fastdfs_file_url) throws Exception {
        if(StringUtils.isBlank(jsonData)){
            throw new FileInputStreamEmptyException("图片的base64文件文件流不可为空!");
        }
        if(StringUtils.isBlank(fastdfs_file_url)){
            throw new FastfdsFileURLEmptyException("fastdfs url不可为空!");
        }
        String date = URLDecoder.decode(jsonData,"UTF-8");
        String[] fileStreams = date.split(",");
        String is = URLDecoder.decode(fileStreams[1],"UTF-8").replace(" ","+");
        byte[] in = Base64.getDecoder().decode(is);
        String pictureName = fileStreams[0].substring(0,fileStreams[0].length()-1);
        String fileExtension = pictureName.substring(pictureName.lastIndexOf(".") + 1).toLowerCase();
        String description = null;
        if ((pictureName != null) && (pictureName.length() > 0)) {
            int dot = pictureName.lastIndexOf('.');
            if ((dot > -1) && (dot < (pictureName.length()))) {
                description = pictureName.substring(0, dot);
            }
        }
        InputStream inputStream = new ByteArrayInputStream(in);
        ObjectNode objectNode = fastDFSHelper.upload(inputStream, "png", "");
        String groupName = objectNode.get("groupName").toString();
        String remoteFileName = objectNode.get("remoteFileName").toString();
        //解析返回的objectNode
        UploadVO uploadVO = new UploadVO();
        uploadVO.setFileName(remoteFileName);
        uploadVO.setFileType(groupName);
        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
        //返回文件路径
        return uploadVO;
    }
}

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

@ -0,0 +1,162 @@
package com.yihu.jw.security.service;
import com.alibaba.fastjson.JSON;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.security.dao.OauthYlzConfigDao;
import com.yihu.jw.security.dao.patient.BasePatientDao;
import com.yihu.jw.security.utils.DateUtil;
import com.yihu.jw.security.utils.QrcodeUtil;
import com.yihu.utils.security.MD5;
import com.ylzinfo.ehc.EhcHandler;
import com.ylzinfo.ehc.common.utils.DateUtils;
import com.ylzinfo.ehc.trans.TransRequest;
import com.ylzinfo.ehc.trans.TransResponse;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
/**
 * Created by Trick on 2019/7/26.
 */
@Service
public class OauthYlzConfigService {
    @Autowired
    private OauthYlzConfigDao oauthYlzConfigDao;
    @Autowired
    private FileUploadService fileUploadService;
    @Autowired
    private BasePatientDao basePatientDao;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    public Map<String,Object> getOauthQRCode(){
        OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findOne("ylz_config");
        try {
            TransRequest e = new TransRequest();
            e.setMethod("ehc.ehealthcard.authurl");
            e.setApp_id(oauthYlzConfigDO.getAppId());
            e.setTerm_id(oauthYlzConfigDO.getTermId());
            e.setVersion(oauthYlzConfigDO.getVersion());
            e.setTimestamp(DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"));
            e.setSign_type(oauthYlzConfigDO.getSignType());
            e.setEnc_type(oauthYlzConfigDO.getEncType());
            com.alibaba.fastjson.JSONObject bizContent = new com.alibaba.fastjson.JSONObject();
            String no = UUID.randomUUID().toString().substring(0,30);
            bizContent.put("out_authorize_no", no);
            bizContent.put("out_authorize_time", DateUtils.getOutTradeTime());
            e.setBiz_content(JSON.toJSONString(bizContent));
            EhcHandler ehcHandler = new EhcHandler(oauthYlzConfigDO.getUrl(), oauthYlzConfigDO.getAppId(), oauthYlzConfigDO.getTermId(), oauthYlzConfigDO.getAppKey());
            TransResponse re = ehcHandler.execute(e);
            String rs = com.alibaba.fastjson.JSONObject.toJSONString(re);
            com.alibaba.fastjson.JSONObject json = (com.alibaba.fastjson.JSONObject) com.alibaba.fastjson.JSONObject.parse(rs);
            com.alibaba.fastjson.JSONObject biz = json.getJSONObject("biz_content");
            InputStream qrcode = QrcodeUtil.createQrcode(biz.getString("ehealth_authurl"),300,"jpg");
            UploadVO uploadVO = fileUploadService.uploadStream(qrcode,"qrcode.jpg",fastdfs_file_url);
            Map<String,Object> map = new HashedMap();
            map.put("fileName",uploadVO.getFileName());
            map.put("fileType",uploadVO.getFileType());
            map.put("fullUrl",uploadVO.getFullUrl());
            map.put("fullUri",uploadVO.getFullUri());
            map.put("out_authorize_no",no);
            return map;
        } catch (Exception var5) {
            var5.printStackTrace();
        }
        return null;
    }
    public Map<String,Object> checkOauthQRCode(String authorizeNo){
        Map<String,Object> rsMap = new HashedMap();
        OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findOne("ylz_config");
        try {
            TransRequest e = new TransRequest();
            e.setMethod("ehc.ehealthcard.auth.query");
            e.setApp_id(oauthYlzConfigDO.getAppId());
            e.setTerm_id(oauthYlzConfigDO.getTermId());
            e.setVersion(oauthYlzConfigDO.getVersion());
            e.setTimestamp(DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss"));
            e.setSign_type(oauthYlzConfigDO.getSignType());
            e.setEnc_type(oauthYlzConfigDO.getEncType());
            com.alibaba.fastjson.JSONObject bizContent = new com.alibaba.fastjson.JSONObject();
            bizContent.put("out_authorize_no", authorizeNo);
            e.setBiz_content(JSON.toJSONString(bizContent));
            EhcHandler ehcHandler = new EhcHandler(oauthYlzConfigDO.getUrl(), oauthYlzConfigDO.getAppId(), oauthYlzConfigDO.getTermId(), oauthYlzConfigDO.getAppKey());
            TransResponse re = ehcHandler.execute(e);
            String rs = com.alibaba.fastjson.JSONObject.toJSONString(re);
            com.alibaba.fastjson.JSONObject json = (com.alibaba.fastjson.JSONObject) com.alibaba.fastjson.JSONObject.parse(rs);
            String ret_code = json.getString("ret_code");
            if("0000".equals(ret_code)){
                com.alibaba.fastjson.JSONObject biz = json.getJSONObject("biz_content");
                String  auth_status = biz.getString("auth_status");
                if("succ".equals(auth_status)){
                    String idcard = biz.getString("id_no");
                    BasePatientDO patientDO =  basePatientDao.findByIdcardAndDel(idcard,"1");
                    if(patientDO == null){
                        BasePatientDO patient = new BasePatientDO();
                        String salt = UUID.randomUUID().toString().substring(0,5);
                        String mobile = biz.getString("mobile_phone");
                        String pw = idcard.substring(mobile.length()-6);
                        patient.setName(biz.getString("user_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.setBirthday(DateUtil.strToDate(biz.getString("birthday"),"yyyyMMdd"));
                        basePatientDao.save(patient);
                        rsMap.put("sCode",auth_status);
                        rsMap.put("sMes","success");
                        rsMap.put("patient",patient);
                        return rsMap;
                    }else{
                        rsMap.put("sCode",auth_status);
                        rsMap.put("sMes","success");
                        rsMap.put("patient",patientDO);
                        return rsMap;
                    }
                }else if("ing".equals(auth_status)){
                    rsMap.put("sCode",auth_status);
                    rsMap.put("sMes","正在授权");
                    return rsMap;
                }else if("fail".equals(auth_status)){
                    rsMap.put("sCode",auth_status);
                    rsMap.put("sMes","授权失败");
                    return rsMap;
                }else if("cancel".equals(auth_status)){
                    rsMap.put("sCode",auth_status);
                    rsMap.put("sMes","取消授权");
                    return rsMap;
                }
            }
            rsMap.put("sCode","err");
            rsMap.put("sMes","请求失败");
            return rsMap;
        }catch (Exception e){
            e.printStackTrace();
        }
        rsMap.put("sCode","err");
        rsMap.put("sMes","请求失败");
        return rsMap;
    }
}

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

@ -0,0 +1,1106 @@
package com.yihu.jw.security.utils;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * Created by chenweida on 2017/5/19.
 */
public class DateUtil {
    public static final String yyyy_MM_dd_HH_mm_ss="yyyy-MM-dd HH:mm:ss";
    public static final String HH_MM = "HH:mm";
    public static final String HH_MM_SS = "HH:mm:ss";
    public static final String YY = "yy";
    public static final String YYYYMM = "yyyyMM";
    public static final String YYYYMMDD = "yyyyMMdd";
    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
    public static final String YYYY_MM_DD_HH = "yyyy-MM-dd HH";
    public static final String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final String YYYY_M_D_HH_MM_SS = "yyyy/M/d HH:mm:ss";
    public static final String YYYY_MM_DD_ = "yyyy/MM/dd";
    public static final String YYYY_MM_DD_HH_MM_SS_ = "yyyy/MM/dd HH:mm:ss";
    public static final String YYYYMMddHHmmssSSS  = "yyyyMMddHHmmssSSS";
    public static final String YYYY_MM ="yyyy-MM";
    public static Date dateTimeParse(String date) throws ParseException {
        return new SimpleDateFormat(yyyy_MM_dd_HH_mm_ss).parse(date);
    }
    /**
     * 时间格式转中文格式
     */
    public static String dateToChinese(Date date) {
        SimpleDateFormat formatter =   new SimpleDateFormat( "yyyy年MM月dd日 EEEEaaaa hh:mm", Locale.CHINA);
        return formatter.format(date);
    }
    /**
     * 字符串转时间格式
     */
    public static Date strToDate(String strDate) {
        if (StringUtils.isEmpty(strDate)) {
            return null;
        }
        else{
            int length = strDate.length();
            if(strDate.contains("/"))
            {
                strDate = strDate.replace("/","-");
            }
            if(strDate.contains("-"))
            {
                if(length == 10)
                {
                    return strToDate(strDate,YYYY_MM_DD);
                }
                else if(length == 19)
                {
                    return strToDate(strDate,YYYY_MM_DD_HH_MM_SS);
                }
            }
            else{
                if(length == 8)
                {
                    return strToDate(strDate,YYYYMMDD);
                }
                else if(length == 14)
                {
                    return strToDate(strDate,YYYYMMDDHHMMSS);
                }
            }
        }
        return null;
    }
    /**
     * 获取现在时间
     *
     * @return 返回时间类型 yyyy-MM-dd HH:mm:ss
     */
    public static Date getNowDate() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        String dateString = formatter.format(currentTime);
        ParsePosition pos = new ParsePosition(0);
        return formatter.parse(dateString, pos);
    }
    /**
     * 获取现在时间
     *
     * @return返回短时间格式 yyyy-MM-dd
     */
    public static Date getNowDateShort() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD);
        String dateString = formatter.format(currentTime);
        return strToDate(dateString, YYYY_MM_DD);
    }
    /**
     * 获取现在时间
     *
     * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
     */
    public static String getStringDate() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        return formatter.format(currentTime);
    }
    /**
     * 获取现在时间
     *
     * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
     */
    public static String getStringDate(String format) {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        return formatter.format(currentTime);
    }
    /**
     * 获取现在时间
     *
     * @return 返回短时间字符串格式yyyy-MM-dd
     */
    public static String getStringDateShort() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD);
        return formatter.format(currentTime);
    }
    /**
     * 获取时间 小时:分;秒 HH:mm:ss
     *
     * @return
     */
    public static String getTimeShort() {
        SimpleDateFormat formatter = new SimpleDateFormat(HH_MM_SS);
        Date currentTime = new Date();
        return formatter.format(currentTime);
    }
    /**
     * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
     *
     * @param strDate
     * @return
     */
    public static Date strToDateLong(String strDate) {
        if (StringUtils.isEmpty(strDate)) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        ParsePosition pos = new ParsePosition(0);
        return formatter.parse(strDate, pos);
    }
    public static Date strToDateShort(String strDate) {
        if (StringUtils.isEmpty(strDate)) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD);
        ParsePosition pos = new ParsePosition(0);
        return formatter.parse(strDate, pos);
    }
    /**
     * 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
     *
     * @param dateDate
     * @return
     */
    public static String dateToStrLong(Date dateDate) {
        if (dateDate == null) {
            return "";
        }
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        return formatter.format(dateDate);
    }
    public static String dateToStrNoSecond(Date dateDate) {
        if (dateDate == null) {
            return "";
        }
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD_HH_MM);
        return formatter.format(dateDate);
    }
    /**
     * 将长时间格式时间转换为字符串 yyyy-MM-dd
     *
     * @param dateDate
     * @return
     */
    public static String dateToStrShort(Date dateDate) {
        if (dateDate == null) {
            return "";
        }
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD);
        return formatter.format(dateDate);
    }
    /**
     * 将短时间格式时间转换为字符串 yyyy-MM-dd
     */
    public static String dateToStr(Date dateDate, String format) {
        if (dateDate == null) {
            return "";
        }
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        return formatter.format(dateDate);
    }
    /**
     * 将短时间格式字符串转换为时间
     *
     * @param strDate
     * @return
     */
    public static Date strToDate(String strDate, String format) {
        if (StringUtils.isEmpty(strDate)) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        ParsePosition pos = new ParsePosition(0);
        return formatter.parse(strDate, pos);
    }
    public static Date strToDateAppendNowTime(String strDate, String format) {
        if (StringUtils.isEmpty(strDate)) {
            return null;
        }
        strDate += " " + getTimeShort();
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        ParsePosition pos = new ParsePosition(0);
        return formatter.parse(strDate, pos);
    }
    /**
     * 得到现在时间
     *
     * @return
     */
    public static Date getNow() {
        Date currentTime = new Date();
        return currentTime;
    }
    /**
     * 提取一个月中的最后一天
     *
     * @param day
     * @return
     */
    public static Date getLastDate(long day) {
        Date date = new Date();
        long date_3_hm = date.getTime() - 3600000 * 34 * day;
        Date date_3_hm_date = new Date(date_3_hm);
        return date_3_hm_date;
    }
    /**
     * 得到现在时间
     *
     * @return 字符串 yyyyMMdd HHmmss
     */
    public static String getStringToday() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
        String dateString = formatter.format(currentTime);
        return dateString;
    }
    /**
     * 得到现在小时
     */
    public static String getHour() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        String dateString = formatter.format(currentTime);
        String hour;
        hour = dateString.substring(11, 13);
        return hour;
    }
    /**
     * 得到现在分钟
     *
     * @return
     */
    public static String getTime() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        String dateString = formatter.format(currentTime);
        String min;
        min = dateString.substring(14, 16);
        return min;
    }
    /**
     * 根据用户传入的时间表示格式,返回当前时间的格式 如果是yyyyMMdd,注意字母y不能大写。
     *
     * @param sformat
     *            yyyyMMddhhmmss
     * @return
     */
    public static String getUserDate(String sformat) {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(sformat);
        String dateString = formatter.format(currentTime);
        return dateString;
    }
    /**
     * 得到二个日期间的间隔天数
     */
    public static String getTwoDay(String sj1, String sj2) {
        SimpleDateFormat myFormatter = new SimpleDateFormat(YYYY_MM_DD);
        long day = 0;
        try {
            Date date = myFormatter.parse(sj1);
            Date mydate = myFormatter.parse(sj2);
            day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
        } catch (Exception e) {
            return "";
        }
        return day + "";
    }
    /**
     * 时间前推或后推分钟,其中JJ表示分钟.
     */
    public static String getPreTime(String sj1, String jj) {
        SimpleDateFormat format = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        String mydate1 = "";
        try {
            Date date1 = format.parse(sj1);
            long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60;
            date1.setTime(Time * 1000);
            mydate1 = format.format(date1);
        } catch (Exception e) {
        }
        return mydate1;
    }
    /**
     * 时间前推或后推天数(负数前推正数后推)
     * date 基准时间
     */
    public static Date getPreDays(Date date, int days) {
        Date day = null;
        try {
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            c.add(Calendar.DATE, days);
            day = c.getTime();
        } catch (Exception e) {
        }
        return day;
    }
    /**
     * 得到一个时间延后或前移几分钟的时间,nowdate为时间,delay为前移或后延的分钟数
     */
    public static Date getNextMin(Date date, int delay) {
        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.MINUTE, delay);
            return cal.getTime();
        } catch (Exception e) {
            return null;
        }
    }
    /**
     * 得到一个时间延后或前移几天的时间,nowdate为时间,delay为前移或后延的天数
     */
    public static String getNextDay(String nowdate, int delay) {
        try {
            SimpleDateFormat format = new SimpleDateFormat(YYYY_MM_DD);
            String mdate = "";
            Date d = strToDate(nowdate, YYYY_MM_DD);
            long myTime = (d.getTime() / 1000) + delay * 24 * 60 * 60;
            d.setTime(myTime * 1000);
            mdate = format.format(d);
            return mdate;
        } catch (Exception e) {
            return "";
        }
    }
    public static String getNextDay(Date d, int days) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.add(Calendar.DATE, days);
        return dateToStrShort(c.getTime());
    }
    public static String getNextMonth(Date d, int months) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.add(Calendar.MONTH, months);
        return dateToStrShort(c.getTime());
    }
    public static Date getNextMonthReturnDate(Date d, int months) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.add(Calendar.MONTH, months);
        return c.getTime();
    }
    public static String getNextYear(Date d, int year) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.add(Calendar.YEAR, year);
        return dateToStrShort(c.getTime());
    }
    /**
     * 获取本月第一天
     * @return
     */
    public static String getCurMonthFirstDayShort(){
        Calendar c = Calendar.getInstance();
        c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
        return dateToStrShort(c.getTime());
    }
    /**
     * 判断是否润年
     *
     * @param ddate
     * @return
     */
    public static boolean isLeapYear(String ddate) {
        /**
         * 详细设计: 1.被400整除是闰年,否则: 2.不能被4整除则不是闰年 3.能被4整除同时不能被100整除则是闰年
         * 3.能被4整除同时能被100整除则不是闰年
         */
        Date d = strToDate(ddate, YYYY_MM_DD);
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        gc.setTime(d);
        int year = gc.get(Calendar.YEAR);
        if ((year % 400) == 0){
            return true;
        } else if ((year % 4) == 0) {
            if ((year % 100) == 0){
                return false;
            } else{
                return true;
            }
        } else{
            return false;
        }
    }
    /**
     * 返回美国时间格式 26 Apr 2006
     *
     * @param str
     * @return
     */
    public static String getEDate(String str) {
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD);
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(str, pos);
        String j = strtodate.toString();
        String[] k = j.split(" ");
        return k[2] + k[1].toUpperCase() + k[5].substring(2, 4);
    }
    /**
     * 获取一个月的最后一天
     *
     * @param dat
     * @return
     */
    public static String getEndDateOfMonth(String dat) {// yyyy-MM-dd
        String str = dat.substring(0, 8);
        String month = dat.substring(5, 7);
        int mon = Integer.parseInt(month);
        if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) {
            str += "31";
        } else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) {
            str += "30";
        } else {
            if (isLeapYear(dat)) {
                str += "29";
            } else {
                str += "28";
            }
        }
        return str;
    }
    /**
     * 产生周序列,即得到当前时间所在的年度是第几周
     *
     * @return
     */
    public static String getSeqWeek() {
        Calendar c = Calendar.getInstance(Locale.CHINA);
        String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR));
        if (week.length() == 1){
            week = "0" + week;
        }
        String year = Integer.toString(c.get(Calendar.YEAR));
        return year + week;
    }
    /**
     * 获得一个日期所在的周的星期几的日期,如要找出2002年2月3日所在周的星期一是几号
     *
     * @param sdate
     * @param num
     * @return
     */
    public static String getWeek(String sdate, String num) {
        // 再转换为时间
        Date dd = DateUtil.strToDate(sdate, YYYY_MM_DD);
        Calendar c = Calendar.getInstance();
        c.setTime(dd);
        if (num.equals("1")){ // 返回星期一所在的日期
            c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        }
        else if (num.equals("2")){ // 返回星期二所在的日期
            c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
        }
        else if (num.equals("3")){ // 返回星期三所在的日期
            c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
        }
        else if (num.equals("4")){ // 返回星期四所在的日期
            c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
        }
        else if (num.equals("5")){ // 返回星期五所在的日期
            c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
        }
        else if (num.equals("6")){ // 返回星期六所在的日期
            c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
        }
        else if (num.equals("0")){ // 返回星期日所在的日期
            c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
        }
        return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
    }
    /**
     * 根据一个日期,返回是星期几的字符串
     *
     * @param sdate
     * @return
     */
    public static String getWeek(String sdate) {
        // 再转换为时间
        Date date = DateUtil.strToDate(sdate, YYYY_MM_DD);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        // int hour=c.get(Calendar.DAY_OF_WEEK);
        // hour中存的就是星期几了,其范围 1~7
        // 1=星期日 7=星期六,其他类推
        return new SimpleDateFormat("EEEE").format(c.getTime());
    }
    public static String getWeekStr(String sdate) {
        String str = "";
        str = DateUtil.getWeek(sdate);
        if ("1".equals(str)) {
            str = "星期日";
        } else if ("2".equals(str)) {
            str = "星期一";
        } else if ("3".equals(str)) {
            str = "星期二";
        } else if ("4".equals(str)) {
            str = "星期三";
        } else if ("5".equals(str)) {
            str = "星期四";
        } else if ("6".equals(str)) {
            str = "星期五";
        } else if ("7".equals(str)) {
            str = "星期六";
        }
        return str;
    }
    /**
     * 两个时间之间的天数
     *
     * @param date1
     * @param date2
     * @return
     */
    public static long getDays(String date1, String date2) {
        if(date1 == null || date1.equals("")){
            return 0;
        }
        if(date2 == null || date2.equals("")){
            return 0;
        }
        // 转换为标准时间
        SimpleDateFormat myFormatter = new SimpleDateFormat(YYYY_MM_DD);
        Date date = null;
        Date mydate = null;
        try {
            date = myFormatter.parse(date1);
            mydate = myFormatter.parse(date2);
        } catch (Exception e) {
        }
        long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
        return day;
    }
    /**
     * 返回两个日期相差的天数
     * @param date1
     * @param date2
     * @return
     */
    public static long getDays(Date date1, Date date2) {
        if (date1 == null || date2 == null){
            return 0;
        }
        long day = (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000);
        return day;
    }
    /**
     * 返回两个日期相差的小时数(保留2位小数)
     * @param date1
     * @param date2
     * @return
     */
    public static float getHours(Date date1, Date date2) {
        if (date1 == null || date2 == null){
            return 0;
        }
        float hours = (date1.getTime() - date2.getTime()) / (float)(60 * 60 * 1000);
        BigDecimal decimal = new BigDecimal(hours);
        float hour = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
        return hour;
    }
    /**
     * 形成如下的日历 , 根据传入的一个时间返回一个结构 星期日 星期一 星期二 星期三 星期四 星期五 星期六 下面是当月的各个时间
     * 此函数返回该日历第一行星期日所在的日期
     *
     * @param sdate
     * @return
     */
    public static String getNowMonth(String sdate) {
        // 取该时间所在月的一号
        sdate = sdate.substring(0, 8) + "01";
        // 得到这个月的1号是星期几
        Date date = DateUtil.strToDate(sdate, YYYY_MM_DD);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int u = c.get(Calendar.DAY_OF_WEEK);
        String newday = DateUtil.getNextDay(sdate, 1 - u);
        return newday;
    }
    /**
     * 取得数据库主键 生成格式为yyyymmddhhmmss+k位随机数
     *
     * @param k 表示是取几位随机数,可以自己定
     */
    public static String getNo(int k) {
        return getUserDate("yyyyMMddhhmmss") + getRandom(k);
    }
    /**
     * 取得流水号 生成格式为yyyymmddhhmmss+k位随机UUID
     *
     * @param k 表示是取几位随机数,可以自己定
     */
    public static String getUidNo(int k) {
        return getUserDate("yyyyMMddhhmmss") + UUID.randomUUID().toString().replaceAll("-", "").substring(0, k);
    }
    /**
     * 返回一个随机数
     *
     * @param i
     * @return
     */
    public static String getRandom(int i) {
        Random jjj = new Random();
        if(i == 0){
            return "";
        }
        String jj = "";
        for (int k = 0; k < i; k++) {
            jj = jj + jjj.nextInt(9);
        }
        return jj;
    }
    /**
     * 根据用户生日计算年龄
     */
    public static int getAgeByBirthday(Date birthday) {
        try {
            int age = 0;
            if (birthday == null) {
                return age;
            }
            String birth = new SimpleDateFormat("yyyyMMdd").format(birthday);
            int year = Integer.valueOf(birth.substring(0, 4));
            int month = Integer.valueOf(birth.substring(4, 6));
            int day = Integer.valueOf(birth.substring(6));
            Calendar cal = Calendar.getInstance();
            age = cal.get(Calendar.YEAR) - year;
            //周岁计算
            if (cal.get(Calendar.MONTH) < (month - 1) || (cal.get(Calendar.MONTH) == (month - 1) && cal.get(Calendar.DATE) < day)) {
                age--;
            }
            return age;
        } catch (Exception e) {
            return 0;
        }
    }
    /**
     *  字符串转时间
     * @param str 时间字符串
     * @param eg 格式
     * @return
     */
    public static Date stringToDate(String str, String eg) {
        DateFormat format = new SimpleDateFormat(eg);
        Date date = null;
        if (str != null && !"".equals(str)) {
            try {
                date = format.parse(str);
            } catch (Exception e) {
                return null;
            }
        }
        return date;
    }
    public static int getNowMonth(){
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.MONTH)+1;
    }
    public static int getNowYear(){
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.YEAR);
    }
    /**
     * 获取周一
     * @return
     */
    public static String getMondayOfThisWeek() {
        SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (day_of_week == 0){
            day_of_week = 7;
        }
        c.add(Calendar.DATE, -day_of_week + 1);
        return df2.format(c.getTime());
    }
    /**
     * 得到本周周日
     *
     * @return yyyy-MM-dd
     */
    public static String getSundayOfThisWeek() {
        SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (day_of_week == 0){
            day_of_week = 7;
        }
        c.add(Calendar.DATE, -day_of_week + 7);
        return df2.format(c.getTime());
    }
    /**
     * 获取当月第一天
     * @return
     */
    public static String getFristDayOfMonth() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        // 获取前月的第一天
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
        String first = format.format(c.getTime());
        return format.format(c.getTime());
    }
    /**
     * 获取当月最后一天
     */
    public static String getLastDayOfMonth(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        // 获取前月的第一天
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
        return format.format(ca.getTime());
    }
    public static int getSignYear(){
        Calendar ca = Calendar.getInstance();
        if(getNowMonth()>=4){
            return getNowYear();
        }
        return getNowYear()-1;
    }
    /**
     * 计算预产期
     * 末次月经开始日期(第一天),月份+9,日期+7
     * @param date
     * @return
     */
    public static Date getDueDate(Date date){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH,9);
        cal.add(Calendar.DAY_OF_YEAR,7);
        return cal.getTime();
    }
    /**
     * 计算产检时间
     * @param date
     * @param day
     * @return
     */
    public static Date getPrenatalInspectorDate(Date date,Integer day){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_YEAR,day);
        return cal.getTime();
    }
    /**
     * 将HH:MM格式的字符串转TIME
     * @param hhmm
     * @return
     */
    public static Time hhmmStrToTime(String hhmm){
        Time time = null;
        DateFormat sdf = new SimpleDateFormat("HH:mm");
        try {
            Date date = sdf.parse(hhmm);
            time = new Time(date.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return time;
    }
    /**
     * 获取当前时间的Timestamp
     * @return
     */
    public static Timestamp getNowTimestamp(){
        Date date = new Date();
        Timestamp nousedate = new Timestamp(date.getTime());
        return nousedate;
    }
    /**
     *  日期加减天数
     * @param date 时间
     * @param days 天数�?
     * @return
     */
    public static Date setDateTime(Date date,int days){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DATE, cal.get(Calendar.DATE) +(days));
        return  cal.getTime();
    }
    /**
     * 获取去年日期
     * @return
     */
    public static String getLastYear(){
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.YEAR,-1);
        return dateToStrLong(cal.getTime());
    }
    /**
     * 获取儿童的年龄
     * @param date
     * @return
     */
    public static String getChildAge(Date date){
        Calendar now = Calendar.getInstance();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int year = now.get(Calendar.YEAR)-cal.get(Calendar.YEAR);
        int month = now.get(Calendar.MONTH)-cal.get(Calendar.MONTH);
        if(month<0){
            year--;
            month+=12;
        }
        int day = now.get(Calendar.DAY_OF_MONTH)-cal.get(Calendar.DAY_OF_MONTH);
        if(day<0){
            month--;
            Calendar temp = Calendar.getInstance();
            temp.setTime(date);
            temp.add(Calendar.MONTH,1);
            temp.set(Calendar.DAY_OF_MONTH,1);
            temp.add(Calendar.DAY_OF_MONTH,-1);
            day = temp.get(Calendar.DAY_OF_MONTH)+now.get(Calendar.DAY_OF_MONTH)-cal.get(Calendar.DAY_OF_MONTH);
        }
        String y = year>0? year+"岁":"";
        String m = month>0? month+"月":"";
        String d = day>0? day+"天":"";
        return y+m+d;
    }
    public static int getWeekOfMonth(String dateString){
        Date date = strToDate(dateString);
        return getWeekOfMonth(date);
    }
    public static int getWeekOfMonth(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
        return weekOfMonth;
    }
    //将时间维度查出来的quotaDate转成yyyy-MM
    public static String changeQuotaDate(Date quotaDate){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String  date = sdf.format(quotaDate);
        return date;
    }
    public static String getYear(String strDate, String format){
        Date date = strToDate(strDate,format);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.YEAR)+"";
    }
    public static String getMonth(String dateString){
        Date date = strToDate(dateString);
        return new SimpleDateFormat(YYYY_MM).format(date);
    }
    /**
     * 获取某个时间
     *
     * @return返回短时间格式 yyyy-MM-dd
     */
    public static Date getDateShort(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat(YYYY_MM_DD);
        String dateString = formatter.format(date);
        return strToDate(dateString, YYYY_MM_DD);
    }
    /**
     * 获取当月第一天
     * @return
     */
    public static String getFristDayOfMonthThisDate(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        // 获取前月的第一天
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
        String first = format.format(c.getTime());
        return format.format(c.getTime());
    }
    /**
     * 获取当月最后一天
     */
    public static String getLastDayOfMonthThisDate(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        // 获取前月的第一天
        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
        return format.format(ca.getTime());
    }
    /**
     * 根据日期对象返回星期几
     * @param date
     * @return
     */
    public static int getWeekByDate(Date date){
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int week = c.get(Calendar.DAY_OF_WEEK);
        return week;
    }
    /**
     * 获取当天0点
     * @return
     */
    public static Date getDateStart(){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        Date zero = calendar.getTime();
        return zero;
    }
    /**
     * 获取当天23:59:59
     * @return
     */
    public static Date getDateEnd(){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        Date zero = calendar.getTime();
        return zero;
    }
    public static void main(String[] args) {
        Date dateStart = getDateStart();
        Date dateEnd = getDateEnd();
        System.out.println(dateStart );
        System.out.println(dateEnd);
    }
    
    /**
     * 根据身份证的号码算出当前身份证持有者的年龄
     *
     * @param
     * @throws Exception
     */
    public static int getAgeForIdcard(String idcard) {
        try {
            int age = 0;
            
            if (org.apache.commons.lang3.StringUtils.isEmpty(idcard)) {
                return age;
            }
            
            String birth = "";
            
            if (idcard.length() == 18) {
                birth = idcard.substring(6, 14);
            } else if (idcard.length() == 15) {
                birth = "19" + idcard.substring(6, 12);
            }
            
            int year = Integer.valueOf(birth.substring(0, 4));
            int month = Integer.valueOf(birth.substring(4, 6));
            int day = Integer.valueOf(birth.substring(6));
            Calendar cal = Calendar.getInstance();
            age = cal.get(Calendar.YEAR) - year;
            //周岁计算
            if (cal.get(Calendar.MONTH) < (month - 1) || (cal.get(Calendar.MONTH) == (month - 1) && cal.get(Calendar.DATE) < day)) {
                age--;
            }
            
            return age;
        } catch (Exception e) {
        
        }
        return -1;
    }
}

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

@ -0,0 +1,80 @@
package com.yihu.jw.security.utils;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by lyr on 2016/08/10.
 */
public class QrcodeUtil {
    /**
     * 二维码图片生成
     *
     * @param content 二维码内容
     * @param imgType 图片类型
     * @param size    图片尺寸
     * @return
     */
    public static File QrcodeEncode(String content, String fileName, String path, String imgType, int size) throws Exception {
        File pathFile = new File(path);
        File outputFile = new File(path + File.separator + fileName + ".png");
        if (!pathFile.exists()) {
            pathFile.mkdir();
        }
        if (outputFile.exists()) {
            outputFile.delete();
        }
        outputFile.createNewFile();
        Map<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
        // 内容所使用字符集编码
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, size, size, hints);
        // 生成二维码
        MatrixToImageWriter.writeToFile(bitMatrix, imgType, outputFile);
        return outputFile;
    }
    /**
     * 创建二维码
     * @param content
     * @return
     */
    public static InputStream createQrcode(String content,int size,String imgType) {
        byte[] imagesStream=null;
        ByteArrayOutputStream os = null;
        try {
            HashMap<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
            hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
            hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            hints.put(EncodeHintType.MARGIN, 0);
            BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
              BarcodeFormat.QR_CODE, size, size, hints);
             os = new ByteArrayOutputStream();
            MatrixToImageWriter.writeToStream(bitMatrix, imgType, os);
            return new ByteArrayInputStream(os.toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}

+ 23 - 2
server/svr-authentication/src/main/resources/application.yml

@ -22,7 +22,19 @@ user:
  autoUnlockTime: 5  #账户锁定后,自动解锁时间  以分钟计算
  reflashFailedCountTime: 5 #将失败次数重置为0
  tryLoginTimes: 5 #失败重试次数
fast-dfs:
  tracker-server: 172.26.0.110:22122 #服务器地址
  connect-timeout: 2 #链接超时时间
  network-timeout: 30
  charset: ISO8859-1 #编码
  http:
    tracker-http-port: 80
    anti-steal-token: no
    secret-key: FastDFS1234567890
  pool: #连接池大小
    init-size: 5
    max-size: 20
    wait-time: 500
---
spring:
  profiles: jwdev
@ -40,6 +52,9 @@ iHealth:
  user-info-uri: http://ehr.yihu.com/wlyy/iHealth/userInfo
zhongshanHospital:
  user-info-uri: http://laptop-u738dn2p:10023/mqsdk/getUserInfoByOpenid
fastDFS:
  fastdfs_file_url: http://172.26.0.110:8888/
---
spring:
  profiles: jwtest
@ -57,6 +72,9 @@ iHealth:
  user-info-uri: http://ehr.yihu.com/wlyy/iHealth/userInfo
zhongshanHospital:
  user-info-uri: http://laptop-u738dn2p:10023/mqsdk/getUserInfoByOpenid
fastDFS:
  fastdfs_file_url: http://172.26.0.110:8888/
---
spring:
  profiles: jwprod
@ -73,4 +91,7 @@ spring:
iHealth:
  user-info-uri: http://ehr.yihu.com/wlyy/iHealth/userInfo
zhongshanHospital:
  user-info-uri: http://laptop-u738dn2p:10023/mqsdk/getUserInfoByOpenid
  user-info-uri: http://laptop-u738dn2p:10023/mqsdk/getUserInfoByOpenid
fastDFS:
  fastdfs_file_url: http://192.0.33.26:8888/

+ 6 - 2
svr/svr-internet-hospital/pom.xml

@ -69,7 +69,11 @@
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>com.ylz.loginsdk</groupId>
            <artifactId>ehcsdk</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-entity</artifactId>
@ -96,11 +100,11 @@
            <artifactId>common-web</artifactId>
        </dependency>
        <!-- 文件服务器 -->
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>fastdfs-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!-- Jzkl Starter -->
        <dependency>

+ 6 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java

@ -478,6 +478,12 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
        return success(prescriptionService.test());
    }
    @PostMapping(value = "test2")
    @ApiOperation(value = "test2", notes = "test2")
    public Envelop test(String no)throws Exception {
        return success(prescriptionService.test2(no));
    }
    @GetMapping(value = BaseHospitalRequestMapping.Prescription.findPatientInfo)
    @ApiOperation(value = "获取居民信息接口", notes = "获取居民信息接口")