xs 5 tahun lalu
induk
melakukan
c6b613f891

+ 19 - 19
src/main/java/com/jeeplus/modules/sg/project/web/ProjectTemController.java

@@ -11,6 +11,7 @@ import com.jeeplus.modules.sg.project.entity.WbsProject;
 import com.jeeplus.modules.sg.project.entity.WbsSelection;
 import com.jeeplus.modules.sg.project.service.ProjectService;
 import com.jeeplus.modules.sg.project.util.ExportUtil;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -23,6 +24,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -60,35 +62,33 @@ public class ProjectTemController extends BaseController {
      *数据导入
      */
     @RequestMapping("/import")
-    public String importFile(@RequestParam(value = "itemNames[]")MultipartFile[] file, @RequestParam(value = "itemNames[]")String[] itemName,
-                             RedirectAttributes redirectAttributes, HttpServletRequest request, Model model) {
-        String projectName = request.getParameter("projectName");     //项目名称
-//        String[] itemName = request.getParameterValues("itemNames");     //项目名称
-        String[] type = request.getParameterValues("types");     //工程类型
-        String id = getId();
+    public String importFile(@RequestParam(value = "file")MultipartFile[] file,String projectName,String[] itemNames,String[] itemTypes,Model model,
+                             RedirectAttributes redirectAttributes) throws IOException, InvalidFormatException {
         WbsProject wbsProject = new WbsProject();
         wbsProject.setProjectName(projectName);
         projectService.save(wbsProject);
         List<WbsProject> wbsProjects = projectService.findByName(projectName);
         WbsProject wbsProject1 = wbsProjects.get(0);
         String projectId = wbsProject1.getId();
-        try {
-            for(int i = 0;i<type.length;i++) {
+//        try {
+            for(int i = 0;i<itemTypes.length;i++) {
 //            保存数据到数据库
-                if (type.equals("1")) {
-                    overheadLineService.saveJk(file[i], itemName[i], id, projectId, type[i]);
+                if (itemTypes[i].equals("1")) {
+                    String id = getId();
+                    overheadLineService.saveJk(file[i], itemNames[i], id, projectId, itemTypes[i]);
                 }
-                if (type.equals("2")) {
-                    overheadLineService.saveDl(file[i], itemName[i], id, projectId, type[i]);
+                if (itemTypes[i].equals("2")) {
+                    String id = getId();
+                    overheadLineService.saveDl(file[i], itemNames[i], id, projectId, itemTypes[i]);
                 }
             }
-        } catch (RuntimeException e) {
-            addMessage(redirectAttributes, "导入失败,"+e.getMessage());
-            return "redirect:/a/project/tem/index";
-        }   catch (Exception e){
-            addMessage(redirectAttributes, "导入失败");
-            return "redirect:/a/project/tem/index";
-        }
+//        } catch (RuntimeException e) {
+//            addMessage(redirectAttributes, "导入失败,"+e.getMessage());
+//            return "redirect:/a/project/tem/index";
+//        }   catch (Exception e){
+//            addMessage(redirectAttributes, "导入失败");
+//            return "redirect:/a/project/tem/index";
+//        }
         addMessage(redirectAttributes, "导入成功");
         return "redirect:/a/project/tem/list?projectId="+projectId;
     }

+ 7 - 0
src/main/webapp/webpage/modules/sg/free/wbslist.jsp

@@ -47,7 +47,14 @@
     <sys:message content="${message}"/>
     <div class="" style="margin-right: 30px;float: right;margin-top: 20px">
         <div class="layui-btn-group">
+           <c:forEach items="${map.list1}" var="data1" varStatus="index">
+               <c:if test="${empty data1.projectId}">
             <a class="layui-btn layui-btn-meself" href="${ctx}/project/tolist"><img class="layui-meself-img1" src="${ctxp}/icon/back.png" alt="">&nbsp;返回</a>
+               </c:if>
+               <c:if test="${not empty data1.projectId}">
+                   <a class="layui-btn layui-btn-meself" href="${ctx}/project/tem/tolist?projectId=${data1.projectId}"><img class="layui-meself-img1" src="${ctxp}/icon/back.png" alt="">&nbsp;返回</a>
+               </c:if>
+           </c:forEach>
             <c:forEach items="${map.list1}" var="data1" varStatus="index">
                 <a class="layui-btn layui-btn-warm layui-btn-meself" href="${ctx}/jkxl/export?id=${data1.id}&type=${data1.type}"><img class="layui-meself-img1" src="${ctxp}/icon/daochu.png" alt="">&nbsp;导出</a>
             </c:forEach>

+ 30 - 108
src/main/webapp/webpage/modules/sg/project/addItem2Form.jsp

@@ -79,31 +79,35 @@
                                     </div>
                                 </div>
                             </div>
-                            <form id="myform" action="${ctx}/project/tem/import" method="post" enctype="multipart/form-data">
-                                <input type="text" name="itemNames" value="11111" style="display: none">
                             <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                                 <legend style="font-size: 15px;">选择项目</legend>
                             </fieldset>
                             <div class="layui-upload">
-                                <button type="button" class="layui-btn layui-btn-normal" id="testList">选择文件</button>
+                                <button type="button" class="layui-btn layui-btn-normal" onclick="add()">添加文件</button>
                                 <div class="layui-upload-list">
+                                    <form id="myform" action="${ctx}/project/tem/import" method="post" enctype="multipart/form-data">
+                                        <input type="text" name="projectName" value="" style="display: none" id="id1">
+                                        <input type="text" name="itemNames" value="" style="display: none" id="id2">
+                                        <input type="text" name="itemTypes" value="" style="display: none" id="id3">
                                         <table class="layui-table" id="mytable">
                                         <thead>
                                         <tr>
-                                            <th hidden>文件</th>
                                             <th>文件名</th>
                                             <th>项目名称</th>
                                             <th>项目类型</th>
                                             <th>操作</th>
                                         </tr></thead>
-                                        <tbody id="demoList"></tbody>
-                                    </table>
+                                        <tbody id="demoList">
 
+                                        </tbody>
+                                    </table>
+                                        <button type="button" class="layui-btn" onclick="okSubmit()">确定</button>
+                                    </form>
                                 </div>
 
                             </div>
-                                <button type="submit" class="layui-btn" >确定</button>
-                            </form>
+
+
 
                 </div>
             </div>
@@ -112,53 +116,24 @@
 
 </body>
 <script>
-    // var files;
-    layui.use(['upload','form'],function(){
-        var $ = layui.jquery
-            ,form = layui.form
-            ,upload = layui.upload;
-        //多文件列表示例
-        var demoListView = $('#demoList')
-            ,uploadListIns = upload.render({
-            elem: '#testList'
-            // ,url: '/sddd'
-            ,accept: 'file'
-            ,multiple: true
-            ,auto: false
-            ,choose: function(obj){
-                var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
-                //读取本地文件
-                obj.preview(function(index, file, result){
-                    var tr = $(['<tr id="upload-'+ index +'">'
-                        ,'<td style="display: none" ">'+file+'</td>'
-                        ,'<td>'+ file.name +'</td>'
-                        ,'<td><div contenteditable="true" class="mydiv1">请输入项目名称</div></td>'
-                        ,'<td>'
-                        ,' <select name="type" class="myselect"><option value="">请选择项目类型(必选)</option><option value="1">架空线路工程</option><option value="2">电缆工程</option></select>'
-                        ,'</td>'
-                        ,'<td>'
-                        // ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
-                        ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
-                        ,'</td>'
-                        ,'</tr>'].join(''));
-
-                    //删除
-                    tr.find('.demo-delete').on('click', function(){
-                        delete files[index]; //删除对应的文件
-                        tr.remove();
-                        uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值,以免删除后出现同名文件不可选
-                    });
-
-                    demoListView.append(tr);
-                });
-            }
-        });
-
-    });
+    function add() {
+        var tr = $(['<tr>'
+            ,'<td><input type="file" name="file"></td>'
+            ,'<td><div contenteditable="true" class="mydiv1">请输入项目名称</div></td>'
+            ,'<td>'
+            ,' <select name="type" class="myselect"><option value="">请选择项目类型(必选)</option><option value="1">架空线路工程</option><option value="2">电缆工程</option></select>'
+            ,'</td>'
+            ,'<td>'
+            ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" onclick="delete()">删除</button>'
+            ,'</td>'
+            ,'</tr>'].join(''));
+        $("#demoList").append(tr);
+    }
 </script>
 <script>
     function okSubmit() {
         var inputval = $("#myinput").val();
+        $("#id1").val(inputval);
 
         var div1 =  document.getElementsByClassName("mydiv1");
         var divvalue=[];
@@ -166,69 +141,16 @@
             divvalue[i]=div1[i].innerHTML;
         }
         var dJson = JSON.stringify(divvalue);
-        // alert(dJson);
+        $("#id2").val(divvalue);
+
         var select1=document.getElementsByClassName("myselect");
         var selectval=[];
         for (var i = 0; i < select1.length; i++) {
             selectval[i]=select1[i].value;
         }
         var selectJson = JSON.stringify(selectval);
-        // alert(selectJson);
-
-        var formda = new FormData();
-        // var array = [];
-        $("#mytable tr").each(function () {
-            var text = $(this).children("td:first-child").text();
-                // array.push(text);
-            formda.append("files",text);
-
-        })
-        // array.splice(0,1);
-        // alert(array);
-        formda.append("projectName",inputval);
-        formda.append("itemNames",divvalue);
-        formda.append("types",selectval);
-        // var arr = JSON.stringify(array);
-        /*
-            1/工程名称inputval
-            /文件名称array
-            2/项目名称divvalue
-            3/项目类型selectval
-         */
-
-        $.ajax({
-            type: "post",
-            url: "${ctx}/project/tem/import",
-            processData:false,
-            contentType:false,
-            // data: {
-            //     "projectName": inputval,
-            //     "flie":array,
-            //     "itemNames":dJson,
-            //     "types":selectJson
-            // },
-            data: formda,
-            dataType : 'json',
-            success: function (res) {
-
-            }
-        })
+        $("#id3").val(selectval);
+        $("#myform").submit();
     }
 </script>
-<%--<script>--%>
-    <%--function AutoContent(type) {--%>
-        <%--if (type=="in"){--%>
-            <%--var input2val = $("#myinput").val();--%>
-            <%--if (input2val=="请输入项目名称"){--%>
-                <%--$("#myinput").html("");--%>
-            <%--}--%>
-        <%--}--%>
-        <%--if (type=="out"){--%>
-            <%--var input2val = $("#myinput").val();--%>
-            <%--if (input2val==""){--%>
-                <%--$("#myinput").html("请输入项目名称");--%>
-            <%--}--%>
-        <%--}--%>
-    <%--}--%>
-<%--</script>--%>
 </html>