蔡德晨 5 years ago
parent
commit
ad74d7a925

+ 51 - 3
src/main/java/com/jeeplus/common/utils/excel/ImportExcel.java

@@ -99,6 +99,11 @@ public class ImportExcel {
 			throws InvalidFormatException, IOException {
 		this(new File(fileName), headerNum, sheetIndex);
 	}
+
+	public ImportExcel(String fileName, int headerNum, String sheetName)
+			throws InvalidFormatException, IOException {
+		this(new File(fileName), headerNum, sheetName);
+	}
 	
 	/**
 	 * 构造函数
@@ -112,6 +117,11 @@ public class ImportExcel {
 			throws InvalidFormatException, IOException {
 		this(file.getName(), new FileInputStream(file), headerNum, sheetIndex);
 	}
+
+	public ImportExcel(File file, int headerNum, String sheetName)
+			throws InvalidFormatException, IOException {
+		this(file.getName(), new FileInputStream(file), headerNum, sheetName);
+	}
 	
 	/**
 	 * 构造函数
@@ -121,9 +131,14 @@ public class ImportExcel {
 	 * @throws InvalidFormatException 
 	 * @throws IOException 
 	 */
-	public ImportExcel(MultipartFile multipartFile, int headerNum, int sheetIndex) 
+	public ImportExcel(MultipartFile multipartFile, int headerNum, int sheetName)
 			throws InvalidFormatException, IOException {
-		this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetIndex);
+		this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetName);
+	}
+
+	public ImportExcel(MultipartFile multipartFile, int headerNum, String sheetName)
+			throws InvalidFormatException, IOException {
+		this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetName);
 	}
 
 	/**
@@ -134,7 +149,7 @@ public class ImportExcel {
 	 * @throws InvalidFormatException 
 	 * @throws IOException 
 	 */
-	public ImportExcel(String fileName, InputStream is, int headerNum, int sheetIndex) 
+	public ImportExcel(String fileName, InputStream is, int headerNum, int sheetIndex)
 			throws InvalidFormatException, IOException {
 		if (StringUtils.isBlank(fileName)){
 			throw new RuntimeException("导入文档为空!");
@@ -152,6 +167,39 @@ public class ImportExcel {
 		this.headerNum = headerNum;
 		log.debug("Initialize success.");
 	}
+
+	public ImportExcel(String fileName, InputStream is, int headerNum, String sheetName)
+			throws InvalidFormatException, IOException {
+		if (StringUtils.isBlank(fileName)){
+			throw new RuntimeException("导入文档为空!");
+		}else if(fileName.toLowerCase().endsWith("xls")){
+			this.wb = new HSSFWorkbook(is);
+		}else if(fileName.toLowerCase().endsWith("xlsx")){
+			this.wb = new XSSFWorkbook(is);
+		}else{
+			throw new RuntimeException("文档格式不正确!");
+		}
+		this.sheet = this.wb.getSheet(sheetName);
+		this.headerNum = headerNum;
+		log.debug("Initialize success.");
+	}
+
+//	public ImportExcel(MultipartFile file,int headerNum,String sheetName) throws IOException {
+//		String fileName = file.getOriginalFilename();
+//		InputStream is = file.getInputStream();
+//		if (StringUtils.isBlank(fileName)){
+//			throw new RuntimeException("导入文档为空!");
+//		}else if(fileName.toLowerCase().endsWith("xls")){
+//			this.wb = new HSSFWorkbook(is);
+//		}else if(fileName.toLowerCase().endsWith("xlsx")){
+//			this.wb = new XSSFWorkbook(is);
+//		}else{
+//			throw new RuntimeException("文档格式不正确!");
+//		}
+//		this.sheet = this.wb.getSheet(sheetName);
+//		this.headerNum = headerNum;
+//		log.debug("Initialize success.");
+//	}
 	
 	/**
 	 * 获取行对象

+ 27 - 1
src/main/java/com/jeeplus/modules/sg/entity/JkxlData.java

@@ -1,5 +1,7 @@
 package com.jeeplus.modules.sg.entity;
 
+import com.jeeplus.common.utils.excel.annotation.ExcelField;
+
 public class JkxlData {
     private String id;
     private String wbsCode;
@@ -26,7 +28,28 @@ public class JkxlData {
     private String projectId;
     private String describe;
     private String parentNode;
+    private String mountMatter;
+    private String mountServer;
+
+    @ExcelField(title="挂接物料", align=2, sort=6)
+    public String getMountMatter() {
+        return mountMatter;
+    }
+
+    public void setMountMatter(String mountMatter) {
+        this.mountMatter = mountMatter;
+    }
 
+    @ExcelField(title="挂接服务", align=2, sort=7)
+    public String getMountServer() {
+        return mountServer;
+    }
+
+    public void setMountServer(String mountServer) {
+        this.mountServer = mountServer;
+    }
+
+    @ExcelField(title="标准WBS要素", align=2, sort=1)
     public String getWbsId() {
         return wbsId;
     }
@@ -35,6 +58,7 @@ public class JkxlData {
         this.wbsId = wbsId;
     }
 
+    @ExcelField(title="当前的内部项目号 - 标准 WBS", align=2, sort=3)
     public String getProjectId() {
         return projectId;
     }
@@ -43,6 +67,7 @@ public class JkxlData {
         this.projectId = projectId;
     }
 
+    @ExcelField(title="描述", align=2, sort=2)
     public String getDescribe() {
         return describe;
     }
@@ -58,7 +83,7 @@ public class JkxlData {
     public void setParentNode(String parentNode) {
         this.parentNode = parentNode;
     }
-
+    @ExcelField(title="简明ID(WBS元素)", align=2, sort=4)
     public String getWbsCode() {
         return wbsCode;
     }
@@ -67,6 +92,7 @@ public class JkxlData {
         this.wbsCode = wbsCode;
     }
 
+    @ExcelField(title="科目分配元素", align=2, sort=5)
     public Double getTotalFee() {
         return totalFee;
     }

+ 1 - 0
src/main/java/com/jeeplus/modules/sg/mapper/JkxlMapper.java

@@ -13,4 +13,5 @@ public interface JkxlMapper {
     List<JkxlData> getList(String id);
     void save(JkxlData jkxlData);
     void saveProject(WbsProject project);
+    List<JkxlData> findList(String id);
 }

+ 16 - 1
src/main/java/com/jeeplus/modules/sg/mapper/xml/JkxlMapper.xml

@@ -12,7 +12,7 @@
         SELECT
          a.describe,
          a.short_id as wbsCode,
-         a.parent_node as parentNode;
+         a.parent_node as parentNode,
          b.id,
          b.original_total_cost as originalTotalCost,
          b.original_rg_cost as originalRgCost,
@@ -31,6 +31,21 @@
          b.total_fee as totalFee
          FROM sg_wbs_elements a LEFT JOIN sg_wbs_fee b on a.short_id = b.wbs_code
          WHERE a.id = #{id}
+         order by a.short_id
+	</select>
+
+
+	<select id="findList" parameterType="String" resultType="com.jeeplus.modules.sg.entity.JkxlData">
+		 SELECT
+		 a.id as wbsId,
+         a.project_id as projectId,
+         a.describe,
+         a.short_id as wbsCode,
+         a.mount_matter as mountMatter,
+         a.mount_server as mountServer,
+         b.total_fee as totalFee
+         FROM sg_wbs_elements a LEFT JOIN sg_wbs_fee b on a.short_id = b.wbs_code
+         WHERE a.id = #{id}
 	</select>
 
 

+ 4 - 0
src/main/java/com/jeeplus/modules/sg/service/JkxlService.java

@@ -24,6 +24,10 @@ public class JkxlService {
        return jkxlMapper.getList(id);
    }
 
+   public List<JkxlData> findList(String id){
+       return jkxlMapper.findList(id);
+   }
+
    @Transactional
    public void save(JkxlData jkxlData){
        jkxlMapper.save(jkxlData);

+ 5 - 0
src/main/java/com/jeeplus/modules/sg/util/BashInfo.java

@@ -2,6 +2,11 @@ package com.jeeplus.modules.sg.util;
 
 public class BashInfo {
     public static final String PROJECTNAME = "架空线路";
+    public static final String SHEET_FBFXJJ = "分部分项工程量清单计价表";
+    public static final String SHEET_HZB = "工程项目竣工结算汇总表";
+    public static final String SHEET_CSB = "措施项目清单计价表(一)";
+    public static final String SHEET_QTFY = "其他项目清单计价表";
+    public static final String SHEET_GFQD = "规费项目清单计价表";
     public static final String JCGC = "1 基础工程";
     public static final String GTGC = "2 杆塔工程";
     public static final String JDGC = "3 接地工程";

+ 2 - 1
src/main/java/com/jeeplus/modules/sg/util/JkxlExcel.java

@@ -11,7 +11,8 @@ import java.util.List;
 
 public class JkxlExcel {
     public static List<JkxlData> getData(String  file) throws IOException, InvalidFormatException {
-        ImportExcel importExcel = new ImportExcel(file,1,3);
+
+        ImportExcel importExcel = new ImportExcel(file,1,"分部分项工程量清单计价表");
         List<JkxlData> list = new ArrayList<>();
         int lastRow = importExcel.getLastDataRowNum();
         int[] row = new int[6];

+ 4 - 4
src/main/java/com/jeeplus/modules/sg/util/Text.java

@@ -14,13 +14,13 @@ public class Text {
  @Test
   public void text() throws IOException, InvalidFormatException {
       String file = "target/1.xls";
-      double[] d = {0.17,0.0332,0.0322};
-//      List<JkxlData> list = JkxlExcel.getData(file);
+//      double[] d = {0.17,0.0332,0.0322};
+      List<JkxlData> list = JkxlExcel.getData(file);
 //     double doubles = JkxlExcel.get(file);
 
 //     System.out.println(doubles);
-     JkxlController jkxlController = new JkxlController();
+//     JkxlController jkxlController = new JkxlController();
 //     List<JkxlData> data = jkxlController.getData(file, d);
-//     System.out.println(data);
+     System.out.println(list);
  }
 }

+ 21 - 5
src/main/java/com/jeeplus/modules/sg/web/JkxlController.java

@@ -1,5 +1,7 @@
 package com.jeeplus.modules.sg.web;
 
+import com.jeeplus.common.utils.DateUtils;
+import com.jeeplus.common.utils.excel.ExportExcel;
 import com.jeeplus.common.utils.excel.ImportExcel;
 import com.jeeplus.core.web.BaseController;
 import com.jeeplus.modules.sg.entity.JkxlData;
@@ -15,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
 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.ArrayList;
@@ -67,13 +70,26 @@ public class JkxlController extends BaseController {
     return "";
   }
 
+  @RequestMapping("/export")
+  public String export(HttpServletRequest request, HttpServletResponse response,Model model,RedirectAttributes redirectAttributes){
+    String id = request.getParameter("id");
+    try{
+      String fileName = "架空线路"+ DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
+      List<JkxlData> list = jkxlService.findList(id);
+      new ExportExcel(null,JkxlData.class).setDataList(list).dispose().write(response, fileName).dispose();
+    }catch (Exception e){
+      addMessage(redirectAttributes, "导出失败");
+    }
+    return "redirect:/a/jkxl/index";
+  }
+
 
   public List<JkxlData> getData(MultipartFile file,double[] rate,String id,double sl) throws IOException, InvalidFormatException {
-    ImportExcel importExcel = new ImportExcel(file,1,3);
-    ImportExcel csqd = new ImportExcel(file,1,8);
-    ImportExcel gf = new ImportExcel(file,1,17);
-    ImportExcel qt = new ImportExcel(file,1,10);
-    ImportExcel total = new ImportExcel(file,1,1);
+    ImportExcel importExcel = new ImportExcel(file,1,BashInfo.SHEET_FBFXJJ);
+    ImportExcel csqd = new ImportExcel(file,1,BashInfo.SHEET_CSB);
+    ImportExcel gf = new ImportExcel(file,1,BashInfo.SHEET_GFQD);
+    ImportExcel qt = new ImportExcel(file,1,BashInfo.SHEET_QTFY);
+    ImportExcel total = new ImportExcel(file,1,BashInfo.SHEET_HZB );
     double[] csRate = getCsRate(csqd);
     double[] gfRate = getGfRate(gf);
     double[] qtFees = getQtFees(qt);