|
@@ -1,24 +1,31 @@
|
|
|
package com.ruoyi.project.training.bccnew.controller;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.ruoyi.common.utils.file.ExcelUtils;
|
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
|
-import com.ruoyi.framework.config.RuoYiConfig;
|
|
|
-import com.ruoyi.project.training.bccnew.domain.TTsFirstplanTmpl;
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
|
|
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
|
|
-import com.ruoyi.project.training.bccnew.domain.TTsFlplanTmpl;
|
|
|
-import com.ruoyi.project.training.bccnew.service.ITTsFlplanTmplService;
|
|
|
+import com.ruoyi.framework.config.RuoYiConfig;
|
|
|
import com.ruoyi.framework.web.controller.BaseController;
|
|
|
import com.ruoyi.framework.web.domain.AjaxResult;
|
|
|
-import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.framework.web.page.TableDataInfo;
|
|
|
+import com.ruoyi.project.training.bccnew.domain.TTsFlplanTmpl;
|
|
|
+import com.ruoyi.project.training.bccnew.service.ITTsFlplanTmplService;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* 分离培训模版Controller
|
|
|
*
|
|
@@ -27,8 +34,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/training/flPlan")
|
|
|
-public class TTsFlplanTmplController extends BaseController
|
|
|
-{
|
|
|
+public class TTsFlplanTmplController extends BaseController {
|
|
|
@Autowired
|
|
|
private ITTsFlplanTmplService tTsFlplanTmplService;
|
|
|
|
|
@@ -37,8 +43,7 @@ public class TTsFlplanTmplController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('training:flPlan:list')")
|
|
|
@GetMapping("/list")
|
|
|
- public TableDataInfo list(TTsFlplanTmpl tTsFlplanTmpl)
|
|
|
- {
|
|
|
+ public TableDataInfo list(TTsFlplanTmpl tTsFlplanTmpl) {
|
|
|
startPage();
|
|
|
List<TTsFlplanTmpl> list = tTsFlplanTmplService.selectTTsFlplanTmplList(tTsFlplanTmpl);
|
|
|
return getDataTable(list);
|
|
@@ -50,8 +55,7 @@ public class TTsFlplanTmplController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('training:flPlan:export')")
|
|
|
@Log(title = "分离培训模版", businessType = BusinessType.EXPORT)
|
|
|
@GetMapping("/export")
|
|
|
- public AjaxResult export(TTsFlplanTmpl tTsFlplanTmpl)
|
|
|
- {
|
|
|
+ public AjaxResult export(TTsFlplanTmpl tTsFlplanTmpl) {
|
|
|
List<TTsFlplanTmpl> list = tTsFlplanTmplService.selectTTsFlplanTmplList(tTsFlplanTmpl);
|
|
|
ExcelUtil<TTsFlplanTmpl> util = new ExcelUtil<TTsFlplanTmpl>(TTsFlplanTmpl.class);
|
|
|
return util.exportExcel(list, "flPlan");
|
|
@@ -62,8 +66,7 @@ public class TTsFlplanTmplController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('training:flPlan:query')")
|
|
|
@GetMapping(value = "/{id}")
|
|
|
- public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
|
- {
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") Long id) {
|
|
|
return AjaxResult.success(tTsFlplanTmplService.selectTTsFlplanTmplById(id));
|
|
|
}
|
|
|
|
|
@@ -73,8 +76,7 @@ public class TTsFlplanTmplController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('training:flPlan:add')")
|
|
|
@Log(title = "分离培训模版", businessType = BusinessType.INSERT)
|
|
|
@PostMapping
|
|
|
- public AjaxResult add(@RequestBody TTsFlplanTmpl tTsFlplanTmpl)
|
|
|
- {
|
|
|
+ public AjaxResult add(@RequestBody TTsFlplanTmpl tTsFlplanTmpl) {
|
|
|
return toAjax(tTsFlplanTmplService.insertTTsFlplanTmpl(tTsFlplanTmpl));
|
|
|
}
|
|
|
|
|
@@ -84,8 +86,7 @@ public class TTsFlplanTmplController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('training:flPlan:edit')")
|
|
|
@Log(title = "分离培训模版", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping
|
|
|
- public AjaxResult edit(@RequestBody TTsFlplanTmpl tTsFlplanTmpl)
|
|
|
- {
|
|
|
+ public AjaxResult edit(@RequestBody TTsFlplanTmpl tTsFlplanTmpl) {
|
|
|
return toAjax(tTsFlplanTmplService.updateTTsFlplanTmpl(tTsFlplanTmpl));
|
|
|
}
|
|
|
|
|
@@ -94,9 +95,8 @@ public class TTsFlplanTmplController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('training:flPlan:remove')")
|
|
|
@Log(title = "分离培训模版", businessType = BusinessType.DELETE)
|
|
|
- @DeleteMapping("/{ids}")
|
|
|
- public AjaxResult remove(@PathVariable Long[] ids)
|
|
|
- {
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids) {
|
|
|
return toAjax(tTsFlplanTmplService.deleteTTsFlplanTmplByIds(ids));
|
|
|
}
|
|
|
|
|
@@ -113,4 +113,85 @@ public class TTsFlplanTmplController extends BaseController
|
|
|
}
|
|
|
return AjaxResult.error("上传失败,请联系管理员");
|
|
|
}
|
|
|
+
|
|
|
+ @PreAuthorize("@ss.hasPermi('training:flPlan:add')")
|
|
|
+ @Log(title = "分离培训模版", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping("/importData")
|
|
|
+ public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ //获取操作人员ID
|
|
|
+ Long userId = getUserId();
|
|
|
+ //报错行数统计
|
|
|
+ List<Integer> failRow = new ArrayList<Integer>();
|
|
|
+ Workbook workbook = ExcelUtils.getWorkBook(file);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ List<TTsFlplanTmpl> list = new ArrayList<>();
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ int failNumber = 0;
|
|
|
+ for (int i = 1; i <= rowNum; i++) {
|
|
|
+ try {
|
|
|
+ logger.info("读取行数:" + i);
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ if (row == null) {
|
|
|
+ sheet.removeRow(row);
|
|
|
+ rowNum++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int cellNum = row.getLastCellNum();
|
|
|
+ TTsFlplanTmpl entity = new TTsFlplanTmpl();
|
|
|
+ for (int j = 0; j < cellNum; j++) {
|
|
|
+ Cell cell = row.getCell(j);
|
|
|
+ if (cell == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String cellValue = ExcelUtils.getCellValue(cell);
|
|
|
+ logger.info("cellValue:" + cellValue);
|
|
|
+ if (j == 0) {
|
|
|
+ entity.setSortTmpl(cellValue);
|
|
|
+ } else if (j == 1) {
|
|
|
+ entity.setCourseCode(cellValue);
|
|
|
+ } else if (j == 2) {
|
|
|
+ entity.setTopic(cellValue);
|
|
|
+ } else if (j == 3) {
|
|
|
+ entity.setContent(cellValue);
|
|
|
+ } else if (j == 4) {
|
|
|
+ entity.setCourseDay(Long.valueOf(cellValue));
|
|
|
+ } else if (j == 5) {
|
|
|
+ entity.setCourseHour(Long.valueOf(cellValue));
|
|
|
+ } else if (j == 6) {
|
|
|
+ entity.setDetailPlan(cellValue);
|
|
|
+ } else if (j == 7) {
|
|
|
+ entity.setTrainer(cellValue);
|
|
|
+ } else if (j == 8) {
|
|
|
+ entity.setTimerNeed(Long.valueOf(cellValue));
|
|
|
+ } else if (j == 9) {
|
|
|
+ entity.setRemarks(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ entity.setCreaterCode(userId.toString());
|
|
|
+ entity.setCreatedate(new Date());
|
|
|
+ logger.info("entity:" + entity);
|
|
|
+ list.add(entity);
|
|
|
+ } catch (Exception e) {
|
|
|
+ failNumber++;
|
|
|
+ failRow.add(i + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int successNumber = 0;
|
|
|
+ int failNum = 0;
|
|
|
+ for (TTsFlplanTmpl t : list) {
|
|
|
+ failNum++;
|
|
|
+ try {
|
|
|
+ add(t);
|
|
|
+ successNumber++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ failNumber++;
|
|
|
+ failRow.add(failNum + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("list:" + JSON.toJSONString(list));
|
|
|
+ logger.info("successNumber:{}", successNumber);
|
|
|
+ logger.info("failNumber:{}", failNumber);
|
|
|
+ logger.info("failRow:{}", failRow);
|
|
|
+ return AjaxResult.success(String.valueOf(successNumber), failRow);
|
|
|
+ }
|
|
|
}
|