Commit 1931eaaf by Suvalue

table导出excel接口

parent 88c9efb5
...@@ -90,6 +90,11 @@ ...@@ -90,6 +90,11 @@
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> </dependency>
<dependency>
<groupId>me.chyxion</groupId>
<artifactId>table-to-xls</artifactId>
<version>0.0.1-RELEASE</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
...@@ -151,6 +156,7 @@ ...@@ -151,6 +156,7 @@
<!--endregion--> <!--endregion-->
</dependencies> </dependencies>
</plugin> </plugin>
</plugins> </plugins>
......
package com.bsoft.api.controller;
import com.bsoft.api.common.Result;
import com.bsoft.api.service.ExcelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@Api(tags = "Excel导出")
@RestController
public class ExcelController {
@Autowired
private ExcelService excelService;
@PostMapping("xls")
@ApiOperation("将Table转换为Xls")
public Object tableToXls(HttpServletRequest request,@RequestBody String tableStr){
String realPath = request.getSession().getServletContext().getRealPath("/");
System.out.println(realPath);
String fileUrl =excelService.tableToXls(realPath,tableStr);
return Result.success(fileUrl);
}
}
package com.bsoft.api.service;
import com.bsoft.api.common.handlers.GlobalExceptionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public interface ExcelService {
static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
String tableToXls(String realPath,String tableStr);
}
package com.bsoft.api.service.Impl;
import com.bsoft.api.service.ExcelService;
import me.chyxion.xls.TableToXls;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileOutputStream;
import java.util.UUID;
@Service
public class ExcelServiceImpl implements ExcelService {
@Override
public String tableToXls(String realPath, String tableStr) {
try {
File directory = new File(realPath+"/excel");
if (!directory .exists() && !directory .isDirectory())
{
directory .mkdir();
}
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
String fileName = uuid+".xls";
FileOutputStream fout = new FileOutputStream(directory+"/"+fileName);
TableToXls.process(tableStr, fout);
fout.close();
return "excel/"+fileName;
}catch (Exception ex){
log.error(ex.getMessage(), ex);
}
return null;
}
}
...@@ -5,7 +5,7 @@ jdbc.password=123456 ...@@ -5,7 +5,7 @@ jdbc.password=123456
jdbc.driverClass=com.mysql.jdbc.Driver jdbc.driverClass=com.mysql.jdbc.Driver
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.username=ll spring.datasource.username=ch
spring.datasource.password=123456 spring.datasource.password=123456
spring.datasource.url=jdbc:oracle:thin:@192.168.18.171:1521:his spring.datasource.url=jdbc:oracle:thin:@192.168.18.171:1521:his
......
...@@ -14,3 +14,4 @@ config.path.exclude[0]=/login ...@@ -14,3 +14,4 @@ config.path.exclude[0]=/login
spring.aop.auto=true spring.aop.auto=true
# Whether subclass-based (CGLIB) proxies are to be created (true) # Whether subclass-based (CGLIB) proxies are to be created (true)
spring.aop.proxy-target-class=false spring.aop.proxy-target-class=false
spring.jmx.enabled=false
\ No newline at end of file
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
where ID = #{id,jdbcType=DECIMAL} where ID = #{id,jdbcType=DECIMAL}
</select> </select>
<select id="selectByCode" resultMap="BaseResultMap"> <select id="selectByCode" resultMap="BaseResultMap">
select d.ID, d.CREATE_DATE, d.CREATE_USERID, d.STATE, d.MDC_CODE, d.MDC_NAME, d."DATE",d.MDC_NUM, select DISTINCT d.ID, d.CREATE_DATE, d.CREATE_USERID, d.STATE, d.MDC_CODE, d.MDC_NAME, d."DATE",d.MDC_NUM,
d.PARENT_ID, d."LEVEL", d.ORG_ID, d.ORG_NAME d.PARENT_ID, d."LEVEL", d.ORG_ID, d.ORG_NAME
from SER_DISEASE d,SER_DISEASE_DOC_RS rs from SER_DISEASE d,SER_DISEASE_DOC_RS rs
where d.STATE=1 where d.STATE=1
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<!-- &lt;!&ndash; 主键生成方式 &ndash;&gt;--> <!-- &lt;!&ndash; 主键生成方式 &ndash;&gt;-->
<!-- <generatedKey column="id" sqlStatement="select SEQ_SYS_USER_ID.nextval from dual" identity="true" />--> <!-- <generatedKey column="id" sqlStatement="select SEQ_SYS_USER_ID.nextval from dual" identity="true" />-->
<!-- </table>--> <!-- </table>-->
<table tableName="SER_DIM_VALUE" schema="ll" > <table tableName="SER_DIM_VALUE" >
<generatedKey column="id" sqlStatement="select SEQ_SER_DIM_VALUE_ID.nextval from dual" identity="true" /> <generatedKey column="id" sqlStatement="select SEQ_SER_DIM_VALUE_ID.nextval from dual" identity="true" />
</table> </table>
<!-- <table tableName="DIC_IND" schema="ll" >--> <!-- <table tableName="DIC_IND" schema="ll" >-->
......
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