Browse Source

设备分页-统计

tanbin 1 month ago
parent
commit
9b6897ca72

+ 19 - 0
device-api-service-merc-mini/src/main/java/com/xy/controller/MercPcDeviceController.java

@@ -13,6 +13,7 @@ import com.xy.collections.list.JArrayList;
 import com.xy.collections.map.JMap;
 import com.xy.device.EnumDeviceActiveStatus;
 import com.xy.device.EnumDeviceFreezeStatus;
+import com.xy.device.EnumDeviceOnlineStatus;
 import com.xy.dto.*;
 import com.xy.dto.be.MercDto;
 import com.xy.dto.common.MercPlaceDto;
@@ -42,6 +43,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import javax.validation.Valid;
 import java.time.LocalDateTime;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
 
@@ -57,6 +59,7 @@ public class MercPcDeviceController {
 
     private final DeviceInfoServiceImpl deviceService;
     private final MercService mercService;
+    private final DeviceStatusServiceImpl deviceStatusService;
 
     @ApiOperation("设备分页-商户")
     @PostMapping("page")
@@ -75,6 +78,22 @@ public class MercPcDeviceController {
         return R.ok(vo2PageBean);
     }
 
+    @ApiOperation("设备分页-统计")
+    @PostMapping("pageCount")
+    public R<DeviceInfoDto.PageCount> pageCount(@RequestBody DeviceInfoDto.Page page) {
+        page.setMercId(page.getMercId() == null ? MercAuthUtils.getMercId() : page.getMercId());
+        //非商户管理员,按设备权限过滤
+        if (!MercAuthUtils.isMercAdmin()) {
+            List<Long> mercDeviceIds = getMercDeviceIds();
+            if (CollUtil.isEmpty(mercDeviceIds)) {
+                return R.ok(new DeviceInfoDto.PageCount ());
+            }
+            page.setMyDeviceIds(mercDeviceIds);
+        }
+         return R.ok(deviceService.pageCountForPc(page));
+    }
+
+
     /**
      * 获取商户设备列表
      *

+ 7 - 0
device-api-service/src/main/java/com/xy/mapper/DeviceInfoMapper.java

@@ -28,6 +28,13 @@ public interface DeviceInfoMapper extends BaseMapper<DeviceInfo> {
      */
     IPage<DeviceInfoQueryPage> queryPage(IPage page, @Param("queryPage") DeviceInfoDto.Page queryPage);
 
+    /**
+     * 设备统计PC端
+     * @param queryPage
+     * @return
+     */
+    DeviceInfoDto.PageCount pageCountForPc( @Param("queryPage") DeviceInfoDto.Page queryPage);
+
     /**
      * 小程序首页设备列表线路分组
      *

+ 9 - 0
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -53,6 +53,7 @@ import io.swagger.annotations.ApiOperation;
 import jodd.introspector.MapperFunction;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
@@ -1923,6 +1924,14 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
     }
 
 
+    /**
+     * 设备统计PC端
+     * @param page
+     * @return
+     */
+    public DeviceInfoDto.PageCount pageCountForPc(DeviceInfoDto.Page page) {
+        return  baseMapper.pageCountForPc(  page);
+    }
     public PageBean<DeviceInfoDto.Vo2> queryPage(DeviceInfoDto.Page page) {
         IPage<DeviceInfoQueryPage> iPage = baseMapper.queryPage(toIPage(page.getPage()), page);
         PageBean<DeviceInfoDto.Vo2> pageBean = toPageBean(DeviceInfoDto.Vo2.class, iPage);

+ 125 - 0
device-api-service/src/main/resources/mapper/DeviceInfoMapper.xml

@@ -388,6 +388,131 @@
         </if>
     </select>
 
+
+    <!-- 分页查询统计 -->
+    <select id="pageCountForPc" resultType="com.xy.dto.DeviceInfoDto$PageCount">
+        SELECT
+        COUNT(*) AS total,
+        SUM(CASE WHEN status.net_state = 'online' THEN 1 ELSE 0 END) AS onlineNum,
+        SUM(CASE WHEN status.net_state = 'offline' THEN 1 ELSE 0 END) AS offLineNum,
+        SUM(CASE WHEN info.active_state = 1 THEN 1 ELSE 0 END) AS activeNum,
+        SUM(CASE WHEN info.active_state = 0 THEN 1 ELSE 0 END) AS noActiveNum
+        FROM device_info info
+        JOIN device_status status ON info.device_id = status.device_id
+        join device_sysinfo sysinfo on info.device_id = sysinfo.device_id
+
+        <where>
+            <if test="queryPage.isBindMerc != null">
+                <choose>
+                    <when test="queryPage.isBindMerc == true">
+                        and info.merc_id is not null
+                    </when>
+                    <otherwise>
+                        and (info.merc_id is null or info.merc_id = '')
+                    </otherwise>
+                </choose>
+            </if>
+            <if test="queryPage.isHaveNfc != null">
+                and sysinfo.is_have_alipay_npad= #{queryPage.isHaveNfc}
+            </if>
+            <if test="queryPage.keyword != null and queryPage.keyword != ''">
+                and CONCAT(IFNULL(info.device_name, ''), IFNULL(info.device_id, '')) LIKE
+                CONCAT('%',#{queryPage.keyword},'%')
+            </if>
+            <if test="queryPage.showStatus != null">
+                and info.show_status = #{queryPage.showStatus}
+            </if>
+            <if test="queryPage.deviceIdName != null and queryPage.deviceIdName != ''">
+                and (
+                LOCATE(#{queryPage.deviceIdName}, info.device_id) > 0 or
+                LOCATE(#{queryPage.deviceIdName}, info.device_name)
+                > 0
+                )
+            </if>
+            <if test="queryPage.deviceId != null">
+                and LOCATE(#{queryPage.deviceId}, info.device_id) > 0
+            </if>
+            <if test="queryPage.deviceIdList != null">
+                and info.device_id IN
+                <foreach collection="queryPage.deviceIdList" item="deviceId" open="(" close=")" separator=",">
+                    #{deviceId}
+                </foreach>
+            </if>
+
+            <if test="queryPage.deviceName != null and queryPage.deviceName != ''">
+                and LOCATE(#{queryPage.deviceName}, info.device_name) > 0
+            </if>
+            <if test="queryPage.no != null and queryPage.no != ''">
+                and (
+                LOCATE(#{queryPage.no}, info.merc_device_code) > 0 or
+                LOCATE(#{queryPage.no}, sysinfo.device_sn) > 0 or
+                LOCATE(#{queryPage.no}, sysinfo.sim_iccid) > 0
+                )
+            </if>
+            <if test="queryPage.activeState != null">
+                and info.active_state = #{queryPage.activeState}
+            </if>
+            <if test="queryPage.netState != null">
+                and status.net_state = #{queryPage.netState}
+            </if>
+
+            <if test="queryPage.stockStatus != null">
+                and status.stock_status = #{queryPage.stockStatus}
+            </if>
+
+
+            <if test="queryPage.busyState != null">
+                and info.busy_state = #{queryPage.busyState}
+            </if>
+            <if test="queryPage.deviceType != null">
+                and info.device_type = #{queryPage.deviceType}
+            </if>
+            <if test="queryPage.mercDeviceCode != null and queryPage.mercDeviceCode != ''">
+                and LOCATE(#{queryPage.mercDeviceCode}, info.merc_device_code) > 0
+            </if>
+            <if test="queryPage.mercCode != null and queryPage.mercCode != ''">
+                and info.merc_code = #{queryPage.mercCode}
+            </if>
+            <if test="queryPage.mercId != null">
+                and info.merc_id = #{queryPage.mercId}
+            </if>
+            <if test="queryPage.merc != null and queryPage.merc != ''">
+                and (
+                info.merc_id = #{queryPage.merc} or info.merc_code like concat(#{queryPage.merc}, '%') or
+                LOCATE(#{queryPage.merc}, mr.name) > 0
+                )
+            </if>
+            <if test="queryPage.placeId != null">
+                and info.place_id = #{queryPage.placeId}
+            </if>
+            <if test="queryPage.placeLineId != null">
+                and info.place_line_id = #{queryPage.placeLineId}
+            </if>
+            <if test="queryPage.districtId != null">
+                and info.district_id = #{queryPage.districtId}
+            </if>
+            <if test="queryPage.activeState != null">
+                and info.active_state = #{queryPage.activeState}
+            </if>
+            <if test="queryPage.busyState != null">
+                and info.busy_state = #{queryPage.busyState}
+            </if>
+            <if test="queryPage.appUpmVersion != null and queryPage.appUpmVersion != ''">
+                and sysinfo.app_upm_version = #{queryPage.appUpmVersion}
+            </if>
+            <if test="queryPage.appDownmVersion != null and queryPage.appDownmVersion != ''">
+                and sysinfo.app_downm_version = #{queryPage.appDownmVersion}
+            </if>
+            <if test="queryPage.beginActiveTime != null and queryPage.beginActiveTime != ''">
+                and info.active_time >= #{queryPage.beginActiveTime}
+            </if>
+            <if test="queryPage.endActiveTime != null and queryPage.endActiveTime != ''">
+                and info.active_time &lt;= #{queryPage.endActiveTime}
+            </if>
+        </where>
+    </select>
+
+
     <!--  小程序首页设备列表线路分组  -->
     <select id="merHomeCountList" resultType="com.xy.dto.DeviceInfoDto$MercHomeCountVO">
         select count(*) deviceNum, IFNULL(district_id, -1) districtId

+ 20 - 0
device-api/src/main/java/com/xy/dto/DeviceInfoDto.java

@@ -791,6 +791,26 @@ public class DeviceInfoDto {
 
     }
 
+    @Data
+    @Accessors(chain = true)
+    public static class PageCount {
+        @ApiModelProperty(value = "总设备数")
+        private Integer total;
+
+        @ApiModelProperty(value = "在线设备数量")
+        private Integer onlineNum;
+
+        @ApiModelProperty(value = "离线设备数量")
+        private Integer offLineNum;
+
+        @ApiModelProperty(value = "激活设备数量")
+        private Integer activeNum;
+
+        @ApiModelProperty(value = "未激活设备数量")
+        private Integer noActiveNum;
+
+
+    }
     @Data
     @Accessors(chain = true)
     public static class Vo2 extends Vo {