Browse Source

Merge remote-tracking branch 'origin/20210716' into 20210716

lihui001 3 years ago
parent
commit
75d2cf3f3e
29 changed files with 915 additions and 40 deletions
  1. 7 1
      zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/dto/ProductVo.java
  2. 6 0
      zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/dto/alarm/AlarmRulePageDto.java
  3. 4 0
      zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/dto/alarm/AlarmTypeDto.java
  4. 8 2
      zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/vo/OrgTreeVo.java
  5. 4 1
      zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/AlarmTypeMapper.java
  6. 7 1
      zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/DeviceAlarmRuleMapper.java
  7. 15 12
      zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/OrgMapper.java
  8. 7 2
      zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/entity/AlarmType.java
  9. 17 0
      zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/OrgMapper.xml
  10. 7 1
      zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/ProductMapper.xml
  11. 202 0
      zoniot-rmcp/zoniot-rmcp-core/src/main/resources/mapper/AlarmTypeMapper.xml
  12. 7 5
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/controller/AlarmRuleController.java
  13. 16 1
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/controller/CommonController.java
  14. 48 0
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/download/adapter/InstallPlanExcelFillAdapter.java
  15. 61 0
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/download/service/InstallPlanService.java
  16. 2 0
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/model/DownloadExcelData.java
  17. 31 0
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/model/InstallPalnData.java
  18. 17 0
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/model/InstallPlanInfoData.java
  19. 33 0
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/resolver/listener/InstallPlanListener.java
  20. 3 1
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/AlarmRuleService.java
  21. 8 1
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/ProductService.java
  22. 30 7
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/AlarmRuleServiceImpl.java
  23. 35 4
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/AlarmTypeServiceImpl.java
  24. 115 1
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/OrgServiceImpl.java
  25. 13 0
      zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/ProductServiceImpl.java
  26. BIN
      zoniot-rmcp/zoniot-rmcp-web/src/main/resources/excel/installPlanTemplate.xlsx
  27. 23 0
      zoniot-rmcp/zoniot-rmcp-web/src/test/java/com/zcxk/rmcp/web/CommDataListener.java
  28. 34 0
      zoniot-rmcp/zoniot-rmcp-web/src/test/java/com/zcxk/rmcp/web/DemoDataListener.java
  29. 155 0
      zoniot-rmcp/zoniot-rmcp-web/src/test/java/com/zcxk/rmcp/web/Excel.java

+ 7 - 1
zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/dto/ProductVo.java

@@ -10,9 +10,15 @@ import lombok.Data;
 @Data
 public class ProductVo {
 
-    @ApiModelProperty(value="")
+    @ApiModelProperty(value="id")
     private Integer id;
 
+    @ApiModelProperty(value="分类")
+    private Integer categoryId;
+
+    @ApiModelProperty(value="厂商")
+    private Integer manufacturerId;
+
     @ApiModelProperty(value="产品名称")
     private String productName;
 

+ 6 - 0
zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/dto/alarm/AlarmRulePageDto.java

@@ -0,0 +1,6 @@
+package com.zcxk.rmcp.api.dto.alarm;
+
+import com.zcxk.rmcp.api.dto.BasePageDto;
+
+public class AlarmRulePageDto extends BasePageDto {
+}

+ 4 - 0
zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/dto/alarm/AlarmTypeDto.java

@@ -1,4 +1,8 @@
 package com.zcxk.rmcp.api.dto.alarm;
 
+import lombok.Data;
+
+@Data
 public class AlarmTypeDto {
+    private Integer id;
 }

+ 8 - 2
zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/vo/OrgTreeVo.java

@@ -1,6 +1,7 @@
 package com.zcxk.rmcp.api.vo;
 
 import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
 
 import java.util.List;
 
@@ -8,17 +9,22 @@ import java.util.List;
  * @author linqingwei
  * @date 2021-07-22 11:09
  */
+@Data
 public class OrgTreeVo {
 
     @ApiModelProperty(value = "主键")
     private Integer id;
 
+    @ApiModelProperty(value = "机构类型")
+    private String orgType;
+
     @ApiModelProperty(value = "上级机构")
     private Integer parentOrgId;
 
     @ApiModelProperty(value = "机构名称")
     private String orgName;
 
-    @ApiModelProperty(value = "子类")
-    private List<OrgTreeVo> children;
+    private List<OrgTreeVo> orgs;
+
+    private boolean disabled;
 }

+ 4 - 1
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/AlarmTypeMapper.java

@@ -1,5 +1,6 @@
 package com.zcxk.rmcp.core.dao;
 
+import com.zcxk.core.common.pojo.UserCondition;
 import com.zcxk.rmcp.api.dto.alarm.AlarmTypeDto;
 import com.zcxk.rmcp.api.dto.alarm.AlarmTypePageDto;
 import com.zcxk.rmcp.core.entity.AlarmType;
@@ -41,7 +42,7 @@ public interface AlarmTypeMapper {
      * @param alarmType 实例对象
      * @return 对象列表
      */
-    List<AlarmTypeDto> selectList(AlarmTypePageDto alarmType);
+    List<AlarmTypeDto> selectList(AlarmTypePageDto alarmType, UserCondition userCondition);
 
     /**
      * 新增数据
@@ -85,4 +86,6 @@ public interface AlarmTypeMapper {
 
 
     List<AlarmType> selectTypesWithRules(List<Integer> ids);
+
+    void delete(List<Integer> ids);
 }

+ 7 - 1
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/DeviceAlarmRuleMapper.java

@@ -1,5 +1,8 @@
 package com.zcxk.rmcp.core.dao;
 
+import com.zcxk.core.common.pojo.UserCondition;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRuleDto;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRulePageDto;
 import com.zcxk.rmcp.core.entity.DeviceAlarmRule;
 import org.apache.ibatis.annotations.Param;
 
@@ -41,7 +44,7 @@ public interface DeviceAlarmRuleMapper {
      * @param deviceAlarmRule 实例对象
      * @return 对象列表
      */
-    List<DeviceAlarmRule> selectList(DeviceAlarmRule deviceAlarmRule);
+    List<AlarmRuleDto> selectList(AlarmRulePageDto deviceAlarmRule, UserCondition userCondition);
 
     /**
      * 新增数据
@@ -83,4 +86,7 @@ public interface DeviceAlarmRuleMapper {
     int count();
 
 
+    void delete(List<Integer> ids);
+
+    void deleteAll(UserCondition userCondition);
 }

+ 15 - 12
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/OrgMapper.java

@@ -1,6 +1,7 @@
 package com.zcxk.rmcp.core.dao;
 
 import com.zcxk.core.common.pojo.UserCondition;
+import com.zcxk.rmcp.api.vo.OrgTreeVo;
 import com.zcxk.rmcp.core.entity.Org;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -18,21 +19,21 @@ public interface OrgMapper {
     int updateByPrimaryKeySelective(Org record);
 
     /**
-    * @author Andy
-    * @description 如果id存在,则删除再插入,如果不存在则插入
-    * @date 11:09 2021/7/29
-    * @param org
-    * @return void
-    **/
+     * @param org
+     * @return void
+     * @author Andy
+     * @description 如果id存在,则删除再插入,如果不存在则插入
+     * @date 11:09 2021/7/29
+     **/
     void replaceInsert(Org org);
 
     /**
-    * @author Andy
-    * @description 物理删除
-    * @date 10:05 2021/7/29
-    * @param id
-    * @return int
-    **/
+     * @param id
+     * @return int
+     * @author Andy
+     * @description 物理删除
+     * @date 10:05 2021/7/29
+     **/
     int deleteById(int id);
 
     List<Org> findList(@Param("userCondition") UserCondition userCondition);
@@ -40,4 +41,6 @@ public interface OrgMapper {
     Org findByName(@Param("tenantId") String tenantId, @Param("name") String name);
 
     Org findByParentIdAndName(@Param("parentId") Integer parentId, @Param("name") String name);
+
+    List<OrgTreeVo> selectTrees(@Param("org") Org org);
 }

+ 7 - 2
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/entity/AlarmType.java

@@ -11,12 +11,12 @@ import io.swagger.annotations.ApiModelProperty;
  * 设备告警类型(AlarmType)实体类
  *
  * @author hym
- * @since 2021-07-30 10:57:47
+ * @since 2021-07-30 11:28:50
  */
 @Data
 @ApiModel
 public class AlarmType implements Serializable {
-    private static final long serialVersionUID = 358911974200006071L;
+    private static final long serialVersionUID = -27168393864976552L;
     /**
      * id
      */
@@ -72,4 +72,9 @@ public class AlarmType implements Serializable {
      */
     @ApiModelProperty(value = "租户id")
     private String tenantId;
+    /**
+     * 1启用 0禁用
+     */
+    @ApiModelProperty(value = "1启用 0禁用")
+    private Integer alarmStatus;
 }

+ 17 - 0
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/OrgMapper.xml

@@ -314,4 +314,21 @@
   <select id="findByParentIdAndName" resultMap="BaseResultMap">
     select id,ORG_NAME from rmcp_org where STATUS = 1 and PARENT_ORG_ID = #{parentId} and ORG_NAME = #{name}
   </select>
+
+  <select id="selectTrees" resultType="com.zcxk.rmcp.api.vo.OrgTreeVo">
+    select ID, TENANT_ID, ORG_TYPE, PARENT_ORG_ID, ORG_AREA_ID, ORG_NAME, ORG_STATE, REMARK, ORG_LEADER_NAME, ORG_LEADER_PHONE, ORG_LEADER_EMAIL, ORG_LEADER_SEX, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY
+    from rmcp_org
+    <where>
+      and status!=0
+      <if test="org.tenantId!=null ">
+        and TENANT_ID=#{org.tenantId}
+      </if>
+      <if test="org.orgType=='company'||org.orgType=='department'">
+        and ORG_TYPE=#{org.orgType}
+      </if>
+      <if test="org.id!=null">
+        and id=#{org.id}
+      </if>
+    </where>
+    </select>
 </mapper>

+ 7 - 1
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/ProductMapper.xml

@@ -159,7 +159,13 @@
   </update>
 
   <select id="findList" resultType="com.zcxk.rmcp.api.dto.ProductVo">
-    select rp.id,rp.product_name,rp.product_model,rm.name as manufacturer_name
+    select
+    rp.id,
+    rp.product_category_id as category_id,
+    rp.manufacturer_id,
+    rp.product_name,
+    rp.product_model,
+    rm.name as manufacturer_name
     from rmcp_product rp left join rmcp_manufacturer rm on rp.manufacturer_id = rm.id
     where rp.status = 1
     <if test="categoryId != null">and product_category_id = #{categoryId}</if>

+ 202 - 0
zoniot-rmcp/zoniot-rmcp-core/src/main/resources/mapper/AlarmTypeMapper.xml

@@ -0,0 +1,202 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zcxk.rmcp.core.dao.AlarmTypeMapper">
+    <!-- 结果集 -->
+    <resultMap type="com.zcxk.rmcp.core.entity.AlarmType" id="AlarmTypeMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="productCategroyId" column="product_categroy_id" jdbcType="INTEGER"/>
+        <result property="deviceTypeId" column="device_type_id" jdbcType="INTEGER"/>
+        <result property="name" column="name" jdbcType="VARCHAR"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
+        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
+        <result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
+        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
+        <result property="typeDesc" column="type_desc" jdbcType="VARCHAR"/>
+        <result property="tenantId" column="tenant_id" jdbcType="VARCHAR"/>
+        <result property="alarmStatus" column="alarm_status" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <!-- 基本字段 -->
+    <sql id="Base_Column_List">
+        id, product_categroy_id, device_type_id, name, status, create_date, create_by, update_date, update_by, type_desc, tenant_id, alarm_status    </sql>
+
+    <!-- 查询单个 -->
+    <select id="selectById" resultMap="AlarmTypeMap">
+        select
+        <include refid="Base_Column_List"/>
+        from rmcp_alarm_type
+        where id = #{id}
+    </select>
+
+
+    <!-- 查询全部 -->
+    <select id="selectAll" resultMap="AlarmTypeMap">
+        select
+        <include refid="Base_Column_List"/>
+        from rmcp_alarm_type
+    </select>
+
+    <!--通过实体作为筛选条件查询-->
+    <select id="selectList" resultMap="AlarmTypeMap">
+        select
+        <include refid="Base_Column_List"/>
+        from rmcp_alarm_type
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="productCategroyId != null">
+                and product_categroy_id = #{productCategroyId}
+            </if>
+            <if test="deviceTypeId != null">
+                and device_type_id = #{deviceTypeId}
+            </if>
+            <if test="name != null and name != ''">
+                and name = #{name}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+            <if test="createDate != null">
+                and create_date = #{createDate}
+            </if>
+            <if test="createBy != null and createBy != ''">
+                and create_by = #{createBy}
+            </if>
+            <if test="updateDate != null">
+                and update_date = #{updateDate}
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                and update_by = #{updateBy}
+            </if>
+            <if test="typeDesc != null and typeDesc != ''">
+                and type_desc = #{typeDesc}
+            </if>
+            <if test="tenantId != null and tenantId != ''">
+                and tenant_id = #{tenantId}
+            </if>
+            <if test="alarmStatus != null">
+                and alarm_status = #{alarmStatus}
+            </if>
+        </where>
+    </select>
+
+    <!-- 新增所有列 -->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into rmcp_alarm_type(id, product_categroy_id, device_type_id, name, status, create_date, create_by,
+                                    update_date, update_by, type_desc, tenant_id, alarm_status)
+        values (#{id}, #{productCategroyId}, #{deviceTypeId}, #{name}, #{status}, #{createDate}, #{createBy},
+                #{updateDate}, #{updateBy}, #{typeDesc}, #{tenantId}, #{alarmStatus})
+    </insert>
+
+    <!-- 批量新增 -->
+    <insert id="batchInsert">
+        insert into rmcp_alarm_type(id, product_categroy_id, device_type_id, name, status, create_date, create_by,
+        update_date, update_by, type_desc, tenant_id, alarm_status)
+        values
+        <foreach collection="alarmTypes" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.productCategroyId}, #{item.deviceTypeId}, #{item.name}, #{item.status},
+            #{item.createDate}, #{item.createBy}, #{item.updateDate}, #{item.updateBy}, #{item.typeDesc},
+            #{item.tenantId}, #{item.alarmStatus} )
+        </foreach>
+    </insert>
+
+    <!-- 通过主键修改数据 -->
+    <update id="update">
+        update rmcp_alarm_type
+        <set>
+            <if test="productCategroyId != null">
+                product_categroy_id = #{productCategroyId},
+            </if>
+            <if test="deviceTypeId != null">
+                device_type_id = #{deviceTypeId},
+            </if>
+            <if test="name != null and name != ''">
+                name = #{name},
+            </if>
+            <if test="status != null">
+                status = #{status},
+            </if>
+            <if test="createDate != null">
+                create_date = #{createDate},
+            </if>
+            <if test="createBy != null and createBy != ''">
+                create_by = #{createBy},
+            </if>
+            <if test="updateDate != null">
+                update_date = #{updateDate},
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                update_by = #{updateBy},
+            </if>
+            <if test="typeDesc != null and typeDesc != ''">
+                type_desc = #{typeDesc},
+            </if>
+            <if test="tenantId != null and tenantId != ''">
+                tenant_id = #{tenantId},
+            </if>
+            <if test="alarmStatus != null">
+                alarm_status = #{alarmStatus},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete
+        from rmcp_alarm_type
+        where id = #{id}
+    </delete>
+
+    <!-- 总数 -->
+    <select id="count" resultType="int">
+        select count(*)
+        from rmcp_alarm_type
+    </select>
+    <select id="selectPage" resultMap="AlarmTypeMap">
+        select
+        <include refid="Base_Column_List"/>
+        from rmcp_alarm_type
+        <where>
+            <if test="alarmType.id != null">
+                and id = #{alarmType.id}
+            </if>
+            <if test="alarmType.productCategroyId != null">
+                and product_categroy_id = #{alarmType.productCategroyId}
+            </if>
+            <if test="alarmType.deviceTypeId != null">
+                and device_type_id = #{alarmType.deviceTypeId}
+            </if>
+            <if test="alarmType.name != null and alarmType.name != ''">
+                and name = #{alarmType.name}
+            </if>
+            <if test="alarmType.status != null">
+                and status = #{alarmType.status}
+            </if>
+            <if test="alarmType.createDate != null">
+                and create_date = #{alarmType.createDate}
+            </if>
+            <if test="alarmType.createBy != null and alarmType.createBy != ''">
+                and create_by = #{alarmType.createBy}
+            </if>
+            <if test="alarmType.updateDate != null">
+                and update_date = #{alarmType.updateDate}
+            </if>
+            <if test="alarmType.updateBy != null and alarmType.updateBy != ''">
+                and update_by = #{alarmType.updateBy}
+            </if>
+            <if test="alarmType.typeDesc != null and alarmType.typeDesc != ''">
+                and type_desc = #{alarmType.typeDesc}
+            </if>
+            <if test="alarmType.tenantId != null and alarmType.tenantId != ''">
+                and tenant_id = #{alarmType.tenantId}
+            </if>
+            <if test="alarmType.alarmStatus != null">
+                and alarm_status = #{alarmType.alarmStatus}
+            </if>
+        </where>
+    </select>
+</mapper>

+ 7 - 5
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/controller/AlarmRuleController.java

@@ -2,7 +2,9 @@ package com.zcxk.rmcp.web.controller;
 
 
 import com.zcxk.core.common.pojo.AjaxMessage;
+import com.zcxk.core.mysql.pageing.Pagination;
 import com.zcxk.rmcp.api.dto.alarm.AlarmRuleDto;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRulePageDto;
 import com.zcxk.rmcp.api.dto.alarm.ConfigDataDto;
 import com.zcxk.rmcp.api.dto.alarm.RuleMeasuringDto;
 import com.zcxk.rmcp.web.service.AlarmRuleService;
@@ -24,12 +26,12 @@ public class AlarmRuleController {
     @Autowired
     private AlarmRuleService deviceAlarmRuleService;
 
-    @GetMapping("/getList")
+    @GetMapping("/getPage")
     @ApiOperation(value = "查询异常规则列表")
-    public AjaxMessage<List<AlarmRuleDto>> getList(
-            @ApiParam(value = "异常类型id", required = true) @RequestParam Integer alarmTypeId
-    ) {
-        List<AlarmRuleDto> list = deviceAlarmRuleService.getList(alarmTypeId);
+    public AjaxMessage<Pagination<AlarmRuleDto>> getList(
+            @ApiParam(value = "异常类型id", required = true) @RequestBody AlarmRulePageDto alarmRulePageDto
+            ) {
+        Pagination<AlarmRuleDto> list = deviceAlarmRuleService.getList(alarmRulePageDto);
         return AjaxMessage.success(list);
     }
 

+ 16 - 1
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/controller/CommonController.java

@@ -1,11 +1,13 @@
 package com.zcxk.rmcp.web.controller;
 
 import com.zcxk.core.common.pojo.AjaxMessage;
+import com.zcxk.rmcp.api.dto.ProductVo;
 import com.zcxk.rmcp.api.vo.AreaVo;
 import com.zcxk.rmcp.api.vo.OrgTreeVo;
 import com.zcxk.rmcp.core.dao.AreaMapper;
 import com.zcxk.rmcp.core.entity.Org;
 import com.zcxk.rmcp.web.service.OrgService;
+import com.zcxk.rmcp.web.service.ProductService;
 import com.zcxk.rmcp.web.util.TreeUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -30,6 +32,8 @@ public class CommonController {
     private OrgService orgService;
     @Autowired
     private AreaMapper areaMapper;
+    @Autowired
+    private ProductService productService;
 
 
     @GetMapping("/getAllArea")
@@ -40,7 +44,7 @@ public class CommonController {
         return AjaxMessage.success(TreeUtil.getAreaTree(list, 100000, 1));
     }
 
-    @RequestMapping(value = "getOrgUserTree", method = RequestMethod.POST)
+    @GetMapping("getOrgUserTree")
     @ApiOperation(value = "获取机构树")
     public AjaxMessage<List<OrgTreeVo>> getOrgUserTree(
         @ApiParam(value = "机构类型", required = true) @RequestParam String orgType,
@@ -52,4 +56,15 @@ public class CommonController {
 
         return AjaxMessage.success(orgService.getUserTrees(org));
     }
+
+
+    @GetMapping("getProductList")
+    @ApiOperation(value = "获取产品列表")
+    public AjaxMessage<List<ProductVo>> getProductList(
+            @ApiParam(value = "分类id", required = false) @RequestParam(required = false) Integer categoryId
+    ) {
+        List<ProductVo> list = productService.getProductList(categoryId);
+        return AjaxMessage.success(list);
+    }
+
 }

+ 48 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/download/adapter/InstallPlanExcelFillAdapter.java

@@ -0,0 +1,48 @@
+package com.zcxk.rmcp.web.excel.download.adapter;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.write.metadata.WriteSheet;
+import com.alibaba.excel.write.metadata.fill.FillConfig;
+import com.zcxk.rmcp.web.excel.download.AbstractDownloadExcelAdapter;
+import com.zcxk.rmcp.web.excel.model.InstallPlanInfoData;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author linqingwei
+ * @date 2021-07-30 10:55
+ */
+public class InstallPlanExcelFillAdapter extends AbstractDownloadExcelAdapter {
+    @Override
+    public AbstractDownloadExcelAdapter fillData() {
+        data.setTemplatePath("excel/installPlanTemplate.xlsx");
+
+        InputStream in = this.getClass().getClassLoader().getResourceAsStream(data.getTemplatePath());
+        ExcelWriter excelWriter = EasyExcel.write(data.getFilePath()).withTemplate(in).build();
+
+        //填充设备数据
+        WriteSheet installPalnSheet = EasyExcel.writerSheet("安装计划模板").build();
+        WriteSheet deviceTypeSheet = EasyExcel.writerSheet("设备型号").build();
+        WriteSheet orgSheet = EasyExcel.writerSheet("公司").build();
+        WriteSheet communitySheet = EasyExcel.writerSheet("小区").build();
+
+        excelWriter.fill(data.getProductDataList(), deviceTypeSheet);
+        excelWriter.fill(data.getOrgDataList(), orgSheet);
+        excelWriter.fill(data.getCommunityDataList(), communitySheet);
+
+        if (data.getInstallPlanInfoData() == null) {
+            data.setInstallPlanInfoData(new InstallPlanInfoData());
+        }
+
+        FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
+        excelWriter.fill(data.getInstallPlanInfoData(), fillConfig, installPalnSheet);
+        excelWriter.fill(data.getInstallPalnDataList(), fillConfig, installPalnSheet);
+
+        // 千万别忘记关闭流
+        excelWriter.finish();
+        return this;
+    }
+}

+ 61 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/download/service/InstallPlanService.java

@@ -0,0 +1,61 @@
+package com.zcxk.rmcp.web.excel.download.service;
+
+import com.zcxk.core.oauth2.util.UserUtil;
+import com.zcxk.rmcp.api.dto.ProductVo;
+import com.zcxk.rmcp.api.vo.CommunityVo;
+import com.zcxk.rmcp.core.dao.CommunityMapper;
+import com.zcxk.rmcp.core.dao.OrgMapper;
+import com.zcxk.rmcp.core.dao.ProductCategoryMapper;
+import com.zcxk.rmcp.core.dao.ProductMapper;
+import com.zcxk.rmcp.core.entity.Community;
+import com.zcxk.rmcp.core.entity.Org;
+import com.zcxk.rmcp.core.entity.ProductCategory;
+import com.zcxk.rmcp.web.excel.download.DownloadExcelService;
+import com.zcxk.rmcp.web.excel.model.CommImportData;
+import com.zcxk.rmcp.web.excel.model.DownloadExcelData;
+import com.zcxk.rmcp.web.service.CommonService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author linqingwei
+ * @date 2021-07-30 10:54
+ */
+@Service
+public class InstallPlanService implements DownloadExcelService {
+
+    @Resource
+    private ProductMapper productMapper;
+    @Resource
+    private OrgMapper orgMapper;
+    @Resource
+    private CommunityMapper communityMapper;
+    @Autowired
+    private CommonService commonService;
+
+    @Override
+    public void setParam(DownloadExcelData data) {
+        data.setFilePath(commonService.getExcelFilePath("template"));
+        data.setDownloadName("安装计划批量导入模板");
+
+
+        data.setProductDataList(convertProductData(productMapper.findList(data.getCategoryId())));
+        data.setCommunityDataList(convertCommunityData(communityMapper.listCommunity(new Community(), UserUtil.getCurrentUser().getUserCondition())));
+        data.setOrgDataList(convertOrgData(orgMapper.findList(UserUtil.getCurrentUser().getUserCondition())));
+    }
+    private List<CommImportData> convertCommunityData(List<CommunityVo> list){
+        return list.stream().map(vo ->new CommImportData(vo.getName(),Math.toIntExact(vo.getId()))).collect(Collectors.toList());
+    }
+
+    private List<CommImportData> convertOrgData(List<Org> list){
+        return list.stream().map(vo ->new CommImportData(vo.getOrgName(),Math.toIntExact(vo.getId()))).collect(Collectors.toList());
+    }
+    private List<CommImportData> convertProductData(List<ProductVo> list){
+        return list.stream().map(vo ->new CommImportData(vo.getManufacturerName()+"/"+vo.getProductName()+"/"+vo.getProductModel(),Math.toIntExact(vo.getId()))).collect(Collectors.toList());
+    }
+}

+ 2 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/model/DownloadExcelData.java

@@ -22,4 +22,6 @@ public class DownloadExcelData {
     private List<CommImportData> communityDataList;
     private List<CommImportData> orgDataList;
     private List<InstallMeterData> installMeterDataList;
+    private InstallPlanInfoData installPlanInfoData;
+    private List<InstallPalnData> installPalnDataList;
 }

+ 31 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/model/InstallPalnData.java

@@ -0,0 +1,31 @@
+package com.zcxk.rmcp.web.excel.model;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+/**
+ * @author linqingwei
+ * @date 2021-07-30 10:59
+ */
+@Data
+public class InstallPalnData {
+
+    @ExcelProperty(index = 0)
+    private String buildingName;
+    @ExcelProperty(index = 1)
+    private String unitName;
+    @ExcelProperty(index = 2)
+    private String floorName;
+    @ExcelProperty(index = 3)
+    private String doorNo;
+    @ExcelProperty(index = 4)
+    private String meterNo;
+    @ExcelProperty(index = 5)
+    private String username;
+    @ExcelProperty(index = 6)
+    private String phone;
+    @ExcelProperty(index = 7)
+    private String idCard;
+    @ExcelProperty(index = 8)
+    private String remark;
+}

+ 17 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/model/InstallPlanInfoData.java

@@ -0,0 +1,17 @@
+package com.zcxk.rmcp.web.excel.model;
+
+import lombok.Data;
+
+/**
+ * @author linqingwei
+ * @date 2021-07-30 11:17
+ */
+@Data
+public class InstallPlanInfoData {
+    private String companyName;
+    private String deptName;
+    private String communityName;
+    private String deviceTypeName;
+    private String unit;
+    private String phone;
+}

+ 33 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/excel/resolver/listener/InstallPlanListener.java

@@ -0,0 +1,33 @@
+package com.zcxk.rmcp.web.excel.resolver.listener;
+
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.alibaba.fastjson.JSON;
+import com.zcxk.rmcp.web.excel.model.InstallMeterData;
+import com.zcxk.rmcp.web.excel.model.InstallPalnData;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Map;
+
+/**
+ * @author linqingweidd
+ * @date 2021-07-30 11:39
+ */
+@Slf4j
+public class InstallPlanListener extends AnalysisEventListener<InstallPalnData> {
+    @Override
+    public void invoke(InstallPalnData installPalnData, AnalysisContext analysisContext) {
+        System.out.println(installPalnData);
+    }
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+
+    }
+
+    @Override
+    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
+        log.info("解析到一条头数据:{}", JSON.toJSONString(headMap));
+    }
+
+}

+ 3 - 1
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/AlarmRuleService.java

@@ -1,13 +1,15 @@
 package com.zcxk.rmcp.web.service;
 
+import com.zcxk.core.mysql.pageing.Pagination;
 import com.zcxk.rmcp.api.dto.alarm.AlarmRuleDto;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRulePageDto;
 import com.zcxk.rmcp.api.dto.alarm.ConfigDataDto;
 import com.zcxk.rmcp.api.dto.alarm.RuleMeasuringDto;
 
 import java.util.List;
 
 public interface AlarmRuleService {
-    List<AlarmRuleDto> getList(Integer alarmTypeId);
+    Pagination<AlarmRuleDto> getList(AlarmRulePageDto alarmTypeId);
 
     void add(AlarmRuleDto deviceAlarmRule);
 

+ 8 - 1
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/ProductService.java

@@ -1,7 +1,11 @@
 package com.zcxk.rmcp.web.service;
 
+import com.zcxk.rmcp.api.dto.ProductVo;
 import com.zcxk.rmcp.core.entity.Product;
-    /**
+
+import java.util.List;
+
+/**
  * 
  * @author linqingwei
  * @date 2021-07-21 9:43
@@ -16,4 +20,7 @@ public interface ProductService{
     Product getByName(String productName, String productModel);
 
     Product findById(Integer productId);
+
+    List<ProductVo> getProductList(Integer categoryId);
+
 }

+ 30 - 7
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/AlarmRuleServiceImpl.java

@@ -1,37 +1,60 @@
 package com.zcxk.rmcp.web.service.impl;
 
+import com.github.pagehelper.page.PageMethod;
+import com.zcxk.core.common.util.BeanCopyUtils;
+import com.zcxk.core.mysql.pageing.Pagination;
+import com.zcxk.core.oauth2.util.UserUtil;
 import com.zcxk.rmcp.api.dto.alarm.AlarmRuleDto;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRulePageDto;
 import com.zcxk.rmcp.api.dto.alarm.ConfigDataDto;
 import com.zcxk.rmcp.api.dto.alarm.RuleMeasuringDto;
+import com.zcxk.rmcp.api.dto.measurementSettlement.MeasurementSettlementDto;
+import com.zcxk.rmcp.core.dao.DeviceAlarmRuleMapper;
+import com.zcxk.rmcp.core.entity.DeviceAlarmRule;
 import com.zcxk.rmcp.web.service.AlarmRuleService;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 import java.util.List;
 @Service
 public class AlarmRuleServiceImpl implements AlarmRuleService {
+    @Resource
+    private DeviceAlarmRuleMapper deviceAlarmRuleMapper;
     @Override
-    public List<AlarmRuleDto> getList(Integer alarmTypeId) {
-        return null;
+    public Pagination<AlarmRuleDto> getList(AlarmRulePageDto alarmRulePageDto) {
+        PageMethod.startPage(alarmRulePageDto.getPageNum(),alarmRulePageDto.getPageSize());
+        List<AlarmRuleDto>alarmRuleDtos=deviceAlarmRuleMapper.selectList(alarmRulePageDto,
+                UserUtil.getCurrentUser().getUserCondition());
+        if (CollectionUtils.isEmpty(alarmRuleDtos)){
+            return new Pagination<>();
+        }
+        return new Pagination<>(alarmRuleDtos);
     }
 
     @Override
-    public void add(AlarmRuleDto deviceAlarmRule) {
-
+    public void add(AlarmRuleDto alarmRuleDto) {
+        DeviceAlarmRule deviceAlarmRule=new DeviceAlarmRule();
+        BeanCopyUtils.copyProperties(alarmRuleDto, deviceAlarmRule, DeviceAlarmRule.class);
+        deviceAlarmRuleMapper.insert(deviceAlarmRule);
     }
 
     @Override
-    public void edit(AlarmRuleDto deviceAlarmRule) {
-
+    public void edit(AlarmRuleDto alarmRuleDto) {
+        DeviceAlarmRule deviceAlarmRule=new DeviceAlarmRule();
+        BeanCopyUtils.copyProperties(alarmRuleDto, deviceAlarmRule, DeviceAlarmRule.class);
+        deviceAlarmRuleMapper.update(deviceAlarmRule);
     }
 
     @Override
     public void delete(List<Integer> ids) {
-
+        deviceAlarmRuleMapper.delete(ids);
     }
 
     @Override
     public void deleteAll() {
 
+        deviceAlarmRuleMapper.deleteAll( UserUtil.getCurrentUser().getUserCondition());
     }
 
     @Override

+ 35 - 4
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/AlarmTypeServiceImpl.java

@@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.page.PageMethod;
 import com.zcxk.core.common.util.BeanCopyUtils;
 import com.zcxk.core.mysql.pageing.Pagination;
+import com.zcxk.core.oauth2.util.UserUtil;
 import com.zcxk.rmcp.api.dto.alarm.AlarmTypeDto;
 import com.zcxk.rmcp.api.dto.alarm.AlarmTypePageDto;
 import com.zcxk.rmcp.core.dao.AlarmTypeMapper;
@@ -14,6 +15,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 @Service
 public class AlarmTypeServiceImpl implements AlarmTypeService {
@@ -22,7 +24,8 @@ public class AlarmTypeServiceImpl implements AlarmTypeService {
     @Override
     public Pagination<AlarmTypeDto> getAlarmTypePage(AlarmTypePageDto alarmTypePageDto) {
         PageMethod.startPage(alarmTypePageDto.getPageNum(),alarmTypePageDto.getPageSize());
-        List<AlarmTypeDto> alarmTypes = alarmTypeMapper.selectList(alarmTypePageDto);
+        List<AlarmTypeDto> alarmTypes = alarmTypeMapper.selectList(alarmTypePageDto
+                , UserUtil.getCurrentUser().getUserCondition());
         if (CollectionUtils.isEmpty(alarmTypes)){
             return new Pagination<>();
         }
@@ -32,6 +35,8 @@ public class AlarmTypeServiceImpl implements AlarmTypeService {
     @Override
     public void add(AlarmTypeDto alarmTypeDto) {
         AlarmType alarmType=new AlarmType();
+        alarmType.setStatus(1);
+        alarmType.setAlarmStatus(1);
         BeanCopyUtils.copyProperties(alarmTypeDto, alarmType, AlarmType.class);
         alarmTypeMapper.insert(alarmType);
     }
@@ -45,17 +50,43 @@ public class AlarmTypeServiceImpl implements AlarmTypeService {
 
     @Override
     public int delete(List<Integer> ids) {
-        //alarmTypeMapper.selectTypesWithRules(ids);
-        return 0;
+        List<AlarmType>alarmTypes=alarmTypeMapper.selectTypesWithRules(ids);
+        if(CollectionUtils.isEmpty(alarmTypes)){
+            alarmTypeMapper.delete(ids);
+            return 0;
+        }
+        return 1;
     }
 
     @Override
     public int deleteAll() {
-        return 0;
+        List<AlarmTypeDto>alarmTypeDtos=alarmTypeMapper.selectList(new AlarmTypePageDto(),
+                UserUtil.getCurrentUser().getUserCondition());
+        List<Integer>ids=new ArrayList<>();
+        alarmTypeDtos.forEach(alarmTypeDto -> {
+            ids.add(alarmTypeDto.getId());
+        });
+        List<AlarmType>alarmTypes=alarmTypeMapper.selectTypesWithRules(ids);
+        if(CollectionUtils.isEmpty(alarmTypes)){
+            alarmTypeMapper.delete(ids);
+            return 0;
+        }
+        return 1;
     }
 
     @Override
     public void updateStatus(Integer id) {
+        AlarmType alarmType = alarmTypeMapper.selectById(id);
+        if (alarmType != null) {
+            alarmType.setId(id);
+            if (alarmType.getStatus() == 1) {
+                alarmType.setStatus(2);//禁用
+            } else {
+                alarmType.setStatus(1);//正常
+            }
+           alarmTypeMapper.update(alarmType);
+
+        }
 
     }
 }

+ 115 - 1
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/OrgServiceImpl.java

@@ -1,13 +1,22 @@
 package com.zcxk.rmcp.web.service.impl;
 
+import com.zcxk.core.common.pojo.ProgramItem;
+import com.zcxk.core.oauth2.pojo.LoginUser;
+import com.zcxk.core.oauth2.util.UserUtil;
 import com.zcxk.rmcp.api.vo.OrgTreeVo;
 import com.zcxk.rmcp.web.service.OrgService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import com.zcxk.rmcp.core.dao.OrgMapper;
 import com.zcxk.rmcp.core.entity.Org;
 
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+
+import static com.google.common.collect.Lists.newArrayList;
 
 /**
  * 
@@ -32,7 +41,112 @@ public class OrgServiceImpl implements OrgService {
 
     @Override
     public List<OrgTreeVo> getUserTrees(Org org) {
-        return null;
+        LoginUser currentUser = UserUtil.getCurrentUser();
+        org.setTenantId(currentUser.getTenantId());
+        Integer id=org.getId();
+        org.setId(null);
+        Set<Integer> orgIds=new HashSet<>();
+        List<ProgramItem> programItemList = currentUser.getProgramItemList();
+        if(programItemList!=null){
+            programItemList.forEach(programItem -> {
+                orgIds.add(programItem.getOrgId());
+            });
+        }
+
+        List<OrgTreeVo> trees = new ArrayList<>();
+        if("company".equals(org.getOrgType())){
+
+            if(currentUser.getDepartmentId()==null&&currentUser.getPermissonType()==2){
+                trees=orgMapper.selectTrees(org);
+                trees=getOrgTreeByOrg(trees,currentUser.getCompanyId(),orgIds);
+            }else{
+                org.setId(currentUser.getCompanyId());
+                trees=orgMapper.selectTrees(org);
+            }
+        }else{
+            if(currentUser.getDepartmentId()!=null&&currentUser.getPermissonType()==4){
+                org.setOrgType("department");
+                trees=orgMapper.selectTrees(org);
+                trees=getOrgTreeByOrg(trees,currentUser.getDepartmentId(),orgIds);
+            }if(currentUser.getDepartmentId()!=null&&currentUser.getPermissonType()==3){
+                org.setId(currentUser.getDepartmentId());
+                trees=orgMapper.selectTrees(org);
+            }else{
+                trees=orgMapper.selectTrees(org);
+                trees=getOrgDepartmentTree(trees,id);
+
+            }
+
+        }
+
+        return trees;
+    }
+
+    List<OrgTreeVo> getOrgTreeByOrg(List<OrgTreeVo> trees,int id, Set<Integer>orgIds){
+        OrgTreeVo fatherOrgTree=new OrgTreeVo();
+        for (OrgTreeVo tree : trees) {
+            if(tree.getId()==id){
+                fatherOrgTree=tree;
+                break;
+            }
+
+        }
+
+        trees=getOrgTree(trees,id,1,orgIds);
+        fatherOrgTree.setOrgs(trees);
+        List<OrgTreeVo> result=new ArrayList<>();
+        result.add(fatherOrgTree);
+        trees=result;
+        return trees;
+    }
+    public  List<OrgTreeVo> getOrgTree(List<OrgTreeVo> list, Integer id, Integer level, Set<Integer>orgIds) {
+        List<OrgTreeVo> temList = newArrayList();
+        if (list != null) {
+            for (OrgTreeVo orgTree : list) {
+
+                if (id.equals(orgTree.getParentOrgId())) {
+
+                    orgTree.setDisabled(false);
+
+                    List<OrgTreeVo> chidren = getOrgTree(list, orgTree.getId(),level,orgIds);
+                    OrgTreeVo temPermission = new OrgTreeVo();
+                    BeanUtils.copyProperties(orgTree, temPermission);
+                    temPermission.setOrgs(chidren);
+                    temList.add(temPermission);
+                    level--;
+                }
+
+            }
+        }
+        if (temList.size() > 0) {
+            return temList;
+        } else {
+            return null;
+        }
+    }
+    public  List<OrgTreeVo> getOrgDepartmentTree(List<OrgTreeVo> list, Integer id) {
+        List<OrgTreeVo> temList = newArrayList();
+        if (list != null) {
+            for (OrgTreeVo orgTree : list) {
+
+                if (id.equals(orgTree.getParentOrgId())
+                        &&"department".equals(orgTree.getOrgType())) {
+
+                    List<OrgTreeVo> chidren = getOrgDepartmentTree(list, orgTree.getId());
+                    OrgTreeVo temPermission = new OrgTreeVo();
+                    BeanUtils.copyProperties(orgTree, temPermission);
+                    temPermission.setOrgs(chidren);
+                    temList.add(temPermission);
+                    ;
+                }
+
+            }
+        }
+        if (temList.size() > 0) {
+            return temList;
+        } else {
+            return null;
+        }
     }
 
     @Override

+ 13 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/ProductServiceImpl.java

@@ -1,11 +1,17 @@
 package com.zcxk.rmcp.web.service.impl;
 
+import com.zcxk.rmcp.api.dto.ProductVo;
 import com.zcxk.rmcp.web.service.ProductService;
 import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import com.zcxk.rmcp.core.dao.ProductMapper;
 import com.zcxk.rmcp.core.entity.Product;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static com.google.common.collect.Lists.newArrayList;
+
 /**
  * 
  * @author linqingwei
@@ -36,4 +42,11 @@ public class ProductServiceImpl implements ProductService {
     public Product findById(Integer productId) {
         return productMapper.findById(productId);
     }
+
+    @Override
+    public List<ProductVo> getProductList(Integer categoryId) {
+        return productMapper.findList(categoryId);
+    }
+
+
 }

BIN
zoniot-rmcp/zoniot-rmcp-web/src/main/resources/excel/installPlanTemplate.xlsx


+ 23 - 0
zoniot-rmcp/zoniot-rmcp-web/src/test/java/com/zcxk/rmcp/web/CommDataListener.java

@@ -0,0 +1,23 @@
+package com.zcxk.rmcp.web;
+
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.zcxk.rmcp.web.excel.model.CommImportData;
+
+/**
+ * @author linqingwei
+ * @date 2021-07-22 18:42
+ */
+public class CommDataListener extends AnalysisEventListener<CommImportData> {
+
+
+    @Override
+    public void invoke(CommImportData commImportData, AnalysisContext analysisContext) {
+        System.out.println(commImportData);
+    }
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+
+    }
+}

+ 34 - 0
zoniot-rmcp/zoniot-rmcp-web/src/test/java/com/zcxk/rmcp/web/DemoDataListener.java

@@ -0,0 +1,34 @@
+package com.zcxk.rmcp.web;
+
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.alibaba.excel.read.listener.ReadListener;
+import com.zcxk.rmcp.web.excel.model.DeviceImportData;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author linqingwei
+ * @date 2021-07-22 18:37
+ */
+public class DemoDataListener extends AnalysisEventListener<DeviceImportData> {
+
+    private List<DeviceImportData> list = new ArrayList<>();
+    @Override
+    public void invoke(DeviceImportData deviceImportData, AnalysisContext analysisContext) {
+        if (deviceImportData != null && deviceImportData.getDeviceNo() != null) {
+            System.out.println(deviceImportData);
+            list.add(deviceImportData);
+        }
+    }
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+        System.out.println(analysisContext);
+    }
+    public List<DeviceImportData> getData(){
+        return list;
+    }
+
+}

+ 155 - 0
zoniot-rmcp/zoniot-rmcp-web/src/test/java/com/zcxk/rmcp/web/Excel.java

@@ -0,0 +1,155 @@
+package com.zcxk.rmcp.web;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelReader;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.read.metadata.ReadSheet;
+import com.alibaba.excel.write.metadata.WriteSheet;
+import com.alibaba.excel.write.metadata.fill.FillConfig;
+import com.zcxk.rmcp.core.entity.Community;
+import com.zcxk.rmcp.web.excel.model.CommImportData;
+import com.zcxk.rmcp.web.excel.model.DeviceImportData;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author linqingwei
+ * @date 2021-07-22 11:39
+ */
+public class Excel {
+
+    @Test
+    public void listFill() {
+        // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
+        // 填充list 的时候还要注意 模板中{.} 多了个点 表示list
+        String templateFileName = "E:\\test\\deviceTemplate_V2.1.xlsx";
+
+        // 方案1 一下子全部放到内存里面 并填充
+        //String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx";
+        // 这里 会填充到第一个sheet, 然后文件流会自动关闭
+        //EasyExcel.write(fileName).withTemplate(templateFileName).sheet().doFill(data());
+
+        List<Community> list = new ArrayList<>();
+        Community community1 = new Community();
+        community1.setId(1);
+        community1.setName("小区1");
+        list.add(community1);
+        Community community2 = new Community();
+        community2.setId(2);
+        community2.setName("小区2");
+        list.add(community2);
+        // 方案2 分多次 填充 会使用文件缓存(省内存)
+        String fileName = "E:\\test\\test1.xlsx";
+        ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
+        WriteSheet deviceSheet = EasyExcel.writerSheet("档案管理-批量导入").build();
+        WriteSheet deviceTypeSheet = EasyExcel.writerSheet("设备型号").build();
+        WriteSheet orgSheet = EasyExcel.writerSheet("公司").build();
+        WriteSheet writeSheet = EasyExcel.writerSheet("小区").build();
+        //excelWriter.fill(new ArrayList<DeviceImportData>(), deviceSheet);
+        //excelWriter.fill(new ArrayList<>(), deviceTypeSheet);
+        //excelWriter.fill(new ArrayList<>(), orgSheet);
+        excelWriter.fill(list, writeSheet);
+
+        // 千万别忘记关闭流
+        excelWriter.finish();
+
+    }
+
+    @Test
+    public void repeatedRead() {
+
+        String fileName = "E:\\test\\template.xlsx";
+        // 读取全部sheet
+        // 这里需要注意 DemoDataListener的doAfterAllAnalysed 会在每个sheet读取完毕后调用一次。然后所有sheet都会往同一个DemoDataListener里面写
+        //EasyExcel.read(fileName, DeviceImportData.class, new DemoDataListener()).doReadAll();
+
+        // 读取部分sheet
+        //fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
+        ExcelReader excelReader = EasyExcel.read(fileName).build();
+        // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener
+        DemoDataListener demoDataListener = new DemoDataListener();
+
+        ReadSheet readSheet1 =
+                EasyExcel.readSheet(0).head(DeviceImportData.class).headRowNumber(4).registerReadListener(demoDataListener).build();
+        ReadSheet readSheet2 =
+                EasyExcel.readSheet(1).head(CommImportData.class).registerReadListener(new CommDataListener()).build();
+        // 这里注意 一定要把sheet1 sheet2 一起传进去,不然有个问题就是03版的excel 会读取多次,浪费性能
+        excelReader.read(readSheet1, readSheet2);
+        // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
+        excelReader.finish();
+
+        List<DeviceImportData> list = demoDataListener.getData();
+        System.out.println(list);
+    }
+
+    @Test
+    public void templateWrite() {
+        List<DeviceImportData> list = new ArrayList<>();
+        DeviceImportData data1 = new DeviceImportData();
+        data1.setDeviceNo("11111111111");
+        data1.setMeterNo("11111111111");
+        data1.setDeviceTypeName("华旭/LoRaWAN水表/智能水表");
+
+        DeviceImportData data2 = new DeviceImportData();
+        data2.setDeviceNo("2222222222222");
+        data2.setMeterNo("22222222222222");
+        data2.setDeviceTypeName("华旭/LoRaWAN水表/智能水表");
+        list.add(data1);
+        list.add(data2);
+
+        String templateFileName = "E:\\test\\template.xlsx";
+        String fileName = "E:\\test\\test.xlsx";
+        // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
+        EasyExcel.write(fileName, DeviceImportData.class).withTemplate(templateFileName).sheet().doWrite(list);
+    }
+
+
+    @Test
+    public void complexFill() {
+
+        List<CommImportData> list = new ArrayList<>();
+        CommImportData data1 = new CommImportData();
+        data1.setId(1);
+        data1.setName("测试1");
+        list.add(data1);
+        CommImportData data2 = new CommImportData();
+        data2.setId(2);
+        data2.setName("测试2");
+        list.add(data2);
+
+        List<CommImportData> list1 = new ArrayList<>();
+        CommImportData data3 = new CommImportData();
+        data3.setId(3);
+        data3.setName("测试3");
+        list1.add(data3);
+        // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
+        // {} 代表普通变量 {.} 代表是list的变量
+        String templateFileName = "E:\\test\\installPlanTemplate20210727.xlsx";
+
+        String fileName = "E:\\test\\test2.xlsx";
+        ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
+        WriteSheet listheet = EasyExcel.writerSheet("安装计划").build();
+        WriteSheet deviceTypeSheet = EasyExcel.writerSheet("设备型号").build();
+        WriteSheet orgSheet = EasyExcel.writerSheet("公司").build();
+        WriteSheet writeSheet = EasyExcel.writerSheet("小区").build();
+        // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行,然后下面的数据往后移动。默认 是false,会直接使用下一行,如果没有则创建。
+        // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了,所以慎用
+        // 简单的说 如果你的模板有list,且list不是最后一行,下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
+        // 如果数据量大 list不是最后一行 参照下一个
+        excelWriter.fill(list, deviceTypeSheet);
+        excelWriter.fill(list1, orgSheet);
+        excelWriter.fill(list, writeSheet);
+
+        Map<String,String> map = new HashMap<>();
+        map.put("unit","test");
+        map.put("phone","test1");
+        FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
+        excelWriter.fill(map, fillConfig, listheet);
+        excelWriter.fill(list1, fillConfig, listheet);
+        excelWriter.finish();
+    }
+}