From f7c31fd48ec3e31b95b05447738bfc4794b21e2c Mon Sep 17 00:00:00 2001 From: suerwei <18810552194@163.com> Date: 星期五, 17 五月 2024 18:11:25 +0800 Subject: [PATCH] 钻孔导入功能 --- javaweb-plus/javaweb-cms/src/main/resources/templates/geo/hole/hole.html | 27 +++++++++++++ javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/HoleServiceImpl.java | 61 ++++++++++++++++++++++++++++++ javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/DeviceLogServiceImpl.java | 3 - javaweb-plus/javaweb-cms/src/main/resources/templates/geo/deviceLog/deviceLog.html | 2 javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/controller/HoleController.java | 19 +++++++-- javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/IHoleService.java | 7 +++ 6 files changed, 110 insertions(+), 9 deletions(-) diff --git a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/controller/HoleController.java b/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/controller/HoleController.java index 6ae2f30..307390f 100644 --- a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/controller/HoleController.java +++ b/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); + } + } diff --git a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/IHoleService.java b/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/IHoleService.java index 7ca5bdd..95f9c43 100644 --- a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/IHoleService.java +++ b/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); } diff --git a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/DeviceLogServiceImpl.java b/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/DeviceLogServiceImpl.java index 12845c1..df6206c 100644 --- a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/DeviceLogServiceImpl.java +++ b/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\\" ; /** diff --git a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/HoleServiceImpl.java b/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/HoleServiceImpl.java index ba7f4c6..088a3ee 100644 --- a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/HoleServiceImpl.java +++ b/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; + } + + + } diff --git a/javaweb-plus/javaweb-cms/src/main/resources/templates/geo/deviceLog/deviceLog.html b/javaweb-plus/javaweb-cms/src/main/resources/templates/geo/deviceLog/deviceLog.html index a801b86..ce46554 100644 --- a/javaweb-plus/javaweb-cms/src/main/resources/templates/geo/deviceLog/deviceLog.html +++ b/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"> diff --git a/javaweb-plus/javaweb-cms/src/main/resources/templates/geo/hole/hole.html b/javaweb-plus/javaweb-cms/src/main/resources/templates/geo/hole/hole.html index d8f0e22..11fd90d 100644 --- a/javaweb-plus/javaweb-cms/src/main/resources/templates/geo/hole/hole.html +++ b/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"> + 鎻愮ず锛氫粎鍏佽瀵煎叆鈥渪ls鈥濇垨鈥渪lsx鈥濇牸寮忔枃浠讹紒 + </font> + </div> + </form> +</script> + </html> \ No newline at end of file -- Gitblit v1.9.1