javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/controller/HoleController.java
@@ -6,11 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.*; import com.javaweb.common.annotation.Log; import com.javaweb.common.enums.BusinessType; import com.javaweb.geo.domain.Hole; @@ -19,6 +15,7 @@ import com.javaweb.common.core.domain.AjaxResult; import com.javaweb.common.utils.poi.ExcelUtil; import com.javaweb.common.core.page.TableDataInfo; import org.springframework.web.multipart.MultipartFile; /** * 钻孔Controller @@ -121,4 +118,16 @@ return toAjax(holeService.deleteHoleByIds(ids)); } /** * 导入钻孔 */ @RequiresPermissions("geo:hole:import") @Log(title = "导入钻孔") @PostMapping( "/importHole/{projectId}") @ResponseBody public AjaxResult importHole(@PathVariable("projectId") String projectId, @RequestParam("file") MultipartFile file, boolean updateSupport){ String message = holeService.importHole(projectId,file,updateSupport); return AjaxResult.success(message); } } javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/IHoleService.java
@@ -1,6 +1,8 @@ package com.javaweb.geo.service; import com.javaweb.geo.domain.Hole; import org.springframework.web.multipart.MultipartFile; import java.util.List; /** @@ -58,4 +60,9 @@ * @return 结果 */ public int deleteHoleById(String ids); /** * 导入钻孔 */ String importHole(String projectId, MultipartFile file, boolean updateSupport); } javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/DeviceLogServiceImpl.java
@@ -38,9 +38,6 @@ @Autowired private IProjectService projectService; @Autowired private IDeviceService deviceService; private String fileSaveDir = Global.getProfile() + "\\template\\" ; /** javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/HoleServiceImpl.java
@@ -1,7 +1,11 @@ package com.javaweb.geo.service.impl; import java.io.File; import java.util.List; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import com.javaweb.common.config.Global; import com.javaweb.common.utils.DateUtils; import com.javaweb.common.utils.IdGenerate; import com.javaweb.geo.domain.*; @@ -11,6 +15,7 @@ import org.springframework.stereotype.Service; import com.javaweb.common.core.text.Convert; import org.springframework.util.ObjectUtils; import org.springframework.web.multipart.MultipartFile; /** * 钻孔Service业务层处理 @@ -41,6 +46,12 @@ @Autowired private HoleYantuMapper holeYantuMapper; @Autowired private IProjectService projectService; private String fileSaveDir = Global.getProfile() + "\\template\\" ; /** * 查询钻孔 @@ -151,4 +162,54 @@ public int deleteHoleById(String ids) { return holeMapper.deleteHoleById(ids); } /** * 导入钻孔 */ @Override public String importHole(String projectId, MultipartFile file, boolean updateSupport) { try { String dest = saveExcel(file); List<Hole> list = readData(dest); for (Hole item : list) { insertHole(item); } } catch (Exception e) { return e.toString(); } return "导入完毕" ; } private String saveExcel(MultipartFile file) { String filename = file.getOriginalFilename(); File dir = new File(fileSaveDir); if (!dir.exists()) { dir.mkdir(); } String addr = fileSaveDir + filename; try { File dest = new File(addr); file.transferTo(dest); } catch (Exception e) { return null; } return addr; } private List<Hole> readData(String filepath) { ExcelReader reader = ExcelUtil.getReader(filepath, 0); reader.addHeaderAlias("钻孔编号", "code"); reader.addHeaderAlias("孔口高程", "elevation"); reader.addHeaderAlias("设计孔深", "depth"); reader.addHeaderAlias("钻孔经度", "longitude"); reader.addHeaderAlias("钻孔纬度", "latitude"); reader.addHeaderAlias("进度", "pic1"); List<Hole> list = reader.readAll(Hole.class); return list; } } javaweb-plus/javaweb-cms/src/main/resources/templates/geo/deviceLog/deviceLog.html
@@ -166,7 +166,7 @@ <div class="col-xs-offset-1"> <input type="file" id="file" name="file"/> <div class="mt10 pt5"> <input type="checkbox" id="updateSupport" name="updateSupport" title="导入设备出入库信息信息"> 是否更新已经存在的数据 <input type="checkbox" id="updateSupport" name="updateSupport" title="导入设备出入库信息"> 是否更新已经存在的数据 <a onclick="importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a> </div> <font color="red" class="pull-left mt10"> javaweb-plus/javaweb-cms/src/main/resources/templates/geo/hole/hole.html
@@ -45,6 +45,9 @@ <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="geo:hole:remove"> <i class="fa fa-remove"></i> 删除 </a> <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="geo:hole:import"> <i class="fa fa-upload"></i> 导入 </a> </div> <div class="col-sm-12 select-table table-striped"> <table id="bootstrap-table"></table> @@ -67,6 +70,7 @@ updateUrl: prefix + "/edit/{id}", removeUrl: prefix + "/remove", exportUrl: prefix + "/export", importUrl: prefix + "/importHole/"+projectId, modalName: "钻孔", columns: [{ checkbox: true @@ -123,6 +127,29 @@ }; $.table.init(options); }); //下载 function importTemplate() { var filename="钻孔模板.xls"; window.location.href = ctx + "common/download?fileName=" + encodeURI(filename) + "&delete=" + false; } </script> </body> <!-- 导入区域 --> <script id="importTpl" type="text/template"> <form enctype="multipart/form-data" class="mt20 mb10"> <div class="col-xs-offset-1"> <input type="file" id="file" name="file"/> <div class="mt10 pt5"> <input type="checkbox" id="updateSupport" name="updateSupport" title="导入钻孔信息"> 是否更新已经存在的数据 <a onclick="importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a> </div> <font color="red" class="pull-left mt10"> 提示:仅允许导入“xls”或“xlsx”格式文件! </font> </div> </form> </script> </html>