Commit aab6081e authored by 赵建伟's avatar 赵建伟

update codes

parent f280c2df
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="18c38e3b-9b7f-4a3f-b141-edcb320b1d24" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/conf/en-cn.properties" beforeDir="false" afterPath="$PROJECT_DIR$/conf/en-cn.properties" afterDir="false" />
</list>
<list default="true" id="18c38e3b-9b7f-4a3f-b141-edcb320b1d24" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
......@@ -125,7 +123,7 @@
<workItem from="1588154352798" duration="195000" />
<workItem from="1588220085338" duration="7993000" />
<workItem from="1588248522289" duration="2820000" />
<workItem from="1588344251422" duration="13761000" />
<workItem from="1588344251422" duration="16485000" />
</task>
<task id="LOCAL-00001" summary="add init codes.">
<created>1587723565207</created>
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="73604af3-3cbc-41f8-9a5f-e6a14a2ada76" name="Default Changelist" comment="add">
<change beforePath="$PROJECT_DIR$/../../../conf/en-cn.properties" beforeDir="false" afterPath="$PROJECT_DIR$/../../../conf/en-cn.properties" afterDir="false" />
</list>
<list default="true" id="73604af3-3cbc-41f8-9a5f-e6a14a2ada76" name="Default Changelist" comment="add" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
......@@ -75,8 +73,8 @@
</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="com.gmei.data.gateway.server.service" />
<recent name="com.gmei.data.gateway.server.service.impl" />
<recent name="com.gmei.data.gateway.server.service" />
<recent name="com.gmei.data.gateway.server.bean" />
</key>
</component>
......@@ -219,7 +217,7 @@
<workItem from="1588148891822" duration="2318000" />
<workItem from="1588152718016" duration="1463000" />
<workItem from="1588154601852" duration="28557000" />
<workItem from="1588344252163" duration="8979000" />
<workItem from="1588344252163" duration="11055000" />
</task>
<servers />
</component>
......
......@@ -11,6 +11,12 @@ public class BiReportEndpoint {
@Autowired
public BiReportService biReportService;
@ResponseBody
@RequestMapping(value = "/execSql")
public int execSql(@RequestParam String name){
return biReportService.genExcel(name);
}
@ResponseBody
@RequestMapping(value = "/genExcel")
public int genExcel(@RequestParam String name){
......
package com.gmei.data.gateway.server.service;
public interface BiReportService {
int execSql(String name);
int genExcel(String name);
int sendEmail(String to,String cc,String name);
}
package com.gmei.data.gateway.server.service;
import com.gmei.data.gateway.server.dto.ExcelGenDto;
public interface HivesqlService {
int executeSql(String name);
}
......@@ -2,10 +2,7 @@ package com.gmei.data.gateway.server.service.impl;
import com.gmei.data.gateway.server.common.Constants;
import com.gmei.data.gateway.server.dto.ExcelGenDto;
import com.gmei.data.gateway.server.service.BiReportService;
import com.gmei.data.gateway.server.service.EmailService;
import com.gmei.data.gateway.server.service.ExcelService;
import com.gmei.data.gateway.server.service.SparksqlService;
import com.gmei.data.gateway.server.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -23,15 +20,22 @@ public class BiReportServiceImpl implements BiReportService {
@Autowired
public ExcelService excelService;
@Autowired
public HivesqlService hivesqlService;
@Autowired
public SparksqlService sparksqlService;
@Override
public int execSql(String name){
return hivesqlService.executeSql(name);
}
@Override
public int genExcel(String name){
ExcelGenDto resultDto = sparksqlService.getResultDto(name);
if(null == resultDto){
return Constants.FAIL;
}else{
return excelService.genExcel(resultDto, "测试示例");
return excelService.genExcel(resultDto, name);
}
}
......
package com.gmei.data.gateway.server.service.impl;
import com.gmei.data.gateway.server.service.HivesqlService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/**
* @ClassName HivesqlServiceImpl
* @Author apple
* @Date 2020/5/01
* @Version V1.0
**/
@Service
public class HivesqlServiceImpl implements HivesqlService {
@Value("${sql.input.path}")
private String sqlPath;
@Value("${datasource.hiveSql.jdbcUrl}")
private String hiveSqlJdbcUrl;
private static final Logger logger = LoggerFactory.getLogger(HivesqlServiceImpl.class);
@Override
public int executeSql(String name){
File sqlDir = new File(sqlPath + name);
File[] files = sqlDir.listFiles();
for(File file : files){
BufferedReader reader = null;
StringBuffer sbf = new StringBuffer();
try {
reader = new BufferedReader(new FileReader(file));
String tempStr;
while ((tempStr = reader.readLine()) != null) {
sbf.append("\n").append(tempStr);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
continue;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
logger.error(e1.getMessage());
continue;
}
}
}
String hql = sbf.toString();
Connection conn = null;
try{
conn = DriverManager.getConnection(hiveSqlJdbcUrl,"data","");
Statement statement = conn.createStatement();
int updateCount = statement.executeUpdate(hql);
if(updateCount > 0){
logger.info("*** Execute success, hql: {}",hql);
}else{
logger.warn("*** Execute finish, hql: {}",hql);
}
}catch (Exception e){
e.printStackTrace();
logger.error("*** Execute failed, error message: {}, hql: {}",e.getMessage(),hql);
return 1;
}
}
return 0;
}
}
......@@ -27,8 +27,8 @@ public class SparksqlServiceImpl implements SparksqlService {
@Value("${sql.input.path}")
private String sqlPath;
@Value("${datasource.sparksql.jdbcUrl}")
private String sparksqlJdbcUrl;
@Value("${datasource.sparkSql.jdbcUrl}")
private String sparkSqlJdbcUrl;
@Value("${proper.file.path}")
private String properFilePath;
private static final Logger logger = LoggerFactory.getLogger(SparksqlServiceImpl.class);
......@@ -84,7 +84,7 @@ public class SparksqlServiceImpl implements SparksqlService {
String hql = sbf.toString();
Connection conn = null;
try{
conn = DriverManager.getConnection(sparksqlJdbcUrl,"data","");
conn = DriverManager.getConnection(sparkSqlJdbcUrl,"data","");
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery(hql);
ResultSetMetaData metaData = rs.getMetaData();
......
......@@ -10,8 +10,10 @@ spring:
default-encoding: UTF-8
datasource:
sparksql:
sparkSql:
jdbcUrl: jdbc:hive2://bj-gm-prod-cos-datacenter003:10010
hiveSql:
jdbcUrl: jdbc:hive2://bj-gm-prod-cos-datacenter006:10000
#---email send config---
mail:
......
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