dcs 5 kuukautta sitten
vanhempi
commit
e7d5825346

+ 5 - 0
virgo.api/pom.xml

@@ -36,6 +36,11 @@
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-quartz</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi-ooxml</artifactId>
+			<version>4.1.2</version>
+		</dependency>
 
 
 	</dependencies>

+ 13 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/model/Contract.java

@@ -13,6 +13,11 @@ public class Contract {
 
     private long id;
 
+    /**
+     * 类型
+     */
+    private Integer type;
+
     /**
      * 名称
      */
@@ -207,6 +212,14 @@ public class Contract {
         this.id = id;
     }
 
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
     public String getName() {
         return name;
     }

+ 32 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/test/controller/TestCont.java

@@ -4,11 +4,17 @@ import com.bosshand.virgo.api.service.ProjectItemTargetRoomService;
 import com.bosshand.virgo.api.test.model.*;
 import com.bosshand.virgo.api.test.service.TestService;
 import com.bosshand.virgo.core.response.Response;
+import com.bosshand.virgo.exception.BadRequestException;
+import com.bosshand.virgo.exception.Constant;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -451,6 +457,32 @@ public class TestCont {
         return Response.ok(testService.save(data));
     }
 
+    @ApiOperation("用能分析数据表格下载")
+    @RequestMapping(value = "/downloadModel", method = RequestMethod.GET)
+    public Response getModel(final HttpServletResponse response) throws Exception {
+        byte[] data = null;
+        OutputStream outputStream = null;
+        try {
+            data = testService.getModel();
+            response.setCharacterEncoding("UTF-8");
+            response.setContentType("application/x-msdownload");
+            response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("能耗数据表格.xlsx", "UTF-8"));
+            OutputStream outputSream = response.getOutputStream();
+            outputSream.write(data);
+            outputSream.flush();
+        } catch (IOException e) {
+            throw new BadRequestException("Fail to write stream", Constant.RET_DOCUMENT_ERROR, e);
+        } finally {
+            if (outputStream != null) {
+                try {
+                    outputStream.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+        return Response.ok();
+    }
+
 
 
 

+ 39 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/test/service/TestService.java

@@ -4,12 +4,19 @@ import com.bosshand.virgo.api.test.controller.dto.*;
 import com.bosshand.virgo.api.test.dao.*;
 import com.bosshand.virgo.api.test.model.*;
 import com.bosshand.virgo.core.utils.DateTimeUtils;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -580,5 +587,37 @@ public class TestService {
         return powerDistributionMachineDao.updateState(ids, state);
     }
 
+    public byte[] getModel() {
+        // 创建一个新的工作簿
+        Workbook workbook = new XSSFWorkbook();
+        // 创建一个工作表(sheet)
+        Sheet sheet = workbook.createSheet("model");
+        // 创建行(0基索引)
+        Row row = sheet.createRow(0);
+        // 创建单元格并写入数据
+        String st = "年用水量,年用电量,年用气量,月用水量,月用电量,月用气量,日用水量,日用电量,日用气量";
+        String[] split = st.split(",");
+        for (int i = 0; i < split.length; i++) {
+            Cell cell = row.createCell(i);
+            cell.setCellValue(split[i]);
+        }
+        // 写入到文件
+        try {
+            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+            workbook.write(outputStream);
+            return outputStream.toByteArray();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            // 清理资源
+            try {
+                workbook.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
 
 }

+ 8 - 2
virgo.api/src/main/resources/mapper/ContractMapper.xml

@@ -6,6 +6,7 @@
 
     <resultMap type="com.bosshand.virgo.api.model.Contract" id="contractResult">
         <id column="id" property="id"/>
+        <result column="type" property="type"/>
         <result column="name" property="name"/>
         <result column="code" property="code"/>
         <result column="createDate" property="createDate"/>
@@ -44,6 +45,7 @@
 
     <resultMap type="com.bosshand.virgo.api.model.Contract" id="result">
         <id column="id" property="id"/>
+        <result column="type" property="type"/>
         <result column="name" property="name"/>
         <result column="code" property="code"/>
         <result column="createDate" property="createDate"/>
@@ -84,10 +86,10 @@
 
 
     <insert id="insert" parameterType="com.bosshand.virgo.api.model.Contract" useGeneratedKeys="true" keyProperty="id">
-        INSERT INTO contract(`name`, `code`, `createDate`, `organizationId`, `organizationName`, `roleId`, `roleName`, `investmentPromotion`, `operator`, `investmentPromotionName`, `operatorName`,`tenantType`, `merchantId`, `merchantName`, `clientId`, `clientName`,
+        INSERT INTO contract(`type`, `name`, `code`, `createDate`, `organizationId`, `organizationName`, `roleId`, `roleName`, `investmentPromotion`, `operator`, `investmentPromotionName`, `operatorName`,`tenantType`, `merchantId`, `merchantName`, `clientId`, `clientName`,
                              `tenant`, `industry`, `corporation`, `signatory`, `tenantContactPerson`, `signingDate`, `startDate`, `endDate`,
                              `lateFeesStartingDays`, `lateFeesProportion`, `lateFeesCeiling`, `tagIds`, `projectId`, `projectItemTargetRoomIds`, `attachment`, `document`, `status`, `data`)
-        VALUES (#{name}, #{code}, now(), #{organizationId}, #{organizationName}, #{roleId}, #{roleName}, #{investmentPromotion}, #{operator}, #{investmentPromotionName}, #{operatorName}, #{tenantType}, #{merchantId}, #{merchantName}, #{clientId}, #{clientName}, #{tenant},
+        VALUES (#{type}, #{name}, #{code}, now(), #{organizationId}, #{organizationName}, #{roleId}, #{roleName}, #{investmentPromotion}, #{operator}, #{investmentPromotionName}, #{operatorName}, #{tenantType}, #{merchantId}, #{merchantName}, #{clientId}, #{clientName}, #{tenant},
                 #{industry}, #{corporation}, #{signatory}, #{tenantContactPerson}, #{signingDate}, #{startDate}, #{endDate}, #{lateFeesStartingDays},
                 #{lateFeesProportion}, #{lateFeesCeiling}, #{tagIds}, #{projectId}, #{projectItemTargetRoomIds}, #{attachment}, #{document}, #{status}, #{data})
     </insert>
@@ -99,6 +101,7 @@
     <update id="update" parameterType="com.bosshand.virgo.api.model.Contract">
         UPDATE contract
         <trim prefix="set" suffixOverrides=",">
+            <if test="type!=null">type=#{type},</if>
             <if test="name!=null">name=#{name},</if>
             <if test="organizationId!=0">organizationId=#{organizationId},</if>
             <if test="organizationName!=null">organizationName=#{organizationName},</if>
@@ -170,6 +173,7 @@
     <select id="getList" resultMap="contractResult">
         SELECT * FROM contract
         <where>
+            <if test="type!=null">and type=#{type}</if>
             <if test="name!=null">and name=#{name}</if>
             <if test="code!=null">and code=#{code}</if>
             <if test="organizationId!=0">and organizationId=#{organizationId}</if>
@@ -218,6 +222,7 @@
     <select id="getTotalCount" parameterType="com.bosshand.virgo.api.model.Contract" resultType="Integer">
         SELECT count(*) FROM contract
         <where>
+            <if test="type!=null">and type=#{type}</if>
             <if test="name!=null">and name=#{name}</if>
             <if test="code!=null">and code=#{code}</if>
             <if test="organizationId!=0">and organizationId=#{organizationId}</if>
@@ -265,6 +270,7 @@
     <select id="getLimit" resultMap="contractResult">
         SELECT * FROM contract
         <where>
+            <if test="p.type!=null">and type=#{p.type}</if>
             <if test="p.name!=null">and name=#{p.name}</if>
             <if test="p.code!=null">and code=#{p.code}</if>
             <if test="p.organizationId!=0">and organizationId=#{p.organizationId}</if>

+ 1 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/config/ShiroConfig.java

@@ -62,6 +62,7 @@ public class ShiroConfig {
 
 
 		filterChainDefinitionMap.put("/client/downloadModel", "anon");
+		filterChainDefinitionMap.put("/test/downloadModel", "anon");
 		filterChainDefinitionMap.put("/project/getProjectName/**", "anon");
 		filterChainDefinitionMap.put("/projectItemTargetRoom/open/**", "anon");
 		filterChainDefinitionMap.put("/flow/projectFromYui/**","anon");