作者 张晓杰

Merge branch 'dev' of http://39.105.222.208:1024/leihd/factory-java into dev

  1 +package org.jeecg.common.system.base.controller;
  2 +
  3 +import org.springframework.beans.factory.annotation.Qualifier;
  4 +import org.springframework.beans.factory.annotation.Value;
  5 +import org.springframework.boot.context.properties.ConfigurationProperties;
  6 +import org.springframework.boot.jdbc.DataSourceBuilder;
  7 +import org.springframework.context.annotation.Bean;
  8 +import org.springframework.context.annotation.Configuration;
  9 +import org.springframework.context.annotation.PropertySource;
  10 +import org.springframework.jdbc.datasource.DataSourceTransactionManager;
  11 +import org.springframework.jdbc.datasource.DriverManagerDataSource;
  12 +import org.springframework.transaction.PlatformTransactionManager;
  13 +import org.springframework.transaction.annotation.EnableTransactionManagement;
  14 +
  15 +import javax.sql.DataSource;
  16 +
  17 +@Configuration
  18 +@EnableTransactionManagement
  19 +public class AppConfig {
  20 + @Bean
  21 + public DataSource dataSource() {
  22 + // 配置数据源
  23 + DriverManagerDataSource dataSource = new DriverManagerDataSource();
  24 + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
  25 + dataSource.setUrl("jdbc:mysql://rm-2zeiuncjm75qti641ho.mysql.rds.aliyuncs.com:3306/jeecg-boot");
  26 + dataSource.setUsername("ntsd_root");
  27 + dataSource.setPassword("L3bHRJwg6lJ2SC4WFfGA");
  28 + return dataSource;
  29 + }
  30 + @Bean
  31 + public PlatformTransactionManager transactionManager(DataSource dataSource) {
  32 + // 配置事务管理器
  33 + return new DataSourceTransactionManager(dataSource);
  34 + }
  35 +}
@@ -313,7 +313,9 @@ public class JeecgController<T, S extends IService<T>> { @@ -313,7 +313,9 @@ public class JeecgController<T, S extends IService<T>> {
313 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); 313 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
314 //update-end-author:taoyan date:20190528 for:批量插入数据 314 //update-end-author:taoyan date:20190528 for:批量插入数据
315 return Result.ok("文件导入成功!数据行数:" + list.size()); 315 return Result.ok("文件导入成功!数据行数:" + list.size());
316 - } catch (Exception e) { 316 + }catch (ExcelImportException e) {
  317 + return Result.error("文件导入失败,导入数据格式错误");
  318 + }catch (Exception e) {
317 //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示 319 //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
318 String msg = e.getMessage(); 320 String msg = e.getMessage();
319 log.error(msg, e); 321 log.error(msg, e);
@@ -378,7 +380,9 @@ public class JeecgController<T, S extends IService<T>> { @@ -378,7 +380,9 @@ public class JeecgController<T, S extends IService<T>> {
378 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); 380 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
379 //update-end-author:taoyan date:20190528 for:批量插入数据 381 //update-end-author:taoyan date:20190528 for:批量插入数据
380 return Result.ok("文件导入成功!数据行数:" + list.size()); 382 return Result.ok("文件导入成功!数据行数:" + list.size());
381 - } catch (Exception e) { 383 + }catch (ExcelImportException e) {
  384 + return Result.error("文件导入失败,导入数据格式错误");
  385 + }catch (Exception e) {
382 //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示 386 //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
383 String msg = e.getMessage(); 387 String msg = e.getMessage();
384 log.error(msg, e); 388 log.error(msg, e);
@@ -302,7 +302,8 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService @@ -302,7 +302,8 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService
302 302
303 //工资导入 303 //工资导入
304 304
305 - protected Result<?> importExcelgz(HttpServletRequest request, HttpServletResponse response, Class<T> clazz, Class<b> base) { 305 + @Transactional
  306 + public Result<?> importExcelgz(HttpServletRequest request, HttpServletResponse response, Class<T> clazz, Class<b> base) {
306 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; 307 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
307 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); 308 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
308 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { 309 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
@@ -314,6 +315,7 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService @@ -314,6 +315,7 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService
314 315
315 // params.setKeyIndex(1); 316 // params.setKeyIndex(1);
316 params.setNeedSave(true); 317 params.setNeedSave(true);
  318 +
317 try { 319 try {
318 List<T> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params); 320 List<T> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
319 321
@@ -384,6 +386,8 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService @@ -384,6 +386,8 @@ public class JeecgController2<T, t, b, V extends IService<t>, S extends IService
384 return Result.error("文件数据为空"); 386 return Result.error("文件数据为空");
385 } 387 }
386 System.out.println("导入的数据:"+shuju); 388 System.out.println("导入的数据:"+shuju);
  389 + System.out.println("数据库数据:"+service.list());
  390 +
387 service.saveBatch(shuju); 391 service.saveBatch(shuju);
388 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); 392 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
389 //update-end-author:taoyan date:20190528 for:批量插入数据 393 //update-end-author:taoyan date:20190528 for:批量插入数据
@@ -247,7 +247,7 @@ public class TblSalaryCalculationController extends JeecgController2<TblSalaryCa @@ -247,7 +247,7 @@ public class TblSalaryCalculationController extends JeecgController2<TblSalaryCa
247 return Result.OK("成功!"); 247 return Result.OK("成功!");
248 } 248 }
249 // tblSalaryCalculationService.qi(); 249 // tblSalaryCalculationService.qi();
250 - return Result.OK("计算失败,没有该月数据!"); 250 + return Result.error("计算失败,没有该月数据!");
251 } 251 }
252 252
253 253