白名单批量上传

pull/1/head
bmpandlcm 11 months ago
parent e8a638e32d
commit a388f44dfb

@ -37,12 +37,12 @@ public class MyEnvironmentPostProcessor implements EnvironmentPostProcessor {
fileNewproperties.createNewFile(); fileNewproperties.createNewFile();
} }
properties.load(new FileInputStream(path)); properties.load(new FileInputStream(path));
String DBType = properties.getProperty("DBType") == null ? "1" : properties.getProperty("DBType"); String DBType = properties.getProperty("WhiteDBType") == null ? "1" : properties.getProperty("WhiteDBType");
Newproperties.load(new FileInputStream(NewPath)); Newproperties.load(new FileInputStream(NewPath));
properties.setProperty("spring.logback.logPath",PathUtil.TomcatPath+"/logs"); properties.setProperty("spring.logback.logPath",PathUtil.TomcatPath+"/logs");
properties.setProperty("spring.datasource.url",properties.getProperty("DBUrl")); properties.setProperty("spring.datasource.url",properties.getProperty("WhiteDBUrl"));
properties.setProperty("spring.datasource.username",properties.getProperty("DBUserName")); properties.setProperty("spring.datasource.username",properties.getProperty("WhiteDBUserName"));
properties.setProperty("spring.datasource.password",PassWordUtils.decrypt(properties.getProperty("DBPassWord"))); properties.setProperty("spring.datasource.password",PassWordUtils.decrypt(properties.getProperty("WhiteDBPassWord")));
if(DBType.equals("1")){ if(DBType.equals("1")){
properties.setProperty("spring.datasource.driver-class-name",Newproperties.getProperty("sqlClassName")); properties.setProperty("spring.datasource.driver-class-name",Newproperties.getProperty("sqlClassName"));
properties.setProperty("spring.datasource.validationQuery",Newproperties.getProperty("sqlvalidationQuery")); properties.setProperty("spring.datasource.validationQuery",Newproperties.getProperty("sqlvalidationQuery"));

@ -12,13 +12,13 @@ public class MybatisPlusConfig {
@Bean @Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() { public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
if(PropertiesUtil.getValue("DBType").equals("1")){ if(PropertiesUtil.getValue("WhiteDBType").equals("1")){
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQL_SERVER2005)); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQL_SERVER2005));
}else if(PropertiesUtil.getValue("DBType").equals("2")){ }else if(PropertiesUtil.getValue("WhiteDBType").equals("2")){
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.ORACLE)); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.ORACLE));
}else if(PropertiesUtil.getValue("DBType").equals("3")){ }else if(PropertiesUtil.getValue("WhiteDBType").equals("3")){
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.DM)); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.DM));
}else if(PropertiesUtil.getValue("DBType").equals("4")){ }else if(PropertiesUtil.getValue("WhiteDBType").equals("4")){
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
} }
return interceptor; return interceptor;

@ -0,0 +1,166 @@
package com.nmgs.controller;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.nmgs.config.ResultData;
import com.nmgs.util.LogUtil;
import com.nmgs.util.PubTools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/whiteBatchImport")
@Api(tags = "白名单批量导入")
public class WhiteBatchImportController {
//实现Spring Boot 的文件下载功能,映射网址为/download
@ApiOperation(value = "模板下载",httpMethod = "GET",ignoreJsonView = false )
@ApiImplicitParams(
@ApiImplicitParam(value = "fileName",defaultValue = "gasstation")
)
@RequestMapping(value = "/download", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
@ResponseBody
public String downloadFile(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
String fileName = request.getParameter("fileName");
if(PubTools.isNull(fileName)){
fileName="白名单模板空白";
}
fileName =fileName+".xlsx";
String fileP=com.nmgs.util.PathUtil.webappsPath+"//"+ fileName;
LogUtil.WriteLog_Info("模板下载地址====="+fileP,"WhiteBatchImportController");
File file = new File(fileP);
// 如果文件名存在,则进行下载
if (file.exists()) {
// 配置文件下载
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
// 下载文件能正常显示中文
response.addHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
// 实现文件下载
byte[] buffer = new byte[1024*1024*100];
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
OutputStream os = response.getOutputStream();
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}
System.out.println("Download the song successfully!");
return "下载成功!";
}
catch (Exception e) {
System.out.println("Download the song failed!");
return "下载失败!";
}
finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//return "Download the song successfully!";
}
}else{
return file.getPath()+"文件不存在!";
}
}
/**
* excel
* @param file
* @throws Exception
*/
@PostMapping("/import")
public ResultData<String> importExcel(MultipartFile file) throws Exception {
InputStream inputStream = file.getInputStream();
ExcelReader reader = ExcelUtil.getReader(inputStream);
// 方式1(推荐) 通过 javabean的方式读取Excel内的对象但是要求表头必须是英文跟javabean的属性要对应起来
// List<User> list = reader.readAll(User.class);
// 方式2忽略表头的中文直接读取表的内容
List<List<Object>> read = reader.read(1);
/* List<User> users = CollUtil.newArrayList();
for (List<Object> row : list) {
User user = new User();
user.setUsername(row.get(0).toString());
user.setPassword(row.get(1).toString());
user.setNickname(row.get(2).toString());
user.setEmail(row.get(3).toString());
user.setPhone(row.get(4).toString());
user.setAddress(row.get(5).toString());
user.setAvatarUrl(row.get(6).toString());
users.add(user);
}*/
return ResultData.success("","",1);
}
@PostMapping("/uploadFile")
public ResultData<String> uploadFile(HttpServletRequest request, HttpServletResponse response,@RequestParam("file") MultipartFile file) throws UnsupportedEncodingException {
System.out.println("文件上传开始");
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
// 下载文件能正常显示中文
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
//当前项目的目录
String path = com.nmgs.util.PathUtil.webappsPath + "\\CarNoFile\\";
//每天创建一个文件目录
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
String fileDirName = sdf.format(new Date());
String folderPath = path + fileDirName;
System.out.println("文件路径=====>"+folderPath);
File fileTemp=new File(folderPath);
if (!fileTemp.exists())
{
fileTemp.mkdirs();
}
String fileName="";
if (file != null){
try
{
fileName = file.getOriginalFilename();
System.out.println("上传的文件名称======>"+fileName);
File fileDocument=new File(folderPath,fileName);
File fileExists=new File(folderPath+"//"+fileName);
if(fileExists.exists()){
fileExists.delete();
}else{
fileDocument.mkdir();
file.transferTo(fileDocument);
}
}
catch (Exception ex)
{
System.out.println("文件异常====="+ ex.getMessage());
return ResultData.fail("文件异常====="+ ex.getMessage());
}
}
return ResultData.success(1,fileName);
}
}

@ -28,7 +28,7 @@ public class WhiteAccountSeriveImpl implements IWhiteAccountSerive {
@Override @Override
public Page<WhiteAccountText> getWhiteAccountTextByPage(Map<String, Object> params) { public Page<WhiteAccountText> getWhiteAccountTextByPage(Map<String, Object> params) {
//从配置文件中读取数据库连接类型 //从配置文件中读取数据库连接类型
params.put("DBTYPE", PropertiesUtil.getValue("DBType")); params.put("DBTYPE", PropertiesUtil.getValue("WhiteDBType"));
//设置分页 //设置分页
Integer pageNum = (Integer) params.get("pageNum"); Integer pageNum = (Integer) params.get("pageNum");
Integer pageSize = (Integer) params.get("pageSize"); Integer pageSize = (Integer) params.get("pageSize");
@ -103,7 +103,7 @@ public class WhiteAccountSeriveImpl implements IWhiteAccountSerive {
@Override @Override
public List<WhiteAccountText> getWhiteAccountText(Map<String, Object> params) { public List<WhiteAccountText> getWhiteAccountText(Map<String, Object> params) {
//从配置文件中读取数据库连接类型 //从配置文件中读取数据库连接类型
params.put("DBTYPE", PropertiesUtil.getValue("DBType")); params.put("DBTYPE", PubTools.getDBType());
List<WhiteAccountText> records = whiteAccountMapper.getWhiteAccountText(params); List<WhiteAccountText> records = whiteAccountMapper.getWhiteAccountText(params);
return records; return records;
} }

@ -31,7 +31,7 @@ public class WhiteCarnoDicSeviceImpl implements IWhiteCarnoDicService {
@Override @Override
public Page<WhiteCarnoDic> getWhiteCarnoDicByPage(Map<String, Object> params) { public Page<WhiteCarnoDic> getWhiteCarnoDicByPage(Map<String, Object> params) {
//从配置文件中读取数据库连接类型 //从配置文件中读取数据库连接类型
params.put("DBTYPE", PropertiesUtil.getValue("DBType")); params.put("DBTYPE", PubTools.getDBType());
//设置分页 //设置分页
Integer pageNum = (Integer) params.get("pageNum"); Integer pageNum = (Integer) params.get("pageNum");
Integer pageSize = (Integer) params.get("pageSize"); Integer pageSize = (Integer) params.get("pageSize");
@ -124,7 +124,7 @@ public class WhiteCarnoDicSeviceImpl implements IWhiteCarnoDicService {
@Override @Override
public List<WhiteCarnoDic> getWhiteCarnoDicList(Map<String, Object> params) { public List<WhiteCarnoDic> getWhiteCarnoDicList(Map<String, Object> params) {
//从配置文件中读取数据库连接类型 //从配置文件中读取数据库连接类型
params.put("DBTYPE", PropertiesUtil.getValue("DBType")); params.put("DBTYPE", PubTools.getDBType());
List<WhiteCarnoDic> records = whiteCarnoDicMapper.getWhiteCarnoDicList(params); List<WhiteCarnoDic> records = whiteCarnoDicMapper.getWhiteCarnoDicList(params);
return records; return records;
} }

@ -40,7 +40,7 @@ public class WhiteCarnoListSeriveImpl implements IWhiteCarnoListSerive {
@Override @Override
public Page<WhiteCarnoList> getWhiteCarnoListByPage(Map<String, Object> params) { public Page<WhiteCarnoList> getWhiteCarnoListByPage(Map<String, Object> params) {
//从配置文件中读取数据库连接类型 //从配置文件中读取数据库连接类型
params.put("DBTYPE", PropertiesUtil.getValue("DBType")); params.put("DBTYPE", PubTools.getDBType());
//设置分页 //设置分页
Integer pageNum = (Integer) params.get("pageNum"); Integer pageNum = (Integer) params.get("pageNum");
Integer pageSize = (Integer) params.get("pageSize"); Integer pageSize = (Integer) params.get("pageSize");
@ -272,7 +272,7 @@ public class WhiteCarnoListSeriveImpl implements IWhiteCarnoListSerive {
@Override @Override
public List<WhiteCarnoList> getWhiteCarnoList(Map<String, Object> params) { public List<WhiteCarnoList> getWhiteCarnoList(Map<String, Object> params) {
//从配置文件中读取数据库连接类型 //从配置文件中读取数据库连接类型
params.put("DBTYPE", PropertiesUtil.getValue("DBType")); params.put("DBTYPE", PubTools.getDBType());
String whiteOutTimeT = PropertiesUtil.getValue("WhiteOutTime"); String whiteOutTimeT = PropertiesUtil.getValue("WhiteOutTime");
params.put("CURRENTDATE",PubTools.getCurrentDate()); params.put("CURRENTDATE",PubTools.getCurrentDate());
params.put("CURRENTWILLDATE",PubTools.getAddNumDate(Integer.parseInt(whiteOutTimeT))); params.put("CURRENTWILLDATE",PubTools.getAddNumDate(Integer.parseInt(whiteOutTimeT)));
@ -302,7 +302,7 @@ public class WhiteCarnoListSeriveImpl implements IWhiteCarnoListSerive {
@Override @Override
public int batchUpdateById(Map<String, Object> req) throws Exception { public int batchUpdateById(Map<String, Object> req) throws Exception {
try{ try{
req.put("DBType",PropertiesUtil.getValue("DBType")); req.put("DBType",PubTools.getDBType());
if(!PubTools.isEmpty(req.get("id"))){ if(!PubTools.isEmpty(req.get("id"))){
String[] ids = req.get("id").toString().split(","); String[] ids = req.get("id").toString().split(",");
int i = whiteCarnoListMapper.batchUpdateById(ids, req); int i = whiteCarnoListMapper.batchUpdateById(ids, req);
@ -342,7 +342,7 @@ public class WhiteCarnoListSeriveImpl implements IWhiteCarnoListSerive {
@Override @Override
public int publishVersion(Map<String, Object> req) throws Exception { public int publishVersion(Map<String, Object> req) throws Exception {
req.put("DBType",PropertiesUtil.getValue("DBType")); req.put("DBType",PubTools.getDBType());
int ret= this.whiteCarnoListMapper.publishVersion(req); int ret= this.whiteCarnoListMapper.publishVersion(req);
if(ret>-1){ if(ret>-1){
WhiteCarnoLogTable wclt = new WhiteCarnoLogTable(); WhiteCarnoLogTable wclt = new WhiteCarnoLogTable();
@ -369,7 +369,7 @@ public class WhiteCarnoListSeriveImpl implements IWhiteCarnoListSerive {
@Override @Override
public Map<String,String> getVersion(Map<String, Object> req) throws Exception { public Map<String,String> getVersion(Map<String, Object> req) throws Exception {
req.put("DBType",PropertiesUtil.getValue("DBType")); req.put("DBType",PubTools.getDBType());
String verN = ""; String verN = "";
String oldVerno = "0"; String oldVerno = "0";
Map<String,String> map=new HashMap<String,String>(); Map<String,String> map=new HashMap<String,String>();

@ -11,6 +11,7 @@ import com.nmgs.mapper.WhiteOperationLogMapper;
import com.nmgs.service.IOperationLogService; import com.nmgs.service.IOperationLogService;
import com.nmgs.service.IWhiteCarnoLogService; import com.nmgs.service.IWhiteCarnoLogService;
import com.nmgs.util.PropertiesUtil; import com.nmgs.util.PropertiesUtil;
import com.nmgs.util.PubTools;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -33,7 +34,7 @@ public class WhiteCarnoLogServiceImpl extends ServiceImpl<WhiteCarnoLogMapper,Wh
@Override @Override
public Page<WhiteCarnoLogTable> getWhiteCarnoLogByPage(Map<String, Object> params) { public Page<WhiteCarnoLogTable> getWhiteCarnoLogByPage(Map<String, Object> params) {
//从配置文件中读取数据库连接类型 //从配置文件中读取数据库连接类型
params.put("DBTYPE", PropertiesUtil.getValue("DBType")); params.put("DBTYPE", PubTools.getDBType());
//设置分页 //设置分页
Integer pageNum = (Integer) params.get("pageNum"); Integer pageNum = (Integer) params.get("pageNum");
Integer pageSize = (Integer) params.get("pageSize"); Integer pageSize = (Integer) params.get("pageSize");

@ -183,6 +183,10 @@ public class PubTools {
return relseltflag; return relseltflag;
} }
public static String getDBType(){
return PropertiesUtil.getValue("WhiteDBType");
}
} }

Loading…
Cancel
Save