Commit 6635f598 by manxiaoqiang

Merge remote-tracking branch 'origin/master'

parents 7a501c2f 6e758498
......@@ -65,7 +65,7 @@
<!-- 单位是分钟-->
<mail.valid_time>3</mail.valid_time>
<report.url>http://ec2-54-222-233-230.cn-north-1.compute.amazonaws.com.cn:9010</report.url>
<report.url>http://localhost:8082</report.url>
<!--Redis setting-->
<redis.key.validtime>120</redis.key.validtime>
<redis.ip.requesttimes>5</redis.ip.requesttimes>
......
......@@ -16,6 +16,12 @@ import util.UserLogThread;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
/**
* Created by zxy on 2017/12/27.
*/
......@@ -29,13 +35,24 @@ public class AppController
@RequestMapping(value = "find", method = RequestMethod.GET)
@ResponseBody
public ResultModel findAll(@RequestParam Integer reyun, @RequestParam String location, @RequestParam String firstCate, @RequestParam String secondCate,
@RequestParam int pageNum, @RequestParam int pageSize, @RequestParam String sortString, @RequestParam Integer isASC) {
@RequestParam int pageNum, @RequestParam int pageSize, @RequestParam String sortString, @RequestParam Integer isASC, @RequestParam String searchString,
@RequestParam String startDate, @RequestParam String endDate) {
AppInfo app = new AppInfo();
app.setLocation(location);
app.setFirstCate(firstCate);
app.setSecondCate(secondCate);
app.setReyun(reyun);
return ResultModel.OK(appService.findAppList(app, pageNum, pageSize, sortString, isASC));
Map result = new HashMap();
try {
result = appService.findAppList(app, pageNum, pageSize, sortString, isASC, searchString, startDate, endDate);
}
catch (ExecutionException e) {
e.printStackTrace();
}
catch (InterruptedException e) {
e.printStackTrace();
}
return ResultModel.OK(result);
}
///api/applist/category/1
......@@ -51,4 +68,10 @@ public class AppController
public ResultModel findCity() {
return ResultModel.OK(appService.findCity());
}
@RequestMapping(value = "data", method = RequestMethod.GET)
@ResponseBody
public ResultModel findDeviceData() {
return ResultModel.OK(appService.findAppDataList("2017-12-22", "2017-12-22", null, 0, 0, 20));
}
}
......@@ -3,6 +3,7 @@ package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
/**
* Created by Administrator on 2017/12/26.
......@@ -24,6 +25,9 @@ public class AppInfo
private String thirdCate;
private String otherCate;
@Transient
private Long newDevice;
@Id
@GeneratedValue
public Long getId()
......@@ -146,6 +150,16 @@ public class AppInfo
this.otherCate = otherCate;
}
public Long getNewDevice()
{
return newDevice;
}
public void setNewDevice(Long newDevice)
{
this.newDevice = newDevice;
}
@Override
public String toString()
{
......@@ -162,6 +176,7 @@ public class AppInfo
", secondCate=" + secondCate +
", thirdCate=" + thirdCate +
", otherCate='" + otherCate + '\'' +
", newDevice='" + newDevice + '\'' +
'}';
}
}
......@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Set;
/**
* Created by zxy on 2017/12/26.
......@@ -14,4 +15,5 @@ public interface AppInfoRepository extends JpaRepository<AppInfo, Long>, JpaSpec
{
@Query(value = "select a from AppInfo a where reyun=0 or reyun is null")
List<AppInfo> findAppListByReyun();
}
package common.service;
import common.model.AppInfo;
import dmp.model.AppData;
import net.sf.json.JSONArray;
import org.springframework.data.domain.Page;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
/**
* Created by zxy on 2017/12/27.
*/
public interface AppService
{
Page<AppInfo> findAppList(AppInfo app, int pageNum, int pageSize, String sort, Integer isASC);
Map findAppList(AppInfo app, int pageNum, int pageSize, String sort, Integer isASC, String searchString, String startDate, String endDate)
throws ExecutionException, InterruptedException;
List<String> findAllCategoryByLevel(int level);
List<String> findCity();
String findAppDataList(String startDate, String endDate, List<String> pkgNameList, Integer isASC);
JSONArray findAppDataList(String startDate, String endDate, List<String> pkgNameList, Integer isASC, Integer startNum, Integer size);
}
......@@ -5,7 +5,11 @@ import common.repository.AppCategoryRepository;
import common.repository.AppInfoRepository;
import common.repository.CityRepository;
import common.service.AppService;
import dmp.model.AppData;
import common.task.ReportCallable;
import dmp.model.OtPkgDevStats;
import dmp.repository.OtPkgDevStatsRepository;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -14,7 +18,9 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import tkio.model.App;
import util.Constant;
import util.DBUtil;
import util.HttpClientUtil;
import util.StringUtil;
......@@ -23,9 +29,18 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
* Created by zxys on 2017/12/27.
......@@ -37,20 +52,100 @@ public class AppServiceImpl implements AppService
@Autowired AppInfoRepository appInfoRepository;
@Autowired AppCategoryRepository appCategoryRepository;
@Autowired CityRepository cityRepository;
@Autowired OtPkgDevStatsRepository otPkgDevStatsRepository;
@Override
public Page<AppInfo> findAppList(AppInfo app, int pageNum, int pageSize, String sortString, Integer isASC)
public Map findAppList(AppInfo app, int pageNum, int pageSize, String sortString, Integer isASC, String searchString, String startDate, String endDate)
throws ExecutionException, InterruptedException
{
Specification<AppInfo> specification = getWhereClause(app);
List<Sort.Order> orders = new ArrayList<Sort.Order>();
if (StringUtil.isEmpty(sortString)) {
sortString = "pkgName";
pageNum = pageNum-1;
ExecutorService pool = Executors.newFixedThreadPool(2);
ReportCallable callableTotal = new ReportCallable(app,pageNum,pageSize,sortString,isASC,searchString,startDate,endDate, true);
ReportCallable callableDimension = new ReportCallable(app,pageNum,pageSize,sortString,isASC,searchString,startDate,endDate, false);
//执行任务并获取Future对象
Future<Map<String, Object>> futureTotal = pool.submit(callableTotal);
Future<Map<String, Object>> futureDimension = pool.submit(callableDimension);
Map<String, Object> resultTotal = futureTotal.get();
Map<String, Object> resultDimension = futureDimension.get();
Map<String, Object> result = new HashMap<>();
result.put("content", resultDimension.get("content"));
result.put("totalElements", resultTotal.get("totalElements"));
/*
List<AppInfo> appList = new ArrayList<>();
Page<AppInfo> appInfoPage = null;
Specification<AppInfo> specification = getWhereClause(app, searchString);
if (!StringUtil.isEmpty(sortString) && sortString.equals("new_device")) {
appList = appInfoRepository.findAll(specification);
result.put("totalElements", appList.size());
} else {
List<Sort.Order> orders = new ArrayList<Sort.Order>();
if (StringUtil.isEmpty(sortString)) {
sortString = "pkgName";
}
orders.add(new Sort.Order((isASC!=null && isASC==0)?Sort.Direction.DESC:Sort.Direction.ASC,sortString));
Sort sort = new Sort(orders);
Pageable pageable = new PageRequest(pageNum, pageSize, sort);
appInfoPage = appInfoRepository.findAll(specification, pageable);
result.put("content", appInfoPage.getContent());
result.put("totalElements", appInfoPage.getTotalElements());
}
orders.add(new Sort.Order((isASC!=null && isASC==0)?Sort.Direction.DESC:Sort.Direction.ASC,sortString));
Sort sort = new Sort(orders);
Pageable pageable = new PageRequest(pageNum, pageSize, sort);
Page<AppInfo> appInfoPage = appInfoRepository.findAll(specification, pageable);
return appInfoPage;
if (!StringUtil.isEmpty(sortString) && sortString.equals("new_device")) {
List<String> pkgList = new ArrayList<>();
Map<String, AppInfo> appMap = new HashMap<>();
for (AppInfo appin : appList) {
pkgList.add(appin.getPkgName());
appMap.put(appin.getPkgName(), appin);
}
JSONArray values = findAppDataList(startDate, endDate, pkgList, isASC, pageNum*pageSize, pageSize);
Map<String, Object> valueResult = new HashMap<>();
List<String> pkgs = new ArrayList<>();
for (int i=0; i<values.size(); i++) {
JSONObject o = values.getJSONObject(i);
valueResult.put(o.get("valueResult").toString(), o.get("new_device"));
pkgs.add(o.get("valueResult").toString());
}
List<AppInfo> resultAppList = new ArrayList<>();
for (String pkg : pkgs) {
AppInfo ai = appMap.get(pkg);
ai.setNewDevice(Long.getLong(valueResult.get(pkg).toString()));
resultAppList.add(ai);
}
result.put("content", resultAppList);
if (resultAppList.size() == 0) {
result.put("totalElements", 0);
}
} else {
List<String> pkgnameList = new ArrayList<>();
for (AppInfo ai : appInfoPage) {
pkgnameList.add(ai.getPkgName());
}
JSONArray values = findAppDataList(startDate, endDate, pkgnameList, null, null, null);
Map<String, Object> valueResult = new HashMap<>();
for (int i=0; i<values.size(); i++) {
JSONObject o = values.getJSONObject(i);
valueResult.put(o.get("valueResult").toString(), o.get("new_device"));
}
for (AppInfo ai : appInfoPage) {
if (valueResult.containsKey(ai.getPkgName())) {
ai.setNewDevice(Long.getLong(valueResult.get(ai.getPkgName()).toString()));
} else {
ai.setNewDevice(0L);
}
}
result.put("content", appInfoPage.getContent());
result.put("totalElements", appInfoPage.getTotalElements());
}*/
return result;
}
@Override
......@@ -66,13 +161,28 @@ public class AppServiceImpl implements AppService
}
@Override
public String findAppDataList(String startDate, String endDate, List<String> pkgNameList, Integer isASC)
public JSONArray findAppDataList(String startDate, String endDate, List<String> pkgNameList, Integer isASC, Integer startNum, Integer size)
{
// Specification<OtPkgDevStats> specification = getWhereClause(pkgNameList, startDate, endDate);
// List<Sort.Order> orders = new ArrayList<Sort.Order>();
// orders.add(new Sort.Order((isASC!=null && isASC==0)?Sort.Direction.DESC:Sort.Direction.ASC,"devnum"));
// Sort sort = new Sort(orders);
// Pageable pageable = new PageRequest(pageNum-1, pageSize, sort);
// otPkgDevStatsRepository.findAll(specification, pageable);
Map<String, String> conditions = new HashedMap();
String url = Constant.reportUrl + "/api/dmp/newdevicebypkgname/test";
conditions.put("datatype", "list");
conditions.put("startdate", "2017-12-20");
conditions.put("enddate", "2017-12-26");
conditions.put("startdate", startDate);
conditions.put("enddate", endDate);
if (startNum != null) {
conditions.put("startnum", startNum.toString());
}
if (size != null) {
conditions.put("size", size.toString());
}
if (pkgNameList != null && pkgNameList.size()>0) {
conditions.put("pkgname", String.join(",", pkgNameList));
}
......@@ -80,7 +190,17 @@ public class AppServiceImpl implements AppService
conditions.put("isasc", isASC.toString());
}
String responseJson = HttpClientUtil.doHttpPostRequest(url, "manager", conditions);
return responseJson;
System.out.println(responseJson);
JSONArray array = new JSONArray();
JSONObject object = JSONObject.fromObject(responseJson);
if (object.containsKey("content")) {
JSONObject content = object.getJSONObject("content");
if (content != null && content.containsKey("val")) {
array = content.getJSONArray("val");
}
}
return array;
}
/**
......@@ -88,7 +208,7 @@ public class AppServiceImpl implements AppService
* @param appInfo
* @return
*/
private Specification<AppInfo> getWhereClause(final AppInfo appInfo){
private Specification<AppInfo> getWhereClause(final AppInfo appInfo, String searchString){
return new Specification<AppInfo>() {
@Override
public Predicate toPredicate(Root<AppInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
......@@ -105,14 +225,55 @@ public class AppServiceImpl implements AppService
if (!StringUtil.isEmpty(appInfo.getSecondCate())) {
predicate.add(cb.equal(root.get("secondCate").as(String.class), appInfo.getSecondCate()));
}
if (!StringUtil.isEmpty(searchString)) {
List<Predicate> innerPredicate = new ArrayList<>();
innerPredicate.add(cb.like(root.get("name").as(String.class), "%"+searchString+"%"));
innerPredicate.add(cb.like(root.get("company").as(String.class), "%"+searchString+"%"));
innerPredicate.add(cb.like(root.get("pkgName").as(String.class), "%"+searchString+"%"));
Predicate p = cb.or(innerPredicate.toArray(new Predicate[innerPredicate.size()]));
predicate.add(p);
}
Predicate[] pre = new Predicate[predicate.size()];
query.where(predicate.toArray(pre));
return query.getRestriction();
}
};
}
/**
* 动态生成where语句
* @param
* @return
*/
private Specification<OtPkgDevStats> getWhereClause(List<String> pkgList, String startDate, String endDate){
return new Specification<OtPkgDevStats>() {
@Override
public Predicate toPredicate(Root<OtPkgDevStats> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicate = new ArrayList<>();
CriteriaBuilder.In<String> in = cb.in(root.get("pkgname").as(String.class));
for (String pkg : pkgList) {
in.value(pkg);
}
predicate.add(in);
if (!StringUtil.isEmpty(startDate)) {
predicate.add(cb.greaterThanOrEqualTo(root.get("ds").as(String.class), startDate));
}
if (!StringUtil.isEmpty(endDate)) {
predicate.add(cb.lessThanOrEqualTo(root.get("ds").as(String.class), endDate));
}
Predicate[] pre = new Predicate[predicate.size()];
query.multiselect(root.get("pkgname").as(String.class), cb.sum(root.get("devNum").as(Long.class)).alias("devnum"));
query.where(predicate.toArray(pre));
query.groupBy(root.get("pkgname").as(String.class));
return query.getRestriction();
}
};
}
}
package common.task;
import common.model.AppInfo;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import util.DBUtil;
import util.StringUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
/**
* 漏斗和留存报表数据获取线程
*/
public class ReportCallable
implements Callable<Map<String, Object>> {
protected static Logger logger = LoggerFactory.getLogger(ReportCallable.class);
private AppInfo app;
private int pageNum;
private int pageSize;
private String sortString;
private Integer isASC;
private String searchString;
private String startDate;
private String endDate;
private Map<String, Object> result = new HashMap();
private int totalNum;
private boolean isTotal;
public ReportCallable(AppInfo app, int pageNum, int pageSize, String sortString, Integer isASC, String searchString, String startDate, String endDate, boolean isTotal) {
super();
this.app = app;
this.pageNum = pageNum;
this.pageSize = pageSize;
this.sortString = sortString;
this.searchString = searchString;
this.isASC = isASC;
this.startDate = startDate;
this.endDate = endDate;
this.isTotal = isTotal;
}
public Map<String, Object> getResult() {
return result;
}
@Override
public Map<String, Object> call() throws Exception {
logger.debug("thread start....................");
String sql = generateSql(app, pageNum, pageSize, sortString, isASC, searchString, startDate, endDate, isTotal);
System.out.println(sql);
if (isTotal) {
Integer total = 0;
try {
total = queryTotalDB(sql);
}
catch (SQLException e) {
e.printStackTrace();
}
System.out.println(total);
result.put("totalElements", total);
} else {
List<AppInfo> list = new ArrayList<>();
try {
list = queryDB(sql);
}
catch (SQLException e) {
e.printStackTrace();
}
System.out.println(list);
result.put("content", list);
}
logger.debug("thread end....................");
return result;
}
public Map<String, String> getSortMap() {
Map<String, String> map = new HashMap<>();
map.put("name", "name");
map.put("reyun", "reyun");
map.put("pkgName", "pkg_name");
map.put("company", "company");
map.put("firstCate", "first_cate");
map.put("secondCate","second_cate");
map.put("os", "os");
map.put("logoUrl", "logo_url");
map.put("newDevice", "num");
return map;
}
public String generateSql(AppInfo appInfo, int pageNum, int pageSize, String sortString, Integer isASC, String searchString, String startDate, String endDate, boolean isTotal) {
String sql = "select t1.`name`,t1.reyun,t1.pkg_name,t1.company,t1.first_cate,t1.logo_url,t1.os,t1.second_cate, sum(t2.dev_num) as num \n" +
"from (\n" +
"select * from app_info \n" +
"%s %s\n" +
") t1 \n" +
"JOIN (\n" +
"SELECT * from ot_pkg_dev_stats \n" +
"%s %s\n" +
") t2 \n" +
"on t1.pkg_name=t2.pkgname \n" +
"group by t1.`name`,t1.reyun,t1.pkg_name,t1.company,t1.first_cate,t1.logo_url,t1.os,t1.second_cate";
String orderSql = " order by %s %s";
String limitSql = " limit %s,%s";
StringBuffer app_sb = new StringBuffer();
if (appInfo.getReyun() != null) {
app_sb.append(" and ").append("reyun=").append(appInfo.getReyun());
}
if (!StringUtil.isEmpty(appInfo.getLocation())) {
app_sb.append(" and ").append("location='").append(appInfo.getLocation()).append("'");
}
if (!StringUtil.isEmpty(appInfo.getFirstCate())) {
app_sb.append(" and ").append("first_cate='").append(appInfo.getFirstCate()).append("'");
}
if (!StringUtil.isEmpty(appInfo.getSecondCate())) {
app_sb.append(" and ").append("second_cate='").append(appInfo.getSecondCate()).append("'");
}
if (!StringUtil.isEmpty(searchString)) {
StringBuffer searchsb = new StringBuffer();
searchsb.append(" name like ").append("'").append("%"+searchString+"%").append("'");
searchsb.append(" or company like ").append("'").append("%"+searchString+"%").append("'");
searchsb.append(" or pkgName like ").append("'").append("%"+searchString+"%").append("'");
app_sb.append(" and (").append(searchsb).append(")");
}
StringBuffer data_sb = new StringBuffer();
if (!StringUtil.isEmpty(startDate)) {
data_sb.append(" and ").append("ds>='").append(startDate).append("'");
}
if (!StringUtil.isEmpty(endDate)) {
data_sb.append(" and ").append("ds<='").append(startDate).append("'");
}
String result = "";
if (isTotal) {
result = String.format("select count(1) as totalcount from ("+sql+") t", app_sb.length()>0?" where ":"",
app_sb.length()>0?app_sb.substring(5):"",
data_sb.length()>0?" where ":"",
data_sb.length()>0?data_sb.substring(5):"");
} else {
String resultOrderSql = "";
if (!StringUtil.isEmpty(sortString)) {
sortString = getSortMap().get(sortString);
resultOrderSql = String.format(orderSql, sortString, isASC!=null && isASC==0?"DESC":"ASC");
}
String resultLimitSql = String.format(limitSql, pageNum*pageSize, pageSize);
result = String.format(sql + " %s %s", app_sb.length()>0?" where ":"",
app_sb.length()>0?app_sb.substring(5):"",
data_sb.length()>0?" where ":"",
data_sb.length()>0?data_sb.substring(5):"",
StringUtil.isEmpty(sortString)?"":resultOrderSql,
resultLimitSql);
}
return result;
}
public List<AppInfo> queryDB(String sql)
throws SQLException
{
List<AppInfo> list = new ArrayList<>();
Connection connection = DBUtil.newInstance().getConn();
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
AppInfo app = new AppInfo();
app.setName(rs.getString("name"));
app.setNewDevice(rs.getLong("num"));
app.setReyun(rs.getInt("reyun"));
app.setPkgName(rs.getString("pkg_name"));
app.setFirstCate(rs.getString("first_cate"));
app.setCompany(rs.getString("company"));
app.setLogoUrl(rs.getString("logo_url"));
app.setOs(rs.getString("os"));
app.setSecondCate(rs.getString("second_cate"));
list.add(app);
}
return list;
}
public int queryTotalDB(String sql)
throws SQLException
{
int result = 0;
Connection connection = DBUtil.newInstance().getConn();
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
result = rs.getInt("totalcount");
}
return result;
}
}
......@@ -3,18 +3,19 @@ package dmp.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* Created by zxy on 2017/12/28.
*/
@Entity
public class AppData
public class OtPkgDevStats
{
private Long id;
private String pkgName;
private String pkgname;
private String ds;
private Long newDevice;
private Long devNum;
@Id
@GeneratedValue
......@@ -28,34 +29,35 @@ public class AppData
this.id = id;
}
public String getPkgName()
public String getDs()
{
return pkgName;
return ds;
}
public void setPkgName(String pkgName)
public void setDs(String ds)
{
this.pkgName = pkgName;
this.ds = ds;
}
public String getDs()
public String getPkgname()
{
return ds;
return pkgname;
}
public void setDs(String ds)
public void setPkgname(String pkgname)
{
this.ds = ds;
this.pkgname = pkgname;
}
public Long getNewDevice()
public Long getDevNum()
{
return newDevice;
return devNum;
}
public void setNewDevice(Long newDevice)
public void setDevNum(Long devNum)
{
this.newDevice = newDevice;
this.devNum = devNum;
}
@Override
......@@ -63,9 +65,9 @@ public class AppData
{
return "AppData{" +
"id=" + id +
", pkgName='" + pkgName + '\'' +
", pkgname='" + pkgname + '\'' +
", ds='" + ds + '\'' +
", newDevice=" + newDevice +
", devNum=" + devNum +
'}';
}
}
package dmp.repository;
import dmp.model.AppData;
import common.model.AppInfo;
import dmp.model.OtPkgDevStats;
import dmp.model.TagCrawlerAppsWandoujia;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
......@@ -10,8 +12,7 @@ import java.util.List;
/**
* Created by Administrator on 2017/12/28.
*/
public interface AppDataRepository extends JpaRepository<AppData, Long>
public interface OtPkgDevStatsRepository
extends JpaRepository<OtPkgDevStats, Long>, JpaSpecificationExecutor<OtPkgDevStats>
{
@Query(value="select ad.pkgName,sum(ad.newDevice) as num from AppData ad where ds>=?1 and ds<=?2 group by ad.pkgName",nativeQuery=true)
List<AppData> findAllByDs(String startDate, String endDate);
}
......@@ -27,6 +27,12 @@ public class Constant {
public static String REDIS_IP_REQUEST_TIMES = redis.getString("redis.ip.requesttimes");
public static String REDIS_IP_UNKNOWN_REQUEST_TIMES = redis.getString("redis.ip.unknown.requesttimes");
public static ResourceBundle resourceBundle = ResourceBundle.getBundle("db");
public static String dburl = resourceBundle.getString("db.url");
public static String dbusername = resourceBundle.getString("db.username");
public static String dbpassword = resourceBundle.getString("db.password");
public static String dbdriver = resourceBundle.getString("db.driver");
......
package util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
/**
* 数据库工具类
* @author ruijie liruijie0603@126.com
* @date 2014-11-28
*/
public class DBUtil
{
private final static Logger logger = LoggerFactory.getLogger(DBUtil.class);
private static DBUtil dbUtil;
private String driverClass = "";
private String url = "";
private String username = "";
private String password = "";
private DBUtil() {
driverClass = Constant.dbdriver;
url = Constant.dburl;
username = Constant.dbusername;
password = Constant.dbpassword;
}
public static DBUtil newInstance() {
if (dbUtil == null) {
dbUtil = new DBUtil();
}
return dbUtil;
}
public Connection getConn() {
Connection conn = null;
try {
Class.forName(driverClass);
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
logger.error(e.getMessage(), e);
} catch (SQLException e) {
logger.error(e.getMessage(), e);
}
return conn;
}
public void insert(String sql) {
Connection conn = getConn();
Statement statement = null;
try {
statement = conn.createStatement();
statement.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (statement != null)
statement.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public ResultSet query(String sql) {
Connection conn = getConn();
Statement statement = null;
ResultSet rs = null;
try {
statement = conn.createStatement();
rs = statement.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public PreparedStatement getStatement(Connection conn, String sql) {
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException e) {
logger.error(e.getMessage(), e);
}
return pstmt;
}
public void release(ResultSet rs, PreparedStatement pstmt, Connection conn) {
try {
if (rs != null) {
rs.close();
rs = null;
}
} catch (SQLException e) {
logger.error(e.getMessage(), e);
} finally {
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
} catch (SQLException e) {
logger.error(e.getMessage(), e);
} finally {
try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
logger.error(e.getMessage(), e);
}
}
}
}
public void release(ResultSet rs,Statement pstmt, Connection conn) {
try {
if (rs != null) {
rs.close();
rs = null;
}
} catch (SQLException e) {
logger.error(e.getMessage(), e);
} finally {
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
} catch (SQLException e) {
logger.error(e.getMessage(), e);
} finally {
try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
logger.error(e.getMessage(), e);
}
}
}
}
public void ExcuteNonQueryBatch(List<String> sqlList) {
Connection conn = null;
Statement _Statement = null;
try {
if (sqlList != null && sqlList.size() > 0) {
conn = getConn();
conn.setAutoCommit(false);
for (int i = 0; i < sqlList.size(); i++) {
_Statement = conn.createStatement();
logger.info(sqlList.get(i));
_Statement.executeUpdate(sqlList.get(i));
// System.out.println(sqlList.get(i));
}
conn.commit();
}
} catch (Exception e) {
try {
if (_Statement != null)
_Statement.close();
if (conn != null)
conn.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
}
}
......@@ -94,7 +94,7 @@
<property name="jpaProperties">
<props>
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop><!-- none -->
<prop key="hibernate.connection.CharSet">utf8</prop>
......
db.driver=${datasource.driver}
db.url=${default.datasource.url}
db.username=${default.datasource.username}
db.password=${default.datasource.password}
......@@ -94,7 +94,7 @@
<property name="jpaProperties">
<props>
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop><!-- none -->
<prop key="hibernate.connection.CharSet">utf8</prop>
......
report.url=http://ec2-54-222-233-230.cn-north-1.compute.amazonaws.com.cn:9010
report.url=http://localhost:8082
awsneed=${awsneed}
profile.table=${profile.table}
event.table=${event.table}
......
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://192.168.2.57:3306/manager?characterEncoding=utf-8
db.username=root
db.password=reyun123
......@@ -6,7 +6,6 @@ track\controller\TrackAccountController.class
dmp\model\TagCrawlerAppsWandoujia.class
util\ValidateUtil.class
tkio\repository\CampaignRepository.class
dmp\model\AppData.class
util\HttpClientUtil.class
common\model\Auth.class
tkio\repository\AccountRepository.class
......@@ -17,6 +16,7 @@ exception\GlobalExceptionAdvice.class
tkio\model\Campaign.class
security\RedisTokenManager.class
tkio\model\Account.class
common\task\ReportCallable.class
security\AbstractTokenManager.class
track\repository\TrackAccountRepository.class
common\model\UserLog.class
......@@ -36,7 +36,6 @@ track\repository\TrackChannelRepository.class
tkio\service\impl\TkioAccountServiceImpl.class
util\DateUtil.class
common\model\AppCategory.class
dmp\repository\AppDataRepository.class
tkio\repository\ChannelRepository.class
security\RedisLoginStatusManager.class
common\model\Notice.class
......@@ -54,6 +53,7 @@ util\MailUtils.class
exception\TransferCurrentAccountException.class
common\repository\Account4WebRepository.class
common\repository\MenuRepository.class
common\service\impl\AppServiceImpl$2.class
common\model\City.class
common\service\impl\AppServiceImpl.class
common\repository\ReminderRepository.class
......@@ -85,6 +85,7 @@ util\ResultModel.class
dic\RoleEnum.class
util\CipherUtil.class
common\controller\UserLogController.class
dmp\repository\OtPkgDevStatsRepository.class
tkio\model\App.class
security\resolvers\LoginUserMethodArgumentsResolver.class
tkio\service\TkioAccountService.class
......@@ -100,6 +101,7 @@ common\repository\CodeRepository.class
tkio\model\SalesManLeader.class
common\controller\AppController.class
common\service\MenuService.class
util\DBUtil.class
common\repository\AppCategoryRepository.class
tkio\repository\AppRepository.class
common\service\impl\UserLogServiceImpl.class
......@@ -125,3 +127,4 @@ util\ResultStatus.class
tkio\model\IsNotified.class
track\task\AccountTask.class
tkio\model\Auth.class
dmp\model\OtPkgDevStats.class
......@@ -19,6 +19,7 @@ E:\IDEA_workspace\manager\src\main\java\tkio\task\AccountTask.java
E:\IDEA_workspace\manager\src\main\java\tkio\model\Campaign.java
E:\IDEA_workspace\manager\src\main\java\common\service\AppService.java
E:\IDEA_workspace\manager\src\main\java\util\ValidateUtil.java
E:\IDEA_workspace\manager\src\main\java\dmp\repository\OtPkgDevStatsRepository.java
E:\IDEA_workspace\manager\src\main\java\common\service\impl\MenuServiceImpl.java
E:\IDEA_workspace\manager\src\main\java\common\controller\LoginController.java
E:\IDEA_workspace\manager\src\main\java\common\model\AppCategory.java
......@@ -36,9 +37,9 @@ E:\IDEA_workspace\manager\src\main\java\track\task\AccountTask.java
E:\IDEA_workspace\manager\src\main\java\tkio\model\Auth.java
E:\IDEA_workspace\manager\src\main\java\dmp\model\TagCrawlerAppsWandoujia.java
E:\IDEA_workspace\manager\src\main\java\common\controller\UserLogController.java
E:\IDEA_workspace\manager\src\main\java\dmp\repository\AppDataRepository.java
E:\IDEA_workspace\manager\src\main\java\common\model\Code.java
E:\IDEA_workspace\manager\src\main\java\track\repository\TrackCampaignRepository.java
E:\IDEA_workspace\manager\src\main\java\common\task\ReportCallable.java
E:\IDEA_workspace\manager\src\main\java\exception\GlobalExceptionAdvice.java
E:\IDEA_workspace\manager\src\main\java\security\annotation\CurrentAccount.java
E:\IDEA_workspace\manager\src\main\java\tkio\model\UserLog.java
......@@ -55,6 +56,7 @@ E:\IDEA_workspace\manager\src\main\java\common\model\Account4Web.java
E:\IDEA_workspace\manager\src\main\java\common\repository\CityRepository.java
E:\IDEA_workspace\manager\src\main\java\tkio\repository\AppRepository.java
E:\IDEA_workspace\manager\src\main\java\util\MailUtils.java
E:\IDEA_workspace\manager\src\main\java\dmp\model\OtPkgDevStats.java
E:\IDEA_workspace\manager\src\main\java\common\model\Reminder.java
E:\IDEA_workspace\manager\src\main\java\tkio\repository\IsNotifiedRepository.java
E:\IDEA_workspace\manager\src\main\java\tkio\repository\PackageTypeRepository.java
......@@ -62,6 +64,7 @@ E:\IDEA_workspace\manager\src\main\java\tkio\model\IsNotified.java
E:\IDEA_workspace\manager\src\main\java\common\repository\AuthRepository.java
E:\IDEA_workspace\manager\src\main\java\common\repository\PaymentRepository.java
E:\IDEA_workspace\manager\src\main\java\common\model\UserLog.java
E:\IDEA_workspace\manager\src\main\java\util\DBUtil.java
E:\IDEA_workspace\manager\src\main\java\track\model\Channel.java
E:\IDEA_workspace\manager\src\main\java\tkio\repository\CampaignRepository.java
E:\IDEA_workspace\manager\src\main\java\tkio\repository\ChannelRepository.java
......@@ -105,7 +108,6 @@ E:\IDEA_workspace\manager\src\main\java\common\model\KeyValue.java
E:\IDEA_workspace\manager\src\main\java\tkio\model\App.java
E:\IDEA_workspace\manager\src\main\java\common\repository\AppCategoryRepository.java
E:\IDEA_workspace\manager\src\main\java\dmp\repository\TagCrawlerAppsWandoujiaRepository.java
E:\IDEA_workspace\manager\src\main\java\dmp\model\AppData.java
E:\IDEA_workspace\manager\src\main\java\dic\OperateObjectTypeEnum.java
E:\IDEA_workspace\manager\src\main\java\dic\RoleTypeEnum.java
E:\IDEA_workspace\manager\src\main\java\tkio\service\impl\AccountFlowRestrictServiceImpl.java
......
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