Search in sources :

Example 1 with RealNameAuthentication

use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.

the class BasicInformationController method download.

/**
 * 下载回执报告
 *
 * @param evidenceSn
 * @param request
 * @param response
 * @param uiModel
 * @return
 * @throws Exception
 */
@RequestMapping(value = "outpdf/{evidenceSn}")
public String download(@PathVariable("evidenceSn") String evidenceSn, HttpServletRequest request, HttpServletResponse response, Model uiModel) throws Exception {
    RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
    String fileName = null;
    if (realNameAuthentication == null) {
        realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
    }
    try {
        if (realNameAuthentication == null) {
            String oper = "下载回执报告失败";
            String info = "失败原因:服务器出错,请联系管理员";
            LogUtil.evidencelog(sqlSession, null, oper, info);
            return "服务器出错,请联系管理员";
        }
        // 得到接口路径
        String urlAgent = realNameAuthentication.getRealNameddress();
        EvidenceEnclosureExample enclo = new EvidenceEnclosureExample();
        EvidenceEnclosureExample.Criteria enclosureEx = enclo.createCriteria();
        enclosureEx.andEvidenceSnEqualTo(evidenceSn);
        enclosureEx.andPdfTypeEqualTo("3");
        EvidenceEnclosure enclosure = sqlSession.selectOne("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclo);
        if (enclosure == null) {
            return "未找到该证据编号的信息";
        }
        String base64 = EvidenceSaveServiceApi.decryptedAndDownload(sqlSession, enclosure.getBuid(), urlAgent);
        response.reset();
        fileName = Calendar.getInstance().getTimeInMillis() + "";
        fileName = reportTemplate.chineseUtf(fileName, request);
        response.addHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".pdf").getBytes("utf-8"), "iso-8859-1"));
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/pdf");
        if (base64 == null || base64.contains("exception")) {
            String oper = "下载回执报告失败";
            String info = "失败原因:base64为空";
            LogUtil.evidencelog(sqlSession, null, oper, info);
            return "base64为空";
        }
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            // Base64解码
            byte[] bytes = decoder.decodeBuffer(base64);
            for (int i = 0; i < bytes.length; ++i) {
                if (bytes[i] < 0) {
                    // 调整异常数据
                    bytes[i] += 256;
                }
            }
            // FileOutputStream out = new
            // FileOutputStream("D:/test/itext/123.pdf");
            // 生成文件的路径
            OutputStream out = response.getOutputStream();
            // OutputStream os = new
            // BufferedOutputStream(response.getOutputStream());
            out.write(bytes);
            out.flush();
            out.close();
            String oper = "下载回执报告成功";
            String info = "报告名称:" + fileName + ".pdf";
            LogUtil.evidencelog(sqlSession, null, oper, info);
        } catch (Exception e) {
            String oper = "下载回执报告失败";
            String info = "失败原因:" + e.getMessage();
            LogUtil.evidencelog(sqlSession, null, oper, info);
            return e.getMessage();
        }
    } catch (Exception e) {
        // TODO Auto-generated catch
        e.printStackTrace();
        String oper = "下载回执报告失败";
        String info = "失败原因:" + e.getMessage();
        LogUtil.evidencelog(sqlSession, null, oper, info);
    }
    return null;
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) EvidenceEnclosureExample(com.itrus.portal.db.EvidenceEnclosureExample) EvidenceEnclosure(com.itrus.portal.db.EvidenceEnclosure) RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) BASE64Decoder(sun.misc.BASE64Decoder) JSONException(org.json.JSONException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RealNameAuthentication

use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.

the class RealNameAuthenticationSerivceImpl method getRealNameAuthenticationByTwo.

/**
 * 获取密码服务配置
 * @return
 * @throws Exception
 */
public RealNameAuthentication getRealNameAuthenticationByTwo() throws Exception {
    RealNameAuthenticationExample re = new RealNameAuthenticationExample();
    RealNameAuthenticationExample.Criteria rec = re.createCriteria();
    rec.andTypeEqualTo(2);
    RealNameAuthentication realname = this.getRealNameAuthenticationExample(re);
    return realname;
}
Also used : RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample)

Example 3 with RealNameAuthentication

use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.

the class RealNameAuthenticationSerivceImpl method getRealNameAuthenticationByThree.

/**
 * 获取时间戳服务配置
 * @return
 * @throws Exception
 */
public RealNameAuthentication getRealNameAuthenticationByThree() throws Exception {
    RealNameAuthenticationExample re = new RealNameAuthenticationExample();
    RealNameAuthenticationExample.Criteria rec = re.createCriteria();
    rec.andTypeEqualTo(3);
    RealNameAuthentication realname = this.getRealNameAuthenticationExample(re);
    return realname;
}
Also used : RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample)

Example 4 with RealNameAuthentication

use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.

the class RealNameAuthenticationSerivceImpl method getRealNameAuthenticationByOne.

/**
 * 获取原子服务配置
 * @return
 * @throws Exception
 */
public RealNameAuthentication getRealNameAuthenticationByOne() throws Exception {
    RealNameAuthenticationExample re = new RealNameAuthenticationExample();
    RealNameAuthenticationExample.Criteria rec = re.createCriteria();
    rec.andTypeEqualTo(1);
    RealNameAuthentication realname = this.getRealNameAuthenticationExample(re);
    return realname;
}
Also used : RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample)

Example 5 with RealNameAuthentication

use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.

the class AuthService method getToken.

// @Autowired
// private static RealNameAuthenticationSerivceImpl authenticationSerivceImpl = new RealNameAuthenticationSerivceImpl();
/**
 * 获得token
 * 访问其他接口的时候 在头信息增加 Authorization :bear+token bear和token之间加个空格
 */
private static String getToken() {
    // client_secret:43b484748d3a936330bc50da70d6ce69e1dfef90
    try {
        // RealNameAuthentication realNameAuthentication =  authenticationSerivceImpl.getRealNameAuthenticationExample(new RealNameAuthenticationExample());
        long nowDate = System.currentTimeMillis();
        if (ACCESS_TOKEN != null && new Date(nowDate + inDateTime).before(inDate)) {
            return ACCESS_TOKEN;
        }
        RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
        if (realNameAuthentication == null) {
            List<RealNameAuthentication> list = SpringContextHolder.getBean(SqlSession.class).selectList("com.itrus.portal.db.RealNameAuthenticationMapper.selectByExample", new RealNameAuthenticationExample());
            if (list == null || list.isEmpty()) {
                return null;
            }
            for (RealNameAuthentication nameAuthentication : list) {
                if (nameAuthentication.getType() == 2)
                    realNameAuthentication = nameAuthentication;
            }
            if (realNameAuthentication == null) {
                return null;
            }
        }
        Map params = new HashMap();
        params.put("grant_type", "client_credentials");
        params.put("client_id", realNameAuthentication.getIdCode());
        params.put("client_secret", realNameAuthentication.getKeyCode());
        String rep = HttpClientUtil.postForm(realNameAuthentication.getAccessTokenaddress() + TOKEN, null, params);
        // System.out.println("AuthService getToken()_rep : " + rep);
        JSONObject data = JSON.parseObject(rep);
        ACCESS_TOKEN = data.getString("access_token");
        inDate = new Date(nowDate + data.getLongValue("expires_in"));
        return ACCESS_TOKEN;
    } catch (RestClientException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) HashMap(java.util.HashMap) IOException(java.io.IOException) RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Date(java.util.Date) RestClientException(org.springframework.web.client.RestClientException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) RealNameAuthenticationExample(com.itrus.portal.db.RealNameAuthenticationExample) JSONObject(com.alibaba.fastjson.JSONObject) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RestClientException(org.springframework.web.client.RestClientException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RealNameAuthentication (com.itrus.portal.db.RealNameAuthentication)24 JSONObject (com.alibaba.fastjson.JSONObject)14 HashMap (java.util.HashMap)14 IOException (java.io.IOException)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 EvidenceBasicInformation (com.itrus.portal.db.EvidenceBasicInformation)8 EvidenceEnclosure (com.itrus.portal.db.EvidenceEnclosure)8 EvidenceEnclosureExample (com.itrus.portal.db.EvidenceEnclosureExample)8 ApplicationInfo (com.itrus.portal.db.ApplicationInfo)6 RealNameAuthenticationExample (com.itrus.portal.db.RealNameAuthenticationExample)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Map (java.util.Map)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 AppService (com.itrus.portal.db.AppService)4 EvidenceSaveService (com.itrus.portal.db.EvidenceSaveService)3 BufferedOutputStream (java.io.BufferedOutputStream)3 List (java.util.List)3 JSONException (org.json.JSONException)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2