Commit e48dc441 authored by weizhikai's avatar weizhikai

Merge branch 'dev_mysql' of http://code.tech.tax.asia.pwcinternal.com/root/atms into dev_wzk_phase1

parents 4c6af1dd 8baf5057
package pwc.taxtech.atms.common.util;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
/**
* author kevin
*/
public class DataBaseTableUtil {
private static String url;
private static String username;
private static String password;
private final static String driver = "com.mysql.jdbc.Driver";
static {
InputStream in = null;
in = DataBaseTableUtil.class.getClassLoader().getResourceAsStream("conf/conf.properties");
Properties p = new Properties();
try {
p.load(in);
} catch (IOException e) {
e.printStackTrace();
}
url = p.getProperty("jdbc_url");
username = p.getProperty("jdbc_user");
password = p.getProperty("jdbc_password");
}
/**
* 读取mysql某数据库下表的注释信息
*
* @author xxx
*/
public static Connection getMySQLConnection() throws Exception {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
/**
* 获取当前数据库下的所有表名称
* @return
* @throws Exception
*/
public static List getAllTableName() throws Exception {
List tables = new ArrayList();
Connection conn = getMySQLConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SHOW TABLES ");
while (rs.next()) {
String tableName = rs.getString(1);
tables.add(tableName);
}
rs.close();
stmt.close();
conn.close();
return tables;
}
/**
* 获得某表的建表语句
*
* @param tableName
* @return
* @throws Exception
*/
public static Map getCommentByTableName(List tableName) throws Exception {
Map map = new HashMap();
Connection conn = getMySQLConnection();
Statement stmt = conn.createStatement();
for (int i = 0; i < tableName.size(); i++) {
String table = (String) tableName.get(i);
ResultSet rs = stmt.executeQuery("SHOW CREATE TABLE " + table);
if (rs != null && rs.next()) {
String createDDL = rs.getString(2);
String comment = parse(createDDL);
map.put(table, comment);
}
rs.close();
}
stmt.close();
conn.close();
return map;
}
/**
* 获得某表中所有字段的注释
*
* @param tableName
* @return
* @throws Exception
*/
public static void getColumnCommentByTableName(List tableName) throws Exception {
Map map = new HashMap();
Connection conn = getMySQLConnection();
Statement stmt = conn.createStatement();
for (int i = 0; i < tableName.size(); i++) {
String table = (String) tableName.get(i);
ResultSet rs = stmt.executeQuery("show full columns from " + table);
System.out.println("【" + table + "】");
// if (rs != null && rs.next()) {
//map.put(rs.getString("Field"), rs.getString("Comment"));
while (rs.next()) {
// System.out.println("字段名称:" + rs.getString("Field") + "\t"+ "字段注释:" + rs.getString("Comment") );
System.out.println(rs.getString("Field") + "\t:\t" + rs.getString("Comment"));
}
// }
rs.close();
}
stmt.close();
conn.close();
// return map;
}
/**
* 返回注释信息
*
* @param all
* @return
*/
public static String parse(String all) {
String comment = null;
int index = all.indexOf("COMMENT='");
if (index < 0) {
return "";
}
comment = all.substring(index + 9);
comment = comment.substring(0, comment.length() - 1);
return comment;
}
public void main(String[] args) throws Exception {
List tables = getAllTableName();
Map tablesComment = getCommentByTableName(tables);
Set names = tablesComment.keySet();
Iterator iter = names.iterator();
while (iter.hasNext()) {
String name = (String) iter.next();
System.out.println("Table Name: " + name + ", Comment: " + tablesComment.get(name));
}
getColumnCommentByTableName(tables);
}
public static List<String> getTableComment(String tableName) {
List<String> commentComments = Lists.newArrayList();
Connection conn = null;
try {
conn = getMySQLConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("show full columns from " + tableName);
while (rs.next()) {
commentComments.add(rs.getString("Comment"));
}
} catch (Exception e) {
e.printStackTrace();
}
return commentComments;
}
}
......@@ -664,34 +664,6 @@ public class DateUtils {
return cale.get(Calendar.YEAR);
}
/**
* 取得数据库主键 生成格式为yyyymmddhhmmss+k位随机数
*
* @param k 表示是取几位随机数,可以自己定
*/
public static String getNo(int k) {
return getUserDate("yyyyMMddhhmmss") + getRandom(k);
}
/**
* 返回一个随机数
*
* @param i
* @return
*/
public static String getRandom(int i) {
Random jjj = new Random();
// int suiJiShu = jjj.nextInt(9);
if (i == 0)
return "";
String jj = "";
for (int k = 0; k < i; k++) {
jj = jj + jjj.nextInt(9);
}
return jj;
}
/**
* @param date
......
......@@ -8,18 +8,12 @@ package pwc.taxtech.atms.common.util;
* Version 1.0
**/
import com.google.common.collect.Lists;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.nutz.http.Http;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.BASE64Encoder;
import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -222,49 +216,6 @@ public class FileExcelUtil {
}
}
/**
* 将批量文件打包下载成zip
*
* @param request
* @param response
* @param zipName 下载的zip名
* @param files 要打包的批量文件
* @param zipDir 存放zip文件的文件夹路径
* @throws Exception
*/
public static synchronized void downloadZip(HttpServletRequest request, HttpServletResponse response, String zipName, List<File> files, String zipDir) throws Exception {
//ZIPPATH = this.getClass().getResource("/").getPath().substring(1) + "zipDir";
FileExcelUtil.createFile(zipDir);// 先生成存放zip文件的文件夹
String zipPath = zipDir + "/" + Math.random() + ".zip";
File srcfile[] = new File[files.size()];
File zip = new File(zipPath);
for (int i = 0; i < files.size(); i++) {
srcfile[i] = files.get(i);
}
FileInputStream inStream = null;
ServletOutputStream os = null;
try {
//设置下载zip的头信息
FileExcelUtil.setZipDownLoadHeadInfo(response, request, zipName);
os = response.getOutputStream();
FileExcelUtil.ZipFiles(srcfile, zip);
inStream = new FileInputStream(zip);
byte[] buf = new byte[4096];
int readLength;
while (((readLength = inStream.read(buf)) != -1)) {
os.write(buf, 0, readLength);
}
} finally {
if (inStream != null) {
inStream.close();
}
if (os != null) {
os.flush();
os.close();
}
deleteDir(zip);
}
}
/**
* //压缩文件
......@@ -272,7 +223,7 @@ public class FileExcelUtil {
* @param srcfile 要压缩的文件数组
* @param zipfile 生成的zip文件对象
*/
public static void ZipFiles(java.io.File[] srcfile, File zipfile) throws Exception {
public static void ZipFiles(File[] srcfile, File zipfile) throws Exception {
byte[] buf = new byte[1024];
FileOutputStream fos = new FileOutputStream(zipfile);
ZipOutputStream out = new ZipOutputStream(fos);
......
......@@ -118,9 +118,9 @@ public final class Constant {
}
public static class InputInvoiceCertificationResult {
public static String CheckPass = "勾选认证";
public static String ScanPass = "扫描认证";
public static String NotPass = "未认证";
public static String Check = "勾选认证";
public static String Scan = "扫描认证";
public static String NotCertified = "未认证";
}
public static class ReportBuildInStringFormat {
......
......@@ -83,22 +83,22 @@ public class JXFP extends FunctionBase implements FreeRefFunction {
List<CertifiedInvoicesList> inputInvoices;
if (authenticationType == 1 && formulaContext.getIsYear()) {
inputInvoices = getInvoice(null, invoiceTypeParam,
Constant.InputInvoiceCertificationResult.CheckPass, Constant.InputInvoiceCertificationResult.ScanPass,
Constant.InputInvoiceCertificationResult.Check, Constant.InputInvoiceCertificationResult.Scan,
null);
} else if (authenticationType == 1) {
inputInvoices =getInvoice(period, invoiceTypeParam,
Constant.InputInvoiceCertificationResult.CheckPass, Constant.InputInvoiceCertificationResult.ScanPass,
Constant.InputInvoiceCertificationResult.Check, Constant.InputInvoiceCertificationResult.Scan,
null);
}
// 认证未通过与未认证暂认为是同一个意思
else if (authenticationType == 2 && formulaContext.getIsYear()) {
inputInvoices = getInvoice(null, invoiceTypeParam,
null, null, Constant.InputInvoiceCertificationResult.NotPass);
null, null, Constant.InputInvoiceCertificationResult.NotCertified);
}
// 认证未通过与未认证暂认为是同一个意思
else if (authenticationType == 0 || authenticationType == 2) {
inputInvoices =getInvoice(period, invoiceTypeParam, null,
null, Constant.InputInvoiceCertificationResult.NotPass);
null, Constant.InputInvoiceCertificationResult.NotCertified);
} else {
saveFormulaBlock(period, ec, formulaExpression, new BigDecimal("0.0"), 0L, formulaContext.getProjectId());
return NumberEval.ZERO;
......
......@@ -5,17 +5,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import pwc.taxtech.atms.CommonIT;
import pwc.taxtech.atms.common.util.DataBaseTableUtil;
import pwc.taxtech.atms.common.util.DateUtils;
import pwc.taxtech.atms.constant.enums.EnumTbImportType;
import pwc.taxtech.atms.entity.Organization;
import pwc.taxtech.atms.entity.OrganizationExample;
import pwc.taxtech.atms.vat.entity.EbitCellData;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment