Parcourir la source

完成项目管理开发

sptkw il y a 2 ans
Parent
commit
ff3756d425
12 fichiers modifiés avec 370 ajouts et 71 suppressions
  1. 12 0
      iot-module/iot-module-manage/iot-module-manage-api/src/main/java/com/middle/platform/manage/api/enums/ApiConstants.java
  2. 21 0
      iot-module/iot-module-manage/iot-module-manage-api/src/main/java/com/middle/platform/manage/api/enums/DeviceStatus.java
  3. 4 0
      iot-module/iot-module-manage/iot-module-manage-biz/pom.xml
  4. 30 10
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotProjectController.java
  5. 24 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/ChangeStatus.java
  6. 42 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/IotProjectPara.java
  7. 20 0
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/IotProjectVo.java
  8. 15 3
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProjectDeviceMapper.java
  9. 10 4
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProjectMapper.java
  10. 55 5
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotProjectService.java
  11. 42 18
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProjectDeviceMapper.xml
  12. 95 31
      iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProjectMapper.xml

+ 12 - 0
iot-module/iot-module-manage/iot-module-manage-api/src/main/java/com/middle/platform/manage/api/enums/ApiConstants.java

@@ -0,0 +1,12 @@
+package com.middle.platform.manage.api.enums;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-03 10:28:58
+ */
+public class ApiConstants {
+    public static final String NAME = "iot-manage";
+
+    public static final String VERSION = "1.0.0";
+
+}

+ 21 - 0
iot-module/iot-module-manage/iot-module-manage-api/src/main/java/com/middle/platform/manage/api/enums/DeviceStatus.java

@@ -0,0 +1,21 @@
+package com.middle.platform.manage.api.enums;
+
+/**
+ * 设备在线状态
+ *
+ * @author Aick Spt
+ * @date 2023-12-21 17:27
+ */
+public class DeviceStatus {
+    public static final int ONLINE_VAL = 1;//在线
+
+    public static final int OFFLINE_VAL = 0;//离线
+
+    public static final String ONLINE = "在线";
+
+    public static final String OFFLINE = "离线";
+
+    public String getStatus(Integer status) {
+        return (status.equals(ONLINE_VAL)) ? ONLINE : OFFLINE;
+    }
+}

+ 4 - 0
iot-module/iot-module-manage/iot-module-manage-biz/pom.xml

@@ -66,5 +66,9 @@
             <groupId>com.middle.platform</groupId>
             <artifactId>iot-module-system-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.middle.platform</groupId>
+            <artifactId>iot-module-manage-api</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 30 - 10
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/controller/IotProjectController.java

@@ -1,9 +1,11 @@
 package com.middle.platform.manage.biz.controller;
 
 import com.middle.platform.common.utils.Result;
+import com.middle.platform.manage.biz.domain.req.ChangeStatus;
+import com.middle.platform.manage.biz.domain.req.IotProjectPara;
 import com.middle.platform.manage.biz.domain.req.ProjectPage;
-import com.middle.platform.manage.biz.service.IotProductService;
 import com.middle.platform.manage.biz.service.IotProjectService;
+import jakarta.validation.constraints.NotNull;
 import lombok.RequiredArgsConstructor;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -30,20 +32,38 @@ public class IotProjectController {
     }
 
     /**
-     * 新增产品
+     * 新增项目
      */
     @PostMapping("/save")
-    public Result<Object> save(@RequestBody @Validated ProjectPage iotProjectPara) {
-        return Result.ok();
-//        return Result.ok(iotProjectService.save(iotProjectPara));
+    public Result<Object> save(@RequestBody @Validated IotProjectPara iotProjectPara) {
+        return Result.ok(iotProjectService.save(iotProjectPara), "保存成功");
     }
 
     /**
-     * 删除产品
+     * 删除项目
      */
-    @DeleteMapping("/remove/{id}")
-    public Result<Object> remove(@PathVariable("id") Long id) {
-        return Result.ok(1, "删除成功");
-//        return Result.ok(iotProjectService.remove(id), "删除成功");
+    @DeleteMapping("/remove")
+    public Result<Object> remove(@RequestParam("id") @NotNull(message = "id不能为空") Long id) {
+        return Result.ok(iotProjectService.remove(id), "删除成功");
     }
+
+    /**
+     * 项目状态更改
+     */
+    @PostMapping("/changeStatus")
+    public Result<Object> changeStatus(@RequestBody @Validated ChangeStatus changeStatus) {
+        int suc = iotProjectService.changeStatus(changeStatus);
+        return Result.ok(suc, (suc == 1) ? "成功" : "失败或状态未变化");
+    }
+
+
+    /**
+     * 项目详情
+     */
+    @GetMapping("/detail")
+    public Result<Object> detail(@RequestParam("id") @NotNull(message = "id不能为空") Long id) {
+        return Result.ok(iotProjectService.detail(id), "查询成功");
+    }
+
+
 }

+ 24 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/ChangeStatus.java

@@ -0,0 +1,24 @@
+package com.middle.platform.manage.biz.domain.req;
+
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 更改状态
+ *
+ * @author Aick Spt
+ * @date 2023-12-22 11:14
+ */
+@Getter
+@Setter
+public class ChangeStatus {
+
+    @NotNull(message = "ID值不能为空")
+    public Long id;
+
+    @NotNull(message = "状态值不能为空")
+    public Integer status;
+
+}

+ 42 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/req/IotProjectPara.java

@@ -0,0 +1,42 @@
+package com.middle.platform.manage.biz.domain.req;
+
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目新增参数
+ * @author Aick Spt
+ * @date 2023-12-22 09:34
+ */
+@Getter
+@Setter
+public class IotProjectPara {
+
+    /**
+     * 项目所属企业字典值
+     */
+    @NotNull(message = "项目所属企业不能为空")
+    private Long companyId;
+
+
+    /**
+     * 项目名称
+     */
+    @NotBlank(message = "项目名称不能为空")
+    private String title;
+
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+
+    /**
+     * 状态
+     */
+    @NotNull(message = "项目状态不能为空")
+    private Integer status;
+}

+ 20 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/domain/vo/IotProjectVo.java

@@ -37,6 +37,11 @@ public class IotProjectVo extends BaseVO {
      */
     private Long companyId;
 
+    /**
+     *  所属企业名称
+     */
+    private String companyName;
+
     /**
      *  备注
      */
@@ -47,4 +52,19 @@ public class IotProjectVo extends BaseVO {
      */
     private Integer status;
 
+    /**
+     * 状态 0 正常 1 停用
+     */
+    private String statusName;
+
+    /**
+     * 设备总数量
+     */
+    private Integer deviceNum;
+
+    /**
+     * 设备在线数量
+     */
+    private Integer deviceOnlineNum;
+
 }

+ 15 - 3
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProjectDeviceMapper.java

@@ -3,11 +3,23 @@ package com.middle.platform.manage.biz.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.middle.platform.manage.biz.entity.IotProjectDevice;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
-* @date 2023-12-19 13:43:38
-* @author xucaiqin
-*/
+ * @author xucaiqin
+ * @date 2023-12-19 13:43:38
+ */
 @Mapper
 public interface IotProjectDeviceMapper extends BaseMapper<IotProjectDevice> {
+
+
+    /**
+     * 查找项目对应设备
+     *
+     * @author Aick Spt
+     * @date 2023-12-21 16:49
+     */
+    Integer queryDeviceNum(@Param("projectId") Long projectId, @Param("status") Integer status);
+
+
 }

+ 10 - 4
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProjectMapper.java

@@ -1,11 +1,12 @@
 package com.middle.platform.manage.biz.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.middle.platform.manage.biz.domain.req.ProductPage;
+import com.middle.platform.manage.biz.domain.req.ChangeStatus;
 import com.middle.platform.manage.biz.domain.req.ProjectPage;
-import com.middle.platform.manage.biz.domain.vo.IotProductVo;
+import com.middle.platform.manage.biz.domain.vo.IotProjectVo;
 import com.middle.platform.manage.biz.entity.IotProject;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -17,9 +18,14 @@ import java.util.List;
 public interface IotProjectMapper extends BaseMapper<IotProject> {
 
     /**
-     * 分页查询
+     * 分页项目查询
      */
-    List<IotProductVo> pageQuery(ProjectPage projectPage);
+    List<IotProjectVo> pageQuery(ProjectPage projectPage);
 
 
+    int delete(@Param("id") Long id);
+
+    IotProjectVo detail(@Param("id") Long id);
+
+    int changeStatus(@Param("changeStatus") ChangeStatus changeStatus);
 }

+ 55 - 5
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotProjectService.java

@@ -1,30 +1,80 @@
 package com.middle.platform.manage.biz.service;
 
+import cn.hutool.core.util.IdUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageHelper;
 import com.middle.platform.common.utils.PageRes;
+import com.middle.platform.manage.api.enums.DeviceStatus;
+import com.middle.platform.manage.biz.domain.req.ChangeStatus;
+import com.middle.platform.manage.biz.domain.req.IotProjectPara;
 import com.middle.platform.manage.biz.domain.req.ProjectPage;
-import com.middle.platform.manage.biz.domain.vo.IotProductVo;
+import com.middle.platform.manage.biz.domain.vo.IotProjectVo;
 import com.middle.platform.manage.biz.entity.IotProject;
+import com.middle.platform.manage.biz.mapper.IotProjectDeviceMapper;
 import com.middle.platform.manage.biz.mapper.IotProjectMapper;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.util.Arrays;
 import java.util.List;
 
 /**
-* @date 2023-12-19 13:43:38
-* @author xucaiqin
-*/
+ * @author xucaiqin
+ * @date 2023-12-19 13:43:38
+ */
 @Service
 @RequiredArgsConstructor
 public class IotProjectService extends ServiceImpl<IotProjectMapper, IotProject> {
 
     private final IotProjectMapper iotProjectMapper;
+    private final IotProjectDeviceMapper iotProjectDeviceMapper;
 
     public Object pageQuery(ProjectPage projectPage) {
         PageHelper.startPage(projectPage.getPage(), projectPage.getPageSize());
-        List<IotProductVo> iotProductVos = iotProjectMapper.pageQuery(projectPage);
+        List<IotProjectVo> iotProductVos = iotProjectMapper.pageQuery(projectPage);
+        iotProductVos.forEach(this::getIotProjectStatusAndDeviceNum);
         return new PageRes<>(iotProductVos);
     }
+
+    /**
+     * 新增
+     *
+     * @author Aick Spt
+     * @date 2023-12-22 09:41
+     */
+    public Object save(IotProjectPara iotProjectPara) {
+        IotProject iotProject = new IotProject();
+        iotProject.setCode(IdUtil.nanoId(12));
+        iotProject.setRemark(iotProjectPara.getRemark());
+        iotProject.setTitle(iotProjectPara.getTitle());
+        iotProject.setStatus(iotProjectPara.getStatus());
+        iotProject.setCompanyId(iotProjectPara.getCompanyId());
+        return iotProjectMapper.insert(iotProject);
+    }
+
+
+    public int remove(Long id) {
+        return iotProjectMapper.delete(id);
+    }
+
+    public IotProjectVo detail(Long id) {
+        IotProjectVo iotProjectVo = iotProjectMapper.detail(id);
+        return this.getIotProjectStatusAndDeviceNum(iotProjectVo);
+    }
+
+    private IotProjectVo getIotProjectStatusAndDeviceNum(IotProjectVo iotProjectVo) {
+        iotProjectVo.setStatusName((iotProjectVo.getStatus().equals(1)) ? "停用" : "正常");
+        Integer deviceNum = iotProjectDeviceMapper.queryDeviceNum(iotProjectVo.getId(), null);
+        Integer deviceOnlineNum = iotProjectDeviceMapper.queryDeviceNum(iotProjectVo.getId(), DeviceStatus.ONLINE_VAL);
+        iotProjectVo.setDeviceNum(deviceNum);
+        iotProjectVo.setDeviceOnlineNum(deviceOnlineNum);
+        return iotProjectVo;
+    }
+
+    public int changeStatus(ChangeStatus changeStatus) {
+        if (Arrays.asList(0, 1).contains(changeStatus.status)) {
+            return iotProjectMapper.changeStatus(changeStatus);
+        }
+        return 0;
+    }
 }

+ 42 - 18
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProjectDeviceMapper.xml

@@ -1,22 +1,46 @@
 <?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.middle.platform.manage.biz.mapper.IotProjectDeviceMapper">
-  <resultMap id="BaseResultMap" type="com.middle.platform.manage.biz.entity.IotProjectDevice">
-    <!--@mbg.generated-->
-    <!--@Table iot_project_device-->
-    <id column="id" jdbcType="BIGINT" property="id" />
-    <result column="project_id" jdbcType="BIGINT" property="projectId" />
-    <result column="device_id" jdbcType="BIGINT" property="deviceId" />
-    <result column="create_by" jdbcType="BIGINT" property="createBy" />
-    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
-    <result column="update_by" jdbcType="BIGINT" property="updateBy" />
-    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
-    <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime" />
-    <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
-  </resultMap>
-  <sql id="Base_Column_List">
-    <!--@mbg.generated-->
-    id, project_id, device_id, create_by, update_time, update_by, create_time, delete_time, 
-    del_flag
-  </sql>
+    <resultMap id="BaseResultMap" type="com.middle.platform.manage.biz.entity.IotProjectDevice">
+        <!--@mbg.generated-->
+        <!--@Table iot_project_device-->
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="project_id" jdbcType="BIGINT" property="projectId"/>
+        <result column="device_id" jdbcType="BIGINT" property="deviceId"/>
+        <result column="create_by" jdbcType="BIGINT" property="createBy"/>
+        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
+        <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime"/>
+        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        <!--@mbg.generated-->
+        id,
+        project_id,
+        device_id,
+        create_by,
+        update_time,
+        update_by,
+        create_time,
+        delete_time,
+        del_flag
+    </sql>
+
+    <select id="queryDeviceNum" resultType="java.lang.Integer">
+        select count(ipd.id) as deviceNum
+        from iot_project_device ipd
+                 left join iot_device ide on ide.id = ipd.device_id
+        <where>
+            ipd.del_flag = 0
+              and ide.del_flag = 0
+              and ide.enable_flag = 1
+            <if test="projectId != null">
+                and ipd.project_id = #{projectId}
+            </if>
+            <if test="status != null">
+                and ide.status = #{status}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 95 - 31
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProjectMapper.xml

@@ -1,36 +1,100 @@
 <?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.middle.platform.manage.biz.mapper.IotProjectMapper">
-  <resultMap id="BaseResultMap" type="com.middle.platform.manage.biz.entity.IotProject">
-    <!--@mbg.generated-->
-    <!--@Table iot_project-->
-    <id column="id" jdbcType="BIGINT" property="id" />
-    <result column="company_id" jdbcType="BIGINT" property="companyId" />
-    <result column="code" jdbcType="VARCHAR" property="code" />
-    <result column="title" jdbcType="VARCHAR" property="title" />
-    <result column="remark" jdbcType="VARCHAR" property="remark" />
-    <result column="status" jdbcType="TINYINT" property="status" />
-    <result column="create_by" jdbcType="BIGINT" property="createBy" />
-    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
-    <result column="update_by" jdbcType="BIGINT" property="updateBy" />
-    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
-    <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime" />
-    <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
-  </resultMap>
-  <sql id="Base_Column_List">
-    <!--@mbg.generated-->
-    id, company_id, code, title, remark, `status`, create_by, create_time, update_by, 
-    update_time, delete_time, del_flag
-  </sql>
+    <resultMap id="BaseResultMap" type="com.middle.platform.manage.biz.entity.IotProject">
+        <!--@mbg.generated-->
+        <!--@Table iot_project-->
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="company_id" jdbcType="BIGINT" property="companyId"/>
+        <result column="code" jdbcType="VARCHAR" property="code"/>
+        <result column="title" jdbcType="VARCHAR" property="title"/>
+        <result column="remark" jdbcType="VARCHAR" property="remark"/>
+        <result column="status" jdbcType="TINYINT" property="status"/>
+        <result column="create_by" jdbcType="BIGINT" property="createBy"/>
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
+        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
+        <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime"/>
+        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        <!--@mbg.generated-->
+        id,
+        company_id,
+        code,
+        title,
+        remark,
+        `status`,
+        create_by,
+        create_time,
+        update_by,
+        update_time,
+        delete_time,
+        del_flag
+    </sql>
 
-  <select id="pageQuery" resultType="com.middle.platform.manage.biz.domain.vo.IotProjectVo">
-    select *
-    from iot_project
-    <where>
-      del_flag = 0
-      <if test="keywords != null and keywords != ''">
-        and title like concat('%', #{keywords,jdbcType=VARCHAR}, '%')
-      </if>
-    </where>
-  </select>
+    <select id="pageQuery" resultType="com.middle.platform.manage.biz.domain.vo.IotProjectVo">
+        select ipr.id,
+               ipr.company_id,
+               ipr.code,
+               ipr.title,
+               ipr.remark,
+               ipr.`status`,
+               ipr.create_by,
+               ipr.create_time,
+               ipr.update_by,
+               ipr.update_time,
+               ipr.delete_time,
+               ipr.del_flag,
+               sdi.label companyName
+        from iot_project ipr
+                 left join sys_dict_item sdi on ipr.company_id = sdi.value
+        <where>
+            ipr.del_flag = 0
+              and sdi.type = 'company_msg'
+            <if test="keywords != null and keywords != ''">
+                and ipr.title like concat('%', #{keywords,jdbcType=VARCHAR}, '%')
+            </if>
+        </where>
+    </select>
+
+
+    <delete id="delete">
+        update iot_project
+        set del_flag = 1
+        <where>
+            id = #{id,jdbcType=BIGINT}
+        </where>
+    </delete>
+
+    <select id="detail" resultType="com.middle.platform.manage.biz.domain.vo.IotProjectVo">
+        select ipr.id,
+               ipr.company_id,
+               ipr.code,
+               ipr.title,
+               ipr.remark,
+               ipr.`status`,
+               ipr.create_by,
+               ipr.create_time,
+               ipr.update_by,
+               ipr.update_time,
+               ipr.delete_time,
+               ipr.del_flag,
+               sdi.label companyName
+        from iot_project ipr
+                 left join sys_dict_item sdi on ipr.company_id = sdi.value
+        <where>
+            ipr.del_flag = 0
+              and sdi.type = 'company_msg'
+              and ipr.id = #{id,jdbcType=BIGINT}
+        </where>
+    </select>
+
+    <update id="changeStatus">
+        update iot_project
+        set status = #{changeStatus.status,jdbcType=INTEGER}
+        <where>
+            id = #{changeStatus.id,jdbcType=BIGINT}
+        </where>
+    </update>
 </mapper>