diff --git a/src/com/engine/organization/service/impl/PostInfoServiceImpl.java b/src/com/engine/organization/service/impl/PostInfoServiceImpl.java index 0fd60b62..604a2a8e 100644 --- a/src/com/engine/organization/service/impl/PostInfoServiceImpl.java +++ b/src/com/engine/organization/service/impl/PostInfoServiceImpl.java @@ -17,10 +17,17 @@ import com.engine.organization.service.PostInfoService; import com.engine.organization.util.*; import com.engine.organization.util.db.DBType; import com.engine.organization.util.db.MapperProxyFactory; +import com.engine.organization.util.excel.ExcelUtil; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.GCONST; import weaver.general.Util; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.*; @@ -41,6 +48,39 @@ public class PostInfoServiceImpl extends Service implements PostInfoService { private PostMapper getPostMapper() { return MapperProxyFactory.getProxy(PostMapper.class); } + // 判断编制导入模板是否存在,不存在则创建该文件 + static { + try { + String outPutPath = GCONST.getRootPath() + File.separator + "hrm" + File.separator + "import" + File.separator + "template" + File.separator + "postinfo.xls"; + File excelPathFile = new File(outPutPath); + if (!excelPathFile.exists()) { + String columns = "编号,名称,职务分类,权限,责任,资格,描述说明"; + String[] split = columns.split(","); + List columnList = new ArrayList<>(Arrays.asList(split)); + // 创建导入模板 + List> excelSheetData = new ArrayList<>(); + excelSheetData.add(columnList); + XSSFWorkbook sheets = ExcelUtil.genWorkbookV2(excelSheetData, "postinfo"); + File excelFile = new File(outPutPath); + if (!excelFile.exists()) { + String substring = outPutPath.substring(0, outPutPath.lastIndexOf(File.separator)); + File file = new File(substring); + if (file.mkdirs()) { + boolean newFile = excelPathFile.createNewFile(); + if (!newFile) { + throw new IOException(outPutPath + "文件创建失败"); + } + } + } + FileOutputStream out = new FileOutputStream(excelPathFile); + sheets.write(out); + out.flush(); + } + } catch (IOException e) { + new BaseBean().writeLog(e); + throw new RuntimeException(e); + } + } @Override public Map listPage(Map params) { diff --git a/src/com/engine/organization/util/saveimport/PostInfoImportUtil.java b/src/com/engine/organization/util/saveimport/PostInfoImportUtil.java index df9d271d..3ece4927 100644 --- a/src/com/engine/organization/util/saveimport/PostInfoImportUtil.java +++ b/src/com/engine/organization/util/saveimport/PostInfoImportUtil.java @@ -56,7 +56,7 @@ public class PostInfoImportUtil { // 当前sheet XSSFSheet sheetAt = workbook.getSheetAt(0); int lastRow = sheetAt.getLastRowNum(); - OrganizationAssert.isTrue(lastRow > 0, "导入数据为空"); + OrganizationAssert.isTrue(lastRow > 0, "文件数据为空"); short lastCellNum = sheetAt.getRow(0).getLastCellNum(); List extendInfoPOS = new ArrayList<>(); Date currDate = new Date();